Added missing newline chars to logging commands
[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.GetOrientation(updateBufferIndex);
56   Vector3 axis;
57   Radian angle;
58   rotation.ToAxisAngle(axis, angle);
59
60   std::string nodeName= DALI_LOG_GET_OBJECT_STRING((&node));
61
62   {
63     std::ostringstream oss;
64     std::ios_base::fmtflags mask = oss.flags();
65     mask &= ~std::ios_base::scientific;
66     mask |=  std::ios_base::fixed;
67     oss << std::setprecision(2) << std::setiosflags(mask)
68         << std::setw(level*2) << std::setfill(' ') << "";
69     oss << "Node "  << nodeName << " " << &node
70         << "  Position (" << position.x << ", " << position.y << ", " << position.z << ")"
71         << "  WorldPosition (" << fullPos.x << ", " << fullPos.y << ", " << fullPos.z << ")"
72         << "  Orientation (" << Degree(angle).degree << "degrees <" << axis.x << ", " << axis.y << ", " << axis.z << ">)"
73         << "  Scale (" << scale.x << ", " << scale.y << ", " << scale.z << ")"
74         << std::endl;
75
76     DALI_LOG_INFO(gNodeLogFilter, Debug::Verbose, "%s\n", oss.str().c_str());
77   }
78
79   {
80     std::ostringstream oss;
81     std::ios_base::fmtflags mask = oss.flags();
82     mask &= ~std::ios_base::scientific;
83     mask |=  std::ios_base::fixed;
84     oss << std::setprecision(2) << std::setiosflags(mask)
85         << std::setw(level*2) << std::setfill(' ') << "";
86
87     std::string trafoMatrix = Debug::MatrixToString(node.GetWorldMatrix(updateBufferIndex), 2, level*2);
88     DALI_LOG_INFO(gNodeLogFilter, Debug::Verbose, "%s\n", trafoMatrix.c_str());
89   }
90
91   ++level;
92
93   for ( NodeConstIter iter = node.GetChildren().Begin(); iter != node.GetChildren().End(); ++iter )
94   {
95     PrintNodes(**iter, updateBufferIndex, level);
96   }
97 #endif // DEBUG_ENABLED
98 }
99
100 void PrintNodeTree( const Node& node, BufferIndex bufferIndex, std::string indentation )
101 {
102 #if defined(DEBUG_ENABLED)
103
104   std::cout << "Node " << &node
105             << " \"" << node.mDebugString << "\""
106             << " Origin: "       << node.GetParentOrigin()
107             << " Anchor: "       << node.GetAnchorPoint()
108             << " Size: "         << node.GetSize(bufferIndex)
109             << " Pos: "          << node.GetPosition(bufferIndex)
110             << " Ori: "          << node.GetOrientation(bufferIndex)
111             << " Scale: "        << node.GetScale(bufferIndex)
112             << " Color: "        << node.GetColor(bufferIndex)
113             << " Visible: "      << node.IsVisible(bufferIndex)
114             << " World Pos: "    << node.GetWorldPosition(bufferIndex)
115             << " World Ori: "    << node.GetWorldOrientation(bufferIndex)
116             << " World Scale: "  << node.GetWorldScale(bufferIndex)
117             << " World Color: "  << node.GetWorldColor(bufferIndex)
118             << " World Matrix: " << node.GetWorldMatrix(bufferIndex)
119             << std::endl;
120
121   for ( NodeConstIter iter = node.GetChildren().Begin(); iter != node.GetChildren().End(); ++iter)
122   {
123     std::cout << indentation << "|" << std::endl
124               << indentation << "---->";
125
126     std::string nextIndent = indentation;
127     if ( (iter + 1) != node.GetChildren().End() )
128     {
129       nextIndent += "|    ";
130     }
131     else
132     {
133       nextIndent += "     ";
134     }
135
136     PrintNodeTree(**iter, bufferIndex, nextIndent);
137   }
138
139 #endif // DEBUG_ENABLED
140 }
141
142 } // SceneGraph
143
144 } // Internal
145
146 } // Dali