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