1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "precompiled_slideshow.hxx"
25
26 #include "debug.hxx"
27
28 #if OSL_DEBUG_LEVEL > 1
29
30 #include "animationnodes/basecontainernode.hxx"
31 #include "animationnodes/paralleltimecontainer.hxx"
32 #include "animationnodes/sequentialtimecontainer.hxx"
33 #include "animationnodes/animationtransitionfilternode.hxx"
34 #include "animationnodes/animationaudionode.hxx"
35 #include "animationnodes/animationcolornode.hxx"
36 #include "animationnodes/animationcommandnode.hxx"
37 #include "animationnodes/animationpathmotionnode.hxx"
38 #include "animationnodes/animationsetnode.hxx"
39 #include "animationnodes/animationtransformnode.hxx"
40 #include "animationnodes/propertyanimationnode.hxx"
41
42 #include <com/sun/star/animations/XAnimationNode.hpp>
43 #include <com/sun/star/animations/Event.hpp>
44
45 #include <cstdio>
46 #include <cstdarg>
47
48 using ::rtl::OUString;
49 using namespace ::com::sun::star;
50
51
52 namespace slideshow { namespace internal {
53
54 namespace {
55
56 class NodeContainer : public BaseContainerNode
57 {
58 public:
59 void ShowChildrenState (void) const;
60 };
61
62
63
64
DebugGetDescription(const AnimationNodeSharedPtr & rpNode)65 OUString DebugGetDescription (const AnimationNodeSharedPtr& rpNode)
66 {
67 if (::boost::dynamic_pointer_cast<BaseContainerNode>(rpNode))
68 {
69 // Node is a container.
70 if (::boost::dynamic_pointer_cast<ParallelTimeContainer>(rpNode))
71 return OUString::createFromAscii("ParallelTimeContainer");
72 else if (::boost::dynamic_pointer_cast<SequentialTimeContainer>(rpNode))
73 return OUString::createFromAscii("SequentialTimeContainer");
74 else
75 return OUString::createFromAscii("<unknown container>");
76 }
77 else if (::boost::dynamic_pointer_cast<AnimationTransitionFilterNode>(rpNode))
78 return OUString::createFromAscii("AnimationTransitionFilterNode");
79 else if (::boost::dynamic_pointer_cast<AnimationAudioNode>(rpNode))
80 return OUString::createFromAscii("AnimationAudioNode");
81 else if (::boost::dynamic_pointer_cast<AnimationColorNode>(rpNode))
82 return OUString::createFromAscii("AnimationColorNode");
83 else if (::boost::dynamic_pointer_cast<AnimationCommandNode>(rpNode))
84 return OUString::createFromAscii("AnimationCommandNode");
85 else if (::boost::dynamic_pointer_cast<AnimationPathMotionNode>(rpNode))
86 return OUString::createFromAscii("AnimationPathMotionNode");
87 else if (::boost::dynamic_pointer_cast<AnimationSetNode>(rpNode))
88 return OUString::createFromAscii("AnimationSetNode");
89 else if (::boost::dynamic_pointer_cast<AnimationTransformNode>(rpNode))
90 return OUString::createFromAscii("AnimationTransformNode");
91 else if (::boost::dynamic_pointer_cast<PropertyAnimationNode>(rpNode))
92 return OUString::createFromAscii("PropertyAnimationNode");
93 else
94 return OUString::createFromAscii("<unknown node type>");
95 }
96
97
98
99
DebugShowState(const AnimationNodeSharedPtr & rpNode)100 void DebugShowState (const AnimationNodeSharedPtr& rpNode)
101 {
102 if ( ! rpNode)
103 return;
104
105 OUString sState;
106 OUString sStateColor;
107 switch (rpNode->getState())
108 {
109 default:
110 case AnimationNode::INVALID:
111 sState = OUString::createFromAscii("Invalid");
112 sStateColor = OUString::createFromAscii("firebrick1");
113 break;
114 case AnimationNode::UNRESOLVED:
115 sState = OUString::createFromAscii("Unresolved");
116 sStateColor = OUString::createFromAscii("dodgerblue4");
117 break;
118 case AnimationNode::RESOLVED:
119 sState = OUString::createFromAscii("Resolved");
120 sStateColor = OUString::createFromAscii("dodgerblue");
121 break;
122 case AnimationNode::ACTIVE:
123 sState = OUString::createFromAscii("Active");
124 sStateColor = OUString::createFromAscii("seagreen1");
125 break;
126 case AnimationNode::FROZEN:
127 sState = OUString::createFromAscii("Frozen");
128 sStateColor = OUString::createFromAscii("lightskyblue1");
129 break;
130 case AnimationNode::ENDED:
131 sState = OUString::createFromAscii("Ended");
132 sStateColor = OUString::createFromAscii("slategray3");
133 break;
134 }
135
136 const uno::Any aBegin (rpNode->getXAnimationNode()->getBegin());
137 OUString sTrigger;
138 if (aBegin.hasValue())
139 {
140 animations::Event aEvent;
141 double nTimeOffset;
142 const static char* sEventTriggers[] = {
143 "NONE", "ON_BEGIN", "ON_END", "BEGIN_EVENT", "END_EVENT", "ON_CLICK",
144 "ON_DBL_CLICK", "ON_MOUSE_ENTER", "ON_MOUSE_LEAVE", "ON_NEXT", "ON_PREV",
145 "ON_STOP_AUDIO", "REPEAT"};
146 if (aBegin >>= aEvent)
147 {
148 sTrigger = OUString::createFromAscii(sEventTriggers[aEvent.Trigger]);
149 }
150 else if (aBegin >>= nTimeOffset)
151 {
152 sTrigger = OUString::valueOf(nTimeOffset);
153 }
154 else
155 {
156 sTrigger = OUString::createFromAscii("other");
157 }
158 }
159 else
160 sTrigger = ::rtl::OUString::createFromAscii("void");
161
162 TRACE("Node state: n%x [label=\"%x / %x / %s\\n%s\\n%s\",style=filled,fillcolor=\"%s\"]\r",
163 rpNode.get(),
164 rpNode.get(),
165 rpNode->getXAnimationNode().get(),
166 ::rtl::OUStringToOString(sState, RTL_TEXTENCODING_ASCII_US).getStr(),
167 ::rtl::OUStringToOString(DebugGetDescription(rpNode), RTL_TEXTENCODING_ASCII_US).getStr(),
168 ::rtl::OUStringToOString(sTrigger, RTL_TEXTENCODING_ASCII_US).getStr(),
169 ::rtl::OUStringToOString(sStateColor, RTL_TEXTENCODING_ASCII_US).getStr());
170
171 BaseContainerNodeSharedPtr pContainer (
172 ::boost::dynamic_pointer_cast<BaseContainerNode>(rpNode));
173 if (pContainer)
174 ::boost::static_pointer_cast<NodeContainer>(rpNode)->ShowChildrenState();
175 }
176
177
178
179
ShowChildrenState(void) const180 void NodeContainer::ShowChildrenState (void) const
181 {
182 for (std::size_t nIndex=0; nIndex<maChildren.size(); ++nIndex)
183 {
184 TRACE("Node connection: n%x -> n%x", this, maChildren[nIndex].get());
185 DebugShowState(maChildren[nIndex]);
186 }
187 }
188
189
190
191
DebugGetTreeRoot(const BaseNodeSharedPtr & rpNode)192 AnimationNodeSharedPtr DebugGetTreeRoot (const BaseNodeSharedPtr& rpNode)
193 {
194 BaseNodeSharedPtr pNode (rpNode);
195 if (pNode)
196 {
197 BaseNodeSharedPtr pParent (pNode->getParentNode());
198 while (pParent)
199 {
200 pNode = pParent;
201 pParent = pNode->getParentNode();
202 }
203 }
204 return pNode;
205 }
206
207 } // end of anonymous namespace
208
209
210
211
Debug_ShowNodeTree(const AnimationNodeSharedPtr & rpNode)212 void Debug_ShowNodeTree (const AnimationNodeSharedPtr& rpNode)
213 {
214 DebugTraceScope aTraceScope ("NodeTree");
215
216 DebugShowState(DebugGetTreeRoot(::boost::dynamic_pointer_cast<BaseNode>(rpNode)));
217 }
218
219
220
221
222 //----- Tracing ---------------------------------------------------------------
223
224 extern "C" {
225
226 namespace {
227
228 class TraceData
229 {
230 public:
TraceData(void)231 TraceData (void)
232 : mnIndentation(0),
233 mpFile(fopen(TRACE_LOG_FILE_NAME, "w")),
234 maTime()
235 {
236 }
237
238 int mnIndentation;
239 FILE* mpFile;
240 ::canvas::tools::ElapsedTime maTime;
241 };
242 static TraceData gTraceData;
243
DebugTrace(const int nIndentationOffset,const sal_Char * sFormat,va_list args)244 inline void SAL_CALL DebugTrace (
245 const int nIndentationOffset,
246 const sal_Char* sFormat,
247 va_list args)
248 {
249 if (gTraceData.mpFile != NULL)
250 {
251 // Write line head with current time and indentation.
252 // Adapt indentation.
253 if (nIndentationOffset < 0)
254 gTraceData.mnIndentation += nIndentationOffset;
255 fprintf(gTraceData.mpFile, "%10.8f ", gTraceData.maTime.getElapsedTime());
256 for (int nIndentation=0; nIndentation<gTraceData.mnIndentation; ++nIndentation)
257 fprintf(gTraceData.mpFile, " ");
258 if (nIndentationOffset > 0)
259 gTraceData.mnIndentation += nIndentationOffset;
260
261 // Write message.
262 vfprintf(gTraceData.mpFile, sFormat, args);
263 fprintf(gTraceData.mpFile, "\n");
264 fflush(gTraceData.mpFile);
265 }
266 }
267
268 } // end of anonymous namespace
269
270
271 } // end of extern "C"
272
DebugTraceBegin(const sal_Char * sFormat,...)273 void SAL_CALL DebugTraceBegin (const sal_Char* sFormat, ...)
274 {
275 va_list args;
276 va_start(args, sFormat);
277 DebugTrace(+1,sFormat, args);
278 va_end(args);
279 }
280
DebugTraceEnd(const sal_Char * sFormat,...)281 void SAL_CALL DebugTraceEnd (const sal_Char* sFormat, ...)
282 {
283 va_list args;
284 va_start(args, sFormat);
285 DebugTrace(-1,sFormat, args);
286 va_end(args);
287 }
288
DebugTraceMessage(const sal_Char * sFormat,...)289 void SAL_CALL DebugTraceMessage (const sal_Char* sFormat, ...)
290 {
291 va_list args;
292 va_start(args, sFormat);
293 DebugTrace(0,sFormat, args);
294 va_end(args);
295 }
296
297
298
DebugTraceScope(const sal_Char * sFormat,...)299 DebugTraceScope::DebugTraceScope (const sal_Char* sFormat, ...)
300 : msMessage(new sal_Char[mnBufferSize])
301 {
302 va_list args;
303 va_start(args, sFormat);
304
305 msMessage[mnBufferSize-1] = 0;
306 vsnprintf(msMessage, mnBufferSize-1, sFormat, args);
307 TRACE_BEGIN("[ %s", msMessage);
308 va_end(args);
309 }
310
~DebugTraceScope(void)311 DebugTraceScope::~DebugTraceScope (void)
312 {
313 TRACE_END("] %s", msMessage);
314 delete [] msMessage;
315 }
316
317
318 } }
319
320 #endif // OSL_DEBUG_LEVEL > 1
321