1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "ScatterChartType.hxx"
27 #include "PropertyHelper.hxx"
28 #include "macros.hxx"
29 #include "servicenames_charttypes.hxx"
30 #include "ContainerHelper.hxx"
31 #include "CartesianCoordinateSystem.hxx"
32 #include "AxisHelper.hxx"
33 #include "AxisIndexDefines.hxx"
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/chart2/AxisType.hpp>
36 #include <com/sun/star/chart2/CurveStyle.hpp>
37 
38 using namespace ::com::sun::star;
39 
40 using ::rtl::OUString;
41 using ::com::sun::star::beans::Property;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::Any;
45 using ::osl::MutexGuard;
46 
47 namespace
48 {
49 
50 enum
51 {
52     PROP_SCATTERCHARTTYPE_CURVE_STYLE,
53     PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
54     PROP_SCATTERCHARTTYPE_SPLINE_ORDER
55 };
56 
lcl_AddPropertiesToVector(::std::vector<Property> & rOutProperties)57 void lcl_AddPropertiesToVector(
58     ::std::vector< Property > & rOutProperties )
59 {
60     rOutProperties.push_back(
61         Property( C2U( "CurveStyle" ),
62                   PROP_SCATTERCHARTTYPE_CURVE_STYLE,
63                   ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)),
64                   beans::PropertyAttribute::BOUND
65                   | beans::PropertyAttribute::MAYBEDEFAULT ));
66 
67     rOutProperties.push_back(
68         Property( C2U( "CurveResolution" ),
69                   PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
70                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
71                   beans::PropertyAttribute::BOUND
72                   | beans::PropertyAttribute::MAYBEDEFAULT ));
73     rOutProperties.push_back(
74         Property( C2U( "SplineOrder" ),
75                   PROP_SCATTERCHARTTYPE_SPLINE_ORDER,
76                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
77                   beans::PropertyAttribute::BOUND
78                   | beans::PropertyAttribute::MAYBEDEFAULT ));
79 }
80 
81 struct StaticScatterChartTypeDefaults_Initializer
82 {
operator ()__anonbeb6d15f0111::StaticScatterChartTypeDefaults_Initializer83     ::chart::tPropertyValueMap* operator()()
84     {
85         static ::chart::tPropertyValueMap aStaticDefaults;
86         lcl_AddDefaultsToMap( aStaticDefaults );
87         return &aStaticDefaults;
88     }
89 private:
lcl_AddDefaultsToMap__anonbeb6d15f0111::StaticScatterChartTypeDefaults_Initializer90     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
91     {
92         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCATTERCHARTTYPE_CURVE_STYLE, chart2::CurveStyle_LINES );
93         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION, 20 );
94 
95         // todo: check whether order 3 means polygons of order 3 or 2. (see
96         // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
97         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_SPLINE_ORDER, 3 );
98     }
99 };
100 
101 struct StaticScatterChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticScatterChartTypeDefaults_Initializer >
102 {
103 };
104 
105 struct StaticScatterChartTypeInfoHelper_Initializer
106 {
operator ()__anonbeb6d15f0111::StaticScatterChartTypeInfoHelper_Initializer107     ::cppu::OPropertyArrayHelper* operator()()
108     {
109         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
110         return &aPropHelper;
111     }
112 
113 private:
lcl_GetPropertySequence__anonbeb6d15f0111::StaticScatterChartTypeInfoHelper_Initializer114     Sequence< Property > lcl_GetPropertySequence()
115     {
116         ::std::vector< ::com::sun::star::beans::Property > aProperties;
117         lcl_AddPropertiesToVector( aProperties );
118 
119         ::std::sort( aProperties.begin(), aProperties.end(),
120                      ::chart::PropertyNameLess() );
121 
122         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
123     }
124 
125 };
126 
127 struct StaticScatterChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticScatterChartTypeInfoHelper_Initializer >
128 {
129 };
130 
131 struct StaticScatterChartTypeInfo_Initializer
132 {
operator ()__anonbeb6d15f0111::StaticScatterChartTypeInfo_Initializer133     uno::Reference< beans::XPropertySetInfo >* operator()()
134     {
135         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
136             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticScatterChartTypeInfoHelper::get() ) );
137         return &xPropertySetInfo;
138     }
139 };
140 
141 struct StaticScatterChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticScatterChartTypeInfo_Initializer >
142 {
143 };
144 
145 } // anonymous namespace
146 
147 namespace chart
148 {
149 
ScatterChartType(const uno::Reference<uno::XComponentContext> & xContext,chart2::CurveStyle eCurveStyle,sal_Int32 nResolution,sal_Int32 nOrder)150 ScatterChartType::ScatterChartType(
151     const uno::Reference< uno::XComponentContext > & xContext,
152     chart2::CurveStyle eCurveStyle /* chart2::CurveStyle_LINES */ ,
153     sal_Int32 nResolution /* = 20 */,
154     sal_Int32 nOrder /* = 3 */ ) :
155         ChartType( xContext )
156 {
157     if( eCurveStyle != chart2::CurveStyle_LINES )
158         setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_STYLE,
159                                           uno::makeAny( eCurveStyle ));
160     if( nResolution != 20 )
161         setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
162                                           uno::makeAny( nResolution ));
163     if( nOrder != 3 )
164         setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_SPLINE_ORDER,
165                                           uno::makeAny( nOrder ));
166 }
167 
ScatterChartType(const ScatterChartType & rOther)168 ScatterChartType::ScatterChartType( const ScatterChartType & rOther ) :
169         ChartType( rOther )
170 {
171 }
172 
~ScatterChartType()173 ScatterChartType::~ScatterChartType()
174 {}
175 
176 // ____ XCloneable ____
createClone()177 uno::Reference< util::XCloneable > SAL_CALL ScatterChartType::createClone()
178     throw (uno::RuntimeException)
179 {
180     return uno::Reference< util::XCloneable >( new ScatterChartType( *this ));
181 }
182 
183 // ____ XChartType ____
184 // ____ XChartType ____
185 Reference< chart2::XCoordinateSystem > SAL_CALL
createCoordinateSystem(::sal_Int32 DimensionCount)186     ScatterChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
187     throw (lang::IllegalArgumentException,
188            uno::RuntimeException)
189 {
190     Reference< chart2::XCoordinateSystem > xResult(
191         new CartesianCoordinateSystem(
192             GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False ));
193 
194     for( sal_Int32 i=0; i<DimensionCount; ++i )
195     {
196         Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
197         if( !xAxis.is() )
198         {
199             OSL_ENSURE(false,"a created coordinate system should have an axis for each dimension");
200             continue;
201         }
202 
203         chart2::ScaleData aScaleData = xAxis->getScaleData();
204         aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
205         aScaleData.Scaling = AxisHelper::createLinearScaling();
206 
207         if( i == 2  )
208             aScaleData.AxisType = chart2::AxisType::SERIES;
209         else
210             aScaleData.AxisType = chart2::AxisType::REALNUMBER;
211 
212         xAxis->setScaleData( aScaleData );
213     }
214 
215     return xResult;
216 }
217 
getChartType()218 ::rtl::OUString SAL_CALL ScatterChartType::getChartType()
219     throw (uno::RuntimeException)
220 {
221     return CHART2_SERVICE_NAME_CHARTTYPE_SCATTER;
222 }
223 
getSupportedMandatoryRoles()224 uno::Sequence< ::rtl::OUString > SAL_CALL ScatterChartType::getSupportedMandatoryRoles()
225     throw (uno::RuntimeException)
226 {
227     static uno::Sequence< ::rtl::OUString > aMandRolesSeq;
228 
229     if( aMandRolesSeq.getLength() == 0 )
230     {
231         aMandRolesSeq.realloc( 3 );
232         aMandRolesSeq[0] = C2U( "label" );
233         aMandRolesSeq[1] = C2U( "values-x" );
234         aMandRolesSeq[2] = C2U( "values-y" );
235     }
236 
237     return aMandRolesSeq;
238 }
239 
getSupportedOptionalRoles()240 uno::Sequence< ::rtl::OUString > SAL_CALL ScatterChartType::getSupportedOptionalRoles()
241     throw (uno::RuntimeException)
242 {
243     static uno::Sequence< ::rtl::OUString > aOptRolesSeq;
244 
245 //     if( aOptRolesSeq.getLength() == 0 )
246 //     {
247 //         aOptRolesSeq.realloc( 2 );
248 //         aOptRolesSeq[0] = C2U( "error-bars-x" );
249 //         aOptRolesSeq[1] = C2U( "error-bars-y" );
250 //     }
251 
252     return aOptRolesSeq;
253 }
254 
255 
256 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const257 uno::Any ScatterChartType::GetDefaultValue( sal_Int32 nHandle ) const
258     throw(beans::UnknownPropertyException)
259 {
260     const tPropertyValueMap& rStaticDefaults = *StaticScatterChartTypeDefaults::get();
261     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
262     if( aFound == rStaticDefaults.end() )
263         return uno::Any();
264     return (*aFound).second;
265 }
266 
267 // ____ OPropertySet ____
getInfoHelper()268 ::cppu::IPropertyArrayHelper & SAL_CALL ScatterChartType::getInfoHelper()
269 {
270     return *StaticScatterChartTypeInfoHelper::get();
271 }
272 
273 // ____ XPropertySet ____
getPropertySetInfo()274 uno::Reference< beans::XPropertySetInfo > SAL_CALL ScatterChartType::getPropertySetInfo()
275     throw (uno::RuntimeException)
276 {
277     return *StaticScatterChartTypeInfo::get();
278 }
279 
getSupportedServiceNames_Static()280 uno::Sequence< ::rtl::OUString > ScatterChartType::getSupportedServiceNames_Static()
281 {
282     uno::Sequence< ::rtl::OUString > aServices( 3 );
283     aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_SCATTER;
284     aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
285     aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
286     return aServices;
287 }
288 
289 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
290 APPHELPER_XSERVICEINFO_IMPL( ScatterChartType,
291                              C2U( "com.sun.star.comp.chart.ScatterChartType" ));
292 
293 } //  namespace chart
294