Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_3D_SceneGeometry.cxx
blobae8449dcf257688c72a9ad66b8026581a219970d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "tp_3D_SceneGeometry.hxx"
22 #include <BaseGFXHelper.hxx>
23 #include <DiagramHelper.hxx>
24 #include <ChartTypeHelper.hxx>
25 #include <ThreeDHelper.hxx>
26 #include <rtl/math.hxx>
27 #include <editeng/unoprnms.hxx>
28 #include <com/sun/star/drawing/ProjectionMode.hpp>
29 #include <tools/diagnose_ex.h>
31 namespace chart
34 using namespace ::com::sun::star;
36 namespace
39 void lcl_shiftAngleToValidRange( sal_Int64& rnAngleDegree )
41 //valid range: ]-180,180]
42 while( rnAngleDegree<=-180 )
43 rnAngleDegree+=360;
44 while( rnAngleDegree>180 )
45 rnAngleDegree-=360;
48 void lcl_SetMetricFieldLimits( MetricField& rField, sal_Int64 nLimit )
50 rField.SetMin(-1*nLimit);
51 rField.SetFirst(-1*nLimit);
52 rField.SetMax(nLimit);
53 rField.SetLast(nLimit);
57 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 , m_rControllerLockHelper( rControllerLockHelper )
71 get(m_pCbxRightAngledAxes,"CBX_RIGHT_ANGLED_AXES");
72 get(m_pMFXRotation, "MTR_FLD_X_ROTATION");
73 get(m_pMFYRotation, "MTR_FLD_Y_ROTATION");
74 get(m_pFtZRotation, "FT_Z_ROTATION");
75 get(m_pMFZRotation, "MTR_FLD_Z_ROTATION");
76 get(m_pCbxPerspective,"CBX_PERSPECTIVE");
77 get(m_pMFPerspective, "MTR_FLD_PERSPECTIVE");
79 double fXAngle, fYAngle, fZAngle;
80 ThreeDHelper::getRotationAngleFromDiagram( m_xSceneProperties, fXAngle, fYAngle, fZAngle );
82 fXAngle = basegfx::rad2deg(fXAngle);
83 fYAngle = basegfx::rad2deg(fYAngle);
84 fZAngle = basegfx::rad2deg(fZAngle);
86 OSL_ENSURE( fZAngle>=-90 && fZAngle<=90, "z angle is out of valid range" );
88 lcl_SetMetricFieldLimits( *m_pMFZRotation, 90 );
90 m_nXRotation = ::basegfx::fround(fXAngle*pow(10.0,m_pMFXRotation->GetDecimalDigits()));
91 m_nYRotation = ::basegfx::fround(-1.0*fYAngle*pow(10.0,m_pMFYRotation->GetDecimalDigits()));
92 m_nZRotation = ::basegfx::fround(-1.0*fZAngle*pow(10.0,m_pMFZRotation->GetDecimalDigits()));
94 lcl_shiftAngleToValidRange( m_nXRotation );
95 lcl_shiftAngleToValidRange( m_nYRotation );
96 lcl_shiftAngleToValidRange( m_nZRotation );
98 m_pMFXRotation->SetValue(m_nXRotation);
99 m_pMFYRotation->SetValue(m_nYRotation);
100 m_pMFZRotation->SetValue(m_nZRotation);
102 const sal_uLong nTimeout = 4*EDIT_UPDATEDATA_TIMEOUT;
103 Link<Edit&,void> aAngleChangedLink( LINK( this, ThreeD_SceneGeometry_TabPage, AngleChanged ));
104 Link<Edit&,void> aAngleEditedLink( LINK( this, ThreeD_SceneGeometry_TabPage, AngleEdited ));
106 m_pMFXRotation->EnableUpdateData( nTimeout );
107 m_pMFXRotation->SetUpdateDataHdl( aAngleChangedLink );
108 m_pMFXRotation->SetModifyHdl( aAngleEditedLink );
110 m_pMFYRotation->EnableUpdateData( nTimeout );
111 m_pMFYRotation->SetUpdateDataHdl( aAngleChangedLink );
112 m_pMFYRotation->SetModifyHdl( aAngleEditedLink );
114 m_pMFZRotation->EnableUpdateData( nTimeout );
115 m_pMFZRotation->SetUpdateDataHdl( aAngleChangedLink );
116 m_pMFZRotation->SetModifyHdl( aAngleEditedLink );
118 drawing::ProjectionMode aProjectionMode = drawing::ProjectionMode_PERSPECTIVE;
119 m_xSceneProperties->getPropertyValue( "D3DScenePerspective" ) >>= aProjectionMode;
120 m_pCbxPerspective->Check( aProjectionMode == drawing::ProjectionMode_PERSPECTIVE );
121 m_pCbxPerspective->SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveToggled ));
123 sal_Int32 nPerspectivePercentage = 20;
124 m_xSceneProperties->getPropertyValue( "Perspective" ) >>= nPerspectivePercentage;
125 m_pMFPerspective->SetValue( nPerspectivePercentage );
127 m_pMFPerspective->EnableUpdateData( nTimeout );
128 m_pMFPerspective->SetUpdateDataHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveChanged ) );
129 m_pMFPerspective->SetModifyHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveEdited ) );
130 m_pMFPerspective->Enable( m_pCbxPerspective->IsChecked() );
132 //RightAngledAxes
133 uno::Reference< chart2::XDiagram > xDiagram( m_xSceneProperties, uno::UNO_QUERY );
134 if( ChartTypeHelper::isSupportingRightAngledAxes(
135 DiagramHelper::getChartTypeByIndex( xDiagram, 0 ) ) )
137 bool bRightAngledAxes = false;
138 m_xSceneProperties->getPropertyValue( "RightAngledAxes" ) >>= bRightAngledAxes;
139 m_pCbxRightAngledAxes->SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled ));
140 m_pCbxRightAngledAxes->Check( bRightAngledAxes );
142 else
144 m_pCbxRightAngledAxes->Enable(false);
148 ThreeD_SceneGeometry_TabPage::~ThreeD_SceneGeometry_TabPage()
150 disposeOnce();
153 void ThreeD_SceneGeometry_TabPage::dispose()
155 m_pCbxRightAngledAxes.clear();
156 m_pMFXRotation.clear();
157 m_pMFYRotation.clear();
158 m_pFtZRotation.clear();
159 m_pMFZRotation.clear();
160 m_pCbxPerspective.clear();
161 m_pMFPerspective.clear();
162 TabPage::dispose();
166 void ThreeD_SceneGeometry_TabPage::commitPendingChanges()
168 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
170 if( m_bAngleChangePending )
171 applyAnglesToModel();
172 if( m_bPerspectiveChangePending )
173 applyPerspectiveToModel();
176 void ThreeD_SceneGeometry_TabPage::applyAnglesToModel()
178 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
180 double fXAngle = 0.0, fYAngle = 0.0, fZAngle = 0.0;
182 if( !m_pMFZRotation->IsEmptyFieldValue() )
183 m_nZRotation = m_pMFZRotation->GetValue();
185 fXAngle = double(m_nXRotation)/pow(10.0,m_pMFXRotation->GetDecimalDigits());
186 fYAngle = double(-1.0*m_nYRotation)/pow(10.0,m_pMFYRotation->GetDecimalDigits());
187 fZAngle = double(-1.0*m_nZRotation)/pow(10.0,m_pMFZRotation->GetDecimalDigits());
189 fXAngle = basegfx::deg2rad(fXAngle);
190 fYAngle = basegfx::deg2rad(fYAngle);
191 fZAngle = basegfx::deg2rad(fZAngle);
193 ThreeDHelper::setRotationAngleToDiagram( m_xSceneProperties, fXAngle, fYAngle, fZAngle );
195 m_bAngleChangePending = false;
198 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, AngleEdited, Edit&, void)
200 m_nXRotation = m_pMFXRotation->GetValue();
201 m_nYRotation = m_pMFYRotation->GetValue();
203 m_bAngleChangePending = true;
206 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, AngleChanged, Edit&, void)
208 applyAnglesToModel();
211 void ThreeD_SceneGeometry_TabPage::applyPerspectiveToModel()
213 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
215 drawing::ProjectionMode aMode = m_pCbxPerspective->IsChecked()
216 ? drawing::ProjectionMode_PERSPECTIVE
217 : drawing::ProjectionMode_PARALLEL;
221 m_xSceneProperties->setPropertyValue( "D3DScenePerspective" , uno::Any( aMode ));
222 m_xSceneProperties->setPropertyValue( "Perspective" , uno::Any( static_cast<sal_Int32>(m_pMFPerspective->GetValue()) ));
224 catch( const uno::Exception & )
226 DBG_UNHANDLED_EXCEPTION("chart2");
229 m_bPerspectiveChangePending = false;
232 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveEdited, Edit&, void)
234 m_bPerspectiveChangePending = true;
237 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveChanged, Edit&, void)
239 applyPerspectiveToModel();
242 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveToggled, CheckBox&, void)
244 m_pMFPerspective->Enable( m_pCbxPerspective->IsChecked() );
245 applyPerspectiveToModel();
248 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled, CheckBox&, void)
250 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
252 bool bEnableZ = !m_pCbxRightAngledAxes->IsChecked();
253 m_pFtZRotation->Enable( bEnableZ );
254 m_pMFZRotation->Enable( bEnableZ );
255 m_pMFZRotation->EnableEmptyFieldValue( !bEnableZ );
256 if( !bEnableZ )
258 m_nXRotation = m_pMFXRotation->GetValue();
259 m_nYRotation = m_pMFYRotation->GetValue();
260 m_nZRotation = m_pMFZRotation->GetValue();
262 m_pMFXRotation->SetValue(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nXRotation), ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes())));
263 m_pMFYRotation->SetValue(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nYRotation), ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes())));
264 m_pMFZRotation->SetEmptyFieldValue();
266 lcl_SetMetricFieldLimits( *m_pMFXRotation, static_cast<sal_Int64>(ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes()));
267 lcl_SetMetricFieldLimits( *m_pMFYRotation, static_cast<sal_Int64>(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()));
269 else
271 lcl_SetMetricFieldLimits( *m_pMFXRotation, 180 );
272 lcl_SetMetricFieldLimits( *m_pMFYRotation, 180 );
274 m_pMFXRotation->SetValue(m_nXRotation);
275 m_pMFYRotation->SetValue(m_nYRotation);
276 m_pMFZRotation->SetValue(m_nZRotation);
279 ThreeDHelper::switchRightAngledAxes( m_xSceneProperties, m_pCbxRightAngledAxes->IsChecked() );
282 } //namespace chart
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */