1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*cde9e8dcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cde9e8dcSAndrew Rist  * distributed with this work for additional information
6*cde9e8dcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cde9e8dcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist  * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist  *
11*cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist  *
13*cde9e8dcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist  * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*cde9e8dcSAndrew Rist  * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist  * under the License.
19*cde9e8dcSAndrew Rist  *
20*cde9e8dcSAndrew Rist  *************************************************************/
21*cde9e8dcSAndrew Rist 
22*cde9e8dcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "VPolarRadiusAxis.hxx"
28cdf0e10cSrcweir #include "VCartesianAxis.hxx"
29cdf0e10cSrcweir #include "PlottingPositionHelper.hxx"
30cdf0e10cSrcweir #include "CommonConverters.hxx"
31cdf0e10cSrcweir #include "Tickmarks_Equidistant.hxx"
32cdf0e10cSrcweir #include <rtl/math.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //.............................................................................
35cdf0e10cSrcweir namespace chart
36cdf0e10cSrcweir {
37cdf0e10cSrcweir //.............................................................................
38cdf0e10cSrcweir using namespace ::com::sun::star;
39cdf0e10cSrcweir using namespace ::com::sun::star::chart2;
40cdf0e10cSrcweir using namespace ::rtl::math;
41cdf0e10cSrcweir 
VPolarRadiusAxis(const AxisProperties & rAxisProperties,const uno::Reference<util::XNumberFormatsSupplier> & xNumberFormatsSupplier,sal_Int32 nDimensionCount)42cdf0e10cSrcweir VPolarRadiusAxis::VPolarRadiusAxis( const AxisProperties& rAxisProperties
43cdf0e10cSrcweir             , const uno::Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier
44cdf0e10cSrcweir             , sal_Int32 nDimensionCount )
45cdf0e10cSrcweir             : VPolarAxis( rAxisProperties, xNumberFormatsSupplier, 1/*nDimensionIndex*/, nDimensionCount )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     m_aAxisProperties.m_fLabelDirectionSign=0.0;
48cdf0e10cSrcweir     m_aAxisProperties.m_fInnerDirectionSign=0.0;
49cdf0e10cSrcweir     m_aAxisProperties.m_bIsMainAxis=false;
50cdf0e10cSrcweir     m_aAxisProperties.m_aLabelAlignment=LABEL_ALIGN_RIGHT;
51cdf0e10cSrcweir     m_aAxisProperties.init();
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     m_apAxisWithLabels = std::auto_ptr<VCartesianAxis>( new VCartesianAxis(
54cdf0e10cSrcweir         m_aAxisProperties,xNumberFormatsSupplier,1/*nDimensionIndex*/,nDimensionCount
55cdf0e10cSrcweir         ,new PolarPlottingPositionHelper() ) );
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
~VPolarRadiusAxis()58cdf0e10cSrcweir VPolarRadiusAxis::~VPolarRadiusAxis()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     delete m_pPosHelper;
61cdf0e10cSrcweir     m_pPosHelper = NULL;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
setTransformationSceneToScreen(const drawing::HomogenMatrix & rMatrix)64cdf0e10cSrcweir void VPolarRadiusAxis::setTransformationSceneToScreen( const drawing::HomogenMatrix& rMatrix)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     VPolarAxis::setTransformationSceneToScreen( rMatrix );
67cdf0e10cSrcweir     m_apAxisWithLabels->setTransformationSceneToScreen( rMatrix );
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
setExplicitScaleAndIncrement(const ExplicitScaleData & rScale,const ExplicitIncrementData & rIncrement)70cdf0e10cSrcweir void VPolarRadiusAxis::setExplicitScaleAndIncrement(
71cdf0e10cSrcweir               const ExplicitScaleData& rScale
72cdf0e10cSrcweir             , const ExplicitIncrementData& rIncrement )
73cdf0e10cSrcweir             throw (uno::RuntimeException)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     VPolarAxis::setExplicitScaleAndIncrement( rScale, rIncrement );
76cdf0e10cSrcweir     m_apAxisWithLabels->setExplicitScaleAndIncrement( rScale, rIncrement );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
initPlotter(const uno::Reference<drawing::XShapes> & xLogicTarget,const uno::Reference<drawing::XShapes> & xFinalTarget,const uno::Reference<lang::XMultiServiceFactory> & xShapeFactory,const rtl::OUString & rCID)79cdf0e10cSrcweir void VPolarRadiusAxis::initPlotter(  const uno::Reference< drawing::XShapes >& xLogicTarget
80cdf0e10cSrcweir 	   , const uno::Reference< drawing::XShapes >& xFinalTarget
81cdf0e10cSrcweir 	   , const uno::Reference< lang::XMultiServiceFactory >& xShapeFactory
82cdf0e10cSrcweir        , const rtl::OUString& rCID )
83cdf0e10cSrcweir 	        throw (uno::RuntimeException)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir     VPolarAxis::initPlotter(  xLogicTarget, xFinalTarget, xShapeFactory, rCID );
86cdf0e10cSrcweir     m_apAxisWithLabels->initPlotter(  xLogicTarget, xFinalTarget, xShapeFactory, rCID );
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
setScales(const std::vector<ExplicitScaleData> & rScales,bool bSwapXAndYAxis)89cdf0e10cSrcweir void VPolarRadiusAxis::setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     VPolarAxis::setScales( rScales, bSwapXAndYAxis );
92cdf0e10cSrcweir     m_apAxisWithLabels->setScales( rScales, bSwapXAndYAxis );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
initAxisLabelProperties(const::com::sun::star::awt::Size & rFontReferenceSize,const::com::sun::star::awt::Rectangle & rMaximumSpaceForLabels)95cdf0e10cSrcweir void VPolarRadiusAxis::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize
96cdf0e10cSrcweir                   , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     VPolarAxis::initAxisLabelProperties( rFontReferenceSize, rMaximumSpaceForLabels );
99cdf0e10cSrcweir     m_apAxisWithLabels->initAxisLabelProperties( rFontReferenceSize, rMaximumSpaceForLabels );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
estimateMaximumAutoMainIncrementCount()102cdf0e10cSrcweir sal_Int32 VPolarRadiusAxis::estimateMaximumAutoMainIncrementCount()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     return 2;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
prepareShapeCreation()107cdf0e10cSrcweir bool VPolarRadiusAxis::prepareShapeCreation()
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     //returns true if all is ready for further shape creation and any shapes need to be created
110cdf0e10cSrcweir     if( !isAnythingToDraw() )
111cdf0e10cSrcweir         return false;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     if( m_xGroupShape_Shapes.is() )
114cdf0e10cSrcweir         return true;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     return true;
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
createMaximumLabels()119cdf0e10cSrcweir void VPolarRadiusAxis::createMaximumLabels()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     m_apAxisWithLabels->createMaximumLabels();
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
updatePositions()124cdf0e10cSrcweir void VPolarRadiusAxis::updatePositions()
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     m_apAxisWithLabels->updatePositions();
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
createLabels()129cdf0e10cSrcweir void VPolarRadiusAxis::createLabels()
130cdf0e10cSrcweir {
131cdf0e10cSrcweir     m_apAxisWithLabels->createLabels();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
createShapes()134cdf0e10cSrcweir void VPolarRadiusAxis::createShapes()
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     if( !prepareShapeCreation() )
137cdf0e10cSrcweir         return;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     const ExplicitScaleData& rAngleScale         = m_pPosHelper->getScales()[0];
140cdf0e10cSrcweir     const ExplicitIncrementData& rAngleIncrement = m_aIncrements[0];
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     ::std::vector< ::std::vector< TickInfo > > aAngleTickInfos;
143cdf0e10cSrcweir     TickFactory aAngleTickFactory( rAngleScale, rAngleIncrement );
144cdf0e10cSrcweir     aAngleTickFactory.getAllTicks( aAngleTickInfos );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     uno::Reference< XScaling > xInverseScaling( NULL );
147cdf0e10cSrcweir     if( rAngleScale.Scaling.is() )
148cdf0e10cSrcweir         xInverseScaling = rAngleScale.Scaling->getInverseScaling();
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     AxisProperties aAxisProperties(m_aAxisProperties);
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     sal_Int32 nTick = 0;
153cdf0e10cSrcweir     EquidistantTickIter aIter( aAngleTickInfos, rAngleIncrement, 0, 0 );
154cdf0e10cSrcweir     for( TickInfo* pTickInfo = aIter.firstInfo()
155cdf0e10cSrcweir         ; pTickInfo; pTickInfo = aIter.nextInfo(), nTick++ )
156cdf0e10cSrcweir     {
157cdf0e10cSrcweir         if( nTick == 0 )
158cdf0e10cSrcweir         {
159cdf0e10cSrcweir             m_apAxisWithLabels->createShapes();
160cdf0e10cSrcweir             continue;
161cdf0e10cSrcweir         }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
164cdf0e10cSrcweir         aAxisProperties.m_pfMainLinePositionAtOtherAxis = new double( pTickInfo->getUnscaledTickValue() );
165cdf0e10cSrcweir         aAxisProperties.m_bDisplayLabels=false;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         //-------------------
168cdf0e10cSrcweir         VCartesianAxis aAxis(aAxisProperties,m_xNumberFormatsSupplier
169cdf0e10cSrcweir             ,1,2,new PolarPlottingPositionHelper());
170cdf0e10cSrcweir         aAxis.setExplicitScaleAndIncrement( m_aScale, m_aIncrement );
171cdf0e10cSrcweir         aAxis.initPlotter(m_xLogicTarget,m_xFinalTarget,m_xShapeFactory, m_aCID );
172cdf0e10cSrcweir         aAxis.setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix( m_aMatrixScreenToScene ) );
173cdf0e10cSrcweir         aAxis.setScales( m_pPosHelper->getScales(), false );
174cdf0e10cSrcweir         aAxis.initAxisLabelProperties(m_aAxisLabelProperties.m_aFontReferenceSize,m_aAxisLabelProperties.m_aMaximumSpaceForLabels);
175cdf0e10cSrcweir         aAxis.createShapes();
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir //.............................................................................
180cdf0e10cSrcweir } //namespace chart
181cdf0e10cSrcweir //.............................................................................
182