2 * Copyright (c) 2018 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/integration-api/debug.h>
18 #include <dali/public-api/object/property.h>
19 #include <dali/public-api/object/property-index-ranges.h>
20 #include <dali-toolkit/public-api/controls/control-impl.h>
21 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
22 #include <dali-toolkit/internal/controls/control/control-debug.h>
23 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
28 #if defined(DEBUG_ENABLED)
40 JsonWriter( Property::Value& value )
45 std::string ToString()
47 std::ostringstream stream;
52 void ToStream( std::ostream& stream )
54 switch( mValue.GetType() )
56 case Dali::Property::BOOLEAN:
58 auto value = mValue.Get<bool>();
59 stream << ((value)?"true":"false");
62 case Dali::Property::FLOAT:
64 stream << mValue.Get<float>();
67 case Dali::Property::INTEGER:
69 stream << mValue.Get<int>();
72 case Dali::Property::VECTOR2:
74 auto vector = mValue.Get<Vector2>();
75 stream << "[" << vector.x << ", " << vector.y << "]";
78 case Dali::Property::VECTOR3:
80 auto vector = mValue.Get<Vector3>();
81 stream << "[" << vector.x << ", " << vector.y << ", " << vector.z << "]";
84 case Dali::Property::VECTOR4:
86 auto vector = mValue.Get<Vector4>();
87 stream << "[" << vector.x << ", " << vector.y << ", " << vector.z << ", " << vector.w << "]";
90 case Dali::Property::MATRIX3:
92 auto matrix = mValue.Get<Matrix3>();
94 for( int i=0; i<9; ++i )
98 stream << matrix.AsFloat()[i];
103 case Dali::Property::MATRIX:
105 auto matrix = mValue.Get<Matrix>();
107 for( int i=0; i<16; ++i )
111 stream << matrix.AsFloat()[i];
116 case Dali::Property::RECTANGLE:
118 auto vector = mValue.Get<Rect<int> >();
119 stream << "[" << vector.x << ", " << vector.y << ", " << vector.width << ", " << vector.height << "]";
122 case Dali::Property::ROTATION:
124 auto angleAxis = mValue.Get<AngleAxis>();
125 stream << "[ [ " << angleAxis.axis.x << ", " << angleAxis.axis.y << ", " << angleAxis.axis.z << "], "
126 << angleAxis.angle.radian << "]";
129 case Dali::Property::STRING:
131 stream << '"' << mValue.Get<std::string>() << '"';
134 case Dali::Property::ARRAY:
136 auto array = mValue.GetArray();
140 for( Property::Array::SizeType i=0; i<array->Size(); ++i)
144 auto outValue = JsonWriter( array->GetElementAt(i) );
145 stream << outValue.ToString();
151 case Dali::Property::MAP:
153 auto map = mValue.GetMap();
157 for( Property::Map::SizeType i=0; i<map->Count(); ++i)
161 auto key = map->GetKeyAt( i );
162 auto outValue = JsonWriter( map->GetValue(i) );
163 stream << '\"' << key << "\":";
164 stream << outValue.ToString();
170 case Dali::Property::EXTENTS:
172 stream << mValue.Get<Extents>();
175 case Dali::Property::NONE:
177 stream << "undefined type";
183 Property::Value& mValue;
186 static std::ostream& operator<<( std::ostream& o, JsonWriter& value )
193 std::ostream& operator<<( std::ostream& o, const RegisteredVisual& registeredVisual )
195 o << "{\n" << "\"index\":" << registeredVisual.index << ",\n";
196 o << "\"enabled\":" << (registeredVisual.enabled?"true":"false") << ",\n";
197 o << "\"pending\":" << (registeredVisual.pending?"true":"false") << ",\n";
200 registeredVisual.visual.CreatePropertyMap( map );
201 o << "\"visual\": {\n\"name\":\"" << registeredVisual.visual.GetName() << "\",\n";
202 o << map << "}\n" << "\n}\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";
239 std::ostream& DumpPropertiesWithPredicate( std::ostream& o, Dali::Handle handle,
240 Property::IndexContainer& indices, std::function<bool(int)> predicate)
243 for( auto index : indices )
245 if( predicate( index ) )
253 DumpProperty( o, index, handle );
259 std::ostream& DumpProperties( std::ostream& o, Handle handle )
261 Property::IndexContainer indices;
262 handle.GetPropertyIndices( indices );
264 auto childPropertiesP = [](int index) -> bool
266 return CHILD_PROPERTY_REGISTRATION_START_INDEX <= index && index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX;
268 auto propertiesP = [](int index) -> bool
270 return !(CHILD_PROPERTY_REGISTRATION_START_INDEX <= index && index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX);
273 o << "\"childProperties\":[\n" ;
274 DumpPropertiesWithPredicate( o, handle, indices, childPropertiesP );
275 o << std::endl << "]," << std::endl;
277 o << "\"Properties\":[\n" ;
278 DumpPropertiesWithPredicate( o, handle, indices, propertiesP );
279 o << std::endl << "]" << std::endl;
284 std::string DumpControl( const Internal::Control& control )
286 auto& controlData = Internal::Control::Impl::Get( control );
288 std::ostringstream oss;
290 const std::string& name = control.Self().GetProperty< std::string >( Dali::Actor::Property::NAME );
293 oss << "\"name\":\"" << name << "\",\n";
295 oss << "\"id\":\"" << control.Self().GetProperty< int >( Actor::Property::ID ) << "\",\n";
296 oss << "\"registeredVisuals\":\n" << controlData.mVisuals << ",\n";
297 oss << "\"removeVisuals\":\n" << 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