merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / model / template / ScatterChartType.cxx
blob8c4ab0d18415efd4125b41a34824f4af6fe7df63
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "ScatterChartType.hxx"
31 #include "PropertyHelper.hxx"
32 #include "macros.hxx"
33 #include "servicenames_charttypes.hxx"
34 #include "ContainerHelper.hxx"
35 #include "CartesianCoordinateSystem.hxx"
36 #include "AxisHelper.hxx"
37 #include "AxisIndexDefines.hxx"
38 #include <com/sun/star/beans/PropertyAttribute.hpp>
39 #include <com/sun/star/chart2/AxisType.hpp>
40 #include <com/sun/star/chart2/CurveStyle.hpp>
42 using namespace ::com::sun::star;
44 using ::rtl::OUString;
45 using ::com::sun::star::beans::Property;
46 using ::com::sun::star::uno::Sequence;
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::uno::Any;
49 using ::osl::MutexGuard;
51 namespace
54 enum
56 PROP_SCATTERCHARTTYPE_CURVE_STYLE,
57 PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
58 PROP_SCATTERCHARTTYPE_SPLINE_ORDER
61 void lcl_AddPropertiesToVector(
62 ::std::vector< Property > & rOutProperties )
64 rOutProperties.push_back(
65 Property( C2U( "CurveStyle" ),
66 PROP_SCATTERCHARTTYPE_CURVE_STYLE,
67 ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)),
68 beans::PropertyAttribute::BOUND
69 | beans::PropertyAttribute::MAYBEDEFAULT ));
71 rOutProperties.push_back(
72 Property( C2U( "CurveResolution" ),
73 PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
74 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
75 beans::PropertyAttribute::BOUND
76 | beans::PropertyAttribute::MAYBEDEFAULT ));
77 rOutProperties.push_back(
78 Property( C2U( "SplineOrder" ),
79 PROP_SCATTERCHARTTYPE_SPLINE_ORDER,
80 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
81 beans::PropertyAttribute::BOUND
82 | beans::PropertyAttribute::MAYBEDEFAULT ));
85 void lcl_AddDefaultsToMap(
86 ::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 );
96 const Sequence< Property > & lcl_GetPropertySequence()
98 static Sequence< Property > aPropSeq;
100 // /--
101 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
102 if( 0 == aPropSeq.getLength() )
104 // get properties
105 ::std::vector< ::com::sun::star::beans::Property > aProperties;
106 lcl_AddPropertiesToVector( aProperties );
108 // and sort them for access via bsearch
109 ::std::sort( aProperties.begin(), aProperties.end(),
110 ::chart::PropertyNameLess() );
112 // transfer result to static Sequence
113 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
116 return aPropSeq;
119 } // anonymous namespace
121 namespace chart
124 ScatterChartType::ScatterChartType(
125 const uno::Reference< uno::XComponentContext > & xContext,
126 chart2::CurveStyle eCurveStyle /* chart2::CurveStyle_LINES */ ,
127 sal_Int32 nResolution /* = 20 */,
128 sal_Int32 nOrder /* = 3 */ ) :
129 ChartType( xContext )
131 if( eCurveStyle != chart2::CurveStyle_LINES )
132 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_STYLE,
133 uno::makeAny( eCurveStyle ));
134 if( nResolution != 20 )
135 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION,
136 uno::makeAny( nResolution ));
137 if( nOrder != 3 )
138 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_SPLINE_ORDER,
139 uno::makeAny( nOrder ));
142 ScatterChartType::ScatterChartType( const ScatterChartType & rOther ) :
143 ChartType( rOther )
147 ScatterChartType::~ScatterChartType()
150 // ____ XCloneable ____
151 uno::Reference< util::XCloneable > SAL_CALL ScatterChartType::createClone()
152 throw (uno::RuntimeException)
154 return uno::Reference< util::XCloneable >( new ScatterChartType( *this ));
157 // ____ XChartType ____
158 // ____ XChartType ____
159 Reference< chart2::XCoordinateSystem > SAL_CALL
160 ScatterChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
161 throw (lang::IllegalArgumentException,
162 uno::RuntimeException)
164 Reference< chart2::XCoordinateSystem > xResult(
165 new CartesianCoordinateSystem(
166 GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False ));
168 for( sal_Int32 i=0; i<DimensionCount; ++i )
170 Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
171 if( !xAxis.is() )
173 OSL_ENSURE(false,"a created coordinate system should have an axis for each dimension");
174 continue;
177 chart2::ScaleData aScaleData = xAxis->getScaleData();
178 aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
179 aScaleData.Scaling = AxisHelper::createLinearScaling();
181 if( i == 2 )
182 aScaleData.AxisType = chart2::AxisType::SERIES;
183 else
184 aScaleData.AxisType = chart2::AxisType::REALNUMBER;
186 xAxis->setScaleData( aScaleData );
189 return xResult;
192 ::rtl::OUString SAL_CALL ScatterChartType::getChartType()
193 throw (uno::RuntimeException)
195 return CHART2_SERVICE_NAME_CHARTTYPE_SCATTER;
198 uno::Sequence< ::rtl::OUString > SAL_CALL ScatterChartType::getSupportedMandatoryRoles()
199 throw (uno::RuntimeException)
201 static uno::Sequence< ::rtl::OUString > aMandRolesSeq;
203 if( aMandRolesSeq.getLength() == 0 )
205 aMandRolesSeq.realloc( 3 );
206 aMandRolesSeq[0] = C2U( "label" );
207 aMandRolesSeq[1] = C2U( "values-x" );
208 aMandRolesSeq[2] = C2U( "values-y" );
211 return aMandRolesSeq;
214 uno::Sequence< ::rtl::OUString > SAL_CALL ScatterChartType::getSupportedOptionalRoles()
215 throw (uno::RuntimeException)
217 static uno::Sequence< ::rtl::OUString > aOptRolesSeq;
219 // if( aOptRolesSeq.getLength() == 0 )
220 // {
221 // aOptRolesSeq.realloc( 2 );
222 // aOptRolesSeq[0] = C2U( "error-bars-x" );
223 // aOptRolesSeq[1] = C2U( "error-bars-y" );
224 // }
226 return aOptRolesSeq;
230 // ____ OPropertySet ____
231 uno::Any ScatterChartType::GetDefaultValue( sal_Int32 nHandle ) const
232 throw(beans::UnknownPropertyException)
234 static tPropertyValueMap aStaticDefaults;
236 // /--
237 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
238 if( 0 == aStaticDefaults.size() )
240 // initialize defaults
241 lcl_AddDefaultsToMap( aStaticDefaults );
244 tPropertyValueMap::const_iterator aFound(
245 aStaticDefaults.find( nHandle ));
247 if( aFound == aStaticDefaults.end())
248 return uno::Any();
250 return (*aFound).second;
251 // \--
254 // ____ OPropertySet ____
255 ::cppu::IPropertyArrayHelper & SAL_CALL ScatterChartType::getInfoHelper()
257 static ::cppu::OPropertyArrayHelper aArrayHelper( lcl_GetPropertySequence(),
258 /* bSorted = */ sal_True );
260 return aArrayHelper;
264 // ____ XPropertySet ____
265 uno::Reference< beans::XPropertySetInfo > SAL_CALL
266 ScatterChartType::getPropertySetInfo()
267 throw (uno::RuntimeException)
269 static uno::Reference< beans::XPropertySetInfo > xInfo;
271 // /--
272 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
273 if( !xInfo.is())
275 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
276 getInfoHelper());
279 return xInfo;
280 // \--
283 uno::Sequence< ::rtl::OUString > ScatterChartType::getSupportedServiceNames_Static()
285 uno::Sequence< ::rtl::OUString > aServices( 3 );
286 aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_SCATTER;
287 aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
288 aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
289 return aServices;
292 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
293 APPHELPER_XSERVICEINFO_IMPL( ScatterChartType,
294 C2U( "com.sun.star.comp.chart.ScatterChartType" ));
296 } // namespace chart