Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "VPolarGrid.hxx"
21 : #include "VCartesianGrid.hxx"
22 : #include "Tickmarks.hxx"
23 : #include "PlottingPositionHelper.hxx"
24 : #include "ShapeFactory.hxx"
25 : #include "ObjectIdentifier.hxx"
26 : #include "macros.hxx"
27 : #include "CommonConverters.hxx"
28 : #include "Tickmarks_Equidistant.hxx"
29 : #include <com/sun/star/drawing/LineStyle.hpp>
30 :
31 : #include <vector>
32 : #include <memory>
33 :
34 : //.............................................................................
35 : namespace chart
36 : {
37 : //.............................................................................
38 : using namespace ::com::sun::star;
39 : using namespace ::com::sun::star::chart2;
40 : using ::com::sun::star::uno::Reference;
41 :
42 0 : VPolarGrid::VPolarGrid( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount
43 : , const uno::Sequence< Reference< beans::XPropertySet > > & rGridPropertiesList )
44 : : VAxisOrGridBase( nDimensionIndex, nDimensionCount )
45 : , m_aGridPropertiesList( rGridPropertiesList )
46 0 : , m_pPosHelper( new PolarPlottingPositionHelper() )
47 0 : , m_aIncrements()
48 : {
49 0 : PlotterBase::m_pPosHelper = m_pPosHelper;
50 0 : }
51 :
52 0 : VPolarGrid::~VPolarGrid()
53 : {
54 0 : delete m_pPosHelper;
55 0 : m_pPosHelper = NULL;
56 0 : }
57 :
58 0 : void VPolarGrid::setIncrements( const std::vector< ExplicitIncrementData >& rIncrements )
59 : {
60 0 : m_aIncrements = rIncrements;
61 0 : }
62 :
63 0 : void VPolarGrid::getAllTickInfos( sal_Int32 nDimensionIndex, ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const
64 : {
65 : TickFactory aTickFactory(
66 0 : m_pPosHelper->getScales()[nDimensionIndex], m_aIncrements[nDimensionIndex] );
67 0 : aTickFactory.getAllTicks( rAllTickInfos );
68 0 : }
69 :
70 0 : void VPolarGrid::createLinePointSequence_ForAngleAxis(
71 : drawing::PointSequenceSequence& rPoints
72 : , ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos
73 : , const ExplicitIncrementData& rIncrement
74 : , const ExplicitScaleData& rScale
75 : , PolarPlottingPositionHelper* pPosHelper
76 : , double fLogicRadius, double fLogicZ )
77 : {
78 0 : Reference< XScaling > xInverseScaling( NULL );
79 0 : if( rScale.Scaling.is() )
80 0 : xInverseScaling = rScale.Scaling->getInverseScaling();
81 :
82 0 : sal_Int32 nTick = 0;
83 0 : EquidistantTickIter aIter( rAllTickInfos, rIncrement, 0, 0 );
84 0 : for( TickInfo* pTickInfo = aIter.firstInfo()
85 : ; pTickInfo
86 : ; pTickInfo = aIter.nextInfo(), nTick++ )
87 : {
88 0 : if(nTick>=rPoints[0].getLength())
89 0 : rPoints[0].realloc(rPoints[0].getLength()+30);
90 :
91 : //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
92 0 : double fLogicAngle = pTickInfo->getUnscaledTickValue();
93 :
94 0 : drawing::Position3D aScenePosition3D( pPosHelper->transformAngleRadiusToScene( fLogicAngle, fLogicRadius, fLogicZ ) );
95 0 : rPoints[0][nTick].X = static_cast<sal_Int32>(aScenePosition3D.PositionX);
96 0 : rPoints[0][nTick].Y = static_cast<sal_Int32>(aScenePosition3D.PositionY);
97 : }
98 0 : if(rPoints[0].getLength()>1)
99 : {
100 0 : rPoints[0].realloc(nTick+1);
101 0 : rPoints[0][nTick].X = rPoints[0][0].X;
102 0 : rPoints[0][nTick].Y = rPoints[0][0].Y;
103 : }
104 : else
105 0 : rPoints[0].realloc(0);
106 0 : }
107 : #ifdef NOTYET
108 : void VPolarGrid::create2DAngleGrid( const Reference< drawing::XShapes >& xLogicTarget
109 : , ::std::vector< ::std::vector< TickInfo > >& /* rRadiusTickInfos */
110 : , ::std::vector< ::std::vector< TickInfo > >& rAngleTickInfos
111 : , const ::std::vector<VLineProperties>& rLinePropertiesList )
112 : {
113 : Reference< drawing::XShapes > xMainTarget(
114 : this->createGroupShape( xLogicTarget, m_aCID ) );
115 :
116 : const ExplicitScaleData& rAngleScale = m_pPosHelper->getScales()[0];
117 : Reference< XScaling > xInverseScaling( NULL );
118 : if( rAngleScale.Scaling.is() )
119 : xInverseScaling = rAngleScale.Scaling->getInverseScaling();
120 :
121 : double fLogicInnerRadius = m_pPosHelper->getInnerLogicRadius();
122 : double fLogicOuterRadius = m_pPosHelper->getOuterLogicRadius();
123 :
124 : sal_Int32 nLinePropertiesCount = rLinePropertiesList.size();
125 : ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = rAngleTickInfos.begin();
126 : if(nLinePropertiesCount)
127 : {
128 : double fLogicZ = 1.0;//as defined
129 : sal_Int32 nDepth=0;
130 : //create axis main lines
131 : drawing::PointSequenceSequence aAllPoints;
132 : ::std::vector< TickInfo >::iterator aTickIter = (*aDepthIter).begin();
133 : const ::std::vector< TickInfo >::const_iterator aTickEnd = (*aDepthIter).end();
134 : for( ; aTickIter != aTickEnd; ++aTickIter )
135 : {
136 : TickInfo& rTickInfo = *aTickIter;
137 : if( !rTickInfo.bPaintIt )
138 : continue;
139 :
140 : //xxxxx rTickInfo.updateUnscaledValue( xInverseScaling );
141 : double fLogicAngle = rTickInfo.getUnscaledTickValue();
142 :
143 : drawing::PointSequenceSequence aPoints(1);
144 : aPoints[0].realloc(2);
145 : drawing::Position3D aScenePositionStart( m_pPosHelper->transformAngleRadiusToScene( fLogicAngle, fLogicInnerRadius, fLogicZ ) );
146 : drawing::Position3D aScenePositionEnd( m_pPosHelper->transformAngleRadiusToScene( fLogicAngle, fLogicOuterRadius, fLogicZ ) );
147 : aPoints[0][0].X = static_cast<sal_Int32>(aScenePositionStart.PositionX);
148 : aPoints[0][0].Y = static_cast<sal_Int32>(aScenePositionStart.PositionY);
149 : aPoints[0][1].X = static_cast<sal_Int32>(aScenePositionEnd.PositionX);
150 : aPoints[0][1].Y = static_cast<sal_Int32>(aScenePositionEnd.PositionY);
151 : appendPointSequence( aAllPoints, aPoints );
152 : }
153 :
154 : Reference< drawing::XShape > xShape = m_pShapeFactory->createLine2D(
155 : xMainTarget, aAllPoints, &rLinePropertiesList[nDepth] );
156 : //because of this name this line will be used for marking
157 : m_pShapeFactory->setShapeName( xShape, C2U("MarkHandles") );
158 : }
159 : }
160 : #endif
161 :
162 0 : void VPolarGrid::create2DRadiusGrid( const Reference< drawing::XShapes >& xLogicTarget
163 : , ::std::vector< ::std::vector< TickInfo > >& rRadiusTickInfos
164 : , ::std::vector< ::std::vector< TickInfo > >& rAngleTickInfos
165 : , const ::std::vector<VLineProperties>& rLinePropertiesList )
166 : {
167 : Reference< drawing::XShapes > xMainTarget(
168 0 : this->createGroupShape( xLogicTarget, m_aCID ) );
169 :
170 0 : const ExplicitScaleData& rRadiusScale = m_pPosHelper->getScales()[1];
171 0 : const ExplicitScaleData& rAngleScale = m_pPosHelper->getScales()[0];
172 0 : const ExplicitIncrementData& rAngleIncrement = m_aIncrements[0];
173 0 : Reference< XScaling > xInverseRadiusScaling( NULL );
174 0 : if( rRadiusScale.Scaling.is() )
175 0 : xInverseRadiusScaling = rRadiusScale.Scaling->getInverseScaling();
176 :
177 0 : sal_Int32 nLinePropertiesCount = rLinePropertiesList.size();
178 0 : ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = rRadiusTickInfos.begin();
179 0 : const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd = rRadiusTickInfos.end();
180 0 : for( sal_Int32 nDepth=0
181 0 : ; aDepthIter != aDepthEnd && nDepth < nLinePropertiesCount
182 : ; ++aDepthIter, nDepth++ )
183 : {
184 0 : if( !rLinePropertiesList[nDepth].isLineVisible() )
185 0 : continue;
186 :
187 0 : Reference< drawing::XShapes > xTarget( xMainTarget );
188 0 : if( nDepth > 0 )
189 : {
190 : xTarget.set( this->createGroupShape( xLogicTarget
191 : , ObjectIdentifier::addChildParticle( m_aCID, ObjectIdentifier::createChildParticleWithIndex( OBJECTTYPE_SUBGRID, nDepth-1 ) )
192 0 : ) );
193 0 : if(!xTarget.is())
194 0 : xTarget.set( xMainTarget );
195 : }
196 :
197 : //create axis main lines
198 0 : drawing::PointSequenceSequence aAllPoints;
199 0 : ::std::vector< TickInfo >::iterator aTickIter = (*aDepthIter).begin();
200 0 : const ::std::vector< TickInfo >::const_iterator aTickEnd = (*aDepthIter).end();
201 0 : for( ; aTickIter != aTickEnd; ++aTickIter )
202 : {
203 0 : TickInfo& rTickInfo = *aTickIter;
204 0 : if( !rTickInfo.bPaintIt )
205 0 : continue;
206 :
207 : //xxxxx rTickInfo.updateUnscaledValue( xInverseRadiusScaling );
208 0 : double fLogicRadius = rTickInfo.getUnscaledTickValue();
209 0 : double fLogicZ = 1.0;//as defined
210 :
211 0 : drawing::PointSequenceSequence aPoints(1);
212 : VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints, rAngleTickInfos
213 0 : , rAngleIncrement, rAngleScale, m_pPosHelper, fLogicRadius, fLogicZ );
214 0 : if(aPoints[0].getLength())
215 0 : appendPointSequence( aAllPoints, aPoints );
216 0 : }
217 :
218 : Reference< drawing::XShape > xShape = m_pShapeFactory->createLine2D(
219 0 : xTarget, aAllPoints, &rLinePropertiesList[nDepth] );
220 : //because of this name this line will be used for marking
221 0 : m_pShapeFactory->setShapeName( xShape, C2U("MarkHandles") );
222 0 : }
223 0 : }
224 :
225 0 : void VPolarGrid::createShapes()
226 : {
227 : OSL_PRECOND(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"Axis is not proper initialized");
228 0 : if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is()))
229 : return;
230 0 : if(!m_aGridPropertiesList.getLength())
231 : return;
232 :
233 : //-----------------------------------------
234 : //create all scaled tickmark values
235 0 : ::std::vector< ::std::vector< TickInfo > > aAngleTickInfos;
236 0 : ::std::vector< ::std::vector< TickInfo > > aRadiusTickInfos;
237 0 : getAllTickInfos( 0, aAngleTickInfos );
238 0 : getAllTickInfos( 1, aRadiusTickInfos );
239 :
240 : //-----------------------------------------
241 0 : ::std::vector<VLineProperties> aLinePropertiesList;
242 0 : VCartesianGrid::fillLinePropertiesFromGridModel( aLinePropertiesList, m_aGridPropertiesList );
243 :
244 : //-----------------------------------------
245 : //create tick mark line shapes
246 0 : if(2==m_nDimension)
247 : {
248 0 : if(m_nDimensionIndex==1)
249 0 : this->create2DRadiusGrid( m_xLogicTarget, aRadiusTickInfos, aAngleTickInfos, aLinePropertiesList );
250 : //else //no Angle Grid so far as this equals exactly the y axis positions
251 : // this->create2DAngleGrid( m_xLogicTarget, aRadiusTickInfos, aAngleTickInfos, aLinePropertiesList );
252 0 : }
253 : }
254 :
255 : //.............................................................................
256 : } //namespace chart
257 : //.............................................................................
258 :
259 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|