1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_chart2.hxx" 30*cdf0e10cSrcweir #include "VPolarGrid.hxx" 31*cdf0e10cSrcweir #include "VCartesianGrid.hxx" 32*cdf0e10cSrcweir #include "Tickmarks.hxx" 33*cdf0e10cSrcweir #include "PlottingPositionHelper.hxx" 34*cdf0e10cSrcweir #include "ShapeFactory.hxx" 35*cdf0e10cSrcweir #include "ObjectIdentifier.hxx" 36*cdf0e10cSrcweir #include "macros.hxx" 37*cdf0e10cSrcweir #include "CommonConverters.hxx" 38*cdf0e10cSrcweir #include "Tickmarks_Equidistant.hxx" 39*cdf0e10cSrcweir #include <com/sun/star/drawing/LineStyle.hpp> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include <vector> 42*cdf0e10cSrcweir #include <memory> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir //............................................................................. 45*cdf0e10cSrcweir namespace chart 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir //............................................................................. 48*cdf0e10cSrcweir using namespace ::com::sun::star; 49*cdf0e10cSrcweir using namespace ::com::sun::star::chart2; 50*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir VPolarGrid::VPolarGrid( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount 53*cdf0e10cSrcweir , const uno::Sequence< Reference< beans::XPropertySet > > & rGridPropertiesList ) 54*cdf0e10cSrcweir : VAxisOrGridBase( nDimensionIndex, nDimensionCount ) 55*cdf0e10cSrcweir , m_aGridPropertiesList( rGridPropertiesList ) 56*cdf0e10cSrcweir , m_pPosHelper( new PolarPlottingPositionHelper() ) 57*cdf0e10cSrcweir , m_aIncrements() 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir PlotterBase::m_pPosHelper = m_pPosHelper; 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir VPolarGrid::~VPolarGrid() 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir delete m_pPosHelper; 65*cdf0e10cSrcweir m_pPosHelper = NULL; 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir void VPolarGrid::setIncrements( const std::vector< ExplicitIncrementData >& rIncrements ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir m_aIncrements = rIncrements; 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir void VPolarGrid::getAllTickInfos( sal_Int32 nDimensionIndex, ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos ) const 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir TickFactory aTickFactory( 76*cdf0e10cSrcweir m_pPosHelper->getScales()[nDimensionIndex], m_aIncrements[nDimensionIndex] ); 77*cdf0e10cSrcweir aTickFactory.getAllTicks( rAllTickInfos ); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir void VPolarGrid::createLinePointSequence_ForAngleAxis( 81*cdf0e10cSrcweir drawing::PointSequenceSequence& rPoints 82*cdf0e10cSrcweir , ::std::vector< ::std::vector< TickInfo > >& rAllTickInfos 83*cdf0e10cSrcweir , const ExplicitIncrementData& rIncrement 84*cdf0e10cSrcweir , const ExplicitScaleData& rScale 85*cdf0e10cSrcweir , PolarPlottingPositionHelper* pPosHelper 86*cdf0e10cSrcweir , double fLogicRadius, double fLogicZ ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir Reference< XScaling > xInverseScaling( NULL ); 89*cdf0e10cSrcweir if( rScale.Scaling.is() ) 90*cdf0e10cSrcweir xInverseScaling = rScale.Scaling->getInverseScaling(); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir sal_Int32 nTick = 0; 93*cdf0e10cSrcweir EquidistantTickIter aIter( rAllTickInfos, rIncrement, 0, 0 ); 94*cdf0e10cSrcweir for( TickInfo* pTickInfo = aIter.firstInfo() 95*cdf0e10cSrcweir ; pTickInfo 96*cdf0e10cSrcweir ; pTickInfo = aIter.nextInfo(), nTick++ ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir if(nTick>=rPoints[0].getLength()) 99*cdf0e10cSrcweir rPoints[0].realloc(rPoints[0].getLength()+30); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir //xxxxx pTickInfo->updateUnscaledValue( xInverseScaling ); 102*cdf0e10cSrcweir double fLogicAngle = pTickInfo->getUnscaledTickValue(); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir drawing::Position3D aScenePosition3D( pPosHelper->transformAngleRadiusToScene( fLogicAngle, fLogicRadius, fLogicZ ) ); 105*cdf0e10cSrcweir rPoints[0][nTick].X = static_cast<sal_Int32>(aScenePosition3D.PositionX); 106*cdf0e10cSrcweir rPoints[0][nTick].Y = static_cast<sal_Int32>(aScenePosition3D.PositionY); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir if(rPoints[0].getLength()>1) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir rPoints[0].realloc(nTick+1); 111*cdf0e10cSrcweir rPoints[0][nTick].X = rPoints[0][0].X; 112*cdf0e10cSrcweir rPoints[0][nTick].Y = rPoints[0][0].Y; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir else 115*cdf0e10cSrcweir rPoints[0].realloc(0); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir #ifdef NOTYET 118*cdf0e10cSrcweir void VPolarGrid::create2DAngleGrid( const Reference< drawing::XShapes >& xLogicTarget 119*cdf0e10cSrcweir , ::std::vector< ::std::vector< TickInfo > >& /* rRadiusTickInfos */ 120*cdf0e10cSrcweir , ::std::vector< ::std::vector< TickInfo > >& rAngleTickInfos 121*cdf0e10cSrcweir , const ::std::vector<VLineProperties>& rLinePropertiesList ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir Reference< drawing::XShapes > xMainTarget( 124*cdf0e10cSrcweir this->createGroupShape( xLogicTarget, m_aCID ) ); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir const ExplicitScaleData& rAngleScale = m_pPosHelper->getScales()[0]; 127*cdf0e10cSrcweir Reference< XScaling > xInverseScaling( NULL ); 128*cdf0e10cSrcweir if( rAngleScale.Scaling.is() ) 129*cdf0e10cSrcweir xInverseScaling = rAngleScale.Scaling->getInverseScaling(); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir double fLogicInnerRadius = m_pPosHelper->getInnerLogicRadius(); 132*cdf0e10cSrcweir double fLogicOuterRadius = m_pPosHelper->getOuterLogicRadius(); 133*cdf0e10cSrcweir double fLogicZ = 1.0;//as defined 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir sal_Int32 nLinePropertiesCount = rLinePropertiesList.size(); 136*cdf0e10cSrcweir ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = rAngleTickInfos.begin(); 137*cdf0e10cSrcweir sal_Int32 nDepth=0; 138*cdf0e10cSrcweir /* 139*cdf0e10cSrcweir //no subgrids so far for polar angle grid (need different radii) 140*cdf0e10cSrcweir const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd = rAngleTickInfos.end(); 141*cdf0e10cSrcweir for( ; aDepthIter != aDepthEnd && nDepth < nLinePropertiesCount 142*cdf0e10cSrcweir ; aDepthIter++, nDepth++ ) 143*cdf0e10cSrcweir */ 144*cdf0e10cSrcweir if(nLinePropertiesCount) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir //create axis main lines 147*cdf0e10cSrcweir drawing::PointSequenceSequence aAllPoints; 148*cdf0e10cSrcweir ::std::vector< TickInfo >::iterator aTickIter = (*aDepthIter).begin(); 149*cdf0e10cSrcweir const ::std::vector< TickInfo >::const_iterator aTickEnd = (*aDepthIter).end(); 150*cdf0e10cSrcweir for( ; aTickIter != aTickEnd; aTickIter++ ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir TickInfo& rTickInfo = *aTickIter; 153*cdf0e10cSrcweir if( !rTickInfo.bPaintIt ) 154*cdf0e10cSrcweir continue; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir //xxxxx rTickInfo.updateUnscaledValue( xInverseScaling ); 157*cdf0e10cSrcweir double fLogicAngle = rTickInfo.getUnscaledTickValue(); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir drawing::PointSequenceSequence aPoints(1); 160*cdf0e10cSrcweir aPoints[0].realloc(2); 161*cdf0e10cSrcweir drawing::Position3D aScenePositionStart( m_pPosHelper->transformAngleRadiusToScene( fLogicAngle, fLogicInnerRadius, fLogicZ ) ); 162*cdf0e10cSrcweir drawing::Position3D aScenePositionEnd( m_pPosHelper->transformAngleRadiusToScene( fLogicAngle, fLogicOuterRadius, fLogicZ ) ); 163*cdf0e10cSrcweir aPoints[0][0].X = static_cast<sal_Int32>(aScenePositionStart.PositionX); 164*cdf0e10cSrcweir aPoints[0][0].Y = static_cast<sal_Int32>(aScenePositionStart.PositionY); 165*cdf0e10cSrcweir aPoints[0][1].X = static_cast<sal_Int32>(aScenePositionEnd.PositionX); 166*cdf0e10cSrcweir aPoints[0][1].Y = static_cast<sal_Int32>(aScenePositionEnd.PositionY); 167*cdf0e10cSrcweir appendPointSequence( aAllPoints, aPoints ); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir Reference< drawing::XShape > xShape = m_pShapeFactory->createLine2D( 171*cdf0e10cSrcweir xMainTarget, aAllPoints, &rLinePropertiesList[nDepth] ); 172*cdf0e10cSrcweir //because of this name this line will be used for marking 173*cdf0e10cSrcweir m_pShapeFactory->setShapeName( xShape, C2U("MarkHandles") ); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir #endif 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir void VPolarGrid::create2DRadiusGrid( const Reference< drawing::XShapes >& xLogicTarget 179*cdf0e10cSrcweir , ::std::vector< ::std::vector< TickInfo > >& rRadiusTickInfos 180*cdf0e10cSrcweir , ::std::vector< ::std::vector< TickInfo > >& rAngleTickInfos 181*cdf0e10cSrcweir , const ::std::vector<VLineProperties>& rLinePropertiesList ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir Reference< drawing::XShapes > xMainTarget( 184*cdf0e10cSrcweir this->createGroupShape( xLogicTarget, m_aCID ) ); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir const ExplicitScaleData& rRadiusScale = m_pPosHelper->getScales()[1]; 187*cdf0e10cSrcweir const ExplicitScaleData& rAngleScale = m_pPosHelper->getScales()[0]; 188*cdf0e10cSrcweir const ExplicitIncrementData& rAngleIncrement = m_aIncrements[0]; 189*cdf0e10cSrcweir Reference< XScaling > xInverseRadiusScaling( NULL ); 190*cdf0e10cSrcweir if( rRadiusScale.Scaling.is() ) 191*cdf0e10cSrcweir xInverseRadiusScaling = rRadiusScale.Scaling->getInverseScaling(); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir sal_Int32 nLinePropertiesCount = rLinePropertiesList.size(); 194*cdf0e10cSrcweir ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = rRadiusTickInfos.begin(); 195*cdf0e10cSrcweir const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd = rRadiusTickInfos.end(); 196*cdf0e10cSrcweir for( sal_Int32 nDepth=0 197*cdf0e10cSrcweir ; aDepthIter != aDepthEnd && nDepth < nLinePropertiesCount 198*cdf0e10cSrcweir ; aDepthIter++, nDepth++ ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir if( !rLinePropertiesList[nDepth].isLineVisible() ) 201*cdf0e10cSrcweir continue; 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir Reference< drawing::XShapes > xTarget( xMainTarget ); 204*cdf0e10cSrcweir if( nDepth > 0 ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir xTarget.set( this->createGroupShape( xLogicTarget 207*cdf0e10cSrcweir , ObjectIdentifier::addChildParticle( m_aCID, ObjectIdentifier::createChildParticleWithIndex( OBJECTTYPE_SUBGRID, nDepth-1 ) ) 208*cdf0e10cSrcweir ) ); 209*cdf0e10cSrcweir if(!xTarget.is()) 210*cdf0e10cSrcweir xTarget.set( xMainTarget ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir //create axis main lines 214*cdf0e10cSrcweir drawing::PointSequenceSequence aAllPoints; 215*cdf0e10cSrcweir ::std::vector< TickInfo >::iterator aTickIter = (*aDepthIter).begin(); 216*cdf0e10cSrcweir const ::std::vector< TickInfo >::const_iterator aTickEnd = (*aDepthIter).end(); 217*cdf0e10cSrcweir for( ; aTickIter != aTickEnd; aTickIter++ ) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir TickInfo& rTickInfo = *aTickIter; 220*cdf0e10cSrcweir if( !rTickInfo.bPaintIt ) 221*cdf0e10cSrcweir continue; 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir //xxxxx rTickInfo.updateUnscaledValue( xInverseRadiusScaling ); 224*cdf0e10cSrcweir double fLogicRadius = rTickInfo.getUnscaledTickValue(); 225*cdf0e10cSrcweir double fLogicZ = 1.0;//as defined 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir drawing::PointSequenceSequence aPoints(1); 228*cdf0e10cSrcweir VPolarGrid::createLinePointSequence_ForAngleAxis( aPoints, rAngleTickInfos 229*cdf0e10cSrcweir , rAngleIncrement, rAngleScale, m_pPosHelper, fLogicRadius, fLogicZ ); 230*cdf0e10cSrcweir if(aPoints[0].getLength()) 231*cdf0e10cSrcweir appendPointSequence( aAllPoints, aPoints ); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir Reference< drawing::XShape > xShape = m_pShapeFactory->createLine2D( 235*cdf0e10cSrcweir xTarget, aAllPoints, &rLinePropertiesList[nDepth] ); 236*cdf0e10cSrcweir //because of this name this line will be used for marking 237*cdf0e10cSrcweir m_pShapeFactory->setShapeName( xShape, C2U("MarkHandles") ); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir void VPolarGrid::createShapes() 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir DBG_ASSERT(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"Axis is not proper initialized"); 244*cdf0e10cSrcweir if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is())) 245*cdf0e10cSrcweir return; 246*cdf0e10cSrcweir if(!m_aGridPropertiesList.getLength()) 247*cdf0e10cSrcweir return; 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir //----------------------------------------- 250*cdf0e10cSrcweir //create all scaled tickmark values 251*cdf0e10cSrcweir ::std::vector< ::std::vector< TickInfo > > aAngleTickInfos; 252*cdf0e10cSrcweir ::std::vector< ::std::vector< TickInfo > > aRadiusTickInfos; 253*cdf0e10cSrcweir getAllTickInfos( 0, aAngleTickInfos ); 254*cdf0e10cSrcweir getAllTickInfos( 1, aRadiusTickInfos ); 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir //----------------------------------------- 257*cdf0e10cSrcweir ::std::vector<VLineProperties> aLinePropertiesList; 258*cdf0e10cSrcweir VCartesianGrid::fillLinePropertiesFromGridModel( aLinePropertiesList, m_aGridPropertiesList ); 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir //----------------------------------------- 261*cdf0e10cSrcweir //create tick mark line shapes 262*cdf0e10cSrcweir if(2==m_nDimension) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir if(m_nDimensionIndex==1) 265*cdf0e10cSrcweir this->create2DRadiusGrid( m_xLogicTarget, aRadiusTickInfos, aAngleTickInfos, aLinePropertiesList ); 266*cdf0e10cSrcweir //else //no Angle Grid so far as this equals exactly the y axis positions 267*cdf0e10cSrcweir // this->create2DAngleGrid( m_xLogicTarget, aRadiusTickInfos, aAngleTickInfos, aLinePropertiesList ); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir //............................................................................. 272*cdf0e10cSrcweir } //namespace chart 273*cdf0e10cSrcweir //............................................................................. 274