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