1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 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" 33 34 namespace 35 { 36 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" )); 45 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" )); 54 } 55 56 //............................................................................. 57 namespace chart 58 { 59 //............................................................................. 60 using namespace ::com::sun::star; 61 using namespace ::com::sun::star::chart2; 62 63 LogarithmicScaling::LogarithmicScaling( const uno::Reference< uno::XComponentContext > & xContext ) : 64 m_fBase( 10.0 ), 65 m_fLogOfBase( log( 10.0 ) ), 66 m_xContext( xContext ) 67 { 68 } 69 70 LogarithmicScaling::LogarithmicScaling( double fBase ) : 71 m_fBase( fBase ), 72 m_fLogOfBase( log( fBase ) ) 73 { 74 } 75 76 LogarithmicScaling::~LogarithmicScaling() 77 { 78 } 79 80 double SAL_CALL 81 LogarithmicScaling::doScaling( double value ) 82 throw (uno::RuntimeException) 83 { 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; 90 } 91 92 uno::Reference< XScaling > SAL_CALL 93 LogarithmicScaling::getInverseScaling() 94 throw (uno::RuntimeException) 95 { 96 return new ExponentialScaling( m_fBase ); 97 } 98 99 ::rtl::OUString SAL_CALL 100 LogarithmicScaling::getServiceName() 101 throw (uno::RuntimeException) 102 { 103 return lcl_aServiceName_Logarithmic; 104 } 105 106 uno::Sequence< ::rtl::OUString > LogarithmicScaling::getSupportedServiceNames_Static() 107 { 108 return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Logarithmic, 1 ); 109 } 110 111 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static 112 APPHELPER_XSERVICEINFO_IMPL( LogarithmicScaling, lcl_aServiceName_Logarithmic ) 113 114 // ---------------------------------------- 115 116 ExponentialScaling::ExponentialScaling( const uno::Reference< uno::XComponentContext > & xContext ) : 117 m_fBase( 10.0 ), 118 m_xContext( xContext ) 119 { 120 } 121 122 ExponentialScaling::ExponentialScaling( double fBase ) : 123 m_fBase( fBase ) 124 { 125 } 126 127 ExponentialScaling::~ExponentialScaling() 128 { 129 } 130 131 double SAL_CALL 132 ExponentialScaling::doScaling( double value ) 133 throw (uno::RuntimeException) 134 { 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; 141 } 142 143 uno::Reference< XScaling > SAL_CALL 144 ExponentialScaling::getInverseScaling() 145 throw (uno::RuntimeException) 146 { 147 return new LogarithmicScaling( m_fBase ); 148 } 149 150 ::rtl::OUString SAL_CALL 151 ExponentialScaling::getServiceName() 152 throw (uno::RuntimeException) 153 { 154 return lcl_aServiceName_Exponential; 155 } 156 157 uno::Sequence< ::rtl::OUString > ExponentialScaling::getSupportedServiceNames_Static() 158 { 159 return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Exponential, 1 ); 160 } 161 162 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static 163 APPHELPER_XSERVICEINFO_IMPL( ExponentialScaling, lcl_aServiceName_Exponential ) 164 165 // ---------------------------------------- 166 167 LinearScaling::LinearScaling( const uno::Reference< uno::XComponentContext > & xContext ) : 168 m_fSlope( 1.0 ), 169 m_fOffset( 0.0 ), 170 m_xContext( xContext ) 171 {} 172 173 LinearScaling::LinearScaling( double fSlope, double fOffset ) : 174 m_fSlope( fSlope ), 175 m_fOffset( fOffset ) 176 {} 177 178 LinearScaling::~LinearScaling() 179 {} 180 181 double SAL_CALL LinearScaling::doScaling( double value ) 182 throw (uno::RuntimeException) 183 { 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; 190 } 191 192 uno::Reference< XScaling > SAL_CALL 193 LinearScaling::getInverseScaling() 194 throw (uno::RuntimeException) 195 { 196 // ToDo: ApproxEqual ? 197 if( m_fSlope == 0 ) 198 throw uno::RuntimeException(); 199 200 return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope ); 201 } 202 203 ::rtl::OUString SAL_CALL 204 LinearScaling::getServiceName() 205 throw (uno::RuntimeException) 206 { 207 return lcl_aServiceName_Linear; 208 } 209 210 uno::Sequence< ::rtl::OUString > LinearScaling::getSupportedServiceNames_Static() 211 { 212 return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Linear, 1 ); 213 } 214 215 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static 216 APPHELPER_XSERVICEINFO_IMPL( LinearScaling, lcl_aServiceName_Linear ) 217 218 // ---------------------------------------- 219 220 PowerScaling::PowerScaling( const uno::Reference< uno::XComponentContext > & xContext ) : 221 m_fExponent( 10.0 ), 222 m_xContext( xContext ) 223 {} 224 225 PowerScaling::PowerScaling( double fExponent ) : 226 m_fExponent( fExponent ) 227 {} 228 229 PowerScaling::~PowerScaling() 230 {} 231 232 double SAL_CALL PowerScaling::doScaling( double value ) 233 throw (uno::RuntimeException) 234 { 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; 241 } 242 243 uno::Reference< XScaling > SAL_CALL 244 PowerScaling::getInverseScaling() 245 throw (uno::RuntimeException) 246 { 247 // ToDo: ApproxEqual ? 248 if( m_fExponent == 0 ) 249 throw uno::RuntimeException(); 250 251 return new PowerScaling( 1.0 / m_fExponent ); 252 } 253 254 ::rtl::OUString SAL_CALL 255 PowerScaling::getServiceName() 256 throw (uno::RuntimeException) 257 { 258 return lcl_aServiceName_Power; 259 } 260 261 uno::Sequence< ::rtl::OUString > PowerScaling::getSupportedServiceNames_Static() 262 { 263 return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Power, 1 ); 264 } 265 266 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static 267 APPHELPER_XSERVICEINFO_IMPL( PowerScaling, lcl_aServiceName_Power ) 268 269 //............................................................................. 270 } //namespace chart 271 //............................................................................. 272