LibreOffice Module chart2 (master) 1
VCartesianGrid.cxx
Go to the documentation of this file.
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"
23#include <ShapeFactory.hxx>
24#include <ObjectIdentifier.hxx>
25#include <CommonConverters.hxx>
26#include <AxisHelper.hxx>
27#include <VLineProperties.hxx>
28#include <GridProperties.hxx>
29#include <com/sun/star/drawing/PointSequenceSequence.hpp>
30#include <com/sun/star/drawing/LineStyle.hpp>
31
32#include <memory>
33#include <vector>
34
35namespace chart
36{
37using namespace ::com::sun::star;
38using namespace ::com::sun::star::chart2;
39using ::com::sun::star::uno::Reference;
40using ::com::sun::star::uno::Sequence;
41
42namespace {
43
44struct GridLinePoints
45{
46 Sequence< double > P0;
47 Sequence< double > P1;
48 Sequence< double > P2;
49
50 GridLinePoints( const PlottingPositionHelper* pPosHelper, sal_Int32 nDimensionIndex
54 void update( double fScaledTickValue );
55
57};
58
59}
60
61GridLinePoints::GridLinePoints( const PlottingPositionHelper* pPosHelper, sal_Int32 nDimensionIndex
62 , CuboidPlanePosition eLeftWallPos
63 , CuboidPlanePosition eBackWallPos
64 , CuboidPlanePosition eBottomPos )
65 : m_nDimensionIndex(nDimensionIndex)
66{
67 double MinX = pPosHelper->getLogicMinX();
68 double MinY = pPosHelper->getLogicMinY();
69 double MinZ = pPosHelper->getLogicMinZ();
70 double MaxX = pPosHelper->getLogicMaxX();
71 double MaxY = pPosHelper->getLogicMaxY();
72 double MaxZ = pPosHelper->getLogicMaxZ();
73
74 pPosHelper->doLogicScaling( &MinX,&MinY,&MinZ );
75 pPosHelper->doLogicScaling( &MaxX,&MaxY,&MaxZ );
76
77 if(!pPosHelper->isMathematicalOrientationX())
78 std::swap( MinX, MaxX );
79 if(!pPosHelper->isMathematicalOrientationY())
80 std::swap( MinY, MaxY );
81 if(pPosHelper->isMathematicalOrientationZ())//z axis in draw is reverse to mathematical
82 std::swap( MinZ, MaxZ );
83 bool bSwapXY = pPosHelper->isSwapXAndY();
84
85 //P0: point on 'back' wall, not on 'left' wall
86 //P1: point on both walls
87 //P2: point on 'left' wall not on 'back' wall
88
89 const double v0 = (eLeftWallPos == CuboidPlanePosition_Left || bSwapXY) ? MinX : MaxX;
90 const double v1 = (eLeftWallPos == CuboidPlanePosition_Left || !bSwapXY) ? MinY : MaxY;
91 const double v2 = (eBackWallPos == CuboidPlanePosition_Back) ? MinZ : MaxZ;
92 P0 = P1 = P2 = { v0, v1, v2 };
93
95 {
96 P0.getArray()[1] = (eLeftWallPos == CuboidPlanePosition_Left || !bSwapXY) ? MaxY : MinY;
97 P2.getArray()[2]= (eBackWallPos == CuboidPlanePosition_Back) ? MaxZ : MinZ;
98 if( eBottomPos != CuboidPlanePosition_Bottom && !bSwapXY )
99 P2=P1;
100 }
101 else if(m_nDimensionIndex==1)
102 {
103 P0.getArray()[0]= (eLeftWallPos == CuboidPlanePosition_Left || bSwapXY) ? MaxX : MinX;
104 P2.getArray()[2]= (eBackWallPos == CuboidPlanePosition_Back) ? MaxZ : MinZ;
105 if( eBottomPos != CuboidPlanePosition_Bottom && bSwapXY )
106 P2=P1;
107 }
108 else if(m_nDimensionIndex==2)
109 {
110 P0.getArray()[0]= (eLeftWallPos == CuboidPlanePosition_Left || bSwapXY) ? MaxX : MinX;
111 P2.getArray()[1]= (eLeftWallPos == CuboidPlanePosition_Left || !bSwapXY) ? MaxY : MinY;
112 if( eBottomPos != CuboidPlanePosition_Bottom )
113 {
114 if( !bSwapXY )
115 P0=P1;
116 else
117 P2=P1;
118 }
119 }
120}
121
122void GridLinePoints::update( double fScaledTickValue )
123{
124 P0.getArray()[m_nDimensionIndex] = P1.getArray()[m_nDimensionIndex] = P2.getArray()[m_nDimensionIndex] = fScaledTickValue;
125}
126
127static void addLine2D( drawing::PointSequenceSequence& rPoints, sal_Int32 nIndex
128 , const GridLinePoints& rScaledLogicPoints
129 , const XTransformation2& rTransformation
130 )
131{
132 drawing::Position3D aPA = rTransformation.transform( SequenceToPosition3D(rScaledLogicPoints.P0) );
133 drawing::Position3D aPB = rTransformation.transform( SequenceToPosition3D(rScaledLogicPoints.P1) );
134
135 rPoints.getArray()[nIndex]
136 = { { static_cast<sal_Int32>(aPA.PositionX), static_cast<sal_Int32>(aPA.PositionY) },
137 { static_cast<sal_Int32>(aPB.PositionX), static_cast<sal_Int32>(aPB.PositionY) } };
138}
139
140static void addLine3D( std::vector<std::vector<css::drawing::Position3D>>& rPoints, sal_Int32 nIndex
141 , const GridLinePoints& rBasePoints
142 , const XTransformation2 & rTransformation )
143{
144 drawing::Position3D aPoint =rTransformation.transform( rBasePoints.P0 );
145 AddPointToPoly( rPoints, aPoint, nIndex );
146 aPoint = rTransformation.transform( rBasePoints.P1 );
147 AddPointToPoly( rPoints, aPoint, nIndex );
148 aPoint = rTransformation.transform( rBasePoints.P2 );
149 AddPointToPoly( rPoints, aPoint, nIndex );
150}
151
152VCartesianGrid::VCartesianGrid( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount
153 , std::vector< rtl::Reference< ::chart::GridProperties > > aGridPropertiesList )
154 : VAxisOrGridBase( nDimensionIndex, nDimensionCount )
155 , m_aGridPropertiesList( std::move(aGridPropertiesList) )
156{
158}
159
161{
162 delete m_pPosHelper;
163 m_pPosHelper = nullptr;
164}
165
166void VCartesianGrid::fillLinePropertiesFromGridModel( std::vector<VLineProperties>& rLinePropertiesList
167 , const std::vector< rtl::Reference< ::chart::GridProperties > > & rGridPropertiesList )
168{
169 rLinePropertiesList.clear();
170 if( rGridPropertiesList.empty() )
171 return;
172
173 VLineProperties aLineProperties;
174 for( const auto & rxPropSet : rGridPropertiesList )
175 {
176 if(!AxisHelper::isGridVisible( rxPropSet ))
177 aLineProperties.LineStyle <<= drawing::LineStyle_NONE;
178 else
179 aLineProperties.initFromPropertySet( rxPropSet );
180 rLinePropertiesList.push_back(aLineProperties);
181 }
182};
183
185{
186 if(m_aGridPropertiesList.empty())
187 return;
188 //somehow equal to axis tickmarks
189
190 //create named group shape
191 rtl::Reference< SvxShapeGroupAnyD > xGroupShape_Shapes(
193
194 if(!xGroupShape_Shapes.is())
195 return;
196
197 std::vector<VLineProperties> aLinePropertiesList;
199
200 //create all scaled tickmark values
201 std::unique_ptr< TickFactory > apTickFactory( createTickFactory() );
202 TickFactory& aTickFactory = *apTickFactory;
203 TickInfoArraysType aAllTickInfos;
204 aTickFactory.getAllTicks( aAllTickInfos );
205
206 //create tick mark line shapes
207
208 if(aAllTickInfos.empty())//no tickmarks at all
209 return;
210
211 TickInfoArraysType::iterator aDepthIter = aAllTickInfos.begin();
212 const TickInfoArraysType::const_iterator aDepthEnd = aAllTickInfos.end();
213
214 sal_Int32 nLinePropertiesCount = aLinePropertiesList.size();
215 for( sal_Int32 nDepth=0
216 ; aDepthIter != aDepthEnd && nDepth < nLinePropertiesCount
217 ; ++aDepthIter, nDepth++ )
218 {
219 if( !aLinePropertiesList[nDepth].isLineVisible() )
220 continue;
221
222 rtl::Reference< SvxShapeGroupAnyD > xTarget( xGroupShape_Shapes );
223 if( nDepth > 0 )
224 {
227 );
228 if(!xTarget.is())
229 xTarget = xGroupShape_Shapes;
230 }
231
232 if(m_nDimension==2)
233 {
234
235 GridLinePoints aGridLinePoints( m_pPosHelper, m_nDimensionIndex );
236
237 sal_Int32 nPointCount = (*aDepthIter).size();
238 drawing::PointSequenceSequence aPoints(nPointCount);
239
240 sal_Int32 nRealPointCount = 0;
241 for (auto const& tick : *aDepthIter)
242 {
243 if( !tick.bPaintIt )
244 continue;
245 aGridLinePoints.update( tick.fScaledTickValue );
246 addLine2D( aPoints, nRealPointCount, aGridLinePoints, *m_pPosHelper->getTransformationScaledLogicToScene() );
247 nRealPointCount++;
248 }
249 aPoints.realloc(nRealPointCount);
250 ShapeFactory::createLine2D( xTarget, aPoints, &aLinePropertiesList[nDepth] );
251
252 //prepare polygon for handle shape:
253 drawing::PointSequenceSequence aHandlesPoints(1);
254 auto pHandlesPoints = aHandlesPoints.getArray();
255 pHandlesPoints[0].realloc(nRealPointCount);
256 auto pHandlesPoints0 = pHandlesPoints[0].getArray();
257 for( sal_Int32 nN = 0; nN<nRealPointCount; nN++)
258 pHandlesPoints0[nN] = aPoints[nN][1];
259
260 //create handle shape:
261 VLineProperties aHandleLineProperties;
262 aHandleLineProperties.LineStyle <<= drawing::LineStyle_NONE;
264 ShapeFactory::createLine2D( xTarget, aHandlesPoints, &aHandleLineProperties );
265 ::chart::ShapeFactory::setShapeName( xHandleShape, "HandlesOnly" );
266 }
267 else //if(2!=m_nDimension)
268 {
269 GridLinePoints aGridLinePoints( m_pPosHelper, m_nDimensionIndex, m_eLeftWallPos, m_eBackWallPos, m_eBottomPos );
270
271 sal_Int32 nPointCount = (*aDepthIter).size();
272 std::vector<std::vector<css::drawing::Position3D>> aPoints;
273 aPoints.resize(nPointCount);
274
275 sal_Int32 nRealPointCount = 0;
276 sal_Int32 nPolyIndex = 0;
277 for (auto const& tick : *aDepthIter)
278 {
279 if( !tick.bPaintIt )
280 {
281 ++nPolyIndex;
282 continue;
283 }
284
285 aGridLinePoints.update( tick.fScaledTickValue );
286 addLine3D( aPoints, nPolyIndex, aGridLinePoints, *m_pPosHelper->getTransformationScaledLogicToScene() );
287 nRealPointCount+=3;
288 ++nPolyIndex;
289 }
290 aPoints.resize(nRealPointCount);
291 ShapeFactory::createLine3D( xTarget, aPoints, aLinePropertiesList[nDepth] );
292 }
293 }
294}
295
296} //namespace chart
297
298/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Sequence< double > P1
sal_Int32 m_nDimensionIndex
Sequence< double > P0
Sequence< double > P2
static bool isGridVisible(const rtl::Reference< ::chart::GridProperties > &xGridProperties)
Definition: AxisHelper.cxx:665
static OUString createChildParticleWithIndex(ObjectType eObjectType, sal_Int32 nIndex)
static OUString addChildParticle(std::u16string_view rParticle, std::u16string_view rChildParticle)
rtl::Reference< SvxShapeGroupAnyD > m_xLogicTarget
Definition: PlotterBase.hxx:69
PlottingPositionHelper * m_pPosHelper
Definition: PlotterBase.hxx:75
const sal_Int32 m_nDimension
Definition: PlotterBase.hxx:73
rtl::Reference< SvxShapeGroupAnyD > createGroupShape(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const OUString &rName=OUString())
Definition: PlotterBase.cxx:71
virtual ::chart::XTransformation2 * getTransformationScaledLogicToScene() const
static void setShapeName(const rtl::Reference< SvxShape > &xShape, const OUString &rName)
static rtl::Reference< Svx3DPolygonObject > createLine3D(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const std::vector< std::vector< css::drawing::Position3D > > &rPoints, const VLineProperties &rLineProperties)
static rtl::Reference< SvxShapePolyPolygon > createLine2D(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const css::drawing::PointSequenceSequence &rPoints, const VLineProperties *pLineProperties=nullptr)
void getAllTicks(TickInfoArraysType &rAllTickInfos) const
Definition: Tickmarks.cxx:119
CuboidPlanePosition m_eBottomPos
CuboidPlanePosition m_eLeftWallPos
virtual TickFactory * createTickFactory()
CuboidPlanePosition m_eBackWallPos
virtual void createShapes() override
static void fillLinePropertiesFromGridModel(std::vector< VLineProperties > &rLinePropertiesList, const std::vector< rtl::Reference< ::chart::GridProperties > > &rGridPropertiesList)
virtual ~VCartesianGrid() override
std::vector< rtl::Reference< ::chart::GridProperties > > m_aGridPropertiesList
allows the transformation of numeric values from one coordinate-system into another.
virtual css::drawing::Position3D transform(const css::drawing::Position3D &rSourceValues) const =0
transforms the given input data tuple, given in the source coordinate system, according to the intern...
Reference< XInterface > xTarget
sal_Int32 nIndex
@ OBJECTTYPE_SUBGRID
OOO_DLLPUBLIC_CHARTTOOLS void AddPointToPoly(css::drawing::PolyPolygonShape3D &rPoly, const css::drawing::Position3D &rPos, sal_Int32 nSequenceIndex=0)
PolyPolygonShape3D + drawing::Position3D -> PolyPolygonShape3D.
static void addLine3D(std::vector< std::vector< css::drawing::Position3D > > &rPoints, sal_Int32 nIndex, const GridLinePoints &rBasePoints, const XTransformation2 &rTransformation)
std::vector< TickInfoArrayType > TickInfoArraysType
Definition: Tickmarks.hxx:59
static void addLine2D(drawing::PointSequenceSequence &rPoints, sal_Int32 nIndex, const GridLinePoints &rScaledLogicPoints, const XTransformation2 &rTransformation)
CuboidPlanePosition
@ CuboidPlanePosition_Left
@ CuboidPlanePosition_Back
@ CuboidPlanePosition_Bottom
OOO_DLLPUBLIC_CHARTTOOLS css::drawing::Position3D SequenceToPosition3D(const css::uno::Sequence< double > &rSeq)
Sequence<double> -> drawing::Position3D.
void initFromPropertySet(const css::uno::Reference< css::beans::XPropertySet > &xProp)
bool update()