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

Generated by: LCOV version 1.11