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 "ScatterChartTypeTemplate.hxx"
21 : #include "macros.hxx"
22 : #include "XYDataInterpreter.hxx"
23 : #include "CartesianCoordinateSystem.hxx"
24 : #include "DiagramHelper.hxx"
25 : #include "servicenames_charttypes.hxx"
26 : #include "ContainerHelper.hxx"
27 : #include "DataSeriesHelper.hxx"
28 : #include "PropertyHelper.hxx"
29 : #include <unonames.hxx>
30 :
31 : #include <com/sun/star/chart2/SymbolStyle.hpp>
32 : #include <com/sun/star/chart2/Symbol.hpp>
33 : #include <com/sun/star/drawing/LineStyle.hpp>
34 : #include <com/sun/star/beans/PropertyAttribute.hpp>
35 :
36 : #include <algorithm>
37 :
38 : using namespace ::com::sun::star;
39 :
40 : using ::com::sun::star::uno::Reference;
41 : using ::com::sun::star::uno::Sequence;
42 : using ::com::sun::star::beans::Property;
43 : using ::com::sun::star::uno::Any;
44 : using ::osl::MutexGuard;
45 :
46 : namespace
47 : {
48 :
49 : enum
50 : {
51 : PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE,
52 : PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION,
53 : PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
54 :
55 : };
56 :
57 4 : void lcl_AddPropertiesToVector(
58 : ::std::vector< Property > & rOutProperties )
59 : {
60 : rOutProperties.push_back(
61 : Property( CHART_UNONAME_CURVE_STYLE,
62 : PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE,
63 4 : ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)),
64 : beans::PropertyAttribute::BOUND
65 8 : | beans::PropertyAttribute::MAYBEDEFAULT ));
66 : rOutProperties.push_back(
67 : Property( CHART_UNONAME_CURVE_RESOLUTION,
68 : PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION,
69 4 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
70 : beans::PropertyAttribute::BOUND
71 8 : | beans::PropertyAttribute::MAYBEDEFAULT ));
72 : rOutProperties.push_back(
73 : Property( CHART_UNONAME_SPLINE_ORDER,
74 : PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER,
75 4 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
76 : beans::PropertyAttribute::BOUND
77 8 : | beans::PropertyAttribute::MAYBEDEFAULT ));
78 4 : }
79 :
80 : struct StaticScatterChartTypeTemplateDefaults_Initializer
81 : {
82 4 : ::chart::tPropertyValueMap* operator()()
83 : {
84 4 : static ::chart::tPropertyValueMap aStaticDefaults;
85 4 : lcl_AddDefaultsToMap( aStaticDefaults );
86 4 : return &aStaticDefaults;
87 : }
88 : private:
89 4 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
90 : {
91 4 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, chart2::CurveStyle_LINES );
92 4 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, 20 );
93 :
94 : // todo: check whether order 3 means polygons of order 3 or 2. (see
95 : // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
96 4 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, 3 );
97 4 : }
98 : };
99 :
100 : struct StaticScatterChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticScatterChartTypeTemplateDefaults_Initializer >
101 : {
102 : };
103 :
104 : struct StaticScatterChartTypeTemplateInfoHelper_Initializer
105 : {
106 4 : ::cppu::OPropertyArrayHelper* operator()()
107 : {
108 4 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
109 4 : return &aPropHelper;
110 : }
111 :
112 : private:
113 4 : Sequence< Property > lcl_GetPropertySequence()
114 : {
115 4 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
116 4 : lcl_AddPropertiesToVector( aProperties );
117 :
118 : ::std::sort( aProperties.begin(), aProperties.end(),
119 4 : ::chart::PropertyNameLess() );
120 :
121 4 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
122 : }
123 :
124 : };
125 :
126 : struct StaticScatterChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticScatterChartTypeTemplateInfoHelper_Initializer >
127 : {
128 : };
129 :
130 : struct StaticScatterChartTypeTemplateInfo_Initializer
131 : {
132 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
133 : {
134 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
135 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticScatterChartTypeTemplateInfoHelper::get() ) );
136 0 : return &xPropertySetInfo;
137 : }
138 : };
139 :
140 : struct StaticScatterChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticScatterChartTypeTemplateInfo_Initializer >
141 : {
142 : };
143 :
144 : } // anonymous namespace
145 :
146 : namespace chart
147 : {
148 :
149 2884 : ScatterChartTypeTemplate::ScatterChartTypeTemplate(
150 : Reference<
151 : uno::XComponentContext > const & xContext,
152 : const OUString & rServiceName,
153 : bool bSymbols,
154 : bool bHasLines /* = true */,
155 : sal_Int32 nDim /* = 2 */ ) :
156 : ChartTypeTemplate( xContext, rServiceName ),
157 : ::property::OPropertySet( m_aMutex ),
158 : m_bHasSymbols( bSymbols ),
159 : m_bHasLines( bHasLines ),
160 2884 : m_nDim( nDim )
161 : {
162 2884 : if( nDim == 3 )
163 0 : m_bHasSymbols = false;
164 2884 : }
165 :
166 5768 : ScatterChartTypeTemplate::~ScatterChartTypeTemplate()
167 5768 : {}
168 :
169 : // ____ OPropertySet ____
170 9144 : uno::Any ScatterChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
171 : throw(beans::UnknownPropertyException)
172 : {
173 9144 : const tPropertyValueMap& rStaticDefaults = *StaticScatterChartTypeTemplateDefaults::get();
174 9144 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
175 9144 : if( aFound == rStaticDefaults.end() )
176 0 : return uno::Any();
177 9144 : return (*aFound).second;
178 : }
179 :
180 8859 : ::cppu::IPropertyArrayHelper & SAL_CALL ScatterChartTypeTemplate::getInfoHelper()
181 : {
182 8859 : return *StaticScatterChartTypeTemplateInfoHelper::get();
183 : }
184 :
185 : // ____ XPropertySet ____
186 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL ScatterChartTypeTemplate::getPropertySetInfo()
187 : throw (uno::RuntimeException, std::exception)
188 : {
189 0 : return *StaticScatterChartTypeTemplateInfo::get();
190 : }
191 :
192 2982 : sal_Int32 ScatterChartTypeTemplate::getDimension() const
193 : {
194 2982 : return m_nDim;
195 : }
196 :
197 340 : StackMode ScatterChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
198 : {
199 340 : if( m_nDim == 3 )
200 0 : return StackMode_Z_STACKED;
201 340 : return StackMode_NONE;
202 : }
203 :
204 29 : void SAL_CALL ScatterChartTypeTemplate::applyStyle(
205 : const Reference< chart2::XDataSeries >& xSeries,
206 : ::sal_Int32 nChartTypeIndex,
207 : ::sal_Int32 nSeriesIndex,
208 : ::sal_Int32 nSeriesCount )
209 : throw (uno::RuntimeException, std::exception)
210 : {
211 29 : ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
212 :
213 : try
214 : {
215 29 : Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
216 :
217 29 : DataSeriesHelper::switchSymbolsOnOrOff( xProp, m_bHasSymbols, nSeriesIndex );
218 29 : DataSeriesHelper::switchLinesOnOrOff( xProp, m_bHasLines );
219 29 : DataSeriesHelper::makeLinesThickOrThin( xProp, m_nDim==2 );
220 29 : if( m_nDim==3 )
221 0 : DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "BorderStyle", uno::makeAny( drawing::LineStyle_NONE ) );
222 : }
223 0 : catch( const uno::Exception & ex )
224 : {
225 : ASSERT_EXCEPTION( ex );
226 : }
227 29 : }
228 :
229 : // ____ XChartTypeTemplate ____
230 20 : sal_Bool SAL_CALL ScatterChartTypeTemplate::supportsCategories()
231 : throw (uno::RuntimeException, std::exception)
232 : {
233 20 : return sal_False;
234 : }
235 :
236 2864 : sal_Bool SAL_CALL ScatterChartTypeTemplate::matchesTemplate(
237 : const Reference< chart2::XDiagram >& xDiagram,
238 : sal_Bool bAdaptProperties )
239 : throw (uno::RuntimeException, std::exception)
240 : {
241 2864 : sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
242 :
243 : // check symbol-style and line-style
244 : // for a template with symbols (or with lines) it is ok, if there is at least one series
245 : // with symbols (or with lines)
246 2864 : if( bResult )
247 : {
248 248 : bool bSymbolFound = false;
249 248 : bool bLineFound = false;
250 :
251 : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
252 248 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
253 :
254 1332 : for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt =
255 1136 : aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt )
256 : {
257 : try
258 : {
259 274 : chart2::Symbol aSymbProp;
260 : drawing::LineStyle eLineStyle;
261 470 : Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY_THROW );
262 :
263 1096 : bool bCurrentHasSymbol = (xProp->getPropertyValue( "Symbol") >>= aSymbProp) &&
264 548 : (aSymbProp.Style != chart2::SymbolStyle_NONE);
265 :
266 274 : if( bCurrentHasSymbol )
267 257 : bSymbolFound = true;
268 :
269 274 : if( bCurrentHasSymbol && (!m_bHasSymbols) )
270 : {
271 78 : bResult = false;
272 78 : break;
273 : }
274 :
275 784 : bool bCurrentHasLine = (xProp->getPropertyValue( "LineStyle") >>= eLineStyle) &&
276 392 : ( eLineStyle != drawing::LineStyle_NONE );
277 :
278 196 : if( bCurrentHasLine )
279 46 : bLineFound = true;
280 :
281 196 : if( bCurrentHasLine && (!m_bHasLines) )
282 : {
283 0 : bResult = false;
284 0 : break;
285 196 : }
286 : }
287 0 : catch( const uno::Exception & ex )
288 : {
289 : ASSERT_EXCEPTION( ex );
290 : }
291 : }
292 :
293 248 : if(bResult)
294 : {
295 170 : if( !bLineFound && m_bHasLines && bSymbolFound )
296 75 : bResult = false;
297 95 : else if( !bSymbolFound && m_bHasSymbols && bLineFound )
298 0 : bResult = false;
299 95 : else if( !bLineFound && !bSymbolFound )
300 0 : return m_bHasLines && m_bHasSymbols;
301 248 : }
302 : }
303 :
304 : // adapt curve style, spline order and resolution
305 2864 : if( bResult && bAdaptProperties )
306 : {
307 : try
308 : {
309 : uno::Reference< beans::XPropertySet > xChartTypeProp(
310 : DiagramHelper::getChartTypeByIndex( xDiagram, 0 ),
311 95 : uno::UNO_QUERY_THROW );
312 95 : setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, xChartTypeProp->getPropertyValue(CHART_UNONAME_CURVE_STYLE) );
313 95 : setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, xChartTypeProp->getPropertyValue(CHART_UNONAME_CURVE_RESOLUTION) );
314 95 : setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, xChartTypeProp->getPropertyValue(CHART_UNONAME_SPLINE_ORDER) );
315 : }
316 0 : catch( const uno::Exception & ex )
317 : {
318 : ASSERT_EXCEPTION( ex );
319 : }
320 : }
321 :
322 2864 : return bResult;
323 : }
324 :
325 49 : Reference< chart2::XChartType > ScatterChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
326 : {
327 49 : Reference< chart2::XChartType > xResult;
328 :
329 : try
330 : {
331 : Reference< lang::XMultiServiceFactory > xFact(
332 49 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
333 49 : xResult.set( xFact->createInstance(
334 49 : CHART2_SERVICE_NAME_CHARTTYPE_SCATTER ), uno::UNO_QUERY_THROW );
335 :
336 98 : Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY );
337 49 : if( xCTProp.is())
338 : {
339 49 : xCTProp->setPropertyValue(
340 49 : CHART_UNONAME_CURVE_STYLE, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE ));
341 49 : xCTProp->setPropertyValue(
342 49 : CHART_UNONAME_CURVE_RESOLUTION, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION ));
343 49 : xCTProp->setPropertyValue(
344 49 : CHART_UNONAME_SPLINE_ORDER, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER ));
345 49 : }
346 : }
347 0 : catch( const uno::Exception & ex )
348 : {
349 : ASSERT_EXCEPTION( ex );
350 : }
351 :
352 49 : return xResult;
353 : }
354 :
355 2904 : Reference< chart2::XChartType > SAL_CALL ScatterChartTypeTemplate::getChartTypeForNewSeries(
356 : const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
357 : throw (uno::RuntimeException, std::exception)
358 : {
359 2904 : Reference< chart2::XChartType > xResult;
360 :
361 : try
362 : {
363 : Reference< lang::XMultiServiceFactory > xFact(
364 2904 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
365 2904 : xResult.set( xFact->createInstance(
366 2904 : CHART2_SERVICE_NAME_CHARTTYPE_SCATTER ), uno::UNO_QUERY_THROW );
367 :
368 2904 : ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
369 :
370 5808 : Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY );
371 2904 : if( xCTProp.is())
372 : {
373 2904 : xCTProp->setPropertyValue(
374 2904 : CHART_UNONAME_CURVE_STYLE, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE ));
375 2904 : xCTProp->setPropertyValue(
376 2904 : CHART_UNONAME_CURVE_RESOLUTION, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION ));
377 2904 : xCTProp->setPropertyValue(
378 2904 : CHART_UNONAME_SPLINE_ORDER, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER ));
379 2904 : }
380 : }
381 0 : catch( const uno::Exception & ex )
382 : {
383 : ASSERT_EXCEPTION( ex );
384 : }
385 :
386 2904 : return xResult;
387 : }
388 :
389 20 : Reference< chart2::XDataInterpreter > SAL_CALL ScatterChartTypeTemplate::getDataInterpreter()
390 : throw (uno::RuntimeException, std::exception)
391 : {
392 20 : if( ! m_xDataInterpreter.is())
393 20 : m_xDataInterpreter.set( new XYDataInterpreter( GetComponentContext()) );
394 :
395 20 : return m_xDataInterpreter;
396 : }
397 :
398 23262 : IMPLEMENT_FORWARD_XINTERFACE2( ScatterChartTypeTemplate, ChartTypeTemplate, OPropertySet )
399 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScatterChartTypeTemplate, ChartTypeTemplate, OPropertySet )
400 :
401 : } // namespace chart
402 :
403 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|