1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_Preferences_ColorDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
28 #include "SMESHGUI_Preferences_ColorDlg.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_Utils.h"
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>
47 #include <QPushButton>
48 #include <QVBoxLayout>
49 #include <QHBoxLayout>
50 #include <QGridLayout>
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 )
69 setWindowTitle( tr( "DIALOG_TITLE" ) );
70 setSizeGripEnabled( true );
72 // -------------------------------
73 QVBoxLayout* topLayout = new QVBoxLayout( this );
74 topLayout->setSpacing( SPACING );
75 topLayout->setMargin( MARGIN );
77 // -------------------------------
78 QGroupBox* ButtonGroup1 = new QGroupBox( tr( "GRP_ELEMENTS" ), this );
79 QGridLayout* ButtonGroup1Layout = new QGridLayout( ButtonGroup1 );
80 ButtonGroup1Layout->setSpacing( SPACING );
81 ButtonGroup1Layout->setMargin( MARGIN );
83 QLabel* TextLabel_Fill = new QLabel( tr( "SURFACE_COLOR_LBL" ), ButtonGroup1 );
85 toolSurfColor = new QtxBiColorTool(ButtonGroup1);
86 toolSurfColor->setText( tr( "BACKSURFACE_COLOR_LBL" ));
88 QLabel* TextLabel_Outline = new QLabel( tr( "OUTLINE_COLOR_LBL" ), ButtonGroup1 );
89 btnOutlineColor = new QtxColorButton( ButtonGroup1 );
91 QLabel* TextLabel_Wireframe = new QLabel( tr( "WIREFRAME_COLOR_LBL" ), ButtonGroup1 );
92 btnWireframeColor = new QtxColorButton( ButtonGroup1 );
94 QLabel* TextLabel_0DElements_Color = new QLabel( tr( "0D_ELEMENTS_COLOR_LBL" ), ButtonGroup1 );
95 btn0DElementsColor = new QtxColorButton( ButtonGroup1 );
97 QLabel* TextLabel_0DElements_Size = new QLabel( tr( "0D_ELEMENTS_SIZE_LBL" ), ButtonGroup1 );
98 SpinBox_0DElements_Size = new SalomeApp_IntSpinBox( ButtonGroup1 );
99 SpinBox_0DElements_Size->setAcceptNames( false ); // No Notebook variables allowed
100 SpinBox_0DElements_Size->setRange( 1, 10 );
101 SpinBox_0DElements_Size->setSingleStep( 1 );
102 SpinBox_0DElements_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
103 SpinBox_0DElements_Size->setButtonSymbols( QSpinBox::PlusMinus );
105 QLabel* TextLabel_BallElem_Color = new QLabel( tr( "BALL_ELEMENTS_COLOR_LBL" ), ButtonGroup1 );
106 btnBallElemColor = new QtxColorButton( ButtonGroup1 );
108 QLabel* TextLabel_BallElem_Size = new QLabel( tr( "BALL_ELEMENTS_SIZE_LBL" ), ButtonGroup1 );
109 SpinBox_BallElem_Size = new SalomeApp_IntSpinBox( ButtonGroup1 );
110 SpinBox_BallElem_Size->setAcceptNames( false ); // No Notebook variables allowed
111 SpinBox_BallElem_Size->setRange( 1, 10 );
112 SpinBox_BallElem_Size->setSingleStep( 1 );
113 SpinBox_BallElem_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
114 SpinBox_BallElem_Size->setButtonSymbols( QSpinBox::PlusMinus );
116 QLabel* TextLabel_Width = new QLabel( tr( "LINE_WIDTH_LBL" ), ButtonGroup1 );
117 SpinBox_Width = new SalomeApp_IntSpinBox( ButtonGroup1 );
118 SpinBox_Width->setAcceptNames( false ); // No Notebook variables allowed
119 SpinBox_Width->setRange( 1, 5 );
120 SpinBox_Width->setSingleStep( 1 );
121 SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
122 SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
124 QLabel* TextLabel_ShrinkCoeff = new QLabel( tr( "SHRINK_COEF_LBL" ), ButtonGroup1 );
125 SpinBox_Shrink = new SalomeApp_IntSpinBox( ButtonGroup1 );
126 SpinBox_Shrink->setAcceptNames( false ); // No Notebook variables allowed
127 SpinBox_Shrink->setRange( 20, 100 );
128 SpinBox_Shrink->setSingleStep( 1 );
129 SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
130 SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
133 ButtonGroup1Layout->addWidget( TextLabel_Fill, row, 0 );
134 ButtonGroup1Layout->addWidget( toolSurfColor, row++, 1, 1, 3 );
136 ButtonGroup1Layout->addWidget( TextLabel_Outline, row, 0 );
137 ButtonGroup1Layout->addWidget( btnOutlineColor, row, 1 );
138 ButtonGroup1Layout->addWidget( TextLabel_Wireframe, row, 2 );
139 ButtonGroup1Layout->addWidget( btnWireframeColor, row++, 3 );
141 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Color, row, 0 );
142 ButtonGroup1Layout->addWidget( btn0DElementsColor, row, 1 );
144 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Size, row, 2 );
145 ButtonGroup1Layout->addWidget( SpinBox_0DElements_Size, row++, 3 );
147 ButtonGroup1Layout->addWidget( TextLabel_BallElem_Color, row, 0 );
148 ButtonGroup1Layout->addWidget( btnBallElemColor, row, 1 );
150 ButtonGroup1Layout->addWidget( TextLabel_BallElem_Size, row, 2 );
151 ButtonGroup1Layout->addWidget( SpinBox_BallElem_Size, row++, 3 );
153 ButtonGroup1Layout->addWidget( TextLabel_Width, row, 0 );
154 ButtonGroup1Layout->addWidget( SpinBox_Width, row, 1 );
155 ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff, row, 2 );
156 ButtonGroup1Layout->addWidget( SpinBox_Shrink, row, 3 );
158 // -------------------------------
159 QGroupBox* ButtonGroup2 = new QGroupBox( tr( "GRP_NODES" ), this );
160 QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2 );
161 ButtonGroup2Layout->setSpacing( SPACING );
162 ButtonGroup2Layout->setMargin( MARGIN );
164 QLabel* TextLabel_Nodes_Color = new QLabel( tr( "NODES_COLOR_LBL" ), ButtonGroup2 );
165 btnNodeColor = new QtxColorButton( ButtonGroup2 );
167 QGroupBox* MarkerGroup = new QGroupBox( tr( "NODES_MARKER_LBL" ), ButtonGroup2 );
168 QVBoxLayout* MarkerGroupLayout = new QVBoxLayout( MarkerGroup );
169 MarkerGroupLayout->setSpacing( 0 );
170 MarkerGroupLayout->setMargin( 0 );
172 MarkerWidget = new VTKViewer_MarkerWidget( MarkerGroup );
174 MarkerGroupLayout->addWidget( MarkerWidget );
177 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color, row, 0 );
178 ButtonGroup2Layout->addWidget( btnNodeColor, row++, 1 );
179 ButtonGroup2Layout->addWidget( MarkerGroup, row++, 0, 1, 3 );
180 ButtonGroup2Layout->setColumnStretch( row, 1 );
182 // -------------------------------
183 QGroupBox* ButtonGroup3 = new QGroupBox( tr( "GRP_ORIENTATION" ), this );
184 QGridLayout* ButtonGroup3Layout = new QGridLayout( ButtonGroup3 );
185 ButtonGroup3Layout->setSpacing( SPACING );
186 ButtonGroup3Layout->setMargin( MARGIN );
188 QLabel* TextLabel_Orientation_Color = new QLabel( tr( "ORIENTATION_COLOR_LBL" ), ButtonGroup3 );
189 btnOrientationColor = new QtxColorButton( ButtonGroup3 );
191 QLabel* TextLabel_Orientation_Scale = new QLabel( tr( "ORIENTATION_SCALE_LBL" ), ButtonGroup3 );
192 SpinBox_Orientation_Scale = new SMESHGUI_SpinBox( ButtonGroup3 );
193 SpinBox_Orientation_Scale->setAcceptNames( false ); // No Notebook variables allowed
194 SpinBox_Orientation_Scale->RangeStepAndValidator( .05, .5, .05, "parametric_precision" );
195 SpinBox_Orientation_Scale->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
196 SpinBox_Orientation_Scale->setButtonSymbols( QSpinBox::PlusMinus );
198 CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D_VECTORS_LBL" ), ButtonGroup3 );
201 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Color, row, 0 );
202 ButtonGroup3Layout->addWidget( btnOrientationColor, row, 1 );
203 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Scale, row, 2 );
204 ButtonGroup3Layout->addWidget( SpinBox_Orientation_Scale, row++, 3 );
205 ButtonGroup3Layout->addWidget( CheckBox_Orientation_3DVectors, row, 0, 1, 4 );
207 // -------------------------------
208 QGroupBox* ButtonGroup4 = new QGroupBox( tr( "GRP_SELECTION" ), this );
209 QGridLayout* ButtonGroup4Layout = new QGridLayout( ButtonGroup4 );
210 ButtonGroup3Layout->setSpacing( SPACING );
211 ButtonGroup3Layout->setMargin( MARGIN );
213 QLabel* TextLabel_Selection_Color = new QLabel( tr( "SELECTION_COLOR_LBL" ), ButtonGroup4 );
214 btnSelectionColor = new QtxColorButton( ButtonGroup4 );
216 QLabel* TextLabel_Preselection_Color = new QLabel( tr( "PRESELECTION_COLOR_LBL" ), ButtonGroup4 );
217 btnPreselectionColor = new QtxColorButton( ButtonGroup4 );
220 ButtonGroup4Layout->addWidget( TextLabel_Selection_Color, row, 0 );
221 ButtonGroup4Layout->addWidget( btnSelectionColor, row, 1 );
222 ButtonGroup4Layout->addWidget( TextLabel_Preselection_Color, row, 2 );
223 ButtonGroup4Layout->addWidget( btnPreselectionColor, row, 3 );
225 // -------------------------------
226 QGroupBox* GroupButtons = new QGroupBox( this );
227 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
228 GroupButtonsLayout->setSpacing( SPACING );
229 GroupButtonsLayout->setMargin( MARGIN );
231 QPushButton* buttonOk = new QPushButton( tr( "SMESH_BUT_OK" ), GroupButtons );
232 buttonOk->setAutoDefault( true );
233 buttonOk->setDefault( true );
235 QPushButton* buttonCancel = new QPushButton( tr( "SMESH_BUT_CANCEL" ), GroupButtons );
236 buttonCancel->setAutoDefault( true );
238 QPushButton* buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
239 buttonHelp->setAutoDefault( true );
241 GroupButtonsLayout->addWidget( buttonOk );
242 GroupButtonsLayout->addSpacing( 10 );
243 GroupButtonsLayout->addStretch();
244 GroupButtonsLayout->addWidget( buttonCancel );
245 GroupButtonsLayout->addWidget( buttonHelp );
247 // -------------------------------
248 topLayout->addWidget( ButtonGroup1 );
249 topLayout->addWidget( ButtonGroup2 );
250 topLayout->addWidget( ButtonGroup3 );
251 // rnv: Selection and preselection colors are defined only in the Preferences
252 // topLayout->addWidget( ButtonGroup4 );
253 ButtonGroup4->hide();
254 topLayout->addWidget( GroupButtons );
256 // -------------------------------
257 mySMESHGUI->SetActiveDialogBox( this );
259 myHelpFileName = "colors_size_page.html";
261 /* signals and slots connections */
262 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
263 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
264 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
266 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
267 this, SLOT( DeactivateActiveDialog() ) );
268 /* to close dialog if study change */
269 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
270 this, SLOT( ClickOnCancel() ) );
273 //=================================================================================
274 // function : ~SMESHGUI_Preferences_ColorDlg()
275 // purpose : Destructor
276 //=================================================================================
277 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
281 //=================================================================================
282 // function : ClickOnOk()
284 //=================================================================================
285 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
287 mySMESHGUI->ResetState();
291 //=================================================================================
292 // function : ClickOnCancel()
294 //=================================================================================
295 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
297 mySMESHGUI->ResetState();
301 //=================================================================================
302 // function : ClickOnHelp()
304 //=================================================================================
305 void SMESHGUI_Preferences_ColorDlg::ClickOnHelp()
307 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
309 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
313 platform = "winapplication";
315 platform = "application";
317 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
318 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
319 arg(app->resourceMgr()->stringValue("ExternalBrowser",
321 arg(myHelpFileName));
325 //=================================================================================
326 // function : DeactivateActiveDialog()
328 //=================================================================================
329 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
333 //=================================================================================
334 // function : closeEvent()
336 //=================================================================================
337 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
339 ClickOnCancel(); /* same than click on cancel button */
342 //=================================================================================
343 // function : ActivateThisDialog()
345 //=================================================================================
346 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
348 /* Emit a signal to deactivate any active dialog */
349 mySMESHGUI->EmitSignalDeactivateDialog();
352 //=================================================================================
353 // function : SetColor()
355 //=================================================================================
356 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
359 case 1 : toolSurfColor->setMainColor( color ); break; // fill
360 case 2 : btnWireframeColor->setColor( color ); break; // wireframe
361 case 3 : btnNodeColor->setColor( color ); break; // node
362 case 4 : btnOutlineColor->setColor( color ); break; // outline
363 case 5 : btn0DElementsColor->setColor( color ); break; // 0d elements
364 case 6 : btnBallElemColor->setColor( color ); break; // ball elements
365 case 7 : btnOrientationColor->setColor( color ); break; // orientation of faces
366 case 8 : btnSelectionColor->setColor( color ); break; // selection color
367 case 9 : btnPreselectionColor->setColor( color ); break; // pre-selection color
372 //=================================================================================
373 // function : GetColor()
375 //=================================================================================
376 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
380 case 1 : color = toolSurfColor->mainColor(); break; // fill
381 case 2 : color = btnWireframeColor->color(); break; // outline
382 case 3 : color = btnNodeColor->color(); break; // node
383 case 4 : color = btnOutlineColor->color(); break; // node
384 case 5 : color = btn0DElementsColor->color(); break; // 0d elements
385 case 6 : color = btnBallElemColor->color(); break; // 0d elements
386 case 7 : color = btnOrientationColor->color(); break; // orientation of faces
387 case 8 : color = btnSelectionColor->color(); break; // selection color
388 case 9 : color = btnPreselectionColor->color(); break; // pre-selection color
395 //=================================================================================
396 // function : SetIntValue()
398 //=================================================================================
399 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
402 case 1 : SpinBox_Width->setValue( value ); break; // width
403 case 2 : SpinBox_Shrink->setValue( value ); break; // shrink coeff
404 case 3 : SpinBox_0DElements_Size->setValue( value ); break; // 0d elements
405 case 4 : SpinBox_BallElem_Size->setValue( value ); break; // 0d elements
410 //=================================================================================
411 // function : GetIntValue()
413 //=================================================================================
414 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
418 case 1 : res = SpinBox_Width->value(); break; // width
419 case 2 : res = SpinBox_Shrink->value(); break; // shrink coeff
420 case 3 : res = SpinBox_0DElements_Size->value(); break; // 0d elements
421 case 4 : res = SpinBox_BallElem_Size->value(); break; // 0d elements
427 //=================================================================================
428 // function : SetDoubleValue()
430 //=================================================================================
431 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
434 case 1 : SpinBox_Orientation_Scale->setValue( value ); break; // orientation scale
439 //=================================================================================
440 // function : GetDoubleValue()
442 //=================================================================================
443 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
447 case 1 : res = SpinBox_Orientation_Scale->value(); break; // orientation scale
453 //=================================================================================
454 // function : SetBooleanValue()
456 //=================================================================================
457 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
460 case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break; // 3D vectors
465 //=================================================================================
466 // function : GetBooleanValue()
468 //=================================================================================
469 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
473 case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break; // 3D vectors
479 //=================================================================================
480 // function : setCustomMarkerMap()
482 //=================================================================================
483 void SMESHGUI_Preferences_ColorDlg::setCustomMarkerMap( VTK::MarkerMap theMarkerMap )
485 MarkerWidget->setCustomMarkerMap( theMarkerMap );
488 //=================================================================================
489 // function : getCustomMarkerMap()
491 //=================================================================================
492 VTK::MarkerMap SMESHGUI_Preferences_ColorDlg::getCustomMarkerMap()
494 return MarkerWidget->getCustomMarkerMap();
497 //=================================================================================
498 // function : setStandardMarker()
500 //=================================================================================
501 void SMESHGUI_Preferences_ColorDlg::setStandardMarker( VTK::MarkerType theMarkerType,
502 VTK::MarkerScale theMarkerScale )
504 MarkerWidget->setStandardMarker( theMarkerType, theMarkerScale );
507 //=================================================================================
508 // function : setCustomMarker()
510 //=================================================================================
511 void SMESHGUI_Preferences_ColorDlg::setCustomMarker( int theId )
513 MarkerWidget->setCustomMarker( theId );
516 //=================================================================================
517 // function : getMarkerType()
519 //=================================================================================
520 VTK::MarkerType SMESHGUI_Preferences_ColorDlg::getMarkerType() const
522 return MarkerWidget->getMarkerType();
525 //=================================================================================
526 // function : getStandardMarkerScale()
528 //=================================================================================
529 VTK::MarkerScale SMESHGUI_Preferences_ColorDlg::getStandardMarkerScale() const
531 return MarkerWidget->getStandardMarkerScale();
534 //=================================================================================
535 // function : getCustomMarkerID()
537 //=================================================================================
538 int SMESHGUI_Preferences_ColorDlg::getCustomMarkerID() const
540 return MarkerWidget->getCustomMarkerID();
543 //=================================================================================
544 // function : SetDeltaBrightness(int)
546 //=================================================================================
547 void SMESHGUI_Preferences_ColorDlg::SetDeltaBrightness(int delta)
549 toolSurfColor->setDelta(delta);
551 //=================================================================================
552 // function : GetDeltaBrightness()
554 //=================================================================================
555 int SMESHGUI_Preferences_ColorDlg::GetDeltaBrightness()
557 return toolSurfColor->delta();
560 //=================================================================================
561 // function : keyPressEvent()
563 //=================================================================================
564 void SMESHGUI_Preferences_ColorDlg::keyPressEvent( QKeyEvent* e )
566 QDialog::keyPressEvent( e );
567 if ( e->isAccepted() )
570 if ( e->key() == Qt::Key_F1 ) {