1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "ScatterChartTypeTemplate.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>
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>
38 using namespace ::com::sun::star
;
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
;
51 PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE
,
52 PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION
,
53 PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
57 void lcl_AddPropertiesToVector(
58 ::std::vector
< Property
> & rOutProperties
)
60 rOutProperties
.push_back(
61 Property( CHART_UNONAME_CURVE_STYLE
,
62 PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE
,
63 cppu::UnoType
<chart2::CurveStyle
>::get(),
64 beans::PropertyAttribute::BOUND
65 | beans::PropertyAttribute::MAYBEDEFAULT
));
66 rOutProperties
.push_back(
67 Property( CHART_UNONAME_CURVE_RESOLUTION
,
68 PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION
,
69 cppu::UnoType
<sal_Int32
>::get(),
70 beans::PropertyAttribute::BOUND
71 | beans::PropertyAttribute::MAYBEDEFAULT
));
72 rOutProperties
.push_back(
73 Property( CHART_UNONAME_SPLINE_ORDER
,
74 PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
,
75 cppu::UnoType
<sal_Int32
>::get(),
76 beans::PropertyAttribute::BOUND
77 | beans::PropertyAttribute::MAYBEDEFAULT
));
80 struct StaticScatterChartTypeTemplateDefaults_Initializer
82 ::chart::tPropertyValueMap
* operator()()
84 static ::chart::tPropertyValueMap aStaticDefaults
;
85 lcl_AddDefaultsToMap( aStaticDefaults
);
86 return &aStaticDefaults
;
89 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
91 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE
, chart2::CurveStyle_LINES
);
92 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION
, 20 );
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 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
, 3 );
100 struct StaticScatterChartTypeTemplateDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticScatterChartTypeTemplateDefaults_Initializer
>
104 struct StaticScatterChartTypeTemplateInfoHelper_Initializer
106 ::cppu::OPropertyArrayHelper
* operator()()
108 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
113 static Sequence
< Property
> lcl_GetPropertySequence()
115 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
116 lcl_AddPropertiesToVector( aProperties
);
118 ::std::sort( aProperties
.begin(), aProperties
.end(),
119 ::chart::PropertyNameLess() );
121 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
126 struct StaticScatterChartTypeTemplateInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticScatterChartTypeTemplateInfoHelper_Initializer
>
130 struct StaticScatterChartTypeTemplateInfo_Initializer
132 uno::Reference
< beans::XPropertySetInfo
>* operator()()
134 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
135 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticScatterChartTypeTemplateInfoHelper::get() ) );
136 return &xPropertySetInfo
;
140 struct StaticScatterChartTypeTemplateInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticScatterChartTypeTemplateInfo_Initializer
>
144 } // anonymous namespace
149 ScatterChartTypeTemplate::ScatterChartTypeTemplate(
151 uno::XComponentContext
> const & xContext
,
152 const OUString
& rServiceName
,
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
),
163 m_bHasSymbols
= false;
166 ScatterChartTypeTemplate::~ScatterChartTypeTemplate()
169 // ____ OPropertySet ____
170 uno::Any
ScatterChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle
) const
171 throw(beans::UnknownPropertyException
)
173 const tPropertyValueMap
& rStaticDefaults
= *StaticScatterChartTypeTemplateDefaults::get();
174 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
175 if( aFound
== rStaticDefaults
.end() )
177 return (*aFound
).second
;
180 ::cppu::IPropertyArrayHelper
& SAL_CALL
ScatterChartTypeTemplate::getInfoHelper()
182 return *StaticScatterChartTypeTemplateInfoHelper::get();
185 // ____ XPropertySet ____
186 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
ScatterChartTypeTemplate::getPropertySetInfo()
187 throw (uno::RuntimeException
, std::exception
)
189 return *StaticScatterChartTypeTemplateInfo::get();
192 sal_Int32
ScatterChartTypeTemplate::getDimension() const
197 StackMode
ScatterChartTypeTemplate::getStackMode( sal_Int32
/* nChartTypeIndex */ ) const
200 return StackMode_Z_STACKED
;
201 return StackMode_NONE
;
204 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
)
211 ChartTypeTemplate::applyStyle( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
215 Reference
< beans::XPropertySet
> xProp( xSeries
, uno::UNO_QUERY_THROW
);
217 DataSeriesHelper::switchSymbolsOnOrOff( xProp
, m_bHasSymbols
, nSeriesIndex
);
218 DataSeriesHelper::switchLinesOnOrOff( xProp
, m_bHasLines
);
219 DataSeriesHelper::makeLinesThickOrThin( xProp
, m_nDim
==2 );
221 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries
, "BorderStyle", uno::makeAny( drawing::LineStyle_NONE
) );
223 catch( const uno::Exception
& ex
)
225 ASSERT_EXCEPTION( ex
);
229 // ____ XChartTypeTemplate ____
230 sal_Bool SAL_CALL
ScatterChartTypeTemplate::supportsCategories()
231 throw (uno::RuntimeException
, std::exception
)
236 sal_Bool SAL_CALL
ScatterChartTypeTemplate::matchesTemplate(
237 const Reference
< chart2::XDiagram
>& xDiagram
,
238 sal_Bool bAdaptProperties
)
239 throw (uno::RuntimeException
, std::exception
)
241 bool bResult
= ChartTypeTemplate::matchesTemplate( xDiagram
, bAdaptProperties
);
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)
248 bool bSymbolFound
= false;
249 bool bLineFound
= false;
251 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVec(
252 DiagramHelper::getDataSeriesFromDiagram( xDiagram
));
254 for( ::std::vector
< Reference
< chart2::XDataSeries
> >::const_iterator aIt
=
255 aSeriesVec
.begin(); aIt
!= aSeriesVec
.end(); ++aIt
)
259 chart2::Symbol aSymbProp
;
260 drawing::LineStyle eLineStyle
;
261 Reference
< beans::XPropertySet
> xProp( *aIt
, uno::UNO_QUERY_THROW
);
263 bool bCurrentHasSymbol
= (xProp
->getPropertyValue( "Symbol") >>= aSymbProp
) &&
264 (aSymbProp
.Style
!= chart2::SymbolStyle_NONE
);
266 if( bCurrentHasSymbol
)
269 if( bCurrentHasSymbol
&& (!m_bHasSymbols
) )
275 bool bCurrentHasLine
= (xProp
->getPropertyValue( "LineStyle") >>= eLineStyle
) &&
276 ( eLineStyle
!= drawing::LineStyle_NONE
);
278 if( bCurrentHasLine
)
281 if( bCurrentHasLine
&& (!m_bHasLines
) )
287 catch( const uno::Exception
& ex
)
289 ASSERT_EXCEPTION( ex
);
295 if( !bLineFound
&& m_bHasLines
&& bSymbolFound
)
297 else if( !bSymbolFound
&& m_bHasSymbols
&& bLineFound
)
299 else if( !bLineFound
&& !bSymbolFound
)
300 return m_bHasLines
&& m_bHasSymbols
;
304 // adapt curve style, spline order and resolution
305 if( bResult
&& bAdaptProperties
)
309 uno::Reference
< beans::XPropertySet
> xChartTypeProp(
310 DiagramHelper::getChartTypeByIndex( xDiagram
, 0 ),
311 uno::UNO_QUERY_THROW
);
312 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE
, xChartTypeProp
->getPropertyValue(CHART_UNONAME_CURVE_STYLE
) );
313 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION
, xChartTypeProp
->getPropertyValue(CHART_UNONAME_CURVE_RESOLUTION
) );
314 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
, xChartTypeProp
->getPropertyValue(CHART_UNONAME_SPLINE_ORDER
) );
316 catch( const uno::Exception
& ex
)
318 ASSERT_EXCEPTION( ex
);
325 Reference
< chart2::XChartType
> ScatterChartTypeTemplate::getChartTypeForIndex( sal_Int32
/*nChartTypeIndex*/ )
327 Reference
< chart2::XChartType
> xResult
;
331 Reference
< lang::XMultiServiceFactory
> xFact(
332 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
333 xResult
.set( xFact
->createInstance(
334 CHART2_SERVICE_NAME_CHARTTYPE_SCATTER
), uno::UNO_QUERY_THROW
);
336 Reference
< beans::XPropertySet
> xCTProp( xResult
, uno::UNO_QUERY
);
339 xCTProp
->setPropertyValue(
340 CHART_UNONAME_CURVE_STYLE
, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE
));
341 xCTProp
->setPropertyValue(
342 CHART_UNONAME_CURVE_RESOLUTION
, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION
));
343 xCTProp
->setPropertyValue(
344 CHART_UNONAME_SPLINE_ORDER
, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
));
347 catch( const uno::Exception
& ex
)
349 ASSERT_EXCEPTION( ex
);
355 Reference
< chart2::XChartType
> SAL_CALL
ScatterChartTypeTemplate::getChartTypeForNewSeries(
356 const uno::Sequence
< Reference
< chart2::XChartType
> >& aFormerlyUsedChartTypes
)
357 throw (uno::RuntimeException
, std::exception
)
359 Reference
< chart2::XChartType
> xResult
;
363 Reference
< lang::XMultiServiceFactory
> xFact(
364 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
365 xResult
.set( xFact
->createInstance(
366 CHART2_SERVICE_NAME_CHARTTYPE_SCATTER
), uno::UNO_QUERY_THROW
);
368 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes
, xResult
);
370 Reference
< beans::XPropertySet
> xCTProp( xResult
, uno::UNO_QUERY
);
373 xCTProp
->setPropertyValue(
374 CHART_UNONAME_CURVE_STYLE
, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE
));
375 xCTProp
->setPropertyValue(
376 CHART_UNONAME_CURVE_RESOLUTION
, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION
));
377 xCTProp
->setPropertyValue(
378 CHART_UNONAME_SPLINE_ORDER
, getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
));
381 catch( const uno::Exception
& ex
)
383 ASSERT_EXCEPTION( ex
);
389 Reference
< chart2::XDataInterpreter
> SAL_CALL
ScatterChartTypeTemplate::getDataInterpreter()
390 throw (uno::RuntimeException
, std::exception
)
392 if( ! m_xDataInterpreter
.is())
393 m_xDataInterpreter
.set( new XYDataInterpreter( GetComponentContext()) );
395 return m_xDataInterpreter
;
398 IMPLEMENT_FORWARD_XINTERFACE2( ScatterChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
399 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScatterChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
403 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */