Salome HOME
Issue 0020638: EDF 1225 SMESH: Missing options in Color/Size menu
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Preferences_ColorDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_Preferences_ColorDlg.cxx
24 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "SMESHGUI_Preferences_ColorDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_Utils.h"
31
32 // SALOME GUI includes
33 #include <SUIT_Desktop.h>
34 #include <QtxColorButton.h>
35 #include <QtxDoubleSpinBox.h>
36 #include <QtxIntSpinBox.h>
37
38 // Qt includes
39 #include <QGroupBox>
40 #include <QLabel>
41 #include <QPushButton>
42 #include <QVBoxLayout>
43 #include <QHBoxLayout>
44 #include <QGridLayout>
45 #include <QSpinBox>
46 #include <QCheckBox>
47
48 #define SPACING 6
49 #define MARGIN  11
50
51 //=================================================================================
52 // function : SMESHGUI_Preferences_ColorDlg()
53 // purpose  : Constructs a SMESHGUI_Preferences_ColorDlg which is a child
54 //            of 'parent', with the name 'name' and widget flags set to 'f'
55 //            The dialog will by default be modeless, unless you
56 //            set'modal' to true to construct a modal dialog.
57 //=================================================================================
58 SMESHGUI_Preferences_ColorDlg::SMESHGUI_Preferences_ColorDlg( SMESHGUI* theModule )
59   : QDialog( SMESH::GetDesktop( theModule ) ),
60     mySMESHGUI( theModule )
61 {
62   setModal( true );
63   setWindowTitle( tr( "Preferences - Set Color" ) );
64   setSizeGripEnabled( true );
65
66   // -------------------------------
67   QVBoxLayout* topLayout = new QVBoxLayout( this );
68   topLayout->setSpacing( SPACING );
69   topLayout->setMargin( MARGIN );
70
71   // -------------------------------
72   QGroupBox* ButtonGroup1 = new QGroupBox( tr( "Elements" ), this );
73   QGridLayout* ButtonGroup1Layout = new QGridLayout( ButtonGroup1 );
74   ButtonGroup1Layout->setSpacing( SPACING );
75   ButtonGroup1Layout->setMargin( MARGIN );
76
77   QLabel* TextLabel_Fill = new QLabel( tr( "Fill" ), ButtonGroup1 );
78   btnFillColor = new QtxColorButton( ButtonGroup1 );
79
80   QLabel* TextLabel_BackFace = new QLabel( tr( "Back Face" ), ButtonGroup1 );
81   btnBackFaceColor = new QtxColorButton( ButtonGroup1 );
82
83   QLabel* TextLabel_Outine = new QLabel( tr( "Outline" ), ButtonGroup1 );
84   btnOutlineColor = new QtxColorButton( ButtonGroup1 );
85
86   QLabel* TextLabel_0DElements_Color = new QLabel( tr( "0D elements" ), ButtonGroup1 );
87   btn0DElementsColor = new QtxColorButton( ButtonGroup1 );
88
89   QLabel* TextLabel_0DElements_Size = new QLabel( tr( "Size of 0D elements" ), ButtonGroup1 );
90   SpinBox_0DElements_Size = new QSpinBox( ButtonGroup1 );
91   SpinBox_0DElements_Size->setRange( 1, 10 );
92   SpinBox_0DElements_Size->setSingleStep( 1 );
93   SpinBox_0DElements_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94   SpinBox_0DElements_Size->setButtonSymbols( QSpinBox::PlusMinus );
95
96   QLabel* TextLabel_Width = new QLabel( tr( "Width" ), ButtonGroup1 );
97   SpinBox_Width = new QSpinBox( ButtonGroup1 );
98   SpinBox_Width->setRange( 0, 5 );
99   SpinBox_Width->setSingleStep( 1 );
100   SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
101   SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
102
103   QLabel* TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1 );
104   SpinBox_Shrink = new QtxIntSpinBox( ButtonGroup1 );
105   SpinBox_Shrink->setRange( 20, 100 );
106   SpinBox_Shrink->setSingleStep( 1 );
107   SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
108   SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
109
110   ButtonGroup1Layout->addWidget( TextLabel_Fill,             0, 0 );
111   ButtonGroup1Layout->addWidget( btnFillColor,               0, 1 );
112   ButtonGroup1Layout->addWidget( TextLabel_BackFace,         0, 2 );
113   ButtonGroup1Layout->addWidget( btnBackFaceColor,           0, 3 );
114   ButtonGroup1Layout->addWidget( TextLabel_Outine,           1, 0 );
115   ButtonGroup1Layout->addWidget( btnOutlineColor,            1, 1 );
116   ButtonGroup1Layout->addWidget( TextLabel_0DElements_Color, 1, 2 );
117   ButtonGroup1Layout->addWidget( btn0DElementsColor,         1, 3 );
118   ButtonGroup1Layout->addWidget( TextLabel_0DElements_Size,  2, 0 );
119   ButtonGroup1Layout->addWidget( SpinBox_0DElements_Size,    2, 1 );
120   ButtonGroup1Layout->addWidget( TextLabel_Width,            3, 0 );
121   ButtonGroup1Layout->addWidget( SpinBox_Width,              3, 1 );
122   ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff,      3, 2 );
123   ButtonGroup1Layout->addWidget( SpinBox_Shrink,             3, 3 );
124
125   // -------------------------------
126   QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
127   QHBoxLayout* ButtonGroup2Layout = new QHBoxLayout( ButtonGroup2 );
128   ButtonGroup2Layout->setSpacing( SPACING );
129   ButtonGroup2Layout->setMargin( MARGIN );
130
131   QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
132   btnNodeColor = new QtxColorButton( ButtonGroup2 );
133
134   QLabel* TextLabel_Nodes_Size = new QLabel( tr( "Size" ), ButtonGroup2 );
135   SpinBox_Nodes_Size = new QSpinBox( ButtonGroup2 );
136   SpinBox_Nodes_Size->setRange( 0, 5 );
137   SpinBox_Nodes_Size->setSingleStep( 1 );
138   SpinBox_Nodes_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
139   SpinBox_Nodes_Size->setButtonSymbols( QSpinBox::PlusMinus );
140
141   ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color );
142   ButtonGroup2Layout->addWidget( btnNodeColor );
143   ButtonGroup2Layout->addWidget( TextLabel_Nodes_Size );
144   ButtonGroup2Layout->addWidget( SpinBox_Nodes_Size );
145
146   // -------------------------------
147   QGroupBox* ButtonGroup3 = new QGroupBox( tr( "Orientation of faces" ), this );
148   QGridLayout* ButtonGroup3Layout = new QGridLayout( ButtonGroup3 );
149   ButtonGroup3Layout->setSpacing( SPACING );
150   ButtonGroup3Layout->setMargin( MARGIN );
151
152   QLabel* TextLabel_Orientation_Color = new QLabel( tr( "Color" ), ButtonGroup3 );
153   btnOrientationColor = new QtxColorButton( ButtonGroup3 );
154
155   QLabel* TextLabel_Orientation_Scale = new QLabel( tr( "Scale" ), ButtonGroup3 );
156   SpinBox_Orientation_Scale = new QtxDoubleSpinBox( ButtonGroup3 );
157   SpinBox_Orientation_Scale->setRange( 0.05, 0.5 );
158   SpinBox_Orientation_Scale->setSingleStep( 0.05 );
159   SpinBox_Orientation_Scale->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
160   SpinBox_Orientation_Scale->setButtonSymbols( QSpinBox::PlusMinus );
161
162   CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D vectors" ), ButtonGroup3 );
163
164   ButtonGroup3Layout->addWidget( TextLabel_Orientation_Color,    0, 0 );
165   ButtonGroup3Layout->addWidget( btnOrientationColor,            0, 1 );
166   ButtonGroup3Layout->addWidget( TextLabel_Orientation_Scale,    0, 2 );
167   ButtonGroup3Layout->addWidget( SpinBox_Orientation_Scale,      0, 3 );
168   ButtonGroup3Layout->addWidget( CheckBox_Orientation_3DVectors, 1, 0, 1, 4 );
169
170   // -------------------------------
171   QGroupBox* GroupButtons = new QGroupBox( this );
172   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
173   GroupButtonsLayout->setSpacing( SPACING );
174   GroupButtonsLayout->setMargin( MARGIN );
175
176   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
177   buttonOk->setAutoDefault( true );
178   buttonOk->setDefault( true );
179
180   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
181   buttonCancel->setAutoDefault( true );
182
183   GroupButtonsLayout->addWidget( buttonOk );
184   GroupButtonsLayout->addSpacing( 10 );
185   GroupButtonsLayout->addStretch();
186   GroupButtonsLayout->addWidget( buttonCancel );
187
188   // -------------------------------
189   topLayout->addWidget( ButtonGroup1 );
190   topLayout->addWidget( ButtonGroup2 );
191   topLayout->addWidget( ButtonGroup3 );
192   topLayout->addWidget( GroupButtons );
193
194   // -------------------------------
195   mySMESHGUI->SetActiveDialogBox( this );
196
197   /* signals and slots connections */
198   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
199   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
200
201   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
202            this,       SLOT( DeactivateActiveDialog() ) );
203   /* to close dialog if study change */
204   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
205            this,       SLOT( ClickOnCancel() ) );
206 }
207
208 //=================================================================================
209 // function : ~SMESHGUI_Preferences_ColorDlg()
210 // purpose  : Destructor
211 //=================================================================================
212 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
213 {
214 }
215
216 //=================================================================================
217 // function : ClickOnOk()
218 // purpose  :
219 //=================================================================================
220 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
221 {
222   mySMESHGUI->ResetState();
223   accept();
224 }
225
226 //=================================================================================
227 // function : ClickOnCancel()
228 // purpose  :
229 //=================================================================================
230 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
231 {
232   mySMESHGUI->ResetState();
233   reject();
234 }
235
236 //=================================================================================
237 // function : DeactivateActiveDialog()
238 // purpose  :
239 //=================================================================================
240 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
241 {
242 }
243
244 //=================================================================================
245 // function : closeEvent()
246 // purpose  :
247 //=================================================================================
248 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
249 {
250   ClickOnCancel(); /* same than click on cancel button */
251 }
252
253 //=================================================================================
254 // function : ActivateThisDialog()
255 // purpose  :
256 //=================================================================================
257 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
258 {
259   /* Emit a signal to deactivate any active dialog */
260   mySMESHGUI->EmitSignalDeactivateDialog();
261 }
262
263 //=================================================================================
264 // function : SetColor()
265 // purpose  :
266 //=================================================================================
267 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
268 {
269   switch ( type ) {
270   case 1 : btnFillColor->setColor( color );        break; // fill
271   case 2 : btnOutlineColor->setColor( color );     break; // outline
272   case 3 : btnNodeColor->setColor( color );        break; // node
273   case 4 : btnBackFaceColor->setColor( color );    break; // back face
274   case 5 : btn0DElementsColor->setColor( color );  break; // 0d elements
275   case 6 : btnOrientationColor->setColor( color ); break; // orientation of faces
276   default: break;
277   }
278 }
279
280 //=================================================================================
281 // function : GetColor()
282 // purpose  :
283 //=================================================================================
284 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
285 {
286   QColor color;
287   switch ( type ) {
288   case 1 : color = btnFillColor->color();        break; // fill
289   case 2 : color = btnOutlineColor->color();     break; // outline
290   case 3 : color = btnNodeColor->color();        break; // node
291   case 4 : color = btnBackFaceColor->color();    break; // back face
292   case 5 : color = btn0DElementsColor->color();  break; // 0d elements
293   case 6 : color = btnOrientationColor->color(); break; // orientation of faces
294   default: break;
295   }
296   return color;
297 }
298
299 //=================================================================================
300 // function : SetIntValue()
301 // purpose  :
302 //=================================================================================
303 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
304 {
305   switch ( type ) {
306   case 1 : SpinBox_Width->setValue( value );           break; // width
307   case 2 : SpinBox_Nodes_Size->setValue( value );      break; // nodes size = value; break;
308   case 3 : SpinBox_Shrink->setValue( value );          break; // shrink coeff
309   case 4 : SpinBox_0DElements_Size->setValue( value ); break; // 0d elements
310   default: break;
311   }
312 }
313
314 //=================================================================================
315 // function : GetIntValue()
316 // purpose  :
317 //=================================================================================
318 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
319 {
320   int res = 0;
321   switch ( type ) {
322   case 1 : res = SpinBox_Width->value();           break; // width
323   case 2 : res = SpinBox_Nodes_Size->value();      break; // nodes size
324   case 3 : res = SpinBox_Shrink->value();          break; // shrink coeff
325   case 4 : res = SpinBox_0DElements_Size->value(); break; // 0d elements
326   default: break;
327   }
328   return res;
329 }
330
331 //=================================================================================
332 // function : SetDoubleValue()
333 // purpose  :
334 //=================================================================================
335 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
336 {
337   switch ( type ) {
338   case 1 : SpinBox_Orientation_Scale->setValue( value ); break; // orientation scale
339   default: break;
340   }
341 }
342
343 //=================================================================================
344 // function : GetDoubleValue()
345 // purpose  :
346 //=================================================================================
347 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
348 {
349   double res = 0;
350   switch ( type ) {
351   case 1 : res = SpinBox_Orientation_Scale->value(); break; // orientation scale
352   default: break;
353   }
354   return res;
355 }
356
357 //=================================================================================
358 // function : SetBooleanValue()
359 // purpose  :
360 //=================================================================================
361 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
362 {
363   switch ( type ) {
364   case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break; // 3D vectors
365   default: break;
366   }
367 }
368
369 //=================================================================================
370 // function : GetBooleanValue()
371 // purpose  :
372 //=================================================================================
373 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
374 {
375   bool res = false;
376   switch ( type ) {
377   case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break; // 3D vectors
378   default: break;
379   }
380   return res;
381 }