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

Generated by: LCOV version 1.10