Bump for 3.6-28
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_3D_SceneGeometry.cxx
blob18f4481020caa63af85b1ba5f96729104534b6b9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "tp_3D_SceneGeometry.hxx"
31 #include "tp_3D_SceneGeometry.hrc"
32 #include "ResId.hxx"
33 #include "NoWarningThisInCTOR.hxx"
34 #include "BaseGFXHelper.hxx"
35 #include "macros.hxx"
36 #include "DiagramHelper.hxx"
37 #include "ChartTypeHelper.hxx"
38 #include "ThreeDHelper.hxx"
39 #include <rtl/math.hxx>
40 #include <editeng/unoprnms.hxx>
41 #include <com/sun/star/drawing/ProjectionMode.hpp>
43 //.............................................................................
44 namespace chart
46 //.............................................................................
48 using namespace ::com::sun::star;
50 namespace
53 void lcl_shiftAngleToValidRange( sal_Int64& rnAngleDegree )
55 //valid range: ]-180,180]
56 while( rnAngleDegree<=-180 )
57 rnAngleDegree+=360;
58 while( rnAngleDegree>180 )
59 rnAngleDegree-=360;
62 void lcl_SetMetricFieldLimits( MetricField& rField, sal_Int64 nLimit )
64 rField.SetMin(-1*nLimit);
65 rField.SetFirst(-1*nLimit);
66 rField.SetMax(nLimit);
67 rField.SetLast(nLimit);
71 ThreeD_SceneGeometry_TabPage::ThreeD_SceneGeometry_TabPage( Window* pWindow
72 , const uno::Reference< beans::XPropertySet > & xSceneProperties
73 , ControllerLockHelper & rControllerLockHelper )
74 : TabPage ( pWindow, SchResId( TP_3D_SCENEGEOMETRY ) )
75 , m_xSceneProperties( xSceneProperties )
76 , m_aCbxRightAngledAxes( this, SchResId( CBX_RIGHT_ANGLED_AXES ) )
77 , m_aFtXRotation ( this, SchResId( FT_X_ROTATION ) )
78 , m_aMFXRotation ( this, SchResId( MTR_FLD_X_ROTATION ) )
79 , m_aFtYRotation ( this, SchResId( FT_Y_ROTATION ) )
80 , m_aMFYRotation ( this, SchResId( MTR_FLD_Y_ROTATION ) )
81 , m_aFtZRotation ( this, SchResId( FT_Z_ROTATION ) )
82 , m_aMFZRotation ( this, SchResId( MTR_FLD_Z_ROTATION ) )
83 , m_aCbxPerspective ( this, SchResId( CBX_PERSPECTIVE ) )
84 , m_aMFPerspective ( this, SchResId( MTR_FLD_PERSPECTIVE ) )
85 , m_nXRotation(0)
86 , m_nYRotation(0)
87 , m_nZRotation(0)
88 , m_bAngleChangePending( false )
89 , m_bPerspectiveChangePending( false )
90 , m_rControllerLockHelper( rControllerLockHelper )
92 FreeResource();
94 double fXAngle, fYAngle, fZAngle;
95 ThreeDHelper::getRotationAngleFromDiagram( m_xSceneProperties, fXAngle, fYAngle, fZAngle );
97 fXAngle = BaseGFXHelper::Rad2Deg( fXAngle );
98 fYAngle = BaseGFXHelper::Rad2Deg( fYAngle );
99 fZAngle = BaseGFXHelper::Rad2Deg( fZAngle );
101 OSL_ENSURE( fZAngle>=-90 && fZAngle<=90, "z angle is out of valid range" );
103 lcl_SetMetricFieldLimits( m_aMFZRotation, 90 );
105 m_nXRotation = ::basegfx::fround(fXAngle*pow(10.0,m_aMFXRotation.GetDecimalDigits()));
106 m_nYRotation = ::basegfx::fround(-1.0*fYAngle*pow(10.0,m_aMFYRotation.GetDecimalDigits()));
107 m_nZRotation = ::basegfx::fround(-1.0*fZAngle*pow(10.0,m_aMFZRotation.GetDecimalDigits()));
109 lcl_shiftAngleToValidRange( m_nXRotation );
110 lcl_shiftAngleToValidRange( m_nYRotation );
111 lcl_shiftAngleToValidRange( m_nZRotation );
113 m_aMFXRotation.SetValue(m_nXRotation);
114 m_aMFYRotation.SetValue(m_nYRotation);
115 m_aMFZRotation.SetValue(m_nZRotation);
117 const sal_uLong nTimeout = 4*EDIT_UPDATEDATA_TIMEOUT;
118 Link aAngleChangedLink( LINK( this, ThreeD_SceneGeometry_TabPage, AngleChanged ));
119 Link aAngleEditedLink( LINK( this, ThreeD_SceneGeometry_TabPage, AngleEdited ));
121 m_aMFXRotation.EnableUpdateData( nTimeout );
122 m_aMFXRotation.SetUpdateDataHdl( aAngleChangedLink );
123 m_aMFXRotation.SetModifyHdl( aAngleEditedLink );
125 m_aMFYRotation.EnableUpdateData( nTimeout );
126 m_aMFYRotation.SetUpdateDataHdl( aAngleChangedLink );
127 m_aMFYRotation.SetModifyHdl( aAngleEditedLink );
129 m_aMFZRotation.EnableUpdateData( nTimeout );
130 m_aMFZRotation.SetUpdateDataHdl( aAngleChangedLink );
131 m_aMFZRotation.SetModifyHdl( aAngleEditedLink );
133 drawing::ProjectionMode aProjectionMode = drawing::ProjectionMode_PERSPECTIVE;
134 m_xSceneProperties->getPropertyValue( C2U("D3DScenePerspective")) >>= aProjectionMode;
135 m_aCbxPerspective.Check( aProjectionMode == drawing::ProjectionMode_PERSPECTIVE );
136 m_aCbxPerspective.SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveToggled ));
138 sal_Int32 nPerspectivePercentage = 20;
139 m_xSceneProperties->getPropertyValue( C2U("Perspective")) >>= nPerspectivePercentage;
140 m_aMFPerspective.SetValue( nPerspectivePercentage );
142 m_aMFPerspective.EnableUpdateData( nTimeout );
143 m_aMFPerspective.SetUpdateDataHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveChanged ) );
144 m_aMFPerspective.SetModifyHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveEdited ) );
145 m_aMFPerspective.Enable( m_aCbxPerspective.IsChecked() );
148 //RightAngledAxes
149 sal_Bool bRightAngledAxes = false;
151 uno::Reference< chart2::XDiagram > xDiagram( m_xSceneProperties, uno::UNO_QUERY );
152 if( ChartTypeHelper::isSupportingRightAngledAxes(
153 DiagramHelper::getChartTypeByIndex( xDiagram, 0 ) ) )
155 m_xSceneProperties->getPropertyValue( C2U("RightAngledAxes")) >>= bRightAngledAxes;
156 m_aCbxRightAngledAxes.SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled ));
157 m_aCbxRightAngledAxes.Check( bRightAngledAxes );
159 else
161 m_aCbxRightAngledAxes.Enable(false);
163 m_aMFPerspective.SetAccessibleName(m_aCbxPerspective.GetText());
164 m_aMFPerspective.SetAccessibleRelationLabeledBy(&m_aCbxPerspective);
167 ThreeD_SceneGeometry_TabPage::~ThreeD_SceneGeometry_TabPage()
171 void ThreeD_SceneGeometry_TabPage::commitPendingChanges()
173 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
175 if( m_bAngleChangePending )
176 applyAnglesToModel();
177 if( m_bPerspectiveChangePending )
178 applyPerspectiveToModel();
181 void ThreeD_SceneGeometry_TabPage::applyAnglesToModel()
183 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
185 double fXAngle = 0.0, fYAngle = 0.0, fZAngle = 0.0;
187 if( !m_aMFZRotation.IsEmptyFieldValue() )
188 m_nZRotation = m_aMFZRotation.GetValue();
190 fXAngle = double(m_nXRotation)/double(pow(10.0,m_aMFXRotation.GetDecimalDigits()));
191 fYAngle = double(-1.0*m_nYRotation)/double(pow(10.0,m_aMFYRotation.GetDecimalDigits()));
192 fZAngle = double(-1.0*m_nZRotation)/double(pow(10.0,m_aMFZRotation.GetDecimalDigits()));
194 fXAngle = BaseGFXHelper::Deg2Rad( fXAngle );
195 fYAngle = BaseGFXHelper::Deg2Rad( fYAngle );
196 fZAngle = BaseGFXHelper::Deg2Rad( fZAngle );
198 ThreeDHelper::setRotationAngleToDiagram( m_xSceneProperties, fXAngle, fYAngle, fZAngle );
200 m_bAngleChangePending = false;
203 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, AngleEdited)
205 m_nXRotation = m_aMFXRotation.GetValue();
206 m_nYRotation = m_aMFYRotation.GetValue();
208 m_bAngleChangePending = true;
209 return 0;
212 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, AngleChanged)
214 applyAnglesToModel();
215 return 0;
218 void ThreeD_SceneGeometry_TabPage::applyPerspectiveToModel()
220 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
222 drawing::ProjectionMode aMode = m_aCbxPerspective.IsChecked()
223 ? drawing::ProjectionMode_PERSPECTIVE
224 : drawing::ProjectionMode_PARALLEL;
228 m_xSceneProperties->setPropertyValue( C2U("D3DScenePerspective"), uno::makeAny( aMode ));
229 m_xSceneProperties->setPropertyValue( C2U("Perspective"), uno::makeAny( (sal_Int32)m_aMFPerspective.GetValue() ));
231 catch( const uno::Exception & ex )
233 ASSERT_EXCEPTION( ex );
236 m_bPerspectiveChangePending = false;
239 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveEdited)
241 m_bPerspectiveChangePending = true;
242 return 0;
245 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveChanged)
247 applyPerspectiveToModel();
248 return 0;
251 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveToggled)
253 m_aMFPerspective.Enable( m_aCbxPerspective.IsChecked() );
254 applyPerspectiveToModel();
255 return 0;
258 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled)
260 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
262 bool bEnableZ = !m_aCbxRightAngledAxes.IsChecked();
263 m_aFtZRotation.Enable( bEnableZ );
264 m_aMFZRotation.Enable( bEnableZ );
265 m_aMFZRotation.EnableEmptyFieldValue( !bEnableZ );
266 if( !bEnableZ )
268 m_nXRotation = m_aMFXRotation.GetValue();
269 m_nYRotation = m_aMFYRotation.GetValue();
270 m_nZRotation = m_aMFZRotation.GetValue();
272 m_aMFXRotation.SetValue(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nXRotation), ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes())));
273 m_aMFYRotation.SetValue(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nYRotation), ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes())));
274 m_aMFZRotation.SetEmptyFieldValue();
276 lcl_SetMetricFieldLimits( m_aMFXRotation, static_cast<sal_Int64>(ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes()));
277 lcl_SetMetricFieldLimits( m_aMFYRotation, static_cast<sal_Int64>(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()));
279 else
281 lcl_SetMetricFieldLimits( m_aMFXRotation, 180 );
282 lcl_SetMetricFieldLimits( m_aMFYRotation, 180 );
284 m_aMFXRotation.SetValue(m_nXRotation);
285 m_aMFYRotation.SetValue(m_nYRotation);
286 m_aMFZRotation.SetValue(m_nZRotation);
289 ThreeDHelper::switchRightAngledAxes( m_xSceneProperties, m_aCbxRightAngledAxes.IsChecked(), true /*bRotateLights*/ );
291 return 0;
294 //.............................................................................
295 } //namespace chart
296 //.............................................................................
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */