1 // Copyright (C) 2007-2008 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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_Preferences_ColorDlg.cxx
24 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
27 #include "SMESHGUI_Preferences_ColorDlg.h"
30 #include "SMESHGUI_Utils.h"
32 // SALOME GUI includes
33 #include <SUIT_Desktop.h>
34 #include <QtxColorButton.h>
35 #include <QtxDoubleSpinBox.h>
36 #include <QtxIntSpinBox.h>
37 #include <VTKViewer_MarkerWidget.h>
42 #include <QPushButton>
43 #include <QVBoxLayout>
44 #include <QHBoxLayout>
45 #include <QGridLayout>
52 //=================================================================================
53 // function : SMESHGUI_Preferences_ColorDlg()
54 // purpose : Constructs a SMESHGUI_Preferences_ColorDlg which is a child
55 // of 'parent', with the name 'name' and widget flags set to 'f'
56 // The dialog will by default be modeless, unless you
57 // set'modal' to true to construct a modal dialog.
58 //=================================================================================
59 SMESHGUI_Preferences_ColorDlg::SMESHGUI_Preferences_ColorDlg( SMESHGUI* theModule )
60 : QDialog( SMESH::GetDesktop( theModule ) ),
61 mySMESHGUI( theModule )
64 setWindowTitle( tr( "Preferences - Set Color" ) );
65 setSizeGripEnabled( true );
67 // -------------------------------
68 QVBoxLayout* topLayout = new QVBoxLayout( this );
69 topLayout->setSpacing( SPACING );
70 topLayout->setMargin( MARGIN );
72 // -------------------------------
73 QGroupBox* ButtonGroup1 = new QGroupBox( tr( "Elements" ), this );
74 QGridLayout* ButtonGroup1Layout = new QGridLayout( ButtonGroup1 );
75 ButtonGroup1Layout->setSpacing( SPACING );
76 ButtonGroup1Layout->setMargin( MARGIN );
78 QLabel* TextLabel_Fill = new QLabel( tr( "Fill" ), ButtonGroup1 );
79 btnFillColor = new QtxColorButton( ButtonGroup1 );
81 QLabel* TextLabel_BackFace = new QLabel( tr( "Back Face" ), ButtonGroup1 );
82 btnBackFaceColor = new QtxColorButton( ButtonGroup1 );
84 QLabel* TextLabel_Outine = new QLabel( tr( "Outline" ), ButtonGroup1 );
85 btnOutlineColor = new QtxColorButton( ButtonGroup1 );
87 QLabel* TextLabel_0DElements_Color = new QLabel( tr( "0D elements" ), ButtonGroup1 );
88 btn0DElementsColor = new QtxColorButton( ButtonGroup1 );
90 QLabel* TextLabel_0DElements_Size = new QLabel( tr( "Size of 0D elements" ), ButtonGroup1 );
91 SpinBox_0DElements_Size = new QSpinBox( ButtonGroup1 );
92 SpinBox_0DElements_Size->setRange( 1, 10 );
93 SpinBox_0DElements_Size->setSingleStep( 1 );
94 SpinBox_0DElements_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
95 SpinBox_0DElements_Size->setButtonSymbols( QSpinBox::PlusMinus );
97 QLabel* TextLabel_Width = new QLabel( tr( "Width" ), ButtonGroup1 );
98 SpinBox_Width = new QSpinBox( ButtonGroup1 );
99 SpinBox_Width->setRange( 0, 5 );
100 SpinBox_Width->setSingleStep( 1 );
101 SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
102 SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
104 QLabel* TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1 );
105 SpinBox_Shrink = new QtxIntSpinBox( ButtonGroup1 );
106 SpinBox_Shrink->setRange( 20, 100 );
107 SpinBox_Shrink->setSingleStep( 1 );
108 SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
109 SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
111 ButtonGroup1Layout->addWidget( TextLabel_Fill, 0, 0 );
112 ButtonGroup1Layout->addWidget( btnFillColor, 0, 1 );
113 ButtonGroup1Layout->addWidget( TextLabel_BackFace, 0, 2 );
114 ButtonGroup1Layout->addWidget( btnBackFaceColor, 0, 3 );
115 ButtonGroup1Layout->addWidget( TextLabel_Outine, 1, 0 );
116 ButtonGroup1Layout->addWidget( btnOutlineColor, 1, 1 );
117 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Color, 1, 2 );
118 ButtonGroup1Layout->addWidget( btn0DElementsColor, 1, 3 );
119 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Size, 2, 0 );
120 ButtonGroup1Layout->addWidget( SpinBox_0DElements_Size, 2, 1 );
121 ButtonGroup1Layout->addWidget( TextLabel_Width, 3, 0 );
122 ButtonGroup1Layout->addWidget( SpinBox_Width, 3, 1 );
123 ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff, 3, 2 );
124 ButtonGroup1Layout->addWidget( SpinBox_Shrink, 3, 3 );
126 // -------------------------------
127 QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
128 QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2 );
129 ButtonGroup2Layout->setSpacing( SPACING );
130 ButtonGroup2Layout->setMargin( MARGIN );
132 QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
133 btnNodeColor = new QtxColorButton( ButtonGroup2 );
135 QGroupBox* MarkerGroup = new QGroupBox( tr( "Marker" ), ButtonGroup2 );
136 QVBoxLayout* MarkerGroupLayout = new QVBoxLayout( MarkerGroup );
137 MarkerGroupLayout->setSpacing( 0 );
138 MarkerGroupLayout->setMargin( 0 );
140 MarkerWidget = new VTKViewer_MarkerWidget( MarkerGroup );
142 MarkerGroupLayout->addWidget( MarkerWidget );
144 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color, 0, 0 );
145 ButtonGroup2Layout->addWidget( btnNodeColor, 0, 1 );
146 ButtonGroup2Layout->addWidget( MarkerGroup, 1, 0, 1, 3 );
147 ButtonGroup2Layout->setColumnStretch( 2, 1 );
149 // -------------------------------
150 QGroupBox* ButtonGroup3 = new QGroupBox( tr( "Orientation of faces" ), this );
151 QGridLayout* ButtonGroup3Layout = new QGridLayout( ButtonGroup3 );
152 ButtonGroup3Layout->setSpacing( SPACING );
153 ButtonGroup3Layout->setMargin( MARGIN );
155 QLabel* TextLabel_Orientation_Color = new QLabel( tr( "Color" ), ButtonGroup3 );
156 btnOrientationColor = new QtxColorButton( ButtonGroup3 );
158 QLabel* TextLabel_Orientation_Scale = new QLabel( tr( "Scale" ), ButtonGroup3 );
159 SpinBox_Orientation_Scale = new QtxDoubleSpinBox( ButtonGroup3 );
160 SpinBox_Orientation_Scale->setRange( 0.05, 0.5 );
161 SpinBox_Orientation_Scale->setSingleStep( 0.05 );
162 SpinBox_Orientation_Scale->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
163 SpinBox_Orientation_Scale->setButtonSymbols( QSpinBox::PlusMinus );
165 CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D vectors" ), ButtonGroup3 );
167 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Color, 0, 0 );
168 ButtonGroup3Layout->addWidget( btnOrientationColor, 0, 1 );
169 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Scale, 0, 2 );
170 ButtonGroup3Layout->addWidget( SpinBox_Orientation_Scale, 0, 3 );
171 ButtonGroup3Layout->addWidget( CheckBox_Orientation_3DVectors, 1, 0, 1, 4 );
173 // -------------------------------
174 QGroupBox* GroupButtons = new QGroupBox( this );
175 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
176 GroupButtonsLayout->setSpacing( SPACING );
177 GroupButtonsLayout->setMargin( MARGIN );
179 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
180 buttonOk->setAutoDefault( true );
181 buttonOk->setDefault( true );
183 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
184 buttonCancel->setAutoDefault( true );
186 GroupButtonsLayout->addWidget( buttonOk );
187 GroupButtonsLayout->addSpacing( 10 );
188 GroupButtonsLayout->addStretch();
189 GroupButtonsLayout->addWidget( buttonCancel );
191 // -------------------------------
192 topLayout->addWidget( ButtonGroup1 );
193 topLayout->addWidget( ButtonGroup2 );
194 topLayout->addWidget( ButtonGroup3 );
195 topLayout->addWidget( GroupButtons );
197 // -------------------------------
198 mySMESHGUI->SetActiveDialogBox( this );
200 /* signals and slots connections */
201 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
202 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
204 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
205 this, SLOT( DeactivateActiveDialog() ) );
206 /* to close dialog if study change */
207 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
208 this, SLOT( ClickOnCancel() ) );
211 //=================================================================================
212 // function : ~SMESHGUI_Preferences_ColorDlg()
213 // purpose : Destructor
214 //=================================================================================
215 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
219 //=================================================================================
220 // function : ClickOnOk()
222 //=================================================================================
223 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
225 mySMESHGUI->ResetState();
229 //=================================================================================
230 // function : ClickOnCancel()
232 //=================================================================================
233 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
235 mySMESHGUI->ResetState();
239 //=================================================================================
240 // function : DeactivateActiveDialog()
242 //=================================================================================
243 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
247 //=================================================================================
248 // function : closeEvent()
250 //=================================================================================
251 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
253 ClickOnCancel(); /* same than click on cancel button */
256 //=================================================================================
257 // function : ActivateThisDialog()
259 //=================================================================================
260 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
262 /* Emit a signal to deactivate any active dialog */
263 mySMESHGUI->EmitSignalDeactivateDialog();
266 //=================================================================================
267 // function : SetColor()
269 //=================================================================================
270 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
273 case 1 : btnFillColor->setColor( color ); break; // fill
274 case 2 : btnOutlineColor->setColor( color ); break; // outline
275 case 3 : btnNodeColor->setColor( color ); break; // node
276 case 4 : btnBackFaceColor->setColor( color ); break; // back face
277 case 5 : btn0DElementsColor->setColor( color ); break; // 0d elements
278 case 6 : btnOrientationColor->setColor( color ); break; // orientation of faces
283 //=================================================================================
284 // function : GetColor()
286 //=================================================================================
287 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
291 case 1 : color = btnFillColor->color(); break; // fill
292 case 2 : color = btnOutlineColor->color(); break; // outline
293 case 3 : color = btnNodeColor->color(); break; // node
294 case 4 : color = btnBackFaceColor->color(); break; // back face
295 case 5 : color = btn0DElementsColor->color(); break; // 0d elements
296 case 6 : color = btnOrientationColor->color(); break; // orientation of faces
302 //=================================================================================
303 // function : SetIntValue()
305 //=================================================================================
306 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
309 case 1 : SpinBox_Width->setValue( value ); break; // width
310 case 2 : SpinBox_Shrink->setValue( value ); break; // shrink coeff
311 case 3 : SpinBox_0DElements_Size->setValue( value ); break; // 0d elements
316 //=================================================================================
317 // function : GetIntValue()
319 //=================================================================================
320 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
324 case 1 : res = SpinBox_Width->value(); break; // width
325 case 2 : res = SpinBox_Shrink->value(); break; // shrink coeff
326 case 3 : res = SpinBox_0DElements_Size->value(); break; // 0d elements
332 //=================================================================================
333 // function : SetDoubleValue()
335 //=================================================================================
336 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
339 case 1 : SpinBox_Orientation_Scale->setValue( value ); break; // orientation scale
344 //=================================================================================
345 // function : GetDoubleValue()
347 //=================================================================================
348 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
352 case 1 : res = SpinBox_Orientation_Scale->value(); break; // orientation scale
358 //=================================================================================
359 // function : SetBooleanValue()
361 //=================================================================================
362 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
365 case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break; // 3D vectors
370 //=================================================================================
371 // function : GetBooleanValue()
373 //=================================================================================
374 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
378 case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break; // 3D vectors
384 //=================================================================================
385 // function : setCustomMarkerMap()
387 //=================================================================================
388 void SMESHGUI_Preferences_ColorDlg::setCustomMarkerMap( VTK::MarkerMap theMarkerMap )
390 MarkerWidget->setCustomMarkerMap( theMarkerMap );
393 //=================================================================================
394 // function : getCustomMarkerMap()
396 //=================================================================================
397 VTK::MarkerMap SMESHGUI_Preferences_ColorDlg::getCustomMarkerMap()
399 return MarkerWidget->getCustomMarkerMap();
402 //=================================================================================
403 // function : setStandardMarker()
405 //=================================================================================
406 void SMESHGUI_Preferences_ColorDlg::setStandardMarker( VTK::MarkerType theMarkerType,
407 VTK::MarkerScale theMarkerScale )
409 MarkerWidget->setStandardMarker( theMarkerType, theMarkerScale );
412 //=================================================================================
413 // function : setCustomMarker()
415 //=================================================================================
416 void SMESHGUI_Preferences_ColorDlg::setCustomMarker( int theId )
418 MarkerWidget->setCustomMarker( theId );
421 //=================================================================================
422 // function : getMarkerType()
424 //=================================================================================
425 VTK::MarkerType SMESHGUI_Preferences_ColorDlg::getMarkerType() const
427 return MarkerWidget->getMarkerType();
430 //=================================================================================
431 // function : getStandardMarkerScale()
433 //=================================================================================
434 VTK::MarkerScale SMESHGUI_Preferences_ColorDlg::getStandardMarkerScale() const
436 return MarkerWidget->getStandardMarkerScale();
439 //=================================================================================
440 // function : getCustomMarkerID()
442 //=================================================================================
443 int SMESHGUI_Preferences_ColorDlg::getCustomMarkerID() const
445 return MarkerWidget->getCustomMarkerID();