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