Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / update-manager-debug.cpp
1 /*
2  * Copyright (c) 2021 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 <iomanip>
23 #include <ios>
24 #include <sstream>
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 #ifdef DALI_PRINT_UPDATE_INFO
34
35 namespace Dali
36 {
37 namespace Internal
38 {
39 namespace SceneGraph
40 {
41 #if defined(DEBUG_ENABLED)
42 static Debug::Filter* gNodeLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_UPDATE_MANAGER");
43 #endif
44
45 /**
46  * Debug helper function.
47  */
48 void PrintNodes(const Node& node, BufferIndex updateBufferIndex, int level)
49 {
50   const Vector3&    position = node.GetPosition(updateBufferIndex);
51   const Vector3&    scale    = node.GetScale(updateBufferIndex);
52   const Vector3&    fullPos  = node.GetWorldPosition(updateBufferIndex);
53   const Quaternion& rotation = node.GetOrientation(updateBufferIndex);
54   Vector3           axis;
55   Radian            angle;
56   rotation.ToAxisAngle(axis, angle);
57
58   std::string nodeName = DALI_LOG_GET_OBJECT_STRING((&node));
59
60   {
61     std::ostringstream      oss;
62     std::ios_base::fmtflags mask = oss.flags();
63     mask &= ~std::ios_base::scientific;
64     mask |= std::ios_base::fixed;
65     oss << std::setprecision(2) << std::setiosflags(mask)
66         << std::setw(level * 2) << std::setfill(' ') << "";
67     oss << "Node " << nodeName << " " << &node
68         << "  Position (" << position.x << ", " << position.y << ", " << position.z << ")"
69         << "  WorldPosition (" << fullPos.x << ", " << fullPos.y << ", " << fullPos.z << ")"
70         << "  Orientation (" << Degree(angle).degree << "degrees <" << axis.x << ", " << axis.y << ", " << axis.z << ">)"
71         << "  Scale (" << scale.x << ", " << scale.y << ", " << scale.z << ")"
72         << std::endl;
73
74     DALI_LOG_INFO(gNodeLogFilter, Debug::Verbose, "%s\n", oss.str().c_str());
75   }
76
77   {
78     std::ostringstream      oss;
79     std::ios_base::fmtflags mask = oss.flags();
80     mask &= ~std::ios_base::scientific;
81     mask |= std::ios_base::fixed;
82     oss << std::setprecision(2) << std::setiosflags(mask)
83         << std::setw(level * 2) << std::setfill(' ') << "";
84
85     std::string trafoMatrix = Debug::MatrixToString(node.GetWorldMatrix(updateBufferIndex), 2, level * 2);
86     DALI_LOG_INFO(gNodeLogFilter, Debug::Verbose, "%s\n", trafoMatrix.c_str());
87   }
88
89   ++level;
90
91   for(NodeConstIter iter = node.GetChildren().Begin(); iter != node.GetChildren().End(); ++iter)
92   {
93     PrintNodes(**iter, updateBufferIndex, level);
94   }
95 }
96
97 void PrintNodeTree(const Node& node, BufferIndex bufferIndex, std::string indentation)
98 {
99   std::cout << "Node " << &node
100             << " \"" << node.mDebugString << "\""
101             << " Origin: " << node.GetParentOrigin()
102             << " Anchor: " << node.GetAnchorPoint()
103             << " Size: " << node.GetSize(bufferIndex)
104             << " Pos: " << node.GetPosition(bufferIndex)
105             << " Ori: " << node.GetOrientation(bufferIndex)
106             << " Scale: " << node.GetScale(bufferIndex)
107             << " Color: " << node.GetColor(bufferIndex)
108             << " Visible: " << node.IsVisible(bufferIndex)
109             << " World Pos: " << node.GetWorldPosition(bufferIndex)
110             << " World Ori: " << node.GetWorldOrientation(bufferIndex)
111             << " World Scale: " << node.GetWorldScale(bufferIndex)
112             << " World Color: " << node.GetWorldColor(bufferIndex)
113             << " World Matrix: " << node.GetWorldMatrix(bufferIndex)
114             << std::endl;
115
116   for(NodeConstIter iter = node.GetChildren().Begin(); iter != node.GetChildren().End(); ++iter)
117   {
118     std::cout << indentation << "|" << std::endl
119               << indentation << "---->";
120
121     std::string nextIndent = indentation;
122     if((iter + 1) != node.GetChildren().End())
123     {
124       nextIndent += "|    ";
125     }
126     else
127     {
128       nextIndent += "     ";
129     }
130
131     PrintNodeTree(**iter, bufferIndex, nextIndent);
132   }
133 }
134
135 } // namespace SceneGraph
136
137 } // namespace Internal
138
139 } // namespace Dali
140
141 #endif