LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/chart2/source/view/axes - VCartesianGrid.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 111 158 70.3 %
Date: 2013-07-09 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         418 : 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         418 : GridLinePoints::GridLinePoints( const PlottingPositionHelper* pPosHelper, sal_Int32 nDimensionIndex
      59             :                 , CuboidPlanePosition eLeftWallPos
      60             :                 , CuboidPlanePosition eBackWallPos
      61             :                 , CuboidPlanePosition eBottomPos )
      62         418 :                 : m_nDimensionIndex(nDimensionIndex)
      63             : {
      64         418 :     double MinX = pPosHelper->getLogicMinX();
      65         418 :     double MinY = pPosHelper->getLogicMinY();
      66         418 :     double MinZ = pPosHelper->getLogicMinZ();
      67         418 :     double MaxX = pPosHelper->getLogicMaxX();
      68         418 :     double MaxY = pPosHelper->getLogicMaxY();
      69         418 :     double MaxZ = pPosHelper->getLogicMaxZ();
      70             : 
      71         418 :     pPosHelper->doLogicScaling( &MinX,&MinY,&MinZ );
      72         418 :     pPosHelper->doLogicScaling( &MaxX,&MaxY,&MaxZ );
      73             : 
      74         418 :     if(!pPosHelper->isMathematicalOrientationX())
      75             :     {
      76           0 :         double fHelp = MinX;
      77           0 :         MinX = MaxX;
      78           0 :         MaxX = fHelp;
      79             :     }
      80         418 :     if(!pPosHelper->isMathematicalOrientationY())
      81             :     {
      82          23 :         double fHelp = MinY;
      83          23 :         MinY = MaxY;
      84          23 :         MaxY = fHelp;
      85             :     }
      86         418 :     if(pPosHelper->isMathematicalOrientationZ())//z axis in draw is reverse to mathematical
      87             :     {
      88         418 :         double fHelp = MinZ;
      89         418 :         MinZ = MaxZ;
      90         418 :         MaxZ = fHelp;
      91             :     }
      92         418 :     bool bSwapXY = pPosHelper->isSwapXAndY();
      93             : 
      94         418 :     P0.realloc(3);
      95         418 :     P1.realloc(3);
      96         418 :     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         418 :     P0[0]=P1[0]=P2[0]= (CuboidPlanePosition_Left == eLeftWallPos || bSwapXY) ? MinX : MaxX;
     103         418 :     P0[1]=P1[1]=P2[1]= (CuboidPlanePosition_Left == eLeftWallPos || !bSwapXY) ? MinY : MaxY;
     104         418 :     P0[2]=P1[2]=P2[2]= (CuboidPlanePosition_Back == eBackWallPos) ? MinZ : MaxZ;
     105             : 
     106         418 :     if(m_nDimensionIndex==0)
     107             :     {
     108          46 :         P0[1]= (CuboidPlanePosition_Left == eLeftWallPos || !bSwapXY) ? MaxY : MinY;
     109          46 :         P2[2]= (CuboidPlanePosition_Back == eBackWallPos) ? MaxZ : MinZ;
     110          46 :         if( CuboidPlanePosition_Bottom != eBottomPos && !bSwapXY )
     111           0 :             P2=P1;
     112             :     }
     113         372 :     else if(m_nDimensionIndex==1)
     114             :     {
     115         372 :         P0[0]= (CuboidPlanePosition_Left == eLeftWallPos || bSwapXY) ? MaxX : MinX;
     116         372 :         P2[2]= (CuboidPlanePosition_Back == eBackWallPos) ? MaxZ : MinZ;
     117         372 :         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         418 : }
     133             : 
     134        2309 : void GridLinePoints::update( double fScaledTickValue )
     135             : {
     136        2309 :     P0[m_nDimensionIndex] = P1[m_nDimensionIndex] = P2[m_nDimensionIndex] = fScaledTickValue;
     137        2309 : }
     138             : 
     139        2309 : void addLine2D( drawing::PointSequenceSequence& rPoints, sal_Int32 nIndex
     140             :              , const GridLinePoints& rScaledLogicPoints
     141             :              , const Reference< XTransformation > & xTransformation
     142             :               )
     143             : {
     144        2309 :     drawing::Position3D aPA = SequenceToPosition3D( xTransformation->transform( rScaledLogicPoints.P0 ) );
     145        2309 :     drawing::Position3D aPB = SequenceToPosition3D( xTransformation->transform( rScaledLogicPoints.P1 ) );
     146             : 
     147        2309 :     rPoints[nIndex].realloc(2);
     148        2309 :     rPoints[nIndex][0].X = static_cast<sal_Int32>(aPA.PositionX);
     149        2309 :     rPoints[nIndex][0].Y = static_cast<sal_Int32>(aPA.PositionY);
     150        2309 :     rPoints[nIndex][1].X = static_cast<sal_Int32>(aPB.PositionX);
     151        2309 :     rPoints[nIndex][1].Y = static_cast<sal_Int32>(aPB.PositionY);
     152        2309 : }
     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        1044 : VCartesianGrid::VCartesianGrid( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount
     172             :                                , const Sequence< Reference< beans::XPropertySet > > & rGridPropertiesList )
     173             :             : VAxisOrGridBase( nDimensionIndex, nDimensionCount )
     174        1044 :             , m_aGridPropertiesList( rGridPropertiesList )
     175             : {
     176        1044 :     m_pPosHelper = new PlottingPositionHelper();
     177        1044 : }
     178             : 
     179        2088 : VCartesianGrid::~VCartesianGrid()
     180             : {
     181        1044 :     delete m_pPosHelper;
     182        1044 :     m_pPosHelper = NULL;
     183        1044 : }
     184             : 
     185        1044 : void VCartesianGrid::fillLinePropertiesFromGridModel( ::std::vector<VLineProperties>& rLinePropertiesList
     186             :                                      , const Sequence< Reference< beans::XPropertySet > > & rGridPropertiesList )
     187             : {
     188        1044 :     rLinePropertiesList.clear();
     189        1044 :     if( !rGridPropertiesList.getLength() )
     190        1044 :         return;
     191             : 
     192        1044 :     VLineProperties aLineProperties;
     193        3132 :     for( sal_Int32 nN=0; nN < rGridPropertiesList.getLength(); nN++ )
     194             :     {
     195        2088 :         if(!AxisHelper::isGridVisible( rGridPropertiesList[nN] ))
     196        1670 :             aLineProperties.LineStyle = uno::makeAny( drawing::LineStyle_NONE );
     197             :         else
     198         418 :             aLineProperties.initFromPropertySet( rGridPropertiesList[nN] );
     199        2088 :         rLinePropertiesList.push_back(aLineProperties);
     200        1044 :     }
     201             : };
     202             : 
     203        1044 : void VCartesianGrid::createShapes()
     204             : {
     205        1044 :     if(!m_aGridPropertiesList.getLength())
     206           0 :         return;
     207             :     //somehow equal to axis tickmarks
     208             : 
     209             :     //-----------------------------------------
     210             :     //create named group shape
     211             :     Reference< drawing::XShapes > xGroupShape_Shapes(
     212        1044 :         this->createGroupShape( m_xLogicTarget, m_aCID ) );
     213             : 
     214        1044 :     if(!xGroupShape_Shapes.is())
     215           0 :         return;
     216             :     //-----------------------------------------
     217             : 
     218        2088 :     ::std::vector<VLineProperties> aLinePropertiesList;
     219        1044 :     fillLinePropertiesFromGridModel( aLinePropertiesList, m_aGridPropertiesList );
     220             : 
     221             :     //-----------------------------------------
     222             :     //create all scaled tickmark values
     223        2088 :     boost::scoped_ptr< TickFactory > apTickFactory( this->createTickFactory() );
     224        1044 :     TickFactory& aTickFactory = *apTickFactory.get();
     225        2088 :     ::std::vector< ::std::vector< TickInfo > > aAllTickInfos;
     226        1044 :     aTickFactory.getAllTicks( aAllTickInfos );
     227             : 
     228             :     //-----------------------------------------
     229             :     //create tick mark line shapes
     230        1044 :     ::std::vector< ::std::vector< TickInfo > >::iterator aDepthIter             = aAllTickInfos.begin();
     231        1044 :     const ::std::vector< ::std::vector< TickInfo > >::const_iterator aDepthEnd  = aAllTickInfos.end();
     232             : 
     233        1044 :     if(aDepthIter == aDepthEnd)//no tickmarks at all
     234           0 :         return;
     235             : 
     236             : 
     237        1044 :     sal_Int32 nLinePropertiesCount = aLinePropertiesList.size();
     238        6264 :     for( sal_Int32 nDepth=0
     239        3132 :         ; aDepthIter != aDepthEnd && nDepth < nLinePropertiesCount
     240             :         ; ++aDepthIter, nDepth++ )
     241             :     {
     242        2088 :         if( !aLinePropertiesList[nDepth].isLineVisible() )
     243        1670 :             continue;
     244             : 
     245         418 :         Reference< drawing::XShapes > xTarget( xGroupShape_Shapes );
     246         418 :         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         418 :         if(2==m_nDimension)
     256             :         {
     257             : 
     258         418 :             GridLinePoints aGridLinePoints( m_pPosHelper, m_nDimensionIndex );
     259             : 
     260         418 :             sal_Int32 nPointCount = (*aDepthIter).size();
     261         836 :             drawing::PointSequenceSequence aPoints(nPointCount);
     262             : 
     263         418 :             ::std::vector< TickInfo >::const_iterator       aTickIter = (*aDepthIter).begin();
     264         418 :             const ::std::vector< TickInfo >::const_iterator aTickEnd  = (*aDepthIter).end();
     265         418 :             sal_Int32 nRealPointCount = 0;
     266        2727 :             for( ; aTickIter != aTickEnd; ++aTickIter )
     267             :             {
     268        2309 :                 if( !(*aTickIter).bPaintIt )
     269           0 :                     continue;
     270        2309 :                 aGridLinePoints.update( (*aTickIter).fScaledTickValue );
     271        2309 :                 addLine2D( aPoints, nRealPointCount, aGridLinePoints, m_pPosHelper->getTransformationScaledLogicToScene() );
     272        2309 :                 nRealPointCount++;
     273             :             }
     274         418 :             aPoints.realloc(nRealPointCount);
     275         418 :             m_pShapeFactory->createLine2D( xTarget, aPoints, &aLinePropertiesList[nDepth] );
     276             : 
     277             :             //prepare polygon for handle shape:
     278         836 :             drawing::PointSequenceSequence aHandlesPoints(1);
     279         418 :             sal_Int32 nOldHandleCount = aHandlesPoints[0].getLength();
     280         418 :             aHandlesPoints[0].realloc(nOldHandleCount+nRealPointCount);
     281        2727 :             for( sal_Int32 nN = 0; nN<nRealPointCount; nN++)
     282        2309 :                 aHandlesPoints[0][nOldHandleCount+nN] = aPoints[nN][1];
     283             : 
     284             :             //create handle shape:
     285         836 :             VLineProperties aHandleLineProperties;
     286         418 :             aHandleLineProperties.LineStyle    = uno::makeAny( drawing::LineStyle_NONE );
     287             :             Reference< drawing::XShape > xHandleShape =
     288         836 :                 m_pShapeFactory->createLine2D( xTarget, aHandlesPoints, &aHandleLineProperties );
     289         836 :             m_pShapeFactory->setShapeName( xHandleShape, "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        1462 :     }
     321             : }
     322             : 
     323             : //.............................................................................
     324             : } //namespace chart
     325             : //.............................................................................
     326             : 
     327             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10