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 "ScatterChartType.hxx"
21 : #include "PropertyHelper.hxx"
22 : #include "macros.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>
30 :
31 : #include <com/sun/star/beans/PropertyAttribute.hpp>
32 : #include <com/sun/star/chart2/AxisType.hpp>
33 : #include <com/sun/star/chart2/CurveStyle.hpp>
34 :
35 : using namespace ::com::sun::star;
36 :
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;
42 :
43 : namespace
44 : {
45 :
46 : enum
47 : {
48 : PROP_SCATTERCHARTTYPE_CURVE_STYLE,
49 : PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
50 : PROP_SCATTERCHARTTYPE_SPLINE_ORDER
51 : };
52 :
53 5 : void lcl_AddPropertiesToVector(
54 : ::std::vector< Property > & rOutProperties )
55 : {
56 : rOutProperties.push_back(
57 : Property( CHART_UNONAME_CURVE_STYLE,
58 : PROP_SCATTERCHARTTYPE_CURVE_STYLE,
59 5 : cppu::UnoType<chart2::CurveStyle>::get(),
60 : beans::PropertyAttribute::BOUND
61 10 : | beans::PropertyAttribute::MAYBEDEFAULT ));
62 :
63 : rOutProperties.push_back(
64 : Property( CHART_UNONAME_CURVE_RESOLUTION,
65 : PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
66 5 : cppu::UnoType<sal_Int32>::get(),
67 : beans::PropertyAttribute::BOUND
68 10 : | beans::PropertyAttribute::MAYBEDEFAULT ));
69 : rOutProperties.push_back(
70 : Property( CHART_UNONAME_SPLINE_ORDER,
71 : PROP_SCATTERCHARTTYPE_SPLINE_ORDER,
72 5 : cppu::UnoType<sal_Int32>::get(),
73 : beans::PropertyAttribute::BOUND
74 10 : | beans::PropertyAttribute::MAYBEDEFAULT ));
75 5 : }
76 :
77 : struct StaticScatterChartTypeDefaults_Initializer
78 : {
79 5 : ::chart::tPropertyValueMap* operator()()
80 : {
81 5 : static ::chart::tPropertyValueMap aStaticDefaults;
82 5 : lcl_AddDefaultsToMap( aStaticDefaults );
83 5 : return &aStaticDefaults;
84 : }
85 : private:
86 5 : static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
87 : {
88 5 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCATTERCHARTTYPE_CURVE_STYLE, chart2::CurveStyle_LINES );
89 5 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION, 20 );
90 :
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 5 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_SPLINE_ORDER, 3 );
94 5 : }
95 : };
96 :
97 : struct StaticScatterChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticScatterChartTypeDefaults_Initializer >
98 : {
99 : };
100 :
101 : struct StaticScatterChartTypeInfoHelper_Initializer
102 : {
103 5 : ::cppu::OPropertyArrayHelper* operator()()
104 : {
105 5 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
106 5 : return &aPropHelper;
107 : }
108 :
109 : private:
110 5 : static Sequence< Property > lcl_GetPropertySequence()
111 : {
112 5 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
113 5 : lcl_AddPropertiesToVector( aProperties );
114 :
115 : ::std::sort( aProperties.begin(), aProperties.end(),
116 5 : ::chart::PropertyNameLess() );
117 :
118 5 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
119 : }
120 :
121 : };
122 :
123 : struct StaticScatterChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticScatterChartTypeInfoHelper_Initializer >
124 : {
125 : };
126 :
127 : struct StaticScatterChartTypeInfo_Initializer
128 : {
129 2 : uno::Reference< beans::XPropertySetInfo >* operator()()
130 : {
131 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
132 2 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticScatterChartTypeInfoHelper::get() ) );
133 2 : return &xPropertySetInfo;
134 : }
135 : };
136 :
137 : struct StaticScatterChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticScatterChartTypeInfo_Initializer >
138 : {
139 : };
140 :
141 : } // anonymous namespace
142 :
143 : namespace chart
144 : {
145 :
146 3722 : 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 3722 : ChartType( xContext )
152 : {
153 3722 : if( eCurveStyle != chart2::CurveStyle_LINES )
154 : setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_STYLE,
155 0 : uno::makeAny( eCurveStyle ));
156 3722 : if( nResolution != 20 )
157 : setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
158 0 : uno::makeAny( nResolution ));
159 3722 : if( nOrder != 3 )
160 : setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_SPLINE_ORDER,
161 0 : uno::makeAny( nOrder ));
162 3722 : }
163 :
164 0 : ScatterChartType::ScatterChartType( const ScatterChartType & rOther ) :
165 0 : ChartType( rOther )
166 : {
167 0 : }
168 :
169 7444 : ScatterChartType::~ScatterChartType()
170 7444 : {}
171 :
172 : // ____ XCloneable ____
173 0 : uno::Reference< util::XCloneable > SAL_CALL ScatterChartType::createClone()
174 : throw (uno::RuntimeException, std::exception)
175 : {
176 0 : return uno::Reference< util::XCloneable >( new ScatterChartType( *this ));
177 : }
178 :
179 : // ____ XChartType ____
180 : Reference< chart2::XCoordinateSystem > SAL_CALL
181 29 : ScatterChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
182 : throw (lang::IllegalArgumentException,
183 : uno::RuntimeException, std::exception)
184 : {
185 : Reference< chart2::XCoordinateSystem > xResult(
186 : new CartesianCoordinateSystem(
187 29 : GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ false ));
188 :
189 87 : for( sal_Int32 i=0; i<DimensionCount; ++i )
190 : {
191 58 : Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
192 58 : if( !xAxis.is() )
193 : {
194 : OSL_FAIL("a created coordinate system should have an axis for each dimension");
195 0 : continue;
196 : }
197 :
198 116 : chart2::ScaleData aScaleData = xAxis->getScaleData();
199 58 : aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
200 58 : aScaleData.Scaling = AxisHelper::createLinearScaling();
201 :
202 58 : if( i == 2 )
203 0 : aScaleData.AxisType = chart2::AxisType::SERIES;
204 : else
205 58 : aScaleData.AxisType = chart2::AxisType::REALNUMBER;
206 :
207 58 : xAxis->setScaleData( aScaleData );
208 58 : }
209 :
210 29 : return xResult;
211 : }
212 :
213 18804 : OUString SAL_CALL ScatterChartType::getChartType()
214 : throw (uno::RuntimeException, std::exception)
215 : {
216 18804 : return OUString(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER);
217 : }
218 :
219 0 : uno::Sequence< OUString > SAL_CALL ScatterChartType::getSupportedMandatoryRoles()
220 : throw (uno::RuntimeException, std::exception)
221 : {
222 0 : uno::Sequence< OUString > aMandRolesSeq(3);
223 0 : aMandRolesSeq[0] = "label";
224 0 : aMandRolesSeq[1] = "values-x";
225 0 : aMandRolesSeq[2] = "values-y";
226 0 : return aMandRolesSeq;
227 : }
228 :
229 : // ____ OPropertySet ____
230 12130 : uno::Any ScatterChartType::GetDefaultValue( sal_Int32 nHandle ) const
231 : throw(beans::UnknownPropertyException)
232 : {
233 12130 : const tPropertyValueMap& rStaticDefaults = *StaticScatterChartTypeDefaults::get();
234 12130 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
235 12130 : if( aFound == rStaticDefaults.end() )
236 0 : return uno::Any();
237 12130 : return (*aFound).second;
238 : }
239 :
240 : // ____ OPropertySet ____
241 24654 : ::cppu::IPropertyArrayHelper & SAL_CALL ScatterChartType::getInfoHelper()
242 : {
243 24654 : return *StaticScatterChartTypeInfoHelper::get();
244 : }
245 :
246 : // ____ XPropertySet ____
247 24 : uno::Reference< beans::XPropertySetInfo > SAL_CALL ScatterChartType::getPropertySetInfo()
248 : throw (uno::RuntimeException, std::exception)
249 : {
250 24 : return *StaticScatterChartTypeInfo::get();
251 : }
252 :
253 1 : uno::Sequence< OUString > ScatterChartType::getSupportedServiceNames_Static()
254 : {
255 1 : uno::Sequence< OUString > aServices( 3 );
256 1 : aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_SCATTER;
257 1 : aServices[ 1 ] = "com.sun.star.chart2.ChartType";
258 1 : aServices[ 2 ] = "com.sun.star.beans.PropertySet";
259 1 : return aServices;
260 : }
261 :
262 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
263 1 : OUString SAL_CALL ScatterChartType::getImplementationName()
264 : throw( css::uno::RuntimeException, std::exception )
265 : {
266 1 : return getImplementationName_Static();
267 : }
268 :
269 1 : OUString ScatterChartType::getImplementationName_Static()
270 : {
271 1 : return OUString("com.sun.star.comp.chart.ScatterChartType");
272 : }
273 :
274 0 : sal_Bool SAL_CALL ScatterChartType::supportsService( const OUString& rServiceName )
275 : throw( css::uno::RuntimeException, std::exception )
276 : {
277 0 : return cppu::supportsService(this, rServiceName);
278 : }
279 :
280 1 : css::uno::Sequence< OUString > SAL_CALL ScatterChartType::getSupportedServiceNames()
281 : throw( css::uno::RuntimeException, std::exception )
282 : {
283 1 : return getSupportedServiceNames_Static();
284 : }
285 :
286 : } // namespace chart
287 :
288 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
289 3722 : com_sun_star_comp_chart_ScatterChartType_get_implementation(css::uno::XComponentContext *context,
290 : css::uno::Sequence<css::uno::Any> const &)
291 : {
292 3722 : return cppu::acquire(new ::chart::ScatterChartType(context));
293 : }
294 :
295 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|