Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <xmloff/SchXMLSeriesHelper.hxx>
21 : #include <com/sun/star/chart2/XChartDocument.hpp>
22 : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
23 : #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
24 : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
25 : #include <com/sun/star/lang/XInitialization.hpp>
26 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 :
28 : #include <rtl/ustring.h>
29 :
30 : #include <typeinfo>
31 :
32 : using namespace ::com::sun::star;
33 :
34 : using ::com::sun::star::uno::Reference;
35 : using ::com::sun::star::uno::Sequence;
36 :
37 : ::std::vector< Reference< chart2::XDataSeries > >
38 1692 : SchXMLSeriesHelper::getDataSeriesFromDiagram(
39 : const Reference< chart2::XDiagram > & xDiagram )
40 : {
41 1692 : ::std::vector< Reference< chart2::XDataSeries > > aResult;
42 :
43 : try
44 : {
45 : Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
46 1692 : xDiagram, uno::UNO_QUERY_THROW );
47 : Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
48 3384 : xCooSysCnt->getCoordinateSystems());
49 3384 : for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i )
50 : {
51 1692 : Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[i], uno::UNO_QUERY_THROW );
52 3384 : Sequence< Reference< chart2::XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
53 3536 : for( sal_Int32 j=0; j<aChartTypeSeq.getLength(); ++j )
54 : {
55 1844 : Reference< chart2::XDataSeriesContainer > xDSCnt( aChartTypeSeq[j], uno::UNO_QUERY_THROW );
56 3688 : Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
57 1844 : ::std::copy( aSeriesSeq.getConstArray(), aSeriesSeq.getConstArray() + aSeriesSeq.getLength(),
58 3688 : ::std::back_inserter( aResult ));
59 1844 : }
60 3384 : }
61 : }
62 0 : catch( const uno::Exception & ex )
63 : {
64 : SAL_WARN("xmloff.chart", "Exception caught. Type: " << OUString::createFromAscii( typeid( ex ).name() ) << ", Message: " << ex.Message );
65 : }
66 :
67 1692 : return aResult;
68 : }
69 :
70 0 : ::std::map< Reference< chart2::XDataSeries >, sal_Int32 > SchXMLSeriesHelper::getDataSeriesIndexMapFromDiagram(
71 : const Reference< chart2::XDiagram > & xDiagram )
72 : {
73 0 : ::std::map< Reference< chart2::XDataSeries >, sal_Int32 > aRet;
74 :
75 0 : sal_Int32 nIndex=0;
76 :
77 0 : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( SchXMLSeriesHelper::getDataSeriesFromDiagram( xDiagram ));
78 0 : const ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aSeriesEnd( aSeriesVector.end() );
79 0 : for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
80 : ; aSeriesIt != aSeriesEnd
81 : ; ++aSeriesIt, nIndex++ )
82 : {
83 0 : Reference< chart2::XDataSeries > xSeries( *aSeriesIt );
84 0 : if( xSeries.is() )
85 : {
86 0 : if( aRet.end() == aRet.find(xSeries) )
87 0 : aRet[xSeries]=nIndex;
88 : }
89 0 : }
90 0 : return aRet;
91 : }
92 :
93 : namespace {
94 4 : uno::Reference< chart2::XChartType > lcl_getChartTypeOfSeries(
95 : const uno::Reference< chart2::XDiagram >& xDiagram
96 : , const Reference< chart2::XDataSeries >& xSeries )
97 : {
98 4 : if(!xDiagram.is())
99 0 : return 0;
100 :
101 : //iterate through the model to find the given xSeries
102 : //the found parent indicates the charttype
103 :
104 : //iterate through all coordinate systems
105 4 : uno::Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
106 4 : if( !xCooSysContainer.is())
107 0 : return 0;
108 :
109 8 : uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
110 4 : for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
111 : {
112 4 : uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysList[nCS] );
113 :
114 : //iterate through all chart types in the current coordinate system
115 4 : uno::Reference< chart2::XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
116 : SAL_WARN_IF( !xChartTypeContainer.is(), "xmloff.chart", "xChartTypeContainer is NULL");
117 4 : if( !xChartTypeContainer.is() )
118 0 : continue;
119 4 : uno::Sequence< uno::Reference< chart2::XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
120 4 : for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
121 : {
122 4 : uno::Reference< chart2::XChartType > xChartType( aChartTypeList[nT] );
123 :
124 : //iterate through all series in this chart type
125 4 : uno::Reference< chart2::XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY );
126 : SAL_WARN_IF( !xDataSeriesContainer.is(), "xmloff.chart", "xDataSeriesContainer is NULL");
127 4 : if( !xDataSeriesContainer.is() )
128 0 : continue;
129 :
130 4 : uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
131 4 : for( sal_Int32 nS = 0; nS < aSeriesList.getLength(); ++nS )
132 : {
133 4 : Reference< chart2::XDataSeries > xCurrentSeries( aSeriesList[nS] );
134 :
135 4 : if( xSeries == xCurrentSeries )
136 4 : return xChartType;
137 0 : }
138 0 : }
139 0 : }
140 4 : return 0;
141 : }
142 : }
143 :
144 4 : bool SchXMLSeriesHelper::isCandleStickSeries(
145 : const Reference< chart2::XDataSeries >& xSeries
146 : , const Reference< frame::XModel >& xChartModel )
147 : {
148 4 : bool bRet = false;
149 :
150 4 : uno::Reference< chart2::XChartDocument > xNewDoc( xChartModel, uno::UNO_QUERY );
151 4 : if( xNewDoc.is() )
152 : {
153 4 : uno::Reference< chart2::XDiagram > xNewDiagram( xNewDoc->getFirstDiagram() );
154 4 : if( xNewDiagram.is() )
155 : {
156 : uno::Reference< chart2::XChartType > xChartType( lcl_getChartTypeOfSeries(
157 4 : xNewDiagram, xSeries ) );
158 4 : if( xChartType.is() )
159 : {
160 4 : OUString aServiceName( xChartType->getChartType() );
161 4 : if( aServiceName == "com.sun.star.chart2.CandleStickChartType" )
162 0 : bRet = true;
163 4 : }
164 4 : }
165 : }
166 4 : return bRet;
167 : }
168 :
169 : //static
170 3174 : uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPISeriesPropertySet(
171 : const uno::Reference< chart2::XDataSeries >& xSeries
172 : , const uno::Reference< frame::XModel >& xChartModel )
173 : {
174 3174 : uno::Reference< beans::XPropertySet > xRet;
175 :
176 3174 : if( xSeries.is() )
177 : {
178 : try
179 : {
180 3174 : uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
181 3174 : if( xFactory.is() )
182 : {
183 9522 : xRet = uno::Reference< beans::XPropertySet >( xFactory->createInstance(
184 6348 : "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY );
185 3174 : Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
186 3174 : if(xInit.is())
187 : {
188 3174 : Sequence< uno::Any > aArguments(1);
189 3174 : aArguments[0]=uno::makeAny(xSeries);
190 3174 : xInit->initialize(aArguments);
191 3174 : }
192 3174 : }
193 : }
194 0 : catch( const uno::Exception & rEx )
195 : {
196 : SAL_INFO("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPISeriesPropertySet: " << rEx.Message );
197 : }
198 : }
199 :
200 3174 : return xRet;
201 : }
202 :
203 : //static
204 2088 : uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
205 : const uno::Reference< chart2::XDataSeries >& xSeries
206 : , sal_Int32 nPointIndex
207 : , const uno::Reference< frame::XModel >& xChartModel )
208 : {
209 2088 : uno::Reference< beans::XPropertySet > xRet;
210 :
211 2088 : if( xSeries.is() )
212 : {
213 : try
214 : {
215 2088 : uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
216 2088 : if( xFactory.is() )
217 : {
218 6264 : xRet = uno::Reference< beans::XPropertySet >( xFactory->createInstance(
219 4176 : "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY );
220 2088 : Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
221 2088 : if(xInit.is())
222 : {
223 2088 : Sequence< uno::Any > aArguments(2);
224 2088 : aArguments[0]=uno::makeAny(xSeries);
225 2088 : aArguments[1]=uno::makeAny(nPointIndex);
226 2088 : xInit->initialize(aArguments);
227 2088 : }
228 2088 : }
229 : }
230 0 : catch( const uno::Exception & rEx )
231 : {
232 : SAL_INFO("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPIDataPointPropertySet: " << rEx.Message );
233 : }
234 : }
235 :
236 2088 : return xRet;
237 : }
238 :
239 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|