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