1 // Copyright (C) 2007-2010 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( "Fill" ), ButtonGroup1 );
84 btnFillColor = new QtxColorButton( ButtonGroup1 );
86 QLabel* TextLabel_BackFace = new QLabel( tr( "Back Face" ), ButtonGroup1 );
87 btnBackFaceColor = new QtxColorButton( ButtonGroup1 );
89 QLabel* TextLabel_Outine = new QLabel( tr( "Outline" ), ButtonGroup1 );
90 btnOutlineColor = new QtxColorButton( ButtonGroup1 );
92 QLabel* TextLabel_0DElements_Color = new QLabel( tr( "0D elements" ), ButtonGroup1 );
93 btn0DElementsColor = new QtxColorButton( ButtonGroup1 );
95 QLabel* TextLabel_0DElements_Size = new QLabel( tr( "Size of 0D elements" ), ButtonGroup1 );
96 SpinBox_0DElements_Size = new SalomeApp_IntSpinBox( ButtonGroup1 );
97 SpinBox_0DElements_Size->setAcceptNames( false ); // No Notebook variables allowed
98 SpinBox_0DElements_Size->setRange( 1, 10 );
99 SpinBox_0DElements_Size->setSingleStep( 1 );
100 SpinBox_0DElements_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
101 SpinBox_0DElements_Size->setButtonSymbols( QSpinBox::PlusMinus );
103 QLabel* TextLabel_Width = new QLabel( tr( "Width" ), ButtonGroup1 );
104 SpinBox_Width = new SalomeApp_IntSpinBox( ButtonGroup1 );
105 SpinBox_Width->setAcceptNames( false ); // No Notebook variables allowed
106 SpinBox_Width->setRange( 0, 5 );
107 SpinBox_Width->setSingleStep( 1 );
108 SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
109 SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
111 QLabel* TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1 );
112 SpinBox_Shrink = new SalomeApp_IntSpinBox( ButtonGroup1 );
113 SpinBox_Shrink->setAcceptNames( false ); // No Notebook variables allowed
114 SpinBox_Shrink->setRange( 20, 100 );
115 SpinBox_Shrink->setSingleStep( 1 );
116 SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
117 SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
119 ButtonGroup1Layout->addWidget( TextLabel_Fill, 0, 0 );
120 ButtonGroup1Layout->addWidget( btnFillColor, 0, 1 );
121 ButtonGroup1Layout->addWidget( TextLabel_BackFace, 0, 2 );
122 ButtonGroup1Layout->addWidget( btnBackFaceColor, 0, 3 );
123 ButtonGroup1Layout->addWidget( TextLabel_Outine, 1, 0 );
124 ButtonGroup1Layout->addWidget( btnOutlineColor, 1, 1 );
125 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Color, 1, 2 );
126 ButtonGroup1Layout->addWidget( btn0DElementsColor, 1, 3 );
127 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Size, 2, 0 );
128 ButtonGroup1Layout->addWidget( SpinBox_0DElements_Size, 2, 1 );
129 ButtonGroup1Layout->addWidget( TextLabel_Width, 3, 0 );
130 ButtonGroup1Layout->addWidget( SpinBox_Width, 3, 1 );
131 ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff, 3, 2 );
132 ButtonGroup1Layout->addWidget( SpinBox_Shrink, 3, 3 );
134 // -------------------------------
135 QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
136 QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2 );
137 ButtonGroup2Layout->setSpacing( SPACING );
138 ButtonGroup2Layout->setMargin( MARGIN );
140 QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
141 btnNodeColor = new QtxColorButton( ButtonGroup2 );
143 QGroupBox* MarkerGroup = new QGroupBox( tr( "Marker" ), ButtonGroup2 );
144 QVBoxLayout* MarkerGroupLayout = new QVBoxLayout( MarkerGroup );
145 MarkerGroupLayout->setSpacing( 0 );
146 MarkerGroupLayout->setMargin( 0 );
148 MarkerWidget = new VTKViewer_MarkerWidget( MarkerGroup );
150 MarkerGroupLayout->addWidget( MarkerWidget );
152 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color, 0, 0 );
153 ButtonGroup2Layout->addWidget( btnNodeColor, 0, 1 );
154 ButtonGroup2Layout->addWidget( MarkerGroup, 1, 0, 1, 3 );
155 ButtonGroup2Layout->setColumnStretch( 2, 1 );
157 // -------------------------------
158 QGroupBox* ButtonGroup3 = new QGroupBox( tr( "Orientation of faces" ), this );
159 QGridLayout* ButtonGroup3Layout = new QGridLayout( ButtonGroup3 );
160 ButtonGroup3Layout->setSpacing( SPACING );
161 ButtonGroup3Layout->setMargin( MARGIN );
163 QLabel* TextLabel_Orientation_Color = new QLabel( tr( "Color" ), ButtonGroup3 );
164 btnOrientationColor = new QtxColorButton( ButtonGroup3 );
166 QLabel* TextLabel_Orientation_Scale = new QLabel( tr( "Scale" ), ButtonGroup3 );
167 SpinBox_Orientation_Scale = new SMESHGUI_SpinBox( ButtonGroup3 );
168 SpinBox_Orientation_Scale->setAcceptNames( false ); // No Notebook variables allowed
169 SpinBox_Orientation_Scale->RangeStepAndValidator( .05, .5, .05, "parametric_precision" );
170 SpinBox_Orientation_Scale->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
171 SpinBox_Orientation_Scale->setButtonSymbols( QSpinBox::PlusMinus );
173 CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D vectors" ), ButtonGroup3 );
175 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Color, 0, 0 );
176 ButtonGroup3Layout->addWidget( btnOrientationColor, 0, 1 );
177 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Scale, 0, 2 );
178 ButtonGroup3Layout->addWidget( SpinBox_Orientation_Scale, 0, 3 );
179 ButtonGroup3Layout->addWidget( CheckBox_Orientation_3DVectors, 1, 0, 1, 4 );
181 // -------------------------------
182 QGroupBox* GroupButtons = new QGroupBox( this );
183 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
184 GroupButtonsLayout->setSpacing( SPACING );
185 GroupButtonsLayout->setMargin( MARGIN );
187 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
188 buttonOk->setAutoDefault( true );
189 buttonOk->setDefault( true );
191 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
192 buttonCancel->setAutoDefault( true );
194 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ), GroupButtons );
195 buttonHelp->setAutoDefault( true );
197 GroupButtonsLayout->addWidget( buttonOk );
198 GroupButtonsLayout->addSpacing( 10 );
199 GroupButtonsLayout->addStretch();
200 GroupButtonsLayout->addWidget( buttonCancel );
201 GroupButtonsLayout->addWidget( buttonHelp );
203 // -------------------------------
204 topLayout->addWidget( ButtonGroup1 );
205 topLayout->addWidget( ButtonGroup2 );
206 topLayout->addWidget( ButtonGroup3 );
207 topLayout->addWidget( GroupButtons );
209 // -------------------------------
210 mySMESHGUI->SetActiveDialogBox( this );
212 myHelpFileName = "colors_size_page.html";
214 /* signals and slots connections */
215 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
216 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
217 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
219 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
220 this, SLOT( DeactivateActiveDialog() ) );
221 /* to close dialog if study change */
222 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
223 this, SLOT( ClickOnCancel() ) );
226 //=================================================================================
227 // function : ~SMESHGUI_Preferences_ColorDlg()
228 // purpose : Destructor
229 //=================================================================================
230 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
234 //=================================================================================
235 // function : ClickOnOk()
237 //=================================================================================
238 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
240 mySMESHGUI->ResetState();
244 //=================================================================================
245 // function : ClickOnCancel()
247 //=================================================================================
248 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
250 mySMESHGUI->ResetState();
254 //=================================================================================
255 // function : ClickOnHelp()
257 //=================================================================================
258 void SMESHGUI_Preferences_ColorDlg::ClickOnHelp()
260 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
262 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
266 platform = "winapplication";
268 platform = "application";
270 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
271 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
272 arg(app->resourceMgr()->stringValue("ExternalBrowser",
274 arg(myHelpFileName));
278 //=================================================================================
279 // function : DeactivateActiveDialog()
281 //=================================================================================
282 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
286 //=================================================================================
287 // function : closeEvent()
289 //=================================================================================
290 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
292 ClickOnCancel(); /* same than click on cancel button */
295 //=================================================================================
296 // function : ActivateThisDialog()
298 //=================================================================================
299 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
301 /* Emit a signal to deactivate any active dialog */
302 mySMESHGUI->EmitSignalDeactivateDialog();
305 //=================================================================================
306 // function : SetColor()
308 //=================================================================================
309 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
312 case 1 : btnFillColor->setColor( color ); break; // fill
313 case 2 : btnOutlineColor->setColor( color ); break; // outline
314 case 3 : btnNodeColor->setColor( color ); break; // node
315 case 4 : btnBackFaceColor->setColor( color ); break; // back face
316 case 5 : btn0DElementsColor->setColor( color ); break; // 0d elements
317 case 6 : btnOrientationColor->setColor( color ); break; // orientation of faces
322 //=================================================================================
323 // function : GetColor()
325 //=================================================================================
326 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
330 case 1 : color = btnFillColor->color(); break; // fill
331 case 2 : color = btnOutlineColor->color(); break; // outline
332 case 3 : color = btnNodeColor->color(); break; // node
333 case 4 : color = btnBackFaceColor->color(); break; // back face
334 case 5 : color = btn0DElementsColor->color(); break; // 0d elements
335 case 6 : color = btnOrientationColor->color(); break; // orientation of faces
341 //=================================================================================
342 // function : SetIntValue()
344 //=================================================================================
345 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
348 case 1 : SpinBox_Width->setValue( value ); break; // width
349 case 2 : SpinBox_Shrink->setValue( value ); break; // shrink coeff
350 case 3 : SpinBox_0DElements_Size->setValue( value ); break; // 0d elements
355 //=================================================================================
356 // function : GetIntValue()
358 //=================================================================================
359 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
363 case 1 : res = SpinBox_Width->value(); break; // width
364 case 2 : res = SpinBox_Shrink->value(); break; // shrink coeff
365 case 3 : res = SpinBox_0DElements_Size->value(); break; // 0d elements
371 //=================================================================================
372 // function : SetDoubleValue()
374 //=================================================================================
375 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
378 case 1 : SpinBox_Orientation_Scale->setValue( value ); break; // orientation scale
383 //=================================================================================
384 // function : GetDoubleValue()
386 //=================================================================================
387 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
391 case 1 : res = SpinBox_Orientation_Scale->value(); break; // orientation scale
397 //=================================================================================
398 // function : SetBooleanValue()
400 //=================================================================================
401 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
404 case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break; // 3D vectors
409 //=================================================================================
410 // function : GetBooleanValue()
412 //=================================================================================
413 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
417 case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break; // 3D vectors
423 //=================================================================================
424 // function : setCustomMarkerMap()
426 //=================================================================================
427 void SMESHGUI_Preferences_ColorDlg::setCustomMarkerMap( VTK::MarkerMap theMarkerMap )
429 MarkerWidget->setCustomMarkerMap( theMarkerMap );
432 //=================================================================================
433 // function : getCustomMarkerMap()
435 //=================================================================================
436 VTK::MarkerMap SMESHGUI_Preferences_ColorDlg::getCustomMarkerMap()
438 return MarkerWidget->getCustomMarkerMap();
441 //=================================================================================
442 // function : setStandardMarker()
444 //=================================================================================
445 void SMESHGUI_Preferences_ColorDlg::setStandardMarker( VTK::MarkerType theMarkerType,
446 VTK::MarkerScale theMarkerScale )
448 MarkerWidget->setStandardMarker( theMarkerType, theMarkerScale );
451 //=================================================================================
452 // function : setCustomMarker()
454 //=================================================================================
455 void SMESHGUI_Preferences_ColorDlg::setCustomMarker( int theId )
457 MarkerWidget->setCustomMarker( theId );
460 //=================================================================================
461 // function : getMarkerType()
463 //=================================================================================
464 VTK::MarkerType SMESHGUI_Preferences_ColorDlg::getMarkerType() const
466 return MarkerWidget->getMarkerType();
469 //=================================================================================
470 // function : getStandardMarkerScale()
472 //=================================================================================
473 VTK::MarkerScale SMESHGUI_Preferences_ColorDlg::getStandardMarkerScale() const
475 return MarkerWidget->getStandardMarkerScale();
478 //=================================================================================
479 // function : getCustomMarkerID()
481 //=================================================================================
482 int SMESHGUI_Preferences_ColorDlg::getCustomMarkerID() const
484 return MarkerWidget->getCustomMarkerID();
487 //=================================================================================
488 // function : keyPressEvent()
490 //=================================================================================
491 void SMESHGUI_Preferences_ColorDlg::keyPressEvent( QKeyEvent* e )
493 QDialog::keyPressEvent( e );
494 if ( e->isAccepted() )
497 if ( e->key() == Qt::Key_F1 ) {