1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Scaling.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "Scaling.hxx"
34 #include <rtl/math.hxx>
35 #include "com/sun/star/uno/RuntimeException.hpp"
40 static const ::rtl::OUString
lcl_aServiceName_Logarithmic(
41 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LogarithmicScaling" ));
42 static const ::rtl::OUString
lcl_aServiceName_Exponential(
43 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.ExponentialScaling" ));
44 static const ::rtl::OUString
lcl_aServiceName_Linear(
45 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LinearScaling" ));
46 static const ::rtl::OUString
lcl_aServiceName_Power(
47 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.PowerScaling" ));
49 static const ::rtl::OUString
lcl_aImplementationName_Logarithmic(
50 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LogarithmicScaling" ));
51 static const ::rtl::OUString
lcl_aImplementationName_Exponential(
52 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ExponentialScaling" ));
53 static const ::rtl::OUString
lcl_aImplementationName_Linear(
54 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.LinearScaling" ));
55 static const ::rtl::OUString
lcl_aImplementationName_Power(
56 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PowerScaling" ));
59 //.............................................................................
62 //.............................................................................
63 using namespace ::com::sun::star
;
64 using namespace ::com::sun::star::chart2
;
66 LogarithmicScaling::LogarithmicScaling( const uno::Reference
< uno::XComponentContext
> & xContext
) :
68 m_fLogOfBase( log( 10.0 ) ),
69 m_xContext( xContext
)
73 LogarithmicScaling::LogarithmicScaling( double fBase
) :
75 m_fLogOfBase( log( fBase
) )
79 LogarithmicScaling::~LogarithmicScaling()
84 LogarithmicScaling::doScaling( double value
)
85 throw (uno::RuntimeException
)
88 if( ::rtl::math::isNan( value
) || ::rtl::math::isInf( value
) )
89 ::rtl::math::setNan( & fResult
);
91 fResult
= log( value
) / m_fLogOfBase
;
95 uno::Reference
< XScaling
> SAL_CALL
96 LogarithmicScaling::getInverseScaling()
97 throw (uno::RuntimeException
)
99 return new ExponentialScaling( m_fBase
);
102 ::rtl::OUString SAL_CALL
103 LogarithmicScaling::getServiceName()
104 throw (uno::RuntimeException
)
106 return lcl_aServiceName_Logarithmic
;
109 uno::Sequence
< ::rtl::OUString
> LogarithmicScaling::getSupportedServiceNames_Static()
111 return uno::Sequence
< ::rtl::OUString
>( & lcl_aServiceName_Logarithmic
, 1 );
114 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
115 APPHELPER_XSERVICEINFO_IMPL( LogarithmicScaling
, lcl_aServiceName_Logarithmic
)
117 // ----------------------------------------
119 ExponentialScaling::ExponentialScaling( const uno::Reference
< uno::XComponentContext
> & xContext
) :
121 m_xContext( xContext
)
125 ExponentialScaling::ExponentialScaling( double fBase
) :
130 ExponentialScaling::~ExponentialScaling()
135 ExponentialScaling::doScaling( double value
)
136 throw (uno::RuntimeException
)
139 if( ::rtl::math::isNan( value
) || ::rtl::math::isInf( value
) )
140 ::rtl::math::setNan( & fResult
);
142 fResult
= pow( m_fBase
, value
);
146 uno::Reference
< XScaling
> SAL_CALL
147 ExponentialScaling::getInverseScaling()
148 throw (uno::RuntimeException
)
150 return new LogarithmicScaling( m_fBase
);
153 ::rtl::OUString SAL_CALL
154 ExponentialScaling::getServiceName()
155 throw (uno::RuntimeException
)
157 return lcl_aServiceName_Exponential
;
160 uno::Sequence
< ::rtl::OUString
> ExponentialScaling::getSupportedServiceNames_Static()
162 return uno::Sequence
< ::rtl::OUString
>( & lcl_aServiceName_Exponential
, 1 );
165 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
166 APPHELPER_XSERVICEINFO_IMPL( ExponentialScaling
, lcl_aServiceName_Exponential
)
168 // ----------------------------------------
170 LinearScaling::LinearScaling( const uno::Reference
< uno::XComponentContext
> & xContext
) :
173 m_xContext( xContext
)
176 LinearScaling::LinearScaling( double fSlope
, double fOffset
) :
181 LinearScaling::~LinearScaling()
184 double SAL_CALL
LinearScaling::doScaling( double value
)
185 throw (uno::RuntimeException
)
188 if( ::rtl::math::isNan( value
) || ::rtl::math::isInf( value
) )
189 ::rtl::math::setNan( & fResult
);
191 fResult
= m_fOffset
+ m_fSlope
* value
;
195 uno::Reference
< XScaling
> SAL_CALL
196 LinearScaling::getInverseScaling()
197 throw (uno::RuntimeException
)
199 // ToDo: ApproxEqual ?
201 throw uno::RuntimeException();
203 return new LinearScaling( 1.0 / m_fSlope
, m_fOffset
/ m_fSlope
);
206 ::rtl::OUString SAL_CALL
207 LinearScaling::getServiceName()
208 throw (uno::RuntimeException
)
210 return lcl_aServiceName_Linear
;
213 uno::Sequence
< ::rtl::OUString
> LinearScaling::getSupportedServiceNames_Static()
215 return uno::Sequence
< ::rtl::OUString
>( & lcl_aServiceName_Linear
, 1 );
218 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
219 APPHELPER_XSERVICEINFO_IMPL( LinearScaling
, lcl_aServiceName_Linear
)
221 // ----------------------------------------
223 PowerScaling::PowerScaling( const uno::Reference
< uno::XComponentContext
> & xContext
) :
225 m_xContext( xContext
)
228 PowerScaling::PowerScaling( double fExponent
) :
229 m_fExponent( fExponent
)
232 PowerScaling::~PowerScaling()
235 double SAL_CALL
PowerScaling::doScaling( double value
)
236 throw (uno::RuntimeException
)
239 if( ::rtl::math::isNan( value
) || ::rtl::math::isInf( value
) )
240 ::rtl::math::setNan( & fResult
);
242 fResult
= pow( value
, m_fExponent
);
246 uno::Reference
< XScaling
> SAL_CALL
247 PowerScaling::getInverseScaling()
248 throw (uno::RuntimeException
)
250 // ToDo: ApproxEqual ?
251 if( m_fExponent
== 0 )
252 throw uno::RuntimeException();
254 return new PowerScaling( 1.0 / m_fExponent
);
257 ::rtl::OUString SAL_CALL
258 PowerScaling::getServiceName()
259 throw (uno::RuntimeException
)
261 return lcl_aServiceName_Power
;
264 uno::Sequence
< ::rtl::OUString
> PowerScaling::getSupportedServiceNames_Static()
266 return uno::Sequence
< ::rtl::OUString
>( & lcl_aServiceName_Power
, 1 );
269 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
270 APPHELPER_XSERVICEINFO_IMPL( PowerScaling
, lcl_aServiceName_Power
)
272 //.............................................................................
274 //.............................................................................