Conversion to Apache 2.0 license
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / update-manager-debug.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/update/manager/update-manager-debug.h>
20
21 // EXTERNAL INCLUDES
22 #include <sstream>
23 #include <iomanip>
24 #include <ios>
25
26 // INTERNAL INCLUDES
27 #include <dali/integration-api/debug.h>
28 #include <dali/public-api/common/constants.h>
29 #include <dali/public-api/math/degree.h>
30 #include <dali/public-api/math/radian.h>
31 #include <dali/public-api/math/vector2.h>
32
33 namespace Dali
34 {
35
36 namespace Internal
37 {
38
39 namespace SceneGraph
40 {
41
42 #if defined(DEBUG_ENABLED)
43 static Debug::Filter* gNodeLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_UPDATE_MANAGER");
44 #endif
45
46 /**
47  * Debug helper function.
48  */
49 void PrintNodes( const Node& node, BufferIndex updateBufferIndex, int level )
50 {
51 #if defined(DEBUG_ENABLED)
52   const Vector3& position = node.GetPosition(updateBufferIndex);
53   const Vector3& scale = node.GetScale(updateBufferIndex);
54   const Vector3& fullPos = node.GetWorldPosition(updateBufferIndex);
55   const Quaternion& rotation = node.GetRotation(updateBufferIndex);
56   Vector3 axis;
57   float angle;
58   rotation.ToAxisAngle(axis, angle);
59   angle = angle * 180.0f / Math::PI;
60
61   std::string nodeName= DALI_LOG_GET_OBJECT_STRING((&node));
62
63   {
64     std::ostringstream oss;
65     std::ios_base::fmtflags mask = oss.flags();
66     mask &= ~std::ios_base::scientific;
67     mask |=  std::ios_base::fixed;
68     oss << std::setprecision(2) << std::setiosflags(mask)
69         << std::setw(level*2) << std::setfill(' ') << "";
70     oss << "Node "  << nodeName << " " << &node
71         << "  Pos (" << position.x << ", " << position.y << ", " << position.z << ")"
72         << "  FullPos (" << fullPos.x << ", " << fullPos.y << ", " << fullPos.z << ")"
73         << "  Rot (" << angle << "deg <" << axis.x << ", " << axis.y << ", " << axis.z << ">)"
74         << "  Scale (" << scale.x << ", " << scale.y << ", " << scale.z << ")"
75         << std::endl;
76
77     DALI_LOG_INFO(gNodeLogFilter, Debug::Verbose, "%s", oss.str().c_str());
78   }
79
80   {
81     std::ostringstream oss;
82     std::ios_base::fmtflags mask = oss.flags();
83     mask &= ~std::ios_base::scientific;
84     mask |=  std::ios_base::fixed;
85     oss << std::setprecision(2) << std::setiosflags(mask)
86         << std::setw(level*2) << std::setfill(' ') << "";
87
88     std::string trafoMatrix = Debug::MatrixToString(node.GetWorldMatrix(updateBufferIndex), 2, level*2);
89     DALI_LOG_INFO(gNodeLogFilter, Debug::Verbose, "%s", trafoMatrix.c_str());
90   }
91
92   ++level;
93
94   for ( NodeConstIter iter = node.GetChildren().Begin(); iter != node.GetChildren().End(); ++iter )
95   {
96     PrintNodes(**iter, updateBufferIndex, level);
97   }
98 #endif // DEBUG_ENABLED
99 }
100
101 void PrintNodeTree( const Node& node, BufferIndex bufferIndex, std::string indentation )
102 {
103 #if defined(DEBUG_ENABLED)
104
105   std::cout << "Node " << &node
106             << " \"" << node.mDebugString << "\""
107             << " Origin: "       << node.GetParentOrigin()
108             << " Anchor: "       << node.GetAnchorPoint()
109             << " Size: "         << node.GetSize(bufferIndex)
110             << " Pos: "          << node.GetPosition(bufferIndex)
111             << " Rot: "          << node.GetRotation(bufferIndex)
112             << " Scale: "        << node.GetScale(bufferIndex)
113             << " Color: "        << node.GetColor(bufferIndex)
114             << " Visible: "      << node.IsVisible(bufferIndex)
115             << " World Pos: "    << node.GetWorldPosition(bufferIndex)
116             << " World Rot: "    << node.GetWorldRotation(bufferIndex)
117             << " World Scale: "  << node.GetWorldScale(bufferIndex)
118             << " World Color: "  << node.GetWorldColor(bufferIndex)
119             << " World Matrix: " << node.GetWorldMatrix(bufferIndex)
120             << std::endl;
121
122   for ( NodeConstIter iter = node.GetChildren().Begin(); iter != node.GetChildren().End(); ++iter)
123   {
124     std::cout << indentation << "|" << std::endl
125               << indentation << "---->";
126
127     std::string nextIndent = indentation;
128     if ( (iter + 1) != node.GetChildren().End() )
129     {
130       nextIndent += "|    ";
131     }
132     else
133     {
134       nextIndent += "     ";
135     }
136
137     PrintNodeTree(**iter, bufferIndex, nextIndent);
138   }
139
140 #endif // DEBUG_ENABLED
141 }
142
143 } // SceneGraph
144
145 } // Internal
146
147 } // Dali