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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26
27 #include "ChartDebugTrace.hxx"
28 #include "macros.hxx"
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/chart2/AxisType.hpp>
31 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
32 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
33 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
34 #include <com/sun/star/chart2/StackingDirection.hpp>
35 #include <rtl/math.hxx>
36
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::chart2;
39
40 using ::com::sun::star::uno::Reference;
41 using ::com::sun::star::uno::Sequence;
42 using ::rtl::OUString;
43
44 #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
45
46 namespace
47 {
48 /*
49 const char lcl_aSpace=' ';
50
51 void lcl_IndentedTrace( int nIndent, char* pStr )
52 {
53 if( nIndent > 0 )
54 {
55 OSL_TRACE( "%*c%s", nIndent, lcl_aSpace, pStr );
56 }
57 else
58 {
59 OSL_TRACE( pStr );
60 }
61 }
62
63 void lcl_TraceException( const uno::Exception & aEx )
64 {
65 OSL_TRACE(
66 U2C( C2U( "*** Exception caught during trace. Type: " ) +
67 OUString::createFromAscii( typeid( aEx ).name()) +
68 C2U( ", Message: " ) +
69 aEx.Message ));
70 }
71
72 void lcl_TraceCategories( const Reference< data::XLabeledDataSequence > & xCat, int nIndent )
73 {
74 if( ! xCat.is())
75 return;
76 try
77 {
78 Reference< data::XDataSequence > xValues( xCat->getValues());
79 if( xValues.is())
80 {
81 OSL_TRACE( "%*ccategories: source: %s", nIndent, lcl_aSpace,
82 U2C( xValues->getSourceRangeRepresentation()));
83 }
84 Reference< data::XDataSequence > xLabel( xCat->getLabel());
85 if( xLabel.is())
86 {
87 OSL_TRACE( "%*ccategories' label: source: %s", nIndent, lcl_aSpace,
88 U2C( xLabel->getSourceRangeRepresentation()));
89 }
90 }
91 catch( uno::Exception & ex )
92 {
93 lcl_TraceException( ex );
94 }
95 }
96
97 void lcl_TraceDataSeriesSeq( const Sequence< Reference< XDataSeries > > & aSeries, int nIndent )
98 {
99 for( sal_Int32 j = 0; j < aSeries.getLength(); ++j )
100 {
101 Reference< beans::XPropertySet > xProp( aSeries[j], uno::UNO_QUERY );
102 OUString aId;
103
104 OSL_TRACE( "%*cindex %ld", nIndent, lcl_aSpace, j );
105
106 StackingDirection aStDir;
107 if( xProp.is() &&
108 ( xProp->getPropertyValue( C2U( "StackingDirection" )) >>= aStDir ) &&
109 aStDir != StackingDirection_NO_STACKING )
110 {
111 OSL_TRACE( "%*cstacking in %s", nIndent + 2, lcl_aSpace,
112 (aStDir == StackingDirection_Y_STACKING)
113 ? "y-direction" : "z-direction" );
114 }
115
116 Reference< data::XDataSource > xSource( aSeries[j], uno::UNO_QUERY );
117 if( xSource.is())
118 {
119 Sequence< Reference< data::XLabeledDataSequence > > aSequences( xSource->getDataSequences());
120 const sal_Int32 nMax = aSequences.getLength();
121 for( sal_Int32 k = 0; k < nMax; ++k )
122 {
123 if( aSequences[k].is())
124 {
125 OUString aSourceId(C2U("<none>"));
126 if( aSequences[k]->getValues().is())
127 aSourceId = aSequences[k]->getValues()->getSourceRangeRepresentation();
128 xProp.set( aSequences[k]->getValues(), uno::UNO_QUERY );
129 if( xProp.is() &&
130 ( xProp->getPropertyValue( C2U( "Role" )) >>= aId ))
131 {
132 OSL_TRACE( "%*cdata sequence %d: role: %s, source: %s",
133 nIndent + 2, lcl_aSpace, k, U2C( aId ), U2C( aSourceId ));
134 }
135 else
136 {
137 OSL_TRACE( "%*cdata sequence %d, unknown role, source: %s",
138 nIndent + 2, lcl_aSpace, k, U2C( aSourceId ) );
139 }
140
141 aSourceId = C2U("<none>");
142 if( aSequences[k]->getLabel().is())
143 aSourceId = OUString( aSequences[k]->getLabel()->getSourceRangeRepresentation());
144 xProp.set( aSequences[k]->getLabel(), uno::UNO_QUERY );
145 if( xProp.is() &&
146 ( xProp->getPropertyValue( C2U( "Role" )) >>= aId ))
147 {
148 OSL_TRACE( "%*cdata sequence label %d: role: %s, source: %s",
149 nIndent + 2, lcl_aSpace, k, U2C( aId ), U2C( aSourceId ));
150 }
151 else
152 {
153 OSL_TRACE( "%*cdata sequence label %d: unknown role, source: %s",
154 nIndent + 2, lcl_aSpace, k, U2C( aSourceId ) );
155 }
156 }
157 }
158 }
159 }
160 }
161
162 void lcl_TraceChartType( const Reference< XChartType > & xChartType, int nIndent )
163 {
164 if( xChartType.is())
165 {
166 OSL_TRACE( "%*c* type: %s", nIndent, lcl_aSpace, U2C( xChartType->getChartType()) );
167
168 lcl_IndentedTrace( nIndent + 2, "Supported Roles" );
169 sal_Int32 i=0;
170 Sequence< OUString > aMandRoles( xChartType->getSupportedMandatoryRoles());
171 if( aMandRoles.getLength() > 0 )
172 {
173 lcl_IndentedTrace( nIndent + 4, "mandatory" );
174 for( i=0; i<aMandRoles.getLength(); ++i )
175 {
176 OSL_TRACE( "%*c%s", nIndent + 6, lcl_aSpace, U2C( aMandRoles[i] ));
177 }
178 }
179 Sequence< OUString > aOptRoles( xChartType->getSupportedOptionalRoles());
180 if( aOptRoles.getLength() > 0 )
181 {
182 lcl_IndentedTrace( nIndent + 4, "optional" );
183 for( i=0; i<aOptRoles.getLength(); ++i )
184 {
185 OSL_TRACE( "%*c%s", nIndent + 6, lcl_aSpace, U2C( aOptRoles[i] ));
186 }
187 }
188 OSL_TRACE( "%*crole of sequence for label: %s", nIndent + 2, lcl_aSpace,
189 U2C( xChartType->getRoleOfSequenceForSeriesLabel()));
190
191 Reference< XDataSeriesContainer > xDSCnt( xChartType, uno::UNO_QUERY );
192 if( xDSCnt.is())
193 {
194 lcl_IndentedTrace( nIndent + 2, "Data Series" );
195 lcl_TraceDataSeriesSeq( xDSCnt->getDataSeries(), nIndent + 4 );
196 }
197 }
198 }
199
200 void lcl_TraceCoordinateSystem( const Reference< XCoordinateSystem > & xCooSys, int nIndent )
201 {
202 if( xCooSys.is()) try
203 {
204 sal_Int32 nDim = xCooSys->getDimension();
205 OSL_TRACE( "%*c* dim: %ld, type: %s", nIndent, lcl_aSpace,
206 nDim, U2C( xCooSys->getCoordinateSystemType() ));
207 nIndent += 2;
208 OSL_TRACE( "%*cview service-name: %s", nIndent, lcl_aSpace,
209 U2C( xCooSys->getViewServiceName() ));
210
211 Reference< beans::XPropertySet > xProp( xCooSys, uno::UNO_QUERY );
212 if( xProp.is())
213 {
214 Reference< beans::XPropertySetInfo > xInfo( xProp->getPropertySetInfo(), uno::UNO_QUERY );
215 sal_Bool bSwap;
216 if( xInfo.is() &&
217 xInfo->hasPropertyByName( C2U("SwapXAndYAxis")) &&
218 (xProp->getPropertyValue( C2U("SwapXAndYAxis")) >>= bSwap) &&
219 bSwap )
220 {
221 lcl_IndentedTrace( nIndent, "swap x-axis and y-axis" );
222 }
223 }
224
225 if( nDim >= 2 )
226 {
227 const sal_Int32 nMaxIndex = xCooSys->getMaximumAxisIndexByDimension(1);
228 for(sal_Int32 nI=0; nI<=nMaxIndex; ++nI)
229 {
230 Reference< XScale > xScale( xCooSys->getAxisByDimension( 1, nI ));
231 if( xScale.is())
232 {
233 ScaleData aData( xScale->getScaleData());
234 if( aData.AxisType==AxisType::PERCENT )
235 lcl_IndentedTrace( nIndent, "percent stacking at y-scale" );
236 }
237 }
238 }
239
240 Sequence< uno::Any > aOrigin( xCooSys->getOrigin());
241 double x, y, z;
242 ::rtl::math::setNan( &x ), ::rtl::math::setNan( &y ), ::rtl::math::setNan( &z );
243 if( aOrigin.getLength() > 0 &&
244 aOrigin[0].hasValue() )
245 aOrigin[0] >>= x;
246 if( aOrigin.getLength() > 1 &&
247 aOrigin[1].hasValue() )
248 aOrigin[1] >>= y;
249 if( aOrigin.getLength() > 2 &&
250 aOrigin[2].hasValue() )
251 aOrigin[2] >>= z;
252 OSL_TRACE( "%*corigin: (%f, %f, %f)", nIndent, lcl_aSpace, x, y, z );
253
254 Reference< XChartTypeContainer > xCTCnt( xCooSys, uno::UNO_QUERY );
255 if( xCTCnt.is())
256 {
257 Sequence< Reference< XChartType > > aChartTypes( xCTCnt->getChartTypes());
258 if( aChartTypes.getLength() > 0 )
259 {
260 lcl_IndentedTrace( nIndent, "Chart Types" );
261 for( sal_Int32 i=0; i<aChartTypes.getLength(); ++i )
262 {
263 lcl_TraceChartType( aChartTypes[i], nIndent + 2 );
264 }
265 }
266 }
267 }
268 catch( uno::Exception & ex )
269 {
270 lcl_TraceException( ex );
271 }
272 }
273
274 void lcl_TraceMeter(
275 const Reference< XMeter > & xMeter,
276 const Sequence< Reference< XCoordinateSystem > > & aCooSys,
277 bool bWithCategories,
278 int nIndent )
279 {
280 try
281 {
282 Reference< XCoordinateSystem > xCooSys( xMeter->getCoordinateSystem());
283 for( sal_Int32 i=0; i<aCooSys.getLength(); ++i )
284 if( aCooSys[i] == xCooSys )
285 {
286 OSL_TRACE( "%*cbelongs to Coordinate System %ld.", nIndent + 2, lcl_aSpace, i );
287 }
288 OSL_TRACE( "%*crepresents Dimension %ld.", nIndent + 2, lcl_aSpace, xMeter->getRepresentedDimension());
289 if( bWithCategories )
290 {
291 Reference< XScale > xScale( xCooSys->getAxisByDimension( xMeter->getRepresentedDimension(), xMeter->getIndex() ));
292 if( xScale.is())
293 {
294 ScaleData aData = xScale->getScaleData();
295 if( aData.Categories.is())
296 {
297 lcl_TraceCategories( aData.Categories, nIndent + 2 );
298 }
299 }
300 }
301 }
302 catch( uno::Exception & ex )
303 {
304 lcl_TraceException( ex );
305 }
306 }
307 */
308 } // anonymous namespace
309 #endif
310
311
312 namespace chart
313 {
314 namespace debug
315 {
316
317 #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
318
ChartDebugTraceDocument(const Reference<XChartDocument> &,int)319 void ChartDebugTraceDocument(
320 const Reference< XChartDocument > & /*xDoc*/,
321 int /*nIndent*/ )
322 {
323 /*
324 #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
325 try
326 {
327 OSL_TRACE( "%*cas %sternal data", nIndent, 'h',
328 xDoc->hasInternalDataProvider() ? "in": "ex" );
329
330 Reference< lang::XMultiServiceFactory > xCTManager( xDoc->getChartTypeManager(), uno::UNO_QUERY );
331 if( xCTManager.is())
332 {
333 Sequence< OUString > aServiceNames( xCTManager->getAvailableServiceNames());
334 OSL_TRACE( "%*c ChartTypeManager has %ld entries", nIndent, '*', aServiceNames.getLength());
335 # if OSL_DEBUG_LEVEL >= (CHART_TRACE_OSL_DEBUG_LEVEL + 1)
336 for( sal_Int32 i=0; i<aServiceNames.getLength(); ++i )
337 {
338 OSL_TRACE( "%*c%s", nIndent + 2, lcl_aSpace, U2C( aServiceNames[i] ));
339 }
340 # endif
341 }
342 Reference< XDiagram > xDiagram( xDoc->getFirstDiagram());
343 lcl_IndentedTrace( nIndent, "* Diagram" );
344 ChartDebugTraceDiagram( xDiagram, nIndent + 2 );
345 }
346 catch( uno::Exception & ex )
347 {
348 lcl_TraceException( ex );
349 }
350 #endif
351 */
352 }
353
ChartDebugTraceDiagram(const Reference<XDiagram> &,int)354 void ChartDebugTraceDiagram(
355 const Reference< XDiagram > & /*xDiagram*/,
356 int /*nIndent*/ )
357 {
358 /*
359 #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
360 try
361 {
362 Reference< XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW );
363 Sequence< Reference< XCoordinateSystem > > aCooSys( xCooSysCnt->getCoordinateSystems() );
364 if( aCooSys.getLength() > 0 )
365 {
366 lcl_IndentedTrace( nIndent, "CoordinateSystems" );
367 for( sal_Int32 i=0; i<aCooSys.getLength(); ++i )
368 lcl_TraceCoordinateSystem( aCooSys[i], nIndent + 2 );
369 }
370 else
371 {
372 lcl_IndentedTrace( nIndent, "<No Coordinate Systems>" );
373 }
374
375 Reference< XAxisContainer > xAxisCnt( xDiagram, uno::UNO_QUERY_THROW );
376 Sequence< Reference< XAxis > > aAxes( xAxisCnt->getAxes() );
377 if( aAxes.getLength() > 0 )
378 {
379 lcl_IndentedTrace( nIndent, "Axes" );
380 for( sal_Int32 i=0; i<aAxes.getLength(); ++i )
381 lcl_TraceMeter( Reference< XMeter >( aAxes[i], uno::UNO_QUERY ), aCooSys, true, nIndent + 2 );
382 }
383 else
384 {
385 lcl_IndentedTrace( nIndent, "<No Axes>" );
386 }
387
388 Reference< XGridContainer > xGridCnt( xDiagram, uno::UNO_QUERY_THROW );
389 Sequence< Reference< XGrid > > aGrids( xGridCnt->getGrids() );
390 if( aGrids.getLength() > 0 )
391 {
392 lcl_IndentedTrace( nIndent, "Grids" );
393 for( sal_Int32 i=0; i<aGrids.getLength(); ++i )
394 lcl_TraceMeter( Reference< XMeter >( aGrids[i], uno::UNO_QUERY ), aCooSys, false, nIndent + 2 );
395 }
396 else
397 {
398 lcl_IndentedTrace( nIndent, "<No Grids>" );
399 }
400 }
401 catch( uno::Exception & ex )
402 {
403 lcl_TraceException( ex );
404 }
405
406 #endif
407
408 */
409 }
410 #endif
411
412 } // namespace debug
413 } // namespace chart
414