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_Outine = new QLabel( tr( "Outline" ), ButtonGroup1 );
89 btnOutlineColor = new QtxColorButton( ButtonGroup1 );
91 QLabel* TextLabel_0DElements_Color = new QLabel( tr( "0D elements" ), ButtonGroup1 );
92 btn0DElementsColor = new QtxColorButton( ButtonGroup1 );
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 );
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 );
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 );
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 );
131 // -------------------------------
132 QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
133 QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2 );
134 ButtonGroup2Layout->setSpacing( SPACING );
135 ButtonGroup2Layout->setMargin( MARGIN );
137 QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
138 btnNodeColor = new QtxColorButton( ButtonGroup2 );
140 QGroupBox* MarkerGroup = new QGroupBox( tr( "Marker" ), ButtonGroup2 );
141 QVBoxLayout* MarkerGroupLayout = new QVBoxLayout( MarkerGroup );
142 MarkerGroupLayout->setSpacing( 0 );
143 MarkerGroupLayout->setMargin( 0 );
145 MarkerWidget = new VTKViewer_MarkerWidget( MarkerGroup );
147 MarkerGroupLayout->addWidget( MarkerWidget );
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 );
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 );
160 QLabel* TextLabel_Orientation_Color = new QLabel( tr( "Color" ), ButtonGroup3 );
161 btnOrientationColor = new QtxColorButton( ButtonGroup3 );
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 );
170 CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D vectors" ), ButtonGroup3 );
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 );
178 // -------------------------------
179 QGroupBox* GroupButtons = new QGroupBox( this );
180 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
181 GroupButtonsLayout->setSpacing( SPACING );
182 GroupButtonsLayout->setMargin( MARGIN );
184 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
185 buttonOk->setAutoDefault( true );
186 buttonOk->setDefault( true );
188 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
189 buttonCancel->setAutoDefault( true );
191 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ), GroupButtons );
192 buttonHelp->setAutoDefault( true );
194 GroupButtonsLayout->addWidget( buttonOk );
195 GroupButtonsLayout->addSpacing( 10 );
196 GroupButtonsLayout->addStretch();
197 GroupButtonsLayout->addWidget( buttonCancel );
198 GroupButtonsLayout->addWidget( buttonHelp );
200 // -------------------------------
201 topLayout->addWidget( ButtonGroup1 );
202 topLayout->addWidget( ButtonGroup2 );
203 topLayout->addWidget( ButtonGroup3 );
204 topLayout->addWidget( GroupButtons );
206 // -------------------------------
207 mySMESHGUI->SetActiveDialogBox( this );
209 myHelpFileName = "colors_size_page.html";
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() ) );
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() ) );
223 //=================================================================================
224 // function : ~SMESHGUI_Preferences_ColorDlg()
225 // purpose : Destructor
226 //=================================================================================
227 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
231 //=================================================================================
232 // function : ClickOnOk()
234 //=================================================================================
235 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
237 mySMESHGUI->ResetState();
241 //=================================================================================
242 // function : ClickOnCancel()
244 //=================================================================================
245 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
247 mySMESHGUI->ResetState();
251 //=================================================================================
252 // function : ClickOnHelp()
254 //=================================================================================
255 void SMESHGUI_Preferences_ColorDlg::ClickOnHelp()
257 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
259 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
263 platform = "winapplication";
265 platform = "application";
267 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
268 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
269 arg(app->resourceMgr()->stringValue("ExternalBrowser",
271 arg(myHelpFileName));
275 //=================================================================================
276 // function : DeactivateActiveDialog()
278 //=================================================================================
279 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
283 //=================================================================================
284 // function : closeEvent()
286 //=================================================================================
287 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
289 ClickOnCancel(); /* same than click on cancel button */
292 //=================================================================================
293 // function : ActivateThisDialog()
295 //=================================================================================
296 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
298 /* Emit a signal to deactivate any active dialog */
299 mySMESHGUI->EmitSignalDeactivateDialog();
302 //=================================================================================
303 // function : SetColor()
305 //=================================================================================
306 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
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
318 //=================================================================================
319 // function : GetColor()
321 //=================================================================================
322 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int 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
336 //=================================================================================
337 // function : SetIntValue()
339 //=================================================================================
340 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
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
350 //=================================================================================
351 // function : GetIntValue()
353 //=================================================================================
354 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int 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
366 //=================================================================================
367 // function : SetDoubleValue()
369 //=================================================================================
370 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
373 case 1 : SpinBox_Orientation_Scale->setValue( value ); break; // orientation scale
378 //=================================================================================
379 // function : GetDoubleValue()
381 //=================================================================================
382 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
386 case 1 : res = SpinBox_Orientation_Scale->value(); break; // orientation scale
392 //=================================================================================
393 // function : SetBooleanValue()
395 //=================================================================================
396 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
399 case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break; // 3D vectors
404 //=================================================================================
405 // function : GetBooleanValue()
407 //=================================================================================
408 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
412 case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break; // 3D vectors
418 //=================================================================================
419 // function : setCustomMarkerMap()
421 //=================================================================================
422 void SMESHGUI_Preferences_ColorDlg::setCustomMarkerMap( VTK::MarkerMap theMarkerMap )
424 MarkerWidget->setCustomMarkerMap( theMarkerMap );
427 //=================================================================================
428 // function : getCustomMarkerMap()
430 //=================================================================================
431 VTK::MarkerMap SMESHGUI_Preferences_ColorDlg::getCustomMarkerMap()
433 return MarkerWidget->getCustomMarkerMap();
436 //=================================================================================
437 // function : setStandardMarker()
439 //=================================================================================
440 void SMESHGUI_Preferences_ColorDlg::setStandardMarker( VTK::MarkerType theMarkerType,
441 VTK::MarkerScale theMarkerScale )
443 MarkerWidget->setStandardMarker( theMarkerType, theMarkerScale );
446 //=================================================================================
447 // function : setCustomMarker()
449 //=================================================================================
450 void SMESHGUI_Preferences_ColorDlg::setCustomMarker( int theId )
452 MarkerWidget->setCustomMarker( theId );
455 //=================================================================================
456 // function : getMarkerType()
458 //=================================================================================
459 VTK::MarkerType SMESHGUI_Preferences_ColorDlg::getMarkerType() const
461 return MarkerWidget->getMarkerType();
464 //=================================================================================
465 // function : getStandardMarkerScale()
467 //=================================================================================
468 VTK::MarkerScale SMESHGUI_Preferences_ColorDlg::getStandardMarkerScale() const
470 return MarkerWidget->getStandardMarkerScale();
473 //=================================================================================
474 // function : getCustomMarkerID()
476 //=================================================================================
477 int SMESHGUI_Preferences_ColorDlg::getCustomMarkerID() const
479 return MarkerWidget->getCustomMarkerID();
482 //=================================================================================
483 // function : SetDeltaBrightness(int)
485 //=================================================================================
486 void SMESHGUI_Preferences_ColorDlg::SetDeltaBrightness(int delta)
488 toolSurfColor->setDelta(delta);
490 //=================================================================================
491 // function : GetDeltaBrightness()
493 //=================================================================================
494 int SMESHGUI_Preferences_ColorDlg::GetDeltaBrightness()
496 return toolSurfColor->delta();
499 //=================================================================================
500 // function : keyPressEvent()
502 //=================================================================================
503 void SMESHGUI_Preferences_ColorDlg::keyPressEvent( QKeyEvent* e )
505 QDialog::keyPressEvent( e );
506 if ( e->isAccepted() )
509 if ( e->key() == Qt::Key_F1 ) {