bump product version to 5.0.4.1
[LibreOffice.git] / chart2 / source / tools / Scaling.cxx
blob87237d0154afaaefa7bb28047e9680836d35c9d3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "Scaling.hxx"
21 #include <rtl/math.hxx>
22 #include "com/sun/star/uno/RuntimeException.hpp"
23 #include <cppuhelper/supportsservice.hxx>
25 namespace
28 static const char lcl_aServiceName_Logarithmic[] = "com.sun.star.chart2.LogarithmicScaling";
29 static const char lcl_aServiceName_Exponential[] = "com.sun.star.chart2.ExponentialScaling";
30 static const char lcl_aServiceName_Linear[] = "com.sun.star.chart2.LinearScaling";
31 static const char lcl_aServiceName_Power[] = "com.sun.star.chart2.PowerScaling";
35 namespace chart
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::chart2;
40 LogarithmicScaling::LogarithmicScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
41 m_fBase( 10.0 ),
42 m_fLogOfBase( log( 10.0 ) ),
43 m_xContext( xContext )
47 LogarithmicScaling::LogarithmicScaling( double fBase ) :
48 m_fBase( fBase ),
49 m_fLogOfBase( log( fBase ) )
53 LogarithmicScaling::~LogarithmicScaling()
57 double SAL_CALL LogarithmicScaling::doScaling( double value )
58 throw (uno::RuntimeException, std::exception)
60 double fResult;
61 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
62 ::rtl::math::setNan( & fResult );
63 else
64 fResult = log( value ) / m_fLogOfBase;
65 return fResult;
68 uno::Reference< XScaling > SAL_CALL LogarithmicScaling::getInverseScaling()
69 throw (uno::RuntimeException, std::exception)
71 return new ExponentialScaling( m_fBase );
74 OUString SAL_CALL LogarithmicScaling::getServiceName()
75 throw (uno::RuntimeException, std::exception)
77 return OUString(lcl_aServiceName_Logarithmic);
80 uno::Sequence< OUString > LogarithmicScaling::getSupportedServiceNames_Static()
82 uno::Sequence< OUString > aSeq(1);
83 aSeq.getArray()[0] = lcl_aServiceName_Logarithmic;
84 return aSeq;
87 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
88 OUString SAL_CALL LogarithmicScaling::getImplementationName()
89 throw( css::uno::RuntimeException, std::exception )
91 return getImplementationName_Static();
94 OUString LogarithmicScaling::getImplementationName_Static()
96 return OUString(lcl_aServiceName_Logarithmic);
99 sal_Bool SAL_CALL LogarithmicScaling::supportsService( const OUString& rServiceName )
100 throw( css::uno::RuntimeException, std::exception )
102 return cppu::supportsService(this, rServiceName);
105 css::uno::Sequence< OUString > SAL_CALL LogarithmicScaling::getSupportedServiceNames()
106 throw( css::uno::RuntimeException, std::exception )
108 return getSupportedServiceNames_Static();
111 ExponentialScaling::ExponentialScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
112 m_fBase( 10.0 ),
113 m_xContext( xContext )
117 ExponentialScaling::ExponentialScaling( double fBase ) :
118 m_fBase( fBase )
122 ExponentialScaling::~ExponentialScaling()
126 double SAL_CALL ExponentialScaling::doScaling( double value )
127 throw (uno::RuntimeException, std::exception)
129 double fResult;
130 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
131 ::rtl::math::setNan( & fResult );
132 else
133 fResult = pow( m_fBase, value );
134 return fResult;
137 uno::Reference< XScaling > SAL_CALL ExponentialScaling::getInverseScaling()
138 throw (uno::RuntimeException, std::exception)
140 return new LogarithmicScaling( m_fBase );
143 OUString SAL_CALL ExponentialScaling::getServiceName()
144 throw (uno::RuntimeException, std::exception)
146 return OUString(lcl_aServiceName_Exponential);
149 uno::Sequence< OUString > ExponentialScaling::getSupportedServiceNames_Static()
151 uno::Sequence< OUString > aSeq(1);
152 aSeq.getArray()[0] = lcl_aServiceName_Exponential;
153 return aSeq;
156 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
157 OUString SAL_CALL ExponentialScaling::getImplementationName()
158 throw( css::uno::RuntimeException, std::exception )
160 return getImplementationName_Static();
163 OUString ExponentialScaling::getImplementationName_Static()
165 return OUString(lcl_aServiceName_Exponential);
168 sal_Bool SAL_CALL ExponentialScaling::supportsService( const OUString& rServiceName )
169 throw( css::uno::RuntimeException, std::exception )
171 return cppu::supportsService(this, rServiceName);
174 css::uno::Sequence< OUString > SAL_CALL ExponentialScaling::getSupportedServiceNames()
175 throw( css::uno::RuntimeException, std::exception )
177 return getSupportedServiceNames_Static();
180 LinearScaling::LinearScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
181 m_fSlope( 1.0 ),
182 m_fOffset( 0.0 ),
183 m_xContext( xContext )
186 LinearScaling::LinearScaling( double fSlope, double fOffset ) :
187 m_fSlope( fSlope ),
188 m_fOffset( fOffset )
191 LinearScaling::~LinearScaling()
194 double SAL_CALL LinearScaling::doScaling( double value )
195 throw (uno::RuntimeException, std::exception)
197 double fResult;
198 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
199 ::rtl::math::setNan( & fResult );
200 else
201 fResult = m_fOffset + m_fSlope * value;
202 return fResult;
205 uno::Reference< XScaling > SAL_CALL
206 LinearScaling::getInverseScaling()
207 throw (uno::RuntimeException, std::exception)
209 // ToDo: ApproxEqual ?
210 if( m_fSlope == 0 )
211 throw uno::RuntimeException();
213 return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope );
216 OUString SAL_CALL LinearScaling::getServiceName()
217 throw (uno::RuntimeException, std::exception)
219 return OUString(lcl_aServiceName_Linear);
222 uno::Sequence< OUString > LinearScaling::getSupportedServiceNames_Static()
224 uno::Sequence< OUString > aSeq(1);
225 aSeq.getArray()[0] = lcl_aServiceName_Linear;
226 return aSeq;
229 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
230 OUString SAL_CALL LinearScaling::getImplementationName()
231 throw( css::uno::RuntimeException, std::exception )
233 return getImplementationName_Static();
236 OUString LinearScaling::getImplementationName_Static()
238 return OUString(lcl_aServiceName_Linear) ;
241 sal_Bool SAL_CALL LinearScaling::supportsService( const OUString& rServiceName )
242 throw( css::uno::RuntimeException, std::exception )
244 return cppu::supportsService(this, rServiceName);
247 css::uno::Sequence< OUString > SAL_CALL LinearScaling::getSupportedServiceNames()
248 throw( css::uno::RuntimeException, std::exception )
250 return getSupportedServiceNames_Static();
253 PowerScaling::PowerScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
254 m_fExponent( 10.0 ),
255 m_xContext( xContext )
258 PowerScaling::PowerScaling( double fExponent ) :
259 m_fExponent( fExponent )
262 PowerScaling::~PowerScaling()
265 double SAL_CALL PowerScaling::doScaling( double value )
266 throw (uno::RuntimeException, std::exception)
268 double fResult;
269 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
270 ::rtl::math::setNan( & fResult );
271 else
272 fResult = pow( value, m_fExponent );
273 return fResult;
276 uno::Reference< XScaling > SAL_CALL
277 PowerScaling::getInverseScaling()
278 throw (uno::RuntimeException, std::exception)
280 // ToDo: ApproxEqual ?
281 if( m_fExponent == 0 )
282 throw uno::RuntimeException();
284 return new PowerScaling( 1.0 / m_fExponent );
287 OUString SAL_CALL
288 PowerScaling::getServiceName()
289 throw (uno::RuntimeException, std::exception)
291 return OUString(lcl_aServiceName_Power);
294 uno::Sequence< OUString > PowerScaling::getSupportedServiceNames_Static()
296 uno::Sequence< OUString > aSeq(1);
297 aSeq.getArray()[0] = lcl_aServiceName_Power;
298 return aSeq;
301 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
302 OUString SAL_CALL PowerScaling::getImplementationName()
303 throw( css::uno::RuntimeException, std::exception )
305 return getImplementationName_Static();
308 OUString PowerScaling::getImplementationName_Static()
310 return OUString(lcl_aServiceName_Power);
313 sal_Bool SAL_CALL PowerScaling::supportsService( const OUString& rServiceName )
314 throw( css::uno::RuntimeException, std::exception )
316 return cppu::supportsService(this, rServiceName);
319 css::uno::Sequence< OUString > SAL_CALL PowerScaling::getSupportedServiceNames()
320 throw( css::uno::RuntimeException, std::exception )
322 return getSupportedServiceNames_Static();
325 } //namespace chart
327 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
328 com_sun_star_chart2_LinearScaling_get_implementation(css::uno::XComponentContext *context,
329 css::uno::Sequence<css::uno::Any> const &)
331 return cppu::acquire(new chart::LinearScaling(context));
334 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
335 com_sun_star_chart2_ExponentialScaling_get_implementation(css::uno::XComponentContext *context,
336 css::uno::Sequence<css::uno::Any> const &)
338 return cppu::acquire(new chart::ExponentialScaling(context));
341 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
342 com_sun_star_chart2_LogarithmicScaling_get_implementation(css::uno::XComponentContext *context,
343 css::uno::Sequence<css::uno::Any> const &)
345 return cppu::acquire(new chart::LogarithmicScaling(context));
348 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
349 com_sun_star_chart2_PowerScaling_get_implementation(css::uno::XComponentContext *context,
350 css::uno::Sequence<css::uno::Any> const &)
352 return cppu::acquire(new chart::PowerScaling(context));
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */