1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScatterChartTypeTemplate.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "ScatterChartTypeTemplate.hxx"
35 #include "XYDataInterpreter.hxx"
36 #include "CartesianCoordinateSystem.hxx"
37 #include "DiagramHelper.hxx"
38 #include "servicenames_charttypes.hxx"
39 #include "ContainerHelper.hxx"
40 #include "DataSeriesHelper.hxx"
41 #include <com/sun/star/chart2/SymbolStyle.hpp>
42 #include <com/sun/star/chart2/Symbol.hpp>
43 #include <com/sun/star/drawing/LineStyle.hpp>
44 #include "PropertyHelper.hxx"
45 #include <com/sun/star/beans/PropertyAttribute.hpp>
49 using namespace ::com::sun::star
;
51 using ::com::sun::star::uno::Reference
;
52 using ::com::sun::star::uno::Sequence
;
53 using ::rtl::OUString
;
54 using ::com::sun::star::beans::Property
;
55 using ::com::sun::star::uno::Reference
;
56 using ::com::sun::star::uno::Any
;
57 using ::osl::MutexGuard
;
62 static const OUString
lcl_aServiceName(
63 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.ScatterChartTypeTemplate" ));
67 PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE
,
68 PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION
,
69 PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
73 void lcl_AddPropertiesToVector(
74 ::std::vector
< Property
> & rOutProperties
)
76 rOutProperties
.push_back(
77 Property( C2U( "CurveStyle" ),
78 PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE
,
79 ::getCppuType( reinterpret_cast< const chart2::CurveStyle
* >(0)),
80 beans::PropertyAttribute::BOUND
81 | beans::PropertyAttribute::MAYBEDEFAULT
));
82 rOutProperties
.push_back(
83 Property( C2U( "CurveResolution" ),
84 PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION
,
85 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
86 beans::PropertyAttribute::BOUND
87 | beans::PropertyAttribute::MAYBEDEFAULT
));
88 rOutProperties
.push_back(
89 Property( C2U( "SplineOrder" ),
90 PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
,
91 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
92 beans::PropertyAttribute::BOUND
93 | beans::PropertyAttribute::MAYBEDEFAULT
));
96 void lcl_AddDefaultsToMap(
97 ::chart::tPropertyValueMap
& rOutMap
)
99 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE
, chart2::CurveStyle_LINES
);
100 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION
, 20 );
102 // todo: check whether order 3 means polygons of order 3 or 2. (see
103 // http://www.people.nnov.ru/fractal/Splines/Basis.htm )
104 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
, 3 );
107 const Sequence
< Property
> & lcl_GetPropertySequence()
109 static Sequence
< Property
> aPropSeq
;
112 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
113 if( 0 == aPropSeq
.getLength() )
116 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
117 lcl_AddPropertiesToVector( aProperties
);
119 // and sort them for access via bsearch
120 ::std::sort( aProperties
.begin(), aProperties
.end(),
121 ::chart::PropertyNameLess() );
123 // transfer result to static Sequence
124 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
130 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
132 static ::cppu::OPropertyArrayHelper
aArrayHelper(
133 lcl_GetPropertySequence(),
134 /* bSorted = */ sal_True
);
139 } // anonymous namespace
144 ScatterChartTypeTemplate::ScatterChartTypeTemplate(
146 uno::XComponentContext
> const & xContext
,
147 const OUString
& rServiceName
,
149 bool bHasLines
/* = true */,
150 sal_Int32 nDim
/* = 2 */ ) :
151 ChartTypeTemplate( xContext
, rServiceName
),
152 ::property::OPropertySet( m_aMutex
),
153 m_bHasSymbols( bSymbols
),
154 m_bHasLines( bHasLines
),
158 m_bHasSymbols
= false;
161 ScatterChartTypeTemplate::~ScatterChartTypeTemplate()
164 // ____ OPropertySet ____
165 uno::Any
ScatterChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle
) const
166 throw(beans::UnknownPropertyException
)
168 static tPropertyValueMap aStaticDefaults
;
171 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
172 if( 0 == aStaticDefaults
.size() )
174 // initialize defaults
175 lcl_AddDefaultsToMap( aStaticDefaults
);
178 tPropertyValueMap::const_iterator
aFound(
179 aStaticDefaults
.find( nHandle
));
181 if( aFound
== aStaticDefaults
.end())
184 return (*aFound
).second
;
188 ::cppu::IPropertyArrayHelper
& SAL_CALL
ScatterChartTypeTemplate::getInfoHelper()
190 return lcl_getInfoHelper();
194 // ____ XPropertySet ____
195 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
196 ScatterChartTypeTemplate::getPropertySetInfo()
197 throw (uno::RuntimeException
)
199 static uno::Reference
< beans::XPropertySetInfo
> xInfo
;
202 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
205 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
213 sal_Int32
ScatterChartTypeTemplate::getDimension() const
218 StackMode
ScatterChartTypeTemplate::getStackMode( sal_Int32
/* nChartTypeIndex */ ) const
221 return StackMode_Z_STACKED
;
222 return StackMode_NONE
;
225 bool ScatterChartTypeTemplate::supportsCategories() const
231 void SAL_CALL
ScatterChartTypeTemplate::applyStyle(
232 const Reference
< chart2::XDataSeries
>& xSeries
,
233 ::sal_Int32 nChartTypeIndex
,
234 ::sal_Int32 nSeriesIndex
,
235 ::sal_Int32 nSeriesCount
)
236 throw (uno::RuntimeException
)
238 ChartTypeTemplate::applyStyle( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
242 Reference
< beans::XPropertySet
> xProp( xSeries
, uno::UNO_QUERY_THROW
);
244 DataSeriesHelper::switchSymbolsOnOrOff( xProp
, m_bHasSymbols
, nSeriesIndex
);
245 DataSeriesHelper::switchLinesOnOrOff( xProp
, m_bHasLines
);
246 DataSeriesHelper::makeLinesThickOrThin( xProp
, m_nDim
==2 );
248 catch( uno::Exception
& ex
)
250 ASSERT_EXCEPTION( ex
);
254 // ____ XChartTypeTemplate ____
255 Sequence
< OUString
> SAL_CALL
ScatterChartTypeTemplate::getAvailableCreationParameterNames()
256 throw (uno::RuntimeException
)
258 return Sequence
< OUString
>();
261 sal_Bool SAL_CALL
ScatterChartTypeTemplate::matchesTemplate(
262 const Reference
< chart2::XDiagram
>& xDiagram
,
263 sal_Bool bAdaptProperties
)
264 throw (uno::RuntimeException
)
266 sal_Bool bResult
= ChartTypeTemplate::matchesTemplate( xDiagram
, bAdaptProperties
);
268 // check symbol-style and line-style
269 // for a template with symbols (or with lines) it is ok, if there is at least one series
270 // with symbols (or with lines)
273 bool bSymbolFound
= false;
274 bool bLineFound
= false;
276 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVec(
277 DiagramHelper::getDataSeriesFromDiagram( xDiagram
));
279 for( ::std::vector
< Reference
< chart2::XDataSeries
> >::const_iterator aIt
=
280 aSeriesVec
.begin(); aIt
!= aSeriesVec
.end(); ++aIt
)
284 chart2::Symbol aSymbProp
;
285 drawing::LineStyle eLineStyle
;
286 Reference
< beans::XPropertySet
> xProp( *aIt
, uno::UNO_QUERY_THROW
);
288 bool bCurrentHasSymbol
= (xProp
->getPropertyValue( C2U( "Symbol" )) >>= aSymbProp
) &&
289 (aSymbProp
.Style
!= chart2::SymbolStyle_NONE
);
291 if( bCurrentHasSymbol
)
294 if( bCurrentHasSymbol
&& (!m_bHasSymbols
) )
300 bool bCurrentHasLine
= (xProp
->getPropertyValue( C2U( "LineStyle" )) >>= eLineStyle
) &&
301 ( eLineStyle
!= drawing::LineStyle_NONE
);
303 if( bCurrentHasLine
)
306 if( bCurrentHasLine
&& (!m_bHasLines
) )
312 catch( uno::Exception
& ex
)
314 ASSERT_EXCEPTION( ex
);
320 if( !bLineFound
&& m_bHasLines
&& bSymbolFound
)
322 else if( !bSymbolFound
&& m_bHasSymbols
&& bLineFound
)
324 else if( !bLineFound
&& !bSymbolFound
)
325 return m_bHasLines
&& m_bHasSymbols
;
329 // adapt curve style, spline order and resolution
330 if( bResult
&& bAdaptProperties
)
334 uno::Reference
< beans::XPropertySet
> xChartTypeProp(
335 DiagramHelper::getChartTypeByIndex( xDiagram
, 0 ),
336 uno::UNO_QUERY_THROW
);
337 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE
, xChartTypeProp
->getPropertyValue(C2U("CurveStyle" )) );
338 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION
, xChartTypeProp
->getPropertyValue(C2U("CurveResolution" )) );
339 setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
, xChartTypeProp
->getPropertyValue(C2U("SplineOrder" )) );
341 catch( uno::Exception
& ex
)
343 ASSERT_EXCEPTION( ex
);
350 Reference
< chart2::XChartType
> ScatterChartTypeTemplate::getChartTypeForIndex( sal_Int32
/*nChartTypeIndex*/ )
352 Reference
< chart2::XChartType
> xResult
;
356 Reference
< lang::XMultiServiceFactory
> xFact(
357 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
358 xResult
.set( xFact
->createInstance(
359 CHART2_SERVICE_NAME_CHARTTYPE_SCATTER
), uno::UNO_QUERY_THROW
);
361 Reference
< beans::XPropertySet
> xCTProp( xResult
, uno::UNO_QUERY
);
364 xCTProp
->setPropertyValue(
365 C2U( "CurveStyle" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE
));
366 xCTProp
->setPropertyValue(
367 C2U( "CurveResolution" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION
));
368 xCTProp
->setPropertyValue(
369 C2U( "SplineOrder" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
));
372 catch( uno::Exception
& ex
)
374 ASSERT_EXCEPTION( ex
);
377 setStackModePropertiesToChartType(xResult
);
381 Reference
< chart2::XChartType
> SAL_CALL
ScatterChartTypeTemplate::getChartTypeForNewSeries(
382 const uno::Sequence
< Reference
< chart2::XChartType
> >& aFormerlyUsedChartTypes
)
383 throw (uno::RuntimeException
)
385 Reference
< chart2::XChartType
> xResult
;
389 Reference
< lang::XMultiServiceFactory
> xFact(
390 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
391 xResult
.set( xFact
->createInstance(
392 CHART2_SERVICE_NAME_CHARTTYPE_SCATTER
), uno::UNO_QUERY_THROW
);
394 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes
, xResult
);
396 Reference
< beans::XPropertySet
> xCTProp( xResult
, uno::UNO_QUERY
);
399 xCTProp
->setPropertyValue(
400 C2U( "CurveStyle" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE
));
401 xCTProp
->setPropertyValue(
402 C2U( "CurveResolution" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION
));
403 xCTProp
->setPropertyValue(
404 C2U( "SplineOrder" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER
));
407 catch( uno::Exception
& ex
)
409 ASSERT_EXCEPTION( ex
);
415 Reference
< chart2::XDataInterpreter
> SAL_CALL
ScatterChartTypeTemplate::getDataInterpreter()
416 throw (uno::RuntimeException
)
418 if( ! m_xDataInterpreter
.is())
419 m_xDataInterpreter
.set( new XYDataInterpreter( GetComponentContext()) );
421 return m_xDataInterpreter
;
424 // ----------------------------------------
426 Sequence
< OUString
> ScatterChartTypeTemplate::getSupportedServiceNames_Static()
428 Sequence
< OUString
> aServices( 2 );
429 aServices
[ 0 ] = lcl_aServiceName
;
430 aServices
[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
434 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
435 APPHELPER_XSERVICEINFO_IMPL( ScatterChartTypeTemplate
, lcl_aServiceName
);
437 IMPLEMENT_FORWARD_XINTERFACE2( ScatterChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
438 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScatterChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)