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 <QtxColorButton.h>
37 #include <VTKViewer_MarkerWidget.h>
38 #include <SalomeApp_IntSpinBox.h>
43 #include <QPushButton>
44 #include <QVBoxLayout>
45 #include <QHBoxLayout>
46 #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 SalomeApp_IntSpinBox( ButtonGroup1 );
92 SpinBox_0DElements_Size->setAcceptNames( false ); // No Notebook variables allowed
93 SpinBox_0DElements_Size->setRange( 1, 10 );
94 SpinBox_0DElements_Size->setSingleStep( 1 );
95 SpinBox_0DElements_Size->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
96 SpinBox_0DElements_Size->setButtonSymbols( QSpinBox::PlusMinus );
98 QLabel* TextLabel_Width = new QLabel( tr( "Width" ), ButtonGroup1 );
99 SpinBox_Width = new SalomeApp_IntSpinBox( ButtonGroup1 );
100 SpinBox_Width->setAcceptNames( false ); // No Notebook variables allowed
101 SpinBox_Width->setRange( 0, 5 );
102 SpinBox_Width->setSingleStep( 1 );
103 SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
104 SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
106 QLabel* TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1 );
107 SpinBox_Shrink = new SalomeApp_IntSpinBox( ButtonGroup1 );
108 SpinBox_Shrink->setAcceptNames( false ); // No Notebook variables allowed
109 SpinBox_Shrink->setRange( 20, 100 );
110 SpinBox_Shrink->setSingleStep( 1 );
111 SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
112 SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
114 ButtonGroup1Layout->addWidget( TextLabel_Fill, 0, 0 );
115 ButtonGroup1Layout->addWidget( btnFillColor, 0, 1 );
116 ButtonGroup1Layout->addWidget( TextLabel_BackFace, 0, 2 );
117 ButtonGroup1Layout->addWidget( btnBackFaceColor, 0, 3 );
118 ButtonGroup1Layout->addWidget( TextLabel_Outine, 1, 0 );
119 ButtonGroup1Layout->addWidget( btnOutlineColor, 1, 1 );
120 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Color, 1, 2 );
121 ButtonGroup1Layout->addWidget( btn0DElementsColor, 1, 3 );
122 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Size, 2, 0 );
123 ButtonGroup1Layout->addWidget( SpinBox_0DElements_Size, 2, 1 );
124 ButtonGroup1Layout->addWidget( TextLabel_Width, 3, 0 );
125 ButtonGroup1Layout->addWidget( SpinBox_Width, 3, 1 );
126 ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff, 3, 2 );
127 ButtonGroup1Layout->addWidget( SpinBox_Shrink, 3, 3 );
129 // -------------------------------
130 QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
131 QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2 );
132 ButtonGroup2Layout->setSpacing( SPACING );
133 ButtonGroup2Layout->setMargin( MARGIN );
135 QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
136 btnNodeColor = new QtxColorButton( ButtonGroup2 );
138 QGroupBox* MarkerGroup = new QGroupBox( tr( "Marker" ), ButtonGroup2 );
139 QVBoxLayout* MarkerGroupLayout = new QVBoxLayout( MarkerGroup );
140 MarkerGroupLayout->setSpacing( 0 );
141 MarkerGroupLayout->setMargin( 0 );
143 MarkerWidget = new VTKViewer_MarkerWidget( MarkerGroup );
145 MarkerGroupLayout->addWidget( MarkerWidget );
147 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color, 0, 0 );
148 ButtonGroup2Layout->addWidget( btnNodeColor, 0, 1 );
149 ButtonGroup2Layout->addWidget( MarkerGroup, 1, 0, 1, 3 );
150 ButtonGroup2Layout->setColumnStretch( 2, 1 );
152 // -------------------------------
153 QGroupBox* ButtonGroup3 = new QGroupBox( tr( "Orientation of faces" ), this );
154 QGridLayout* ButtonGroup3Layout = new QGridLayout( ButtonGroup3 );
155 ButtonGroup3Layout->setSpacing( SPACING );
156 ButtonGroup3Layout->setMargin( MARGIN );
158 QLabel* TextLabel_Orientation_Color = new QLabel( tr( "Color" ), ButtonGroup3 );
159 btnOrientationColor = new QtxColorButton( ButtonGroup3 );
161 QLabel* TextLabel_Orientation_Scale = new QLabel( tr( "Scale" ), ButtonGroup3 );
162 SpinBox_Orientation_Scale = new SMESHGUI_SpinBox( ButtonGroup3 );
163 SpinBox_Orientation_Scale->setAcceptNames( false ); // No Notebook variables allowed
164 SpinBox_Orientation_Scale->RangeStepAndValidator( .05, .5, .05, "parametric_precision" );
165 SpinBox_Orientation_Scale->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
166 SpinBox_Orientation_Scale->setButtonSymbols( QSpinBox::PlusMinus );
168 CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D vectors" ), ButtonGroup3 );
170 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Color, 0, 0 );
171 ButtonGroup3Layout->addWidget( btnOrientationColor, 0, 1 );
172 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Scale, 0, 2 );
173 ButtonGroup3Layout->addWidget( SpinBox_Orientation_Scale, 0, 3 );
174 ButtonGroup3Layout->addWidget( CheckBox_Orientation_3DVectors, 1, 0, 1, 4 );
176 // -------------------------------
177 QGroupBox* GroupButtons = new QGroupBox( this );
178 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
179 GroupButtonsLayout->setSpacing( SPACING );
180 GroupButtonsLayout->setMargin( MARGIN );
182 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
183 buttonOk->setAutoDefault( true );
184 buttonOk->setDefault( true );
186 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
187 buttonCancel->setAutoDefault( true );
189 GroupButtonsLayout->addWidget( buttonOk );
190 GroupButtonsLayout->addSpacing( 10 );
191 GroupButtonsLayout->addStretch();
192 GroupButtonsLayout->addWidget( buttonCancel );
194 // -------------------------------
195 topLayout->addWidget( ButtonGroup1 );
196 topLayout->addWidget( ButtonGroup2 );
197 topLayout->addWidget( ButtonGroup3 );
198 topLayout->addWidget( GroupButtons );
200 // -------------------------------
201 mySMESHGUI->SetActiveDialogBox( this );
203 /* signals and slots connections */
204 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
205 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
207 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
208 this, SLOT( DeactivateActiveDialog() ) );
209 /* to close dialog if study change */
210 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
211 this, SLOT( ClickOnCancel() ) );
214 //=================================================================================
215 // function : ~SMESHGUI_Preferences_ColorDlg()
216 // purpose : Destructor
217 //=================================================================================
218 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
222 //=================================================================================
223 // function : ClickOnOk()
225 //=================================================================================
226 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
228 mySMESHGUI->ResetState();
232 //=================================================================================
233 // function : ClickOnCancel()
235 //=================================================================================
236 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
238 mySMESHGUI->ResetState();
242 //=================================================================================
243 // function : DeactivateActiveDialog()
245 //=================================================================================
246 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
250 //=================================================================================
251 // function : closeEvent()
253 //=================================================================================
254 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
256 ClickOnCancel(); /* same than click on cancel button */
259 //=================================================================================
260 // function : ActivateThisDialog()
262 //=================================================================================
263 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
265 /* Emit a signal to deactivate any active dialog */
266 mySMESHGUI->EmitSignalDeactivateDialog();
269 //=================================================================================
270 // function : SetColor()
272 //=================================================================================
273 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
276 case 1 : btnFillColor->setColor( color ); break; // fill
277 case 2 : btnOutlineColor->setColor( color ); break; // outline
278 case 3 : btnNodeColor->setColor( color ); break; // node
279 case 4 : btnBackFaceColor->setColor( color ); break; // back face
280 case 5 : btn0DElementsColor->setColor( color ); break; // 0d elements
281 case 6 : btnOrientationColor->setColor( color ); break; // orientation of faces
286 //=================================================================================
287 // function : GetColor()
289 //=================================================================================
290 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
294 case 1 : color = btnFillColor->color(); break; // fill
295 case 2 : color = btnOutlineColor->color(); break; // outline
296 case 3 : color = btnNodeColor->color(); break; // node
297 case 4 : color = btnBackFaceColor->color(); break; // back face
298 case 5 : color = btn0DElementsColor->color(); break; // 0d elements
299 case 6 : color = btnOrientationColor->color(); break; // orientation of faces
305 //=================================================================================
306 // function : SetIntValue()
308 //=================================================================================
309 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
312 case 1 : SpinBox_Width->setValue( value ); break; // width
313 case 2 : SpinBox_Shrink->setValue( value ); break; // shrink coeff
314 case 3 : SpinBox_0DElements_Size->setValue( value ); break; // 0d elements
319 //=================================================================================
320 // function : GetIntValue()
322 //=================================================================================
323 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
327 case 1 : res = SpinBox_Width->value(); break; // width
328 case 2 : res = SpinBox_Shrink->value(); break; // shrink coeff
329 case 3 : res = SpinBox_0DElements_Size->value(); break; // 0d elements
335 //=================================================================================
336 // function : SetDoubleValue()
338 //=================================================================================
339 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
342 case 1 : SpinBox_Orientation_Scale->setValue( value ); break; // orientation scale
347 //=================================================================================
348 // function : GetDoubleValue()
350 //=================================================================================
351 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
355 case 1 : res = SpinBox_Orientation_Scale->value(); break; // orientation scale
361 //=================================================================================
362 // function : SetBooleanValue()
364 //=================================================================================
365 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
368 case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break; // 3D vectors
373 //=================================================================================
374 // function : GetBooleanValue()
376 //=================================================================================
377 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
381 case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break; // 3D vectors
387 //=================================================================================
388 // function : setCustomMarkerMap()
390 //=================================================================================
391 void SMESHGUI_Preferences_ColorDlg::setCustomMarkerMap( VTK::MarkerMap theMarkerMap )
393 MarkerWidget->setCustomMarkerMap( theMarkerMap );
396 //=================================================================================
397 // function : getCustomMarkerMap()
399 //=================================================================================
400 VTK::MarkerMap SMESHGUI_Preferences_ColorDlg::getCustomMarkerMap()
402 return MarkerWidget->getCustomMarkerMap();
405 //=================================================================================
406 // function : setStandardMarker()
408 //=================================================================================
409 void SMESHGUI_Preferences_ColorDlg::setStandardMarker( VTK::MarkerType theMarkerType,
410 VTK::MarkerScale theMarkerScale )
412 MarkerWidget->setStandardMarker( theMarkerType, theMarkerScale );
415 //=================================================================================
416 // function : setCustomMarker()
418 //=================================================================================
419 void SMESHGUI_Preferences_ColorDlg::setCustomMarker( int theId )
421 MarkerWidget->setCustomMarker( theId );
424 //=================================================================================
425 // function : getMarkerType()
427 //=================================================================================
428 VTK::MarkerType SMESHGUI_Preferences_ColorDlg::getMarkerType() const
430 return MarkerWidget->getMarkerType();
433 //=================================================================================
434 // function : getStandardMarkerScale()
436 //=================================================================================
437 VTK::MarkerScale SMESHGUI_Preferences_ColorDlg::getStandardMarkerScale() const
439 return MarkerWidget->getStandardMarkerScale();
442 //=================================================================================
443 // function : getCustomMarkerID()
445 //=================================================================================
446 int SMESHGUI_Preferences_ColorDlg::getCustomMarkerID() const
448 return MarkerWidget->getCustomMarkerID();