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 "ScatterChartType.hxx"
21 #include "PropertyHelper.hxx"
23 #include "servicenames_charttypes.hxx"
24 #include "ContainerHelper.hxx"
25 #include "CartesianCoordinateSystem.hxx"
26 #include "AxisHelper.hxx"
27 #include "AxisIndexDefines.hxx"
28 #include <unonames.hxx>
29 #include <cppuhelper/supportsservice.hxx>
31 #include <com/sun/star/beans/PropertyAttribute.hpp>
32 #include <com/sun/star/chart2/AxisType.hpp>
33 #include <com/sun/star/chart2/CurveStyle.hpp>
35 using namespace ::com::sun::star
;
37 using ::com::sun::star::beans::Property
;
38 using ::com::sun::star::uno::Sequence
;
39 using ::com::sun::star::uno::Reference
;
40 using ::com::sun::star::uno::Any
;
41 using ::osl::MutexGuard
;
48 PROP_SCATTERCHARTTYPE_CURVE_STYLE
,
49 PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION
,
50 PROP_SCATTERCHARTTYPE_SPLINE_ORDER
53 void lcl_AddPropertiesToVector(
54 ::std::vector
< Property
> & rOutProperties
)
56 rOutProperties
.push_back(
57 Property( CHART_UNONAME_CURVE_STYLE
,
58 PROP_SCATTERCHARTTYPE_CURVE_STYLE
,
59 cppu::UnoType
<chart2::CurveStyle
>::get(),
60 beans::PropertyAttribute::BOUND
61 | beans::PropertyAttribute::MAYBEDEFAULT
));
63 rOutProperties
.push_back(
64 Property( CHART_UNONAME_CURVE_RESOLUTION
,
65 PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION
,
66 cppu::UnoType
<sal_Int32
>::get(),
67 beans::PropertyAttribute::BOUND
68 | beans::PropertyAttribute::MAYBEDEFAULT
));
69 rOutProperties
.push_back(
70 Property( CHART_UNONAME_SPLINE_ORDER
,
71 PROP_SCATTERCHARTTYPE_SPLINE_ORDER
,
72 cppu::UnoType
<sal_Int32
>::get(),
73 beans::PropertyAttribute::BOUND
74 | beans::PropertyAttribute::MAYBEDEFAULT
));
77 struct StaticScatterChartTypeDefaults_Initializer
79 ::chart::tPropertyValueMap
* operator()()
81 static ::chart::tPropertyValueMap aStaticDefaults
;
82 lcl_AddDefaultsToMap( aStaticDefaults
);
83 return &aStaticDefaults
;
86 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
88 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_SCATTERCHARTTYPE_CURVE_STYLE
, chart2::CurveStyle_LINES
);
89 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION
, 20 );
91 // todo: check whether order 3 means polygons of order 3 or 2. (see
92 // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
93 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_SCATTERCHARTTYPE_SPLINE_ORDER
, 3 );
97 struct StaticScatterChartTypeDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticScatterChartTypeDefaults_Initializer
>
101 struct StaticScatterChartTypeInfoHelper_Initializer
103 ::cppu::OPropertyArrayHelper
* operator()()
105 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
110 static Sequence
< Property
> lcl_GetPropertySequence()
112 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
113 lcl_AddPropertiesToVector( aProperties
);
115 ::std::sort( aProperties
.begin(), aProperties
.end(),
116 ::chart::PropertyNameLess() );
118 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
123 struct StaticScatterChartTypeInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticScatterChartTypeInfoHelper_Initializer
>
127 struct StaticScatterChartTypeInfo_Initializer
129 uno::Reference
< beans::XPropertySetInfo
>* operator()()
131 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
132 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticScatterChartTypeInfoHelper::get() ) );
133 return &xPropertySetInfo
;
137 struct StaticScatterChartTypeInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticScatterChartTypeInfo_Initializer
>
141 } // anonymous namespace
146 ScatterChartType::ScatterChartType(
147 const uno::Reference
< uno::XComponentContext
> & xContext
,
148 chart2::CurveStyle eCurveStyle
/* chart2::CurveStyle_LINES */ ,
149 sal_Int32 nResolution
/* = 20 */,
150 sal_Int32 nOrder
/* = 3 */ ) :
151 ChartType( xContext
)
153 if( eCurveStyle
!= chart2::CurveStyle_LINES
)
154 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_STYLE
,
155 uno::makeAny( eCurveStyle
));
156 if( nResolution
!= 20 )
157 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION
,
158 uno::makeAny( nResolution
));
160 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_SPLINE_ORDER
,
161 uno::makeAny( nOrder
));
164 ScatterChartType::ScatterChartType( const ScatterChartType
& rOther
) :
169 ScatterChartType::~ScatterChartType()
172 // ____ XCloneable ____
173 uno::Reference
< util::XCloneable
> SAL_CALL
ScatterChartType::createClone()
174 throw (uno::RuntimeException
, std::exception
)
176 return uno::Reference
< util::XCloneable
>( new ScatterChartType( *this ));
179 // ____ XChartType ____
180 Reference
< chart2::XCoordinateSystem
> SAL_CALL
181 ScatterChartType::createCoordinateSystem( ::sal_Int32 DimensionCount
)
182 throw (lang::IllegalArgumentException
,
183 uno::RuntimeException
, std::exception
)
185 Reference
< chart2::XCoordinateSystem
> xResult(
186 new CartesianCoordinateSystem(
187 GetComponentContext(), DimensionCount
, /* bSwapXAndYAxis */ false ));
189 for( sal_Int32 i
=0; i
<DimensionCount
; ++i
)
191 Reference
< chart2::XAxis
> xAxis( xResult
->getAxisByDimension( i
, MAIN_AXIS_INDEX
) );
194 OSL_FAIL("a created coordinate system should have an axis for each dimension");
198 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
199 aScaleData
.Orientation
= chart2::AxisOrientation_MATHEMATICAL
;
200 aScaleData
.Scaling
= AxisHelper::createLinearScaling();
203 aScaleData
.AxisType
= chart2::AxisType::SERIES
;
205 aScaleData
.AxisType
= chart2::AxisType::REALNUMBER
;
207 xAxis
->setScaleData( aScaleData
);
213 OUString SAL_CALL
ScatterChartType::getChartType()
214 throw (uno::RuntimeException
, std::exception
)
216 return OUString(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER
);
219 uno::Sequence
< OUString
> SAL_CALL
ScatterChartType::getSupportedMandatoryRoles()
220 throw (uno::RuntimeException
, std::exception
)
222 uno::Sequence
< OUString
> aMandRolesSeq(3);
223 aMandRolesSeq
[0] = "label";
224 aMandRolesSeq
[1] = "values-x";
225 aMandRolesSeq
[2] = "values-y";
226 return aMandRolesSeq
;
229 // ____ OPropertySet ____
230 uno::Any
ScatterChartType::GetDefaultValue( sal_Int32 nHandle
) const
231 throw(beans::UnknownPropertyException
)
233 const tPropertyValueMap
& rStaticDefaults
= *StaticScatterChartTypeDefaults::get();
234 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
235 if( aFound
== rStaticDefaults
.end() )
237 return (*aFound
).second
;
240 // ____ OPropertySet ____
241 ::cppu::IPropertyArrayHelper
& SAL_CALL
ScatterChartType::getInfoHelper()
243 return *StaticScatterChartTypeInfoHelper::get();
246 // ____ XPropertySet ____
247 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
ScatterChartType::getPropertySetInfo()
248 throw (uno::RuntimeException
, std::exception
)
250 return *StaticScatterChartTypeInfo::get();
253 uno::Sequence
< OUString
> ScatterChartType::getSupportedServiceNames_Static()
255 uno::Sequence
< OUString
> aServices( 3 );
256 aServices
[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_SCATTER
;
257 aServices
[ 1 ] = "com.sun.star.chart2.ChartType";
258 aServices
[ 2 ] = "com.sun.star.beans.PropertySet";
262 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
263 OUString SAL_CALL
ScatterChartType::getImplementationName()
264 throw( css::uno::RuntimeException
, std::exception
)
266 return getImplementationName_Static();
269 OUString
ScatterChartType::getImplementationName_Static()
271 return OUString("com.sun.star.comp.chart.ScatterChartType");
274 sal_Bool SAL_CALL
ScatterChartType::supportsService( const OUString
& rServiceName
)
275 throw( css::uno::RuntimeException
, std::exception
)
277 return cppu::supportsService(this, rServiceName
);
280 css::uno::Sequence
< OUString
> SAL_CALL
ScatterChartType::getSupportedServiceNames()
281 throw( css::uno::RuntimeException
, std::exception
)
283 return getSupportedServiceNames_Static();
288 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
289 com_sun_star_comp_chart_ScatterChartType_get_implementation(css::uno::XComponentContext
*context
,
290 css::uno::Sequence
<css::uno::Any
> const &)
292 return cppu::acquire(new ::chart::ScatterChartType(context
));
295 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */