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