merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / tools / Scaling.cxx
blobe106f1dcc5e24c6b0f0fd209ac53e9df2755e59f
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 "Scaling.hxx"
31 #include <rtl/math.hxx>
32 #include "com/sun/star/uno/RuntimeException.hpp"
34 namespace
37 static const ::rtl::OUString lcl_aServiceName_Logarithmic(
38 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LogarithmicScaling" ));
39 static const ::rtl::OUString lcl_aServiceName_Exponential(
40 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.ExponentialScaling" ));
41 static const ::rtl::OUString lcl_aServiceName_Linear(
42 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LinearScaling" ));
43 static const ::rtl::OUString lcl_aServiceName_Power(
44 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.PowerScaling" ));
46 static const ::rtl::OUString lcl_aImplementationName_Logarithmic(
47 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LogarithmicScaling" ));
48 static const ::rtl::OUString lcl_aImplementationName_Exponential(
49 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ExponentialScaling" ));
50 static const ::rtl::OUString lcl_aImplementationName_Linear(
51 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LinearScaling" ));
52 static const ::rtl::OUString lcl_aImplementationName_Power(
53 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PowerScaling" ));
56 //.............................................................................
57 namespace chart
59 //.............................................................................
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::chart2;
63 LogarithmicScaling::LogarithmicScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
64 m_fBase( 10.0 ),
65 m_fLogOfBase( log( 10.0 ) ),
66 m_xContext( xContext )
70 LogarithmicScaling::LogarithmicScaling( double fBase ) :
71 m_fBase( fBase ),
72 m_fLogOfBase( log( fBase ) )
76 LogarithmicScaling::~LogarithmicScaling()
80 double SAL_CALL
81 LogarithmicScaling::doScaling( double value )
82 throw (uno::RuntimeException)
84 double fResult;
85 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
86 ::rtl::math::setNan( & fResult );
87 else
88 fResult = log( value ) / m_fLogOfBase;
89 return fResult;
92 uno::Reference< XScaling > SAL_CALL
93 LogarithmicScaling::getInverseScaling()
94 throw (uno::RuntimeException)
96 return new ExponentialScaling( m_fBase );
99 ::rtl::OUString SAL_CALL
100 LogarithmicScaling::getServiceName()
101 throw (uno::RuntimeException)
103 return lcl_aServiceName_Logarithmic;
106 uno::Sequence< ::rtl::OUString > LogarithmicScaling::getSupportedServiceNames_Static()
108 return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Logarithmic, 1 );
111 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
112 APPHELPER_XSERVICEINFO_IMPL( LogarithmicScaling, lcl_aServiceName_Logarithmic )
114 // ----------------------------------------
116 ExponentialScaling::ExponentialScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
117 m_fBase( 10.0 ),
118 m_xContext( xContext )
122 ExponentialScaling::ExponentialScaling( double fBase ) :
123 m_fBase( fBase )
127 ExponentialScaling::~ExponentialScaling()
131 double SAL_CALL
132 ExponentialScaling::doScaling( double value )
133 throw (uno::RuntimeException)
135 double fResult;
136 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
137 ::rtl::math::setNan( & fResult );
138 else
139 fResult = pow( m_fBase, value );
140 return fResult;
143 uno::Reference< XScaling > SAL_CALL
144 ExponentialScaling::getInverseScaling()
145 throw (uno::RuntimeException)
147 return new LogarithmicScaling( m_fBase );
150 ::rtl::OUString SAL_CALL
151 ExponentialScaling::getServiceName()
152 throw (uno::RuntimeException)
154 return lcl_aServiceName_Exponential;
157 uno::Sequence< ::rtl::OUString > ExponentialScaling::getSupportedServiceNames_Static()
159 return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Exponential, 1 );
162 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
163 APPHELPER_XSERVICEINFO_IMPL( ExponentialScaling, lcl_aServiceName_Exponential )
165 // ----------------------------------------
167 LinearScaling::LinearScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
168 m_fSlope( 1.0 ),
169 m_fOffset( 0.0 ),
170 m_xContext( xContext )
173 LinearScaling::LinearScaling( double fSlope, double fOffset ) :
174 m_fSlope( fSlope ),
175 m_fOffset( fOffset )
178 LinearScaling::~LinearScaling()
181 double SAL_CALL LinearScaling::doScaling( double value )
182 throw (uno::RuntimeException)
184 double fResult;
185 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
186 ::rtl::math::setNan( & fResult );
187 else
188 fResult = m_fOffset + m_fSlope * value;
189 return fResult;
192 uno::Reference< XScaling > SAL_CALL
193 LinearScaling::getInverseScaling()
194 throw (uno::RuntimeException)
196 // ToDo: ApproxEqual ?
197 if( m_fSlope == 0 )
198 throw uno::RuntimeException();
200 return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope );
203 ::rtl::OUString SAL_CALL
204 LinearScaling::getServiceName()
205 throw (uno::RuntimeException)
207 return lcl_aServiceName_Linear;
210 uno::Sequence< ::rtl::OUString > LinearScaling::getSupportedServiceNames_Static()
212 return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Linear, 1 );
215 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
216 APPHELPER_XSERVICEINFO_IMPL( LinearScaling, lcl_aServiceName_Linear )
218 // ----------------------------------------
220 PowerScaling::PowerScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
221 m_fExponent( 10.0 ),
222 m_xContext( xContext )
225 PowerScaling::PowerScaling( double fExponent ) :
226 m_fExponent( fExponent )
229 PowerScaling::~PowerScaling()
232 double SAL_CALL PowerScaling::doScaling( double value )
233 throw (uno::RuntimeException)
235 double fResult;
236 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
237 ::rtl::math::setNan( & fResult );
238 else
239 fResult = pow( value, m_fExponent );
240 return fResult;
243 uno::Reference< XScaling > SAL_CALL
244 PowerScaling::getInverseScaling()
245 throw (uno::RuntimeException)
247 // ToDo: ApproxEqual ?
248 if( m_fExponent == 0 )
249 throw uno::RuntimeException();
251 return new PowerScaling( 1.0 / m_fExponent );
254 ::rtl::OUString SAL_CALL
255 PowerScaling::getServiceName()
256 throw (uno::RuntimeException)
258 return lcl_aServiceName_Power;
261 uno::Sequence< ::rtl::OUString > PowerScaling::getSupportedServiceNames_Static()
263 return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Power, 1 );
266 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
267 APPHELPER_XSERVICEINFO_IMPL( PowerScaling, lcl_aServiceName_Power )
269 //.............................................................................
270 } //namespace chart
271 //.............................................................................