merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / tools / ChartDebugTrace.cxx
blob9629138cb2be58cf60b10339665075c5f10e38ff
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "ChartDebugTrace.hxx"
32 #include "macros.hxx"
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/chart2/AxisType.hpp>
35 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
36 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
37 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
38 #include <com/sun/star/chart2/StackingDirection.hpp>
39 #include <rtl/math.hxx>
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::chart2;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::Sequence;
46 using ::rtl::OUString;
48 #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
50 namespace
53 const char lcl_aSpace=' ';
55 void lcl_IndentedTrace( int nIndent, char* pStr )
57 if( nIndent > 0 )
59 OSL_TRACE( "%*c%s", nIndent, lcl_aSpace, pStr );
61 else
63 OSL_TRACE( pStr );
67 void lcl_TraceException( const uno::Exception & aEx )
69 OSL_TRACE(
70 U2C( C2U( "*** Exception caught during trace. Type: " ) +
71 OUString::createFromAscii( typeid( aEx ).name()) +
72 C2U( ", Message: " ) +
73 aEx.Message ));
76 void lcl_TraceCategories( const Reference< data::XLabeledDataSequence > & xCat, int nIndent )
78 if( ! xCat.is())
79 return;
80 try
82 Reference< data::XDataSequence > xValues( xCat->getValues());
83 if( xValues.is())
85 OSL_TRACE( "%*ccategories: source: %s", nIndent, lcl_aSpace,
86 U2C( xValues->getSourceRangeRepresentation()));
88 Reference< data::XDataSequence > xLabel( xCat->getLabel());
89 if( xLabel.is())
91 OSL_TRACE( "%*ccategories' label: source: %s", nIndent, lcl_aSpace,
92 U2C( xLabel->getSourceRangeRepresentation()));
95 catch( uno::Exception & ex )
97 lcl_TraceException( ex );
101 void lcl_TraceDataSeriesSeq( const Sequence< Reference< XDataSeries > > & aSeries, int nIndent )
103 for( sal_Int32 j = 0; j < aSeries.getLength(); ++j )
105 Reference< beans::XPropertySet > xProp( aSeries[j], uno::UNO_QUERY );
106 OUString aId;
108 OSL_TRACE( "%*cindex %ld", nIndent, lcl_aSpace, j );
110 StackingDirection aStDir;
111 if( xProp.is() &&
112 ( xProp->getPropertyValue( C2U( "StackingDirection" )) >>= aStDir ) &&
113 aStDir != StackingDirection_NO_STACKING )
115 OSL_TRACE( "%*cstacking in %s", nIndent + 2, lcl_aSpace,
116 (aStDir == StackingDirection_Y_STACKING)
117 ? "y-direction" : "z-direction" );
120 Reference< data::XDataSource > xSource( aSeries[j], uno::UNO_QUERY );
121 if( xSource.is())
123 Sequence< Reference< data::XLabeledDataSequence > > aSequences( xSource->getDataSequences());
124 const sal_Int32 nMax = aSequences.getLength();
125 for( sal_Int32 k = 0; k < nMax; ++k )
127 if( aSequences[k].is())
129 OUString aSourceId(C2U("<none>"));
130 if( aSequences[k]->getValues().is())
131 aSourceId = aSequences[k]->getValues()->getSourceRangeRepresentation();
132 xProp.set( aSequences[k]->getValues(), uno::UNO_QUERY );
133 if( xProp.is() &&
134 ( xProp->getPropertyValue( C2U( "Role" )) >>= aId ))
136 OSL_TRACE( "%*cdata sequence %d: role: %s, source: %s",
137 nIndent + 2, lcl_aSpace, k, U2C( aId ), U2C( aSourceId ));
139 else
141 OSL_TRACE( "%*cdata sequence %d, unknown role, source: %s",
142 nIndent + 2, lcl_aSpace, k, U2C( aSourceId ) );
145 aSourceId = C2U("<none>");
146 if( aSequences[k]->getLabel().is())
147 aSourceId = OUString( aSequences[k]->getLabel()->getSourceRangeRepresentation());
148 xProp.set( aSequences[k]->getLabel(), uno::UNO_QUERY );
149 if( xProp.is() &&
150 ( xProp->getPropertyValue( C2U( "Role" )) >>= aId ))
152 OSL_TRACE( "%*cdata sequence label %d: role: %s, source: %s",
153 nIndent + 2, lcl_aSpace, k, U2C( aId ), U2C( aSourceId ));
155 else
157 OSL_TRACE( "%*cdata sequence label %d: unknown role, source: %s",
158 nIndent + 2, lcl_aSpace, k, U2C( aSourceId ) );
166 void lcl_TraceChartType( const Reference< XChartType > & xChartType, int nIndent )
168 if( xChartType.is())
170 OSL_TRACE( "%*c* type: %s", nIndent, lcl_aSpace, U2C( xChartType->getChartType()) );
172 lcl_IndentedTrace( nIndent + 2, "Supported Roles" );
173 sal_Int32 i=0;
174 Sequence< OUString > aMandRoles( xChartType->getSupportedMandatoryRoles());
175 if( aMandRoles.getLength() > 0 )
177 lcl_IndentedTrace( nIndent + 4, "mandatory" );
178 for( i=0; i<aMandRoles.getLength(); ++i )
180 OSL_TRACE( "%*c%s", nIndent + 6, lcl_aSpace, U2C( aMandRoles[i] ));
183 Sequence< OUString > aOptRoles( xChartType->getSupportedOptionalRoles());
184 if( aOptRoles.getLength() > 0 )
186 lcl_IndentedTrace( nIndent + 4, "optional" );
187 for( i=0; i<aOptRoles.getLength(); ++i )
189 OSL_TRACE( "%*c%s", nIndent + 6, lcl_aSpace, U2C( aOptRoles[i] ));
192 OSL_TRACE( "%*crole of sequence for label: %s", nIndent + 2, lcl_aSpace,
193 U2C( xChartType->getRoleOfSequenceForSeriesLabel()));
195 Reference< XDataSeriesContainer > xDSCnt( xChartType, uno::UNO_QUERY );
196 if( xDSCnt.is())
198 lcl_IndentedTrace( nIndent + 2, "Data Series" );
199 lcl_TraceDataSeriesSeq( xDSCnt->getDataSeries(), nIndent + 4 );
204 void lcl_TraceCoordinateSystem( const Reference< XCoordinateSystem > & xCooSys, int nIndent )
206 if( xCooSys.is()) try
208 sal_Int32 nDim = xCooSys->getDimension();
209 OSL_TRACE( "%*c* dim: %ld, type: %s", nIndent, lcl_aSpace,
210 nDim, U2C( xCooSys->getCoordinateSystemType() ));
211 nIndent += 2;
212 OSL_TRACE( "%*cview service-name: %s", nIndent, lcl_aSpace,
213 U2C( xCooSys->getViewServiceName() ));
215 Reference< beans::XPropertySet > xProp( xCooSys, uno::UNO_QUERY );
216 if( xProp.is())
218 Reference< beans::XPropertySetInfo > xInfo( xProp->getPropertySetInfo(), uno::UNO_QUERY );
219 sal_Bool bSwap;
220 if( xInfo.is() &&
221 xInfo->hasPropertyByName( C2U("SwapXAndYAxis")) &&
222 (xProp->getPropertyValue( C2U("SwapXAndYAxis")) >>= bSwap) &&
223 bSwap )
225 lcl_IndentedTrace( nIndent, "swap x-axis and y-axis" );
229 if( nDim >= 2 )
231 const sal_Int32 nMaxIndex = xCooSys->getMaximumAxisIndexByDimension(1);
232 for(sal_Int32 nI=0; nI<=nMaxIndex; ++nI)
234 Reference< XScale > xScale( xCooSys->getAxisByDimension( 1, nI ));
235 if( xScale.is())
237 ScaleData aData( xScale->getScaleData());
238 if( aData.AxisType==AxisType::PERCENT )
239 lcl_IndentedTrace( nIndent, "percent stacking at y-scale" );
244 Sequence< uno::Any > aOrigin( xCooSys->getOrigin());
245 double x, y, z;
246 ::rtl::math::setNan( &x ), ::rtl::math::setNan( &y ), ::rtl::math::setNan( &z );
247 if( aOrigin.getLength() > 0 &&
248 aOrigin[0].hasValue() )
249 aOrigin[0] >>= x;
250 if( aOrigin.getLength() > 1 &&
251 aOrigin[1].hasValue() )
252 aOrigin[1] >>= y;
253 if( aOrigin.getLength() > 2 &&
254 aOrigin[2].hasValue() )
255 aOrigin[2] >>= z;
256 OSL_TRACE( "%*corigin: (%f, %f, %f)", nIndent, lcl_aSpace, x, y, z );
258 Reference< XChartTypeContainer > xCTCnt( xCooSys, uno::UNO_QUERY );
259 if( xCTCnt.is())
261 Sequence< Reference< XChartType > > aChartTypes( xCTCnt->getChartTypes());
262 if( aChartTypes.getLength() > 0 )
264 lcl_IndentedTrace( nIndent, "Chart Types" );
265 for( sal_Int32 i=0; i<aChartTypes.getLength(); ++i )
267 lcl_TraceChartType( aChartTypes[i], nIndent + 2 );
272 catch( uno::Exception & ex )
274 lcl_TraceException( ex );
278 void lcl_TraceMeter(
279 const Reference< XMeter > & xMeter,
280 const Sequence< Reference< XCoordinateSystem > > & aCooSys,
281 bool bWithCategories,
282 int nIndent )
286 Reference< XCoordinateSystem > xCooSys( xMeter->getCoordinateSystem());
287 for( sal_Int32 i=0; i<aCooSys.getLength(); ++i )
288 if( aCooSys[i] == xCooSys )
290 OSL_TRACE( "%*cbelongs to Coordinate System %ld.", nIndent + 2, lcl_aSpace, i );
292 OSL_TRACE( "%*crepresents Dimension %ld.", nIndent + 2, lcl_aSpace, xMeter->getRepresentedDimension());
293 if( bWithCategories )
295 Reference< XScale > xScale( xCooSys->getAxisByDimension( xMeter->getRepresentedDimension(), xMeter->getIndex() ));
296 if( xScale.is())
298 ScaleData aData = xScale->getScaleData();
299 if( aData.Categories.is())
301 lcl_TraceCategories( aData.Categories, nIndent + 2 );
306 catch( uno::Exception & ex )
308 lcl_TraceException( ex );
312 } // anonymous namespace
313 #endif
316 namespace chart
318 namespace debug
321 #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
323 void ChartDebugTraceDocument(
324 const Reference< XChartDocument > & /*xDoc*/,
325 int /*nIndent*/ )
328 #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
331 OSL_TRACE( "%*cas %sternal data", nIndent, 'h',
332 xDoc->hasInternalDataProvider() ? "in": "ex" );
334 Reference< lang::XMultiServiceFactory > xCTManager( xDoc->getChartTypeManager(), uno::UNO_QUERY );
335 if( xCTManager.is())
337 Sequence< OUString > aServiceNames( xCTManager->getAvailableServiceNames());
338 OSL_TRACE( "%*c ChartTypeManager has %ld entries", nIndent, '*', aServiceNames.getLength());
339 # if OSL_DEBUG_LEVEL >= (CHART_TRACE_OSL_DEBUG_LEVEL + 1)
340 for( sal_Int32 i=0; i<aServiceNames.getLength(); ++i )
342 OSL_TRACE( "%*c%s", nIndent + 2, lcl_aSpace, U2C( aServiceNames[i] ));
344 # endif
346 Reference< XDiagram > xDiagram( xDoc->getFirstDiagram());
347 lcl_IndentedTrace( nIndent, "* Diagram" );
348 ChartDebugTraceDiagram( xDiagram, nIndent + 2 );
350 catch( uno::Exception & ex )
352 lcl_TraceException( ex );
354 #endif
358 void ChartDebugTraceDiagram(
359 const Reference< XDiagram > & /*xDiagram*/,
360 int /*nIndent*/ )
363 #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
366 Reference< XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW );
367 Sequence< Reference< XCoordinateSystem > > aCooSys( xCooSysCnt->getCoordinateSystems() );
368 if( aCooSys.getLength() > 0 )
370 lcl_IndentedTrace( nIndent, "CoordinateSystems" );
371 for( sal_Int32 i=0; i<aCooSys.getLength(); ++i )
372 lcl_TraceCoordinateSystem( aCooSys[i], nIndent + 2 );
374 else
376 lcl_IndentedTrace( nIndent, "<No Coordinate Systems>" );
379 Reference< XAxisContainer > xAxisCnt( xDiagram, uno::UNO_QUERY_THROW );
380 Sequence< Reference< XAxis > > aAxes( xAxisCnt->getAxes() );
381 if( aAxes.getLength() > 0 )
383 lcl_IndentedTrace( nIndent, "Axes" );
384 for( sal_Int32 i=0; i<aAxes.getLength(); ++i )
385 lcl_TraceMeter( Reference< XMeter >( aAxes[i], uno::UNO_QUERY ), aCooSys, true, nIndent + 2 );
387 else
389 lcl_IndentedTrace( nIndent, "<No Axes>" );
392 Reference< XGridContainer > xGridCnt( xDiagram, uno::UNO_QUERY_THROW );
393 Sequence< Reference< XGrid > > aGrids( xGridCnt->getGrids() );
394 if( aGrids.getLength() > 0 )
396 lcl_IndentedTrace( nIndent, "Grids" );
397 for( sal_Int32 i=0; i<aGrids.getLength(); ++i )
398 lcl_TraceMeter( Reference< XMeter >( aGrids[i], uno::UNO_QUERY ), aCooSys, false, nIndent + 2 );
400 else
402 lcl_IndentedTrace( nIndent, "<No Grids>" );
405 catch( uno::Exception & ex )
407 lcl_TraceException( ex );
410 #endif
414 #endif
416 } // namespace debug
417 } // namespace chart