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