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 "WrappedScaleProperty.hxx"
22 #include "CommonConverters.hxx"
23 #include "AxisHelper.hxx"
24 #include <com/sun/star/chart2/XAxis.hpp>
25 #include <com/sun/star/chart/ChartAxisType.hpp>
26 #include <chartview/ExplicitScaleValues.hxx>
28 using namespace ::com::sun::star
;
29 using ::com::sun::star::uno::Any
;
30 using namespace ::com::sun::star::chart2
;
31 using ::com::sun::star::uno::Reference
;
32 using ::com::sun::star::uno::Sequence
;
33 using ::com::sun::star::chart::TimeIncrement
;
40 WrappedScaleProperty::WrappedScaleProperty( tScaleProperty eScaleProperty
41 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
42 : WrappedProperty(OUString(),OUString())
43 , m_spChart2ModelContact( spChart2ModelContact
)
44 , m_eScaleProperty( eScaleProperty
)
46 switch( m_eScaleProperty
)
54 case SCALE_PROP_ORIGIN
:
55 m_aOuterName
= "Origin";
57 case SCALE_PROP_STEPMAIN
:
58 m_aOuterName
= "StepMain";
60 case SCALE_PROP_STEPHELP
:
61 m_aOuterName
= "StepHelp";
63 case SCALE_PROP_STEPHELP_COUNT
:
64 m_aOuterName
= "StepHelpCount";
66 case SCALE_PROP_AUTO_MAX
:
67 m_aOuterName
= "AutoMax";
69 case SCALE_PROP_AUTO_MIN
:
70 m_aOuterName
= "AutoMin";
72 case SCALE_PROP_AUTO_ORIGIN
:
73 m_aOuterName
= "AutoOrigin";
75 case SCALE_PROP_AUTO_STEPMAIN
:
76 m_aOuterName
= "AutoStepMain";
78 case SCALE_PROP_AUTO_STEPHELP
:
79 m_aOuterName
= "AutoStepHelp";
81 case SCALE_PROP_AXIS_TYPE
:
82 m_aOuterName
= "AxisType";
84 case SCALE_PROP_DATE_INCREMENT
:
85 m_aOuterName
= "TimeIncrement";
87 case SCALE_PROP_EXPLICIT_DATE_INCREMENT
:
88 m_aOuterName
= "ExplicitTimeIncrement";
90 case SCALE_PROP_LOGARITHMIC
:
91 m_aOuterName
= "Logarithmic";
93 case SCALE_PROP_REVERSEDIRECTION
:
94 m_aOuterName
= "ReverseDirection";
97 OSL_FAIL("unknown scale property");
102 WrappedScaleProperty::~WrappedScaleProperty()
106 void WrappedScaleProperty::addWrappedProperties( std::vector
< WrappedProperty
* >& rList
107 , ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
109 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_MAX
, spChart2ModelContact
) );
110 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_MIN
, spChart2ModelContact
) );
111 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_ORIGIN
, spChart2ModelContact
) );
112 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_STEPMAIN
, spChart2ModelContact
) );
113 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_STEPHELP
, spChart2ModelContact
) );
114 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_STEPHELP_COUNT
, spChart2ModelContact
) );
115 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_MAX
, spChart2ModelContact
) );
116 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_MIN
, spChart2ModelContact
) );
117 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_ORIGIN
, spChart2ModelContact
) );
118 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_STEPMAIN
, spChart2ModelContact
) );
119 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_AUTO_STEPHELP
, spChart2ModelContact
) );
120 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_AXIS_TYPE
, spChart2ModelContact
) );
121 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_DATE_INCREMENT
, spChart2ModelContact
) );
122 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_EXPLICIT_DATE_INCREMENT
, spChart2ModelContact
) );
123 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_LOGARITHMIC
, spChart2ModelContact
) );
124 rList
.push_back( new WrappedScaleProperty( SCALE_PROP_REVERSEDIRECTION
, spChart2ModelContact
) );
127 void WrappedScaleProperty::setPropertyValue( const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
128 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
130 setPropertyValue( m_eScaleProperty
, rOuterValue
, xInnerPropertySet
);
133 Any
WrappedScaleProperty::getPropertyValue( const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
134 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
136 return getPropertyValue( m_eScaleProperty
, xInnerPropertySet
);
139 void WrappedScaleProperty::setPropertyValue( tScaleProperty eScaleProperty
, const Any
& rOuterValue
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
140 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
142 m_aOuterValue
= rOuterValue
;
144 Reference
< chart2::XAxis
> xAxis( xInnerPropertySet
, uno::UNO_QUERY
);
145 OSL_ENSURE(xAxis
.is(),"need an XAxis");
149 bool bSetScaleData
= false;
151 chart2::ScaleData
aScaleData( xAxis
->getScaleData() );
154 switch( eScaleProperty
)
158 aScaleData
.Maximum
= rOuterValue
;
159 bSetScaleData
= true;
164 aScaleData
.Minimum
= rOuterValue
;
165 bSetScaleData
= true;
168 case SCALE_PROP_STEPMAIN
:
170 aScaleData
.IncrementData
.Distance
= rOuterValue
;
171 bSetScaleData
= true;
174 case SCALE_PROP_STEPHELP
:
176 Sequence
< chart2::SubIncrement
>& rSubIncrements( aScaleData
.IncrementData
.SubIncrements
);
177 if( rSubIncrements
.getLength() == 0 )
178 rSubIncrements
.realloc( 1 );
180 double fStepHelp
= 0;
181 if( (rOuterValue
>>= fStepHelp
) )
183 double fStepMain
= 0;
184 if( AxisHelper::isLogarithmic(aScaleData
.Scaling
) )
186 sal_Int32 nIntervalCount
= static_cast< sal_Int32
>(fStepHelp
);
187 rSubIncrements
[ 0 ].IntervalCount
<<= nIntervalCount
;
189 else if( (fStepHelp
!= 0.0) &&
190 (aScaleData
.IncrementData
.Distance
>>= fStepMain
) )
192 // approximate interval count
193 sal_Int32 nIntervalCount
= static_cast< sal_Int32
>(fStepMain
/ fStepHelp
);//cppcheck-suppress zerodiv
194 rSubIncrements
[ 0 ].IntervalCount
<<= nIntervalCount
;
197 bSetScaleData
= true;
200 case SCALE_PROP_STEPHELP_COUNT
:
202 Sequence
< chart2::SubIncrement
>& rSubIncrements( aScaleData
.IncrementData
.SubIncrements
);
203 if( rSubIncrements
.getLength() == 0 )
204 rSubIncrements
.realloc( 1 );
205 sal_Int32 nIntervalCount
=0;
206 if( rOuterValue
>>=nIntervalCount
)
207 rSubIncrements
[ 0 ].IntervalCount
<<= nIntervalCount
;
209 rSubIncrements
[ 0 ].IntervalCount
= Any();
210 bSetScaleData
= true;
213 case SCALE_PROP_AUTO_MAX
:
215 if( (rOuterValue
>>= bBool
) && bBool
)
216 aScaleData
.Maximum
= Any();
218 aScaleData
.Maximum
= getPropertyValue( SCALE_PROP_MAX
, xInnerPropertySet
);
219 bSetScaleData
= true;
222 case SCALE_PROP_AUTO_MIN
:
224 if( (rOuterValue
>>= bBool
) && bBool
)
225 aScaleData
.Minimum
= Any();
227 aScaleData
.Minimum
= getPropertyValue( SCALE_PROP_MIN
, xInnerPropertySet
);
228 bSetScaleData
= true;
231 case SCALE_PROP_AUTO_STEPMAIN
:
233 if( (rOuterValue
>>= bBool
) && bBool
)
234 aScaleData
.IncrementData
.Distance
= Any();
236 aScaleData
.IncrementData
.Distance
= getPropertyValue( SCALE_PROP_STEPMAIN
, xInnerPropertySet
);
237 bSetScaleData
= true;
240 case SCALE_PROP_AUTO_STEPHELP
:
242 Sequence
< chart2::SubIncrement
>& rSubIncrements( aScaleData
.IncrementData
.SubIncrements
);
243 if( rSubIncrements
.getLength() == 0 )
244 rSubIncrements
.realloc( 1 );
246 if( (rOuterValue
>>= bBool
) && bBool
)
247 rSubIncrements
[ 0 ].IntervalCount
= Any();
249 rSubIncrements
[ 0 ].IntervalCount
= getPropertyValue( SCALE_PROP_STEPHELP_COUNT
, xInnerPropertySet
);
250 bSetScaleData
= true;
253 case SCALE_PROP_ORIGIN
:
255 aScaleData
.Origin
= rOuterValue
;
256 bSetScaleData
= true;
259 case SCALE_PROP_AUTO_ORIGIN
:
261 if( (rOuterValue
>>= bBool
) && bBool
)
262 aScaleData
.Origin
= Any();
264 aScaleData
.Origin
= getPropertyValue( SCALE_PROP_ORIGIN
, xInnerPropertySet
);
265 bSetScaleData
= true;
268 case SCALE_PROP_AXIS_TYPE
:
271 if( (rOuterValue
>>= nType
) )
273 if( ::com::sun::star::chart::ChartAxisType::AUTOMATIC
== nType
)
275 aScaleData
.AutoDateAxis
= true;
276 if( aScaleData
.AxisType
== AxisType::DATE
)
277 aScaleData
.AxisType
= AxisType::CATEGORY
;
279 else if( ::com::sun::star::chart::ChartAxisType::CATEGORY
== nType
)
281 aScaleData
.AutoDateAxis
= false;
282 if( aScaleData
.AxisType
== AxisType::DATE
)
283 aScaleData
.AxisType
= AxisType::CATEGORY
;
285 else if( ::com::sun::star::chart::ChartAxisType::DATE
== nType
)
287 if( aScaleData
.AxisType
== AxisType::CATEGORY
)
288 aScaleData
.AxisType
= AxisType::DATE
;
290 bSetScaleData
= true;
294 case SCALE_PROP_DATE_INCREMENT
:
296 TimeIncrement aTimeIncrement
;
297 rOuterValue
>>= aTimeIncrement
;
298 aScaleData
.TimeIncrement
= aTimeIncrement
;
299 bSetScaleData
= true;
302 case SCALE_PROP_EXPLICIT_DATE_INCREMENT
:
305 case SCALE_PROP_LOGARITHMIC
:
307 if( rOuterValue
>>= bBool
)
309 bool bWasLogarithm
= AxisHelper::isLogarithmic( aScaleData
.Scaling
);
311 // safe comparison between sal_Bool and bool
312 if( (!bBool
) != (!bWasLogarithm
) )
315 aScaleData
.Scaling
= AxisHelper::createLogarithmicScaling( 10.0 );
317 aScaleData
.Scaling
= 0;
318 bSetScaleData
= true;
323 case SCALE_PROP_REVERSEDIRECTION
:
325 if( rOuterValue
>>= bBool
)
327 bool bWasReverse
= ( AxisOrientation_REVERSE
== aScaleData
.Orientation
);
328 if( (!bBool
) != (!bWasReverse
) ) // safe comparison between sal_Bool and bool
330 aScaleData
.Orientation
= bBool
? AxisOrientation_REVERSE
: AxisOrientation_MATHEMATICAL
;
331 bSetScaleData
= true;
338 OSL_FAIL("unknown scale property");
344 xAxis
->setScaleData( aScaleData
);
347 Any
WrappedScaleProperty::getPropertyValue( tScaleProperty eScaleProperty
, const Reference
< beans::XPropertySet
>& xInnerPropertySet
) const
348 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
350 Any
aRet( m_aOuterValue
);
352 Reference
< chart2::XAxis
> xAxis( xInnerPropertySet
, uno::UNO_QUERY
);
353 OSL_ENSURE(xAxis
.is(),"need an XAxis");
357 chart2::ScaleData
aScaleData( xAxis
->getScaleData() );
359 ExplicitScaleData aExplicitScale
;
360 ExplicitIncrementData aExplicitIncrement
;
362 switch( eScaleProperty
)
366 aRet
= aScaleData
.Maximum
;
367 if( !aRet
.hasValue() )
369 m_spChart2ModelContact
->getExplicitValuesForAxis(
370 xAxis
, aExplicitScale
, aExplicitIncrement
);
371 aRet
<<= aExplicitScale
.Maximum
;
377 aRet
= aScaleData
.Minimum
;
378 if( !aRet
.hasValue() )
380 m_spChart2ModelContact
->getExplicitValuesForAxis(
381 xAxis
, aExplicitScale
, aExplicitIncrement
);
382 aRet
<<= aExplicitScale
.Minimum
;
387 case SCALE_PROP_STEPMAIN
:
389 aRet
= aScaleData
.IncrementData
.Distance
;
390 if( !aRet
.hasValue() )
392 m_spChart2ModelContact
->getExplicitValuesForAxis(
393 xAxis
, aExplicitScale
, aExplicitIncrement
);
394 aRet
<<= aExplicitIncrement
.Distance
;
398 case SCALE_PROP_STEPHELP
:
400 // todo: evaluate PostEquidistant
401 bool bNeedToCalculateExplicitValues
= true;
403 bool bLogarithmic( AxisHelper::isLogarithmic(aScaleData
.Scaling
) );
404 Sequence
< chart2::SubIncrement
>& rSubIncrements( aScaleData
.IncrementData
.SubIncrements
);
407 if( rSubIncrements
.getLength() > 0 )
409 sal_Int32 nIntervalCount
= 0;
410 rSubIncrements
[ 0 ].IntervalCount
>>= nIntervalCount
;
411 aRet
= uno::makeAny( double(nIntervalCount
) );
412 bNeedToCalculateExplicitValues
= false;
415 else if( aScaleData
.IncrementData
.Distance
.hasValue() )
417 if( rSubIncrements
.getLength() > 0 )
419 double fStepMain
= 0;
420 sal_Int32 nIntervalCount
= 0;
421 if( (aScaleData
.IncrementData
.Distance
>>= fStepMain
) &&
422 (rSubIncrements
[ 0 ].IntervalCount
>>= nIntervalCount
) &&
425 aRet
<<= ( fStepMain
/ static_cast< double >( nIntervalCount
) );
426 bNeedToCalculateExplicitValues
= false;
431 aRet
= aScaleData
.IncrementData
.Distance
;
432 bNeedToCalculateExplicitValues
= false;
436 if( bNeedToCalculateExplicitValues
)
438 m_spChart2ModelContact
->getExplicitValuesForAxis(
439 xAxis
, aExplicitScale
, aExplicitIncrement
);
441 if( !aExplicitIncrement
.SubIncrements
.empty() &&
442 aExplicitIncrement
.SubIncrements
[ 0 ].IntervalCount
> 0 )
446 if( rSubIncrements
.getLength() > 0 )
448 sal_Int32 nIntervalCount
= aExplicitIncrement
.SubIncrements
[ 0 ].IntervalCount
;
449 aRet
= uno::makeAny( double(nIntervalCount
) );
453 aRet
<<= ( aExplicitIncrement
.Distance
/
454 static_cast< double >(
455 aExplicitIncrement
.SubIncrements
[ 0 ].IntervalCount
));
462 aRet
<<= aExplicitIncrement
.Distance
;
467 case SCALE_PROP_STEPHELP_COUNT
:
469 sal_Int32 nIntervalCount
= 0;
470 bool bNeedToCalculateExplicitValues
= true;
471 Sequence
< chart2::SubIncrement
>& rSubIncrements( aScaleData
.IncrementData
.SubIncrements
);
472 if( rSubIncrements
.getLength() > 0 )
474 if( (rSubIncrements
[ 0 ].IntervalCount
>>= nIntervalCount
) && (nIntervalCount
> 0) )
475 bNeedToCalculateExplicitValues
= false;
477 if( bNeedToCalculateExplicitValues
)
479 m_spChart2ModelContact
->getExplicitValuesForAxis( xAxis
, aExplicitScale
, aExplicitIncrement
);
480 if( !aExplicitIncrement
.SubIncrements
.empty() )
481 nIntervalCount
= aExplicitIncrement
.SubIncrements
[ 0 ].IntervalCount
;
483 aRet
= uno::makeAny( nIntervalCount
);
486 case SCALE_PROP_AUTO_MAX
:
488 aRet
<<= !aScaleData
.Maximum
.hasValue();
491 case SCALE_PROP_AUTO_MIN
:
493 aRet
<<= !aScaleData
.Minimum
.hasValue();
496 case SCALE_PROP_AUTO_STEPMAIN
:
498 aRet
<<= !aScaleData
.IncrementData
.Distance
.hasValue();
501 case SCALE_PROP_AUTO_STEPHELP
:
503 Sequence
< chart2::SubIncrement
>& rSubIncrements( aScaleData
.IncrementData
.SubIncrements
);
504 if( rSubIncrements
.getLength() > 0 )
505 aRet
<<= !rSubIncrements
[ 0 ].IntervalCount
.hasValue();
510 case SCALE_PROP_ORIGIN
:
512 aRet
= aScaleData
.Origin
;
513 if( !aRet
.hasValue() )
515 m_spChart2ModelContact
->getExplicitValuesForAxis(
516 xAxis
, aExplicitScale
, aExplicitIncrement
);
517 aRet
<<= aExplicitScale
.Origin
;
521 case SCALE_PROP_AUTO_ORIGIN
:
523 aRet
<<= !hasDoubleValue(aScaleData
.Origin
);
526 case SCALE_PROP_AXIS_TYPE
:
528 sal_Int32 nType
= ::com::sun::star::chart::ChartAxisType::AUTOMATIC
;
529 if( aScaleData
.AxisType
== AxisType::DATE
)
531 nType
= ::com::sun::star::chart::ChartAxisType::DATE
;
533 else if( aScaleData
.AxisType
== AxisType::CATEGORY
)
535 if( !aScaleData
.AutoDateAxis
)
536 nType
= ::com::sun::star::chart::ChartAxisType::CATEGORY
;
538 aRet
= uno::makeAny( nType
);
541 case SCALE_PROP_DATE_INCREMENT
:
543 if( aScaleData
.AxisType
== AxisType::DATE
|| aScaleData
.AutoDateAxis
)
544 aRet
= uno::makeAny( aScaleData
.TimeIncrement
);
547 case SCALE_PROP_EXPLICIT_DATE_INCREMENT
:
549 if( aScaleData
.AxisType
== AxisType::DATE
|| aScaleData
.AutoDateAxis
)
551 m_spChart2ModelContact
->getExplicitValuesForAxis( xAxis
, aExplicitScale
, aExplicitIncrement
);
552 if( aExplicitScale
.AxisType
== AxisType::DATE
)
554 TimeIncrement aTimeIncrement
;
555 aTimeIncrement
.MajorTimeInterval
= uno::makeAny( aExplicitIncrement
.MajorTimeInterval
);
556 aTimeIncrement
.MinorTimeInterval
= uno::makeAny( aExplicitIncrement
.MinorTimeInterval
);
557 aTimeIncrement
.TimeResolution
= uno::makeAny( aExplicitScale
.TimeResolution
);
558 aRet
= uno::makeAny(aTimeIncrement
);
562 if( aScaleData
.AxisType
== AxisType::DATE
|| aScaleData
.AutoDateAxis
)
563 aRet
= uno::makeAny( aScaleData
.TimeIncrement
);
566 case SCALE_PROP_LOGARITHMIC
:
568 aRet
<<= AxisHelper::isLogarithmic(aScaleData
.Scaling
);
571 case SCALE_PROP_REVERSEDIRECTION
:
573 aRet
<<= AxisOrientation_REVERSE
== aScaleData
.Orientation
;
578 OSL_FAIL("unknown scale property");
586 } // namespace wrapper
589 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */