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 
31 #include "VPolarRadiusAxis.hxx"
32 #include "VCartesianAxis.hxx"
33 #include "PlottingPositionHelper.hxx"
34 #include "CommonConverters.hxx"
35 #include "Tickmarks_Equidistant.hxx"
36 #include <rtl/math.hxx>
37 
38 //.............................................................................
39 namespace chart
40 {
41 //.............................................................................
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::chart2;
44 using namespace ::rtl::math;
45 
46 VPolarRadiusAxis::VPolarRadiusAxis( const AxisProperties& rAxisProperties
47             , const uno::Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier
48             , sal_Int32 nDimensionCount )
49             : VPolarAxis( rAxisProperties, xNumberFormatsSupplier, 1/*nDimensionIndex*/, nDimensionCount )
50 {
51     m_aAxisProperties.m_fLabelDirectionSign=0.0;
52     m_aAxisProperties.m_fInnerDirectionSign=0.0;
53     m_aAxisProperties.m_bIsMainAxis=false;
54     m_aAxisProperties.m_aLabelAlignment=LABEL_ALIGN_RIGHT;
55     m_aAxisProperties.init();
56 
57     m_apAxisWithLabels = std::auto_ptr<VCartesianAxis>( new VCartesianAxis(
58         m_aAxisProperties,xNumberFormatsSupplier,1/*nDimensionIndex*/,nDimensionCount
59         ,new PolarPlottingPositionHelper() ) );
60 }
61 
62 VPolarRadiusAxis::~VPolarRadiusAxis()
63 {
64     delete m_pPosHelper;
65     m_pPosHelper = NULL;
66 }
67 
68 void VPolarRadiusAxis::setTransformationSceneToScreen( const drawing::HomogenMatrix& rMatrix)
69 {
70     VPolarAxis::setTransformationSceneToScreen( rMatrix );
71     m_apAxisWithLabels->setTransformationSceneToScreen( rMatrix );
72 }
73 
74 void VPolarRadiusAxis::setExplicitScaleAndIncrement(
75               const ExplicitScaleData& rScale
76             , const ExplicitIncrementData& rIncrement )
77             throw (uno::RuntimeException)
78 {
79     VPolarAxis::setExplicitScaleAndIncrement( rScale, rIncrement );
80     m_apAxisWithLabels->setExplicitScaleAndIncrement( rScale, rIncrement );
81 }
82 
83 void VPolarRadiusAxis::initPlotter(  const uno::Reference< drawing::XShapes >& xLogicTarget
84 	   , const uno::Reference< drawing::XShapes >& xFinalTarget
85 	   , const uno::Reference< lang::XMultiServiceFactory >& xShapeFactory
86        , const rtl::OUString& rCID )
87 	        throw (uno::RuntimeException)
88 {
89     VPolarAxis::initPlotter(  xLogicTarget, xFinalTarget, xShapeFactory, rCID );
90     m_apAxisWithLabels->initPlotter(  xLogicTarget, xFinalTarget, xShapeFactory, rCID );
91 }
92 
93 void VPolarRadiusAxis::setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis )
94 {
95     VPolarAxis::setScales( rScales, bSwapXAndYAxis );
96     m_apAxisWithLabels->setScales( rScales, bSwapXAndYAxis );
97 }
98 
99 void VPolarRadiusAxis::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize
100                   , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels )
101 {
102     VPolarAxis::initAxisLabelProperties( rFontReferenceSize, rMaximumSpaceForLabels );
103     m_apAxisWithLabels->initAxisLabelProperties( rFontReferenceSize, rMaximumSpaceForLabels );
104 }
105 
106 sal_Int32 VPolarRadiusAxis::estimateMaximumAutoMainIncrementCount()
107 {
108     return 2;
109 }
110 
111 bool VPolarRadiusAxis::prepareShapeCreation()
112 {
113     //returns true if all is ready for further shape creation and any shapes need to be created
114     if( !isAnythingToDraw() )
115         return false;
116 
117     if( m_xGroupShape_Shapes.is() )
118         return true;
119 
120     return true;
121 }
122 
123 void VPolarRadiusAxis::createMaximumLabels()
124 {
125     m_apAxisWithLabels->createMaximumLabels();
126 }
127 
128 void VPolarRadiusAxis::updatePositions()
129 {
130     m_apAxisWithLabels->updatePositions();
131 }
132 
133 void VPolarRadiusAxis::createLabels()
134 {
135     m_apAxisWithLabels->createLabels();
136 }
137 
138 void VPolarRadiusAxis::createShapes()
139 {
140     if( !prepareShapeCreation() )
141         return;
142 
143     const ExplicitScaleData& rAngleScale         = m_pPosHelper->getScales()[0];
144     const ExplicitIncrementData& rAngleIncrement = m_aIncrements[0];
145 
146     ::std::vector< ::std::vector< TickInfo > > aAngleTickInfos;
147     TickFactory aAngleTickFactory( rAngleScale, rAngleIncrement );
148     aAngleTickFactory.getAllTicks( aAngleTickInfos );
149 
150     uno::Reference< XScaling > xInverseScaling( NULL );
151     if( rAngleScale.Scaling.is() )
152         xInverseScaling = rAngleScale.Scaling->getInverseScaling();
153 
154     AxisProperties aAxisProperties(m_aAxisProperties);
155 
156     sal_Int32 nTick = 0;
157     EquidistantTickIter aIter( aAngleTickInfos, rAngleIncrement, 0, 0 );
158     for( TickInfo* pTickInfo = aIter.firstInfo()
159         ; pTickInfo; pTickInfo = aIter.nextInfo(), nTick++ )
160     {
161         if( nTick == 0 )
162         {
163             m_apAxisWithLabels->createShapes();
164             continue;
165         }
166 
167         //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
168         aAxisProperties.m_pfMainLinePositionAtOtherAxis = new double( pTickInfo->getUnscaledTickValue() );
169         aAxisProperties.m_bDisplayLabels=false;
170 
171         //-------------------
172         VCartesianAxis aAxis(aAxisProperties,m_xNumberFormatsSupplier
173             ,1,2,new PolarPlottingPositionHelper());
174         aAxis.setExplicitScaleAndIncrement( m_aScale, m_aIncrement );
175         aAxis.initPlotter(m_xLogicTarget,m_xFinalTarget,m_xShapeFactory, m_aCID );
176         aAxis.setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix( m_aMatrixScreenToScene ) );
177         aAxis.setScales( m_pPosHelper->getScales(), false );
178         aAxis.initAxisLabelProperties(m_aAxisLabelProperties.m_aFontReferenceSize,m_aAxisLabelProperties.m_aMaximumSpaceForLabels);
179         aAxis.createShapes();
180     }
181 }
182 
183 //.............................................................................
184 } //namespace chart
185 //.............................................................................
186