2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
18 #include <dali-toolkit/internal/controls/control/control-debug.h>
19 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
20 #include <dali-toolkit/public-api/controls/control-impl.h>
21 #include <dali/integration-api/debug.h>
22 #include <dali/public-api/object/property-index-ranges.h>
23 #include <dali/public-api/object/property.h>
28 #if defined(DEBUG_ENABLED)
39 JsonWriter(Property::Value& value)
44 std::string ToString()
46 std::ostringstream stream;
51 void ToStream(std::ostream& stream)
53 switch(mValue.GetType())
55 case Dali::Property::BOOLEAN:
57 auto value = mValue.Get<bool>();
58 stream << ((value) ? "true" : "false");
61 case Dali::Property::FLOAT:
63 stream << mValue.Get<float>();
66 case Dali::Property::INTEGER:
68 stream << mValue.Get<int>();
71 case Dali::Property::VECTOR2:
73 auto vector = mValue.Get<Vector2>();
74 stream << "[" << vector.x << ", " << vector.y << "]";
77 case Dali::Property::VECTOR3:
79 auto vector = mValue.Get<Vector3>();
80 stream << "[" << vector.x << ", " << vector.y << ", " << vector.z << "]";
83 case Dali::Property::VECTOR4:
85 auto vector = mValue.Get<Vector4>();
86 stream << "[" << vector.x << ", " << vector.y << ", " << vector.z << ", " << vector.w << "]";
89 case Dali::Property::MATRIX3:
91 auto matrix = mValue.Get<Matrix3>();
93 for(int i = 0; i < 9; ++i)
97 stream << matrix.AsFloat()[i];
102 case Dali::Property::MATRIX:
104 auto matrix = mValue.Get<Matrix>();
106 for(int i = 0; i < 16; ++i)
110 stream << matrix.AsFloat()[i];
115 case Dali::Property::RECTANGLE:
117 auto vector = mValue.Get<Rect<int> >();
118 stream << "[" << vector.x << ", " << vector.y << ", " << vector.width << ", " << vector.height << "]";
121 case Dali::Property::ROTATION:
123 auto angleAxis = mValue.Get<AngleAxis>();
124 stream << "[ [ " << angleAxis.axis.x << ", " << angleAxis.axis.y << ", " << angleAxis.axis.z << "], "
125 << angleAxis.angle.radian << "]";
128 case Dali::Property::STRING:
130 stream << '"' << mValue.Get<std::string>() << '"';
133 case Dali::Property::ARRAY:
135 auto array = mValue.GetArray();
139 for(Property::Array::SizeType i = 0; i < array->Size(); ++i)
143 auto outValue = JsonWriter(array->GetElementAt(i));
144 stream << outValue.ToString();
150 case Dali::Property::MAP:
152 auto map = mValue.GetMap();
156 for(Property::Map::SizeType i = 0; i < map->Count(); ++i)
160 auto key = map->GetKeyAt(i);
161 auto outValue = JsonWriter(map->GetValue(i));
162 stream << '\"' << key << "\":";
163 stream << outValue.ToString();
169 case Dali::Property::EXTENTS:
171 stream << mValue.Get<Extents>();
174 case Dali::Property::NONE:
176 stream << "undefined type";
182 Property::Value& mValue;
185 static std::ostream& operator<<(std::ostream& o, JsonWriter& value)
191 std::ostream& operator<<(std::ostream& o, const RegisteredVisual& registeredVisual)
194 << "\"index\":" << registeredVisual.index << ",\n";
195 o << "\"enabled\":" << (registeredVisual.enabled ? "true" : "false") << ",\n";
196 o << "\"pending\":" << (registeredVisual.pending ? "true" : "false") << ",\n";
199 registeredVisual.visual.CreatePropertyMap(map);
200 o << "\"visual\": {\n\"name\":\"" << registeredVisual.visual.GetName() << "\",\n";
206 std::ostream& operator<<(std::ostream& o, const RegisteredVisualContainer& visualContainer)
211 for(auto&& elem : visualContainer)
225 std::ostream& DumpProperty(std::ostream& o, Property::Index index, Handle handle)
227 auto propertyValue = handle.GetProperty(index);
228 auto jsonPropertyValue = JsonWriter(propertyValue);
231 o << "\"index\":" << index << ",\n";
232 o << "\"name\":\"" << handle.GetPropertyName(index) << "\",\n";
233 o << "\"value\":" << jsonPropertyValue << "\n";
238 std::ostream& DumpPropertiesWithPredicate(std::ostream& o, Dali::Handle handle, Property::IndexContainer& indices, std::function<bool(int)> predicate)
241 for(auto index : indices)
251 DumpProperty(o, index, handle);
257 std::ostream& DumpProperties(std::ostream& o, Handle handle)
259 Property::IndexContainer indices;
260 handle.GetPropertyIndices(indices);
262 auto childPropertiesP = [](int index) -> bool {
263 return CHILD_PROPERTY_REGISTRATION_START_INDEX <= index && index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX;
265 auto propertiesP = [](int index) -> bool {
266 return !(CHILD_PROPERTY_REGISTRATION_START_INDEX <= index && index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX);
269 o << "\"childProperties\":[\n";
270 DumpPropertiesWithPredicate(o, handle, indices, childPropertiesP);
272 << "]," << std::endl;
274 o << "\"Properties\":[\n";
275 DumpPropertiesWithPredicate(o, handle, indices, propertiesP);
282 std::string DumpControl(const Internal::Control& control)
284 auto& controlData = Internal::Control::Impl::Get(control);
286 std::ostringstream oss;
288 const std::string& name = control.Self().GetProperty<std::string>(Dali::Actor::Property::NAME);
291 oss << "\"name\":\"" << name << "\",\n";
293 oss << "\"id\":\"" << control.Self().GetProperty<int>(Actor::Property::ID) << "\",\n";
294 oss << "\"registeredVisuals\":\n"
295 << controlData.mVisuals << ",\n";
296 oss << "\"removeVisuals\":\n"
297 << controlData.mRemoveVisuals << ",\n";
298 oss << "\"rendererCount\":" << control.Self().GetRendererCount() << ",\n";
299 oss << "\"properties\":\n{\n";
300 DumpProperties(oss, control.Self()) << "}\n";
305 std::string DumpActor(Actor actor)
307 std::ostringstream oss;
309 const std::string& name = actor.GetProperty<std::string>(Dali::Actor::Property::NAME);
312 oss << "\"name\":\"" << name << "\",\n";
314 oss << "\"id\":\"" << actor.GetProperty<int>(Actor::Property::ID) << "\",\n";
315 oss << "\"rendererCount\":" << actor.GetRendererCount() << ",\n";
316 oss << "\"properties\":\n{\n";
317 Toolkit::Internal::DumpProperties(oss, actor) << "}\n";
322 void DumpControlHierarchy(std::ostream& o, Actor actor)
324 auto control = Toolkit::Control::DownCast(actor);
328 o << "\"Control\":" << DumpControl(Toolkit::Internal::GetImplementation(control));
332 o << "\"Actor\":" << DumpActor(actor);
334 o << ",\n\"children\":[\n";
336 for(auto count = actor.GetChildCount(), i = 0u; i < count; ++i)
344 DumpControlHierarchy(o, actor.GetChildAt(i));
349 } // namespace Internal
350 } // namespace Toolkit