1*cde9e8dcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*cde9e8dcSAndrew Rist * distributed with this work for additional information 6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance 9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an 15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the 17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations 18*cde9e8dcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*cde9e8dcSAndrew Rist *************************************************************/ 21*cde9e8dcSAndrew Rist 22*cde9e8dcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_chart2.hxx" 26cdf0e10cSrcweir #include "VCartesianGrid.hxx" 27cdf0e10cSrcweir #include "Tickmarks.hxx" 28cdf0e10cSrcweir #include "PlottingPositionHelper.hxx" 29cdf0e10cSrcweir #include "ShapeFactory.hxx" 30cdf0e10cSrcweir #include "ObjectIdentifier.hxx" 31cdf0e10cSrcweir #include "macros.hxx" 32cdf0e10cSrcweir #include "CommonConverters.hxx" 33cdf0e10cSrcweir #include "AxisHelper.hxx" 34cdf0e10cSrcweir #include <com/sun/star/drawing/PointSequenceSequence.hpp> 35cdf0e10cSrcweir #include <com/sun/star/drawing/LineStyle.hpp> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <vector> 38cdf0e10cSrcweir #include <memory> 39cdf0e10cSrcweir 40cdf0e10cSrcweir //............................................................................. 41cdf0e10cSrcweir namespace chart 42cdf0e10cSrcweir { 43cdf0e10cSrcweir //............................................................................. 44cdf0e10cSrcweir using namespace ::com::sun::star; 45cdf0e10cSrcweir using namespace ::com::sun::star::chart2; 46cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 47cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 48cdf0e10cSrcweir 49cdf0e10cSrcweir struct GridLinePoints 50cdf0e10cSrcweir { 51cdf0e10cSrcweir Sequence< double > P0; 52cdf0e10cSrcweir Sequence< double > P1; 53cdf0e10cSrcweir Sequence< double > P2; 54cdf0e10cSrcweir 55cdf0e10cSrcweir GridLinePoints( const PlottingPositionHelper* pPosHelper, sal_Int32 nDimensionIndex 56cdf0e10cSrcweir , CuboidPlanePosition eLeftWallPos=CuboidPlanePosition_Left 57cdf0e10cSrcweir , CuboidPlanePosition eBackWallPos=CuboidPlanePosition_Back 58cdf0e10cSrcweir , CuboidPlanePosition eBottomPos=CuboidPlanePosition_Bottom ); 59cdf0e10cSrcweir void update( double fScaledTickValue ); 60cdf0e10cSrcweir 61cdf0e10cSrcweir sal_Int32 m_nDimensionIndex; 62cdf0e10cSrcweir }; 63cdf0e10cSrcweir 64cdf0e10cSrcweir GridLinePoints::GridLinePoints( const PlottingPositionHelper* pPosHelper, sal_Int32 nDimensionIndex 65cdf0e10cSrcweir , CuboidPlanePosition eLeftWallPos 66cdf0e10cSrcweir , CuboidPlanePosition eBackWallPos 67cdf0e10cSrcweir , CuboidPlanePosition eBottomPos ) 68cdf0e10cSrcweir : m_nDimensionIndex(nDimensionIndex) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir double MinX = pPosHelper->getLogicMinX(); 71cdf0e10cSrcweir double MinY = pPosHelper->getLogicMinY(); 72cdf0e10cSrcweir double MinZ = pPosHelper->getLogicMinZ(); 73cdf0e10cSrcweir double MaxX = pPosHelper->getLogicMaxX(); 74cdf0e10cSrcweir double MaxY = pPosHelper->getLogicMaxY(); 75cdf0e10cSrcweir double MaxZ = pPosHelper->getLogicMaxZ(); 76cdf0e10cSrcweir 77cdf0e10cSrcweir pPosHelper->doLogicScaling( &MinX,&MinY,&MinZ ); 78cdf0e10cSrcweir pPosHelper->doLogicScaling( &MaxX,&MaxY,&MaxZ ); 79cdf0e10cSrcweir 80cdf0e10cSrcweir if(!pPosHelper->isMathematicalOrientationX()) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir double fHelp = MinX; 83cdf0e10cSrcweir MinX = MaxX; 84cdf0e10cSrcweir MaxX = fHelp; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir if(!pPosHelper->isMathematicalOrientationY()) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir double fHelp = MinY; 89cdf0e10cSrcweir MinY = MaxY; 90cdf0e10cSrcweir MaxY = fHelp; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir if(pPosHelper->isMathematicalOrientationZ())//z axis in draw is reverse to mathematical 93cdf0e10cSrcweir { 94cdf0e10cSrcweir double fHelp = MinZ; 95cdf0e10cSrcweir MinZ = MaxZ; 96cdf0e10cSrcweir MaxZ = fHelp; 97cdf0e10cSrcweir } 98cdf0e10cSrcweir bool bSwapXY = pPosHelper->isSwapXAndY(); 99cdf0e10cSrcweir 100cdf0e10cSrcweir P0.realloc(3); 101cdf0e10cSrcweir P1.realloc(3); 102cdf0e10cSrcweir P2.realloc(3); 103cdf0e10cSrcweir 104cdf0e10cSrcweir //P0: point on 'back' wall, not on 'left' wall 105cdf0e10cSrcweir //P1: point on both walls 106cdf0e10cSrcweir //P2: point on 'left' wall not on 'back' wall 107cdf0e10cSrcweir 108cdf0e10cSrcweir P0[0]=P1[0]=P2[0]= (CuboidPlanePosition_Left == eLeftWallPos || bSwapXY) ? MinX : MaxX; 109cdf0e10cSrcweir P0[1]=P1[1]=P2[1]= (CuboidPlanePosition_Left == eLeftWallPos || !bSwapXY) ? MinY : MaxY; 110cdf0e10cSrcweir P0[2]=P1[2]=P2[2]= (CuboidPlanePosition_Back == eBackWallPos) ? MinZ : MaxZ; 111cdf0e10cSrcweir 112cdf0e10cSrcweir if(m_nDimensionIndex==0) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir P0[1]= (CuboidPlanePosition_Left == eLeftWallPos || !bSwapXY) ? MaxY : MinY; 115cdf0e10cSrcweir P2[2]= (CuboidPlanePosition_Back == eBackWallPos) ? MaxZ : MinZ; 116cdf0e10cSrcweir if( CuboidPlanePosition_Bottom != eBottomPos && !bSwapXY ) 117cdf0e10cSrcweir P2=P1; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir else if(m_nDimensionIndex==1) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir P0[0]= (CuboidPlanePosition_Left == eLeftWallPos || bSwapXY) ? MaxX : MinX; 122cdf0e10cSrcweir P2[2]= (CuboidPlanePosition_Back == eBackWallPos) ? MaxZ : MinZ; 123cdf0e10cSrcweir if( CuboidPlanePosition_Bottom != eBottomPos && bSwapXY ) 124cdf0e10cSrcweir P2=P1; 125cdf0e10cSrcweir } 126cdf0e10cSrcweir else if(m_nDimensionIndex==2) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir P0[0]= (CuboidPlanePosition_Left == eLeftWallPos || bSwapXY) ? MaxX : MinX; 129cdf0e10cSrcweir P2[1]= (CuboidPlanePosition_Left == eLeftWallPos || !bSwapXY) ? MaxY : MinY; 130cdf0e10cSrcweir if( CuboidPlanePosition_Bottom != eBottomPos ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir if( !bSwapXY ) 133cdf0e10cSrcweir P0=P1; 134cdf0e10cSrcweir else 135cdf0e10cSrcweir P2=P1; 136cdf0e10cSrcweir } 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir void GridLinePoints::update( double fScaledTickValue ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir P0[m_nDimensionIndex] = P1[m_nDimensionIndex] = P2[m_nDimensionIndex] = fScaledTickValue; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir void addLine2D( drawing::PointSequenceSequence& rPoints, sal_Int32 nIndex 146cdf0e10cSrcweir , const GridLinePoints& rScaledLogicPoints 147cdf0e10cSrcweir , const Reference< XTransformation > & xTransformation 148cdf0e10cSrcweir ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir drawing::Position3D aPA = SequenceToPosition3D( xTransformation->transform( rScaledLogicPoints.P0 ) ); 151cdf0e10cSrcweir drawing::Position3D aPB = SequenceToPosition3D( xTransformation->transform( rScaledLogicPoints.P1 ) ); 152cdf0e10cSrcweir 153cdf0e10cSrcweir rPoints[nIndex].realloc(2); 154cdf0e10cSrcweir rPoints[nIndex][0].X = static_cast<sal_Int32>(aPA.PositionX); 155cdf0e10cSrcweir rPoints[nIndex][0].Y = static_cast<sal_Int32>(aPA.PositionY); 156cdf0e10cSrcweir rPoints[nIndex][1].X = static_cast<sal_Int32>(aPB.PositionX); 157cdf0e10cSrcweir rPoints[nIndex][1].Y = static_cast<sal_Int32>(aPB.PositionY); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir void addLine3D( drawing::PolyPolygonShape3D& rPoints, sal_Int32 nIndex 161cdf0e10cSrcweir , const GridLinePoints& rBasePoints 162cdf0e10cSrcweir , const Reference< XTransformation > & xTransformation ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir drawing::Position3D aPoint = SequenceToPosition3D( xTransformation->transform( rBasePoints.P0 ) ); 165cdf0e10cSrcweir AddPointToPoly( rPoints, aPoint, nIndex ); 166cdf0e10cSrcweir aPoint = SequenceToPosition3D( xTransformation->transform( rBasePoints.P1 ) ); 167cdf0e10cSrcweir AddPointToPoly( rPoints, aPoint, nIndex ); 168cdf0e10cSrcweir aPoint = SequenceToPosition3D( xTransformation->transform( rBasePoints.P2 ) ); 169cdf0e10cSrcweir AddPointToPoly( rPoints, aPoint, nIndex ); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir 172cdf0e10cSrcweir //--------------------------------------------------------------------------------- 173cdf0e10cSrcweir //--------------------------------------------------------------------------------- 174cdf0e10cSrcweir //--------------------------------------------------------------------------------- 175cdf0e10cSrcweir //--------------------------------------------------------------------------------- 176cdf0e10cSrcweir 177cdf0e10cSrcweir VCartesianGrid::VCartesianGrid( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount 178cdf0e10cSrcweir , const Sequence< Reference< beans::XPropertySet > > & rGridPropertiesList ) 179cdf0e10cSrcweir : VAxisOrGridBase( nDimensionIndex, nDimensionCount ) 180cdf0e10cSrcweir , m_aGridPropertiesList( rGridPropertiesList ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir m_pPosHelper = new PlottingPositionHelper(); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir VCartesianGrid::~VCartesianGrid() 186cdf0e10cSrcweir { 187cdf0e10cSrcweir delete m_pPosHelper; 188cdf0e10cSrcweir m_pPosHelper = NULL; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir void VCartesianGrid::fillLinePropertiesFromGridModel( ::std::vector<VLineProperties>& rLinePropertiesList 192cdf0e10cSrcweir , const Sequence< Reference< beans::XPropertySet > > & rGridPropertiesList ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir rLinePropertiesList.clear(); 195cdf0e10cSrcweir if( !rGridPropertiesList.getLength() ) 196cdf0e10cSrcweir return; 197cdf0e10cSrcweir 198cdf0e10cSrcweir VLineProperties aLineProperties; 199cdf0e10cSrcweir for( sal_Int32 nN=0; nN < rGridPropertiesList.getLength(); nN++ ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir if(!AxisHelper::isGridVisible( rGridPropertiesList[nN] )) 202cdf0e10cSrcweir aLineProperties.LineStyle = uno::makeAny( drawing::LineStyle_NONE ); 203cdf0e10cSrcweir else 204cdf0e10cSrcweir aLineProperties.initFromPropertySet( rGridPropertiesList[nN] ); 205cdf0e10cSrcweir rLinePropertiesList.push_back(aLineProperties); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir }; 208cdf0e10cSrcweir 209cdf0e10cSrcweir void VCartesianGrid::createShapes() 210cdf0e10cSrcweir { 211cdf0e10cSrcweir if(!m_aGridPropertiesList.getLength()) 212cdf0e10cSrcweir return; 213cdf0e10cSrcweir //somehow equal to axis tickmarks 214cdf0e10cSrcweir 215cdf0e10cSrcweir //----------------------------------------- 216cdf0e10cSrcweir //create named group shape 217cdf0e10cSrcweir Reference< drawing::XShapes > xGroupShape_Shapes( 218cdf0e10cSrcweir this->createGroupShape( m_xLogicTarget, m_aCID ) ); 219cdf0e10cSrcweir 220cdf0e10cSrcweir if(!xGroupShape_Shapes.is()) 221cdf0e10cSrcweir return; 222cdf0e10cSrcweir //----------------------------------------- 223cdf0e10cSrcweir 224cdf0e10cSrcweir ::std::vector<VLineProperties> aLinePropertiesList; 225cdf0e10cSrcweir fillLinePropertiesFromGridModel( aLinePropertiesList, m_aGridPropertiesList ); 226cdf0e10cSrcweir 227cdf0e10cSrcweir //----------------------------------------- 228cdf0e10cSrcweir //create all scaled tickmark values 229cdf0e10cSrcweir std::auto_ptr< TickFactory > apTickFactory( this->createTickFactory() ); 230cdf0e10cSrcweir TickFactory& aTickFactory = *apTickFactory.get(); 231cdf0e10cSrcweir ::std::vector< ::std::vector< TickInfo > > aAllTickInfos; 232cdf0e10cSrcweir aTickFactory.getAllTicks( aAllTickInfos ); 233cdf0e10cSrcweir 234cdf0e10cSrcweir //----------------------------------------- 235cdf0e10cSrcweir //create tick mark line shapes 236cdf0e10cSrcweir ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter = aAllTickInfos.begin(); 237cdf0e10cSrcweir const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd = aAllTickInfos.end(); 238cdf0e10cSrcweir 239cdf0e10cSrcweir if(aDepthIter == aDepthEnd)//no tickmarks at all 240cdf0e10cSrcweir return; 241cdf0e10cSrcweir 242cdf0e10cSrcweir 243cdf0e10cSrcweir sal_Int32 nLinePropertiesCount = aLinePropertiesList.size(); 244cdf0e10cSrcweir for( sal_Int32 nDepth=0 245cdf0e10cSrcweir ; aDepthIter != aDepthEnd && nDepth < nLinePropertiesCount 246cdf0e10cSrcweir ; aDepthIter++, nDepth++ ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir if( !aLinePropertiesList[nDepth].isLineVisible() ) 249cdf0e10cSrcweir continue; 250cdf0e10cSrcweir 251cdf0e10cSrcweir Reference< drawing::XShapes > xTarget( xGroupShape_Shapes ); 252cdf0e10cSrcweir if( nDepth > 0 ) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir xTarget.set( this->createGroupShape( m_xLogicTarget 255cdf0e10cSrcweir , ObjectIdentifier::addChildParticle( m_aCID, ObjectIdentifier::createChildParticleWithIndex( OBJECTTYPE_SUBGRID, nDepth-1 ) ) 256cdf0e10cSrcweir ) ); 257cdf0e10cSrcweir if(!xTarget.is()) 258cdf0e10cSrcweir xTarget.set( xGroupShape_Shapes ); 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir if(2==m_nDimension) 262cdf0e10cSrcweir { 263cdf0e10cSrcweir 264cdf0e10cSrcweir GridLinePoints aGridLinePoints( m_pPosHelper, m_nDimensionIndex ); 265cdf0e10cSrcweir 266cdf0e10cSrcweir sal_Int32 nPointCount = (*aDepthIter).size(); 267cdf0e10cSrcweir drawing::PointSequenceSequence aPoints(nPointCount); 268cdf0e10cSrcweir 269cdf0e10cSrcweir ::std::vector< TickInfo >::const_iterator aTickIter = (*aDepthIter).begin(); 270cdf0e10cSrcweir const ::std::vector< TickInfo >::const_iterator aTickEnd = (*aDepthIter).end(); 271cdf0e10cSrcweir sal_Int32 nRealPointCount = 0; 272cdf0e10cSrcweir for( ; aTickIter != aTickEnd; aTickIter++ ) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir if( !(*aTickIter).bPaintIt ) 275cdf0e10cSrcweir continue; 276cdf0e10cSrcweir aGridLinePoints.update( (*aTickIter).fScaledTickValue ); 277cdf0e10cSrcweir addLine2D( aPoints, nRealPointCount, aGridLinePoints, m_pPosHelper->getTransformationScaledLogicToScene() ); 278cdf0e10cSrcweir nRealPointCount++; 279cdf0e10cSrcweir } 280cdf0e10cSrcweir aPoints.realloc(nRealPointCount); 281cdf0e10cSrcweir m_pShapeFactory->createLine2D( xTarget, aPoints, &aLinePropertiesList[nDepth] ); 282cdf0e10cSrcweir 283cdf0e10cSrcweir //prepare polygon for handle shape: 284cdf0e10cSrcweir drawing::PointSequenceSequence aHandlesPoints(1); 285cdf0e10cSrcweir sal_Int32 nOldHandleCount = aHandlesPoints[0].getLength(); 286cdf0e10cSrcweir aHandlesPoints[0].realloc(nOldHandleCount+nRealPointCount); 287cdf0e10cSrcweir for( sal_Int32 nN = 0; nN<nRealPointCount; nN++) 288cdf0e10cSrcweir aHandlesPoints[0][nOldHandleCount+nN] = aPoints[nN][1]; 289cdf0e10cSrcweir 290cdf0e10cSrcweir //create handle shape: 291cdf0e10cSrcweir VLineProperties aHandleLineProperties; 292cdf0e10cSrcweir aHandleLineProperties.LineStyle = uno::makeAny( drawing::LineStyle_NONE ); 293cdf0e10cSrcweir Reference< drawing::XShape > xHandleShape = 294cdf0e10cSrcweir m_pShapeFactory->createLine2D( xTarget, aHandlesPoints, &aHandleLineProperties ); 295cdf0e10cSrcweir m_pShapeFactory->setShapeName( xHandleShape, C2U("HandlesOnly") ); 296cdf0e10cSrcweir } 297cdf0e10cSrcweir //----------------------------------------- 298cdf0e10cSrcweir else //if(2!=m_nDimension) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir GridLinePoints aGridLinePoints( m_pPosHelper, m_nDimensionIndex, m_eLeftWallPos, m_eBackWallPos, m_eBottomPos ); 301cdf0e10cSrcweir 302cdf0e10cSrcweir sal_Int32 nPointCount = (*aDepthIter).size(); 303cdf0e10cSrcweir drawing::PolyPolygonShape3D aPoints; 304cdf0e10cSrcweir aPoints.SequenceX.realloc(nPointCount); 305cdf0e10cSrcweir aPoints.SequenceY.realloc(nPointCount); 306cdf0e10cSrcweir aPoints.SequenceZ.realloc(nPointCount); 307cdf0e10cSrcweir 308cdf0e10cSrcweir ::std::vector< TickInfo >::const_iterator aTickIter = (*aDepthIter).begin(); 309cdf0e10cSrcweir const ::std::vector< TickInfo >::const_iterator aTickEnd = (*aDepthIter).end(); 310cdf0e10cSrcweir sal_Int32 nRealPointCount = 0; 311cdf0e10cSrcweir sal_Int32 nPolyIndex = 0; 312cdf0e10cSrcweir for( ; aTickIter != aTickEnd; aTickIter++, nPolyIndex++ ) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir if( !(*aTickIter).bPaintIt ) 315cdf0e10cSrcweir continue; 316cdf0e10cSrcweir 317cdf0e10cSrcweir aGridLinePoints.update( (*aTickIter).fScaledTickValue ); 318cdf0e10cSrcweir addLine3D( aPoints, nPolyIndex, aGridLinePoints, m_pPosHelper->getTransformationScaledLogicToScene() ); 319cdf0e10cSrcweir nRealPointCount+=3; 320cdf0e10cSrcweir } 321cdf0e10cSrcweir aPoints.SequenceX.realloc(nRealPointCount); 322cdf0e10cSrcweir aPoints.SequenceY.realloc(nRealPointCount); 323cdf0e10cSrcweir aPoints.SequenceZ.realloc(nRealPointCount); 324cdf0e10cSrcweir m_pShapeFactory->createLine3D( xTarget, aPoints, aLinePropertiesList[nDepth] ); 325cdf0e10cSrcweir } 326cdf0e10cSrcweir } 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir //............................................................................. 330cdf0e10cSrcweir } //namespace chart 331cdf0e10cSrcweir //............................................................................. 332