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( "0D_ELEMENTS_COLOR_LBL" ), ButtonGroup1 );
106 btnBallElemColor = new QtxColorButton( ButtonGroup1 );
108 QLabel* TextLabel_BallElem_Size = new QLabel( tr( "BALLELEM_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 );
132 ButtonGroup1Layout->addWidget( TextLabel_Fill, 0, 0 );
133 ButtonGroup1Layout->addWidget( toolSurfColor, 0, 1, 1, 3 );
135 ButtonGroup1Layout->addWidget( TextLabel_Outline, 1, 0 );
136 ButtonGroup1Layout->addWidget( btnOutlineColor, 1, 1 );
137 ButtonGroup1Layout->addWidget( TextLabel_Wireframe, 1, 2 );
138 ButtonGroup1Layout->addWidget( btnWireframeColor, 1, 3 );
140 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Color, 2, 0 );
141 ButtonGroup1Layout->addWidget( btn0DElementsColor, 2, 1 );
143 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Size, 2, 2 );
144 ButtonGroup1Layout->addWidget( SpinBox_0DElements_Size, 2, 3 );
146 ButtonGroup1Layout->addWidget( TextLabel_BallElem_Color, 2, 0 );
147 ButtonGroup1Layout->addWidget( btnBallElemColor, 2, 1 );
149 ButtonGroup1Layout->addWidget( TextLabel_BallElem_Size, 2, 2 );
150 ButtonGroup1Layout->addWidget( SpinBox_BallElem_Size, 2, 3 );
152 ButtonGroup1Layout->addWidget( TextLabel_Width, 3, 0 );
153 ButtonGroup1Layout->addWidget( SpinBox_Width, 3, 1 );
154 ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff, 3, 2 );
155 ButtonGroup1Layout->addWidget( SpinBox_Shrink, 3, 3 );
157 // -------------------------------
158 QGroupBox* ButtonGroup2 = new QGroupBox( tr( "GRP_NODES" ), this );
159 QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2 );
160 ButtonGroup2Layout->setSpacing( SPACING );
161 ButtonGroup2Layout->setMargin( MARGIN );
163 QLabel* TextLabel_Nodes_Color = new QLabel( tr( "NODES_COLOR_LBL" ), ButtonGroup2 );
164 btnNodeColor = new QtxColorButton( ButtonGroup2 );
166 QGroupBox* MarkerGroup = new QGroupBox( tr( "NODES_MARKER_LBL" ), ButtonGroup2 );
167 QVBoxLayout* MarkerGroupLayout = new QVBoxLayout( MarkerGroup );
168 MarkerGroupLayout->setSpacing( 0 );
169 MarkerGroupLayout->setMargin( 0 );
171 MarkerWidget = new VTKViewer_MarkerWidget( MarkerGroup );
173 MarkerGroupLayout->addWidget( MarkerWidget );
175 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color, 0, 0 );
176 ButtonGroup2Layout->addWidget( btnNodeColor, 0, 1 );
177 ButtonGroup2Layout->addWidget( MarkerGroup, 1, 0, 1, 3 );
178 ButtonGroup2Layout->setColumnStretch( 2, 1 );
180 // -------------------------------
181 QGroupBox* ButtonGroup3 = new QGroupBox( tr( "GRP_ORIENTATION" ), this );
182 QGridLayout* ButtonGroup3Layout = new QGridLayout( ButtonGroup3 );
183 ButtonGroup3Layout->setSpacing( SPACING );
184 ButtonGroup3Layout->setMargin( MARGIN );
186 QLabel* TextLabel_Orientation_Color = new QLabel( tr( "ORIENTATION_COLOR_LBL" ), ButtonGroup3 );
187 btnOrientationColor = new QtxColorButton( ButtonGroup3 );
189 QLabel* TextLabel_Orientation_Scale = new QLabel( tr( "ORIENTATION_SCALE_LBL" ), ButtonGroup3 );
190 SpinBox_Orientation_Scale = new SMESHGUI_SpinBox( ButtonGroup3 );
191 SpinBox_Orientation_Scale->setAcceptNames( false ); // No Notebook variables allowed
192 SpinBox_Orientation_Scale->RangeStepAndValidator( .05, .5, .05, "parametric_precision" );
193 SpinBox_Orientation_Scale->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
194 SpinBox_Orientation_Scale->setButtonSymbols( QSpinBox::PlusMinus );
196 CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D_VECTORS_LBL" ), ButtonGroup3 );
198 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Color, 0, 0 );
199 ButtonGroup3Layout->addWidget( btnOrientationColor, 0, 1 );
200 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Scale, 0, 2 );
201 ButtonGroup3Layout->addWidget( SpinBox_Orientation_Scale, 0, 3 );
202 ButtonGroup3Layout->addWidget( CheckBox_Orientation_3DVectors, 1, 0, 1, 4 );
204 // -------------------------------
205 QGroupBox* ButtonGroup4 = new QGroupBox( tr( "GRP_SELECTION" ), this );
206 QGridLayout* ButtonGroup4Layout = new QGridLayout( ButtonGroup4 );
207 ButtonGroup3Layout->setSpacing( SPACING );
208 ButtonGroup3Layout->setMargin( MARGIN );
210 QLabel* TextLabel_Selection_Color = new QLabel( tr( "SELECTION_COLOR_LBL" ), ButtonGroup4 );
211 btnSelectionColor = new QtxColorButton( ButtonGroup4 );
213 QLabel* TextLabel_Preselection_Color = new QLabel( tr( "PRESELECTION_COLOR_LBL" ), ButtonGroup4 );
214 btnPreselectionColor = new QtxColorButton( ButtonGroup4 );
216 ButtonGroup4Layout->addWidget( TextLabel_Selection_Color, 0, 0 );
217 ButtonGroup4Layout->addWidget( btnSelectionColor, 0, 1 );
218 ButtonGroup4Layout->addWidget( TextLabel_Preselection_Color, 0, 2 );
219 ButtonGroup4Layout->addWidget( btnPreselectionColor, 0, 3 );
221 // -------------------------------
222 QGroupBox* GroupButtons = new QGroupBox( this );
223 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
224 GroupButtonsLayout->setSpacing( SPACING );
225 GroupButtonsLayout->setMargin( MARGIN );
227 QPushButton* buttonOk = new QPushButton( tr( "SMESH_BUT_OK" ), GroupButtons );
228 buttonOk->setAutoDefault( true );
229 buttonOk->setDefault( true );
231 QPushButton* buttonCancel = new QPushButton( tr( "SMESH_BUT_CANCEL" ), GroupButtons );
232 buttonCancel->setAutoDefault( true );
234 QPushButton* buttonHelp = new QPushButton( tr( "SMESH_BUT_HELP" ), GroupButtons );
235 buttonHelp->setAutoDefault( true );
237 GroupButtonsLayout->addWidget( buttonOk );
238 GroupButtonsLayout->addSpacing( 10 );
239 GroupButtonsLayout->addStretch();
240 GroupButtonsLayout->addWidget( buttonCancel );
241 GroupButtonsLayout->addWidget( buttonHelp );
243 // -------------------------------
244 topLayout->addWidget( ButtonGroup1 );
245 topLayout->addWidget( ButtonGroup2 );
246 topLayout->addWidget( ButtonGroup3 );
247 // rnv: Selection and preselection colors are defined only in the Preferences
248 // topLayout->addWidget( ButtonGroup4 );
249 ButtonGroup4->hide();
250 topLayout->addWidget( GroupButtons );
252 // -------------------------------
253 mySMESHGUI->SetActiveDialogBox( this );
255 myHelpFileName = "colors_size_page.html";
257 /* signals and slots connections */
258 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
259 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
260 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
262 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
263 this, SLOT( DeactivateActiveDialog() ) );
264 /* to close dialog if study change */
265 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
266 this, SLOT( ClickOnCancel() ) );
269 //=================================================================================
270 // function : ~SMESHGUI_Preferences_ColorDlg()
271 // purpose : Destructor
272 //=================================================================================
273 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
277 //=================================================================================
278 // function : ClickOnOk()
280 //=================================================================================
281 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
283 mySMESHGUI->ResetState();
287 //=================================================================================
288 // function : ClickOnCancel()
290 //=================================================================================
291 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
293 mySMESHGUI->ResetState();
297 //=================================================================================
298 // function : ClickOnHelp()
300 //=================================================================================
301 void SMESHGUI_Preferences_ColorDlg::ClickOnHelp()
303 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
305 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
309 platform = "winapplication";
311 platform = "application";
313 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
314 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
315 arg(app->resourceMgr()->stringValue("ExternalBrowser",
317 arg(myHelpFileName));
321 //=================================================================================
322 // function : DeactivateActiveDialog()
324 //=================================================================================
325 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
329 //=================================================================================
330 // function : closeEvent()
332 //=================================================================================
333 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
335 ClickOnCancel(); /* same than click on cancel button */
338 //=================================================================================
339 // function : ActivateThisDialog()
341 //=================================================================================
342 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
344 /* Emit a signal to deactivate any active dialog */
345 mySMESHGUI->EmitSignalDeactivateDialog();
348 //=================================================================================
349 // function : SetColor()
351 //=================================================================================
352 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
355 case 1 : toolSurfColor->setMainColor( color ); break; // fill
356 case 2 : btnWireframeColor->setColor( color ); break; // wireframe
357 case 3 : btnNodeColor->setColor( color ); break; // node
358 case 4 : btnOutlineColor->setColor( color ); break; // outline
359 case 5 : btn0DElementsColor->setColor( color ); break; // 0d elements
360 case 6 : btnBallElemColor->setColor( color ); break; // ball elements
361 case 7 : btnOrientationColor->setColor( color ); break; // orientation of faces
362 case 8 : btnSelectionColor->setColor( color ); break; // selection color
363 case 9 : btnPreselectionColor->setColor( color ); break; // pre-selection color
368 //=================================================================================
369 // function : GetColor()
371 //=================================================================================
372 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
376 case 1 : color = toolSurfColor->mainColor(); break; // fill
377 case 2 : color = btnWireframeColor->color(); break; // outline
378 case 3 : color = btnNodeColor->color(); break; // node
379 case 4 : color = btnOutlineColor->color(); break; // node
380 case 5 : color = btn0DElementsColor->color(); break; // 0d elements
381 case 6 : color = btnBallElemColor->color(); break; // 0d elements
382 case 7 : color = btnOrientationColor->color(); break; // orientation of faces
383 case 8 : color = btnSelectionColor->color(); break; // selection color
384 case 9 : color = btnPreselectionColor->color(); break; // pre-selection color
391 //=================================================================================
392 // function : SetIntValue()
394 //=================================================================================
395 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
398 case 1 : SpinBox_Width->setValue( value ); break; // width
399 case 2 : SpinBox_Shrink->setValue( value ); break; // shrink coeff
400 case 3 : SpinBox_0DElements_Size->setValue( value ); break; // 0d elements
401 case 4 : SpinBox_BallElem_Size->setValue( value ); break; // 0d elements
406 //=================================================================================
407 // function : GetIntValue()
409 //=================================================================================
410 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
414 case 1 : res = SpinBox_Width->value(); break; // width
415 case 2 : res = SpinBox_Shrink->value(); break; // shrink coeff
416 case 3 : res = SpinBox_0DElements_Size->value(); break; // 0d elements
417 case 4 : res = SpinBox_BallElem_Size->value(); break; // 0d elements
423 //=================================================================================
424 // function : SetDoubleValue()
426 //=================================================================================
427 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
430 case 1 : SpinBox_Orientation_Scale->setValue( value ); break; // orientation scale
435 //=================================================================================
436 // function : GetDoubleValue()
438 //=================================================================================
439 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
443 case 1 : res = SpinBox_Orientation_Scale->value(); break; // orientation scale
449 //=================================================================================
450 // function : SetBooleanValue()
452 //=================================================================================
453 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
456 case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break; // 3D vectors
461 //=================================================================================
462 // function : GetBooleanValue()
464 //=================================================================================
465 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
469 case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break; // 3D vectors
475 //=================================================================================
476 // function : setCustomMarkerMap()
478 //=================================================================================
479 void SMESHGUI_Preferences_ColorDlg::setCustomMarkerMap( VTK::MarkerMap theMarkerMap )
481 MarkerWidget->setCustomMarkerMap( theMarkerMap );
484 //=================================================================================
485 // function : getCustomMarkerMap()
487 //=================================================================================
488 VTK::MarkerMap SMESHGUI_Preferences_ColorDlg::getCustomMarkerMap()
490 return MarkerWidget->getCustomMarkerMap();
493 //=================================================================================
494 // function : setStandardMarker()
496 //=================================================================================
497 void SMESHGUI_Preferences_ColorDlg::setStandardMarker( VTK::MarkerType theMarkerType,
498 VTK::MarkerScale theMarkerScale )
500 MarkerWidget->setStandardMarker( theMarkerType, theMarkerScale );
503 //=================================================================================
504 // function : setCustomMarker()
506 //=================================================================================
507 void SMESHGUI_Preferences_ColorDlg::setCustomMarker( int theId )
509 MarkerWidget->setCustomMarker( theId );
512 //=================================================================================
513 // function : getMarkerType()
515 //=================================================================================
516 VTK::MarkerType SMESHGUI_Preferences_ColorDlg::getMarkerType() const
518 return MarkerWidget->getMarkerType();
521 //=================================================================================
522 // function : getStandardMarkerScale()
524 //=================================================================================
525 VTK::MarkerScale SMESHGUI_Preferences_ColorDlg::getStandardMarkerScale() const
527 return MarkerWidget->getStandardMarkerScale();
530 //=================================================================================
531 // function : getCustomMarkerID()
533 //=================================================================================
534 int SMESHGUI_Preferences_ColorDlg::getCustomMarkerID() const
536 return MarkerWidget->getCustomMarkerID();
539 //=================================================================================
540 // function : SetDeltaBrightness(int)
542 //=================================================================================
543 void SMESHGUI_Preferences_ColorDlg::SetDeltaBrightness(int delta)
545 toolSurfColor->setDelta(delta);
547 //=================================================================================
548 // function : GetDeltaBrightness()
550 //=================================================================================
551 int SMESHGUI_Preferences_ColorDlg::GetDeltaBrightness()
553 return toolSurfColor->delta();
556 //=================================================================================
557 // function : keyPressEvent()
559 //=================================================================================
560 void SMESHGUI_Preferences_ColorDlg::keyPressEvent( QKeyEvent* e )
562 QDialog::keyPressEvent( e );
563 if ( e->isAccepted() )
566 if ( e->key() == Qt::Key_F1 ) {