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