LCOV - code coverage report
Current view: top level - chart2/source/controller/dialogs - tp_3D_SceneGeometry.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 153 0.7 %
Date: 2015-06-13 12:38:46 Functions: 2 23 8.7 %
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 :     uno::Reference< chart2::XDiagram > xDiagram( m_xSceneProperties, uno::UNO_QUERY );
     134           0 :     if( ChartTypeHelper::isSupportingRightAngledAxes(
     135           0 :             DiagramHelper::getChartTypeByIndex( xDiagram, 0 ) ) )
     136             :     {
     137           0 :         bool bRightAngledAxes = false;
     138           0 :         m_xSceneProperties->getPropertyValue( "RightAngledAxes" ) >>= bRightAngledAxes;
     139           0 :         m_pCbxRightAngledAxes->SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled ));
     140           0 :         m_pCbxRightAngledAxes->Check( bRightAngledAxes );
     141             :     }
     142             :     else
     143             :     {
     144           0 :         m_pCbxRightAngledAxes->Enable(false);
     145             :     }
     146           0 :     m_pMFPerspective->SetAccessibleName(m_pCbxPerspective->GetText());
     147           0 :     m_pMFPerspective->SetAccessibleRelationLabeledBy(m_pCbxPerspective);
     148           0 : }
     149             : 
     150           0 : ThreeD_SceneGeometry_TabPage::~ThreeD_SceneGeometry_TabPage()
     151             : {
     152           0 :     disposeOnce();
     153           0 : }
     154             : 
     155           0 : void ThreeD_SceneGeometry_TabPage::dispose()
     156             : {
     157           0 :     m_pCbxRightAngledAxes.clear();
     158           0 :     m_pMFXRotation.clear();
     159           0 :     m_pMFYRotation.clear();
     160           0 :     m_pFtZRotation.clear();
     161           0 :     m_pMFZRotation.clear();
     162           0 :     m_pCbxPerspective.clear();
     163           0 :     m_pMFPerspective.clear();
     164           0 :     TabPage::dispose();
     165           0 : }
     166             : 
     167             : 
     168           0 : void ThreeD_SceneGeometry_TabPage::commitPendingChanges()
     169             : {
     170           0 :     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
     171             : 
     172           0 :     if( m_bAngleChangePending )
     173           0 :         applyAnglesToModel();
     174           0 :     if( m_bPerspectiveChangePending )
     175           0 :         applyPerspectiveToModel();
     176           0 : }
     177             : 
     178           0 : void ThreeD_SceneGeometry_TabPage::applyAnglesToModel()
     179             : {
     180           0 :     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
     181             : 
     182           0 :     double fXAngle = 0.0, fYAngle = 0.0, fZAngle = 0.0;
     183             : 
     184           0 :     if( !m_pMFZRotation->IsEmptyFieldValue() )
     185           0 :         m_nZRotation = m_pMFZRotation->GetValue();
     186             : 
     187           0 :     fXAngle = double(m_nXRotation)/double(pow(10.0,m_pMFXRotation->GetDecimalDigits()));
     188           0 :     fYAngle = double(-1.0*m_nYRotation)/double(pow(10.0,m_pMFYRotation->GetDecimalDigits()));
     189           0 :     fZAngle = double(-1.0*m_nZRotation)/double(pow(10.0,m_pMFZRotation->GetDecimalDigits()));
     190             : 
     191           0 :     fXAngle = BaseGFXHelper::Deg2Rad( fXAngle );
     192           0 :     fYAngle = BaseGFXHelper::Deg2Rad( fYAngle );
     193           0 :     fZAngle = BaseGFXHelper::Deg2Rad( fZAngle );
     194             : 
     195           0 :     ThreeDHelper::setRotationAngleToDiagram( m_xSceneProperties, fXAngle, fYAngle, fZAngle );
     196             : 
     197           0 :     m_bAngleChangePending = false;
     198           0 : }
     199             : 
     200           0 : IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, AngleEdited)
     201             : {
     202           0 :     m_nXRotation = m_pMFXRotation->GetValue();
     203           0 :     m_nYRotation = m_pMFYRotation->GetValue();
     204             : 
     205           0 :     m_bAngleChangePending = true;
     206           0 :     return 0;
     207             : }
     208             : 
     209           0 : IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, AngleChanged)
     210             : {
     211           0 :     applyAnglesToModel();
     212           0 :     return 0;
     213             : }
     214             : 
     215           0 : void ThreeD_SceneGeometry_TabPage::applyPerspectiveToModel()
     216             : {
     217           0 :     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
     218             : 
     219           0 :     drawing::ProjectionMode aMode = m_pCbxPerspective->IsChecked()
     220             :         ? drawing::ProjectionMode_PERSPECTIVE
     221           0 :         : drawing::ProjectionMode_PARALLEL;
     222             : 
     223             :     try
     224             :     {
     225           0 :         m_xSceneProperties->setPropertyValue( "D3DScenePerspective" , uno::makeAny( aMode ));
     226           0 :         m_xSceneProperties->setPropertyValue( "Perspective" , uno::makeAny( (sal_Int32)m_pMFPerspective->GetValue() ));
     227             :     }
     228           0 :     catch( const uno::Exception & ex )
     229             :     {
     230             :         ASSERT_EXCEPTION( ex );
     231             :     }
     232             : 
     233           0 :     m_bPerspectiveChangePending = false;
     234           0 : }
     235             : 
     236           0 : IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveEdited)
     237             : {
     238           0 :     m_bPerspectiveChangePending = true;
     239           0 :     return 0;
     240             : }
     241             : 
     242           0 : IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveChanged)
     243             : {
     244           0 :     applyPerspectiveToModel();
     245           0 :     return 0;
     246             : }
     247             : 
     248           0 : IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveToggled)
     249             : {
     250           0 :     m_pMFPerspective->Enable( m_pCbxPerspective->IsChecked() );
     251           0 :     applyPerspectiveToModel();
     252           0 :     return 0;
     253             : }
     254             : 
     255           0 : IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled)
     256             : {
     257           0 :     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
     258             : 
     259           0 :     bool bEnableZ = !m_pCbxRightAngledAxes->IsChecked();
     260           0 :     m_pFtZRotation->Enable( bEnableZ );
     261           0 :     m_pMFZRotation->Enable( bEnableZ );
     262           0 :     m_pMFZRotation->EnableEmptyFieldValue( !bEnableZ );
     263           0 :     if( !bEnableZ )
     264             :     {
     265           0 :         m_nXRotation = m_pMFXRotation->GetValue();
     266           0 :         m_nYRotation = m_pMFYRotation->GetValue();
     267           0 :         m_nZRotation = m_pMFZRotation->GetValue();
     268             : 
     269           0 :         m_pMFXRotation->SetValue(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nXRotation), ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes())));
     270           0 :         m_pMFYRotation->SetValue(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nYRotation), ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes())));
     271           0 :         m_pMFZRotation->SetEmptyFieldValue();
     272             : 
     273           0 :         lcl_SetMetricFieldLimits( *m_pMFXRotation, static_cast<sal_Int64>(ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes()));
     274           0 :         lcl_SetMetricFieldLimits( *m_pMFYRotation, static_cast<sal_Int64>(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()));
     275             :     }
     276             :     else
     277             :     {
     278           0 :         lcl_SetMetricFieldLimits( *m_pMFXRotation, 180 );
     279           0 :         lcl_SetMetricFieldLimits( *m_pMFYRotation, 180 );
     280             : 
     281           0 :         m_pMFXRotation->SetValue(m_nXRotation);
     282           0 :         m_pMFYRotation->SetValue(m_nYRotation);
     283           0 :         m_pMFZRotation->SetValue(m_nZRotation);
     284             :     }
     285             : 
     286           0 :     ThreeDHelper::switchRightAngledAxes( m_xSceneProperties, m_pCbxRightAngledAxes->IsChecked(), true /*bRotateLights*/ );
     287             : 
     288           0 :     return 0;
     289             : }
     290             : 
     291          57 : } //namespace chart
     292             : 
     293             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11