Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "SchXMLSeriesHelper.hxx"
31 : : #include <com/sun/star/chart2/XChartDocument.hpp>
32 : : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
33 : : #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
34 : : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
35 : : #include <com/sun/star/lang/XInitialization.hpp>
36 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 : :
38 : : // header for define RTL_CONSTASCII_USTRINGPARAM
39 : : #include <rtl/ustring.h>
40 : : // header for define DBG_ERROR1
41 : : #include <tools/debug.hxx>
42 : :
43 : : #include <typeinfo>
44 : :
45 : : using namespace ::com::sun::star;
46 : : using ::rtl::OUString;
47 : : using ::rtl::OUStringToOString;
48 : :
49 : : using ::com::sun::star::uno::Reference;
50 : : using ::com::sun::star::uno::Sequence;
51 : : using ::rtl::OUString;
52 : :
53 : : // ----------------------------------------
54 : :
55 : : ::std::vector< Reference< chart2::XDataSeries > >
56 : 27 : SchXMLSeriesHelper::getDataSeriesFromDiagram(
57 : : const Reference< chart2::XDiagram > & xDiagram )
58 : : {
59 : 27 : ::std::vector< Reference< chart2::XDataSeries > > aResult;
60 : :
61 : : try
62 : : {
63 : : Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
64 [ + - ]: 27 : xDiagram, uno::UNO_QUERY_THROW );
65 : : Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
66 [ + - ][ + - ]: 27 : xCooSysCnt->getCoordinateSystems());
67 [ + + ]: 54 : for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i )
68 : : {
69 [ + - ][ + - ]: 27 : Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[i], uno::UNO_QUERY_THROW );
70 [ + - ][ + - ]: 27 : Sequence< Reference< chart2::XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
71 [ + + ]: 54 : for( sal_Int32 j=0; j<aChartTypeSeq.getLength(); ++j )
72 : : {
73 [ + - ][ + - ]: 27 : Reference< chart2::XDataSeriesContainer > xDSCnt( aChartTypeSeq[j], uno::UNO_QUERY_THROW );
74 [ + - ][ + - ]: 27 : Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
75 : 27 : ::std::copy( aSeriesSeq.getConstArray(), aSeriesSeq.getConstArray() + aSeriesSeq.getLength(),
76 [ + - + - ]: 54 : ::std::back_inserter( aResult ));
77 [ + - ]: 27 : }
78 [ + - ][ + - ]: 54 : }
[ # # ]
79 : : }
80 [ # # ]: 0 : catch( const uno::Exception & ex )
81 : : {
82 : : (void)ex; // avoid warning for pro build
83 : :
84 : : OSL_FAIL( OUStringToOString( OUString(
85 : : OUString( "Exception caught. Type: " ) +
86 : : OUString::createFromAscii( typeid( ex ).name()) +
87 : : OUString( ", Message: " ) +
88 : : ex.Message), RTL_TEXTENCODING_ASCII_US ).getStr());
89 : :
90 : : }
91 : :
92 : 27 : return aResult;
93 : : }
94 : :
95 : 0 : ::std::map< Reference< chart2::XDataSeries >, sal_Int32 > SchXMLSeriesHelper::getDataSeriesIndexMapFromDiagram(
96 : : const Reference< chart2::XDiagram > & xDiagram )
97 : : {
98 [ # # ]: 0 : ::std::map< Reference< chart2::XDataSeries >, sal_Int32 > aRet;
99 : :
100 : 0 : sal_Int32 nIndex=0;
101 : :
102 [ # # ]: 0 : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( SchXMLSeriesHelper::getDataSeriesFromDiagram( xDiagram ));
103 [ # # ][ # # ]: 0 : for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
[ # # ][ # # ]
104 : 0 : ; aSeriesIt != aSeriesVector.end()
105 : : ; aSeriesIt++, nIndex++ )
106 : : {
107 : 0 : Reference< chart2::XDataSeries > xSeries( *aSeriesIt );
108 [ # # ]: 0 : if( xSeries.is() )
109 : : {
110 [ # # ][ # # ]: 0 : if( aRet.end() == aRet.find(xSeries) )
111 [ # # ]: 0 : aRet[xSeries]=nIndex;
112 : : }
113 : 0 : }
114 : 0 : return aRet;
115 : : }
116 : :
117 : 0 : uno::Reference< chart2::XChartType > lcl_getChartTypeOfSeries(
118 : : const uno::Reference< chart2::XDiagram >& xDiagram
119 : : , const Reference< chart2::XDataSeries >& xSeries )
120 : : {
121 [ # # ]: 0 : if(!xDiagram.is())
122 [ # # ]: 0 : return 0;
123 : :
124 : : //iterate through the model to find the given xSeries
125 : : //the found parent indicates the charttype
126 : :
127 : : //iterate through all coordinate systems
128 [ # # ]: 0 : uno::Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
129 [ # # ]: 0 : if( !xCooSysContainer.is())
130 [ # # ]: 0 : return 0;
131 : :
132 [ # # ][ # # ]: 0 : uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
133 [ # # ]: 0 : for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
134 : : {
135 [ # # ]: 0 : uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysList[nCS] );
136 : :
137 : : //iterate through all chart types in the current coordinate system
138 [ # # ]: 0 : uno::Reference< chart2::XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
139 : : OSL_ASSERT( xChartTypeContainer.is());
140 [ # # ]: 0 : if( !xChartTypeContainer.is() )
141 : 0 : continue;
142 [ # # ][ # # ]: 0 : uno::Sequence< uno::Reference< chart2::XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
143 [ # # ]: 0 : for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
144 : : {
145 [ # # ]: 0 : uno::Reference< chart2::XChartType > xChartType( aChartTypeList[nT] );
146 : :
147 : : //iterate through all series in this chart type
148 [ # # ]: 0 : uno::Reference< chart2::XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY );
149 : : OSL_ASSERT( xDataSeriesContainer.is());
150 [ # # ]: 0 : if( !xDataSeriesContainer.is() )
151 : 0 : continue;
152 : :
153 [ # # ][ # # ]: 0 : uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
154 [ # # ]: 0 : for( sal_Int32 nS = 0; nS < aSeriesList.getLength(); ++nS )
155 : : {
156 [ # # ]: 0 : Reference< chart2::XDataSeries > xCurrentSeries( aSeriesList[nS] );
157 : :
158 [ # # ][ # # ]: 0 : if( xSeries == xCurrentSeries )
159 : 0 : return xChartType;
160 [ # # ]: 0 : }
161 [ # # ][ # # ]: 0 : }
[ # # # ]
[ # # # ]
162 [ # # ][ # # ]: 0 : }
[ # # # ]
[ # # # ]
163 [ # # ][ # # ]: 0 : return 0;
164 : : }
165 : :
166 : 0 : bool SchXMLSeriesHelper::isCandleStickSeries(
167 : : const Reference< chart2::XDataSeries >& xSeries
168 : : , const Reference< frame::XModel >& xChartModel )
169 : : {
170 : 0 : bool bRet = false;
171 : :
172 [ # # ]: 0 : uno::Reference< chart2::XChartDocument > xNewDoc( xChartModel, uno::UNO_QUERY );
173 [ # # ]: 0 : if( xNewDoc.is() )
174 : : {
175 [ # # ][ # # ]: 0 : uno::Reference< chart2::XDiagram > xNewDiagram( xNewDoc->getFirstDiagram() );
176 [ # # ]: 0 : if( xNewDiagram.is() )
177 : : {
178 : : uno::Reference< chart2::XChartType > xChartType( lcl_getChartTypeOfSeries(
179 [ # # ]: 0 : xNewDiagram, xSeries ) );
180 [ # # ]: 0 : if( xChartType.is() )
181 : : {
182 [ # # ][ # # ]: 0 : rtl::OUString aServiceName( xChartType->getChartType() );
183 [ # # ]: 0 : if( aServiceName == "com.sun.star.chart2.CandleStickChartType" )
184 : 0 : bRet = true;
185 : 0 : }
186 : 0 : }
187 : : }
188 : 0 : return bRet;
189 : : }
190 : :
191 : : //static
192 : 92 : uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPISeriesPropertySet(
193 : : const uno::Reference< chart2::XDataSeries >& xSeries
194 : : , const uno::Reference< frame::XModel >& xChartModel )
195 : : {
196 : 92 : uno::Reference< beans::XPropertySet > xRet;
197 : :
198 [ + - ]: 92 : if( xSeries.is() )
199 : : {
200 : : try
201 : : {
202 [ + - ]: 92 : uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
203 [ + - ]: 92 : if( xFactory.is() )
204 : : {
205 [ + - ]: 92 : xRet = uno::Reference< beans::XPropertySet >( xFactory->createInstance(
206 [ + - ][ + - ]: 92 : OUString( "com.sun.star.comp.chart2.DataSeriesWrapper" ) ), uno::UNO_QUERY );
[ + - ]
207 [ + - ]: 92 : Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
208 [ + - ]: 92 : if(xInit.is())
209 : : {
210 [ + - ]: 92 : Sequence< uno::Any > aArguments(1);
211 [ + - ][ + - ]: 92 : aArguments[0]=uno::makeAny(xSeries);
212 [ + - ][ + - ]: 92 : xInit->initialize(aArguments);
[ + - ]
213 : 92 : }
214 [ # # ]: 92 : }
215 : : }
216 [ # # ]: 0 : catch( const uno::Exception & rEx )
217 : : {
218 : : (void)rEx; // avoid warning for pro build
219 : : OSL_TRACE( "Exception caught SchXMLSeriesHelper::createOldAPISeriesPropertySet: %s",
220 : : OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
221 : : }
222 : : }
223 : :
224 : 92 : return xRet;
225 : : }
226 : :
227 : : //static
228 : 0 : uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
229 : : const uno::Reference< chart2::XDataSeries >& xSeries
230 : : , sal_Int32 nPointIndex
231 : : , const uno::Reference< frame::XModel >& xChartModel )
232 : : {
233 : 0 : uno::Reference< beans::XPropertySet > xRet;
234 : :
235 [ # # ]: 0 : if( xSeries.is() )
236 : : {
237 : : try
238 : : {
239 [ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
240 [ # # ]: 0 : if( xFactory.is() )
241 : : {
242 [ # # ]: 0 : xRet = uno::Reference< beans::XPropertySet >( xFactory->createInstance(
243 [ # # ][ # # ]: 0 : OUString( "com.sun.star.comp.chart2.DataSeriesWrapper" ) ), uno::UNO_QUERY );
[ # # ]
244 [ # # ]: 0 : Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
245 [ # # ]: 0 : if(xInit.is())
246 : : {
247 [ # # ]: 0 : Sequence< uno::Any > aArguments(2);
248 [ # # ][ # # ]: 0 : aArguments[0]=uno::makeAny(xSeries);
249 [ # # ][ # # ]: 0 : aArguments[1]=uno::makeAny(nPointIndex);
250 [ # # ][ # # ]: 0 : xInit->initialize(aArguments);
[ # # ]
251 : 0 : }
252 [ # # ]: 0 : }
253 : : }
254 [ # # ]: 0 : catch( const uno::Exception & rEx )
255 : : {
256 : : (void)rEx; // avoid warning for pro build
257 : :
258 : : OSL_TRACE( "Exception caught SchXMLSeriesHelper::createOldAPIDataPointPropertySet: %s",
259 : : OUStringToOString( rEx.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
260 : : }
261 : : }
262 : :
263 : 0 : return xRet;
264 : : }
265 : :
266 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|