Line data Source code
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_SceneAppearance.hxx"
21 : #include "ChartModelHelper.hxx"
22 : #include "ThreeDHelper.hxx"
23 : #include "macros.hxx"
24 : #include <rtl/math.hxx>
25 : #include <com/sun/star/beans/XPropertySet.hpp>
26 :
27 : using namespace ::com::sun::star;
28 :
29 : namespace
30 : {
31 :
32 : struct lcl_ModelProperties
33 : {
34 : drawing::ShadeMode m_aShadeMode;
35 : sal_Int32 m_nRoundedEdges;
36 : sal_Int32 m_nObjectLines;
37 : ::chart::ThreeDLookScheme m_eScheme;
38 :
39 0 : lcl_ModelProperties()
40 : : m_aShadeMode(drawing::ShadeMode_FLAT)
41 : , m_nRoundedEdges(-1)
42 : , m_nObjectLines(-1)
43 0 : , m_eScheme(::chart::ThreeDLookScheme_Unknown)
44 0 : {}
45 : };
46 :
47 0 : lcl_ModelProperties lcl_getPropertiesFromModel( uno::Reference< frame::XModel > & xModel )
48 : {
49 0 : lcl_ModelProperties aProps;
50 : try
51 : {
52 0 : uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( xModel ) );
53 0 : uno::Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY_THROW );
54 0 : xDiaProp->getPropertyValue( "D3DSceneShadeMode" ) >>= aProps.m_aShadeMode;
55 0 : ::chart::ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram, aProps.m_nRoundedEdges, aProps.m_nObjectLines );
56 0 : aProps.m_eScheme = ::chart::ThreeDHelper::detectScheme( xDiagram );
57 : }
58 0 : catch( const uno::Exception & ex )
59 : {
60 : ASSERT_EXCEPTION( ex );
61 : }
62 0 : return aProps;
63 : }
64 :
65 0 : void lcl_setShadeModeAtModel( uno::Reference< frame::XModel > & xModel, drawing::ShadeMode aShadeMode )
66 : {
67 : try
68 : {
69 : uno::Reference< beans::XPropertySet > xDiaProp(
70 0 : ::chart::ChartModelHelper::findDiagram( xModel ), uno::UNO_QUERY_THROW );
71 0 : xDiaProp->setPropertyValue( "D3DSceneShadeMode" , uno::makeAny( aShadeMode ));
72 : }
73 0 : catch( const uno::Exception & ex )
74 : {
75 : ASSERT_EXCEPTION( ex );
76 : }
77 0 : }
78 :
79 : } // anonymous namespace
80 :
81 : namespace chart
82 : {
83 :
84 : #define POS_3DSCHEME_SIMPLE 0
85 : #define POS_3DSCHEME_REALISTIC 1
86 : #define POS_3DSCHEME_CUSTOM 2
87 :
88 0 : ThreeD_SceneAppearance_TabPage::ThreeD_SceneAppearance_TabPage(
89 : vcl::Window* pWindow
90 : , const uno::Reference< frame::XModel > & xChartModel
91 : , ControllerLockHelper & rControllerLockHelper )
92 : : TabPage ( pWindow
93 : , "tp_3D_SceneAppearance"
94 : , "modules/schart/ui/tp_3D_SceneAppearance.ui")
95 : , m_xChartModel ( xChartModel )
96 : , m_bUpdateOtherControls( true )
97 : , m_bCommitToModel( true )
98 0 : , m_rControllerLockHelper( rControllerLockHelper )
99 : {
100 :
101 0 : get(m_pLB_Scheme, "LB_SCHEME");
102 0 : get(m_pCB_Shading, "CB_SHADING");
103 0 : get(m_pCB_ObjectLines, "CB_OBJECTLINES");
104 0 : get(m_pCB_RoundedEdge, "CB_ROUNDEDEDGE");
105 :
106 0 : m_aCustom = m_pLB_Scheme->GetEntry(POS_3DSCHEME_CUSTOM);
107 0 : m_pLB_Scheme->RemoveEntry(POS_3DSCHEME_CUSTOM);
108 0 : m_pLB_Scheme->SetDropDownLineCount(2);
109 :
110 0 : m_pLB_Scheme->SetSelectHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectSchemeHdl ) );
111 :
112 0 : m_pCB_RoundedEdge->SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
113 0 : m_pCB_Shading->SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectShading ) );
114 0 : m_pCB_ObjectLines->SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
115 :
116 0 : m_pCB_RoundedEdge->EnableTriState( true );
117 0 : m_pCB_Shading->EnableTriState( true );
118 0 : m_pCB_ObjectLines->EnableTriState( true );
119 :
120 0 : initControlsFromModel();
121 0 : }
122 :
123 0 : ThreeD_SceneAppearance_TabPage::~ThreeD_SceneAppearance_TabPage()
124 0 : {}
125 :
126 0 : void ThreeD_SceneAppearance_TabPage::ActivatePage()
127 : {
128 0 : updateScheme();
129 0 : }
130 :
131 0 : void ThreeD_SceneAppearance_TabPage::commitPendingChanges()
132 : {
133 0 : }
134 :
135 0 : void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
136 : {
137 0 : if(!m_bCommitToModel)
138 0 : return;
139 :
140 0 : sal_Int32 nObjectLines = -1;
141 :
142 0 : switch( m_pCB_ObjectLines->GetState())
143 : {
144 : case TRISTATE_FALSE:
145 0 : nObjectLines = 0;
146 0 : break;
147 : case TRISTATE_TRUE:
148 0 : nObjectLines = 1;
149 0 : break;
150 : case TRISTATE_INDET:
151 0 : nObjectLines = -1;
152 0 : break;
153 : }
154 :
155 0 : sal_Int32 nCurrentRoundedEdges = -1;
156 0 : switch( m_pCB_RoundedEdge->GetState() )
157 : {
158 : case TRISTATE_FALSE:
159 0 : nCurrentRoundedEdges = 0;
160 0 : break;
161 : case TRISTATE_TRUE:
162 0 : nCurrentRoundedEdges = 5;
163 0 : break;
164 : case TRISTATE_INDET:
165 0 : nCurrentRoundedEdges = -1;
166 0 : break;
167 : }
168 :
169 : // locked controllers
170 0 : ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
171 : ThreeDHelper::setRoundedEdgesAndObjectLines(
172 0 : ::chart::ChartModelHelper::findDiagram( m_xChartModel ), nCurrentRoundedEdges, nObjectLines );
173 : }
174 :
175 0 : void ThreeD_SceneAppearance_TabPage::applyShadeModeToModel()
176 : {
177 0 : if(!m_bCommitToModel)
178 0 : return;
179 :
180 0 : drawing::ShadeMode aShadeMode = drawing::ShadeMode_PHONG;
181 :
182 0 : switch( m_pCB_Shading->GetState())
183 : {
184 : case TRISTATE_FALSE:
185 0 : aShadeMode = drawing::ShadeMode_FLAT;
186 0 : break;
187 : case TRISTATE_TRUE:
188 0 : aShadeMode = drawing::ShadeMode_SMOOTH;
189 0 : break;
190 : case TRISTATE_INDET:
191 : // nothing
192 0 : break;
193 : }
194 :
195 0 : lcl_setShadeModeAtModel( m_xChartModel, aShadeMode );
196 : }
197 :
198 0 : void ThreeD_SceneAppearance_TabPage::initControlsFromModel()
199 : {
200 0 : m_bCommitToModel = false;
201 0 : m_bUpdateOtherControls = false;
202 :
203 0 : lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
204 :
205 0 : if(aProps.m_aShadeMode == drawing::ShadeMode_FLAT)
206 : {
207 0 : m_pCB_Shading->EnableTriState( false );
208 0 : m_pCB_Shading->Check(false);
209 : }
210 0 : else if(aProps.m_aShadeMode == drawing::ShadeMode_SMOOTH)
211 : {
212 0 : m_pCB_Shading->EnableTriState( false );
213 0 : m_pCB_Shading->Check(true);
214 : }
215 : else
216 : {
217 0 : m_pCB_Shading->EnableTriState( true );
218 0 : m_pCB_Shading->SetState( TRISTATE_INDET );
219 : }
220 :
221 0 : if(aProps.m_nObjectLines == 0)
222 : {
223 0 : m_pCB_ObjectLines->EnableTriState( false );
224 0 : m_pCB_ObjectLines->Check(false);
225 : }
226 0 : else if(aProps.m_nObjectLines==1)
227 : {
228 0 : m_pCB_ObjectLines->EnableTriState( false );
229 0 : m_pCB_ObjectLines->Check(true);
230 : }
231 : else
232 : {
233 0 : m_pCB_ObjectLines->EnableTriState( true );
234 0 : m_pCB_ObjectLines->SetState( TRISTATE_INDET );
235 : }
236 :
237 0 : if(aProps.m_nRoundedEdges >= 5)
238 : {
239 0 : m_pCB_RoundedEdge->EnableTriState( false );
240 0 : m_pCB_RoundedEdge->Check(true);
241 : }
242 0 : else if(aProps.m_nRoundedEdges<0)
243 : {
244 0 : m_pCB_RoundedEdge->EnableTriState( false );
245 0 : m_pCB_RoundedEdge->SetState( TRISTATE_INDET );
246 : }
247 : else
248 : {
249 0 : m_pCB_RoundedEdge->EnableTriState( true );
250 0 : m_pCB_RoundedEdge->Check(false);
251 : }
252 0 : m_pCB_RoundedEdge->Enable( !m_pCB_ObjectLines->IsChecked() );
253 :
254 0 : updateScheme();
255 :
256 0 : m_bCommitToModel = true;
257 0 : m_bUpdateOtherControls = true;
258 0 : }
259 :
260 0 : void ThreeD_SceneAppearance_TabPage::updateScheme()
261 : {
262 0 : lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
263 :
264 0 : if( m_pLB_Scheme->GetEntryCount() == (POS_3DSCHEME_CUSTOM+1) )
265 : {
266 0 : m_pLB_Scheme->RemoveEntry(POS_3DSCHEME_CUSTOM);
267 0 : m_pLB_Scheme->SetDropDownLineCount(2);
268 : }
269 0 : switch( aProps.m_eScheme )
270 : {
271 : case ThreeDLookScheme_Simple:
272 0 : m_pLB_Scheme->SelectEntryPos( POS_3DSCHEME_SIMPLE );
273 0 : break;
274 : case ThreeDLookScheme_Realistic:
275 0 : m_pLB_Scheme->SelectEntryPos( POS_3DSCHEME_REALISTIC );
276 0 : break;
277 : case ThreeDLookScheme_Unknown:
278 : {
279 0 : m_pLB_Scheme->InsertEntry(m_aCustom,POS_3DSCHEME_CUSTOM);
280 0 : m_pLB_Scheme->SelectEntryPos( POS_3DSCHEME_CUSTOM );
281 0 : m_pLB_Scheme->SetDropDownLineCount(3);
282 : }
283 0 : break;
284 : }
285 0 : }
286 :
287 0 : IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectSchemeHdl)
288 : {
289 0 : if( !m_bUpdateOtherControls )
290 0 : return 0;
291 :
292 : {
293 : // locked controllers
294 0 : ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
295 :
296 0 : uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( m_xChartModel ) );
297 :
298 0 : if( m_pLB_Scheme->GetSelectEntryPos() == POS_3DSCHEME_REALISTIC )
299 0 : ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Realistic );
300 0 : else if( m_pLB_Scheme->GetSelectEntryPos() == POS_3DSCHEME_SIMPLE )
301 0 : ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Simple );
302 : else
303 : {
304 : OSL_FAIL( "Invalid Entry selected" );
305 0 : }
306 : }
307 :
308 : // update other controls
309 0 : initControlsFromModel();
310 0 : return 0;
311 : }
312 :
313 0 : IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectShading)
314 : {
315 0 : if( !m_bUpdateOtherControls )
316 0 : return 0;
317 :
318 0 : m_pCB_Shading->EnableTriState( false );
319 0 : applyShadeModeToModel();
320 0 : updateScheme();
321 0 : return 0;
322 : }
323 0 : IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines, CheckBox*, pCheckBox )
324 : {
325 0 : if( !m_bUpdateOtherControls )
326 0 : return 0;
327 :
328 0 : if( pCheckBox == m_pCB_ObjectLines )
329 : {
330 0 : m_pCB_ObjectLines->EnableTriState( false );
331 0 : m_bUpdateOtherControls = false;
332 0 : m_pCB_RoundedEdge->Enable( !m_pCB_ObjectLines->IsChecked() );
333 0 : if(!m_pCB_RoundedEdge->IsEnabled())
334 0 : m_pCB_RoundedEdge->Check(false);
335 0 : m_bUpdateOtherControls = true;
336 : }
337 : else
338 0 : m_pCB_RoundedEdge->EnableTriState( false );
339 0 : applyRoundedEdgeAndObjectLinesToModel();
340 0 : updateScheme();
341 0 : return 0;
342 : }
343 :
344 102 : } //namespace chart
345 :
346 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|