1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 
27 #include "tp_3D_SceneAppearance.hxx"
28 #include "tp_3D_SceneAppearance.hrc"
29 #include "ResId.hxx"
30 #include "Strings.hrc"
31 #include "NoWarningThisInCTOR.hxx"
32 #include "ChartModelHelper.hxx"
33 #include "ThreeDHelper.hxx"
34 #include "macros.hxx"
35 #include <rtl/math.hxx>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 
38 using namespace ::com::sun::star;
39 
40 namespace
41 {
42 
43 struct lcl_ModelProperties
44 {
45     drawing::ShadeMode        m_aShadeMode;
46     sal_Int32                 m_nRoundedEdges;
47     sal_Int32                 m_nObjectLines;
48     ::chart::ThreeDLookScheme m_eScheme;
49 
lcl_ModelProperties__anon76017dfe0111::lcl_ModelProperties50     lcl_ModelProperties() :
51             m_nRoundedEdges(-1),
52             m_nObjectLines(-1),
53             m_eScheme(::chart::ThreeDLookScheme_Unknown)
54     {}
55 };
56 
lcl_getPropertiesFromModel(uno::Reference<frame::XModel> & xModel)57 lcl_ModelProperties lcl_getPropertiesFromModel( uno::Reference< frame::XModel > & xModel )
58 {
59     lcl_ModelProperties aProps;
60     try
61     {
62         uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( xModel ) );
63         uno::Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY_THROW );
64         xDiaProp->getPropertyValue( C2U("D3DSceneShadeMode")) >>= aProps.m_aShadeMode;
65         ::chart::ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram, aProps.m_nRoundedEdges, aProps.m_nObjectLines );
66         aProps.m_eScheme = ::chart::ThreeDHelper::detectScheme( xDiagram );
67     }
68     catch( const uno::Exception & ex )
69     {
70         ASSERT_EXCEPTION( ex );
71     }
72     return aProps;
73 }
74 
lcl_setShadeModeAtModel(uno::Reference<frame::XModel> & xModel,drawing::ShadeMode aShadeMode)75 void lcl_setShadeModeAtModel( uno::Reference< frame::XModel > & xModel, drawing::ShadeMode aShadeMode )
76 {
77     try
78     {
79         uno::Reference< beans::XPropertySet > xDiaProp(
80             ::chart::ChartModelHelper::findDiagram( xModel ), uno::UNO_QUERY_THROW );
81         xDiaProp->setPropertyValue( C2U("D3DSceneShadeMode"), uno::makeAny( aShadeMode ));
82     }
83     catch( const uno::Exception & ex )
84     {
85         ASSERT_EXCEPTION( ex );
86     }
87 }
88 
89 } // anonymous namespace
90 
91 //.............................................................................
92 namespace chart
93 {
94 //.............................................................................
95 
96 #define POS_3DSCHEME_SIMPLE    0
97 #define POS_3DSCHEME_REALISTIC 1
98 #define POS_3DSCHEME_CUSTOM 2
99 
ThreeD_SceneAppearance_TabPage(Window * pWindow,const uno::Reference<frame::XModel> & xChartModel,ControllerLockHelper & rControllerLockHelper)100 ThreeD_SceneAppearance_TabPage::ThreeD_SceneAppearance_TabPage(
101       Window* pWindow
102     , const uno::Reference< frame::XModel > & xChartModel
103     , ControllerLockHelper & rControllerLockHelper )
104                 : TabPage 	        ( pWindow, SchResId( TP_3D_SCENEAPPEARANCE ) )
105                 , m_xChartModel     ( xChartModel )
106                 , m_aFT_Scheme      ( this, SchResId( FT_SCHEME ) )
107                 , m_aLB_Scheme      ( this, SchResId( LB_SCHEME ) )
108                 , m_aFL_Seperator   ( this, SchResId( FL_SEPERATOR ) )
109                 , m_aCB_Shading	    ( this, SchResId( CB_SHADING ) )
110                 , m_aCB_ObjectLines ( this, SchResId( CB_OBJECTLINES ) )
111                 , m_aCB_RoundedEdge ( this, SchResId( CB_ROUNDEDEDGE ) )
112                 , m_bUpdateOtherControls( true )
113                 , m_bCommitToModel( true )
114                 , m_rControllerLockHelper( rControllerLockHelper )
115 {
116 	FreeResource();
117     m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_SIMPLE)),POS_3DSCHEME_SIMPLE);
118     m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_REALISTIC)),POS_3DSCHEME_REALISTIC);
119     m_aLB_Scheme.SetDropDownLineCount(2);
120 
121     m_aLB_Scheme.SetSelectHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectSchemeHdl ) );
122 
123     m_aCB_RoundedEdge.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
124     m_aCB_Shading.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectShading ) );
125     m_aCB_ObjectLines.SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
126 
127     m_aCB_RoundedEdge.EnableTriState( sal_True );
128     m_aCB_Shading.EnableTriState( sal_True );
129     m_aCB_ObjectLines.EnableTriState( sal_True );
130 
131     initControlsFromModel();
132 }
133 
~ThreeD_SceneAppearance_TabPage()134 ThreeD_SceneAppearance_TabPage::~ThreeD_SceneAppearance_TabPage()
135 {}
136 
ActivatePage()137 void ThreeD_SceneAppearance_TabPage::ActivatePage()
138 {
139     updateScheme();
140 }
141 
commitPendingChanges()142 void ThreeD_SceneAppearance_TabPage::commitPendingChanges()
143 {
144 }
145 
applyRoundedEdgeAndObjectLinesToModel()146 void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
147 {
148     if(!m_bCommitToModel)
149         return;
150 
151     sal_Int32 nObjectLines = -1;
152 
153     switch( m_aCB_ObjectLines.GetState())
154     {
155         case STATE_NOCHECK:
156             nObjectLines = 0;
157             break;
158         case STATE_CHECK:
159             nObjectLines = 1;
160             break;
161         case STATE_DONTKNOW:
162             nObjectLines = -1;
163             break;
164     }
165 
166     sal_Int32 nCurrentRoundedEdges = -1;
167     switch( m_aCB_RoundedEdge.GetState() )
168     {
169         case STATE_NOCHECK:
170             nCurrentRoundedEdges = 0;
171             break;
172         case STATE_CHECK:
173             nCurrentRoundedEdges = 5;
174             break;
175         case STATE_DONTKNOW:
176             nCurrentRoundedEdges = -1;
177             break;
178     }
179 
180     // /-- locked controllers
181     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
182     ThreeDHelper::setRoundedEdgesAndObjectLines(
183         ::chart::ChartModelHelper::findDiagram( m_xChartModel ), nCurrentRoundedEdges, nObjectLines );
184     // \-- locked controllers
185 }
186 
applyShadeModeToModel()187 void ThreeD_SceneAppearance_TabPage::applyShadeModeToModel()
188 {
189     if(!m_bCommitToModel)
190         return;
191 
192     drawing::ShadeMode aShadeMode = drawing::ShadeMode_PHONG;
193 
194     switch( m_aCB_Shading.GetState())
195     {
196         case STATE_NOCHECK:
197             aShadeMode = drawing::ShadeMode_FLAT;
198             break;
199         case STATE_CHECK:
200             aShadeMode = drawing::ShadeMode_SMOOTH;
201             break;
202         case STATE_DONTKNOW:
203             // nothing
204             break;
205     }
206 
207     lcl_setShadeModeAtModel( m_xChartModel, aShadeMode );
208 }
209 
initControlsFromModel()210 void ThreeD_SceneAppearance_TabPage::initControlsFromModel()
211 {
212     m_bCommitToModel = false;
213     m_bUpdateOtherControls = false;
214 
215     lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
216 
217     if(aProps.m_aShadeMode == drawing::ShadeMode_FLAT)
218     {
219         m_aCB_Shading.EnableTriState( sal_False );
220         m_aCB_Shading.Check(sal_False);
221     }
222     else if(aProps.m_aShadeMode == drawing::ShadeMode_SMOOTH)
223     {
224         m_aCB_Shading.EnableTriState( sal_False );
225         m_aCB_Shading.Check(sal_True);
226     }
227     else
228     {
229         m_aCB_Shading.EnableTriState( sal_True );
230         m_aCB_Shading.SetState( STATE_DONTKNOW );
231     }
232 
233     if(aProps.m_nObjectLines == 0)
234     {
235         m_aCB_ObjectLines.EnableTriState( sal_False );
236         m_aCB_ObjectLines.Check(sal_False);
237     }
238     else if(aProps.m_nObjectLines==1)
239     {
240         m_aCB_ObjectLines.EnableTriState( sal_False );
241         m_aCB_ObjectLines.Check(sal_True);
242     }
243     else
244     {
245         m_aCB_ObjectLines.EnableTriState( sal_True );
246         m_aCB_ObjectLines.SetState( STATE_DONTKNOW );
247     }
248 
249     if(aProps.m_nRoundedEdges >= 5)
250     {
251         m_aCB_RoundedEdge.EnableTriState( sal_False );
252         m_aCB_RoundedEdge.Check(sal_True);
253     }
254     else if(aProps.m_nRoundedEdges<0)
255     {
256         m_aCB_RoundedEdge.EnableTriState( sal_False );
257         m_aCB_RoundedEdge.SetState( STATE_DONTKNOW );
258     }
259     else
260     {
261         m_aCB_RoundedEdge.EnableTriState( sal_True );
262         m_aCB_RoundedEdge.Check(sal_False);
263     }
264     m_aCB_RoundedEdge.Enable( !m_aCB_ObjectLines.IsChecked() );
265 
266     updateScheme();
267 
268     m_bCommitToModel = true;
269     m_bUpdateOtherControls = true;
270 }
271 
updateScheme()272 void ThreeD_SceneAppearance_TabPage::updateScheme()
273 {
274     lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
275 
276     if( m_aLB_Scheme.GetEntryCount() == (POS_3DSCHEME_CUSTOM+1) )
277     {
278         m_aLB_Scheme.RemoveEntry(POS_3DSCHEME_CUSTOM);
279         m_aLB_Scheme.SetDropDownLineCount(2);
280     }
281     switch( aProps.m_eScheme )
282     {
283         case ThreeDLookScheme_Simple:
284             m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_SIMPLE );
285             break;
286         case ThreeDLookScheme_Realistic:
287             m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_REALISTIC );
288             break;
289         case ThreeDLookScheme_Unknown:
290             {
291                 m_aLB_Scheme.InsertEntry(String(SchResId(STR_3DSCHEME_CUSTOM)),POS_3DSCHEME_CUSTOM);
292                 m_aLB_Scheme.SelectEntryPos( POS_3DSCHEME_CUSTOM );
293                 m_aLB_Scheme.SetDropDownLineCount(3);
294             }
295             break;
296     }
297 }
298 
IMPL_LINK(ThreeD_SceneAppearance_TabPage,SelectSchemeHdl,void *,EMPTYARG)299 IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectSchemeHdl, void*, EMPTYARG )
300 {
301     if( !m_bUpdateOtherControls )
302         return 0;
303 
304     {
305         // /-- locked controllers
306         ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
307 
308         uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( m_xChartModel ) );
309 
310         if( m_aLB_Scheme.GetSelectEntryPos() == POS_3DSCHEME_REALISTIC )
311             ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Realistic );
312         else if( m_aLB_Scheme.GetSelectEntryPos() == POS_3DSCHEME_SIMPLE )
313             ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Simple );
314         else
315         {
316             OSL_ENSURE( false, "Invalid Entry selected" );
317         }
318         // \-- locked controllers
319     }
320 
321     // update other controls
322     initControlsFromModel();
323     return 0;
324 }
325 
IMPL_LINK(ThreeD_SceneAppearance_TabPage,SelectShading,void *,EMPTYARG)326 IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectShading, void*, EMPTYARG )
327 {
328     if( !m_bUpdateOtherControls )
329         return 0;
330 
331     m_aCB_Shading.EnableTriState( sal_False );
332     applyShadeModeToModel();
333     updateScheme();
334     return 0;
335 }
IMPL_LINK(ThreeD_SceneAppearance_TabPage,SelectRoundedEdgeOrObjectLines,CheckBox *,pCheckBox)336 IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines, CheckBox*, pCheckBox )
337 {
338     if( !m_bUpdateOtherControls )
339         return 0;
340 
341     if( pCheckBox == &m_aCB_ObjectLines )
342     {
343         m_aCB_ObjectLines.EnableTriState( sal_False );
344         m_bUpdateOtherControls = false;
345         m_aCB_RoundedEdge.Enable( !m_aCB_ObjectLines.IsChecked() );
346         if(!m_aCB_RoundedEdge.IsEnabled())
347             m_aCB_RoundedEdge.Check(sal_False);
348         m_bUpdateOtherControls = true;
349     }
350     else
351         m_aCB_RoundedEdge.EnableTriState( sal_False );
352     applyRoundedEdgeAndObjectLinesToModel();
353     updateScheme();
354     return 0;
355 }
356 
357 //.............................................................................
358 } //namespace chart
359 //.............................................................................
360