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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
/* -*- 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_SceneAppearance.hxx"
#include <ChartModelHelper.hxx>
#include <ChartModel.hxx>
#include <ThreeDHelper.hxx>
#include <ControllerLockGuard.hxx>
#include <Diagram.hxx>
#include <com/sun/star/drawing/ShadeMode.hpp>
#include <comphelper/diagnose_ex.hxx>
#include <utility>
#include <vcl/svapp.hxx>
using namespace ::com::sun::star;
namespace
{
struct lcl_ModelProperties
{
drawing::ShadeMode m_aShadeMode;
sal_Int32 m_nRoundedEdges;
sal_Int32 m_nObjectLines;
::chart::ThreeDLookScheme m_eScheme;
lcl_ModelProperties()
: m_aShadeMode(drawing::ShadeMode_FLAT)
, m_nRoundedEdges(-1)
, m_nObjectLines(-1)
, m_eScheme(::chart::ThreeDLookScheme::ThreeDLookScheme_Unknown)
{}
};
lcl_ModelProperties lcl_getPropertiesFromModel( rtl::Reference<::chart::ChartModel> const & xModel )
{
lcl_ModelProperties aProps;
try
{
rtl::Reference< ::chart::Diagram > xDiagram( xModel->getFirstChartDiagram() );
xDiagram->getPropertyValue( "D3DSceneShadeMode" ) >>= aProps.m_aShadeMode;
::chart::ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram, aProps.m_nRoundedEdges, aProps.m_nObjectLines );
aProps.m_eScheme = xDiagram->detectScheme();
}
catch( const uno::Exception & )
{
DBG_UNHANDLED_EXCEPTION("chart2");
}
return aProps;
}
void lcl_setShadeModeAtModel( rtl::Reference<::chart::ChartModel> const & xModel, drawing::ShadeMode aShadeMode )
{
try
{
rtl::Reference< ::chart::Diagram > xDiaProp = xModel->getFirstChartDiagram();
xDiaProp->setPropertyValue( "D3DSceneShadeMode" , uno::Any( aShadeMode ));
}
catch( const uno::Exception & )
{
DBG_UNHANDLED_EXCEPTION("chart2");
}
}
} // anonymous namespace
namespace chart
{
#define POS_3DSCHEME_SIMPLE 0
#define POS_3DSCHEME_REALISTIC 1
#define POS_3DSCHEME_CUSTOM 2
ThreeD_SceneAppearance_TabPage::ThreeD_SceneAppearance_TabPage(weld::Container* pParent,
rtl::Reference<::chart::ChartModel> xChartModel,
ControllerLockHelper& rControllerLockHelper)
: m_xChartModel(std::move(xChartModel))
, m_bUpdateOtherControls(true)
, m_bCommitToModel(true)
, m_rControllerLockHelper(rControllerLockHelper)
, m_xBuilder(Application::CreateBuilder(pParent, "modules/schart/ui/tp_3D_SceneAppearance.ui"))
, m_xContainer(m_xBuilder->weld_container("tp_3D_SceneAppearance"))
, m_xLB_Scheme(m_xBuilder->weld_combo_box("LB_SCHEME"))
, m_xCB_Shading(m_xBuilder->weld_check_button("CB_SHADING"))
, m_xCB_ObjectLines(m_xBuilder->weld_check_button("CB_OBJECTLINES"))
, m_xCB_RoundedEdge(m_xBuilder->weld_check_button("CB_ROUNDEDEDGE"))
{
m_aCustom = m_xLB_Scheme->get_text(POS_3DSCHEME_CUSTOM);
m_xLB_Scheme->remove(POS_3DSCHEME_CUSTOM);
m_xLB_Scheme->connect_changed( LINK( this, ThreeD_SceneAppearance_TabPage, SelectSchemeHdl ) );
m_xCB_RoundedEdge->connect_toggled( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
m_xCB_Shading->connect_toggled( LINK( this, ThreeD_SceneAppearance_TabPage, SelectShading ) );
m_xCB_ObjectLines->connect_toggled( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
initControlsFromModel();
}
ThreeD_SceneAppearance_TabPage::~ThreeD_SceneAppearance_TabPage()
{
}
void ThreeD_SceneAppearance_TabPage::ActivatePage()
{
updateScheme();
}
void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
{
if(!m_bCommitToModel)
return;
sal_Int32 nObjectLines = -1;
switch( m_xCB_ObjectLines->get_state())
{
case TRISTATE_FALSE:
nObjectLines = 0;
break;
case TRISTATE_TRUE:
nObjectLines = 1;
break;
case TRISTATE_INDET:
nObjectLines = -1;
break;
}
sal_Int32 nCurrentRoundedEdges = -1;
switch( m_xCB_RoundedEdge->get_state() )
{
case TRISTATE_FALSE:
nCurrentRoundedEdges = 0;
break;
case TRISTATE_TRUE:
nCurrentRoundedEdges = 5;
break;
case TRISTATE_INDET:
nCurrentRoundedEdges = -1;
break;
}
// locked controllers
ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
ThreeDHelper::setRoundedEdgesAndObjectLines(
m_xChartModel->getFirstChartDiagram(), nCurrentRoundedEdges, nObjectLines );
}
void ThreeD_SceneAppearance_TabPage::applyShadeModeToModel()
{
if(!m_bCommitToModel)
return;
drawing::ShadeMode aShadeMode = drawing::ShadeMode_PHONG;
switch( m_xCB_Shading->get_state())
{
case TRISTATE_FALSE:
aShadeMode = drawing::ShadeMode_FLAT;
break;
case TRISTATE_TRUE:
aShadeMode = drawing::ShadeMode_SMOOTH;
break;
case TRISTATE_INDET:
// nothing
break;
}
lcl_setShadeModeAtModel( m_xChartModel, aShadeMode );
}
void ThreeD_SceneAppearance_TabPage::initControlsFromModel()
{
m_bCommitToModel = false;
m_bUpdateOtherControls = false;
lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
if(aProps.m_aShadeMode == drawing::ShadeMode_FLAT)
{
m_xCB_Shading->set_active(false);
}
else if(aProps.m_aShadeMode == drawing::ShadeMode_SMOOTH)
{
m_xCB_Shading->set_active(true);
}
else
{
m_xCB_Shading->set_state(TRISTATE_INDET);
}
if(aProps.m_nObjectLines == 0)
{
m_xCB_ObjectLines->set_active(false);
}
else if(aProps.m_nObjectLines==1)
{
m_xCB_ObjectLines->set_active(true);
}
else
{
m_xCB_ObjectLines->set_state(TRISTATE_INDET);
}
if(aProps.m_nRoundedEdges >= 5)
{
m_xCB_RoundedEdge->set_active(true);
}
else if(aProps.m_nRoundedEdges<0)
{
m_xCB_RoundedEdge->set_state(TRISTATE_INDET);
}
else
{
m_xCB_RoundedEdge->set_active(false);
}
m_xCB_RoundedEdge->set_sensitive( !m_xCB_ObjectLines->get_active() );
updateScheme();
m_bCommitToModel = true;
m_bUpdateOtherControls = true;
}
void ThreeD_SceneAppearance_TabPage::updateScheme()
{
lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
if (m_xLB_Scheme->get_count() == (POS_3DSCHEME_CUSTOM+1))
m_xLB_Scheme->remove(POS_3DSCHEME_CUSTOM);
switch( aProps.m_eScheme )
{
case ThreeDLookScheme::ThreeDLookScheme_Simple:
m_xLB_Scheme->set_active( POS_3DSCHEME_SIMPLE );
break;
case ThreeDLookScheme::ThreeDLookScheme_Realistic:
m_xLB_Scheme->set_active( POS_3DSCHEME_REALISTIC );
break;
case ThreeDLookScheme::ThreeDLookScheme_Unknown:
{
m_xLB_Scheme->insert_text(POS_3DSCHEME_CUSTOM, m_aCustom);
m_xLB_Scheme->set_active(POS_3DSCHEME_CUSTOM);
}
break;
}
}
IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectSchemeHdl, weld::ComboBox&, void)
{
if( !m_bUpdateOtherControls )
return;
{
// locked controllers
ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
rtl::Reference< Diagram > xDiagram = m_xChartModel->getFirstChartDiagram();
if( m_xLB_Scheme->get_active() == POS_3DSCHEME_REALISTIC )
xDiagram->setScheme( ThreeDLookScheme::ThreeDLookScheme_Realistic );
else if( m_xLB_Scheme->get_active() == POS_3DSCHEME_SIMPLE )
xDiagram->setScheme( ThreeDLookScheme::ThreeDLookScheme_Simple );
else
{
OSL_FAIL( "Invalid Entry selected" );
}
}
// update other controls
initControlsFromModel();
}
IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectShading, weld::Toggleable&, void)
{
if( !m_bUpdateOtherControls )
return;
applyShadeModeToModel();
updateScheme();
}
IMPL_LINK(ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines, weld::Toggleable&, rCheckBox, void)
{
if( !m_bUpdateOtherControls )
return;
if (&rCheckBox == m_xCB_ObjectLines.get())
{
m_bUpdateOtherControls = false;
m_xCB_RoundedEdge->set_sensitive( !m_xCB_ObjectLines->get_active() );
if(!m_xCB_RoundedEdge->get_sensitive())
m_xCB_RoundedEdge->set_active(false);
m_bUpdateOtherControls = true;
}
applyRoundedEdgeAndObjectLinesToModel();
updateScheme();
}
} //namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|