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 "RegressionCurveModel.hxx"
27 #include "macros.hxx"
28 #include "LineProperties.hxx"
29 #include "RegressionCurveHelper.hxx"
30 #include "RegressionCalculationHelper.hxx"
31 #include "RegressionEquation.hxx"
32 #include "ContainerHelper.hxx"
33 #include "CloneHelper.hxx"
34 #include "PropertyHelper.hxx"
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include <rtl/math.hxx>
37 #include <rtl/ustrbuf.hxx>
38
39 using namespace ::com::sun::star;
40
41 using ::rtl::OUString;
42 using ::rtl::OUStringBuffer;
43 using ::com::sun::star::beans::Property;
44 using ::osl::MutexGuard;
45
46 namespace
47 {
48 static const OUString lcl_aImplementationName_MeanValue(
49 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.MeanValueRegressionCurve" ));
50 static const OUString lcl_aImplementationName_Linear(
51 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LinearRegressionCurve" ));
52 static const OUString lcl_aImplementationName_Logarithmic(
53 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LogarithmicRegressionCurve" ));
54 static const OUString lcl_aImplementationName_Exponential(
55 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ExponentialRegressionCurve" ));
56 static const OUString lcl_aImplementationName_Potential(
57 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PotentialRegressionCurve" ));
58
59 static const OUString lcl_aServiceName(
60 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionCurve" ));
61
62 struct StaticXXXDefaults_Initializer
63 {
operator ()__anonda116b590111::StaticXXXDefaults_Initializer64 ::chart::tPropertyValueMap* operator()()
65 {
66 static ::chart::tPropertyValueMap aStaticDefaults;
67 lcl_AddDefaultsToMap( aStaticDefaults );
68 return &aStaticDefaults;
69 }
70 private:
lcl_AddDefaultsToMap__anonda116b590111::StaticXXXDefaults_Initializer71 void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
72 {
73 ::chart::LineProperties::AddDefaultsToMap( rOutMap );
74 }
75 };
76
77 struct StaticXXXDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticXXXDefaults_Initializer >
78 {
79 };
80
81 struct StaticRegressionCurveInfoHelper_Initializer
82 {
operator ()__anonda116b590111::StaticRegressionCurveInfoHelper_Initializer83 ::cppu::OPropertyArrayHelper* operator()()
84 {
85 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
86 return &aPropHelper;
87 }
88
89 private:
lcl_GetPropertySequence__anonda116b590111::StaticRegressionCurveInfoHelper_Initializer90 uno::Sequence< Property > lcl_GetPropertySequence()
91 {
92 ::std::vector< ::com::sun::star::beans::Property > aProperties;
93 ::chart::LineProperties::AddPropertiesToVector( aProperties );
94
95 ::std::sort( aProperties.begin(), aProperties.end(),
96 ::chart::PropertyNameLess() );
97
98 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
99 }
100 };
101
102 struct StaticRegressionCurveInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticRegressionCurveInfoHelper_Initializer >
103 {
104 };
105
106 struct StaticRegressionCurveInfo_Initializer
107 {
operator ()__anonda116b590111::StaticRegressionCurveInfo_Initializer108 uno::Reference< beans::XPropertySetInfo >* operator()()
109 {
110 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
111 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionCurveInfoHelper::get() ) );
112 return &xPropertySetInfo;
113 }
114 };
115
116 struct StaticRegressionCurveInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticRegressionCurveInfo_Initializer >
117 {
118 };
119
120 } // anonymous namespace
121
122 namespace chart
123 {
124
RegressionCurveModel(uno::Reference<uno::XComponentContext> const & xContext,tCurveType eCurveType)125 RegressionCurveModel::RegressionCurveModel(
126 uno::Reference< uno::XComponentContext > const & xContext,
127 tCurveType eCurveType ) :
128 ::property::OPropertySet( m_aMutex ),
129 m_xContext( xContext ),
130 m_eRegressionCurveType( eCurveType ),
131 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
132 m_xEquationProperties( new RegressionEquation( xContext ))
133 {
134 // set 0 line width (default) hard, so that it is always written to XML,
135 // because the old implementation uses different defaults
136 setFastPropertyValue_NoBroadcast(
137 LineProperties::PROP_LINE_WIDTH, uno::makeAny( sal_Int32( 0 )));
138 ModifyListenerHelper::addListener( m_xEquationProperties, m_xModifyEventForwarder );
139 }
140
RegressionCurveModel(const RegressionCurveModel & rOther)141 RegressionCurveModel::RegressionCurveModel( const RegressionCurveModel & rOther ) :
142 MutexContainer(),
143 impl::RegressionCurveModel_Base(),
144 ::property::OPropertySet( rOther, m_aMutex ),
145 m_xContext( rOther.m_xContext ),
146 m_eRegressionCurveType( rOther.m_eRegressionCurveType ),
147 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
148 {
149 m_xEquationProperties.set( CloneHelper::CreateRefClone< uno::Reference< beans::XPropertySet > >()( rOther.m_xEquationProperties ));
150 ModifyListenerHelper::addListener( m_xEquationProperties, m_xModifyEventForwarder );
151 }
152
~RegressionCurveModel()153 RegressionCurveModel::~RegressionCurveModel()
154 {}
155
156 // ____ XRegressionCurve ____
157 uno::Reference< chart2::XRegressionCurveCalculator > SAL_CALL
getCalculator()158 RegressionCurveModel::getCalculator()
159 throw (uno::RuntimeException)
160 {
161 return RegressionCurveHelper::createRegressionCurveCalculatorByServiceName( getServiceName());
162 }
163
getEquationProperties()164 uno::Reference< beans::XPropertySet > SAL_CALL RegressionCurveModel::getEquationProperties()
165 throw (uno::RuntimeException)
166 {
167 return m_xEquationProperties;
168 }
169
setEquationProperties(const uno::Reference<beans::XPropertySet> & xEquationProperties)170 void SAL_CALL RegressionCurveModel::setEquationProperties( const uno::Reference< beans::XPropertySet >& xEquationProperties )
171 throw (uno::RuntimeException)
172 {
173 if( xEquationProperties.is())
174 {
175 if( m_xEquationProperties.is())
176 ModifyListenerHelper::removeListener( m_xEquationProperties, m_xModifyEventForwarder );
177
178 m_xEquationProperties.set( xEquationProperties );
179 ModifyListenerHelper::addListener( m_xEquationProperties, m_xModifyEventForwarder );
180 fireModifyEvent();
181 }
182 }
183
184 // ____ XServiceName ____
getServiceName()185 ::rtl::OUString SAL_CALL RegressionCurveModel::getServiceName()
186 throw (uno::RuntimeException)
187 {
188 switch( m_eRegressionCurveType )
189 {
190 case CURVE_TYPE_MEAN_VALUE:
191 return C2U( "com.sun.star.chart2.MeanValueRegressionCurve" );
192 case CURVE_TYPE_LINEAR:
193 return C2U( "com.sun.star.chart2.LinearRegressionCurve" );
194 case CURVE_TYPE_LOGARITHM:
195 return C2U( "com.sun.star.chart2.LogarithmicRegressionCurve" );
196 case CURVE_TYPE_EXPONENTIAL:
197 return C2U( "com.sun.star.chart2.ExponentialRegressionCurve" );
198 case CURVE_TYPE_POWER:
199 return C2U( "com.sun.star.chart2.PotentialRegressionCurve" );
200 }
201
202 return ::rtl::OUString();
203 }
204
205 // ____ XModifyBroadcaster ____
addModifyListener(const uno::Reference<util::XModifyListener> & aListener)206 void SAL_CALL RegressionCurveModel::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
207 throw (uno::RuntimeException)
208 {
209 try
210 {
211 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
212 xBroadcaster->addModifyListener( aListener );
213 }
214 catch( const uno::Exception & ex )
215 {
216 ASSERT_EXCEPTION( ex );
217 }
218 }
219
removeModifyListener(const uno::Reference<util::XModifyListener> & aListener)220 void SAL_CALL RegressionCurveModel::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
221 throw (uno::RuntimeException)
222 {
223 try
224 {
225 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
226 xBroadcaster->removeModifyListener( aListener );
227 }
228 catch( const uno::Exception & ex )
229 {
230 ASSERT_EXCEPTION( ex );
231 }
232 }
233
234 // ____ XModifyListener ____
modified(const lang::EventObject & aEvent)235 void SAL_CALL RegressionCurveModel::modified( const lang::EventObject& aEvent )
236 throw (uno::RuntimeException)
237 {
238 m_xModifyEventForwarder->modified( aEvent );
239 }
240
241 // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject &)242 void SAL_CALL RegressionCurveModel::disposing( const lang::EventObject& /* Source */ )
243 throw (uno::RuntimeException)
244 {
245 // nothing
246 }
247
248 // ____ OPropertySet ____
firePropertyChangeEvent()249 void RegressionCurveModel::firePropertyChangeEvent()
250 {
251 fireModifyEvent();
252 }
253
fireModifyEvent()254 void RegressionCurveModel::fireModifyEvent()
255 {
256 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
257 }
258
259 // ================================================================================
260
261 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const262 uno::Any RegressionCurveModel::GetDefaultValue( sal_Int32 nHandle ) const
263 throw(beans::UnknownPropertyException)
264 {
265 const tPropertyValueMap& rStaticDefaults = *StaticXXXDefaults::get();
266 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
267 if( aFound == rStaticDefaults.end() )
268 return uno::Any();
269 return (*aFound).second;
270 }
271
getInfoHelper()272 ::cppu::IPropertyArrayHelper & SAL_CALL RegressionCurveModel::getInfoHelper()
273 {
274 return *StaticRegressionCurveInfoHelper::get();
275 }
276
277 // ____ XPropertySet ____
getPropertySetInfo()278 uno::Reference< beans::XPropertySetInfo > SAL_CALL RegressionCurveModel::getPropertySetInfo()
279 throw (uno::RuntimeException)
280 {
281 return *StaticRegressionCurveInfo::get();
282 }
283
284 // ================================================================================
285
286 // needed by MSC compiler
287 using impl::RegressionCurveModel_Base;
288
IMPLEMENT_FORWARD_XINTERFACE2(RegressionCurveModel,RegressionCurveModel_Base,OPropertySet)289 IMPLEMENT_FORWARD_XINTERFACE2( RegressionCurveModel, RegressionCurveModel_Base, OPropertySet )
290 IMPLEMENT_FORWARD_XTYPEPROVIDER2( RegressionCurveModel, RegressionCurveModel_Base, OPropertySet )
291
292
293
294 // implementations
295
296 // --------------------------------------------------------------------------------
297
298 MeanValueRegressionCurve::MeanValueRegressionCurve(
299 const uno::Reference< uno::XComponentContext > & xContext )
300 : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_MEAN_VALUE )
301 {}
MeanValueRegressionCurve(const MeanValueRegressionCurve & rOther)302 MeanValueRegressionCurve::MeanValueRegressionCurve(
303 const MeanValueRegressionCurve & rOther ) :
304 RegressionCurveModel( rOther )
305 {}
~MeanValueRegressionCurve()306 MeanValueRegressionCurve::~MeanValueRegressionCurve()
307 {}
getSupportedServiceNames_Static()308 uno::Sequence< ::rtl::OUString > MeanValueRegressionCurve::getSupportedServiceNames_Static()
309 {
310 uno::Sequence< ::rtl::OUString > aServices( 2 );
311 aServices[ 0 ] = lcl_aServiceName;
312 aServices[ 1 ] = C2U( "com.sun.star.chart2.MeanValueRegressionCurve" );
313 return aServices;
314 }
315 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
316 APPHELPER_XSERVICEINFO_IMPL( MeanValueRegressionCurve, lcl_aImplementationName_MeanValue );
317
createClone()318 uno::Reference< util::XCloneable > SAL_CALL MeanValueRegressionCurve::createClone()
319 throw (uno::RuntimeException)
320 {
321 return uno::Reference< util::XCloneable >( new MeanValueRegressionCurve( *this ));
322 }
323
324 // --------------------------------------------------------------------------------
325
LinearRegressionCurve(const uno::Reference<uno::XComponentContext> & xContext)326 LinearRegressionCurve::LinearRegressionCurve(
327 const uno::Reference< uno::XComponentContext > & xContext )
328 : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_LINEAR )
329 {}
LinearRegressionCurve(const LinearRegressionCurve & rOther)330 LinearRegressionCurve::LinearRegressionCurve(
331 const LinearRegressionCurve & rOther ) :
332 RegressionCurveModel( rOther )
333 {}
~LinearRegressionCurve()334 LinearRegressionCurve::~LinearRegressionCurve()
335 {}
getSupportedServiceNames_Static()336 uno::Sequence< ::rtl::OUString > LinearRegressionCurve::getSupportedServiceNames_Static()
337 {
338 uno::Sequence< ::rtl::OUString > aServices( 2 );
339 aServices[ 0 ] = lcl_aServiceName;
340 aServices[ 1 ] = C2U( "com.sun.star.chart2.LinearRegressionCurve" );
341 return aServices;
342 }
343 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
344 APPHELPER_XSERVICEINFO_IMPL( LinearRegressionCurve, lcl_aImplementationName_Linear );
345
createClone()346 uno::Reference< util::XCloneable > SAL_CALL LinearRegressionCurve::createClone()
347 throw (uno::RuntimeException)
348 {
349 return uno::Reference< util::XCloneable >( new LinearRegressionCurve( *this ));
350 }
351
352 // --------------------------------------------------------------------------------
353
LogarithmicRegressionCurve(const uno::Reference<uno::XComponentContext> & xContext)354 LogarithmicRegressionCurve::LogarithmicRegressionCurve(
355 const uno::Reference< uno::XComponentContext > & xContext )
356 : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_LOGARITHM )
357 {}
LogarithmicRegressionCurve(const LogarithmicRegressionCurve & rOther)358 LogarithmicRegressionCurve::LogarithmicRegressionCurve(
359 const LogarithmicRegressionCurve & rOther ) :
360 RegressionCurveModel( rOther )
361 {}
~LogarithmicRegressionCurve()362 LogarithmicRegressionCurve::~LogarithmicRegressionCurve()
363 {}
getSupportedServiceNames_Static()364 uno::Sequence< ::rtl::OUString > LogarithmicRegressionCurve::getSupportedServiceNames_Static()
365 {
366 uno::Sequence< ::rtl::OUString > aServices( 2 );
367 aServices[ 0 ] = lcl_aServiceName;
368 aServices[ 1 ] = C2U( "com.sun.star.chart2.LogarithmicRegressionCurve" );
369 return aServices;
370 }
371 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
372 APPHELPER_XSERVICEINFO_IMPL( LogarithmicRegressionCurve, lcl_aImplementationName_Logarithmic );
373
createClone()374 uno::Reference< util::XCloneable > SAL_CALL LogarithmicRegressionCurve::createClone()
375 throw (uno::RuntimeException)
376 {
377 return uno::Reference< util::XCloneable >( new LogarithmicRegressionCurve( *this ));
378 }
379
380 // --------------------------------------------------------------------------------
381
ExponentialRegressionCurve(const uno::Reference<uno::XComponentContext> & xContext)382 ExponentialRegressionCurve::ExponentialRegressionCurve(
383 const uno::Reference< uno::XComponentContext > & xContext )
384 : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_EXPONENTIAL )
385 {}
ExponentialRegressionCurve(const ExponentialRegressionCurve & rOther)386 ExponentialRegressionCurve::ExponentialRegressionCurve(
387 const ExponentialRegressionCurve & rOther ) :
388 RegressionCurveModel( rOther )
389 {}
~ExponentialRegressionCurve()390 ExponentialRegressionCurve::~ExponentialRegressionCurve()
391 {}
getSupportedServiceNames_Static()392 uno::Sequence< ::rtl::OUString > ExponentialRegressionCurve::getSupportedServiceNames_Static()
393 {
394 uno::Sequence< ::rtl::OUString > aServices( 2 );
395 aServices[ 0 ] = lcl_aServiceName;
396 aServices[ 1 ] = C2U( "com.sun.star.chart2.ExponentialRegressionCurve" );
397 return aServices;
398 }
399 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
400 APPHELPER_XSERVICEINFO_IMPL( ExponentialRegressionCurve, lcl_aImplementationName_Exponential );
401
createClone()402 uno::Reference< util::XCloneable > SAL_CALL ExponentialRegressionCurve::createClone()
403 throw (uno::RuntimeException)
404 {
405 return uno::Reference< util::XCloneable >( new ExponentialRegressionCurve( *this ));
406 }
407
408 // --------------------------------------------------------------------------------
409
PotentialRegressionCurve(const uno::Reference<uno::XComponentContext> & xContext)410 PotentialRegressionCurve::PotentialRegressionCurve(
411 const uno::Reference< uno::XComponentContext > & xContext )
412 : RegressionCurveModel( xContext, RegressionCurveModel::CURVE_TYPE_POWER )
413 {}
PotentialRegressionCurve(const PotentialRegressionCurve & rOther)414 PotentialRegressionCurve::PotentialRegressionCurve(
415 const PotentialRegressionCurve & rOther ) :
416 RegressionCurveModel( rOther )
417 {}
~PotentialRegressionCurve()418 PotentialRegressionCurve::~PotentialRegressionCurve()
419 {}
getSupportedServiceNames_Static()420 uno::Sequence< ::rtl::OUString > PotentialRegressionCurve::getSupportedServiceNames_Static()
421 {
422 uno::Sequence< ::rtl::OUString > aServices( 2 );
423 aServices[ 0 ] = lcl_aServiceName;
424 aServices[ 1 ] = C2U( "com.sun.star.chart2.PotentialRegressionCurve" );
425 return aServices;
426 }
427 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
428 APPHELPER_XSERVICEINFO_IMPL( PotentialRegressionCurve, lcl_aImplementationName_Potential );
429
createClone()430 uno::Reference< util::XCloneable > SAL_CALL PotentialRegressionCurve::createClone()
431 throw (uno::RuntimeException)
432 {
433 return uno::Reference< util::XCloneable >( new PotentialRegressionCurve( *this ));
434 }
435
436
437 } // namespace chart
438