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: VPolarGrid.cxx,v $
10 * $Revision: 1.10.44.1 $
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"
33 #include "VPolarGrid.hxx"
34 #include "VCartesianGrid.hxx"
35 #include "TickmarkHelper.hxx"
36 #include "PlottingPositionHelper.hxx"
37 #include "ShapeFactory.hxx"
38 #include "ObjectIdentifier.hxx"
40 #include "CommonConverters.hxx"
41 #include <com/sun/star/drawing/LineStyle.hpp>
46 //.............................................................................
49 //.............................................................................
50 using namespace ::com::sun::star
;
51 using namespace ::com::sun::star::chart2
;
52 using ::com::sun::star::uno::Reference
;
54 VPolarGrid::VPolarGrid( sal_Int32 nDimensionIndex
, sal_Int32 nDimensionCount
55 , const uno::Sequence
< Reference
< beans::XPropertySet
> > & rGridPropertiesList
)
56 : VAxisOrGridBase( nDimensionIndex
, nDimensionCount
)
57 , m_aGridPropertiesList( rGridPropertiesList
)
58 , m_pPosHelper( new PolarPlottingPositionHelper() )
61 PlotterBase::m_pPosHelper
= m_pPosHelper
;
64 VPolarGrid::~VPolarGrid()
70 void VPolarGrid::setIncrements( const uno::Sequence
< ExplicitIncrementData
>& rIncrements
)
72 m_aIncrements
= rIncrements
;
75 void VPolarGrid::getAllTickInfos( sal_Int32 nDimensionIndex
, ::std::vector
< ::std::vector
< TickInfo
> >& rAllTickInfos
) const
77 TickmarkHelper
aTickmarkHelper(
78 m_pPosHelper
->getScales()[nDimensionIndex
], m_aIncrements
[nDimensionIndex
] );
79 aTickmarkHelper
.getAllTicks( rAllTickInfos
);
83 void VPolarGrid::createLinePointSequence_ForAngleAxis(
84 drawing::PointSequenceSequence
& rPoints
85 , ::std::vector
< ::std::vector
< TickInfo
> >& rAllTickInfos
86 , const ExplicitIncrementData
& rIncrement
87 , const ExplicitScaleData
& rScale
88 , PolarPlottingPositionHelper
* pPosHelper
89 , double fLogicRadius
, double fLogicZ
)
91 Reference
< XScaling
> xInverseScaling( NULL
);
92 if( rScale
.Scaling
.is() )
93 xInverseScaling
= rScale
.Scaling
->getInverseScaling();
96 TickIter
aIter( rAllTickInfos
, rIncrement
, 0, 0 );
97 for( TickInfo
* pTickInfo
= aIter
.firstInfo()
99 ; pTickInfo
= aIter
.nextInfo(), nTick
++ )
101 if(nTick
>=rPoints
[0].getLength())
102 rPoints
[0].realloc(rPoints
[0].getLength()+30);
104 pTickInfo
->updateUnscaledValue( xInverseScaling
);
105 double fLogicAngle
= pTickInfo
->fUnscaledTickValue
;
107 drawing::Position3D
aScenePosition3D( pPosHelper
->transformAngleRadiusToScene( fLogicAngle
, fLogicRadius
, fLogicZ
) );
108 rPoints
[0][nTick
].X
= static_cast<sal_Int32
>(aScenePosition3D
.PositionX
);
109 rPoints
[0][nTick
].Y
= static_cast<sal_Int32
>(aScenePosition3D
.PositionY
);
111 if(rPoints
[0].getLength()>1)
113 rPoints
[0].realloc(nTick
+1);
114 rPoints
[0][nTick
].X
= rPoints
[0][0].X
;
115 rPoints
[0][nTick
].Y
= rPoints
[0][0].Y
;
118 rPoints
[0].realloc(0);
121 void VPolarGrid::create2DAngleGrid( const Reference
< drawing::XShapes
>& xLogicTarget
122 , ::std::vector
< ::std::vector
< TickInfo
> >& /* rRadiusTickInfos */
123 , ::std::vector
< ::std::vector
< TickInfo
> >& rAngleTickInfos
124 , const ::std::vector
<VLineProperties
>& rLinePropertiesList
)
126 Reference
< drawing::XShapes
> xMainTarget(
127 this->createGroupShape( xLogicTarget
, m_aCID
) );
129 const ExplicitScaleData
& rAngleScale
= m_pPosHelper
->getScales()[0];
130 Reference
< XScaling
> xInverseScaling( NULL
);
131 if( rAngleScale
.Scaling
.is() )
132 xInverseScaling
= rAngleScale
.Scaling
->getInverseScaling();
134 double fLogicInnerRadius
= m_pPosHelper
->getInnerLogicRadius();
135 double fLogicOuterRadius
= m_pPosHelper
->getOuterLogicRadius();
136 double fLogicZ
= -0.5;//as defined
138 sal_Int32 nLinePropertiesCount
= rLinePropertiesList
.size();
139 ::std::vector
< ::std::vector
< TickInfo
> >::iterator aDepthIter
= rAngleTickInfos
.begin();
142 //no subgrids so far for polar angle grid (need different radii)
143 const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd = rAngleTickInfos.end();
144 for( ; aDepthIter != aDepthEnd && nDepth < nLinePropertiesCount
145 ; aDepthIter++, nDepth++ )
147 if(nLinePropertiesCount
)
149 //create axis main lines
150 drawing::PointSequenceSequence aAllPoints
;
151 ::std::vector
< TickInfo
>::iterator aTickIter
= (*aDepthIter
).begin();
152 const ::std::vector
< TickInfo
>::const_iterator aTickEnd
= (*aDepthIter
).end();
153 for( ; aTickIter
!= aTickEnd
; aTickIter
++ )
155 TickInfo
& rTickInfo
= *aTickIter
;
156 if( !rTickInfo
.bPaintIt
)
159 rTickInfo
.updateUnscaledValue( xInverseScaling
);
160 double fLogicAngle
= rTickInfo
.fUnscaledTickValue
;
162 drawing::PointSequenceSequence
aPoints(1);
163 aPoints
[0].realloc(2);
164 drawing::Position3D
aScenePositionStart( m_pPosHelper
->transformAngleRadiusToScene( fLogicAngle
, fLogicInnerRadius
, fLogicZ
) );
165 drawing::Position3D
aScenePositionEnd( m_pPosHelper
->transformAngleRadiusToScene( fLogicAngle
, fLogicOuterRadius
, fLogicZ
) );
166 aPoints
[0][0].X
= static_cast<sal_Int32
>(aScenePositionStart
.PositionX
);
167 aPoints
[0][0].Y
= static_cast<sal_Int32
>(aScenePositionStart
.PositionY
);
168 aPoints
[0][1].X
= static_cast<sal_Int32
>(aScenePositionEnd
.PositionX
);
169 aPoints
[0][1].Y
= static_cast<sal_Int32
>(aScenePositionEnd
.PositionY
);
170 appendPointSequence( aAllPoints
, aPoints
);
173 Reference
< drawing::XShape
> xShape
= m_pShapeFactory
->createLine2D(
174 xMainTarget
, aAllPoints
, &rLinePropertiesList
[nDepth
] );
175 //because of this name this line will be used for marking
176 m_pShapeFactory
->setShapeName( xShape
, C2U("MarkHandles") );
181 void VPolarGrid::create2DRadiusGrid( const Reference
< drawing::XShapes
>& xLogicTarget
182 , ::std::vector
< ::std::vector
< TickInfo
> >& rRadiusTickInfos
183 , ::std::vector
< ::std::vector
< TickInfo
> >& rAngleTickInfos
184 , const ::std::vector
<VLineProperties
>& rLinePropertiesList
)
186 Reference
< drawing::XShapes
> xMainTarget(
187 this->createGroupShape( xLogicTarget
, m_aCID
) );
189 const ExplicitScaleData
& rRadiusScale
= m_pPosHelper
->getScales()[1];
190 const ExplicitScaleData
& rAngleScale
= m_pPosHelper
->getScales()[0];
191 const ExplicitIncrementData
& rAngleIncrement
= m_aIncrements
[0];
192 Reference
< XScaling
> xInverseRadiusScaling( NULL
);
193 if( rRadiusScale
.Scaling
.is() )
194 xInverseRadiusScaling
= rRadiusScale
.Scaling
->getInverseScaling();
196 sal_Int32 nLinePropertiesCount
= rLinePropertiesList
.size();
197 ::std::vector
< ::std::vector
< TickInfo
> >::iterator aDepthIter
= rRadiusTickInfos
.begin();
198 const ::std::vector
< ::std::vector
< TickInfo
> >::const_iterator aDepthEnd
= rRadiusTickInfos
.end();
199 for( sal_Int32 nDepth
=0
200 ; aDepthIter
!= aDepthEnd
&& nDepth
< nLinePropertiesCount
201 ; aDepthIter
++, nDepth
++ )
203 if( !rLinePropertiesList
[nDepth
].isLineVisible() )
206 Reference
< drawing::XShapes
> xTarget( xMainTarget
);
209 xTarget
.set( this->createGroupShape( xLogicTarget
210 , ObjectIdentifier::addChildParticle( m_aCID
, ObjectIdentifier::createChildParticleWithIndex( OBJECTTYPE_SUBGRID
, nDepth
-1 ) )
213 xTarget
.set( xMainTarget
);
216 //create axis main lines
217 drawing::PointSequenceSequence aAllPoints
;
218 ::std::vector
< TickInfo
>::iterator aTickIter
= (*aDepthIter
).begin();
219 const ::std::vector
< TickInfo
>::const_iterator aTickEnd
= (*aDepthIter
).end();
220 for( ; aTickIter
!= aTickEnd
; aTickIter
++ )
222 TickInfo
& rTickInfo
= *aTickIter
;
223 if( !rTickInfo
.bPaintIt
)
226 rTickInfo
.updateUnscaledValue( xInverseRadiusScaling
);
227 double fLogicRadius
= rTickInfo
.fUnscaledTickValue
;
228 double fLogicZ
= -0.5;//as defined
230 drawing::PointSequenceSequence
aPoints(1);
231 VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints
, rAngleTickInfos
232 , rAngleIncrement
, rAngleScale
, m_pPosHelper
, fLogicRadius
, fLogicZ
);
233 if(aPoints
[0].getLength())
234 appendPointSequence( aAllPoints
, aPoints
);
237 Reference
< drawing::XShape
> xShape
= m_pShapeFactory
->createLine2D(
238 xTarget
, aAllPoints
, &rLinePropertiesList
[nDepth
] );
239 //because of this name this line will be used for marking
240 m_pShapeFactory
->setShapeName( xShape
, C2U("MarkHandles") );
244 void SAL_CALL
VPolarGrid::createShapes()
246 DBG_ASSERT(m_pShapeFactory
&&m_xLogicTarget
.is()&&m_xFinalTarget
.is(),"Axis is not proper initialized");
247 if(!(m_pShapeFactory
&&m_xLogicTarget
.is()&&m_xFinalTarget
.is()))
249 if(!m_aGridPropertiesList
.getLength())
252 //-----------------------------------------
253 //create all scaled tickmark values
254 ::std::vector
< ::std::vector
< TickInfo
> > aAngleTickInfos
;
255 ::std::vector
< ::std::vector
< TickInfo
> > aRadiusTickInfos
;
256 getAllTickInfos( 0, aAngleTickInfos
);
257 getAllTickInfos( 1, aRadiusTickInfos
);
259 //-----------------------------------------
260 ::std::vector
<VLineProperties
> aLinePropertiesList
;
261 VCartesianGrid::fillLinePropertiesFromGridModel( aLinePropertiesList
, m_aGridPropertiesList
);
263 //-----------------------------------------
264 //create tick mark line shapes
267 if(m_nDimensionIndex
==1)
268 this->create2DRadiusGrid( m_xLogicTarget
, aRadiusTickInfos
, aAngleTickInfos
, aLinePropertiesList
);
269 //else //no Angle Grid so far as this equals exactly the y axis positions
270 // this->create2DAngleGrid( m_xLogicTarget, aRadiusTickInfos, aAngleTickInfos, aLinePropertiesList );
274 //.............................................................................
276 //.............................................................................