1 // Copyright (C) 2007-2011 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( "Preferences - Set Color" ) );
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( "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" ), ButtonGroup1 );
85 toolSurfColor = new QtxBiColorTool(ButtonGroup1);
86 toolSurfColor->setText("Back surface color");
88 QLabel* TextLabel_Outline = new QLabel( tr( "Outline color" ), ButtonGroup1 );
89 btnOutlineColor = new QtxColorButton( ButtonGroup1 );
91 QLabel* TextLabel_Wireframe = new QLabel( tr( "Wireframe color" ), ButtonGroup1 );
92 btnWireframeColor = new QtxColorButton( ButtonGroup1 );
94 QLabel* TextLabel_0DElements_Color = new QLabel( tr( "0D elements" ), ButtonGroup1 );
95 btn0DElementsColor = new QtxColorButton( ButtonGroup1 );
97 QLabel* TextLabel_0DElements_Size = new QLabel( tr( "Size of 0D elements" ), 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_Width = new QLabel( tr( "Width" ), ButtonGroup1 );
106 SpinBox_Width = new SalomeApp_IntSpinBox( ButtonGroup1 );
107 SpinBox_Width->setAcceptNames( false ); // No Notebook variables allowed
108 SpinBox_Width->setRange( 0, 5 );
109 SpinBox_Width->setSingleStep( 1 );
110 SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
111 SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
113 QLabel* TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1 );
114 SpinBox_Shrink = new SalomeApp_IntSpinBox( ButtonGroup1 );
115 SpinBox_Shrink->setAcceptNames( false ); // No Notebook variables allowed
116 SpinBox_Shrink->setRange( 20, 100 );
117 SpinBox_Shrink->setSingleStep( 1 );
118 SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
119 SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
121 ButtonGroup1Layout->addWidget( TextLabel_Fill, 0, 0 );
122 ButtonGroup1Layout->addWidget( toolSurfColor, 0, 1, 1, 3 );
124 ButtonGroup1Layout->addWidget( TextLabel_Outline, 1, 0 );
125 ButtonGroup1Layout->addWidget( btnOutlineColor, 1, 1 );
126 ButtonGroup1Layout->addWidget( TextLabel_Wireframe, 1, 2 );
127 ButtonGroup1Layout->addWidget( btnWireframeColor, 1, 3 );
129 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Color, 2, 0 );
130 ButtonGroup1Layout->addWidget( btn0DElementsColor, 2, 1 );
132 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Size, 2, 2 );
133 ButtonGroup1Layout->addWidget( SpinBox_0DElements_Size, 2, 3 );
135 ButtonGroup1Layout->addWidget( TextLabel_Width, 3, 0 );
136 ButtonGroup1Layout->addWidget( SpinBox_Width, 3, 1 );
137 ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff, 3, 2 );
138 ButtonGroup1Layout->addWidget( SpinBox_Shrink, 3, 3 );
140 // -------------------------------
141 QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
142 QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2 );
143 ButtonGroup2Layout->setSpacing( SPACING );
144 ButtonGroup2Layout->setMargin( MARGIN );
146 QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
147 btnNodeColor = new QtxColorButton( ButtonGroup2 );
149 QGroupBox* MarkerGroup = new QGroupBox( tr( "Marker" ), ButtonGroup2 );
150 QVBoxLayout* MarkerGroupLayout = new QVBoxLayout( MarkerGroup );
151 MarkerGroupLayout->setSpacing( 0 );
152 MarkerGroupLayout->setMargin( 0 );
154 MarkerWidget = new VTKViewer_MarkerWidget( MarkerGroup );
156 MarkerGroupLayout->addWidget( MarkerWidget );
158 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color, 0, 0 );
159 ButtonGroup2Layout->addWidget( btnNodeColor, 0, 1 );
160 ButtonGroup2Layout->addWidget( MarkerGroup, 1, 0, 1, 3 );
161 ButtonGroup2Layout->setColumnStretch( 2, 1 );
163 // -------------------------------
164 QGroupBox* ButtonGroup3 = new QGroupBox( tr( "Orientation of faces" ), this );
165 QGridLayout* ButtonGroup3Layout = new QGridLayout( ButtonGroup3 );
166 ButtonGroup3Layout->setSpacing( SPACING );
167 ButtonGroup3Layout->setMargin( MARGIN );
169 QLabel* TextLabel_Orientation_Color = new QLabel( tr( "Color" ), ButtonGroup3 );
170 btnOrientationColor = new QtxColorButton( ButtonGroup3 );
172 QLabel* TextLabel_Orientation_Scale = new QLabel( tr( "Scale" ), ButtonGroup3 );
173 SpinBox_Orientation_Scale = new SMESHGUI_SpinBox( ButtonGroup3 );
174 SpinBox_Orientation_Scale->setAcceptNames( false ); // No Notebook variables allowed
175 SpinBox_Orientation_Scale->RangeStepAndValidator( .05, .5, .05, "parametric_precision" );
176 SpinBox_Orientation_Scale->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
177 SpinBox_Orientation_Scale->setButtonSymbols( QSpinBox::PlusMinus );
179 CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D vectors" ), ButtonGroup3 );
181 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Color, 0, 0 );
182 ButtonGroup3Layout->addWidget( btnOrientationColor, 0, 1 );
183 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Scale, 0, 2 );
184 ButtonGroup3Layout->addWidget( SpinBox_Orientation_Scale, 0, 3 );
185 ButtonGroup3Layout->addWidget( CheckBox_Orientation_3DVectors, 1, 0, 1, 4 );
187 // -------------------------------
188 QGroupBox* ButtonGroup4 = new QGroupBox( tr( "Selection" ), this );
189 QGridLayout* ButtonGroup4Layout = new QGridLayout( ButtonGroup4 );
190 ButtonGroup3Layout->setSpacing( SPACING );
191 ButtonGroup3Layout->setMargin( MARGIN );
193 QLabel* TextLabel_Selection_Color = new QLabel( tr( "Selection color" ), ButtonGroup4 );
194 btnSelectionColor = new QtxColorButton( ButtonGroup4 );
196 QLabel* TextLabel_Preselection_Color = new QLabel( tr( "Pre-selection color" ), ButtonGroup4 );
197 btnPreselectionColor = new QtxColorButton( ButtonGroup4 );
199 ButtonGroup4Layout->addWidget( TextLabel_Selection_Color, 0, 0 );
200 ButtonGroup4Layout->addWidget( btnSelectionColor, 0, 1 );
201 ButtonGroup4Layout->addWidget( TextLabel_Preselection_Color, 0, 2 );
202 ButtonGroup4Layout->addWidget( btnPreselectionColor, 0, 3 );
204 // -------------------------------
205 QGroupBox* GroupButtons = new QGroupBox( this );
206 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
207 GroupButtonsLayout->setSpacing( SPACING );
208 GroupButtonsLayout->setMargin( MARGIN );
210 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
211 buttonOk->setAutoDefault( true );
212 buttonOk->setDefault( true );
214 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
215 buttonCancel->setAutoDefault( true );
217 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ), GroupButtons );
218 buttonHelp->setAutoDefault( true );
220 GroupButtonsLayout->addWidget( buttonOk );
221 GroupButtonsLayout->addSpacing( 10 );
222 GroupButtonsLayout->addStretch();
223 GroupButtonsLayout->addWidget( buttonCancel );
224 GroupButtonsLayout->addWidget( buttonHelp );
226 // -------------------------------
227 topLayout->addWidget( ButtonGroup1 );
228 topLayout->addWidget( ButtonGroup2 );
229 topLayout->addWidget( ButtonGroup3 );
230 // rnv: Selection and preselection colors are defined only in the Preferences
231 // topLayout->addWidget( ButtonGroup4 );
232 ButtonGroup4->hide();
233 topLayout->addWidget( GroupButtons );
235 // -------------------------------
236 mySMESHGUI->SetActiveDialogBox( this );
238 myHelpFileName = "colors_size_page.html";
240 /* signals and slots connections */
241 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
242 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
243 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
245 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
246 this, SLOT( DeactivateActiveDialog() ) );
247 /* to close dialog if study change */
248 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
249 this, SLOT( ClickOnCancel() ) );
252 //=================================================================================
253 // function : ~SMESHGUI_Preferences_ColorDlg()
254 // purpose : Destructor
255 //=================================================================================
256 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
260 //=================================================================================
261 // function : ClickOnOk()
263 //=================================================================================
264 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
266 mySMESHGUI->ResetState();
270 //=================================================================================
271 // function : ClickOnCancel()
273 //=================================================================================
274 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
276 mySMESHGUI->ResetState();
280 //=================================================================================
281 // function : ClickOnHelp()
283 //=================================================================================
284 void SMESHGUI_Preferences_ColorDlg::ClickOnHelp()
286 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
288 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
292 platform = "winapplication";
294 platform = "application";
296 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
297 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
298 arg(app->resourceMgr()->stringValue("ExternalBrowser",
300 arg(myHelpFileName));
304 //=================================================================================
305 // function : DeactivateActiveDialog()
307 //=================================================================================
308 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
312 //=================================================================================
313 // function : closeEvent()
315 //=================================================================================
316 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
318 ClickOnCancel(); /* same than click on cancel button */
321 //=================================================================================
322 // function : ActivateThisDialog()
324 //=================================================================================
325 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
327 /* Emit a signal to deactivate any active dialog */
328 mySMESHGUI->EmitSignalDeactivateDialog();
331 //=================================================================================
332 // function : SetColor()
334 //=================================================================================
335 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
338 case 1 : toolSurfColor->setMainColor( color ); break; // fill
339 case 2 : btnWireframeColor->setColor( color ); break; // wireframe
340 case 3 : btnNodeColor->setColor( color ); break; // node
341 case 4 : btnOutlineColor->setColor( color ); break; // outline
342 case 5 : btn0DElementsColor->setColor( color ); break; // 0d elements
343 case 6 : btnOrientationColor->setColor( color ); break; // orientation of faces
344 case 7 : btnSelectionColor->setColor( color ); break; // selection color
345 case 8 : btnPreselectionColor->setColor( color ); break; // pre-selection color
350 //=================================================================================
351 // function : GetColor()
353 //=================================================================================
354 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
358 case 1 : color = toolSurfColor->mainColor(); break; // fill
359 case 2 : color = btnWireframeColor->color(); break; // outline
360 case 3 : color = btnNodeColor->color(); break; // node
361 case 4 : color = btnOutlineColor->color(); break; // node
362 case 5 : color = btn0DElementsColor->color(); break; // 0d elements
363 case 6 : color = btnOrientationColor->color(); break; // orientation of faces
364 case 7 : color = btnSelectionColor->color(); break; // selection color
365 case 8 : color = btnPreselectionColor->color(); break; // pre-selection color
372 //=================================================================================
373 // function : SetIntValue()
375 //=================================================================================
376 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
379 case 1 : SpinBox_Width->setValue( value ); break; // width
380 case 2 : SpinBox_Shrink->setValue( value ); break; // shrink coeff
381 case 3 : SpinBox_0DElements_Size->setValue( value ); break; // 0d elements
386 //=================================================================================
387 // function : GetIntValue()
389 //=================================================================================
390 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
394 case 1 : res = SpinBox_Width->value(); break; // width
395 case 2 : res = SpinBox_Shrink->value(); break; // shrink coeff
396 case 3 : res = SpinBox_0DElements_Size->value(); break; // 0d elements
402 //=================================================================================
403 // function : SetDoubleValue()
405 //=================================================================================
406 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
409 case 1 : SpinBox_Orientation_Scale->setValue( value ); break; // orientation scale
414 //=================================================================================
415 // function : GetDoubleValue()
417 //=================================================================================
418 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
422 case 1 : res = SpinBox_Orientation_Scale->value(); break; // orientation scale
428 //=================================================================================
429 // function : SetBooleanValue()
431 //=================================================================================
432 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
435 case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break; // 3D vectors
440 //=================================================================================
441 // function : GetBooleanValue()
443 //=================================================================================
444 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
448 case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break; // 3D vectors
454 //=================================================================================
455 // function : setCustomMarkerMap()
457 //=================================================================================
458 void SMESHGUI_Preferences_ColorDlg::setCustomMarkerMap( VTK::MarkerMap theMarkerMap )
460 MarkerWidget->setCustomMarkerMap( theMarkerMap );
463 //=================================================================================
464 // function : getCustomMarkerMap()
466 //=================================================================================
467 VTK::MarkerMap SMESHGUI_Preferences_ColorDlg::getCustomMarkerMap()
469 return MarkerWidget->getCustomMarkerMap();
472 //=================================================================================
473 // function : setStandardMarker()
475 //=================================================================================
476 void SMESHGUI_Preferences_ColorDlg::setStandardMarker( VTK::MarkerType theMarkerType,
477 VTK::MarkerScale theMarkerScale )
479 MarkerWidget->setStandardMarker( theMarkerType, theMarkerScale );
482 //=================================================================================
483 // function : setCustomMarker()
485 //=================================================================================
486 void SMESHGUI_Preferences_ColorDlg::setCustomMarker( int theId )
488 MarkerWidget->setCustomMarker( theId );
491 //=================================================================================
492 // function : getMarkerType()
494 //=================================================================================
495 VTK::MarkerType SMESHGUI_Preferences_ColorDlg::getMarkerType() const
497 return MarkerWidget->getMarkerType();
500 //=================================================================================
501 // function : getStandardMarkerScale()
503 //=================================================================================
504 VTK::MarkerScale SMESHGUI_Preferences_ColorDlg::getStandardMarkerScale() const
506 return MarkerWidget->getStandardMarkerScale();
509 //=================================================================================
510 // function : getCustomMarkerID()
512 //=================================================================================
513 int SMESHGUI_Preferences_ColorDlg::getCustomMarkerID() const
515 return MarkerWidget->getCustomMarkerID();
518 //=================================================================================
519 // function : SetDeltaBrightness(int)
521 //=================================================================================
522 void SMESHGUI_Preferences_ColorDlg::SetDeltaBrightness(int delta)
524 toolSurfColor->setDelta(delta);
526 //=================================================================================
527 // function : GetDeltaBrightness()
529 //=================================================================================
530 int SMESHGUI_Preferences_ColorDlg::GetDeltaBrightness()
532 return toolSurfColor->delta();
535 //=================================================================================
536 // function : keyPressEvent()
538 //=================================================================================
539 void SMESHGUI_Preferences_ColorDlg::keyPressEvent( QKeyEvent* e )
541 QDialog::keyPressEvent( e );
542 if ( e->isAccepted() )
545 if ( e->key() == Qt::Key_F1 ) {