LibreOffice Module chart2 (master) 1
VPolarGrid.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 "VPolarGrid.hxx"
21#include "VCartesianGrid.hxx"
22#include "Tickmarks.hxx"
23#include <GridProperties.hxx>
25#include <ShapeFactory.hxx>
26#include <ObjectIdentifier.hxx>
27#include <CommonConverters.hxx>
28#include <VLineProperties.hxx>
30
31#include <osl/diagnose.h>
32
33#include <vector>
34
35namespace chart
36{
37using namespace ::com::sun::star;
38using namespace ::com::sun::star::chart2;
39using ::com::sun::star::uno::Reference;
40
41VPolarGrid::VPolarGrid( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount
42 , std::vector< rtl::Reference< ::chart::GridProperties > > aGridPropertiesList )
43 : VAxisOrGridBase( nDimensionIndex, nDimensionCount )
44 , m_aGridPropertiesList( std::move(aGridPropertiesList) )
45 , m_pPosHelper( new PolarPlottingPositionHelper() )
46{
48}
49
51{
52}
53
54void VPolarGrid::setIncrements( std::vector< ExplicitIncrementData >&& rIncrements )
55{
56 m_aIncrements = std::move(rIncrements);
57}
58
59void VPolarGrid::getAllTickInfos( sal_Int32 nDimensionIndex, TickInfoArraysType& rAllTickInfos ) const
60{
61 const std::vector<ExplicitScaleData>& rScales = m_pPosHelper->getScales();
62 TickFactory aTickFactory(rScales[nDimensionIndex], m_aIncrements[nDimensionIndex]);
63 aTickFactory.getAllTicks( rAllTickInfos );
64}
65
67 drawing::PointSequenceSequence& rPoints
68 , TickInfoArraysType& rAllTickInfos
69 , const ExplicitIncrementData& rIncrement
70 , const ExplicitScaleData& rScale
71 , PolarPlottingPositionHelper const * pPosHelper
72 , double fLogicRadius, double fLogicZ )
73{
74 Reference< XScaling > xInverseScaling;
75 if( rScale.Scaling.is() )
76 xInverseScaling = rScale.Scaling->getInverseScaling();
77
78 sal_Int32 nTick = 0;
79 EquidistantTickIter aIter( rAllTickInfos, rIncrement, 0 );
80 auto pPoints = rPoints.getArray();
81 for( TickInfo* pTickInfo = aIter.firstInfo()
82 ; pTickInfo
83 ; pTickInfo = aIter.nextInfo(), nTick++ )
84 {
85 if(nTick>=rPoints[0].getLength())
86 pPoints[0].realloc(rPoints[0].getLength()+30);
87 auto pPoints0 = pPoints[0].getArray();
88
89 //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
90 double fLogicAngle = pTickInfo->getUnscaledTickValue();
91
92 drawing::Position3D aScenePosition3D( pPosHelper->transformAngleRadiusToScene( fLogicAngle, fLogicRadius, fLogicZ ) );
93 pPoints0[nTick].X = static_cast<sal_Int32>(aScenePosition3D.PositionX);
94 pPoints0[nTick].Y = static_cast<sal_Int32>(aScenePosition3D.PositionY);
95 }
96 if(rPoints[0].getLength()>1)
97 {
98 pPoints[0].realloc(nTick+1);
99 auto pPoints0 = pPoints[0].getArray();
100 pPoints0[nTick].X = rPoints[0][0].X;
101 pPoints0[nTick].Y = rPoints[0][0].Y;
102 }
103 else
104 pPoints[0].realloc(0);
105}
106#ifdef NOTYET
107void VPolarGrid::create2DAngleGrid( const Reference< drawing::XShapes >& xLogicTarget
108 , TickInfoArraysType& /* rRadiusTickInfos */
109 , TickInfoArraysType& rAngleTickInfos
110 , const std::vector<VLineProperties>& rLinePropertiesList )
111{
113 createGroupShape( xLogicTarget, m_aCID ) );
114
115 const std::vector<ExplicitScaleData>& rScales = m_pPosHelper->getScales();
116 const ExplicitScaleData& rAngleScale = rScales[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 if(nLinePropertiesCount)
126 {
127 double fLogicZ = 1.0;//as defined
128 sal_Int32 nDepth=0;
129 //create axis main lines
130 drawing::PointSequenceSequence aAllPoints;
131 for (auto const& tick : rAngleTickInfos[0])
132 {
133 if( !tick.bPaintIt )
134 continue;
135
136 //xxxxx rTickInfo.updateUnscaledValue( xInverseScaling );
137 double fLogicAngle = tick.getUnscaledTickValue();
138
139 drawing::PointSequenceSequence aPoints(1);
140 aPoints[0].realloc(2);
141 drawing::Position3D aScenePositionStart( m_pPosHelper->transformAngleRadiusToScene( fLogicAngle, fLogicInnerRadius, fLogicZ ) );
142 drawing::Position3D aScenePositionEnd( m_pPosHelper->transformAngleRadiusToScene( fLogicAngle, fLogicOuterRadius, fLogicZ ) );
143 aPoints[0][0].X = static_cast<sal_Int32>(aScenePositionStart.PositionX);
144 aPoints[0][0].Y = static_cast<sal_Int32>(aScenePositionStart.PositionY);
145 aPoints[0][1].X = static_cast<sal_Int32>(aScenePositionEnd.PositionX);
146 aPoints[0][1].Y = static_cast<sal_Int32>(aScenePositionEnd.PositionY);
147 appendPointSequence( aAllPoints, aPoints );
148 }
149
151 xMainTarget, aAllPoints, &rLinePropertiesList[nDepth] );
152 //because of this name this line will be used for marking
153 m_pShapeFactory->setShapeName( xShape, "MarkHandles" );
154 }
155}
156#endif
157
159 , TickInfoArraysType& rRadiusTickInfos
160 , TickInfoArraysType& rAngleTickInfos
161 , const std::vector<VLineProperties>& rLinePropertiesList )
162{
164 createGroupShape( xLogicTarget, m_aCID );
165
166 const std::vector<ExplicitScaleData>& rScales = m_pPosHelper->getScales();
167 const ExplicitScaleData& rRadiusScale = rScales[1];
168 const ExplicitScaleData& rAngleScale = rScales[0];
169 const ExplicitIncrementData& rAngleIncrement = m_aIncrements[0];
170 Reference< XScaling > xInverseRadiusScaling;
171 if( rRadiusScale.Scaling.is() )
172 xInverseRadiusScaling = rRadiusScale.Scaling->getInverseScaling();
173
174 sal_Int32 nLinePropertiesCount = rLinePropertiesList.size();
175 TickInfoArraysType::iterator aDepthIter = rRadiusTickInfos.begin();
176 const TickInfoArraysType::const_iterator aDepthEnd = rRadiusTickInfos.end();
177 for( sal_Int32 nDepth=0
178 ; aDepthIter != aDepthEnd && nDepth < nLinePropertiesCount
179 ; ++aDepthIter, nDepth++ )
180 {
181 if( !rLinePropertiesList[nDepth].isLineVisible() )
182 continue;
183
185 if( nDepth > 0 )
186 {
187 xTarget = createGroupShape( xLogicTarget
189 );
190 if(!xTarget.is())
191 xTarget = xMainTarget;
192 }
193
194 //create axis main lines
195 drawing::PointSequenceSequence aAllPoints;
196 for (auto const& tick : *aDepthIter)
197 {
198 if( !tick.bPaintIt )
199 continue;
200
201 //xxxxx rTickInfo.updateUnscaledValue( xInverseRadiusScaling );
202 double fLogicRadius = tick.getUnscaledTickValue();
203 double const fLogicZ = 1.0;//as defined
204
205 drawing::PointSequenceSequence aPoints(1);
207 , rAngleIncrement, rAngleScale, m_pPosHelper.get(), fLogicRadius, fLogicZ );
208 if(aPoints[0].getLength())
209 appendPointSequence( aAllPoints, aPoints );
210 }
211
213 xTarget, aAllPoints, &rLinePropertiesList[nDepth] );
214 //because of this name this line will be used for marking
215 ::chart::ShapeFactory::setShapeName( xShape, "MarkHandles" );
216 }
217}
218
220{
221 OSL_PRECOND(m_xLogicTarget.is()&&m_xFinalTarget.is(),"Axis is not proper initialized");
222 if(!(m_xLogicTarget.is()&&m_xFinalTarget.is()))
223 return;
224 if(m_aGridPropertiesList.empty())
225 return;
226
227 //create all scaled tickmark values
228 TickInfoArraysType aAngleTickInfos;
229 TickInfoArraysType aRadiusTickInfos;
230 getAllTickInfos( 0, aAngleTickInfos );
231 getAllTickInfos( 1, aRadiusTickInfos );
232
233 std::vector<VLineProperties> aLinePropertiesList;
235
236 //create tick mark line shapes
237 if(m_nDimension==2)
238 {
239 if(m_nDimensionIndex==1)
240 create2DRadiusGrid( m_xLogicTarget, aRadiusTickInfos, aAngleTickInfos, aLinePropertiesList );
241 //else //no Angle Grid so far as this equals exactly the y axis positions
242 // create2DAngleGrid( m_xLogicTarget, aRadiusTickInfos, aAngleTickInfos, aLinePropertiesList );
243 }
244}
245
246} //namespace chart
247
248/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual TickInfo * nextInfo() override
virtual TickInfo * firstInfo() override
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
rtl::Reference< SvxShapeGroupAnyD > m_xFinalTarget
Definition: PlotterBase.hxx:70
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
css::drawing::Position3D transformAngleRadiusToScene(double fLogicValueOnAngleAxis, double fLogicValueOnRadiusAxis, double fLogicZ, bool bDoScaling=true) const
static void setShapeName(const rtl::Reference< SvxShape > &xShape, const OUString &rName)
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
static void fillLinePropertiesFromGridModel(std::vector< VLineProperties > &rLinePropertiesList, const std::vector< rtl::Reference< ::chart::GridProperties > > &rGridPropertiesList)
static void createLinePointSequence_ForAngleAxis(css::drawing::PointSequenceSequence &rPoints, TickInfoArraysType &rAllTickInfos, const ExplicitIncrementData &rIncrement, const ExplicitScaleData &rScale, PolarPlottingPositionHelper const *pPosHelper, double fLogicRadius, double fLogicZ)
Definition: VPolarGrid.cxx:66
std::unique_ptr< PolarPlottingPositionHelper > m_pPosHelper
Definition: VPolarGrid.hxx:58
std::vector< ExplicitIncrementData > m_aIncrements
Definition: VPolarGrid.hxx:59
VPolarGrid(sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount, std::vector< rtl::Reference< ::chart::GridProperties > > aGridPropertiesList)
Definition: VPolarGrid.cxx:41
virtual ~VPolarGrid() override
Definition: VPolarGrid.cxx:50
void create2DRadiusGrid(const rtl::Reference< SvxShapeGroupAnyD > &xLogicTarget, TickInfoArraysType &rRadiusTickInfos, TickInfoArraysType &rAngleTickInfos, const std::vector< VLineProperties > &rLinePropertiesList)
Definition: VPolarGrid.cxx:158
void getAllTickInfos(sal_Int32 nDimensionIndex, TickInfoArraysType &rAllTickInfos) const
Definition: VPolarGrid.cxx:59
std::vector< rtl::Reference< ::chart::GridProperties > > m_aGridPropertiesList
Definition: VPolarGrid.hxx:57
void setIncrements(std::vector< ExplicitIncrementData > &&rIncrements)
Definition: VPolarGrid.cxx:54
virtual void createShapes() override
Definition: VPolarGrid.cxx:219
Reference< XInterface > xTarget
double getLength(const B2DPolygon &rCandidate)
@ OBJECTTYPE_SUBGRID
std::vector< TickInfoArrayType > TickInfoArraysType
Definition: Tickmarks.hxx:59
OOO_DLLPUBLIC_CHARTTOOLS void appendPointSequence(css::drawing::PointSequenceSequence &rTarget, const css::drawing::PointSequenceSequence &rAdd)
drawing::PointSequenceSequence + drawing::PointSequenceSequence
describes how tickmarks are positioned on the scale of an axis.
This structure contains the explicit values for a scale like Minimum and Maximum.
css::uno::Reference< css::chart2::XScaling > Scaling