xref: /AOO41X/main/chart2/source/controller/dialogs/tp_3D_SceneGeometry.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_chart2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "tp_3D_SceneGeometry.hxx"
32*cdf0e10cSrcweir #include "tp_3D_SceneGeometry.hrc"
33*cdf0e10cSrcweir #include "ResId.hxx"
34*cdf0e10cSrcweir #include "NoWarningThisInCTOR.hxx"
35*cdf0e10cSrcweir #include "BaseGFXHelper.hxx"
36*cdf0e10cSrcweir #include "macros.hxx"
37*cdf0e10cSrcweir #include "DiagramHelper.hxx"
38*cdf0e10cSrcweir #include "ChartTypeHelper.hxx"
39*cdf0e10cSrcweir #include "ThreeDHelper.hxx"
40*cdf0e10cSrcweir #include <rtl/math.hxx>
41*cdf0e10cSrcweir #include <editeng/unoprnms.hxx>
42*cdf0e10cSrcweir #include <com/sun/star/drawing/ProjectionMode.hpp>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir //.............................................................................
45*cdf0e10cSrcweir namespace chart
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir //.............................................................................
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir using namespace ::com::sun::star;
50*cdf0e10cSrcweir //using namespace ::com::sun::star::chart2;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir namespace
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir void lcl_shiftAngleToValidRange( sal_Int64& rnAngleDegree )
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir     //valid range:  ]-180,180]
58*cdf0e10cSrcweir     while( rnAngleDegree<=-180 )
59*cdf0e10cSrcweir         rnAngleDegree+=360;
60*cdf0e10cSrcweir     while( rnAngleDegree>180 )
61*cdf0e10cSrcweir         rnAngleDegree-=360;
62*cdf0e10cSrcweir }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir void lcl_SetMetricFieldLimits( MetricField& rField, sal_Int64 nLimit )
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir     rField.SetMin(-1*nLimit);
67*cdf0e10cSrcweir     rField.SetFirst(-1*nLimit);
68*cdf0e10cSrcweir     rField.SetMax(nLimit);
69*cdf0e10cSrcweir     rField.SetLast(nLimit);
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir ThreeD_SceneGeometry_TabPage::ThreeD_SceneGeometry_TabPage( Window* pWindow
74*cdf0e10cSrcweir                 , const uno::Reference< beans::XPropertySet > & xSceneProperties
75*cdf0e10cSrcweir                 , ControllerLockHelper & rControllerLockHelper )
76*cdf0e10cSrcweir                 : TabPage 	    ( pWindow, SchResId( TP_3D_SCENEGEOMETRY ) )
77*cdf0e10cSrcweir                 , m_xSceneProperties( xSceneProperties )
78*cdf0e10cSrcweir                 , m_aCbxRightAngledAxes( this, SchResId( CBX_RIGHT_ANGLED_AXES ) )
79*cdf0e10cSrcweir                 , m_aFtXRotation	( this, SchResId( FT_X_ROTATION ) )
80*cdf0e10cSrcweir 				, m_aMFXRotation	( this, SchResId( MTR_FLD_X_ROTATION ) )
81*cdf0e10cSrcweir 				, m_aFtYRotation	( this, SchResId( FT_Y_ROTATION ) )
82*cdf0e10cSrcweir 				, m_aMFYRotation	( this, SchResId( MTR_FLD_Y_ROTATION ) )
83*cdf0e10cSrcweir                 , m_aFtZRotation	( this, SchResId( FT_Z_ROTATION ) )
84*cdf0e10cSrcweir                 , m_aMFZRotation    ( this, SchResId( MTR_FLD_Z_ROTATION ) )
85*cdf0e10cSrcweir                 , m_aCbxPerspective ( this, SchResId( CBX_PERSPECTIVE ) )
86*cdf0e10cSrcweir                 , m_aMFPerspective  ( this, SchResId( MTR_FLD_PERSPECTIVE ) )
87*cdf0e10cSrcweir                 , m_nXRotation(0)
88*cdf0e10cSrcweir                 , m_nYRotation(0)
89*cdf0e10cSrcweir                 , m_nZRotation(0)
90*cdf0e10cSrcweir                 , m_bAngleChangePending( false )
91*cdf0e10cSrcweir                 , m_bPerspectiveChangePending( false )
92*cdf0e10cSrcweir                 , m_rControllerLockHelper( rControllerLockHelper )
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir 	FreeResource();
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir     double fXAngle, fYAngle, fZAngle;
97*cdf0e10cSrcweir     ThreeDHelper::getRotationAngleFromDiagram( m_xSceneProperties, fXAngle, fYAngle, fZAngle );
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir     fXAngle = BaseGFXHelper::Rad2Deg( fXAngle );
100*cdf0e10cSrcweir     fYAngle = BaseGFXHelper::Rad2Deg( fYAngle );
101*cdf0e10cSrcweir     fZAngle = BaseGFXHelper::Rad2Deg( fZAngle );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     DBG_ASSERT( fZAngle>=-90 && fZAngle<=90, "z angle is out of valid range" );
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     lcl_SetMetricFieldLimits( m_aMFZRotation, 90 );
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     m_nXRotation = ::basegfx::fround(fXAngle*pow(10.0,m_aMFXRotation.GetDecimalDigits()));
108*cdf0e10cSrcweir     m_nYRotation = ::basegfx::fround(-1.0*fYAngle*pow(10.0,m_aMFYRotation.GetDecimalDigits()));
109*cdf0e10cSrcweir     m_nZRotation = ::basegfx::fround(-1.0*fZAngle*pow(10.0,m_aMFZRotation.GetDecimalDigits()));
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     lcl_shiftAngleToValidRange( m_nXRotation );
112*cdf0e10cSrcweir     lcl_shiftAngleToValidRange( m_nYRotation );
113*cdf0e10cSrcweir     lcl_shiftAngleToValidRange( m_nZRotation );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     m_aMFXRotation.SetValue(m_nXRotation);
116*cdf0e10cSrcweir 	m_aMFYRotation.SetValue(m_nYRotation);
117*cdf0e10cSrcweir     m_aMFZRotation.SetValue(m_nZRotation);
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     const sal_uLong nTimeout = 4*EDIT_UPDATEDATA_TIMEOUT;
120*cdf0e10cSrcweir     Link aAngleChangedLink( LINK( this, ThreeD_SceneGeometry_TabPage, AngleChanged ));
121*cdf0e10cSrcweir     Link aAngleEditedLink( LINK( this, ThreeD_SceneGeometry_TabPage, AngleEdited ));
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir     m_aMFXRotation.EnableUpdateData( nTimeout );
124*cdf0e10cSrcweir     m_aMFXRotation.SetUpdateDataHdl( aAngleChangedLink );
125*cdf0e10cSrcweir     m_aMFXRotation.SetModifyHdl( aAngleEditedLink );
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     m_aMFYRotation.EnableUpdateData( nTimeout );
128*cdf0e10cSrcweir     m_aMFYRotation.SetUpdateDataHdl( aAngleChangedLink );
129*cdf0e10cSrcweir     m_aMFYRotation.SetModifyHdl( aAngleEditedLink );
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     m_aMFZRotation.EnableUpdateData( nTimeout );
132*cdf0e10cSrcweir     m_aMFZRotation.SetUpdateDataHdl( aAngleChangedLink );
133*cdf0e10cSrcweir     m_aMFZRotation.SetModifyHdl( aAngleEditedLink );
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     drawing::ProjectionMode aProjectionMode = drawing::ProjectionMode_PERSPECTIVE;
136*cdf0e10cSrcweir     m_xSceneProperties->getPropertyValue( C2U("D3DScenePerspective")) >>= aProjectionMode;
137*cdf0e10cSrcweir     m_aCbxPerspective.Check( aProjectionMode == drawing::ProjectionMode_PERSPECTIVE );
138*cdf0e10cSrcweir     m_aCbxPerspective.SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveToggled ));
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     sal_Int32 nPerspectivePercentage = 20;
141*cdf0e10cSrcweir     m_xSceneProperties->getPropertyValue( C2U("Perspective")) >>= nPerspectivePercentage;
142*cdf0e10cSrcweir     m_aMFPerspective.SetValue( nPerspectivePercentage );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir     m_aMFPerspective.EnableUpdateData( nTimeout );
145*cdf0e10cSrcweir     m_aMFPerspective.SetUpdateDataHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveChanged ) );
146*cdf0e10cSrcweir     m_aMFPerspective.SetModifyHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveEdited ) );
147*cdf0e10cSrcweir     m_aMFPerspective.Enable( m_aCbxPerspective.IsChecked() );
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     //RightAngledAxes
151*cdf0e10cSrcweir     sal_Bool bRightAngledAxes = false;
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     uno::Reference< chart2::XDiagram > xDiagram( m_xSceneProperties, uno::UNO_QUERY );
154*cdf0e10cSrcweir     if( ChartTypeHelper::isSupportingRightAngledAxes(
155*cdf0e10cSrcweir             DiagramHelper::getChartTypeByIndex( xDiagram, 0 ) ) )
156*cdf0e10cSrcweir     {
157*cdf0e10cSrcweir         m_xSceneProperties->getPropertyValue( C2U("RightAngledAxes")) >>= bRightAngledAxes;
158*cdf0e10cSrcweir         m_aCbxRightAngledAxes.SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled ));
159*cdf0e10cSrcweir         m_aCbxRightAngledAxes.Check( bRightAngledAxes );
160*cdf0e10cSrcweir     }
161*cdf0e10cSrcweir     else
162*cdf0e10cSrcweir     {
163*cdf0e10cSrcweir         m_aCbxRightAngledAxes.Enable(false);
164*cdf0e10cSrcweir     }
165*cdf0e10cSrcweir 	m_aMFPerspective.SetAccessibleName(m_aCbxPerspective.GetText());
166*cdf0e10cSrcweir 	m_aMFPerspective.SetAccessibleRelationLabeledBy(&m_aCbxPerspective);
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir ThreeD_SceneGeometry_TabPage::~ThreeD_SceneGeometry_TabPage()
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir void ThreeD_SceneGeometry_TabPage::commitPendingChanges()
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     if( m_bAngleChangePending )
178*cdf0e10cSrcweir         applyAnglesToModel();
179*cdf0e10cSrcweir     if( m_bPerspectiveChangePending )
180*cdf0e10cSrcweir         applyPerspectiveToModel();
181*cdf0e10cSrcweir }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir void ThreeD_SceneGeometry_TabPage::applyAnglesToModel()
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir     double fXAngle = 0.0, fYAngle = 0.0, fZAngle = 0.0;
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     if( !m_aMFZRotation.IsEmptyFieldValue() )
190*cdf0e10cSrcweir         m_nZRotation = m_aMFZRotation.GetValue();
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     fXAngle = double(m_nXRotation)/double(pow(10.0,m_aMFXRotation.GetDecimalDigits()));
193*cdf0e10cSrcweir     fYAngle = double(-1.0*m_nYRotation)/double(pow(10.0,m_aMFYRotation.GetDecimalDigits()));
194*cdf0e10cSrcweir     fZAngle = double(-1.0*m_nZRotation)/double(pow(10.0,m_aMFZRotation.GetDecimalDigits()));
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     fXAngle = BaseGFXHelper::Deg2Rad( fXAngle );
197*cdf0e10cSrcweir     fYAngle = BaseGFXHelper::Deg2Rad( fYAngle );
198*cdf0e10cSrcweir     fZAngle = BaseGFXHelper::Deg2Rad( fZAngle );
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir     ThreeDHelper::setRotationAngleToDiagram( m_xSceneProperties, fXAngle, fYAngle, fZAngle );
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir     m_bAngleChangePending = false;
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir IMPL_LINK( ThreeD_SceneGeometry_TabPage, AngleEdited, void*, EMPTYARG )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir     m_nXRotation = m_aMFXRotation.GetValue();
208*cdf0e10cSrcweir     m_nYRotation = m_aMFYRotation.GetValue();
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir     m_bAngleChangePending = true;
211*cdf0e10cSrcweir     return 0;
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir IMPL_LINK( ThreeD_SceneGeometry_TabPage, AngleChanged, void*, EMPTYARG )
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir     applyAnglesToModel();
217*cdf0e10cSrcweir     return 0;
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir void ThreeD_SceneGeometry_TabPage::applyPerspectiveToModel()
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir     drawing::ProjectionMode aMode = m_aCbxPerspective.IsChecked()
225*cdf0e10cSrcweir         ? drawing::ProjectionMode_PERSPECTIVE
226*cdf0e10cSrcweir         : drawing::ProjectionMode_PARALLEL;
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir     try
229*cdf0e10cSrcweir     {
230*cdf0e10cSrcweir         m_xSceneProperties->setPropertyValue( C2U("D3DScenePerspective"), uno::makeAny( aMode ));
231*cdf0e10cSrcweir         m_xSceneProperties->setPropertyValue( C2U("Perspective"), uno::makeAny( (sal_Int32)m_aMFPerspective.GetValue() ));
232*cdf0e10cSrcweir     }
233*cdf0e10cSrcweir     catch( const uno::Exception & ex )
234*cdf0e10cSrcweir     {
235*cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
236*cdf0e10cSrcweir     }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir     m_bPerspectiveChangePending = false;
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir IMPL_LINK( ThreeD_SceneGeometry_TabPage, PerspectiveEdited, void*, EMPTYARG )
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir     m_bPerspectiveChangePending = true;
244*cdf0e10cSrcweir     return 0;
245*cdf0e10cSrcweir }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir IMPL_LINK( ThreeD_SceneGeometry_TabPage, PerspectiveChanged, void*, EMPTYARG )
248*cdf0e10cSrcweir {
249*cdf0e10cSrcweir     applyPerspectiveToModel();
250*cdf0e10cSrcweir     return 0;
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir IMPL_LINK( ThreeD_SceneGeometry_TabPage, PerspectiveToggled, void*, EMPTYARG )
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir     m_aMFPerspective.Enable( m_aCbxPerspective.IsChecked() );
256*cdf0e10cSrcweir     applyPerspectiveToModel();
257*cdf0e10cSrcweir     return 0;
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir IMPL_LINK( ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled, void*, EMPTYARG )
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     bool bEnableZ = !m_aCbxRightAngledAxes.IsChecked();
265*cdf0e10cSrcweir     m_aFtZRotation.Enable( bEnableZ );
266*cdf0e10cSrcweir     m_aMFZRotation.Enable( bEnableZ );
267*cdf0e10cSrcweir     m_aMFZRotation.EnableEmptyFieldValue( !bEnableZ );
268*cdf0e10cSrcweir     if( !bEnableZ )
269*cdf0e10cSrcweir     {
270*cdf0e10cSrcweir         m_nXRotation = m_aMFXRotation.GetValue();
271*cdf0e10cSrcweir         m_nYRotation = m_aMFYRotation.GetValue();
272*cdf0e10cSrcweir         m_nZRotation = m_aMFZRotation.GetValue();
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir         m_aMFXRotation.SetValue(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nXRotation), ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes())));
275*cdf0e10cSrcweir         m_aMFYRotation.SetValue(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nYRotation), ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes())));
276*cdf0e10cSrcweir         m_aMFZRotation.SetEmptyFieldValue();
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir         lcl_SetMetricFieldLimits( m_aMFXRotation, static_cast<sal_Int64>(ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes()));
279*cdf0e10cSrcweir         lcl_SetMetricFieldLimits( m_aMFYRotation, static_cast<sal_Int64>(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()));
280*cdf0e10cSrcweir     }
281*cdf0e10cSrcweir     else
282*cdf0e10cSrcweir     {
283*cdf0e10cSrcweir         lcl_SetMetricFieldLimits( m_aMFXRotation, 180 );
284*cdf0e10cSrcweir         lcl_SetMetricFieldLimits( m_aMFYRotation, 180 );
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir         m_aMFXRotation.SetValue(m_nXRotation);
287*cdf0e10cSrcweir         m_aMFYRotation.SetValue(m_nYRotation);
288*cdf0e10cSrcweir         m_aMFZRotation.SetValue(m_nZRotation);
289*cdf0e10cSrcweir     }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     ThreeDHelper::switchRightAngledAxes( m_xSceneProperties, m_aCbxRightAngledAxes.IsChecked(), true /*bRotateLights*/ );
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir     return 0;
294*cdf0e10cSrcweir }
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir //.............................................................................
297*cdf0e10cSrcweir } //namespace chart
298*cdf0e10cSrcweir //.............................................................................
299