1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tp_3D_SceneGeometry.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_chart2.hxx"
35 #include "tp_3D_SceneGeometry.hxx"
36 #include "tp_3D_SceneGeometry.hrc"
38 #include "NoWarningThisInCTOR.hxx"
39 #include "BaseGFXHelper.hxx"
41 #include "DiagramHelper.hxx"
42 #include "ChartTypeHelper.hxx"
43 #include "ThreeDHelper.hxx"
44 #include <rtl/math.hxx>
45 #include <svx/unoprnms.hxx>
46 #include <com/sun/star/drawing/ProjectionMode.hpp>
48 //.............................................................................
51 //.............................................................................
53 using namespace ::com::sun::star
;
54 //using namespace ::com::sun::star::chart2;
59 void lcl_shiftAngleToValidRange( sal_Int64
& rnAngleDegree
)
61 //valid range: ]-180,180]
62 while( rnAngleDegree
<=-180 )
64 while( rnAngleDegree
>180 )
68 void lcl_SetMetricFieldLimits( MetricField
& rField
, sal_Int64 nLimit
)
70 rField
.SetMin(-1*nLimit
);
71 rField
.SetFirst(-1*nLimit
);
72 rField
.SetMax(nLimit
);
73 rField
.SetLast(nLimit
);
77 ThreeD_SceneGeometry_TabPage::ThreeD_SceneGeometry_TabPage( Window
* pWindow
78 , const uno::Reference
< beans::XPropertySet
> & xSceneProperties
79 , ControllerLockHelper
& rControllerLockHelper
)
80 : TabPage ( pWindow
, SchResId( TP_3D_SCENEGEOMETRY
) )
81 , m_xSceneProperties( xSceneProperties
)
82 , m_aCbxRightAngledAxes( this, SchResId( CBX_RIGHT_ANGLED_AXES
) )
83 , m_aFtXRotation ( this, SchResId( FT_X_ROTATION
) )
84 , m_aMFXRotation ( this, SchResId( MTR_FLD_X_ROTATION
) )
85 , m_aFtYRotation ( this, SchResId( FT_Y_ROTATION
) )
86 , m_aMFYRotation ( this, SchResId( MTR_FLD_Y_ROTATION
) )
87 , m_aFtZRotation ( this, SchResId( FT_Z_ROTATION
) )
88 , m_aMFZRotation ( this, SchResId( MTR_FLD_Z_ROTATION
) )
89 , m_aCbxPerspective ( this, SchResId( CBX_PERSPECTIVE
) )
90 , m_aMFPerspective ( this, SchResId( MTR_FLD_PERSPECTIVE
) )
94 , m_bAngleChangePending( false )
95 , m_bPerspectiveChangePending( false )
96 , m_rControllerLockHelper( rControllerLockHelper
)
100 double fXAngle
, fYAngle
, fZAngle
;
101 ThreeDHelper::getRotationAngleFromDiagram( m_xSceneProperties
, fXAngle
, fYAngle
, fZAngle
);
103 fXAngle
= BaseGFXHelper::Rad2Deg( fXAngle
);
104 fYAngle
= BaseGFXHelper::Rad2Deg( fYAngle
);
105 fZAngle
= BaseGFXHelper::Rad2Deg( fZAngle
);
107 DBG_ASSERT( fZAngle
>=-90 && fZAngle
<=90, "z angle is out of valid range" );
109 lcl_SetMetricFieldLimits( m_aMFZRotation
, 90 );
111 m_nXRotation
= ::basegfx::fround(fXAngle
*pow(10.0,m_aMFXRotation
.GetDecimalDigits()));
112 m_nYRotation
= ::basegfx::fround(-1.0*fYAngle
*pow(10.0,m_aMFYRotation
.GetDecimalDigits()));
113 m_nZRotation
= ::basegfx::fround(-1.0*fZAngle
*pow(10.0,m_aMFZRotation
.GetDecimalDigits()));
115 lcl_shiftAngleToValidRange( m_nXRotation
);
116 lcl_shiftAngleToValidRange( m_nYRotation
);
117 lcl_shiftAngleToValidRange( m_nZRotation
);
119 m_aMFXRotation
.SetValue(m_nXRotation
);
120 m_aMFYRotation
.SetValue(m_nYRotation
);
121 m_aMFZRotation
.SetValue(m_nZRotation
);
123 const ULONG nTimeout
= 4*EDIT_UPDATEDATA_TIMEOUT
;
124 Link
aAngleChangedLink( LINK( this, ThreeD_SceneGeometry_TabPage
, AngleChanged
));
125 Link
aAngleEditedLink( LINK( this, ThreeD_SceneGeometry_TabPage
, AngleEdited
));
127 m_aMFXRotation
.EnableUpdateData( nTimeout
);
128 m_aMFXRotation
.SetUpdateDataHdl( aAngleChangedLink
);
129 m_aMFXRotation
.SetModifyHdl( aAngleEditedLink
);
131 m_aMFYRotation
.EnableUpdateData( nTimeout
);
132 m_aMFYRotation
.SetUpdateDataHdl( aAngleChangedLink
);
133 m_aMFYRotation
.SetModifyHdl( aAngleEditedLink
);
135 m_aMFZRotation
.EnableUpdateData( nTimeout
);
136 m_aMFZRotation
.SetUpdateDataHdl( aAngleChangedLink
);
137 m_aMFZRotation
.SetModifyHdl( aAngleEditedLink
);
139 drawing::ProjectionMode aProjectionMode
= drawing::ProjectionMode_PERSPECTIVE
;
140 m_xSceneProperties
->getPropertyValue( C2U("D3DScenePerspective")) >>= aProjectionMode
;
141 m_aCbxPerspective
.Check( aProjectionMode
== drawing::ProjectionMode_PERSPECTIVE
);
142 m_aCbxPerspective
.SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage
, PerspectiveToggled
));
144 sal_Int32 nPerspectivePercentage
= 20;
145 m_xSceneProperties
->getPropertyValue( C2U("Perspective")) >>= nPerspectivePercentage
;
146 m_aMFPerspective
.SetValue( nPerspectivePercentage
);
148 m_aMFPerspective
.EnableUpdateData( nTimeout
);
149 m_aMFPerspective
.SetUpdateDataHdl( LINK( this, ThreeD_SceneGeometry_TabPage
, PerspectiveChanged
) );
150 m_aMFPerspective
.SetModifyHdl( LINK( this, ThreeD_SceneGeometry_TabPage
, PerspectiveEdited
) );
151 m_aMFPerspective
.Enable( m_aCbxPerspective
.IsChecked() );
155 sal_Bool bRightAngledAxes
= false;
157 uno::Reference
< chart2::XDiagram
> xDiagram( m_xSceneProperties
, uno::UNO_QUERY
);
158 if( ChartTypeHelper::isSupportingRightAngledAxes(
159 DiagramHelper::getChartTypeByIndex( xDiagram
, 0 ) ) )
161 m_xSceneProperties
->getPropertyValue( C2U("RightAngledAxes")) >>= bRightAngledAxes
;
162 m_aCbxRightAngledAxes
.SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage
, RightAngledAxesToggled
));
163 m_aCbxRightAngledAxes
.Check( bRightAngledAxes
);
167 m_aCbxRightAngledAxes
.Enable(false);
171 ThreeD_SceneGeometry_TabPage::~ThreeD_SceneGeometry_TabPage()
175 void ThreeD_SceneGeometry_TabPage::commitPendingChanges()
177 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
179 if( m_bAngleChangePending
)
180 applyAnglesToModel();
181 if( m_bPerspectiveChangePending
)
182 applyPerspectiveToModel();
185 void ThreeD_SceneGeometry_TabPage::applyAnglesToModel()
187 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
189 double fXAngle
= 0.0, fYAngle
= 0.0, fZAngle
= 0.0;
191 if( !m_aMFZRotation
.IsEmptyFieldValue() )
192 m_nZRotation
= m_aMFZRotation
.GetValue();
194 fXAngle
= double(m_nXRotation
)/double(pow(10.0,m_aMFXRotation
.GetDecimalDigits()));
195 fYAngle
= double(-1.0*m_nYRotation
)/double(pow(10.0,m_aMFYRotation
.GetDecimalDigits()));
196 fZAngle
= double(-1.0*m_nZRotation
)/double(pow(10.0,m_aMFZRotation
.GetDecimalDigits()));
198 fXAngle
= BaseGFXHelper::Deg2Rad( fXAngle
);
199 fYAngle
= BaseGFXHelper::Deg2Rad( fYAngle
);
200 fZAngle
= BaseGFXHelper::Deg2Rad( fZAngle
);
202 ThreeDHelper::setRotationAngleToDiagram( m_xSceneProperties
, fXAngle
, fYAngle
, fZAngle
);
204 m_bAngleChangePending
= false;
207 IMPL_LINK( ThreeD_SceneGeometry_TabPage
, AngleEdited
, void*, EMPTYARG
)
209 m_nXRotation
= m_aMFXRotation
.GetValue();
210 m_nYRotation
= m_aMFYRotation
.GetValue();
212 m_bAngleChangePending
= true;
216 IMPL_LINK( ThreeD_SceneGeometry_TabPage
, AngleChanged
, void*, EMPTYARG
)
218 applyAnglesToModel();
222 void ThreeD_SceneGeometry_TabPage::applyPerspectiveToModel()
224 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
226 drawing::ProjectionMode aMode
= m_aCbxPerspective
.IsChecked()
227 ? drawing::ProjectionMode_PERSPECTIVE
228 : drawing::ProjectionMode_PARALLEL
;
232 m_xSceneProperties
->setPropertyValue( C2U("D3DScenePerspective"), uno::makeAny( aMode
));
233 m_xSceneProperties
->setPropertyValue( C2U("Perspective"), uno::makeAny( (sal_Int32
)m_aMFPerspective
.GetValue() ));
235 catch( const uno::Exception
& ex
)
237 ASSERT_EXCEPTION( ex
);
240 m_bPerspectiveChangePending
= false;
243 IMPL_LINK( ThreeD_SceneGeometry_TabPage
, PerspectiveEdited
, void*, EMPTYARG
)
245 m_bPerspectiveChangePending
= true;
249 IMPL_LINK( ThreeD_SceneGeometry_TabPage
, PerspectiveChanged
, void*, EMPTYARG
)
251 applyPerspectiveToModel();
255 IMPL_LINK( ThreeD_SceneGeometry_TabPage
, PerspectiveToggled
, void*, EMPTYARG
)
257 m_aMFPerspective
.Enable( m_aCbxPerspective
.IsChecked() );
258 applyPerspectiveToModel();
262 IMPL_LINK( ThreeD_SceneGeometry_TabPage
, RightAngledAxesToggled
, void*, EMPTYARG
)
264 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
266 bool bEnableZ
= !m_aCbxRightAngledAxes
.IsChecked();
267 m_aFtZRotation
.Enable( bEnableZ
);
268 m_aMFZRotation
.Enable( bEnableZ
);
269 m_aMFZRotation
.EnableEmptyFieldValue( !bEnableZ
);
272 m_nXRotation
= m_aMFXRotation
.GetValue();
273 m_nYRotation
= m_aMFYRotation
.GetValue();
274 m_nZRotation
= m_aMFZRotation
.GetValue();
276 m_aMFXRotation
.SetValue(static_cast<sal_Int64
>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nXRotation
), ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes())));
277 m_aMFYRotation
.SetValue(static_cast<sal_Int64
>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nYRotation
), ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes())));
278 m_aMFZRotation
.SetEmptyFieldValue();
280 lcl_SetMetricFieldLimits( m_aMFXRotation
, static_cast<sal_Int64
>(ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes()));
281 lcl_SetMetricFieldLimits( m_aMFYRotation
, static_cast<sal_Int64
>(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()));
285 lcl_SetMetricFieldLimits( m_aMFXRotation
, 180 );
286 lcl_SetMetricFieldLimits( m_aMFYRotation
, 180 );
288 m_aMFXRotation
.SetValue(m_nXRotation
);
289 m_aMFYRotation
.SetValue(m_nYRotation
);
290 m_aMFZRotation
.SetValue(m_nZRotation
);
293 ThreeDHelper::switchRightAngledAxes( m_xSceneProperties
, m_aCbxRightAngledAxes
.IsChecked(), true /*bRotateLights*/ );
298 //.............................................................................
300 //.............................................................................