LCOV - code coverage report
Current view: top level - chart2/source/view/main - PlottingPositionHelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 318 352 90.3 %
Date: 2015-06-13 12:38:46 Functions: 36 39 92.3 %
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 "PlottingPositionHelper.hxx"
      21             : #include "CommonConverters.hxx"
      22             : #include "ViewDefines.hxx"
      23             : #include "Linear3DTransformation.hxx"
      24             : #include "VPolarTransformation.hxx"
      25             : #include "AbstractShapeFactory.hxx"
      26             : #include "PropertyMapper.hxx"
      27             : #include "DateHelper.hxx"
      28             : #include "defines.hxx"
      29             : 
      30             : #include <com/sun/star/chart/TimeUnit.hpp>
      31             : #include <com/sun/star/chart2/AxisType.hpp>
      32             : #include <com/sun/star/drawing/DoubleSequence.hpp>
      33             : #include <com/sun/star/drawing/Position3D.hpp>
      34             : 
      35             : #include <rtl/math.hxx>
      36             : 
      37             : namespace chart
      38             : {
      39             : using namespace ::com::sun::star;
      40             : using namespace ::com::sun::star::chart2;
      41             : 
      42        5290 : PlottingPositionHelper::PlottingPositionHelper()
      43             :         : m_aScales()
      44             :         , m_aMatrixScreenToScene()
      45             :         , m_xTransformationLogicToScene(NULL)
      46             :         , m_bSwapXAndY( false )
      47             :         , m_nXResolution( 1000 )
      48             :         , m_nYResolution( 1000 )
      49             :         , m_nZResolution( 1000 )
      50             :         , m_bMaySkipPointsInRegressionCalculation( true )
      51             :         , m_bDateAxis(false)
      52             :         , m_nTimeResolution( ::com::sun::star::chart::TimeUnit::DAY )
      53             :         , m_aNullDate(30,12,1899)
      54             :         , m_fScaledCategoryWidth(1.0)
      55             :         , m_bAllowShiftXAxisPos(false)
      56        5290 :         , m_bAllowShiftZAxisPos(false)
      57             : {
      58        5290 : }
      59          22 : PlottingPositionHelper::PlottingPositionHelper( const PlottingPositionHelper& rSource )
      60             :         : m_aScales( rSource.m_aScales )
      61             :         , m_aMatrixScreenToScene( rSource.m_aMatrixScreenToScene )
      62             :         , m_xTransformationLogicToScene( NULL ) //should be recalculated
      63             :         , m_bSwapXAndY( rSource.m_bSwapXAndY )
      64             :         , m_nXResolution( rSource.m_nXResolution )
      65             :         , m_nYResolution( rSource.m_nYResolution )
      66             :         , m_nZResolution( rSource.m_nZResolution )
      67             :         , m_bMaySkipPointsInRegressionCalculation( rSource.m_bMaySkipPointsInRegressionCalculation )
      68             :         , m_bDateAxis( rSource.m_bDateAxis )
      69             :         , m_nTimeResolution( rSource.m_nTimeResolution )
      70             :         , m_aNullDate( rSource.m_aNullDate )
      71             :         , m_fScaledCategoryWidth( rSource.m_fScaledCategoryWidth )
      72             :         , m_bAllowShiftXAxisPos( rSource.m_bAllowShiftXAxisPos )
      73          22 :         , m_bAllowShiftZAxisPos( rSource.m_bAllowShiftZAxisPos )
      74             : {
      75          22 : }
      76             : 
      77        9615 : PlottingPositionHelper::~PlottingPositionHelper()
      78             : {
      79             : 
      80        9615 : }
      81             : 
      82          18 : PlottingPositionHelper* PlottingPositionHelper::clone() const
      83             : {
      84          18 :     PlottingPositionHelper* pRet = new PlottingPositionHelper(*this);
      85          18 :     return pRet;
      86             : }
      87             : 
      88          22 : PlottingPositionHelper* PlottingPositionHelper::createSecondaryPosHelper( const ExplicitScaleData& rSecondaryScale )
      89             : {
      90          22 :     PlottingPositionHelper* pRet = this->clone();
      91          22 :     pRet->m_aScales[1]=rSecondaryScale;
      92          22 :     return pRet;
      93             : }
      94             : 
      95       22764 : void PlottingPositionHelper::setTransformationSceneToScreen( const drawing::HomogenMatrix& rMatrix)
      96             : {
      97       22764 :     m_aMatrixScreenToScene = HomogenMatrixToB3DHomMatrix(rMatrix);
      98       22764 :     m_xTransformationLogicToScene = NULL;
      99       22764 : }
     100             : 
     101        8452 : void PlottingPositionHelper::setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis )
     102             : {
     103        8452 :     m_aScales = rScales;
     104        8452 :     m_bSwapXAndY = bSwapXAndYAxis;
     105        8452 :     m_xTransformationLogicToScene = NULL;
     106        8452 : }
     107             : 
     108      112433 : uno::Reference< XTransformation > PlottingPositionHelper::getTransformationScaledLogicToScene() const
     109             : {
     110             :     //this is a standard transformation for a cartesian coordinate system
     111             : 
     112             :     //transformation from 2) to 4) //@todo 2) and 4) need a ink to a document
     113             : 
     114             :     //we need to apply this transformation to each geometric object because of a bug/problem
     115             :     //of the old drawing layer (the UNO_NAME_3D_EXTRUDE_DEPTH is an integer value instead of an double )
     116      112433 :     if(!m_xTransformationLogicToScene.is())
     117             :     {
     118       11267 :         ::basegfx::B3DHomMatrix aMatrix;
     119       11267 :         double MinX = getLogicMinX();
     120       11267 :         double MinY = getLogicMinY();
     121       11267 :         double MinZ = getLogicMinZ();
     122       11267 :         double MaxX = getLogicMaxX();
     123       11267 :         double MaxY = getLogicMaxY();
     124       11267 :         double MaxZ = getLogicMaxZ();
     125             : 
     126       11267 :         AxisOrientation nXAxisOrientation = m_aScales[0].Orientation;
     127       11267 :         AxisOrientation nYAxisOrientation = m_aScales[1].Orientation;
     128       11267 :         AxisOrientation nZAxisOrientation = m_aScales[2].Orientation;
     129             : 
     130             :         //apply scaling
     131       11267 :         doUnshiftedLogicScaling( &MinX, &MinY, &MinZ );
     132       11267 :         doUnshiftedLogicScaling( &MaxX, &MaxY, &MaxZ);
     133             : 
     134       11267 :         if(m_bSwapXAndY)
     135             :         {
     136         286 :             std::swap(MinX,MinY);
     137         286 :             std::swap(MaxX,MaxY);
     138         286 :             std::swap(nXAxisOrientation,nYAxisOrientation);
     139             :         }
     140             : 
     141       11267 :         double fWidthX = MaxX - MinX;
     142       11267 :         double fWidthY = MaxY - MinY;
     143       11267 :         double fWidthZ = MaxZ - MinZ;
     144             : 
     145       11267 :         double fScaleDirectionX = AxisOrientation_MATHEMATICAL==nXAxisOrientation ? 1.0 : -1.0;
     146       11267 :         double fScaleDirectionY = AxisOrientation_MATHEMATICAL==nYAxisOrientation ? 1.0 : -1.0;
     147       11267 :         double fScaleDirectionZ = AxisOrientation_MATHEMATICAL==nZAxisOrientation ? -1.0 : 1.0;
     148             : 
     149       11267 :         double fScaleX = fScaleDirectionX*FIXED_SIZE_FOR_3D_CHART_VOLUME/fWidthX;
     150       11267 :         double fScaleY = fScaleDirectionY*FIXED_SIZE_FOR_3D_CHART_VOLUME/fWidthY;
     151       11267 :         double fScaleZ = fScaleDirectionZ*FIXED_SIZE_FOR_3D_CHART_VOLUME/fWidthZ;
     152             : 
     153       11267 :         aMatrix.scale(fScaleX, fScaleY, fScaleZ);
     154             : 
     155       11267 :         if( AxisOrientation_MATHEMATICAL==nXAxisOrientation )
     156       11267 :             aMatrix.translate(-MinX*fScaleX, 0.0, 0.0);
     157             :         else
     158           0 :             aMatrix.translate(-MaxX*fScaleX, 0.0, 0.0);
     159       11267 :         if( AxisOrientation_MATHEMATICAL==nYAxisOrientation )
     160       10803 :             aMatrix.translate(0.0, -MinY*fScaleY, 0.0);
     161             :         else
     162         464 :             aMatrix.translate(0.0, -MaxY*fScaleY, 0.0);
     163       11267 :         if( AxisOrientation_MATHEMATICAL==nZAxisOrientation )
     164       11267 :             aMatrix.translate(0.0, 0.0, -MaxZ*fScaleZ);//z direction in draw is reverse mathematical direction
     165             :         else
     166           0 :             aMatrix.translate(0.0, 0.0, -MinZ*fScaleZ);
     167             : 
     168       11267 :         aMatrix = m_aMatrixScreenToScene*aMatrix;
     169             : 
     170       11267 :         m_xTransformationLogicToScene = new Linear3DTransformation(B3DHomMatrixToHomogenMatrix( aMatrix ),m_bSwapXAndY);
     171             :     }
     172      112433 :     return m_xTransformationLogicToScene;
     173             : }
     174             : 
     175       52131 : drawing::Position3D PlottingPositionHelper::transformLogicToScene(
     176             :     double fX, double fY, double fZ, bool bClip ) const
     177             : {
     178       52131 :     this->doLogicScaling( &fX,&fY,&fZ );
     179       52131 :     if(bClip)
     180       50020 :         this->clipScaledLogicValues( &fX,&fY,&fZ );
     181             : 
     182       52131 :     return this->transformScaledLogicToScene( fX, fY, fZ, false );
     183             : }
     184             : 
     185      106632 : drawing::Position3D PlottingPositionHelper::transformScaledLogicToScene(
     186             :     double fX, double fY, double fZ, bool bClip  ) const
     187             : {
     188      106632 :     if( bClip )
     189       53754 :         this->clipScaledLogicValues( &fX,&fY,&fZ );
     190             : 
     191      106632 :     drawing::Position3D aPos( fX, fY, fZ);
     192             : 
     193             :     uno::Reference< XTransformation > xTransformation =
     194      106632 :         this->getTransformationScaledLogicToScene();
     195             :     uno::Sequence< double > aSeq =
     196      213264 :         xTransformation->transform( Position3DToSequence(aPos) );
     197      213264 :     return SequenceToPosition3D(aSeq);
     198             : }
     199             : 
     200        2634 : awt::Point PlottingPositionHelper::transformSceneToScreenPosition( const drawing::Position3D& rScenePosition3D
     201             :                 , const uno::Reference< drawing::XShapes >& xSceneTarget
     202             :                 , AbstractShapeFactory* pShapeFactory
     203             :                 , sal_Int32 nDimensionCount )
     204             : {
     205             :     //@todo would like to have a cheaper method to do this transformation
     206        2634 :     awt::Point aScreenPoint( static_cast<sal_Int32>(rScenePosition3D.PositionX), static_cast<sal_Int32>(rScenePosition3D.PositionY) );
     207             : 
     208             :     //transformation from scene to screen (only necessary for 3D):
     209        2634 :     if(3==nDimensionCount)
     210             :     {
     211             :         //create 3D anchor shape
     212         656 :         tPropertyNameMap aDummyPropertyNameMap;
     213             :         uno::Reference< drawing::XShape > xShape3DAnchor = pShapeFactory->createCube( xSceneTarget
     214             :                 , rScenePosition3D,drawing::Direction3D(1,1,1)
     215        1312 :                 , 0, 0, aDummyPropertyNameMap);
     216             :         //get 2D position from xShape3DAnchor
     217         656 :         aScreenPoint = xShape3DAnchor->getPosition();
     218        1312 :         xSceneTarget->remove(xShape3DAnchor);
     219             :     }
     220        2634 :     return aScreenPoint;
     221             : }
     222             : 
     223       10349 : void PlottingPositionHelper::transformScaledLogicToScene( drawing::PolyPolygonShape3D& rPolygon ) const
     224             : {
     225       10349 :     drawing::Position3D aScenePosition;
     226       31051 :     for( sal_Int32 nS = rPolygon.SequenceX.getLength(); nS--;)
     227             :     {
     228       10353 :         drawing::DoubleSequence& xValues = rPolygon.SequenceX[nS];
     229       10353 :         drawing::DoubleSequence& yValues = rPolygon.SequenceY[nS];
     230       10353 :         drawing::DoubleSequence& zValues = rPolygon.SequenceZ[nS];
     231       73789 :         for( sal_Int32 nP = xValues.getLength(); nP--; )
     232             :         {
     233       53083 :             double& fX = xValues[nP];
     234       53083 :             double& fY = yValues[nP];
     235       53083 :             double& fZ = zValues[nP];
     236       53083 :             aScenePosition = this->transformScaledLogicToScene( fX,fY,fZ,true );
     237       53083 :             fX = aScenePosition.PositionX;
     238       53083 :             fY = aScenePosition.PositionY;
     239       53083 :             fZ = aScenePosition.PositionZ;
     240             :         }
     241             :     }
     242       10349 : }
     243             : 
     244      104549 : void PlottingPositionHelper::clipScaledLogicValues( double* pX, double* pY, double* pZ ) const
     245             : {
     246             :     //get logic clip values:
     247      104549 :     double MinX = getLogicMinX();
     248      104549 :     double MinY = getLogicMinY();
     249      104549 :     double MinZ = getLogicMinZ();
     250      104549 :     double MaxX = getLogicMaxX();
     251      104549 :     double MaxY = getLogicMaxY();
     252      104549 :     double MaxZ = getLogicMaxZ();
     253             : 
     254             :     //apply scaling
     255      104549 :     doUnshiftedLogicScaling( &MinX, &MinY, &MinZ );
     256      104549 :     doUnshiftedLogicScaling( &MaxX, &MaxY, &MaxZ);
     257             : 
     258      104549 :     if(pX)
     259             :     {
     260      104549 :         if( *pX < MinX )
     261           0 :             *pX = MinX;
     262      104549 :         else if( *pX > MaxX )
     263           0 :             *pX = MaxX;
     264             :     }
     265      104549 :     if(pY)
     266             :     {
     267      104549 :         if( *pY < MinY )
     268          79 :             *pY = MinY;
     269      104470 :         else if( *pY > MaxY )
     270          80 :             *pY = MaxY;
     271             :     }
     272      104549 :     if(pZ)
     273             :     {
     274      104549 :         if( *pZ < MinZ )
     275         964 :             *pZ = MinZ;
     276      103585 :         else if( *pZ > MaxZ )
     277           0 :             *pZ = MaxZ;
     278             :     }
     279      104549 : }
     280             : 
     281         388 : basegfx::B2DRectangle PlottingPositionHelper::getScaledLogicClipDoubleRect() const
     282             : {
     283             :     //get logic clip values:
     284         388 :     double MinX = getLogicMinX();
     285         388 :     double MinY = getLogicMinY();
     286         388 :     double MinZ = getLogicMinZ();
     287         388 :     double MaxX = getLogicMaxX();
     288         388 :     double MaxY = getLogicMaxY();
     289         388 :     double MaxZ = getLogicMaxZ();
     290             : 
     291             :     //apply scaling
     292         388 :     doUnshiftedLogicScaling( &MinX, &MinY, &MinZ );
     293         388 :     doUnshiftedLogicScaling( &MaxX, &MaxY, &MaxZ);
     294             : 
     295         388 :     basegfx::B2DRectangle aRet( MinX, MaxY, MaxX, MinY );
     296         388 :     return aRet;
     297             : }
     298             : 
     299          49 : drawing::Direction3D PlottingPositionHelper::getScaledLogicWidth() const
     300             : {
     301          49 :     drawing::Direction3D aRet;
     302             : 
     303          49 :     double MinX = getLogicMinX();
     304          49 :     double MinY = getLogicMinY();
     305          49 :     double MinZ = getLogicMinZ();
     306          49 :     double MaxX = getLogicMaxX();
     307          49 :     double MaxY = getLogicMaxY();
     308          49 :     double MaxZ = getLogicMaxZ();
     309             : 
     310          49 :     doLogicScaling( &MinX, &MinY, &MinZ );
     311          49 :     doLogicScaling( &MaxX, &MaxY, &MaxZ);
     312             : 
     313          49 :     aRet.DirectionX = MaxX - MinX;
     314          49 :     aRet.DirectionY = MaxY - MinY;
     315          49 :     aRet.DirectionZ = MaxZ - MinZ;
     316          49 :     return aRet;
     317             : }
     318             : 
     319          59 : PolarPlottingPositionHelper::PolarPlottingPositionHelper( NormalAxis eNormalAxis )
     320             :     : m_fRadiusOffset(0.0)
     321             :     , m_fAngleDegreeOffset(90.0)
     322             :     , m_aUnitCartesianToScene()
     323          59 :     , m_eNormalAxis(eNormalAxis)
     324             : {
     325          59 :     m_bMaySkipPointsInRegressionCalculation = false;
     326          59 : }
     327             : 
     328           0 : PolarPlottingPositionHelper::PolarPlottingPositionHelper( const PolarPlottingPositionHelper& rSource )
     329             :     : PlottingPositionHelper(rSource)
     330             :     , m_fRadiusOffset( rSource.m_fRadiusOffset )
     331             :     , m_fAngleDegreeOffset( rSource.m_fAngleDegreeOffset )
     332             :     , m_aUnitCartesianToScene( rSource.m_aUnitCartesianToScene )
     333           0 :     , m_eNormalAxis( rSource.m_eNormalAxis )
     334             : {
     335           0 : }
     336             : 
     337          81 : PolarPlottingPositionHelper::~PolarPlottingPositionHelper()
     338             : {
     339          81 : }
     340             : 
     341           0 : PlottingPositionHelper* PolarPlottingPositionHelper::clone() const
     342             : {
     343           0 :     PolarPlottingPositionHelper* pRet = new PolarPlottingPositionHelper(*this);
     344           0 :     return pRet;
     345             : }
     346             : 
     347         138 : void PolarPlottingPositionHelper::setTransformationSceneToScreen( const drawing::HomogenMatrix& rMatrix)
     348             : {
     349         138 :     PlottingPositionHelper::setTransformationSceneToScreen( rMatrix);
     350         138 :     m_aUnitCartesianToScene =impl_calculateMatrixUnitCartesianToScene( m_aMatrixScreenToScene );
     351         138 : }
     352          67 : void PolarPlottingPositionHelper::setScales( const std::vector< ExplicitScaleData >& rScales, bool bSwapXAndYAxis )
     353             : {
     354          67 :     PlottingPositionHelper::setScales( rScales, bSwapXAndYAxis );
     355          67 :     m_aUnitCartesianToScene =impl_calculateMatrixUnitCartesianToScene( m_aMatrixScreenToScene );
     356          67 : }
     357             : 
     358         205 : ::basegfx::B3DHomMatrix PolarPlottingPositionHelper::impl_calculateMatrixUnitCartesianToScene( const ::basegfx::B3DHomMatrix& rMatrixScreenToScene ) const
     359             : {
     360         205 :     ::basegfx::B3DHomMatrix aRet;
     361             : 
     362         205 :     if( m_aScales.empty() )
     363          26 :         return aRet;
     364             : 
     365         179 :     double fTranslate =1.0;
     366         179 :     double fScale     =FIXED_SIZE_FOR_3D_CHART_VOLUME/2.0;
     367             : 
     368         179 :     double fTranslateLogicZ =fTranslate;
     369         179 :     double fScaleLogicZ     =fScale;
     370             :     {
     371         179 :         double fScaleDirectionZ = AxisOrientation_MATHEMATICAL==m_aScales[2].Orientation ? 1.0 : -1.0;
     372         179 :         double MinZ = getLogicMinZ();
     373         179 :         double MaxZ = getLogicMaxZ();
     374         179 :         doLogicScaling( 0, 0, &MinZ );
     375         179 :         doLogicScaling( 0, 0, &MaxZ );
     376         179 :         double fWidthZ = MaxZ - MinZ;
     377             : 
     378         179 :         if( AxisOrientation_MATHEMATICAL==m_aScales[2].Orientation )
     379         179 :             fTranslateLogicZ=MinZ;
     380             :         else
     381           0 :             fTranslateLogicZ=MaxZ;
     382         179 :         fScaleLogicZ = fScaleDirectionZ*FIXED_SIZE_FOR_3D_CHART_VOLUME/fWidthZ;
     383             :     }
     384             : 
     385         179 :     double fTranslateX = fTranslate;
     386         179 :     double fTranslateY = fTranslate;
     387         179 :     double fTranslateZ = fTranslate;
     388             : 
     389         179 :     double fScaleX = fScale;
     390         179 :     double fScaleY = fScale;
     391         179 :     double fScaleZ = fScale;
     392             : 
     393         179 :     switch(m_eNormalAxis)
     394             :     {
     395             :         case NormalAxis_X:
     396             :             {
     397           0 :                 fTranslateX = fTranslateLogicZ;
     398           0 :                 fScaleX = fScaleLogicZ;
     399             :             }
     400           0 :             break;
     401             :         case NormalAxis_Y:
     402             :             {
     403           0 :                 fTranslateY = fTranslateLogicZ;
     404           0 :                 fScaleY = fScaleLogicZ;
     405             :             }
     406           0 :             break;
     407             :         default: //NormalAxis_Z:
     408             :             {
     409         179 :                 fTranslateZ = fTranslateLogicZ;
     410         179 :                 fScaleZ = fScaleLogicZ;
     411             :             }
     412         179 :             break;
     413             :     }
     414             : 
     415         179 :     aRet.translate(fTranslateX, fTranslateY, fTranslateZ);//x first
     416         179 :     aRet.scale(fScaleX, fScaleY, fScaleZ);//x first
     417             : 
     418         179 :     aRet = rMatrixScreenToScene * aRet;
     419         179 :     return aRet;
     420             : }
     421             : 
     422           0 : uno::Reference< XTransformation > PolarPlottingPositionHelper::getTransformationScaledLogicToScene() const
     423             : {
     424           0 :     if( !m_xTransformationLogicToScene.is() )
     425           0 :         m_xTransformationLogicToScene = new VPolarTransformation(*this);
     426           0 :     return m_xTransformationLogicToScene;
     427             : }
     428             : 
     429         336 : double PolarPlottingPositionHelper::getWidthAngleDegree( double& fStartLogicValueOnAngleAxis, double& fEndLogicValueOnAngleAxis ) const
     430             : {
     431         336 :     const ExplicitScaleData& rAngleScale = m_bSwapXAndY ? m_aScales[1] : m_aScales[0];
     432         336 :     if( AxisOrientation_MATHEMATICAL != rAngleScale.Orientation )
     433             :     {
     434         224 :         double fHelp = fEndLogicValueOnAngleAxis;
     435         224 :         fEndLogicValueOnAngleAxis = fStartLogicValueOnAngleAxis;
     436         224 :         fStartLogicValueOnAngleAxis = fHelp;
     437             :     }
     438             : 
     439         336 :     double fStartAngleDegree = this->transformToAngleDegree( fStartLogicValueOnAngleAxis );
     440         336 :     double fEndAngleDegree   = this->transformToAngleDegree( fEndLogicValueOnAngleAxis );
     441         336 :     double fWidthAngleDegree = fEndAngleDegree - fStartAngleDegree;
     442             : 
     443         672 :     if( ::rtl::math::approxEqual( fStartAngleDegree, fEndAngleDegree )
     444         336 :         && !::rtl::math::approxEqual( fStartLogicValueOnAngleAxis, fEndLogicValueOnAngleAxis ) )
     445           0 :         fWidthAngleDegree = 360.0;
     446             : 
     447         746 :     while(fWidthAngleDegree<0.0)
     448          74 :         fWidthAngleDegree+=360.0;
     449         672 :     while(fWidthAngleDegree>360.0)
     450           0 :         fWidthAngleDegree-=360.0;
     451             : 
     452         336 :     return fWidthAngleDegree;
     453             : }
     454             : 
     455             : //This method does a lot of computation for understanding which scale to
     456             : //utilize and if reverse orientation should be used. Indeed, for a pie or donut,
     457             : //the final result is as simple as multiplying by 360 and adding
     458             : //`m_fAngleDegreeOffset`.
     459        1300 : double PolarPlottingPositionHelper::transformToAngleDegree( double fLogicValueOnAngleAxis, bool bDoScaling ) const
     460             : {
     461        1300 :     double fRet=0.0;
     462             : 
     463        1300 :     double fAxisAngleScaleDirection = 1.0;
     464             :     {
     465        1300 :         const ExplicitScaleData& rScale = m_bSwapXAndY ? m_aScales[1] : m_aScales[0];
     466        1300 :         if(AxisOrientation_MATHEMATICAL != rScale.Orientation)
     467         818 :             fAxisAngleScaleDirection *= -1.0;
     468             :     }
     469             : 
     470        1300 :     double MinAngleValue = 0.0;
     471        1300 :     double MaxAngleValue = 0.0;
     472             :     {
     473        1300 :         double MinX = getLogicMinX();
     474        1300 :         double MinY = getLogicMinY();
     475        1300 :         double MaxX = getLogicMaxX();
     476        1300 :         double MaxY = getLogicMaxY();
     477        1300 :         double MinZ = getLogicMinZ();
     478        1300 :         double MaxZ = getLogicMaxZ();
     479             : 
     480        1300 :         doLogicScaling( &MinX, &MinY, &MinZ );
     481        1300 :         doLogicScaling( &MaxX, &MaxY, &MaxZ);
     482             : 
     483        1300 :         MinAngleValue = m_bSwapXAndY ? MinY : MinX;
     484        1300 :         MaxAngleValue = m_bSwapXAndY ? MaxY : MaxX;
     485             :     }
     486             : 
     487        1300 :     double fScaledLogicAngleValue = 0.0;
     488        1300 :     if(bDoScaling)
     489             :     {
     490        1272 :         double fX = m_bSwapXAndY ? getLogicMaxX() : fLogicValueOnAngleAxis;
     491        1272 :         double fY = m_bSwapXAndY ? fLogicValueOnAngleAxis : getLogicMaxY();
     492        1272 :         double fZ = getLogicMaxZ();
     493        1272 :         clipLogicValues( &fX, &fY, &fZ );
     494        1272 :         doLogicScaling( &fX, &fY, &fZ );
     495        1272 :         fScaledLogicAngleValue = m_bSwapXAndY ? fY : fX;
     496             :     }
     497             :     else
     498          28 :         fScaledLogicAngleValue = fLogicValueOnAngleAxis;
     499             : 
     500             :     fRet = m_fAngleDegreeOffset
     501        1300 :                   + fAxisAngleScaleDirection*(fScaledLogicAngleValue-MinAngleValue)*360.0
     502        1300 :                     /fabs(MaxAngleValue-MinAngleValue);
     503        2750 :     while(fRet>360.0)
     504         150 :         fRet-=360.0;
     505        3254 :     while(fRet<0)
     506         654 :         fRet+=360.0;
     507        1300 :     return fRet;
     508             : }
     509             : 
     510             : /**
     511             :  * Given a value in the radius axis scale range, it returns, in the simplest
     512             :  * case (that is when `m_fRadiusOffset` is zero), the normalized value; when
     513             :  * `m_fRadiusOffset` is not zero (e.g. as in the case of a donut), the interval
     514             :  * used for normalization is extended by `m_fRadiusOffset`: if the axis
     515             :  * orientation is not reversed the new interval becomes
     516             :  * [scale.Minimum - m_fRadiusOffset, scale.Maximum] else it becomes
     517             :  * [scale.Minimum, scale.Maximum + m_fRadiusOffset].
     518             :  * Pay attention here! For the latter case, since the axis orientation is
     519             :  * reversed, the normalization is reversed too. Indeed, we have
     520             :  * `transformToRadius(scale.Maximum + m_fRadiusOffset) = 0` and
     521             :  * `transformToRadius(scale.Minimum) = 1`.
     522             :  *
     523             :  * For a pie chart the radius axis scale range is initialized by the
     524             :  * `getMinimum` and `getMaximum` methods of the `PieChart` object (see notes
     525             :  * for `VCoordinateSystem::prepareAutomaticAxisScaling`).
     526             :  * So we have scale.Minimum = 0.5 (always constant!) and
     527             :  * scale.Maximum = 0.5 + number_of_rings + max_offset
     528             :  * (see notes for `PieChart::getMaxOffset`).
     529             :  * Hence we get the following general formulas for computing normalized inner
     530             :  * and outer radius:
     531             :  *
     532             :  *    1- transformToRadius(inner_radius) =
     533             :  *               (number_of_rings - (ring_index + 1) + m_fRadiusOffset)
     534             :  *                   / (number_of_rings + max_offset + m_fRadiusOffset)
     535             :  *
     536             :  *    2- transformToRadius(outer_radius) =
     537             :  *               (1 + number_of_rings - (ring_index + 1) + m_fRadiusOffset)
     538             :  *                   / (number_of_rings + max_offset + m_fRadiusOffset).
     539             :  *
     540             :  * Here you have to take into account that values for inner and outer radius
     541             :  * are swapped since the radius axis is reversed (See notes for
     542             :  * `PiePositionHelper::getInnerAndOuterRadius`). So indeed inner_radius is
     543             :  * the outer and outer_radius is the inner. Anyway still because of the reverse
     544             :  * orientation, the normalization performed by `transformToRadius` is reversed
     545             :  * too, as we have seen above. Hence `transformToRadius(inner_radius)` is
     546             :  * really the normalized inner radius and  `transformToRadius(outer_radius)` is
     547             :  * really the normalized outer radius.
     548             :  *
     549             :  * Some basic examples where we apply the above formulas:
     550             :  *    1- For a non-exploded pie chart we have:
     551             :  *         `transformToRadius(inner_radius) = 0`,
     552             :  *         `transformToRadius(outer_radius) = 1`.
     553             :  *    2- For a non-exploded donut with a single ring we have:
     554             :  *         `transformToRadius(inner_radius) =
     555             :  *                 m_fRadiusOffset/(1 + m_fRadiusOffset)`,
     556             :  *         `transformToRadius(outer_radius) =
     557             :  *                 (1 + m_fRadiusOffset)/(1 + m_fRadiusOffset) = 1`.
     558             :  *    3- For an exploded pie chart we have:
     559             :  *         `transformToRadius(inner_radius) = 0/(1 + max_offset) = 0`,
     560             :  *         `transformToRadius(outer_radius) = 1/(1 + max_offset)`.
     561             :  *
     562             :  *  The third example needs some remark. Both the logical inner and outer
     563             :  *  radius passed to `transformToRadius` are offset by `max_offset`.
     564             :  *  However the returned normalized values do not contain any (normalized)
     565             :  *  offset term at all, otherwise the returned values would be
     566             :  *  `max_offset/(1 + max_offset)` and `1`. Hence, for exploded pie/donut,
     567             :  *  `transformToRadius` returns the normalized value of radii without any
     568             :  *  offset term. These values are smaller than in the non-exploded case by an
     569             :  *  amount equals to the value of the normalized maximum offset
     570             :  *  (`max_offset/(1 + max_offset)` in the example above). That is due to the
     571             :  *  fact that the normalization keeps into account the space needed for the
     572             :  *  offset. This is the correct behavior, in fact the offset for the current
     573             :  *  slice could be different from the maximum offset.
     574             :  *  These remarks should clarify why the `PieChart::createDataPoint` and
     575             :  *  `PieChart::createTextLabelShape` methods add the normalized offset (for the
     576             :  *  current slice) to the normalized radii in order to achieve the correct
     577             :  *  placement of slice and text shapes.
     578             :  */
     579         964 : double PolarPlottingPositionHelper::transformToRadius( double fLogicValueOnRadiusAxis, bool bDoScaling ) const
     580             : {
     581         964 :     double fNormalRadius = 0.0;
     582             :     {
     583         964 :         double fScaledLogicRadiusValue = 0.0;
     584         964 :         double fX = m_bSwapXAndY ? fLogicValueOnRadiusAxis: getLogicMaxX();
     585         964 :         double fY = m_bSwapXAndY ? getLogicMaxY() : fLogicValueOnRadiusAxis;
     586         964 :         if(bDoScaling)
     587         936 :             doLogicScaling( &fX, &fY, 0 );
     588             : 
     589         964 :         fScaledLogicRadiusValue = m_bSwapXAndY ? fX : fY;
     590             : 
     591         964 :         bool bMinIsInnerRadius = true;
     592         964 :         const ExplicitScaleData& rScale = m_bSwapXAndY ? m_aScales[0] : m_aScales[1];
     593         964 :         if(AxisOrientation_MATHEMATICAL != rScale.Orientation)
     594         224 :             bMinIsInnerRadius = false;
     595             : 
     596         964 :         double fInnerScaledLogicRadius=0.0;
     597         964 :         double fOuterScaledLogicRadius=0.0;
     598             :         {
     599         964 :             double MinX = getLogicMinX();
     600         964 :             double MinY = getLogicMinY();
     601         964 :             doLogicScaling( &MinX, &MinY, 0 );
     602         964 :             double MaxX = getLogicMaxX();
     603         964 :             double MaxY = getLogicMaxY();
     604         964 :             doLogicScaling( &MaxX, &MaxY, 0 );
     605             : 
     606         964 :             double fMin = m_bSwapXAndY ? MinX : MinY;
     607         964 :             double fMax = m_bSwapXAndY ? MaxX : MaxY;
     608             : 
     609         964 :             fInnerScaledLogicRadius = bMinIsInnerRadius ? fMin : fMax;
     610         964 :             fOuterScaledLogicRadius = bMinIsInnerRadius ? fMax : fMin;
     611             :         }
     612             : 
     613         964 :         if( bMinIsInnerRadius )
     614         740 :             fInnerScaledLogicRadius -= fabs(m_fRadiusOffset);
     615             :         else
     616         224 :             fInnerScaledLogicRadius += fabs(m_fRadiusOffset);
     617         964 :         fNormalRadius = (fScaledLogicRadiusValue-fInnerScaledLogicRadius)/(fOuterScaledLogicRadius-fInnerScaledLogicRadius);
     618             :     }
     619         964 :     return fNormalRadius;
     620             : }
     621             : 
     622         148 : drawing::Position3D PolarPlottingPositionHelper::transformLogicToScene( double fX, double fY, double fZ, bool bClip ) const
     623             : {
     624         148 :     if(bClip)
     625         128 :         this->clipLogicValues( &fX,&fY,&fZ );
     626         148 :     double fLogicValueOnAngleAxis  = m_bSwapXAndY ? fY : fX;
     627         148 :     double fLogicValueOnRadiusAxis = m_bSwapXAndY ? fX : fY;
     628         148 :     return this->transformAngleRadiusToScene( fLogicValueOnAngleAxis, fLogicValueOnRadiusAxis, fZ, true );
     629             : }
     630             : 
     631          28 : drawing::Position3D PolarPlottingPositionHelper::transformScaledLogicToScene( double fX, double fY, double fZ, bool bClip ) const
     632             : {
     633          28 :     if(bClip)
     634          28 :         this->clipScaledLogicValues( &fX,&fY,&fZ );
     635          28 :     double fLogicValueOnAngleAxis  = m_bSwapXAndY ? fY : fX;
     636          28 :     double fLogicValueOnRadiusAxis = m_bSwapXAndY ? fX : fY;
     637          28 :     return this->transformAngleRadiusToScene( fLogicValueOnAngleAxis, fLogicValueOnRadiusAxis, fZ, false );
     638             : }
     639        1436 : drawing::Position3D PolarPlottingPositionHelper::transformUnitCircleToScene( double fUnitAngleDegree, double fUnitRadius
     640             :                                                                             , double fLogicZ, bool /* bDoScaling */ ) const
     641             : {
     642        1436 :     double fAnglePi = fUnitAngleDegree*F_PI/180.0;
     643             : 
     644        1436 :     double fX=fUnitRadius*rtl::math::cos(fAnglePi);
     645        1436 :     double fY=fUnitRadius*rtl::math::sin(fAnglePi);
     646        1436 :     double fZ=fLogicZ;
     647             : 
     648        1436 :     switch(m_eNormalAxis)
     649             :     {
     650             :         case NormalAxis_X:
     651           0 :             std::swap(fX,fZ);
     652           0 :             break;
     653             :         case NormalAxis_Y:
     654           0 :             std::swap(fY,fZ);
     655           0 :             fZ*=-1;
     656           0 :             break;
     657             :         default: //NormalAxis_Z
     658        1436 :             break;
     659             :     }
     660             : 
     661             :     //!! applying matrix to vector does ignore translation, so it is important to use a B3DPoint here instead of B3DVector
     662        1436 :     ::basegfx::B3DPoint aPoint(fX,fY,fZ);
     663        2872 :     ::basegfx::B3DPoint aRet = m_aUnitCartesianToScene * aPoint;
     664        2872 :     return B3DPointToPosition3D(aRet);
     665             : }
     666             : 
     667         224 : drawing::Position3D PolarPlottingPositionHelper::transformAngleRadiusToScene( double fLogicValueOnAngleAxis, double fLogicValueOnRadiusAxis, double fLogicZ, bool bDoScaling ) const
     668             : {
     669         224 :     double fUnitAngleDegree = this->transformToAngleDegree(fLogicValueOnAngleAxis,bDoScaling);
     670         224 :     double fUnitRadius      = this->transformToRadius(fLogicValueOnRadiusAxis,bDoScaling);
     671             : 
     672         224 :     return transformUnitCircleToScene( fUnitAngleDegree, fUnitRadius, fLogicZ, bDoScaling );
     673             : }
     674             : 
     675          10 : double PolarPlottingPositionHelper::getOuterLogicRadius() const
     676             : {
     677          10 :     const ExplicitScaleData& rScale = m_bSwapXAndY ? m_aScales[0] : m_aScales[1];
     678          10 :     if( AxisOrientation_MATHEMATICAL==rScale.Orientation )
     679          10 :         return rScale.Maximum;
     680             :     else
     681           0 :         return rScale.Minimum;
     682             : }
     683             : 
     684       44124 : bool PlottingPositionHelper::isPercentY() const
     685             : {
     686       44124 :     return m_aScales[1].AxisType==AxisType::PERCENT;
     687             : }
     688             : 
     689       10348 : double PlottingPositionHelper::getBaseValueY() const
     690             : {
     691       10348 :     return m_aScales[1].Origin;
     692             : }
     693             : 
     694       13359 : void PlottingPositionHelper::setTimeResolution( long nTimeResolution, const Date& rNullDate )
     695             : {
     696       13359 :     m_nTimeResolution = nTimeResolution;
     697       13359 :     m_aNullDate = rNullDate;
     698             : 
     699             :     //adapt category width
     700       13359 :     double fCategoryWidth = 1.0;
     701       13359 :     if( !m_aScales.empty() )
     702             :     {
     703       13359 :         if( m_aScales[0].AxisType == ::com::sun::star::chart2::AxisType::DATE )
     704             :         {
     705           0 :             m_bDateAxis = true;
     706           0 :             if( nTimeResolution == ::com::sun::star::chart::TimeUnit::YEAR )
     707             :             {
     708           0 :                 const double fMonthCount = 12.0;//todo: this depends on the DateScaling and must be adjusted in case we use more generic calendars in future
     709           0 :                 fCategoryWidth = fMonthCount;
     710             :             }
     711             :         }
     712             :     }
     713       13359 :     setScaledCategoryWidth(fCategoryWidth);
     714       13359 : }
     715             : 
     716        2866 : void PlottingPositionHelper::setScaledCategoryWidth( double fScaledCategoryWidth )
     717             : {
     718        2866 :     m_fScaledCategoryWidth = fScaledCategoryWidth;
     719        2866 : }
     720        1034 : void PlottingPositionHelper::AllowShiftXAxisPos( bool bAllowShift )
     721             : {
     722        1034 :     m_bAllowShiftXAxisPos = bAllowShift;
     723        1034 : }
     724        1034 : void PlottingPositionHelper::AllowShiftZAxisPos( bool bAllowShift )
     725             : {
     726        1034 :     m_bAllowShiftZAxisPos = bAllowShift;
     727        1034 : }
     728             : 
     729             : }
     730             : 
     731             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11