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