1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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";
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::chart2
;
40 LogarithmicScaling::LogarithmicScaling( const uno::Reference
< uno::XComponentContext
> & xContext
) :
42 m_fLogOfBase( log( 10.0 ) ),
43 m_xContext( xContext
)
47 LogarithmicScaling::LogarithmicScaling( double fBase
) :
49 m_fLogOfBase( log( fBase
) )
53 LogarithmicScaling::~LogarithmicScaling()
57 double SAL_CALL
LogarithmicScaling::doScaling( double value
)
58 throw (uno::RuntimeException
, std::exception
)
61 if( ::rtl::math::isNan( value
) || ::rtl::math::isInf( value
) )
62 ::rtl::math::setNan( & fResult
);
64 fResult
= log( value
) / m_fLogOfBase
;
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
;
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
) :
113 m_xContext( xContext
)
117 ExponentialScaling::ExponentialScaling( double fBase
) :
122 ExponentialScaling::~ExponentialScaling()
126 double SAL_CALL
ExponentialScaling::doScaling( double value
)
127 throw (uno::RuntimeException
, std::exception
)
130 if( ::rtl::math::isNan( value
) || ::rtl::math::isInf( value
) )
131 ::rtl::math::setNan( & fResult
);
133 fResult
= pow( m_fBase
, value
);
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
;
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
) :
183 m_xContext( xContext
)
186 LinearScaling::LinearScaling( double fSlope
, double fOffset
) :
191 LinearScaling::~LinearScaling()
194 double SAL_CALL
LinearScaling::doScaling( double value
)
195 throw (uno::RuntimeException
, std::exception
)
198 if( ::rtl::math::isNan( value
) || ::rtl::math::isInf( value
) )
199 ::rtl::math::setNan( & fResult
);
201 fResult
= m_fOffset
+ m_fSlope
* value
;
205 uno::Reference
< XScaling
> SAL_CALL
206 LinearScaling::getInverseScaling()
207 throw (uno::RuntimeException
, std::exception
)
209 // ToDo: ApproxEqual ?
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
;
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
) :
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
)
269 if( ::rtl::math::isNan( value
) || ::rtl::math::isInf( value
) )
270 ::rtl::math::setNan( & fResult
);
272 fResult
= pow( value
, m_fExponent
);
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
);
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
;
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();
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: */