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