Salome HOME
9a01ad34e7719e6bf154bced7de93910ee091f6d
[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_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32
33 // SALOME GUI includes
34 #include <SUIT_Desktop.h>
35 #include <QtxColorButton.h>
36 #include <VTKViewer_MarkerWidget.h>
37 #include <SalomeApp_IntSpinBox.h>
38
39 // Qt includes
40 #include <QGroupBox>
41 #include <QLabel>
42 #include <QPushButton>
43 #include <QVBoxLayout>
44 #include <QHBoxLayout>
45 #include <QGridLayout>
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 SalomeApp_IntSpinBox( ButtonGroup1 );
91   SpinBox_0DElements_Size->setAcceptNames( false ); // No Notebook variables allowed
92   SpinBox_0DElements_Size->setRange( 1, 10 );
93   SpinBox_0DElements_Size->setSingleStep( 1 );
94   SpinBox_0DElements_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
95   SpinBox_0DElements_Size->setButtonSymbols( QSpinBox::PlusMinus );
96
97   QLabel* TextLabel_Width = new QLabel( tr( "Width" ), ButtonGroup1 );
98   SpinBox_Width = new SalomeApp_IntSpinBox( ButtonGroup1 );
99   SpinBox_Width->setAcceptNames( false ); // No Notebook variables allowed
100   SpinBox_Width->setRange( 0, 5 );
101   SpinBox_Width->setSingleStep( 1 );
102   SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
103   SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
104
105   QLabel* TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1 );
106   SpinBox_Shrink = new SalomeApp_IntSpinBox( ButtonGroup1 );
107   SpinBox_Shrink->setAcceptNames( false ); // No Notebook variables allowed
108   SpinBox_Shrink->setRange( 20, 100 );
109   SpinBox_Shrink->setSingleStep( 1 );
110   SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
111   SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
112
113   ButtonGroup1Layout->addWidget( TextLabel_Fill,             0, 0 );
114   ButtonGroup1Layout->addWidget( btnFillColor,               0, 1 );
115   ButtonGroup1Layout->addWidget( TextLabel_BackFace,         0, 2 );
116   ButtonGroup1Layout->addWidget( btnBackFaceColor,           0, 3 );
117   ButtonGroup1Layout->addWidget( TextLabel_Outine,           1, 0 );
118   ButtonGroup1Layout->addWidget( btnOutlineColor,            1, 1 );
119   ButtonGroup1Layout->addWidget( TextLabel_0DElements_Color, 1, 2 );
120   ButtonGroup1Layout->addWidget( btn0DElementsColor,         1, 3 );
121   ButtonGroup1Layout->addWidget( TextLabel_0DElements_Size,  2, 0 );
122   ButtonGroup1Layout->addWidget( SpinBox_0DElements_Size,    2, 1 );
123   ButtonGroup1Layout->addWidget( TextLabel_Width,            3, 0 );
124   ButtonGroup1Layout->addWidget( SpinBox_Width,              3, 1 );
125   ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff,      3, 2 );
126   ButtonGroup1Layout->addWidget( SpinBox_Shrink,             3, 3 );
127
128   // -------------------------------
129   QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
130   QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2 );
131   ButtonGroup2Layout->setSpacing( SPACING );
132   ButtonGroup2Layout->setMargin( MARGIN );
133
134   QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
135   btnNodeColor = new QtxColorButton( ButtonGroup2 );
136
137   QGroupBox* MarkerGroup = new QGroupBox( tr( "Marker" ), ButtonGroup2 );
138   QVBoxLayout* MarkerGroupLayout = new QVBoxLayout( MarkerGroup );
139   MarkerGroupLayout->setSpacing( 0 );
140   MarkerGroupLayout->setMargin( 0 );
141
142   MarkerWidget = new VTKViewer_MarkerWidget( MarkerGroup );
143
144   MarkerGroupLayout->addWidget( MarkerWidget );
145
146   ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color, 0, 0 );
147   ButtonGroup2Layout->addWidget( btnNodeColor,          0, 1 );
148   ButtonGroup2Layout->addWidget( MarkerGroup,           1, 0, 1, 3 );
149   ButtonGroup2Layout->setColumnStretch( 2, 1 );
150
151   // -------------------------------
152   QGroupBox* ButtonGroup3 = new QGroupBox( tr( "Orientation of faces" ), this );
153   QGridLayout* ButtonGroup3Layout = new QGridLayout( ButtonGroup3 );
154   ButtonGroup3Layout->setSpacing( SPACING );
155   ButtonGroup3Layout->setMargin( MARGIN );
156
157   QLabel* TextLabel_Orientation_Color = new QLabel( tr( "Color" ), ButtonGroup3 );
158   btnOrientationColor = new QtxColorButton( ButtonGroup3 );
159
160   QLabel* TextLabel_Orientation_Scale = new QLabel( tr( "Scale" ), ButtonGroup3 );
161   SpinBox_Orientation_Scale = new SMESHGUI_SpinBox( ButtonGroup3 );
162   SpinBox_Orientation_Scale->setAcceptNames( false ); // No Notebook variables allowed
163   SpinBox_Orientation_Scale->RangeStepAndValidator( .05, .5, .05, "parametric_precision" );
164   SpinBox_Orientation_Scale->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
165   SpinBox_Orientation_Scale->setButtonSymbols( QSpinBox::PlusMinus );
166
167   CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D vectors" ), ButtonGroup3 );
168
169   ButtonGroup3Layout->addWidget( TextLabel_Orientation_Color,    0, 0 );
170   ButtonGroup3Layout->addWidget( btnOrientationColor,            0, 1 );
171   ButtonGroup3Layout->addWidget( TextLabel_Orientation_Scale,    0, 2 );
172   ButtonGroup3Layout->addWidget( SpinBox_Orientation_Scale,      0, 3 );
173   ButtonGroup3Layout->addWidget( CheckBox_Orientation_3DVectors, 1, 0, 1, 4 );
174
175   // -------------------------------
176   QGroupBox* GroupButtons = new QGroupBox( this );
177   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
178   GroupButtonsLayout->setSpacing( SPACING );
179   GroupButtonsLayout->setMargin( MARGIN );
180
181   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
182   buttonOk->setAutoDefault( true );
183   buttonOk->setDefault( true );
184
185   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
186   buttonCancel->setAutoDefault( true );
187
188   GroupButtonsLayout->addWidget( buttonOk );
189   GroupButtonsLayout->addSpacing( 10 );
190   GroupButtonsLayout->addStretch();
191   GroupButtonsLayout->addWidget( buttonCancel );
192
193   // -------------------------------
194   topLayout->addWidget( ButtonGroup1 );
195   topLayout->addWidget( ButtonGroup2 );
196   topLayout->addWidget( ButtonGroup3 );
197   topLayout->addWidget( GroupButtons );
198
199   // -------------------------------
200   mySMESHGUI->SetActiveDialogBox( this );
201
202   /* signals and slots connections */
203   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
204   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
205
206   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
207            this,       SLOT( DeactivateActiveDialog() ) );
208   /* to close dialog if study change */
209   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
210            this,       SLOT( ClickOnCancel() ) );
211 }
212
213 //=================================================================================
214 // function : ~SMESHGUI_Preferences_ColorDlg()
215 // purpose  : Destructor
216 //=================================================================================
217 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
218 {
219 }
220
221 //=================================================================================
222 // function : ClickOnOk()
223 // purpose  :
224 //=================================================================================
225 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
226 {
227   mySMESHGUI->ResetState();
228   accept();
229 }
230
231 //=================================================================================
232 // function : ClickOnCancel()
233 // purpose  :
234 //=================================================================================
235 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
236 {
237   mySMESHGUI->ResetState();
238   reject();
239 }
240
241 //=================================================================================
242 // function : DeactivateActiveDialog()
243 // purpose  :
244 //=================================================================================
245 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
246 {
247 }
248
249 //=================================================================================
250 // function : closeEvent()
251 // purpose  :
252 //=================================================================================
253 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
254 {
255   ClickOnCancel(); /* same than click on cancel button */
256 }
257
258 //=================================================================================
259 // function : ActivateThisDialog()
260 // purpose  :
261 //=================================================================================
262 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
263 {
264   /* Emit a signal to deactivate any active dialog */
265   mySMESHGUI->EmitSignalDeactivateDialog();
266 }
267
268 //=================================================================================
269 // function : SetColor()
270 // purpose  :
271 //=================================================================================
272 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
273 {
274   switch ( type ) {
275   case 1 : btnFillColor->setColor( color );        break; // fill
276   case 2 : btnOutlineColor->setColor( color );     break; // outline
277   case 3 : btnNodeColor->setColor( color );        break; // node
278   case 4 : btnBackFaceColor->setColor( color );    break; // back face
279   case 5 : btn0DElementsColor->setColor( color );  break; // 0d elements
280   case 6 : btnOrientationColor->setColor( color ); break; // orientation of faces
281   default: break;
282   }
283 }
284
285 //=================================================================================
286 // function : GetColor()
287 // purpose  :
288 //=================================================================================
289 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
290 {
291   QColor color;
292   switch ( type ) {
293   case 1 : color = btnFillColor->color();        break; // fill
294   case 2 : color = btnOutlineColor->color();     break; // outline
295   case 3 : color = btnNodeColor->color();        break; // node
296   case 4 : color = btnBackFaceColor->color();    break; // back face
297   case 5 : color = btn0DElementsColor->color();  break; // 0d elements
298   case 6 : color = btnOrientationColor->color(); break; // orientation of faces
299   default: break;
300   }
301   return color;
302 }
303
304 //=================================================================================
305 // function : SetIntValue()
306 // purpose  :
307 //=================================================================================
308 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
309 {
310   switch ( type ) {
311   case 1 : SpinBox_Width->setValue( value );           break; // width
312   case 2 : SpinBox_Shrink->setValue( value );          break; // shrink coeff
313   case 3 : SpinBox_0DElements_Size->setValue( value ); break; // 0d elements
314   default: break;
315   }
316 }
317
318 //=================================================================================
319 // function : GetIntValue()
320 // purpose  :
321 //=================================================================================
322 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
323 {
324   int res = 0;
325   switch ( type ) {
326   case 1 : res = SpinBox_Width->value();           break; // width
327   case 2 : res = SpinBox_Shrink->value();          break; // shrink coeff
328   case 3 : res = SpinBox_0DElements_Size->value(); break; // 0d elements
329   default: break;
330   }
331   return res;
332 }
333
334 //=================================================================================
335 // function : SetDoubleValue()
336 // purpose  :
337 //=================================================================================
338 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
339 {
340   switch ( type ) {
341   case 1 : SpinBox_Orientation_Scale->setValue( value ); break; // orientation scale
342   default: break;
343   }
344 }
345
346 //=================================================================================
347 // function : GetDoubleValue()
348 // purpose  :
349 //=================================================================================
350 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
351 {
352   double res = 0;
353   switch ( type ) {
354   case 1 : res = SpinBox_Orientation_Scale->value(); break; // orientation scale
355   default: break;
356   }
357   return res;
358 }
359
360 //=================================================================================
361 // function : SetBooleanValue()
362 // purpose  :
363 //=================================================================================
364 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
365 {
366   switch ( type ) {
367   case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break; // 3D vectors
368   default: break;
369   }
370 }
371
372 //=================================================================================
373 // function : GetBooleanValue()
374 // purpose  :
375 //=================================================================================
376 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
377 {
378   bool res = false;
379   switch ( type ) {
380   case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break; // 3D vectors
381   default: break;
382   }
383   return res;
384 }
385
386 //=================================================================================
387 // function : setCustomMarkerMap()
388 // purpose  :
389 //=================================================================================
390 void SMESHGUI_Preferences_ColorDlg::setCustomMarkerMap( VTK::MarkerMap theMarkerMap )
391 {
392   MarkerWidget->setCustomMarkerMap( theMarkerMap );
393 }
394
395 //=================================================================================
396 // function : getCustomMarkerMap()
397 // purpose  :
398 //=================================================================================
399 VTK::MarkerMap SMESHGUI_Preferences_ColorDlg::getCustomMarkerMap()
400 {
401   return MarkerWidget->getCustomMarkerMap();
402 }
403
404 //=================================================================================
405 // function : setStandardMarker()
406 // purpose  :
407 //=================================================================================
408 void SMESHGUI_Preferences_ColorDlg::setStandardMarker( VTK::MarkerType theMarkerType,
409                                                        VTK::MarkerScale theMarkerScale )
410 {
411   MarkerWidget->setStandardMarker( theMarkerType, theMarkerScale );
412 }
413
414 //=================================================================================
415 // function : setCustomMarker()
416 // purpose  :
417 //=================================================================================
418 void SMESHGUI_Preferences_ColorDlg::setCustomMarker( int theId )
419 {
420   MarkerWidget->setCustomMarker( theId );
421 }
422
423 //=================================================================================
424 // function : getMarkerType()
425 // purpose  :
426 //=================================================================================
427 VTK::MarkerType SMESHGUI_Preferences_ColorDlg::getMarkerType() const
428 {
429   return MarkerWidget->getMarkerType();
430 }
431
432 //=================================================================================
433 // function : getStandardMarkerScale()
434 // purpose  :
435 //=================================================================================
436 VTK::MarkerScale SMESHGUI_Preferences_ColorDlg::getStandardMarkerScale() const
437 {
438   return MarkerWidget->getStandardMarkerScale();
439 }
440
441 //=================================================================================
442 // function : getCustomMarkerID()
443 // purpose  :
444 //=================================================================================
445 int SMESHGUI_Preferences_ColorDlg::getCustomMarkerID() const
446 {
447   return MarkerWidget->getCustomMarkerID();
448 }