Debian Codegraph @

chart2/source/controller/dialogs/tp_3D_SceneGeometry.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include "tp_3D_SceneGeometry.hxx"
21
22 #include <Diagram.hxx>
23 #include <ChartType.hxx>
24 #include <ThreeDHelper.hxx>
25 #include <ControllerLockGuard.hxx>
26 #include <com/sun/star/drawing/ProjectionMode.hpp>
27 #include <comphelper/diagnose_ex.hxx>
28 #include <tools/helpers.hxx>
29 #include <utility>
30 #include <vcl/svapp.hxx>
31
32 namespace chart
33 {
34
35 using namespace ::com::sun::star;
36
37 namespace
38 {
39
40 void lcl_SetMetricFieldLimits(weld::MetricSpinButton& rField, sal_Int64 nLimit)
41 {
42 rField.set_range(-1*nLimit, nLimit, FieldUnit::DEGREE);
43 }
44
45 }
46
47 ThreeD_SceneGeometry_TabPage::ThreeD_SceneGeometry_TabPage(weld::Container* pParent,
48 rtl::Reference< ::chart::Diagram > xDiagram,
49 ControllerLockHelper & rControllerLockHelper)
50 : m_xDiagram(std::move( xDiagram ))
51 , m_aAngleTimer("chart2 ThreeD_SceneGeometry_TabPage m_aAngleTimer")
52 , m_aPerspectiveTimer("chart2 ThreeD_SceneGeometry_TabPage m_aPerspectiveTimer")
53 , m_nXRotation(0)
54 , m_nYRotation(0)
55 , m_nZRotation(0)
56 , m_bAngleChangePending( false )
57 , m_bPerspectiveChangePending( false )
58 , m_rControllerLockHelper( rControllerLockHelper )
59 , m_xBuilder(Application::CreateBuilder(pParent, u"modules/schart/ui/tp_3D_SceneGeometry.ui"_ustr))
60 , m_xContainer(m_xBuilder->weld_container(u"tp_3DSceneGeometry"_ustr))
61 , m_xCbxRightAngledAxes(m_xBuilder->weld_check_button(u"CBX_RIGHT_ANGLED_AXES"_ustr))
62 , m_xMFXRotation(m_xBuilder->weld_metric_spin_button(u"MTR_FLD_X_ROTATION"_ustr, FieldUnit::DEGREE))
63 , m_xMFYRotation(m_xBuilder->weld_metric_spin_button(u"MTR_FLD_Y_ROTATION"_ustr, FieldUnit::DEGREE))
64 , m_xFtZRotation(m_xBuilder->weld_label(u"FT_Z_ROTATION"_ustr))
65 , m_xMFZRotation(m_xBuilder->weld_metric_spin_button(u"MTR_FLD_Z_ROTATION"_ustr, FieldUnit::DEGREE))
66 , m_xCbxPerspective(m_xBuilder->weld_check_button(u"CBX_PERSPECTIVE"_ustr))
67 , m_xMFPerspective(m_xBuilder->weld_metric_spin_button(u"MTR_FLD_PERSPECTIVE"_ustr, FieldUnit::PERCENT))
68 {
69 double fXAngle, fYAngle, fZAngle;
70 m_xDiagram->getRotationAngle( fXAngle, fYAngle, fZAngle );
71
72 fXAngle = basegfx::rad2deg(fXAngle);
73 fYAngle = basegfx::rad2deg(fYAngle);
74 fZAngle = basegfx::rad2deg(fZAngle);
75
76 OSL_ENSURE( fZAngle>=-90 && fZAngle<=90, "z angle is out of valid range" );
77
78 lcl_SetMetricFieldLimits( *m_xMFZRotation, 90 );
79
80 m_nXRotation = NormAngle180(
81 ::basegfx::fround(fXAngle * pow(10.0, m_xMFXRotation->get_digits())));
82 m_nYRotation = NormAngle180(
83 ::basegfx::fround(-1.0 * fYAngle * pow(10.0, m_xMFYRotation->get_digits())));
84 m_nZRotation = NormAngle180(
85 ::basegfx::fround(-1.0 * fZAngle * pow(10.0, m_xMFZRotation->get_digits())));
86
87 m_xMFXRotation->set_value(m_nXRotation, FieldUnit::DEGREE);
88 m_xMFYRotation->set_value(m_nYRotation, FieldUnit::DEGREE);
89 m_xMFZRotation->set_value(m_nZRotation, FieldUnit::DEGREE);
90
91 const int nTimeout = 4*EDIT_UPDATEDATA_TIMEOUT;
92 m_aAngleTimer.SetTimeout(nTimeout);
93 m_aAngleTimer.SetInvokeHandler( LINK( this, ThreeD_SceneGeometry_TabPage, AngleChanged ) );
94
95 Link<weld::MetricSpinButton&,void> aAngleEditedLink( LINK( this, ThreeD_SceneGeometry_TabPage, AngleEdited ));
96 m_xMFXRotation->connect_value_changed( aAngleEditedLink );
97 m_xMFYRotation->connect_value_changed( aAngleEditedLink );
98 m_xMFZRotation->connect_value_changed( aAngleEditedLink );
99
100 drawing::ProjectionMode aProjectionMode = drawing::ProjectionMode_PERSPECTIVE;
101 m_xDiagram->getPropertyValue( u"D3DScenePerspective"_ustr ) >>= aProjectionMode;
102 m_xCbxPerspective->set_active( aProjectionMode == drawing::ProjectionMode_PERSPECTIVE );
103 m_xCbxPerspective->connect_toggled( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveToggled ));
104
105 sal_Int32 nPerspectivePercentage = 20;
106 m_xDiagram->getPropertyValue( u"Perspective"_ustr ) >>= nPerspectivePercentage;
107 m_xMFPerspective->set_value(nPerspectivePercentage, FieldUnit::PERCENT);
108
109 m_aPerspectiveTimer.SetTimeout(nTimeout);
110 m_aPerspectiveTimer.SetInvokeHandler( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveChanged ) );
111 m_xMFPerspective->connect_value_changed( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveEdited ) );
112 m_xMFPerspective->set_sensitive( m_xCbxPerspective->get_active() );
113
114 //RightAngledAxes
115 auto xChartType = m_xDiagram->getChartTypeByIndex(0);
116 if (xChartType.is() && xChartType->isSupportingRightAngledAxes())
117 {
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);
123 }
124 else
125 {
126 m_xCbxRightAngledAxes->set_sensitive(false);
127 }
128 }
129
130 ThreeD_SceneGeometry_TabPage::~ThreeD_SceneGeometry_TabPage()
131 {
132 }
133
134 void ThreeD_SceneGeometry_TabPage::commitPendingChanges()
135 {
136 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
137
138 if( m_bAngleChangePending )
139 applyAnglesToModel();
140 if( m_bPerspectiveChangePending )
141 applyPerspectiveToModel();
142 }
143
144 void ThreeD_SceneGeometry_TabPage::applyAnglesToModel()
145 {
146 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
147
148 double fXAngle = 0.0, fYAngle = 0.0, fZAngle = 0.0;
149
150 if (m_xMFZRotation->get_sensitive())
151 m_nZRotation = m_xMFZRotation->get_value(FieldUnit::DEGREE);
152
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());
156
157 fXAngle = basegfx::deg2rad(fXAngle);
158 fYAngle = basegfx::deg2rad(fYAngle);
159 fZAngle = basegfx::deg2rad(fZAngle);
160
161 m_xDiagram->setRotationAngle( fXAngle, fYAngle, fZAngle );
162
163 m_bAngleChangePending = false;
164 m_aAngleTimer.Stop();
165 }
166
167 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, AngleEdited, weld::MetricSpinButton&, void)
168 {
169 m_nXRotation = m_xMFXRotation->get_value(FieldUnit::DEGREE);
170 m_nYRotation = m_xMFYRotation->get_value(FieldUnit::DEGREE);
171
172 m_bAngleChangePending = true;
173
174 m_aAngleTimer.Start();
175 }
176
177 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, AngleChanged, Timer *, void)
178 {
179 applyAnglesToModel();
180 }
181
182 void ThreeD_SceneGeometry_TabPage::applyPerspectiveToModel()
183 {
184 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
185
186 drawing::ProjectionMode aMode = m_xCbxPerspective->get_active()
187 ? drawing::ProjectionMode_PERSPECTIVE
188 : drawing::ProjectionMode_PARALLEL;
189
190 try
191 {
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)) ));
194 }
195 catch( const uno::Exception & )
196 {
197 DBG_UNHANDLED_EXCEPTION("chart2");
198 }
199
200 m_bPerspectiveChangePending = false;
201 m_aPerspectiveTimer.Stop();
202 }
203
204 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveEdited, weld::MetricSpinButton&, void)
205 {
206 m_bPerspectiveChangePending = true;
207 m_aPerspectiveTimer.Start();
208 }
209
210 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveChanged, Timer *, void)
211 {
212 applyPerspectiveToModel();
213 }
214
215 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveToggled, weld::Toggleable&, void)
216 {
217 m_xMFPerspective->set_sensitive(m_xCbxPerspective->get_active());
218 applyPerspectiveToModel();
219 }
220
221 IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled, weld::Toggleable&, void)
222 {
223 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
224
225 bool bEnableZ = !m_xCbxRightAngledAxes->get_active();
226 m_xFtZRotation->set_sensitive( bEnableZ );
227 m_xMFZRotation->set_sensitive( bEnableZ );
228 if (!bEnableZ)
229 {
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);
233
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);
237
238 lcl_SetMetricFieldLimits( *m_xMFXRotation, static_cast<sal_Int64>(ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes()));
239 lcl_SetMetricFieldLimits( *m_xMFYRotation, static_cast<sal_Int64>(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()));
240 }
241 else
242 {
243 lcl_SetMetricFieldLimits( *m_xMFXRotation, 180 );
244 lcl_SetMetricFieldLimits( *m_xMFYRotation, 180 );
245
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);
249 }
250
251 if (m_xDiagram)
252 m_xDiagram->switchRightAngledAxes( m_xCbxRightAngledAxes->get_active() );
253 }
254
255 } //namespace chart
256
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */