LCOV - code coverage report
Current view: top level - chart2/source/controller/dialogs - tp_3D_SceneGeometry.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 142 0.7 %
Date: 2014-11-03 Functions: 2 22 9.1 %
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 "tp_3D_SceneGeometry.hxx"
      21             : 
      22             : #include "BaseGFXHelper.hxx"
      23             : #include "macros.hxx"
      24             : #include "DiagramHelper.hxx"
      25             : #include "ChartTypeHelper.hxx"
      26             : #include "ThreeDHelper.hxx"
      27             : #include <rtl/math.hxx>
      28             : #include <editeng/unoprnms.hxx>
      29             : #include <com/sun/star/drawing/ProjectionMode.hpp>
      30             : 
      31             : namespace chart
      32             : {
      33             : 
      34             : using namespace ::com::sun::star;
      35             : 
      36             : namespace
      37             : {
      38             : 
      39           0 : void lcl_shiftAngleToValidRange( sal_Int64& rnAngleDegree )
      40             : {
      41             :     //valid range:  ]-180,180]
      42           0 :     while( rnAngleDegree<=-180 )
      43           0 :         rnAngleDegree+=360;
      44           0 :     while( rnAngleDegree>180 )
      45           0 :         rnAngleDegree-=360;
      46           0 : }
      47             : 
      48           0 : void lcl_SetMetricFieldLimits( MetricField& rField, sal_Int64 nLimit )
      49             : {
      50           0 :     rField.SetMin(-1*nLimit);
      51           0 :     rField.SetFirst(-1*nLimit);
      52           0 :     rField.SetMax(nLimit);
      53           0 :     rField.SetLast(nLimit);
      54           0 : }
      55             : 
      56             : }
      57           0 : ThreeD_SceneGeometry_TabPage::ThreeD_SceneGeometry_TabPage( vcl::Window* pWindow
      58             :                 , const uno::Reference< beans::XPropertySet > & xSceneProperties
      59             :                 , ControllerLockHelper & rControllerLockHelper )
      60             :                 : TabPage ( pWindow
      61             :                           , "tp_3DSceneGeometry"
      62             :                           , "modules/schart/ui/tp_3D_SceneGeometry.ui")
      63             :                 , m_xSceneProperties( xSceneProperties )
      64             :                 , m_nXRotation(0)
      65             :                 , m_nYRotation(0)
      66             :                 , m_nZRotation(0)
      67             :                 , m_bAngleChangePending( false )
      68             :                 , m_bPerspectiveChangePending( false )
      69           0 :                 , m_rControllerLockHelper( rControllerLockHelper )
      70             : {
      71           0 :     get(m_pCbxRightAngledAxes,"CBX_RIGHT_ANGLED_AXES");
      72           0 :     get(m_pMFXRotation, "MTR_FLD_X_ROTATION");
      73           0 :     get(m_pMFYRotation, "MTR_FLD_Y_ROTATION");
      74           0 :     get(m_pFtZRotation, "FT_Z_ROTATION");
      75           0 :     get(m_pMFZRotation, "MTR_FLD_Z_ROTATION");
      76           0 :     get(m_pCbxPerspective,"CBX_PERSPECTIVE");
      77           0 :     get(m_pMFPerspective, "MTR_FLD_PERSPECTIVE");
      78             : 
      79             :     double fXAngle, fYAngle, fZAngle;
      80           0 :     ThreeDHelper::getRotationAngleFromDiagram( m_xSceneProperties, fXAngle, fYAngle, fZAngle );
      81             : 
      82           0 :     fXAngle = BaseGFXHelper::Rad2Deg( fXAngle );
      83           0 :     fYAngle = BaseGFXHelper::Rad2Deg( fYAngle );
      84           0 :     fZAngle = BaseGFXHelper::Rad2Deg( fZAngle );
      85             : 
      86             :     OSL_ENSURE( fZAngle>=-90 && fZAngle<=90, "z angle is out of valid range" );
      87             : 
      88           0 :     lcl_SetMetricFieldLimits( *m_pMFZRotation, 90 );
      89             : 
      90           0 :     m_nXRotation = ::basegfx::fround(fXAngle*pow(10.0,m_pMFXRotation->GetDecimalDigits()));
      91           0 :     m_nYRotation = ::basegfx::fround(-1.0*fYAngle*pow(10.0,m_pMFYRotation->GetDecimalDigits()));
      92           0 :     m_nZRotation = ::basegfx::fround(-1.0*fZAngle*pow(10.0,m_pMFZRotation->GetDecimalDigits()));
      93             : 
      94           0 :     lcl_shiftAngleToValidRange( m_nXRotation );
      95           0 :     lcl_shiftAngleToValidRange( m_nYRotation );
      96           0 :     lcl_shiftAngleToValidRange( m_nZRotation );
      97             : 
      98           0 :     m_pMFXRotation->SetValue(m_nXRotation);
      99           0 :     m_pMFYRotation->SetValue(m_nYRotation);
     100           0 :     m_pMFZRotation->SetValue(m_nZRotation);
     101             : 
     102           0 :     const sal_uLong nTimeout = 4*EDIT_UPDATEDATA_TIMEOUT;
     103           0 :     Link aAngleChangedLink( LINK( this, ThreeD_SceneGeometry_TabPage, AngleChanged ));
     104           0 :     Link aAngleEditedLink( LINK( this, ThreeD_SceneGeometry_TabPage, AngleEdited ));
     105             : 
     106           0 :     m_pMFXRotation->EnableUpdateData( nTimeout );
     107           0 :     m_pMFXRotation->SetUpdateDataHdl( aAngleChangedLink );
     108           0 :     m_pMFXRotation->SetModifyHdl( aAngleEditedLink );
     109             : 
     110           0 :     m_pMFYRotation->EnableUpdateData( nTimeout );
     111           0 :     m_pMFYRotation->SetUpdateDataHdl( aAngleChangedLink );
     112           0 :     m_pMFYRotation->SetModifyHdl( aAngleEditedLink );
     113             : 
     114           0 :     m_pMFZRotation->EnableUpdateData( nTimeout );
     115           0 :     m_pMFZRotation->SetUpdateDataHdl( aAngleChangedLink );
     116           0 :     m_pMFZRotation->SetModifyHdl( aAngleEditedLink );
     117             : 
     118           0 :     drawing::ProjectionMode aProjectionMode = drawing::ProjectionMode_PERSPECTIVE;
     119           0 :     m_xSceneProperties->getPropertyValue( "D3DScenePerspective" ) >>= aProjectionMode;
     120           0 :     m_pCbxPerspective->Check( aProjectionMode == drawing::ProjectionMode_PERSPECTIVE );
     121           0 :     m_pCbxPerspective->SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveToggled ));
     122             : 
     123           0 :     sal_Int32 nPerspectivePercentage = 20;
     124           0 :     m_xSceneProperties->getPropertyValue( "Perspective" ) >>= nPerspectivePercentage;
     125           0 :     m_pMFPerspective->SetValue( nPerspectivePercentage );
     126             : 
     127           0 :     m_pMFPerspective->EnableUpdateData( nTimeout );
     128           0 :     m_pMFPerspective->SetUpdateDataHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveChanged ) );
     129           0 :     m_pMFPerspective->SetModifyHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveEdited ) );
     130           0 :     m_pMFPerspective->Enable( m_pCbxPerspective->IsChecked() );
     131             : 
     132             :     //RightAngledAxes
     133           0 :     bool bRightAngledAxes = false;
     134             : 
     135           0 :     uno::Reference< chart2::XDiagram > xDiagram( m_xSceneProperties, uno::UNO_QUERY );
     136           0 :     if( ChartTypeHelper::isSupportingRightAngledAxes(
     137           0 :             DiagramHelper::getChartTypeByIndex( xDiagram, 0 ) ) )
     138             :     {
     139           0 :         m_xSceneProperties->getPropertyValue( "RightAngledAxes" ) >>= bRightAngledAxes;
     140           0 :         m_pCbxRightAngledAxes->SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled ));
     141           0 :         m_pCbxRightAngledAxes->Check( bRightAngledAxes );
     142             :     }
     143             :     else
     144             :     {
     145           0 :         m_pCbxRightAngledAxes->Enable(false);
     146             :     }
     147           0 :     m_pMFPerspective->SetAccessibleName(m_pCbxPerspective->GetText());
     148           0 :     m_pMFPerspective->SetAccessibleRelationLabeledBy(m_pCbxPerspective);
     149           0 : }
     150             : 
     151           0 : ThreeD_SceneGeometry_TabPage::~ThreeD_SceneGeometry_TabPage()
     152             : {
     153           0 : }
     154             : 
     155           0 : void ThreeD_SceneGeometry_TabPage::commitPendingChanges()
     156             : {
     157           0 :     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
     158             : 
     159           0 :     if( m_bAngleChangePending )
     160           0 :         applyAnglesToModel();
     161           0 :     if( m_bPerspectiveChangePending )
     162           0 :         applyPerspectiveToModel();
     163           0 : }
     164             : 
     165           0 : void ThreeD_SceneGeometry_TabPage::applyAnglesToModel()
     166             : {
     167           0 :     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
     168             : 
     169           0 :     double fXAngle = 0.0, fYAngle = 0.0, fZAngle = 0.0;
     170             : 
     171           0 :     if( !m_pMFZRotation->IsEmptyFieldValue() )
     172           0 :         m_nZRotation = m_pMFZRotation->GetValue();
     173             : 
     174           0 :     fXAngle = double(m_nXRotation)/double(pow(10.0,m_pMFXRotation->GetDecimalDigits()));
     175           0 :     fYAngle = double(-1.0*m_nYRotation)/double(pow(10.0,m_pMFYRotation->GetDecimalDigits()));
     176           0 :     fZAngle = double(-1.0*m_nZRotation)/double(pow(10.0,m_pMFZRotation->GetDecimalDigits()));
     177             : 
     178           0 :     fXAngle = BaseGFXHelper::Deg2Rad( fXAngle );
     179           0 :     fYAngle = BaseGFXHelper::Deg2Rad( fYAngle );
     180           0 :     fZAngle = BaseGFXHelper::Deg2Rad( fZAngle );
     181             : 
     182           0 :     ThreeDHelper::setRotationAngleToDiagram( m_xSceneProperties, fXAngle, fYAngle, fZAngle );
     183             : 
     184           0 :     m_bAngleChangePending = false;
     185           0 : }
     186             : 
     187           0 : IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, AngleEdited)
     188             : {
     189           0 :     m_nXRotation = m_pMFXRotation->GetValue();
     190           0 :     m_nYRotation = m_pMFYRotation->GetValue();
     191             : 
     192           0 :     m_bAngleChangePending = true;
     193           0 :     return 0;
     194             : }
     195             : 
     196           0 : IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, AngleChanged)
     197             : {
     198           0 :     applyAnglesToModel();
     199           0 :     return 0;
     200             : }
     201             : 
     202           0 : void ThreeD_SceneGeometry_TabPage::applyPerspectiveToModel()
     203             : {
     204           0 :     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
     205             : 
     206           0 :     drawing::ProjectionMode aMode = m_pCbxPerspective->IsChecked()
     207             :         ? drawing::ProjectionMode_PERSPECTIVE
     208           0 :         : drawing::ProjectionMode_PARALLEL;
     209             : 
     210             :     try
     211             :     {
     212           0 :         m_xSceneProperties->setPropertyValue( "D3DScenePerspective" , uno::makeAny( aMode ));
     213           0 :         m_xSceneProperties->setPropertyValue( "Perspective" , uno::makeAny( (sal_Int32)m_pMFPerspective->GetValue() ));
     214             :     }
     215           0 :     catch( const uno::Exception & ex )
     216             :     {
     217             :         ASSERT_EXCEPTION( ex );
     218             :     }
     219             : 
     220           0 :     m_bPerspectiveChangePending = false;
     221           0 : }
     222             : 
     223           0 : IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveEdited)
     224             : {
     225           0 :     m_bPerspectiveChangePending = true;
     226           0 :     return 0;
     227             : }
     228             : 
     229           0 : IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveChanged)
     230             : {
     231           0 :     applyPerspectiveToModel();
     232           0 :     return 0;
     233             : }
     234             : 
     235           0 : IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveToggled)
     236             : {
     237           0 :     m_pMFPerspective->Enable( m_pCbxPerspective->IsChecked() );
     238           0 :     applyPerspectiveToModel();
     239           0 :     return 0;
     240             : }
     241             : 
     242           0 : IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled)
     243             : {
     244           0 :     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
     245             : 
     246           0 :     bool bEnableZ = !m_pCbxRightAngledAxes->IsChecked();
     247           0 :     m_pFtZRotation->Enable( bEnableZ );
     248           0 :     m_pMFZRotation->Enable( bEnableZ );
     249           0 :     m_pMFZRotation->EnableEmptyFieldValue( !bEnableZ );
     250           0 :     if( !bEnableZ )
     251             :     {
     252           0 :         m_nXRotation = m_pMFXRotation->GetValue();
     253           0 :         m_nYRotation = m_pMFYRotation->GetValue();
     254           0 :         m_nZRotation = m_pMFZRotation->GetValue();
     255             : 
     256           0 :         m_pMFXRotation->SetValue(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nXRotation), ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes())));
     257           0 :         m_pMFYRotation->SetValue(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nYRotation), ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes())));
     258           0 :         m_pMFZRotation->SetEmptyFieldValue();
     259             : 
     260           0 :         lcl_SetMetricFieldLimits( *m_pMFXRotation, static_cast<sal_Int64>(ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes()));
     261           0 :         lcl_SetMetricFieldLimits( *m_pMFYRotation, static_cast<sal_Int64>(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()));
     262             :     }
     263             :     else
     264             :     {
     265           0 :         lcl_SetMetricFieldLimits( *m_pMFXRotation, 180 );
     266           0 :         lcl_SetMetricFieldLimits( *m_pMFYRotation, 180 );
     267             : 
     268           0 :         m_pMFXRotation->SetValue(m_nXRotation);
     269           0 :         m_pMFYRotation->SetValue(m_nYRotation);
     270           0 :         m_pMFZRotation->SetValue(m_nZRotation);
     271             :     }
     272             : 
     273           0 :     ThreeDHelper::switchRightAngledAxes( m_xSceneProperties, m_pCbxRightAngledAxes->IsChecked(), true /*bRotateLights*/ );
     274             : 
     275           0 :     return 0;
     276             : }
     277             : 
     278         102 : } //namespace chart
     279             : 
     280             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10