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 <Diagram.hxx>
23 #include <ChartType.hxx>
24 #include <ChartTypeHelper.hxx>
25 #include <ThreeDHelper.hxx>
26 #include <ControllerLockGuard.hxx>
27 #include <com/sun/star/drawing/ProjectionMode.hpp>
28 #include <comphelper/diagnose_ex.hxx>
29 #include <tools/helpers.hxx>
31 #include <vcl/svapp.hxx>
36 using namespace ::com::sun::star
;
41 void lcl_SetMetricFieldLimits(weld::MetricSpinButton
& rField
, sal_Int64 nLimit
)
43 rField
.set_range(-1*nLimit
, nLimit
, FieldUnit::DEGREE
);
48 ThreeD_SceneGeometry_TabPage::ThreeD_SceneGeometry_TabPage(weld::Container
* pParent
,
49 rtl::Reference
< ::chart::Diagram
> xDiagram
,
50 ControllerLockHelper
& rControllerLockHelper
)
51 : m_xDiagram(std::move( xDiagram
))
52 , m_aAngleTimer("chart2 ThreeD_SceneGeometry_TabPage m_aAngleTimer")
53 , m_aPerspectiveTimer("chart2 ThreeD_SceneGeometry_TabPage m_aPerspectiveTimer")
57 , m_bAngleChangePending( false )
58 , m_bPerspectiveChangePending( false )
59 , m_rControllerLockHelper( rControllerLockHelper
)
60 , m_xBuilder(Application::CreateBuilder(pParent
, u
"modules/schart/ui/tp_3D_SceneGeometry.ui"_ustr
))
61 , m_xContainer(m_xBuilder
->weld_container(u
"tp_3DSceneGeometry"_ustr
))
62 , m_xCbxRightAngledAxes(m_xBuilder
->weld_check_button(u
"CBX_RIGHT_ANGLED_AXES"_ustr
))
63 , m_xMFXRotation(m_xBuilder
->weld_metric_spin_button(u
"MTR_FLD_X_ROTATION"_ustr
, FieldUnit::DEGREE
))
64 , m_xMFYRotation(m_xBuilder
->weld_metric_spin_button(u
"MTR_FLD_Y_ROTATION"_ustr
, FieldUnit::DEGREE
))
65 , m_xFtZRotation(m_xBuilder
->weld_label(u
"FT_Z_ROTATION"_ustr
))
66 , m_xMFZRotation(m_xBuilder
->weld_metric_spin_button(u
"MTR_FLD_Z_ROTATION"_ustr
, FieldUnit::DEGREE
))
67 , m_xCbxPerspective(m_xBuilder
->weld_check_button(u
"CBX_PERSPECTIVE"_ustr
))
68 , m_xMFPerspective(m_xBuilder
->weld_metric_spin_button(u
"MTR_FLD_PERSPECTIVE"_ustr
, FieldUnit::PERCENT
))
70 double fXAngle
, fYAngle
, fZAngle
;
71 m_xDiagram
->getRotationAngle( fXAngle
, fYAngle
, fZAngle
);
73 fXAngle
= basegfx::rad2deg(fXAngle
);
74 fYAngle
= basegfx::rad2deg(fYAngle
);
75 fZAngle
= basegfx::rad2deg(fZAngle
);
77 OSL_ENSURE( fZAngle
>=-90 && fZAngle
<=90, "z angle is out of valid range" );
79 lcl_SetMetricFieldLimits( *m_xMFZRotation
, 90 );
81 m_nXRotation
= NormAngle180(
82 ::basegfx::fround(fXAngle
* pow(10.0, m_xMFXRotation
->get_digits())));
83 m_nYRotation
= NormAngle180(
84 ::basegfx::fround(-1.0 * fYAngle
* pow(10.0, m_xMFYRotation
->get_digits())));
85 m_nZRotation
= NormAngle180(
86 ::basegfx::fround(-1.0 * fZAngle
* pow(10.0, m_xMFZRotation
->get_digits())));
88 m_xMFXRotation
->set_value(m_nXRotation
, FieldUnit::DEGREE
);
89 m_xMFYRotation
->set_value(m_nYRotation
, FieldUnit::DEGREE
);
90 m_xMFZRotation
->set_value(m_nZRotation
, FieldUnit::DEGREE
);
92 const int nTimeout
= 4*EDIT_UPDATEDATA_TIMEOUT
;
93 m_aAngleTimer
.SetTimeout(nTimeout
);
94 m_aAngleTimer
.SetInvokeHandler( LINK( this, ThreeD_SceneGeometry_TabPage
, AngleChanged
) );
96 Link
<weld::MetricSpinButton
&,void> aAngleEditedLink( LINK( this, ThreeD_SceneGeometry_TabPage
, AngleEdited
));
97 m_xMFXRotation
->connect_value_changed( aAngleEditedLink
);
98 m_xMFYRotation
->connect_value_changed( aAngleEditedLink
);
99 m_xMFZRotation
->connect_value_changed( aAngleEditedLink
);
101 drawing::ProjectionMode aProjectionMode
= drawing::ProjectionMode_PERSPECTIVE
;
102 m_xDiagram
->getPropertyValue( u
"D3DScenePerspective"_ustr
) >>= aProjectionMode
;
103 m_xCbxPerspective
->set_active( aProjectionMode
== drawing::ProjectionMode_PERSPECTIVE
);
104 m_xCbxPerspective
->connect_toggled( LINK( this, ThreeD_SceneGeometry_TabPage
, PerspectiveToggled
));
106 sal_Int32 nPerspectivePercentage
= 20;
107 m_xDiagram
->getPropertyValue( u
"Perspective"_ustr
) >>= nPerspectivePercentage
;
108 m_xMFPerspective
->set_value(nPerspectivePercentage
, FieldUnit::PERCENT
);
110 m_aPerspectiveTimer
.SetTimeout(nTimeout
);
111 m_aPerspectiveTimer
.SetInvokeHandler( LINK( this, ThreeD_SceneGeometry_TabPage
, PerspectiveChanged
) );
112 m_xMFPerspective
->connect_value_changed( LINK( this, ThreeD_SceneGeometry_TabPage
, PerspectiveEdited
) );
113 m_xMFPerspective
->set_sensitive( m_xCbxPerspective
->get_active() );
116 if (ChartTypeHelper::isSupportingRightAngledAxes(m_xDiagram
->getChartTypeByIndex(0)))
118 bool bRightAngledAxes
= false;
119 m_xDiagram
->getPropertyValue( u
"RightAngledAxes"_ustr
) >>= bRightAngledAxes
;
120 m_xCbxRightAngledAxes
->connect_toggled( LINK( this, ThreeD_SceneGeometry_TabPage
, RightAngledAxesToggled
));
121 m_xCbxRightAngledAxes
->set_active( bRightAngledAxes
);
122 RightAngledAxesToggled(*m_xCbxRightAngledAxes
);
126 m_xCbxRightAngledAxes
->set_sensitive(false);
130 ThreeD_SceneGeometry_TabPage::~ThreeD_SceneGeometry_TabPage()
134 void ThreeD_SceneGeometry_TabPage::commitPendingChanges()
136 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
138 if( m_bAngleChangePending
)
139 applyAnglesToModel();
140 if( m_bPerspectiveChangePending
)
141 applyPerspectiveToModel();
144 void ThreeD_SceneGeometry_TabPage::applyAnglesToModel()
146 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
148 double fXAngle
= 0.0, fYAngle
= 0.0, fZAngle
= 0.0;
150 if (m_xMFZRotation
->get_sensitive())
151 m_nZRotation
= m_xMFZRotation
->get_value(FieldUnit::DEGREE
);
153 fXAngle
= double(m_nXRotation
)/pow(10.0,m_xMFXRotation
->get_digits());
154 fYAngle
= double(-1.0*m_nYRotation
)/pow(10.0,m_xMFYRotation
->get_digits());
155 fZAngle
= double(-1.0*m_nZRotation
)/pow(10.0,m_xMFZRotation
->get_digits());
157 fXAngle
= basegfx::deg2rad(fXAngle
);
158 fYAngle
= basegfx::deg2rad(fYAngle
);
159 fZAngle
= basegfx::deg2rad(fZAngle
);
161 m_xDiagram
->setRotationAngle( fXAngle
, fYAngle
, fZAngle
);
163 m_bAngleChangePending
= false;
164 m_aAngleTimer
.Stop();
167 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage
, AngleEdited
, weld::MetricSpinButton
&, void)
169 m_nXRotation
= m_xMFXRotation
->get_value(FieldUnit::DEGREE
);
170 m_nYRotation
= m_xMFYRotation
->get_value(FieldUnit::DEGREE
);
172 m_bAngleChangePending
= true;
174 m_aAngleTimer
.Start();
177 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage
, AngleChanged
, Timer
*, void)
179 applyAnglesToModel();
182 void ThreeD_SceneGeometry_TabPage::applyPerspectiveToModel()
184 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
186 drawing::ProjectionMode aMode
= m_xCbxPerspective
->get_active()
187 ? drawing::ProjectionMode_PERSPECTIVE
188 : drawing::ProjectionMode_PARALLEL
;
192 m_xDiagram
->setPropertyValue( u
"D3DScenePerspective"_ustr
, uno::Any( aMode
));
193 m_xDiagram
->setPropertyValue( u
"Perspective"_ustr
, uno::Any( static_cast<sal_Int32
>(m_xMFPerspective
->get_value(FieldUnit::PERCENT
)) ));
195 catch( const uno::Exception
& )
197 DBG_UNHANDLED_EXCEPTION("chart2");
200 m_bPerspectiveChangePending
= false;
201 m_aPerspectiveTimer
.Stop();
204 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage
, PerspectiveEdited
, weld::MetricSpinButton
&, void)
206 m_bPerspectiveChangePending
= true;
207 m_aPerspectiveTimer
.Start();
210 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage
, PerspectiveChanged
, Timer
*, void)
212 applyPerspectiveToModel();
215 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage
, PerspectiveToggled
, weld::Toggleable
&, void)
217 m_xMFPerspective
->set_sensitive(m_xCbxPerspective
->get_active());
218 applyPerspectiveToModel();
221 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage
, RightAngledAxesToggled
, weld::Toggleable
&, void)
223 ControllerLockHelperGuard
aGuard( m_rControllerLockHelper
);
225 bool bEnableZ
= !m_xCbxRightAngledAxes
->get_active();
226 m_xFtZRotation
->set_sensitive( bEnableZ
);
227 m_xMFZRotation
->set_sensitive( bEnableZ
);
230 m_nXRotation
= m_xMFXRotation
->get_value(FieldUnit::DEGREE
);
231 m_nYRotation
= m_xMFYRotation
->get_value(FieldUnit::DEGREE
);
232 m_nZRotation
= m_xMFZRotation
->get_value(FieldUnit::DEGREE
);
234 m_xMFXRotation
->set_value(static_cast<sal_Int64
>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nXRotation
), ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes())), FieldUnit::DEGREE
);
235 m_xMFYRotation
->set_value(static_cast<sal_Int64
>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nYRotation
), ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes())), FieldUnit::DEGREE
);
236 m_xMFZRotation
->set_text(u
""_ustr
);
238 lcl_SetMetricFieldLimits( *m_xMFXRotation
, static_cast<sal_Int64
>(ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes()));
239 lcl_SetMetricFieldLimits( *m_xMFYRotation
, static_cast<sal_Int64
>(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()));
243 lcl_SetMetricFieldLimits( *m_xMFXRotation
, 180 );
244 lcl_SetMetricFieldLimits( *m_xMFYRotation
, 180 );
246 m_xMFXRotation
->set_value(m_nXRotation
, FieldUnit::DEGREE
);
247 m_xMFYRotation
->set_value(m_nYRotation
, FieldUnit::DEGREE
);
248 m_xMFZRotation
->set_value(m_nZRotation
, FieldUnit::DEGREE
);
252 m_xDiagram
->switchRightAngledAxes( m_xCbxRightAngledAxes
->get_active() );
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */