1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
31 #include <osl/diagnose.h>
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::chart2
;
39 using ::com::sun::star::uno::Reference
;
41 VPolarGrid::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
) )
46 PlotterBase::m_pPosHelper
= &m_aPosHelper
;
49 VPolarGrid::~VPolarGrid()
53 void VPolarGrid::setIncrements( std::vector
< ExplicitIncrementData
>&& rIncrements
)
55 m_aIncrements
= std::move(rIncrements
);
58 void VPolarGrid::getAllTickInfos( sal_Int32 nDimensionIndex
, TickInfoArraysType
& rAllTickInfos
) const
60 const std::vector
<ExplicitScaleData
>& rScales
= m_pPosHelper
->getScales();
61 TickFactory
aTickFactory(rScales
[nDimensionIndex
], m_aIncrements
[nDimensionIndex
]);
62 aTickFactory
.getAllTicks( rAllTickInfos
);
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
)
73 Reference
< XScaling
> xInverseScaling
;
74 if( rScale
.Scaling
.is() )
75 xInverseScaling
= rScale
.Scaling
->getInverseScaling();
78 EquidistantTickIter
aIter( rAllTickInfos
, rIncrement
, 0 );
79 auto pPoints
= rPoints
.getArray();
80 for( TickInfo
* pTickInfo
= aIter
.firstInfo()
82 ; pTickInfo
= aIter
.nextInfo(), nTick
++ )
84 if(nTick
>=rPoints
[0].getLength())
85 pPoints
[0].realloc(rPoints
[0].getLength()+30);
86 auto pPoints0
= pPoints
[0].getArray();
88 //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling );
89 double fLogicAngle
= pTickInfo
->getUnscaledTickValue();
91 drawing::Position3D
aScenePosition3D( pPosHelper
->transformAngleRadiusToScene( fLogicAngle
, fLogicRadius
, fLogicZ
) );
92 pPoints0
[nTick
].X
= static_cast<sal_Int32
>(aScenePosition3D
.PositionX
);
93 pPoints0
[nTick
].Y
= static_cast<sal_Int32
>(aScenePosition3D
.PositionY
);
95 if(rPoints
[0].getLength()>1)
97 pPoints
[0].realloc(nTick
+1);
98 auto pPoints0
= pPoints
[0].getArray();
99 pPoints0
[nTick
].X
= rPoints
[0][0].X
;
100 pPoints0
[nTick
].Y
= rPoints
[0][0].Y
;
103 pPoints
[0].realloc(0);
106 void VPolarGrid::create2DAngleGrid( const Reference
< drawing::XShapes
>& xLogicTarget
107 , TickInfoArraysType
& /* rRadiusTickInfos */
108 , TickInfoArraysType
& rAngleTickInfos
109 , const std::vector
<VLineProperties
>& rLinePropertiesList
)
111 Reference
< drawing::XShapes
> xMainTarget(
112 createGroupShape( xLogicTarget
, m_aCID
) );
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();
120 double fLogicInnerRadius
= m_pPosHelper
->getInnerLogicRadius();
121 double fLogicOuterRadius
= m_pPosHelper
->getOuterLogicRadius();
123 sal_Int32 nLinePropertiesCount
= rLinePropertiesList
.size();
124 if(nLinePropertiesCount
)
126 double fLogicZ
= 1.0;//as defined
128 //create axis main lines
129 drawing::PointSequenceSequence aAllPoints
;
130 for (auto const& tick
: rAngleTickInfos
[0])
135 //xxxxx rTickInfo.updateUnscaledValue( xInverseScaling );
136 double fLogicAngle
= tick
.getUnscaledTickValue();
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
);
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" );
157 void VPolarGrid::create2DRadiusGrid( const rtl::Reference
<SvxShapeGroupAnyD
>& xLogicTarget
158 , TickInfoArraysType
& rRadiusTickInfos
159 , TickInfoArraysType
& rAngleTickInfos
160 , const std::vector
<VLineProperties
>& rLinePropertiesList
)
162 rtl::Reference
<SvxShapeGroupAnyD
> xMainTarget
=
163 createGroupShape( xLogicTarget
, m_aCID
);
165 const std::vector
<ExplicitScaleData
>& rScales
= m_pPosHelper
->getScales();
166 const ExplicitScaleData
& rRadiusScale
= rScales
[1];
167 const ExplicitScaleData
& rAngleScale
= rScales
[0];
168 const ExplicitIncrementData
& rAngleIncrement
= m_aIncrements
[0];
169 Reference
< XScaling
> xInverseRadiusScaling
;
170 if( rRadiusScale
.Scaling
.is() )
171 xInverseRadiusScaling
= rRadiusScale
.Scaling
->getInverseScaling();
173 sal_Int32 nLinePropertiesCount
= rLinePropertiesList
.size();
174 TickInfoArraysType::iterator aDepthIter
= rRadiusTickInfos
.begin();
175 const TickInfoArraysType::const_iterator aDepthEnd
= rRadiusTickInfos
.end();
176 for( sal_Int32 nDepth
=0
177 ; aDepthIter
!= aDepthEnd
&& nDepth
< nLinePropertiesCount
178 ; ++aDepthIter
, nDepth
++ )
180 if( !rLinePropertiesList
[nDepth
].isLineVisible() )
183 rtl::Reference
<SvxShapeGroupAnyD
> xTarget( xMainTarget
);
186 xTarget
= createGroupShape( xLogicTarget
187 , ObjectIdentifier::addChildParticle( m_aCID
, ObjectIdentifier::createChildParticleWithIndex( OBJECTTYPE_SUBGRID
, nDepth
-1 ) )
190 xTarget
= xMainTarget
;
193 //create axis main lines
194 drawing::PointSequenceSequence aAllPoints
;
195 for (auto const& tick
: *aDepthIter
)
200 //xxxxx rTickInfo.updateUnscaledValue( xInverseRadiusScaling );
201 double fLogicRadius
= tick
.getUnscaledTickValue();
202 double const fLogicZ
= 1.0;//as defined
204 drawing::PointSequenceSequence
aPoints(1);
205 VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints
, rAngleTickInfos
206 , rAngleIncrement
, rAngleScale
, &m_aPosHelper
, fLogicRadius
, fLogicZ
);
207 if(aPoints
[0].getLength())
208 appendPointSequence( aAllPoints
, aPoints
);
211 rtl::Reference
<SvxShapePolyPolygon
> xShape
= ShapeFactory::createLine2D(
212 xTarget
, aAllPoints
, &rLinePropertiesList
[nDepth
] );
213 //because of this name this line will be used for marking
214 ::chart::ShapeFactory::setShapeName( xShape
, u
"MarkHandles"_ustr
);
218 void VPolarGrid::createShapes()
220 OSL_PRECOND(m_xLogicTarget
.is()&&m_xFinalTarget
.is(),"Axis is not proper initialized");
221 if(!(m_xLogicTarget
.is()&&m_xFinalTarget
.is()))
223 if(m_aGridPropertiesList
.empty())
226 //create all scaled tickmark values
227 TickInfoArraysType aAngleTickInfos
;
228 TickInfoArraysType aRadiusTickInfos
;
229 getAllTickInfos( 0, aAngleTickInfos
);
230 getAllTickInfos( 1, aRadiusTickInfos
);
232 std::vector
<VLineProperties
> aLinePropertiesList
;
233 VCartesianGrid::fillLinePropertiesFromGridModel( aLinePropertiesList
, m_aGridPropertiesList
);
235 //create tick mark line shapes
238 if(m_nDimensionIndex
==1)
239 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 );
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */