LibreOffice Module chart2 (master) 1
tp_3D_SceneGeometry.cxx
Go to the documentation of this file.
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
21
22#include <Diagram.hxx>
23#include <DiagramHelper.hxx>
24#include <ChartType.hxx>
25#include <ChartTypeHelper.hxx>
26#include <ThreeDHelper.hxx>
28#include <com/sun/star/drawing/ProjectionMode.hpp>
30#include <tools/helpers.hxx>
31#include <utility>
32#include <vcl/svapp.hxx>
33
34namespace chart
35{
36
37using namespace ::com::sun::star;
38
39namespace
40{
41
42void lcl_SetMetricFieldLimits(weld::MetricSpinButton& rField, sal_Int64 nLimit)
43{
44 rField.set_range(-1*nLimit, nLimit, FieldUnit::DEGREE);
45}
46
47}
48
51 ControllerLockHelper & rControllerLockHelper)
52 : m_xDiagram(std::move( xDiagram ))
53 , m_aAngleTimer("chart2 ThreeD_SceneGeometry_TabPage m_aAngleTimer")
54 , m_aPerspectiveTimer("chart2 ThreeD_SceneGeometry_TabPage m_aPerspectiveTimer")
55 , m_nXRotation(0)
56 , m_nYRotation(0)
57 , m_nZRotation(0)
58 , m_bAngleChangePending( false )
59 , m_bPerspectiveChangePending( false )
60 , m_rControllerLockHelper( rControllerLockHelper )
61 , m_xBuilder(Application::CreateBuilder(pParent, "modules/schart/ui/tp_3D_SceneGeometry.ui"))
62 , m_xContainer(m_xBuilder->weld_container("tp_3DSceneGeometry"))
63 , m_xCbxRightAngledAxes(m_xBuilder->weld_check_button("CBX_RIGHT_ANGLED_AXES"))
64 , m_xMFXRotation(m_xBuilder->weld_metric_spin_button("MTR_FLD_X_ROTATION", FieldUnit::DEGREE))
65 , m_xMFYRotation(m_xBuilder->weld_metric_spin_button("MTR_FLD_Y_ROTATION", FieldUnit::DEGREE))
66 , m_xFtZRotation(m_xBuilder->weld_label("FT_Z_ROTATION"))
67 , m_xMFZRotation(m_xBuilder->weld_metric_spin_button("MTR_FLD_Z_ROTATION", FieldUnit::DEGREE))
68 , m_xCbxPerspective(m_xBuilder->weld_check_button("CBX_PERSPECTIVE"))
69 , m_xMFPerspective(m_xBuilder->weld_metric_spin_button("MTR_FLD_PERSPECTIVE", FieldUnit::PERCENT))
70{
71 double fXAngle, fYAngle, fZAngle;
72 m_xDiagram->getRotationAngle( fXAngle, fYAngle, fZAngle );
73
74 fXAngle = basegfx::rad2deg(fXAngle);
75 fYAngle = basegfx::rad2deg(fYAngle);
76 fZAngle = basegfx::rad2deg(fZAngle);
77
78 OSL_ENSURE( fZAngle>=-90 && fZAngle<=90, "z angle is out of valid range" );
79
80 lcl_SetMetricFieldLimits( *m_xMFZRotation, 90 );
81
83 ::basegfx::fround(fXAngle * pow(10.0, m_xMFXRotation->get_digits())));
85 ::basegfx::fround(-1.0 * fYAngle * pow(10.0, m_xMFYRotation->get_digits())));
87 ::basegfx::fround(-1.0 * fZAngle * pow(10.0, m_xMFZRotation->get_digits())));
88
89 m_xMFXRotation->set_value(m_nXRotation, FieldUnit::DEGREE);
90 m_xMFYRotation->set_value(m_nYRotation, FieldUnit::DEGREE);
91 m_xMFZRotation->set_value(m_nZRotation, FieldUnit::DEGREE);
92
93 const int nTimeout = 4*EDIT_UPDATEDATA_TIMEOUT;
94 m_aAngleTimer.SetTimeout(nTimeout);
96
97 Link<weld::MetricSpinButton&,void> aAngleEditedLink( LINK( this, ThreeD_SceneGeometry_TabPage, AngleEdited ));
98 m_xMFXRotation->connect_value_changed( aAngleEditedLink );
99 m_xMFYRotation->connect_value_changed( aAngleEditedLink );
100 m_xMFZRotation->connect_value_changed( aAngleEditedLink );
101
102 drawing::ProjectionMode aProjectionMode = drawing::ProjectionMode_PERSPECTIVE;
103 m_xDiagram->getPropertyValue( "D3DScenePerspective" ) >>= aProjectionMode;
104 m_xCbxPerspective->set_active( aProjectionMode == drawing::ProjectionMode_PERSPECTIVE );
105 m_xCbxPerspective->connect_toggled( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveToggled ));
106
107 sal_Int32 nPerspectivePercentage = 20;
108 m_xDiagram->getPropertyValue( "Perspective" ) >>= nPerspectivePercentage;
109 m_xMFPerspective->set_value(nPerspectivePercentage, FieldUnit::PERCENT);
110
113 m_xMFPerspective->connect_value_changed( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveEdited ) );
114 m_xMFPerspective->set_sensitive( m_xCbxPerspective->get_active() );
115
116 //RightAngledAxes
117 if (ChartTypeHelper::isSupportingRightAngledAxes(m_xDiagram->getChartTypeByIndex(0)))
118 {
119 bool bRightAngledAxes = false;
120 m_xDiagram->getPropertyValue( "RightAngledAxes" ) >>= bRightAngledAxes;
121 m_xCbxRightAngledAxes->connect_toggled( LINK( this, ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled ));
122 m_xCbxRightAngledAxes->set_active( bRightAngledAxes );
123 RightAngledAxesToggled(*m_xCbxRightAngledAxes);
124 }
125 else
126 {
127 m_xCbxRightAngledAxes->set_sensitive(false);
128 }
129}
130
132{
133}
134
136{
138
143}
144
146{
148
149 double fXAngle = 0.0, fYAngle = 0.0, fZAngle = 0.0;
150
151 if (m_xMFZRotation->get_sensitive())
152 m_nZRotation = m_xMFZRotation->get_value(FieldUnit::DEGREE);
153
154 fXAngle = double(m_nXRotation)/pow(10.0,m_xMFXRotation->get_digits());
155 fYAngle = double(-1.0*m_nYRotation)/pow(10.0,m_xMFYRotation->get_digits());
156 fZAngle = double(-1.0*m_nZRotation)/pow(10.0,m_xMFZRotation->get_digits());
157
158 fXAngle = basegfx::deg2rad(fXAngle);
159 fYAngle = basegfx::deg2rad(fYAngle);
160 fZAngle = basegfx::deg2rad(fZAngle);
161
162 m_xDiagram->setRotationAngle( fXAngle, fYAngle, fZAngle );
163
164 m_bAngleChangePending = false;
166}
167
169{
170 m_nXRotation = m_xMFXRotation->get_value(FieldUnit::DEGREE);
171 m_nYRotation = m_xMFYRotation->get_value(FieldUnit::DEGREE);
172
173 m_bAngleChangePending = true;
174
175 m_aAngleTimer.Start();
176}
177
179{
180 applyAnglesToModel();
181}
182
184{
186
187 drawing::ProjectionMode aMode = m_xCbxPerspective->get_active()
188 ? drawing::ProjectionMode_PERSPECTIVE
189 : drawing::ProjectionMode_PARALLEL;
190
191 try
192 {
193 m_xDiagram->setPropertyValue( "D3DScenePerspective" , uno::Any( aMode ));
194 m_xDiagram->setPropertyValue( "Perspective" , uno::Any( static_cast<sal_Int32>(m_xMFPerspective->get_value(FieldUnit::PERCENT)) ));
195 }
196 catch( const uno::Exception & )
197 {
198 DBG_UNHANDLED_EXCEPTION("chart2");
199 }
200
203}
204
206{
207 m_bPerspectiveChangePending = true;
208 m_aPerspectiveTimer.Start();
209}
210
212{
213 applyPerspectiveToModel();
214}
215
217{
218 m_xMFPerspective->set_sensitive(m_xCbxPerspective->get_active());
219 applyPerspectiveToModel();
220}
221
223{
224 ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
225
226 bool bEnableZ = !m_xCbxRightAngledAxes->get_active();
227 m_xFtZRotation->set_sensitive( bEnableZ );
228 m_xMFZRotation->set_sensitive( bEnableZ );
229 if (!bEnableZ)
230 {
231 m_nXRotation = m_xMFXRotation->get_value(FieldUnit::DEGREE);
232 m_nYRotation = m_xMFYRotation->get_value(FieldUnit::DEGREE);
233 m_nZRotation = m_xMFZRotation->get_value(FieldUnit::DEGREE);
234
235 m_xMFXRotation->set_value(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nXRotation), ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes())), FieldUnit::DEGREE);
236 m_xMFYRotation->set_value(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nYRotation), ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes())), FieldUnit::DEGREE);
237 m_xMFZRotation->set_text("");
238
239 lcl_SetMetricFieldLimits( *m_xMFXRotation, static_cast<sal_Int64>(ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes()));
240 lcl_SetMetricFieldLimits( *m_xMFYRotation, static_cast<sal_Int64>(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()));
241 }
242 else
243 {
244 lcl_SetMetricFieldLimits( *m_xMFXRotation, 180 );
245 lcl_SetMetricFieldLimits( *m_xMFYRotation, 180 );
246
247 m_xMFXRotation->set_value(m_nXRotation, FieldUnit::DEGREE);
248 m_xMFYRotation->set_value(m_nYRotation, FieldUnit::DEGREE);
249 m_xMFZRotation->set_value(m_nZRotation, FieldUnit::DEGREE);
250 }
251
252 if (m_xDiagram)
253 m_xDiagram->switchRightAngledAxes( m_xCbxRightAngledAxes->get_active() );
254}
255
256} //namespace chart
257
258/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void Stop()
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
static bool isSupportingRightAngledAxes(const rtl::Reference< ::chart::ChartType > &xChartType)
This guard calls lockControllers at the given ControllerLockHelper in the CTOR and unlockControllers ...
This helper class can be used to pass a locking mechanism to other objects without exposing the full ...
static double getValueClippedToRange(double fValue, const double &fPositivLimit)
static double getYDegreeAngleLimitForRightAngledAxes()
static double getXDegreeAngleLimitForRightAngledAxes()
std::unique_ptr< weld::CheckButton > m_xCbxRightAngledAxes
std::unique_ptr< weld::MetricSpinButton > m_xMFPerspective
std::unique_ptr< weld::MetricSpinButton > m_xMFZRotation
std::unique_ptr< weld::CheckButton > m_xCbxPerspective
rtl::Reference< ::chart::Diagram > m_xDiagram
ControllerLockHelper & m_rControllerLockHelper
std::unique_ptr< weld::MetricSpinButton > m_xMFXRotation
ThreeD_SceneGeometry_TabPage(weld::Container *pWindow, rtl::Reference< ::chart::Diagram > xDiagram, ControllerLockHelper &rControllerLockHelper)
std::unique_ptr< weld::MetricSpinButton > m_xMFYRotation
void set_range(sal_Int64 min, sal_Int64 max, FieldUnit eValueUnit)
#define DBG_UNHANDLED_EXCEPTION(...)
FieldUnit
std::enable_if< std::is_signed< T >::value, T >::type NormAngle180(T angle)
constexpr double rad2deg(double v)
constexpr double deg2rad(double v)
IMPL_LINK_NOARG(SplinePropertiesDialog, SplineTypeListBoxHdl, weld::ComboBox &, void)
Reference< XNameAccess > m_xContainer
#define EDIT_UPDATEDATA_TIMEOUT
constexpr OUStringLiteral PERCENT(u"Percent")