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 "RegressionCurveModel.hxx"
32 #include "LineProperties.hxx"
33 #include "RegressionCurveHelper.hxx"
34 #include "RegressionCalculationHelper.hxx"
35 #include "RegressionEquation.hxx"
36 #include "ContainerHelper.hxx"
37 #include "CloneHelper.hxx"
38 #include "PropertyHelper.hxx"
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
40 #include <rtl/math.hxx>
41 #include <rtl/ustrbuf.hxx>
43 using namespace ::com::sun::star
;
45 using ::rtl::OUString
;
46 using ::rtl::OUStringBuffer
;
47 using ::com::sun::star::beans::Property
;
48 using ::osl::MutexGuard
;
52 static const OUString
lcl_aImplementationName_MeanValue(
53 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.MeanValueRegressionCurve" ));
54 static const OUString
lcl_aImplementationName_Linear(
55 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LinearRegressionCurve" ));
56 static const OUString
lcl_aImplementationName_Logarithmic(
57 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LogarithmicRegressionCurve" ));
58 static const OUString
lcl_aImplementationName_Exponential(
59 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ExponentialRegressionCurve" ));
60 static const OUString
lcl_aImplementationName_Potential(
61 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PotentialRegressionCurve" ));
63 static const OUString
lcl_aServiceName(
64 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionCurve" ));
66 const uno::Sequence
< Property
> & lcl_GetPropertySequence()
68 static uno::Sequence
< Property
> aPropSeq
;
71 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
72 if( 0 == aPropSeq
.getLength() )
75 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
76 ::chart::LineProperties::AddPropertiesToVector( aProperties
);
78 // and sort them for access via bsearch
79 ::std::sort( aProperties
.begin(), aProperties
.end(),
80 ::chart::PropertyNameLess() );
82 // transfer result to static Sequence
83 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
89 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
91 static ::cppu::OPropertyArrayHelper
aArrayHelper(
92 lcl_GetPropertySequence(),
93 /* bSorted = */ sal_True
);
98 } // anonymous namespace
103 RegressionCurveModel::RegressionCurveModel(
104 uno::Reference
< uno::XComponentContext
> const & xContext
,
105 tCurveType eCurveType
) :
106 ::property::OPropertySet( m_aMutex
),
107 m_xContext( xContext
),
108 m_eRegressionCurveType( eCurveType
),
109 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
110 m_xEquationProperties( new RegressionEquation( xContext
))
112 // set 0 line width (default) hard, so that it is always written to XML,
113 // because the old implementation uses different defaults
114 setFastPropertyValue_NoBroadcast(
115 LineProperties::PROP_LINE_WIDTH
, uno::makeAny( sal_Int32( 0 )));
116 ModifyListenerHelper::addListener( m_xEquationProperties
, m_xModifyEventForwarder
);
119 RegressionCurveModel::RegressionCurveModel( const RegressionCurveModel
& rOther
) :
121 impl::RegressionCurveModel_Base(),
122 ::property::OPropertySet( rOther
, m_aMutex
),
123 m_xContext( rOther
.m_xContext
),
124 m_eRegressionCurveType( rOther
.m_eRegressionCurveType
),
125 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
127 m_xEquationProperties
.set( CloneHelper::CreateRefClone
< uno::Reference
< beans::XPropertySet
> >()( rOther
.m_xEquationProperties
));
128 ModifyListenerHelper::addListener( m_xEquationProperties
, m_xModifyEventForwarder
);
131 RegressionCurveModel::~RegressionCurveModel()
134 // ____ XRegressionCurve ____
135 uno::Reference
< chart2::XRegressionCurveCalculator
> SAL_CALL
136 RegressionCurveModel::getCalculator()
137 throw (uno::RuntimeException
)
139 return RegressionCurveHelper::createRegressionCurveCalculatorByServiceName( getServiceName());
142 uno::Reference
< beans::XPropertySet
> SAL_CALL
RegressionCurveModel::getEquationProperties()
143 throw (uno::RuntimeException
)
145 return m_xEquationProperties
;
148 void SAL_CALL
RegressionCurveModel::setEquationProperties( const uno::Reference
< beans::XPropertySet
>& xEquationProperties
)
149 throw (uno::RuntimeException
)
151 if( xEquationProperties
.is())
153 if( m_xEquationProperties
.is())
154 ModifyListenerHelper::removeListener( m_xEquationProperties
, m_xModifyEventForwarder
);
156 m_xEquationProperties
.set( xEquationProperties
);
157 ModifyListenerHelper::addListener( m_xEquationProperties
, m_xModifyEventForwarder
);
162 // ____ XServiceName ____
163 ::rtl::OUString SAL_CALL
RegressionCurveModel::getServiceName()
164 throw (uno::RuntimeException
)
166 switch( m_eRegressionCurveType
)
168 case CURVE_TYPE_MEAN_VALUE
:
169 return C2U( "com.sun.star.chart2.MeanValueRegressionCurve" );
170 case CURVE_TYPE_LINEAR
:
171 return C2U( "com.sun.star.chart2.LinearRegressionCurve" );
172 case CURVE_TYPE_LOGARITHM
:
173 return C2U( "com.sun.star.chart2.LogarithmicRegressionCurve" );
174 case CURVE_TYPE_EXPONENTIAL
:
175 return C2U( "com.sun.star.chart2.ExponentialRegressionCurve" );
176 case CURVE_TYPE_POWER
:
177 return C2U( "com.sun.star.chart2.PotentialRegressionCurve" );
180 return ::rtl::OUString();
183 // ____ XModifyBroadcaster ____
184 void SAL_CALL
RegressionCurveModel::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
185 throw (uno::RuntimeException
)
189 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
190 xBroadcaster
->addModifyListener( aListener
);
192 catch( const uno::Exception
& ex
)
194 ASSERT_EXCEPTION( ex
);
198 void SAL_CALL
RegressionCurveModel::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
199 throw (uno::RuntimeException
)
203 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
204 xBroadcaster
->removeModifyListener( aListener
);
206 catch( const uno::Exception
& ex
)
208 ASSERT_EXCEPTION( ex
);
212 // ____ XModifyListener ____
213 void SAL_CALL
RegressionCurveModel::modified( const lang::EventObject
& aEvent
)
214 throw (uno::RuntimeException
)
216 m_xModifyEventForwarder
->modified( aEvent
);
219 // ____ XEventListener (base of XModifyListener) ____
220 void SAL_CALL
RegressionCurveModel::disposing( const lang::EventObject
& /* Source */ )
221 throw (uno::RuntimeException
)
226 // ____ OPropertySet ____
227 void RegressionCurveModel::firePropertyChangeEvent()
232 void RegressionCurveModel::fireModifyEvent()
234 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
237 // ================================================================================
239 // ____ OPropertySet ____
240 uno::Any
RegressionCurveModel::GetDefaultValue( sal_Int32 nHandle
) const
241 throw(beans::UnknownPropertyException
)
243 static tPropertyValueMap aStaticDefaults
;
246 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
247 if( 0 == aStaticDefaults
.size() )
249 // initialize defaults
250 LineProperties::AddDefaultsToMap( aStaticDefaults
);
253 tPropertyValueMap::const_iterator
aFound(
254 aStaticDefaults
.find( nHandle
));
256 if( aFound
== aStaticDefaults
.end())
259 return (*aFound
).second
;
263 ::cppu::IPropertyArrayHelper
& SAL_CALL
RegressionCurveModel::getInfoHelper()
265 return lcl_getInfoHelper();
269 // ____ XPropertySet ____
270 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
271 RegressionCurveModel::getPropertySetInfo()
272 throw (uno::RuntimeException
)
274 static uno::Reference
< beans::XPropertySetInfo
> xInfo
;
277 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
280 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
288 // ================================================================================
290 // needed by MSC compiler
291 using impl::RegressionCurveModel_Base
;
293 IMPLEMENT_FORWARD_XINTERFACE2( RegressionCurveModel
, RegressionCurveModel_Base
, OPropertySet
)
294 IMPLEMENT_FORWARD_XTYPEPROVIDER2( RegressionCurveModel
, RegressionCurveModel_Base
, OPropertySet
)
300 // --------------------------------------------------------------------------------
302 MeanValueRegressionCurve::MeanValueRegressionCurve(
303 const uno::Reference
< uno::XComponentContext
> & xContext
)
304 : RegressionCurveModel( xContext
, RegressionCurveModel::CURVE_TYPE_MEAN_VALUE
)
306 MeanValueRegressionCurve::MeanValueRegressionCurve(
307 const MeanValueRegressionCurve
& rOther
) :
308 RegressionCurveModel( rOther
)
310 MeanValueRegressionCurve::~MeanValueRegressionCurve()
312 uno::Sequence
< ::rtl::OUString
> MeanValueRegressionCurve::getSupportedServiceNames_Static()
314 uno::Sequence
< ::rtl::OUString
> aServices( 2 );
315 aServices
[ 0 ] = lcl_aServiceName
;
316 aServices
[ 1 ] = C2U( "com.sun.star.chart2.MeanValueRegressionCurve" );
319 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
320 APPHELPER_XSERVICEINFO_IMPL( MeanValueRegressionCurve
, lcl_aImplementationName_MeanValue
);
322 uno::Reference
< util::XCloneable
> SAL_CALL
MeanValueRegressionCurve::createClone()
323 throw (uno::RuntimeException
)
325 return uno::Reference
< util::XCloneable
>( new MeanValueRegressionCurve( *this ));
328 // --------------------------------------------------------------------------------
330 LinearRegressionCurve::LinearRegressionCurve(
331 const uno::Reference
< uno::XComponentContext
> & xContext
)
332 : RegressionCurveModel( xContext
, RegressionCurveModel::CURVE_TYPE_LINEAR
)
334 LinearRegressionCurve::LinearRegressionCurve(
335 const LinearRegressionCurve
& rOther
) :
336 RegressionCurveModel( rOther
)
338 LinearRegressionCurve::~LinearRegressionCurve()
340 uno::Sequence
< ::rtl::OUString
> LinearRegressionCurve::getSupportedServiceNames_Static()
342 uno::Sequence
< ::rtl::OUString
> aServices( 2 );
343 aServices
[ 0 ] = lcl_aServiceName
;
344 aServices
[ 1 ] = C2U( "com.sun.star.chart2.LinearRegressionCurve" );
347 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
348 APPHELPER_XSERVICEINFO_IMPL( LinearRegressionCurve
, lcl_aImplementationName_Linear
);
350 uno::Reference
< util::XCloneable
> SAL_CALL
LinearRegressionCurve::createClone()
351 throw (uno::RuntimeException
)
353 return uno::Reference
< util::XCloneable
>( new LinearRegressionCurve( *this ));
356 // --------------------------------------------------------------------------------
358 LogarithmicRegressionCurve::LogarithmicRegressionCurve(
359 const uno::Reference
< uno::XComponentContext
> & xContext
)
360 : RegressionCurveModel( xContext
, RegressionCurveModel::CURVE_TYPE_LOGARITHM
)
362 LogarithmicRegressionCurve::LogarithmicRegressionCurve(
363 const LogarithmicRegressionCurve
& rOther
) :
364 RegressionCurveModel( rOther
)
366 LogarithmicRegressionCurve::~LogarithmicRegressionCurve()
368 uno::Sequence
< ::rtl::OUString
> LogarithmicRegressionCurve::getSupportedServiceNames_Static()
370 uno::Sequence
< ::rtl::OUString
> aServices( 2 );
371 aServices
[ 0 ] = lcl_aServiceName
;
372 aServices
[ 1 ] = C2U( "com.sun.star.chart2.LogarithmicRegressionCurve" );
375 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
376 APPHELPER_XSERVICEINFO_IMPL( LogarithmicRegressionCurve
, lcl_aImplementationName_Logarithmic
);
378 uno::Reference
< util::XCloneable
> SAL_CALL
LogarithmicRegressionCurve::createClone()
379 throw (uno::RuntimeException
)
381 return uno::Reference
< util::XCloneable
>( new LogarithmicRegressionCurve( *this ));
384 // --------------------------------------------------------------------------------
386 ExponentialRegressionCurve::ExponentialRegressionCurve(
387 const uno::Reference
< uno::XComponentContext
> & xContext
)
388 : RegressionCurveModel( xContext
, RegressionCurveModel::CURVE_TYPE_EXPONENTIAL
)
390 ExponentialRegressionCurve::ExponentialRegressionCurve(
391 const ExponentialRegressionCurve
& rOther
) :
392 RegressionCurveModel( rOther
)
394 ExponentialRegressionCurve::~ExponentialRegressionCurve()
396 uno::Sequence
< ::rtl::OUString
> ExponentialRegressionCurve::getSupportedServiceNames_Static()
398 uno::Sequence
< ::rtl::OUString
> aServices( 2 );
399 aServices
[ 0 ] = lcl_aServiceName
;
400 aServices
[ 1 ] = C2U( "com.sun.star.chart2.ExponentialRegressionCurve" );
403 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
404 APPHELPER_XSERVICEINFO_IMPL( ExponentialRegressionCurve
, lcl_aImplementationName_Exponential
);
406 uno::Reference
< util::XCloneable
> SAL_CALL
ExponentialRegressionCurve::createClone()
407 throw (uno::RuntimeException
)
409 return uno::Reference
< util::XCloneable
>( new ExponentialRegressionCurve( *this ));
412 // --------------------------------------------------------------------------------
414 PotentialRegressionCurve::PotentialRegressionCurve(
415 const uno::Reference
< uno::XComponentContext
> & xContext
)
416 : RegressionCurveModel( xContext
, RegressionCurveModel::CURVE_TYPE_POWER
)
418 PotentialRegressionCurve::PotentialRegressionCurve(
419 const PotentialRegressionCurve
& rOther
) :
420 RegressionCurveModel( rOther
)
422 PotentialRegressionCurve::~PotentialRegressionCurve()
424 uno::Sequence
< ::rtl::OUString
> PotentialRegressionCurve::getSupportedServiceNames_Static()
426 uno::Sequence
< ::rtl::OUString
> aServices( 2 );
427 aServices
[ 0 ] = lcl_aServiceName
;
428 aServices
[ 1 ] = C2U( "com.sun.star.chart2.PotentialRegressionCurve" );
431 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
432 APPHELPER_XSERVICEINFO_IMPL( PotentialRegressionCurve
, lcl_aImplementationName_Potential
);
434 uno::Reference
< util::XCloneable
> SAL_CALL
PotentialRegressionCurve::createClone()
435 throw (uno::RuntimeException
)
437 return uno::Reference
< util::XCloneable
>( new PotentialRegressionCurve( *this ));