LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/view/axes - VCartesianGrid.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 105 155 67.7 %
Date: 2012-12-27 Functions: 8 10 80.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10