merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / tools / RegressionCurveModel.cxx
blobfc9e5239ce3858e6452e3a6324ccc2331d7efd73
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RegressionCurveModel.cxx,v $
10 * $Revision: 1.9 $
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 "RegressionCurveModel.hxx"
34 #include "macros.hxx"
35 #include "LineProperties.hxx"
36 #include "RegressionCurveHelper.hxx"
37 #include "RegressionCalculationHelper.hxx"
38 #include "RegressionEquation.hxx"
39 #include "ContainerHelper.hxx"
40 #include "CloneHelper.hxx"
41 #include "PropertyHelper.hxx"
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 #include <rtl/math.hxx>
44 #include <rtl/ustrbuf.hxx>
46 using namespace ::com::sun::star;
48 using ::rtl::OUString;
49 using ::rtl::OUStringBuffer;
50 using ::com::sun::star::beans::Property;
51 using ::osl::MutexGuard;
53 namespace
55 static const OUString lcl_aImplementationName_MeanValue(
56 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.MeanValueRegressionCurve" ));
57 static const OUString lcl_aImplementationName_Linear(
58 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LinearRegressionCurve" ));
59 static const OUString lcl_aImplementationName_Logarithmic(
60 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LogarithmicRegressionCurve" ));
61 static const OUString lcl_aImplementationName_Exponential(
62 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ExponentialRegressionCurve" ));
63 static const OUString lcl_aImplementationName_Potential(
64 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PotentialRegressionCurve" ));
66 static const OUString lcl_aServiceName(
67 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionCurve" ));
69 const uno::Sequence< Property > & lcl_GetPropertySequence()
71 static uno::Sequence< Property > aPropSeq;
73 // /--
74 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
75 if( 0 == aPropSeq.getLength() )
77 // get properties
78 ::std::vector< ::com::sun::star::beans::Property > aProperties;
79 ::chart::LineProperties::AddPropertiesToVector( aProperties );
81 // and sort them for access via bsearch
82 ::std::sort( aProperties.begin(), aProperties.end(),
83 ::chart::PropertyNameLess() );
85 // transfer result to static Sequence
86 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
89 return aPropSeq;
92 ::cppu::IPropertyArrayHelper & lcl_getInfoHelper()
94 static ::cppu::OPropertyArrayHelper aArrayHelper(
95 lcl_GetPropertySequence(),
96 /* bSorted = */ sal_True );
98 return aArrayHelper;
101 } // anonymous namespace
103 namespace chart
106 RegressionCurveModel::RegressionCurveModel(
107 uno::Reference< uno::XComponentContext > const & xContext,
108 tCurveType eCurveType ) :
109 ::property::OPropertySet( m_aMutex ),
110 m_xContext( xContext ),
111 m_eRegressionCurveType( eCurveType ),
112 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
113 m_xEquationProperties( new RegressionEquation( xContext ))
115 // set 0 line width (default) hard, so that it is always written to XML,
116 // because the old implementation uses different defaults
117 setFastPropertyValue_NoBroadcast(
118 LineProperties::PROP_LINE_WIDTH, uno::makeAny( sal_Int32( 0 )));
119 ModifyListenerHelper::addListener( m_xEquationProperties, m_xModifyEventForwarder );
122 RegressionCurveModel::RegressionCurveModel( const RegressionCurveModel & rOther ) :
123 MutexContainer(),
124 impl::RegressionCurveModel_Base(),
125 ::property::OPropertySet( rOther, m_aMutex ),
126 m_xContext( rOther.m_xContext ),
127 m_eRegressionCurveType( rOther.m_eRegressionCurveType ),
128 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
130 m_xEquationProperties.set( CloneHelper::CreateRefClone< uno::Reference< beans::XPropertySet > >()( rOther.m_xEquationProperties ));
131 ModifyListenerHelper::addListener( m_xEquationProperties, m_xModifyEventForwarder );
134 RegressionCurveModel::~RegressionCurveModel()
137 // ____ XRegressionCurve ____
138 uno::Reference< chart2::XRegressionCurveCalculator > SAL_CALL
139 RegressionCurveModel::getCalculator()
140 throw (uno::RuntimeException)
142 return RegressionCurveHelper::createRegressionCurveCalculatorByServiceName( getServiceName());
145 uno::Reference< beans::XPropertySet > SAL_CALL RegressionCurveModel::getEquationProperties()
146 throw (uno::RuntimeException)
148 return m_xEquationProperties;
151 void SAL_CALL RegressionCurveModel::setEquationProperties( const uno::Reference< beans::XPropertySet >& xEquationProperties )
152 throw (uno::RuntimeException)
154 if( xEquationProperties.is())
156 if( m_xEquationProperties.is())
157 ModifyListenerHelper::removeListener( m_xEquationProperties, m_xModifyEventForwarder );
159 m_xEquationProperties.set( xEquationProperties );
160 ModifyListenerHelper::addListener( m_xEquationProperties, m_xModifyEventForwarder );
161 fireModifyEvent();
165 // ____ XServiceName ____
166 ::rtl::OUString SAL_CALL RegressionCurveModel::getServiceName()
167 throw (uno::RuntimeException)
169 switch( m_eRegressionCurveType )
171 case CURVE_TYPE_MEAN_VALUE:
172 return C2U( "com.sun.star.chart2.MeanValueRegressionCurve" );
173 case CURVE_TYPE_LINEAR:
174 return C2U( "com.sun.star.chart2.LinearRegressionCurve" );
175 case CURVE_TYPE_LOGARITHM:
176 return C2U( "com.sun.star.chart2.LogarithmicRegressionCurve" );
177 case CURVE_TYPE_EXPONENTIAL:
178 return C2U( "com.sun.star.chart2.ExponentialRegressionCurve" );
179 case CURVE_TYPE_POWER:
180 return C2U( "com.sun.star.chart2.PotentialRegressionCurve" );
183 return ::rtl::OUString();
186 // ____ XModifyBroadcaster ____
187 void SAL_CALL RegressionCurveModel::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
188 throw (uno::RuntimeException)
192 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
193 xBroadcaster->addModifyListener( aListener );
195 catch( const uno::Exception & ex )
197 ASSERT_EXCEPTION( ex );
201 void SAL_CALL RegressionCurveModel::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
202 throw (uno::RuntimeException)
206 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
207 xBroadcaster->removeModifyListener( aListener );
209 catch( const uno::Exception & ex )
211 ASSERT_EXCEPTION( ex );
215 // ____ XModifyListener ____
216 void SAL_CALL RegressionCurveModel::modified( const lang::EventObject& aEvent )
217 throw (uno::RuntimeException)
219 m_xModifyEventForwarder->modified( aEvent );
222 // ____ XEventListener (base of XModifyListener) ____
223 void SAL_CALL RegressionCurveModel::disposing( const lang::EventObject& /* Source */ )
224 throw (uno::RuntimeException)
226 // nothing
229 // ____ OPropertySet ____
230 void RegressionCurveModel::firePropertyChangeEvent()
232 fireModifyEvent();
235 void RegressionCurveModel::fireModifyEvent()
237 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
240 // ================================================================================
242 // ____ OPropertySet ____
243 uno::Any RegressionCurveModel::GetDefaultValue( sal_Int32 nHandle ) const
244 throw(beans::UnknownPropertyException)
246 static tPropertyValueMap aStaticDefaults;
248 // /--
249 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
250 if( 0 == aStaticDefaults.size() )
252 // initialize defaults
253 LineProperties::AddDefaultsToMap( aStaticDefaults );
256 tPropertyValueMap::const_iterator aFound(
257 aStaticDefaults.find( nHandle ));
259 if( aFound == aStaticDefaults.end())
260 return uno::Any();
262 return (*aFound).second;
263 // \--
266 ::cppu::IPropertyArrayHelper & SAL_CALL RegressionCurveModel::getInfoHelper()
268 return lcl_getInfoHelper();
272 // ____ XPropertySet ____
273 uno::Reference< beans::XPropertySetInfo > SAL_CALL
274 RegressionCurveModel::getPropertySetInfo()
275 throw (uno::RuntimeException)
277 static uno::Reference< beans::XPropertySetInfo > xInfo;
279 // /--
280 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
281 if( !xInfo.is())
283 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
284 getInfoHelper());
287 return xInfo;
288 // \--
291 // ================================================================================
293 // needed by MSC compiler
294 using impl::RegressionCurveModel_Base;
296 IMPLEMENT_FORWARD_XINTERFACE2( RegressionCurveModel, RegressionCurveModel_Base, OPropertySet )
297 IMPLEMENT_FORWARD_XTYPEPROVIDER2( RegressionCurveModel, RegressionCurveModel_Base, OPropertySet )
301 // implementations
303 // --------------------------------------------------------------------------------
305 MeanValueRegressionCurve::MeanValueRegressionCurve(
306 const uno::Reference< uno::XComponentContext > & xContext )
307 : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_MEAN_VALUE )
309 MeanValueRegressionCurve::MeanValueRegressionCurve(
310 const MeanValueRegressionCurve & rOther ) :
311 RegressionCurveModel( rOther )
313 MeanValueRegressionCurve::~MeanValueRegressionCurve()
315 uno::Sequence< ::rtl::OUString > MeanValueRegressionCurve::getSupportedServiceNames_Static()
317 uno::Sequence< ::rtl::OUString > aServices( 2 );
318 aServices[ 0 ] = lcl_aServiceName;
319 aServices[ 1 ] = C2U( "com.sun.star.chart2.MeanValueRegressionCurve" );
320 return aServices;
322 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
323 APPHELPER_XSERVICEINFO_IMPL( MeanValueRegressionCurve, lcl_aImplementationName_MeanValue );
325 uno::Reference< util::XCloneable > SAL_CALL MeanValueRegressionCurve::createClone()
326 throw (uno::RuntimeException)
328 return uno::Reference< util::XCloneable >( new MeanValueRegressionCurve( *this ));
331 // --------------------------------------------------------------------------------
333 LinearRegressionCurve::LinearRegressionCurve(
334 const uno::Reference< uno::XComponentContext > & xContext )
335 : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_LINEAR )
337 LinearRegressionCurve::LinearRegressionCurve(
338 const LinearRegressionCurve & rOther ) :
339 RegressionCurveModel( rOther )
341 LinearRegressionCurve::~LinearRegressionCurve()
343 uno::Sequence< ::rtl::OUString > LinearRegressionCurve::getSupportedServiceNames_Static()
345 uno::Sequence< ::rtl::OUString > aServices( 2 );
346 aServices[ 0 ] = lcl_aServiceName;
347 aServices[ 1 ] = C2U( "com.sun.star.chart2.LinearRegressionCurve" );
348 return aServices;
350 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
351 APPHELPER_XSERVICEINFO_IMPL( LinearRegressionCurve, lcl_aImplementationName_Linear );
353 uno::Reference< util::XCloneable > SAL_CALL LinearRegressionCurve::createClone()
354 throw (uno::RuntimeException)
356 return uno::Reference< util::XCloneable >( new LinearRegressionCurve( *this ));
359 // --------------------------------------------------------------------------------
361 LogarithmicRegressionCurve::LogarithmicRegressionCurve(
362 const uno::Reference< uno::XComponentContext > & xContext )
363 : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_LOGARITHM )
365 LogarithmicRegressionCurve::LogarithmicRegressionCurve(
366 const LogarithmicRegressionCurve & rOther ) :
367 RegressionCurveModel( rOther )
369 LogarithmicRegressionCurve::~LogarithmicRegressionCurve()
371 uno::Sequence< ::rtl::OUString > LogarithmicRegressionCurve::getSupportedServiceNames_Static()
373 uno::Sequence< ::rtl::OUString > aServices( 2 );
374 aServices[ 0 ] = lcl_aServiceName;
375 aServices[ 1 ] = C2U( "com.sun.star.chart2.LogarithmicRegressionCurve" );
376 return aServices;
378 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
379 APPHELPER_XSERVICEINFO_IMPL( LogarithmicRegressionCurve, lcl_aImplementationName_Logarithmic );
381 uno::Reference< util::XCloneable > SAL_CALL LogarithmicRegressionCurve::createClone()
382 throw (uno::RuntimeException)
384 return uno::Reference< util::XCloneable >( new LogarithmicRegressionCurve( *this ));
387 // --------------------------------------------------------------------------------
389 ExponentialRegressionCurve::ExponentialRegressionCurve(
390 const uno::Reference< uno::XComponentContext > & xContext )
391 : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_EXPONENTIAL )
393 ExponentialRegressionCurve::ExponentialRegressionCurve(
394 const ExponentialRegressionCurve & rOther ) :
395 RegressionCurveModel( rOther )
397 ExponentialRegressionCurve::~ExponentialRegressionCurve()
399 uno::Sequence< ::rtl::OUString > ExponentialRegressionCurve::getSupportedServiceNames_Static()
401 uno::Sequence< ::rtl::OUString > aServices( 2 );
402 aServices[ 0 ] = lcl_aServiceName;
403 aServices[ 1 ] = C2U( "com.sun.star.chart2.ExponentialRegressionCurve" );
404 return aServices;
406 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
407 APPHELPER_XSERVICEINFO_IMPL( ExponentialRegressionCurve, lcl_aImplementationName_Exponential );
409 uno::Reference< util::XCloneable > SAL_CALL ExponentialRegressionCurve::createClone()
410 throw (uno::RuntimeException)
412 return uno::Reference< util::XCloneable >( new ExponentialRegressionCurve( *this ));
415 // --------------------------------------------------------------------------------
417 PotentialRegressionCurve::PotentialRegressionCurve(
418 const uno::Reference< uno::XComponentContext > & xContext )
419 : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_POWER )
421 PotentialRegressionCurve::PotentialRegressionCurve(
422 const PotentialRegressionCurve & rOther ) :
423 RegressionCurveModel( rOther )
425 PotentialRegressionCurve::~PotentialRegressionCurve()
427 uno::Sequence< ::rtl::OUString > PotentialRegressionCurve::getSupportedServiceNames_Static()
429 uno::Sequence< ::rtl::OUString > aServices( 2 );
430 aServices[ 0 ] = lcl_aServiceName;
431 aServices[ 1 ] = C2U( "com.sun.star.chart2.PotentialRegressionCurve" );
432 return aServices;
434 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
435 APPHELPER_XSERVICEINFO_IMPL( PotentialRegressionCurve, lcl_aImplementationName_Potential );
437 uno::Reference< util::XCloneable > SAL_CALL PotentialRegressionCurve::createClone()
438 throw (uno::RuntimeException)
440 return uno::Reference< util::XCloneable >( new PotentialRegressionCurve( *this ));
444 } // namespace chart