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: WrappedScaleProperty.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"
34 #include "WrappedScaleProperty.hxx"
36 #include "CommonConverters.hxx"
37 #include "AxisHelper.hxx"
38 #include <com/sun/star/chart2/XAxis.hpp>
39 #include <com/sun/star/chart2/ExplicitIncrementData.hpp>
40 #include <com/sun/star/chart2/ExplicitScaleData.hpp>
41 #include <com/sun/star/chart2/AxisOrientation.hpp>
43 using namespace ::com::sun::star
;
44 using ::com::sun::star::uno::Any
;
45 using namespace ::com::sun::star::chart2
;
46 using ::com::sun::star::uno::Reference
;
47 using ::com::sun::star::uno::Sequence
;
48 using ::rtl::OUString
;
50 //.............................................................................
56 WrappedScaleProperty::WrappedScaleProperty( tScaleProperty eScaleProperty
57 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
58 : WrappedProperty(OUString(),OUString())
59 , m_spChart2ModelContact( spChart2ModelContact
)
60 , m_eScaleProperty( eScaleProperty
)
62 switch( m_eScaleProperty
)
65 m_aOuterName
= C2U("Max");
68 m_aOuterName
= C2U("Min");
70 case SCALE_PROP_ORIGIN
:
71 m_aOuterName
= C2U("Origin");
73 case SCALE_PROP_STEPMAIN
:
74 m_aOuterName
= C2U("StepMain");
76 case SCALE_PROP_STEPHELP
:
77 m_aOuterName
= C2U("StepHelp");
79 case SCALE_PROP_STEPHELP_COUNT
:
80 m_aOuterName
= C2U("StepHelpCount");
82 case SCALE_PROP_AUTO_MAX
:
83 m_aOuterName
= C2U("AutoMax");
85 case SCALE_PROP_AUTO_MIN
:
86 m_aOuterName
= C2U("AutoMin");
88 case SCALE_PROP_AUTO_ORIGIN
:
89 m_aOuterName
= C2U("AutoOrigin");
91 case SCALE_PROP_AUTO_STEPMAIN
:
92 m_aOuterName
= C2U("AutoStepMain");
94 case SCALE_PROP_AUTO_STEPHELP
:
95 m_aOuterName
= C2U("AutoStepHelp");
97 case SCALE_PROP_LOGARITHMIC
:
98 m_aOuterName
= C2U("Logarithmic");
100 case SCALE_PROP_REVERSEDIRECTION
:
101 m_aOuterName
= C2U("ReverseDirection");
104 OSL_ENSURE(false,"unknown scale property");
109 WrappedScaleProperty::~WrappedScaleProperty()
114 void WrappedScaleProperty::addWrappedProperties( std::vector
< WrappedProperty
* >& rList
115 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
117 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_MAX
, spChart2ModelContact
) );
118 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_MIN
, spChart2ModelContact
) );
119 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_ORIGIN
, spChart2ModelContact
) );
120 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_STEPMAIN
, spChart2ModelContact
) );
121 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_STEPHELP
, spChart2ModelContact
) );
122 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_STEPHELP_COUNT
, spChart2ModelContact
) );
123 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_MAX
, spChart2ModelContact
) );
124 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_MIN
, spChart2ModelContact
) );
125 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_ORIGIN
, spChart2ModelContact
) );
126 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_STEPMAIN
, spChart2ModelContact
) );
127 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_STEPHELP
, spChart2ModelContact
) );
128 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_LOGARITHMIC
, spChart2ModelContact
) );
129 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_REVERSEDIRECTION
, spChart2ModelContact
) );
132 void WrappedScaleProperty::setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
133 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
135 setPropertyValue( m_eScaleProperty
, rOuterValue
, xInnerPropertySet
);
138 Any
WrappedScaleProperty::getPropertyValue( const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
139 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
141 return getPropertyValue( m_eScaleProperty
, xInnerPropertySet
);
144 void WrappedScaleProperty::setPropertyValue( tScaleProperty eScaleProperty
, const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
145 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
147 m_aOuterValue
= rOuterValue
;
149 Reference
< chart2::XAxis
> xAxis( xInnerPropertySet
, uno::UNO_QUERY
);
150 OSL_ENSURE(xAxis
.is(),"need an XAxis");
154 bool bSetScaleData
= false;
156 chart2::ScaleData
aScaleData( xAxis
->getScaleData() );
158 sal_Bool bBool
= false;
159 switch( eScaleProperty
)
163 aScaleData
.Maximum
= rOuterValue
;
164 bSetScaleData
= true;
169 aScaleData
.Minimum
= rOuterValue
;
170 bSetScaleData
= true;
173 case SCALE_PROP_STEPMAIN
:
175 aScaleData
.IncrementData
.Distance
= rOuterValue
;
176 bSetScaleData
= true;
179 case SCALE_PROP_STEPHELP
:
181 Sequence
< chart2::SubIncrement
>& rSubIncrements( aScaleData
.IncrementData
.SubIncrements
);
182 if( rSubIncrements
.getLength() == 0 )
183 rSubIncrements
.realloc( 1 );
185 double fStepMain
= 0, fStepHelp
= 0;
186 if( (rOuterValue
>>= fStepHelp
) )
188 if( AxisHelper::isLogarithmic(aScaleData
.Scaling
) )
190 sal_Int32 nIntervalCount
= static_cast< sal_Int32
>(fStepHelp
);
191 rSubIncrements
[ 0 ].IntervalCount
<<= nIntervalCount
;
193 else if( (fStepHelp
!= 0.0) &&
194 (aScaleData
.IncrementData
.Distance
>>= fStepMain
) )
196 // approximate interval count
197 sal_Int32 nIntervalCount
= static_cast< sal_Int32
>(fStepMain
/ fStepHelp
);
198 rSubIncrements
[ 0 ].IntervalCount
<<= nIntervalCount
;
201 bSetScaleData
= true;
204 case SCALE_PROP_STEPHELP_COUNT
:
206 Sequence
< chart2::SubIncrement
>& rSubIncrements( aScaleData
.IncrementData
.SubIncrements
);
207 if( rSubIncrements
.getLength() == 0 )
208 rSubIncrements
.realloc( 1 );
209 sal_Int32 nIntervalCount
=0;
210 if( rOuterValue
>>=nIntervalCount
)
211 rSubIncrements
[ 0 ].IntervalCount
<<= nIntervalCount
;
213 rSubIncrements
[ 0 ].IntervalCount
= Any();
214 bSetScaleData
= true;
217 case SCALE_PROP_AUTO_MAX
:
219 if( (rOuterValue
>>= bBool
) && bBool
)
220 aScaleData
.Maximum
= Any();
222 aScaleData
.Maximum
= getPropertyValue( SCALE_PROP_MAX
, xInnerPropertySet
);
223 bSetScaleData
= true;
226 case SCALE_PROP_AUTO_MIN
:
228 if( (rOuterValue
>>= bBool
) && bBool
)
229 aScaleData
.Minimum
= Any();
231 aScaleData
.Minimum
= getPropertyValue( SCALE_PROP_MIN
, xInnerPropertySet
);
232 bSetScaleData
= true;
235 case SCALE_PROP_AUTO_STEPMAIN
:
237 if( (rOuterValue
>>= bBool
) && bBool
)
238 aScaleData
.IncrementData
.Distance
= Any();
240 aScaleData
.IncrementData
.Distance
= getPropertyValue( SCALE_PROP_STEPMAIN
, xInnerPropertySet
);
241 bSetScaleData
= true;
244 case SCALE_PROP_AUTO_STEPHELP
:
246 Sequence
< chart2::SubIncrement
>& rSubIncrements( aScaleData
.IncrementData
.SubIncrements
);
247 if( rSubIncrements
.getLength() == 0 )
248 rSubIncrements
.realloc( 1 );
250 if( (rOuterValue
>>= bBool
) && bBool
)
251 rSubIncrements
[ 0 ].IntervalCount
= Any();
253 rSubIncrements
[ 0 ].IntervalCount
= getPropertyValue( SCALE_PROP_STEPHELP_COUNT
, xInnerPropertySet
);
254 bSetScaleData
= true;
257 case SCALE_PROP_ORIGIN
:
259 aScaleData
.Origin
= rOuterValue
;
260 bSetScaleData
= true;
263 case SCALE_PROP_AUTO_ORIGIN
:
265 if( (rOuterValue
>>= bBool
) && bBool
)
266 aScaleData
.Origin
= Any();
268 aScaleData
.Origin
= getPropertyValue( SCALE_PROP_ORIGIN
, xInnerPropertySet
);
269 bSetScaleData
= true;
272 case SCALE_PROP_LOGARITHMIC
:
274 if( rOuterValue
>>= bBool
)
276 bool bWasLogarithm
= AxisHelper::isLogarithmic( aScaleData
.Scaling
);
278 // safe comparison between sal_Bool and bool
279 if( (!bBool
) != (!bWasLogarithm
) )
282 aScaleData
.Scaling
= AxisHelper::createLogarithmicScaling( 10.0 );
284 aScaleData
.Scaling
= 0;
285 bSetScaleData
= true;
290 case SCALE_PROP_REVERSEDIRECTION
:
292 if( rOuterValue
>>= bBool
)
294 bool bWasReverse
= ( AxisOrientation_REVERSE
== aScaleData
.Orientation
);
295 if( (!bBool
) != (!bWasReverse
) ) // safe comparison between sal_Bool and bool
297 aScaleData
.Orientation
= bBool
? AxisOrientation_REVERSE
: AxisOrientation_MATHEMATICAL
;
298 bSetScaleData
= true;
305 OSL_ENSURE(false,"unknown scale property");
311 xAxis
->setScaleData( aScaleData
);
314 Any
WrappedScaleProperty::getPropertyValue( tScaleProperty eScaleProperty
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
315 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
317 Any
aRet( m_aOuterValue
);
319 Reference
< chart2::XAxis
> xAxis( xInnerPropertySet
, uno::UNO_QUERY
);
320 OSL_ENSURE(xAxis
.is(),"need an XAxis");
324 chart2::ScaleData
aScaleData( xAxis
->getScaleData() );
326 chart2::ExplicitScaleData aExplicitScale
;
327 chart2::ExplicitIncrementData aExplicitIncrement
;
329 switch( eScaleProperty
)
333 aRet
= aScaleData
.Maximum
;
334 if( !aRet
.hasValue() )
336 m_spChart2ModelContact
->getExplicitValuesForAxis(
337 xAxis
, aExplicitScale
, aExplicitIncrement
);
338 aRet
<<= aExplicitScale
.Maximum
;
344 aRet
= aScaleData
.Minimum
;
345 if( !aRet
.hasValue() )
347 m_spChart2ModelContact
->getExplicitValuesForAxis(
348 xAxis
, aExplicitScale
, aExplicitIncrement
);
349 aRet
<<= aExplicitScale
.Minimum
;
354 case SCALE_PROP_STEPMAIN
:
356 aRet
= aScaleData
.IncrementData
.Distance
;
357 if( !aRet
.hasValue() )
359 m_spChart2ModelContact
->getExplicitValuesForAxis(
360 xAxis
, aExplicitScale
, aExplicitIncrement
);
361 aRet
<<= aExplicitIncrement
.Distance
;
365 case SCALE_PROP_STEPHELP
:
367 // todo: evaluate PostEquidistant
368 bool bNeedToCalculateExplicitValues
= true;
370 bool bLogarithmic( AxisHelper::isLogarithmic(aScaleData
.Scaling
) );
371 Sequence
< chart2::SubIncrement
>& rSubIncrements( aScaleData
.IncrementData
.SubIncrements
);
374 if( rSubIncrements
.getLength() > 0 )
376 sal_Int32 nIntervalCount
= 0;
377 rSubIncrements
[ 0 ].IntervalCount
>>= nIntervalCount
;
378 aRet
= uno::makeAny( double(nIntervalCount
) );
379 bNeedToCalculateExplicitValues
= false;
382 else if( aScaleData
.IncrementData
.Distance
.hasValue() )
384 if( rSubIncrements
.getLength() > 0 )
386 double fStepMain
= 0;
387 sal_Int32 nIntervalCount
= 0;
388 if( (aScaleData
.IncrementData
.Distance
>>= fStepMain
) &&
389 (rSubIncrements
[ 0 ].IntervalCount
>>= nIntervalCount
) &&
392 aRet
<<= ( fStepMain
/ static_cast< double >( nIntervalCount
) );
393 bNeedToCalculateExplicitValues
= false;
398 aRet
= aScaleData
.IncrementData
.Distance
;
399 bNeedToCalculateExplicitValues
= false;
403 if( bNeedToCalculateExplicitValues
)
405 m_spChart2ModelContact
->getExplicitValuesForAxis(
406 xAxis
, aExplicitScale
, aExplicitIncrement
);
407 if( aExplicitIncrement
.SubIncrements
.getLength() > 0 &&
408 aExplicitIncrement
.SubIncrements
[ 0 ].IntervalCount
> 0 )
412 if( rSubIncrements
.getLength() > 0 )
414 sal_Int32 nIntervalCount
= aExplicitIncrement
.SubIncrements
[ 0 ].IntervalCount
;
415 aRet
= uno::makeAny( double(nIntervalCount
) );
419 aRet
<<= ( aExplicitIncrement
.Distance
/
420 static_cast< double >(
421 aExplicitIncrement
.SubIncrements
[ 0 ].IntervalCount
));
428 aRet
<<= aExplicitIncrement
.Distance
;
433 case SCALE_PROP_STEPHELP_COUNT
:
435 sal_Int32 nIntervalCount
= 0;
436 bool bNeedToCalculateExplicitValues
= true;
437 Sequence
< chart2::SubIncrement
>& rSubIncrements( aScaleData
.IncrementData
.SubIncrements
);
438 if( rSubIncrements
.getLength() > 0 )
440 if( (rSubIncrements
[ 0 ].IntervalCount
>>= nIntervalCount
) && (nIntervalCount
> 0) )
441 bNeedToCalculateExplicitValues
= false;
443 if( bNeedToCalculateExplicitValues
)
445 m_spChart2ModelContact
->getExplicitValuesForAxis( xAxis
, aExplicitScale
, aExplicitIncrement
);
446 if( aExplicitIncrement
.SubIncrements
.getLength() > 0 )
447 nIntervalCount
= aExplicitIncrement
.SubIncrements
[ 0 ].IntervalCount
;
449 aRet
= uno::makeAny( nIntervalCount
);
452 case SCALE_PROP_AUTO_MAX
:
454 aRet
<<= (sal_Bool
)( !aScaleData
.Maximum
.hasValue() );
457 case SCALE_PROP_AUTO_MIN
:
459 aRet
<<= (sal_Bool
)( !aScaleData
.Minimum
.hasValue() );
462 case SCALE_PROP_AUTO_STEPMAIN
:
464 aRet
<<= (sal_Bool
)( !aScaleData
.IncrementData
.Distance
.hasValue() );
467 case SCALE_PROP_AUTO_STEPHELP
:
469 Sequence
< chart2::SubIncrement
>& rSubIncrements( aScaleData
.IncrementData
.SubIncrements
);
470 if( rSubIncrements
.getLength() > 0 )
471 aRet
<<= (sal_Bool
)( !rSubIncrements
[ 0 ].IntervalCount
.hasValue() );
476 case SCALE_PROP_ORIGIN
:
478 aRet
= aScaleData
.Origin
;
479 if( !aRet
.hasValue() )
481 m_spChart2ModelContact
->getExplicitValuesForAxis(
482 xAxis
, aExplicitScale
, aExplicitIncrement
);
483 aRet
<<= aExplicitScale
.Origin
;
487 case SCALE_PROP_AUTO_ORIGIN
:
489 aRet
<<= !hasDoubleValue(aScaleData
.Origin
);
492 case SCALE_PROP_LOGARITHMIC
:
494 aRet
<<= static_cast< sal_Bool
>( AxisHelper::isLogarithmic(aScaleData
.Scaling
) );
497 case SCALE_PROP_REVERSEDIRECTION
:
499 aRet
<<= static_cast< sal_Bool
>( AxisOrientation_REVERSE
== aScaleData
.Orientation
);
504 OSL_ENSURE(false,"unknown scale property");
512 } // namespace wrapper
514 //.............................................................................