1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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>
34 using namespace ::com::sun::star
;
39 void lcl_shiftAngleToValidRange( sal_Int64
& rnAngleDegree
)
41 //valid range: ]-180,180]
42 while( rnAngleDegree
<=-180 )
44 while( rnAngleDegree
>180 )
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
)
61 , "tp_3DSceneGeometry"
62 , "modules/schart/ui/tp_3D_SceneGeometry.ui")
63 , m_xSceneProperties( xSceneProperties
)
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
= BaseGFXHelper::Rad2Deg( fXAngle
);
83 fYAngle
= BaseGFXHelper::Rad2Deg( fYAngle
);
84 fZAngle
= BaseGFXHelper::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
<> aAngleChangedLink( LINK( this, ThreeD_SceneGeometry_TabPage
, AngleChanged
));
104 Link
<> 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() );
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
);
144 m_pCbxRightAngledAxes
->Enable(false);
146 m_pMFPerspective
->SetAccessibleName(m_pCbxPerspective
->GetText());
147 m_pMFPerspective
->SetAccessibleRelationLabeledBy(m_pCbxPerspective
);
150 ThreeD_SceneGeometry_TabPage::~ThreeD_SceneGeometry_TabPage()
155 void ThreeD_SceneGeometry_TabPage::dispose()
157 m_pCbxRightAngledAxes
.clear();
158 m_pMFXRotation
.clear();
159 m_pMFYRotation
.clear();
160 m_pFtZRotation
.clear();
161 m_pMFZRotation
.clear();
162 m_pCbxPerspective
.clear();
163 m_pMFPerspective
.clear();
168 void ThreeD_SceneGeometry_TabPage::commitPendingChanges()
170 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
172 if( m_bAngleChangePending
)
173 applyAnglesToModel();
174 if( m_bPerspectiveChangePending
)
175 applyPerspectiveToModel();
178 void ThreeD_SceneGeometry_TabPage::applyAnglesToModel()
180 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
182 double fXAngle
= 0.0, fYAngle
= 0.0, fZAngle
= 0.0;
184 if( !m_pMFZRotation
->IsEmptyFieldValue() )
185 m_nZRotation
= m_pMFZRotation
->GetValue();
187 fXAngle
= double(m_nXRotation
)/double(pow(10.0,m_pMFXRotation
->GetDecimalDigits()));
188 fYAngle
= double(-1.0*m_nYRotation
)/double(pow(10.0,m_pMFYRotation
->GetDecimalDigits()));
189 fZAngle
= double(-1.0*m_nZRotation
)/double(pow(10.0,m_pMFZRotation
->GetDecimalDigits()));
191 fXAngle
= BaseGFXHelper::Deg2Rad( fXAngle
);
192 fYAngle
= BaseGFXHelper::Deg2Rad( fYAngle
);
193 fZAngle
= BaseGFXHelper::Deg2Rad( fZAngle
);
195 ThreeDHelper::setRotationAngleToDiagram( m_xSceneProperties
, fXAngle
, fYAngle
, fZAngle
);
197 m_bAngleChangePending
= false;
200 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage
, AngleEdited
)
202 m_nXRotation
= m_pMFXRotation
->GetValue();
203 m_nYRotation
= m_pMFYRotation
->GetValue();
205 m_bAngleChangePending
= true;
209 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage
, AngleChanged
)
211 applyAnglesToModel();
215 void ThreeD_SceneGeometry_TabPage::applyPerspectiveToModel()
217 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
219 drawing::ProjectionMode aMode
= m_pCbxPerspective
->IsChecked()
220 ? drawing::ProjectionMode_PERSPECTIVE
221 : drawing::ProjectionMode_PARALLEL
;
225 m_xSceneProperties
->setPropertyValue( "D3DScenePerspective" , uno::makeAny( aMode
));
226 m_xSceneProperties
->setPropertyValue( "Perspective" , uno::makeAny( (sal_Int32
)m_pMFPerspective
->GetValue() ));
228 catch( const uno::Exception
& ex
)
230 ASSERT_EXCEPTION( ex
);
233 m_bPerspectiveChangePending
= false;
236 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage
, PerspectiveEdited
)
238 m_bPerspectiveChangePending
= true;
242 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage
, PerspectiveChanged
)
244 applyPerspectiveToModel();
248 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage
, PerspectiveToggled
)
250 m_pMFPerspective
->Enable( m_pCbxPerspective
->IsChecked() );
251 applyPerspectiveToModel();
255 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage
, RightAngledAxesToggled
)
257 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
259 bool bEnableZ
= !m_pCbxRightAngledAxes
->IsChecked();
260 m_pFtZRotation
->Enable( bEnableZ
);
261 m_pMFZRotation
->Enable( bEnableZ
);
262 m_pMFZRotation
->EnableEmptyFieldValue( !bEnableZ
);
265 m_nXRotation
= m_pMFXRotation
->GetValue();
266 m_nYRotation
= m_pMFYRotation
->GetValue();
267 m_nZRotation
= m_pMFZRotation
->GetValue();
269 m_pMFXRotation
->SetValue(static_cast<sal_Int64
>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nXRotation
), ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes())));
270 m_pMFYRotation
->SetValue(static_cast<sal_Int64
>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nYRotation
), ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes())));
271 m_pMFZRotation
->SetEmptyFieldValue();
273 lcl_SetMetricFieldLimits( *m_pMFXRotation
, static_cast<sal_Int64
>(ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes()));
274 lcl_SetMetricFieldLimits( *m_pMFYRotation
, static_cast<sal_Int64
>(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()));
278 lcl_SetMetricFieldLimits( *m_pMFXRotation
, 180 );
279 lcl_SetMetricFieldLimits( *m_pMFYRotation
, 180 );
281 m_pMFXRotation
->SetValue(m_nXRotation
);
282 m_pMFYRotation
->SetValue(m_nYRotation
);
283 m_pMFZRotation
->SetValue(m_nZRotation
);
286 ThreeDHelper::switchRightAngledAxes( m_xSceneProperties
, m_pCbxRightAngledAxes
->IsChecked(), true /*bRotateLights*/ );
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */