Branch data 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 "VCartesianGrid.hxx"
21 : : #include "Tickmarks.hxx"
22 : : #include "PlottingPositionHelper.hxx"
23 : : #include "ShapeFactory.hxx"
24 : : #include "ObjectIdentifier.hxx"
25 : : #include "macros.hxx"
26 : : #include "CommonConverters.hxx"
27 : : #include "AxisHelper.hxx"
28 : : #include <com/sun/star/drawing/PointSequenceSequence.hpp>
29 : : #include <com/sun/star/drawing/LineStyle.hpp>
30 : :
31 : : #include <vector>
32 : : #include <boost/scoped_ptr.hpp>
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 : : using ::com::sun::star::uno::Sequence;
42 : :
43 [ + - ][ + - ]: 761 : struct GridLinePoints
44 : : {
45 : : Sequence< double > P0;
46 : : Sequence< double > P1;
47 : : Sequence< double > P2;
48 : :
49 : : GridLinePoints( const PlottingPositionHelper* pPosHelper, sal_Int32 nDimensionIndex
50 : : , CuboidPlanePosition eLeftWallPos=CuboidPlanePosition_Left
51 : : , CuboidPlanePosition eBackWallPos=CuboidPlanePosition_Back
52 : : , CuboidPlanePosition eBottomPos=CuboidPlanePosition_Bottom );
53 : : void update( double fScaledTickValue );
54 : :
55 : : sal_Int32 m_nDimensionIndex;
56 : : };
57 : :
58 : 761 : GridLinePoints::GridLinePoints( const PlottingPositionHelper* pPosHelper, sal_Int32 nDimensionIndex
59 : : , CuboidPlanePosition eLeftWallPos
60 : : , CuboidPlanePosition eBackWallPos
61 : : , CuboidPlanePosition eBottomPos )
62 [ + - ][ + - ]: 761 : : m_nDimensionIndex(nDimensionIndex)
63 : : {
64 [ + - ]: 761 : double MinX = pPosHelper->getLogicMinX();
65 [ + - ]: 761 : double MinY = pPosHelper->getLogicMinY();
66 [ + - ]: 761 : double MinZ = pPosHelper->getLogicMinZ();
67 [ + - ]: 761 : double MaxX = pPosHelper->getLogicMaxX();
68 [ + - ]: 761 : double MaxY = pPosHelper->getLogicMaxY();
69 [ + - ]: 761 : double MaxZ = pPosHelper->getLogicMaxZ();
70 : :
71 [ + - ]: 761 : pPosHelper->doLogicScaling( &MinX,&MinY,&MinZ );
72 [ + - ]: 761 : pPosHelper->doLogicScaling( &MaxX,&MaxY,&MaxZ );
73 : :
74 [ + - ][ - + ]: 761 : if(!pPosHelper->isMathematicalOrientationX())
75 : : {
76 : 0 : double fHelp = MinX;
77 : 0 : MinX = MaxX;
78 : 0 : MaxX = fHelp;
79 : : }
80 [ + - ][ + + ]: 761 : if(!pPosHelper->isMathematicalOrientationY())
81 : : {
82 : 72 : double fHelp = MinY;
83 : 72 : MinY = MaxY;
84 : 72 : MaxY = fHelp;
85 : : }
86 [ + - ][ + - ]: 761 : if(pPosHelper->isMathematicalOrientationZ())//z axis in draw is reverse to mathematical
87 : : {
88 : 761 : double fHelp = MinZ;
89 : 761 : MinZ = MaxZ;
90 : 761 : MaxZ = fHelp;
91 : : }
92 : 761 : bool bSwapXY = pPosHelper->isSwapXAndY();
93 : :
94 [ + - ]: 761 : P0.realloc(3);
95 [ + - ]: 761 : P1.realloc(3);
96 [ + - ]: 761 : P2.realloc(3);
97 : :
98 : : //P0: point on 'back' wall, not on 'left' wall
99 : : //P1: point on both walls
100 : : //P2: point on 'left' wall not on 'back' wall
101 : :
102 [ + - ][ + - ]: 761 : P0[0]=P1[0]=P2[0]= (CuboidPlanePosition_Left == eLeftWallPos || bSwapXY) ? MinX : MaxX;
[ + - ][ - + ]
[ # # ]
103 [ + - ][ + - ]: 761 : P0[1]=P1[1]=P2[1]= (CuboidPlanePosition_Left == eLeftWallPos || !bSwapXY) ? MinY : MaxY;
[ + - ][ - + ]
[ # # ]
104 [ + - ][ + - ]: 761 : P0[2]=P1[2]=P2[2]= (CuboidPlanePosition_Back == eBackWallPos) ? MinZ : MaxZ;
[ + - ][ + - ]
105 : :
106 [ + + ]: 761 : if(m_nDimensionIndex==0)
107 : : {
108 [ + - ][ - + ]: 100 : P0[1]= (CuboidPlanePosition_Left == eLeftWallPos || !bSwapXY) ? MaxY : MinY;
[ # # ]
109 [ + - ][ + - ]: 100 : P2[2]= (CuboidPlanePosition_Back == eBackWallPos) ? MaxZ : MinZ;
110 [ - + ][ # # ]: 100 : if( CuboidPlanePosition_Bottom != eBottomPos && !bSwapXY )
111 [ # # ]: 0 : P2=P1;
112 : : }
113 [ + - ]: 661 : else if(m_nDimensionIndex==1)
114 : : {
115 [ + - ][ - + ]: 661 : P0[0]= (CuboidPlanePosition_Left == eLeftWallPos || bSwapXY) ? MaxX : MinX;
[ # # ]
116 [ + - ][ + - ]: 661 : P2[2]= (CuboidPlanePosition_Back == eBackWallPos) ? MaxZ : MinZ;
117 [ - + ][ # # ]: 661 : if( CuboidPlanePosition_Bottom != eBottomPos && bSwapXY )
118 [ # # ]: 0 : P2=P1;
119 : : }
120 [ # # ]: 0 : else if(m_nDimensionIndex==2)
121 : : {
122 [ # # ][ # # ]: 0 : P0[0]= (CuboidPlanePosition_Left == eLeftWallPos || bSwapXY) ? MaxX : MinX;
[ # # ]
123 [ # # ][ # # ]: 0 : P2[1]= (CuboidPlanePosition_Left == eLeftWallPos || !bSwapXY) ? MaxY : MinY;
[ # # ]
124 [ # # ]: 0 : if( CuboidPlanePosition_Bottom != eBottomPos )
125 : : {
126 [ # # ]: 0 : if( !bSwapXY )
127 [ # # ]: 0 : P0=P1;
128 : : else
129 [ # # ]: 0 : P2=P1;
130 : : }
131 : : }
132 : 761 : }
133 : :
134 : 4080 : void GridLinePoints::update( double fScaledTickValue )
135 : : {
136 : 4080 : P0[m_nDimensionIndex] = P1[m_nDimensionIndex] = P2[m_nDimensionIndex] = fScaledTickValue;
137 : 4080 : }
138 : :
139 : 4080 : void addLine2D( drawing::PointSequenceSequence& rPoints, sal_Int32 nIndex
140 : : , const GridLinePoints& rScaledLogicPoints
141 : : , const Reference< XTransformation > & xTransformation
142 : : )
143 : : {
144 [ + - ][ + - ]: 4080 : drawing::Position3D aPA = SequenceToPosition3D( xTransformation->transform( rScaledLogicPoints.P0 ) );
[ + - ][ + - ]
145 [ + - ][ + - ]: 4080 : drawing::Position3D aPB = SequenceToPosition3D( xTransformation->transform( rScaledLogicPoints.P1 ) );
[ + - ][ + - ]
146 : :
147 [ + - ][ + - ]: 4080 : rPoints[nIndex].realloc(2);
148 [ + - ][ + - ]: 4080 : rPoints[nIndex][0].X = static_cast<sal_Int32>(aPA.PositionX);
149 [ + - ][ + - ]: 4080 : rPoints[nIndex][0].Y = static_cast<sal_Int32>(aPA.PositionY);
150 [ + - ][ + - ]: 4080 : rPoints[nIndex][1].X = static_cast<sal_Int32>(aPB.PositionX);
151 [ + - ][ + - ]: 4080 : rPoints[nIndex][1].Y = static_cast<sal_Int32>(aPB.PositionY);
152 : 4080 : }
153 : :
154 : 0 : void addLine3D( drawing::PolyPolygonShape3D& rPoints, sal_Int32 nIndex
155 : : , const GridLinePoints& rBasePoints
156 : : , const Reference< XTransformation > & xTransformation )
157 : : {
158 [ # # ][ # # ]: 0 : drawing::Position3D aPoint = SequenceToPosition3D( xTransformation->transform( rBasePoints.P0 ) );
[ # # ][ # # ]
159 [ # # ]: 0 : AddPointToPoly( rPoints, aPoint, nIndex );
160 [ # # ][ # # ]: 0 : aPoint = SequenceToPosition3D( xTransformation->transform( rBasePoints.P1 ) );
[ # # ][ # # ]
161 [ # # ]: 0 : AddPointToPoly( rPoints, aPoint, nIndex );
162 [ # # ][ # # ]: 0 : aPoint = SequenceToPosition3D( xTransformation->transform( rBasePoints.P2 ) );
[ # # ][ # # ]
163 [ # # ]: 0 : AddPointToPoly( rPoints, aPoint, nIndex );
164 : 0 : }
165 : :
166 : : //---------------------------------------------------------------------------------
167 : : //---------------------------------------------------------------------------------
168 : : //---------------------------------------------------------------------------------
169 : : //---------------------------------------------------------------------------------
170 : :
171 : 1938 : VCartesianGrid::VCartesianGrid( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount
172 : : , const Sequence< Reference< beans::XPropertySet > > & rGridPropertiesList )
173 : : : VAxisOrGridBase( nDimensionIndex, nDimensionCount )
174 [ + - ]: 1938 : , m_aGridPropertiesList( rGridPropertiesList )
175 : : {
176 [ + - ][ + - ]: 1938 : m_pPosHelper = new PlottingPositionHelper();
177 : 1938 : }
178 : :
179 [ + - ]: 1938 : VCartesianGrid::~VCartesianGrid()
180 : : {
181 [ + - ][ + - ]: 1938 : delete m_pPosHelper;
182 : 1938 : m_pPosHelper = NULL;
183 [ - + ]: 1938 : }
184 : :
185 : 1938 : void VCartesianGrid::fillLinePropertiesFromGridModel( ::std::vector<VLineProperties>& rLinePropertiesList
186 : : , const Sequence< Reference< beans::XPropertySet > > & rGridPropertiesList )
187 : : {
188 : 1938 : rLinePropertiesList.clear();
189 [ + - ]: 1938 : if( !rGridPropertiesList.getLength() )
190 : 1938 : return;
191 : :
192 [ + - ]: 1938 : VLineProperties aLineProperties;
193 [ + + ]: 5814 : for( sal_Int32 nN=0; nN < rGridPropertiesList.getLength(); nN++ )
194 : : {
195 [ + - ][ + + ]: 3876 : if(!AxisHelper::isGridVisible( rGridPropertiesList[nN] ))
196 [ + - ]: 3115 : aLineProperties.LineStyle = uno::makeAny( drawing::LineStyle_NONE );
197 : : else
198 [ + - ]: 761 : aLineProperties.initFromPropertySet( rGridPropertiesList[nN] );
199 [ + - ]: 3876 : rLinePropertiesList.push_back(aLineProperties);
200 : 1938 : }
201 : : };
202 : :
203 : 1938 : void VCartesianGrid::createShapes()
204 : : {
205 [ + - ]: 1938 : if(!m_aGridPropertiesList.getLength())
206 : : return;
207 : : //somehow equal to axis tickmarks
208 : :
209 : : //-----------------------------------------
210 : : //create named group shape
211 : : Reference< drawing::XShapes > xGroupShape_Shapes(
212 [ + - ]: 1938 : this->createGroupShape( m_xLogicTarget, m_aCID ) );
213 : :
214 [ - + ]: 1938 : if(!xGroupShape_Shapes.is())
215 : : return;
216 : : //-----------------------------------------
217 : :
218 [ + - ]: 1938 : ::std::vector<VLineProperties> aLinePropertiesList;
219 [ + - ]: 1938 : fillLinePropertiesFromGridModel( aLinePropertiesList, m_aGridPropertiesList );
220 : :
221 : : //-----------------------------------------
222 : : //create all scaled tickmark values
223 [ + - ]: 1938 : boost::scoped_ptr< TickFactory > apTickFactory( this->createTickFactory() );
224 : 1938 : TickFactory& aTickFactory = *apTickFactory.get();
225 [ + - ]: 1938 : ::std::vector< ::std::vector< TickInfo > > aAllTickInfos;
226 [ + - ]: 1938 : aTickFactory.getAllTicks( aAllTickInfos );
227 : :
228 : : //-----------------------------------------
229 : : //create tick mark line shapes
230 : 1938 : ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = aAllTickInfos.begin();
231 [ + - ]: 1938 : const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd = aAllTickInfos.end();
232 : :
233 [ + - ][ - + ]: 1938 : if(aDepthIter == aDepthEnd)//no tickmarks at all
234 : : return;
235 : :
236 : :
237 : 1938 : sal_Int32 nLinePropertiesCount = aLinePropertiesList.size();
238 [ + + ][ + - ]: 11628 : for( sal_Int32 nDepth=0
[ + + ]
239 [ + - ]: 5814 : ; aDepthIter != aDepthEnd && nDepth < nLinePropertiesCount
240 : : ; ++aDepthIter, nDepth++ )
241 : : {
242 [ + - ][ + + ]: 3876 : if( !aLinePropertiesList[nDepth].isLineVisible() )
243 : 3115 : continue;
244 : :
245 : 761 : Reference< drawing::XShapes > xTarget( xGroupShape_Shapes );
246 [ - + ]: 761 : if( nDepth > 0 )
247 : : {
248 : : xTarget.set( this->createGroupShape( m_xLogicTarget
249 : : , ObjectIdentifier::addChildParticle( m_aCID, ObjectIdentifier::createChildParticleWithIndex( OBJECTTYPE_SUBGRID, nDepth-1 ) )
250 [ # # ][ # # ]: 0 : ) );
[ # # ][ # # ]
251 [ # # ]: 0 : if(!xTarget.is())
252 [ # # ]: 0 : xTarget.set( xGroupShape_Shapes );
253 : : }
254 : :
255 [ + - ]: 761 : if(2==m_nDimension)
256 : : {
257 : :
258 [ + - ]: 761 : GridLinePoints aGridLinePoints( m_pPosHelper, m_nDimensionIndex );
259 : :
260 : 761 : sal_Int32 nPointCount = (*aDepthIter).size();
261 [ + - ]: 761 : drawing::PointSequenceSequence aPoints(nPointCount);
262 : :
263 [ + - ]: 761 : ::std::vector< TickInfo >::const_iterator aTickIter = (*aDepthIter).begin();
264 [ + - ]: 761 : const ::std::vector< TickInfo >::const_iterator aTickEnd = (*aDepthIter).end();
265 : 761 : sal_Int32 nRealPointCount = 0;
266 [ + - ][ + + ]: 4841 : for( ; aTickIter != aTickEnd; ++aTickIter )
267 : : {
268 [ - + ]: 4080 : if( !(*aTickIter).bPaintIt )
269 : 0 : continue;
270 [ + - ]: 4080 : aGridLinePoints.update( (*aTickIter).fScaledTickValue );
271 [ + - ][ + - ]: 4080 : addLine2D( aPoints, nRealPointCount, aGridLinePoints, m_pPosHelper->getTransformationScaledLogicToScene() );
272 : 4080 : nRealPointCount++;
273 : : }
274 [ + - ]: 761 : aPoints.realloc(nRealPointCount);
275 [ + - ]: 761 : m_pShapeFactory->createLine2D( xTarget, aPoints, &aLinePropertiesList[nDepth] );
276 : :
277 : : //prepare polygon for handle shape:
278 [ + - ]: 761 : drawing::PointSequenceSequence aHandlesPoints(1);
279 [ + - ]: 761 : sal_Int32 nOldHandleCount = aHandlesPoints[0].getLength();
280 [ + - ][ + - ]: 761 : aHandlesPoints[0].realloc(nOldHandleCount+nRealPointCount);
281 [ + + ]: 4841 : for( sal_Int32 nN = 0; nN<nRealPointCount; nN++)
282 [ + - ][ + - ]: 4080 : aHandlesPoints[0][nOldHandleCount+nN] = aPoints[nN][1];
[ + - ][ + - ]
283 : :
284 : : //create handle shape:
285 [ + - ]: 761 : VLineProperties aHandleLineProperties;
286 [ + - ]: 761 : aHandleLineProperties.LineStyle = uno::makeAny( drawing::LineStyle_NONE );
287 : : Reference< drawing::XShape > xHandleShape =
288 [ + - ]: 761 : m_pShapeFactory->createLine2D( xTarget, aHandlesPoints, &aHandleLineProperties );
289 [ + - ][ + - ]: 761 : m_pShapeFactory->setShapeName( xHandleShape, C2U("HandlesOnly") );
[ + - ][ + - ]
[ + - ]
290 : : }
291 : : //-----------------------------------------
292 : : else //if(2!=m_nDimension)
293 : : {
294 [ # # ]: 0 : GridLinePoints aGridLinePoints( m_pPosHelper, m_nDimensionIndex, m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
295 : :
296 : 0 : sal_Int32 nPointCount = (*aDepthIter).size();
297 [ # # ]: 0 : drawing::PolyPolygonShape3D aPoints;
298 [ # # ]: 0 : aPoints.SequenceX.realloc(nPointCount);
299 [ # # ]: 0 : aPoints.SequenceY.realloc(nPointCount);
300 [ # # ]: 0 : aPoints.SequenceZ.realloc(nPointCount);
301 : :
302 [ # # ]: 0 : ::std::vector< TickInfo >::const_iterator aTickIter = (*aDepthIter).begin();
303 [ # # ]: 0 : const ::std::vector< TickInfo >::const_iterator aTickEnd = (*aDepthIter).end();
304 : 0 : sal_Int32 nRealPointCount = 0;
305 : 0 : sal_Int32 nPolyIndex = 0;
306 [ # # ][ # # ]: 0 : for( ; aTickIter != aTickEnd; ++aTickIter, ++nPolyIndex )
307 : : {
308 [ # # ]: 0 : if( !(*aTickIter).bPaintIt )
309 : 0 : continue;
310 : :
311 [ # # ]: 0 : aGridLinePoints.update( (*aTickIter).fScaledTickValue );
312 [ # # ][ # # ]: 0 : addLine3D( aPoints, nPolyIndex, aGridLinePoints, m_pPosHelper->getTransformationScaledLogicToScene() );
313 : 0 : nRealPointCount+=3;
314 : : }
315 [ # # ]: 0 : aPoints.SequenceX.realloc(nRealPointCount);
316 [ # # ]: 0 : aPoints.SequenceY.realloc(nRealPointCount);
317 [ # # ]: 0 : aPoints.SequenceZ.realloc(nRealPointCount);
318 [ # # ][ # # ]: 0 : m_pShapeFactory->createLine3D( xTarget, aPoints, aLinePropertiesList[nDepth] );
[ # # ]
319 : : }
320 [ - + ][ + - ]: 2699 : }
[ - + ][ - + ]
[ + - ]
321 : : }
322 : :
323 : : //.............................................................................
324 : : } //namespace chart
325 : : //.............................................................................
326 : :
327 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|