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