1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "tp_3D_SceneGeometry.hxx"

#include <BaseGFXHelper.hxx>
#include <DiagramHelper.hxx>
#include <ChartTypeHelper.hxx>
#include <ThreeDHelper.hxx>
#include <ControllerLockGuard.hxx>
#include <rtl/math.hxx>
#include <editeng/unoprnms.hxx>
#include <com/sun/star/drawing/ProjectionMode.hpp>
#include <tools/diagnose_ex.h>
#include <tools/helpers.hxx>

namespace chart
{

using namespace ::com::sun::star;

namespace
{

void lcl_SetMetricFieldLimits( MetricField& rField, sal_Int64 nLimit )
{
    rField.SetMin(-1*nLimit);
    rField.SetFirst(-1*nLimit);
    rField.SetMax(nLimit);
    rField.SetLast(nLimit);
}

}
ThreeD_SceneGeometry_TabPage::ThreeD_SceneGeometry_TabPage( vcl::Window* pWindow
                , const uno::Reference< beans::XPropertySet > & xSceneProperties
                , ControllerLockHelper & rControllerLockHelper )
                : TabPage ( pWindow
                          , "tp_3DSceneGeometry"
                          , "modules/schart/ui/tp_3D_SceneGeometry.ui")
                , m_xSceneProperties( xSceneProperties )
                , m_nXRotation(0)
                , m_nYRotation(0)
                , m_nZRotation(0)
                , m_bAngleChangePending( false )
                , m_bPerspectiveChangePending( false )
                , m_rControllerLockHelper( rControllerLockHelper )
{
    get(m_pCbxRightAngledAxes,"CBX_RIGHT_ANGLED_AXES");
    get(m_pMFXRotation, "MTR_FLD_X_ROTATION");
    get(m_pMFYRotation, "MTR_FLD_Y_ROTATION");
    get(m_pFtZRotation, "FT_Z_ROTATION");
    get(m_pMFZRotation, "MTR_FLD_Z_ROTATION");
    get(m_pCbxPerspective,"CBX_PERSPECTIVE");
    get(m_pMFPerspective, "MTR_FLD_PERSPECTIVE");

    double fXAngle, fYAngle, fZAngle;
    ThreeDHelper::getRotationAngleFromDiagram( m_xSceneProperties, fXAngle, fYAngle, fZAngle );

    fXAngle = basegfx::rad2deg(fXAngle);
    fYAngle = basegfx::rad2deg(fYAngle);
    fZAngle = basegfx::rad2deg(fZAngle);

    OSL_ENSURE( fZAngle>=-90 && fZAngle<=90, "z angle is out of valid range" );

    lcl_SetMetricFieldLimits( *m_pMFZRotation, 90 );

    m_nXRotation = NormAngle180(
        ::basegfx::fround(fXAngle * pow(10.0, m_pMFXRotation->GetDecimalDigits())));
    m_nYRotation = NormAngle180(
        ::basegfx::fround(-1.0 * fYAngle * pow(10.0, m_pMFYRotation->GetDecimalDigits())));
    m_nZRotation = NormAngle180(
        ::basegfx::fround(-1.0 * fZAngle * pow(10.0, m_pMFZRotation->GetDecimalDigits())));

    m_pMFXRotation->SetValue(m_nXRotation);
    m_pMFYRotation->SetValue(m_nYRotation);
    m_pMFZRotation->SetValue(m_nZRotation);

    const sal_uLong nTimeout = 4*EDIT_UPDATEDATA_TIMEOUT;
    Link<Edit&,void> aAngleChangedLink( LINK( this, ThreeD_SceneGeometry_TabPage, AngleChanged ));
    Link<Edit&,void> aAngleEditedLink( LINK( this, ThreeD_SceneGeometry_TabPage, AngleEdited ));

    m_pMFXRotation->EnableUpdateData( nTimeout );
    m_pMFXRotation->SetUpdateDataHdl( aAngleChangedLink );
    m_pMFXRotation->SetModifyHdl( aAngleEditedLink );

    m_pMFYRotation->EnableUpdateData( nTimeout );
    m_pMFYRotation->SetUpdateDataHdl( aAngleChangedLink );
    m_pMFYRotation->SetModifyHdl( aAngleEditedLink );

    m_pMFZRotation->EnableUpdateData( nTimeout );
    m_pMFZRotation->SetUpdateDataHdl( aAngleChangedLink );
    m_pMFZRotation->SetModifyHdl( aAngleEditedLink );

    drawing::ProjectionMode aProjectionMode = drawing::ProjectionMode_PERSPECTIVE;
    m_xSceneProperties->getPropertyValue( "D3DScenePerspective" ) >>= aProjectionMode;
    m_pCbxPerspective->Check( aProjectionMode == drawing::ProjectionMode_PERSPECTIVE );
    m_pCbxPerspective->SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveToggled ));

    sal_Int32 nPerspectivePercentage = 20;
    m_xSceneProperties->getPropertyValue( "Perspective" ) >>= nPerspectivePercentage;
    m_pMFPerspective->SetValue( nPerspectivePercentage );

    m_pMFPerspective->EnableUpdateData( nTimeout );
    m_pMFPerspective->SetUpdateDataHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveChanged ) );
    m_pMFPerspective->SetModifyHdl( LINK( this, ThreeD_SceneGeometry_TabPage, PerspectiveEdited ) );
    m_pMFPerspective->Enable( m_pCbxPerspective->IsChecked() );

    //RightAngledAxes
    uno::Reference< chart2::XDiagram > xDiagram( m_xSceneProperties, uno::UNO_QUERY );
    if( ChartTypeHelper::isSupportingRightAngledAxes(
            DiagramHelper::getChartTypeByIndex( xDiagram, 0 ) ) )
    {
        bool bRightAngledAxes = false;
        m_xSceneProperties->getPropertyValue( "RightAngledAxes" ) >>= bRightAngledAxes;
        m_pCbxRightAngledAxes->SetToggleHdl( LINK( this, ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled ));
        m_pCbxRightAngledAxes->Check( bRightAngledAxes );
    }
    else
    {
        m_pCbxRightAngledAxes->Enable(false);
    }
}

ThreeD_SceneGeometry_TabPage::~ThreeD_SceneGeometry_TabPage()
{
    disposeOnce();
}

void ThreeD_SceneGeometry_TabPage::dispose()
{
    m_pCbxRightAngledAxes.clear();
    m_pMFXRotation.clear();
    m_pMFYRotation.clear();
    m_pFtZRotation.clear();
    m_pMFZRotation.clear();
    m_pCbxPerspective.clear();
    m_pMFPerspective.clear();
    TabPage::dispose();
}


void ThreeD_SceneGeometry_TabPage::commitPendingChanges()
{
    ControllerLockHelperGuard aGuard( m_rControllerLockHelper );

    if( m_bAngleChangePending )
        applyAnglesToModel();
    if( m_bPerspectiveChangePending )
        applyPerspectiveToModel();
}

void ThreeD_SceneGeometry_TabPage::applyAnglesToModel()
{
    ControllerLockHelperGuard aGuard( m_rControllerLockHelper );

    double fXAngle = 0.0, fYAngle = 0.0, fZAngle = 0.0;

    if( !m_pMFZRotation->IsEmptyFieldValue() )
        m_nZRotation = m_pMFZRotation->GetValue();

    fXAngle = double(m_nXRotation)/pow(10.0,m_pMFXRotation->GetDecimalDigits());
    fYAngle = double(-1.0*m_nYRotation)/pow(10.0,m_pMFYRotation->GetDecimalDigits());
    fZAngle = double(-1.0*m_nZRotation)/pow(10.0,m_pMFZRotation->GetDecimalDigits());

    fXAngle = basegfx::deg2rad(fXAngle);
    fYAngle = basegfx::deg2rad(fYAngle);
    fZAngle = basegfx::deg2rad(fZAngle);

    ThreeDHelper::setRotationAngleToDiagram( m_xSceneProperties, fXAngle, fYAngle, fZAngle );

    m_bAngleChangePending = false;
}

IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, AngleEdited, Edit&, void)<--- syntax error
{
    m_nXRotation = m_pMFXRotation->GetValue();
    m_nYRotation = m_pMFYRotation->GetValue();

    m_bAngleChangePending = true;
}

IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, AngleChanged, Edit&, void)
{
    applyAnglesToModel();
}

void ThreeD_SceneGeometry_TabPage::applyPerspectiveToModel()
{
    ControllerLockHelperGuard aGuard( m_rControllerLockHelper );

    drawing::ProjectionMode aMode = m_pCbxPerspective->IsChecked()
        ? drawing::ProjectionMode_PERSPECTIVE
        : drawing::ProjectionMode_PARALLEL;

    try
    {
        m_xSceneProperties->setPropertyValue( "D3DScenePerspective" , uno::Any( aMode ));
        m_xSceneProperties->setPropertyValue( "Perspective" , uno::Any( static_cast<sal_Int32>(m_pMFPerspective->GetValue()) ));
    }
    catch( const uno::Exception & )
    {
        DBG_UNHANDLED_EXCEPTION("chart2");
    }

    m_bPerspectiveChangePending = false;
}

IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveEdited, Edit&, void)
{
    m_bPerspectiveChangePending = true;
}

IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveChanged, Edit&, void)
{
    applyPerspectiveToModel();
}

IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, PerspectiveToggled, CheckBox&, void)
{
    m_pMFPerspective->Enable( m_pCbxPerspective->IsChecked() );
    applyPerspectiveToModel();
}

IMPL_LINK_NOARG(ThreeD_SceneGeometry_TabPage, RightAngledAxesToggled, CheckBox&, void)
{
    ControllerLockHelperGuard aGuard( m_rControllerLockHelper );

    bool bEnableZ = !m_pCbxRightAngledAxes->IsChecked();
    m_pFtZRotation->Enable( bEnableZ );
    m_pMFZRotation->Enable( bEnableZ );
    m_pMFZRotation->EnableEmptyFieldValue( !bEnableZ );
    if( !bEnableZ )
    {
        m_nXRotation = m_pMFXRotation->GetValue();
        m_nYRotation = m_pMFYRotation->GetValue();
        m_nZRotation = m_pMFZRotation->GetValue();

        m_pMFXRotation->SetValue(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nXRotation), ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes())));
        m_pMFYRotation->SetValue(static_cast<sal_Int64>(ThreeDHelper::getValueClippedToRange(static_cast<double>(m_nYRotation), ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes())));
        m_pMFZRotation->SetEmptyFieldValue();

        lcl_SetMetricFieldLimits( *m_pMFXRotation, static_cast<sal_Int64>(ThreeDHelper::getXDegreeAngleLimitForRightAngledAxes()));
        lcl_SetMetricFieldLimits( *m_pMFYRotation, static_cast<sal_Int64>(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()));
    }
    else
    {
        lcl_SetMetricFieldLimits( *m_pMFXRotation, 180 );
        lcl_SetMetricFieldLimits( *m_pMFYRotation, 180 );

        m_pMFXRotation->SetValue(m_nXRotation);
        m_pMFYRotation->SetValue(m_nYRotation);
        m_pMFZRotation->SetValue(m_nZRotation);
    }

    ThreeDHelper::switchRightAngledAxes( m_xSceneProperties, m_pCbxRightAngledAxes->IsChecked() );
}

} //namespace chart

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */