1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChartDebugTrace.cxx,v $
10 * $Revision: 1.4.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "ChartDebugTrace.hxx"
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/chart2/AxisType.hpp>
38 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
39 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
40 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
41 #include <com/sun/star/chart2/StackingDirection.hpp>
42 #include <rtl/math.hxx>
44 using namespace ::com::sun::star
;
45 using namespace ::com::sun::star::chart2
;
47 using ::com::sun::star::uno::Reference
;
48 using ::com::sun::star::uno::Sequence
;
49 using ::rtl::OUString
;
51 #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
56 const char lcl_aSpace=' ';
58 void lcl_IndentedTrace( int nIndent, char* pStr )
62 OSL_TRACE( "%*c%s", nIndent, lcl_aSpace, pStr );
70 void lcl_TraceException( const uno::Exception & aEx )
73 U2C( C2U( "*** Exception caught during trace. Type: " ) +
74 OUString::createFromAscii( typeid( aEx ).name()) +
75 C2U( ", Message: " ) +
79 void lcl_TraceCategories( const Reference< data::XLabeledDataSequence > & xCat, int nIndent )
85 Reference< data::XDataSequence > xValues( xCat->getValues());
88 OSL_TRACE( "%*ccategories: source: %s", nIndent, lcl_aSpace,
89 U2C( xValues->getSourceRangeRepresentation()));
91 Reference< data::XDataSequence > xLabel( xCat->getLabel());
94 OSL_TRACE( "%*ccategories' label: source: %s", nIndent, lcl_aSpace,
95 U2C( xLabel->getSourceRangeRepresentation()));
98 catch( uno::Exception & ex )
100 lcl_TraceException( ex );
104 void lcl_TraceDataSeriesSeq( const Sequence< Reference< XDataSeries > > & aSeries, int nIndent )
106 for( sal_Int32 j = 0; j < aSeries.getLength(); ++j )
108 Reference< beans::XPropertySet > xProp( aSeries[j], uno::UNO_QUERY );
111 OSL_TRACE( "%*cindex %ld", nIndent, lcl_aSpace, j );
113 StackingDirection aStDir;
115 ( xProp->getPropertyValue( C2U( "StackingDirection" )) >>= aStDir ) &&
116 aStDir != StackingDirection_NO_STACKING )
118 OSL_TRACE( "%*cstacking in %s", nIndent + 2, lcl_aSpace,
119 (aStDir == StackingDirection_Y_STACKING)
120 ? "y-direction" : "z-direction" );
123 Reference< data::XDataSource > xSource( aSeries[j], uno::UNO_QUERY );
126 Sequence< Reference< data::XLabeledDataSequence > > aSequences( xSource->getDataSequences());
127 const sal_Int32 nMax = aSequences.getLength();
128 for( sal_Int32 k = 0; k < nMax; ++k )
130 if( aSequences[k].is())
132 OUString aSourceId(C2U("<none>"));
133 if( aSequences[k]->getValues().is())
134 aSourceId = aSequences[k]->getValues()->getSourceRangeRepresentation();
135 xProp.set( aSequences[k]->getValues(), uno::UNO_QUERY );
137 ( xProp->getPropertyValue( C2U( "Role" )) >>= aId ))
139 OSL_TRACE( "%*cdata sequence %d: role: %s, source: %s",
140 nIndent + 2, lcl_aSpace, k, U2C( aId ), U2C( aSourceId ));
144 OSL_TRACE( "%*cdata sequence %d, unknown role, source: %s",
145 nIndent + 2, lcl_aSpace, k, U2C( aSourceId ) );
148 aSourceId = C2U("<none>");
149 if( aSequences[k]->getLabel().is())
150 aSourceId = OUString( aSequences[k]->getLabel()->getSourceRangeRepresentation());
151 xProp.set( aSequences[k]->getLabel(), uno::UNO_QUERY );
153 ( xProp->getPropertyValue( C2U( "Role" )) >>= aId ))
155 OSL_TRACE( "%*cdata sequence label %d: role: %s, source: %s",
156 nIndent + 2, lcl_aSpace, k, U2C( aId ), U2C( aSourceId ));
160 OSL_TRACE( "%*cdata sequence label %d: unknown role, source: %s",
161 nIndent + 2, lcl_aSpace, k, U2C( aSourceId ) );
169 void lcl_TraceChartType( const Reference< XChartType > & xChartType, int nIndent )
173 OSL_TRACE( "%*c* type: %s", nIndent, lcl_aSpace, U2C( xChartType->getChartType()) );
175 lcl_IndentedTrace( nIndent + 2, "Supported Roles" );
177 Sequence< OUString > aMandRoles( xChartType->getSupportedMandatoryRoles());
178 if( aMandRoles.getLength() > 0 )
180 lcl_IndentedTrace( nIndent + 4, "mandatory" );
181 for( i=0; i<aMandRoles.getLength(); ++i )
183 OSL_TRACE( "%*c%s", nIndent + 6, lcl_aSpace, U2C( aMandRoles[i] ));
186 Sequence< OUString > aOptRoles( xChartType->getSupportedOptionalRoles());
187 if( aOptRoles.getLength() > 0 )
189 lcl_IndentedTrace( nIndent + 4, "optional" );
190 for( i=0; i<aOptRoles.getLength(); ++i )
192 OSL_TRACE( "%*c%s", nIndent + 6, lcl_aSpace, U2C( aOptRoles[i] ));
195 OSL_TRACE( "%*crole of sequence for label: %s", nIndent + 2, lcl_aSpace,
196 U2C( xChartType->getRoleOfSequenceForSeriesLabel()));
198 Reference< XDataSeriesContainer > xDSCnt( xChartType, uno::UNO_QUERY );
201 lcl_IndentedTrace( nIndent + 2, "Data Series" );
202 lcl_TraceDataSeriesSeq( xDSCnt->getDataSeries(), nIndent + 4 );
207 void lcl_TraceCoordinateSystem( const Reference< XCoordinateSystem > & xCooSys, int nIndent )
209 if( xCooSys.is()) try
211 sal_Int32 nDim = xCooSys->getDimension();
212 OSL_TRACE( "%*c* dim: %ld, type: %s", nIndent, lcl_aSpace,
213 nDim, U2C( xCooSys->getCoordinateSystemType() ));
215 OSL_TRACE( "%*cview service-name: %s", nIndent, lcl_aSpace,
216 U2C( xCooSys->getViewServiceName() ));
218 Reference< beans::XPropertySet > xProp( xCooSys, uno::UNO_QUERY );
221 Reference< beans::XPropertySetInfo > xInfo( xProp->getPropertySetInfo(), uno::UNO_QUERY );
224 xInfo->hasPropertyByName( C2U("SwapXAndYAxis")) &&
225 (xProp->getPropertyValue( C2U("SwapXAndYAxis")) >>= bSwap) &&
228 lcl_IndentedTrace( nIndent, "swap x-axis and y-axis" );
234 const sal_Int32 nMaxIndex = xCooSys->getMaximumAxisIndexByDimension(1);
235 for(sal_Int32 nI=0; nI<=nMaxIndex; ++nI)
237 Reference< XScale > xScale( xCooSys->getAxisByDimension( 1, nI ));
240 ScaleData aData( xScale->getScaleData());
241 if( aData.AxisType==AxisType::PERCENT )
242 lcl_IndentedTrace( nIndent, "percent stacking at y-scale" );
247 Sequence< uno::Any > aOrigin( xCooSys->getOrigin());
249 ::rtl::math::setNan( &x ), ::rtl::math::setNan( &y ), ::rtl::math::setNan( &z );
250 if( aOrigin.getLength() > 0 &&
251 aOrigin[0].hasValue() )
253 if( aOrigin.getLength() > 1 &&
254 aOrigin[1].hasValue() )
256 if( aOrigin.getLength() > 2 &&
257 aOrigin[2].hasValue() )
259 OSL_TRACE( "%*corigin: (%f, %f, %f)", nIndent, lcl_aSpace, x, y, z );
261 Reference< XChartTypeContainer > xCTCnt( xCooSys, uno::UNO_QUERY );
264 Sequence< Reference< XChartType > > aChartTypes( xCTCnt->getChartTypes());
265 if( aChartTypes.getLength() > 0 )
267 lcl_IndentedTrace( nIndent, "Chart Types" );
268 for( sal_Int32 i=0; i<aChartTypes.getLength(); ++i )
270 lcl_TraceChartType( aChartTypes[i], nIndent + 2 );
275 catch( uno::Exception & ex )
277 lcl_TraceException( ex );
282 const Reference< XMeter > & xMeter,
283 const Sequence< Reference< XCoordinateSystem > > & aCooSys,
284 bool bWithCategories,
289 Reference< XCoordinateSystem > xCooSys( xMeter->getCoordinateSystem());
290 for( sal_Int32 i=0; i<aCooSys.getLength(); ++i )
291 if( aCooSys[i] == xCooSys )
293 OSL_TRACE( "%*cbelongs to Coordinate System %ld.", nIndent + 2, lcl_aSpace, i );
295 OSL_TRACE( "%*crepresents Dimension %ld.", nIndent + 2, lcl_aSpace, xMeter->getRepresentedDimension());
296 if( bWithCategories )
298 Reference< XScale > xScale( xCooSys->getAxisByDimension( xMeter->getRepresentedDimension(), xMeter->getIndex() ));
301 ScaleData aData = xScale->getScaleData();
302 if( aData.Categories.is())
304 lcl_TraceCategories( aData.Categories, nIndent + 2 );
309 catch( uno::Exception & ex )
311 lcl_TraceException( ex );
315 } // anonymous namespace
324 #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
326 void ChartDebugTraceDocument(
327 const Reference
< XChartDocument
> & /*xDoc*/,
331 #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
334 OSL_TRACE( "%*cas %sternal data", nIndent, 'h',
335 xDoc->hasInternalDataProvider() ? "in": "ex" );
337 Reference< lang::XMultiServiceFactory > xCTManager( xDoc->getChartTypeManager(), uno::UNO_QUERY );
340 Sequence< OUString > aServiceNames( xCTManager->getAvailableServiceNames());
341 OSL_TRACE( "%*c ChartTypeManager has %ld entries", nIndent, '*', aServiceNames.getLength());
342 # if OSL_DEBUG_LEVEL >= (CHART_TRACE_OSL_DEBUG_LEVEL + 1)
343 for( sal_Int32 i=0; i<aServiceNames.getLength(); ++i )
345 OSL_TRACE( "%*c%s", nIndent + 2, lcl_aSpace, U2C( aServiceNames[i] ));
349 Reference< XDiagram > xDiagram( xDoc->getFirstDiagram());
350 lcl_IndentedTrace( nIndent, "* Diagram" );
351 ChartDebugTraceDiagram( xDiagram, nIndent + 2 );
353 catch( uno::Exception & ex )
355 lcl_TraceException( ex );
361 void ChartDebugTraceDiagram(
362 const Reference
< XDiagram
> & /*xDiagram*/,
366 #if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL
369 Reference< XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW );
370 Sequence< Reference< XCoordinateSystem > > aCooSys( xCooSysCnt->getCoordinateSystems() );
371 if( aCooSys.getLength() > 0 )
373 lcl_IndentedTrace( nIndent, "CoordinateSystems" );
374 for( sal_Int32 i=0; i<aCooSys.getLength(); ++i )
375 lcl_TraceCoordinateSystem( aCooSys[i], nIndent + 2 );
379 lcl_IndentedTrace( nIndent, "<No Coordinate Systems>" );
382 Reference< XAxisContainer > xAxisCnt( xDiagram, uno::UNO_QUERY_THROW );
383 Sequence< Reference< XAxis > > aAxes( xAxisCnt->getAxes() );
384 if( aAxes.getLength() > 0 )
386 lcl_IndentedTrace( nIndent, "Axes" );
387 for( sal_Int32 i=0; i<aAxes.getLength(); ++i )
388 lcl_TraceMeter( Reference< XMeter >( aAxes[i], uno::UNO_QUERY ), aCooSys, true, nIndent + 2 );
392 lcl_IndentedTrace( nIndent, "<No Axes>" );
395 Reference< XGridContainer > xGridCnt( xDiagram, uno::UNO_QUERY_THROW );
396 Sequence< Reference< XGrid > > aGrids( xGridCnt->getGrids() );
397 if( aGrids.getLength() > 0 )
399 lcl_IndentedTrace( nIndent, "Grids" );
400 for( sal_Int32 i=0; i<aGrids.getLength(); ++i )
401 lcl_TraceMeter( Reference< XMeter >( aGrids[i], uno::UNO_QUERY ), aCooSys, false, nIndent + 2 );
405 lcl_IndentedTrace( nIndent, "<No Grids>" );
408 catch( uno::Exception & ex )
410 lcl_TraceException( ex );