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_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
33 // SALOME GUI includes
34 #include <SUIT_Desktop.h>
35 #include <QtxColorButton.h>
36 #include <VTKViewer_MarkerWidget.h>
37 #include <SalomeApp_IntSpinBox.h>
42 #include <QPushButton>
43 #include <QVBoxLayout>
44 #include <QHBoxLayout>
45 #include <QGridLayout>
51 //=================================================================================
52 // function : SMESHGUI_Preferences_ColorDlg()
53 // purpose : Constructs a SMESHGUI_Preferences_ColorDlg which is a child
54 // of 'parent', with the name 'name' and widget flags set to 'f'
55 // The dialog will by default be modeless, unless you
56 // set'modal' to true to construct a modal dialog.
57 //=================================================================================
58 SMESHGUI_Preferences_ColorDlg::SMESHGUI_Preferences_ColorDlg( SMESHGUI* theModule )
59 : QDialog( SMESH::GetDesktop( theModule ) ),
60 mySMESHGUI( theModule )
63 setWindowTitle( tr( "Preferences - Set Color" ) );
64 setSizeGripEnabled( true );
66 // -------------------------------
67 QVBoxLayout* topLayout = new QVBoxLayout( this );
68 topLayout->setSpacing( SPACING );
69 topLayout->setMargin( MARGIN );
71 // -------------------------------
72 QGroupBox* ButtonGroup1 = new QGroupBox( tr( "Elements" ), this );
73 QGridLayout* ButtonGroup1Layout = new QGridLayout( ButtonGroup1 );
74 ButtonGroup1Layout->setSpacing( SPACING );
75 ButtonGroup1Layout->setMargin( MARGIN );
77 QLabel* TextLabel_Fill = new QLabel( tr( "Fill" ), ButtonGroup1 );
78 btnFillColor = new QtxColorButton( ButtonGroup1 );
80 QLabel* TextLabel_BackFace = new QLabel( tr( "Back Face" ), ButtonGroup1 );
81 btnBackFaceColor = new QtxColorButton( ButtonGroup1 );
83 QLabel* TextLabel_Outine = new QLabel( tr( "Outline" ), ButtonGroup1 );
84 btnOutlineColor = new QtxColorButton( ButtonGroup1 );
86 QLabel* TextLabel_0DElements_Color = new QLabel( tr( "0D elements" ), ButtonGroup1 );
87 btn0DElementsColor = new QtxColorButton( ButtonGroup1 );
89 QLabel* TextLabel_0DElements_Size = new QLabel( tr( "Size of 0D elements" ), ButtonGroup1 );
90 SpinBox_0DElements_Size = new SalomeApp_IntSpinBox( ButtonGroup1 );
91 SpinBox_0DElements_Size->setAcceptNames( false ); // No Notebook variables allowed
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 SalomeApp_IntSpinBox( ButtonGroup1 );
99 SpinBox_Width->setAcceptNames( false ); // No Notebook variables allowed
100 SpinBox_Width->setRange( 0, 5 );
101 SpinBox_Width->setSingleStep( 1 );
102 SpinBox_Width->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
103 SpinBox_Width->setButtonSymbols( QSpinBox::PlusMinus );
105 QLabel* TextLabel_ShrinkCoeff = new QLabel( tr( "Shrink coef." ), ButtonGroup1 );
106 SpinBox_Shrink = new SalomeApp_IntSpinBox( ButtonGroup1 );
107 SpinBox_Shrink->setAcceptNames( false ); // No Notebook variables allowed
108 SpinBox_Shrink->setRange( 20, 100 );
109 SpinBox_Shrink->setSingleStep( 1 );
110 SpinBox_Shrink->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
111 SpinBox_Shrink->setButtonSymbols( QSpinBox::PlusMinus );
113 ButtonGroup1Layout->addWidget( TextLabel_Fill, 0, 0 );
114 ButtonGroup1Layout->addWidget( btnFillColor, 0, 1 );
115 ButtonGroup1Layout->addWidget( TextLabel_BackFace, 0, 2 );
116 ButtonGroup1Layout->addWidget( btnBackFaceColor, 0, 3 );
117 ButtonGroup1Layout->addWidget( TextLabel_Outine, 1, 0 );
118 ButtonGroup1Layout->addWidget( btnOutlineColor, 1, 1 );
119 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Color, 1, 2 );
120 ButtonGroup1Layout->addWidget( btn0DElementsColor, 1, 3 );
121 ButtonGroup1Layout->addWidget( TextLabel_0DElements_Size, 2, 0 );
122 ButtonGroup1Layout->addWidget( SpinBox_0DElements_Size, 2, 1 );
123 ButtonGroup1Layout->addWidget( TextLabel_Width, 3, 0 );
124 ButtonGroup1Layout->addWidget( SpinBox_Width, 3, 1 );
125 ButtonGroup1Layout->addWidget( TextLabel_ShrinkCoeff, 3, 2 );
126 ButtonGroup1Layout->addWidget( SpinBox_Shrink, 3, 3 );
128 // -------------------------------
129 QGroupBox* ButtonGroup2 = new QGroupBox( tr( "Nodes" ), this );
130 QGridLayout* ButtonGroup2Layout = new QGridLayout( ButtonGroup2 );
131 ButtonGroup2Layout->setSpacing( SPACING );
132 ButtonGroup2Layout->setMargin( MARGIN );
134 QLabel* TextLabel_Nodes_Color = new QLabel( tr( "Color" ), ButtonGroup2 );
135 btnNodeColor = new QtxColorButton( ButtonGroup2 );
137 QGroupBox* MarkerGroup = new QGroupBox( tr( "Marker" ), ButtonGroup2 );
138 QVBoxLayout* MarkerGroupLayout = new QVBoxLayout( MarkerGroup );
139 MarkerGroupLayout->setSpacing( 0 );
140 MarkerGroupLayout->setMargin( 0 );
142 MarkerWidget = new VTKViewer_MarkerWidget( MarkerGroup );
144 MarkerGroupLayout->addWidget( MarkerWidget );
146 ButtonGroup2Layout->addWidget( TextLabel_Nodes_Color, 0, 0 );
147 ButtonGroup2Layout->addWidget( btnNodeColor, 0, 1 );
148 ButtonGroup2Layout->addWidget( MarkerGroup, 1, 0, 1, 3 );
149 ButtonGroup2Layout->setColumnStretch( 2, 1 );
151 // -------------------------------
152 QGroupBox* ButtonGroup3 = new QGroupBox( tr( "Orientation of faces" ), this );
153 QGridLayout* ButtonGroup3Layout = new QGridLayout( ButtonGroup3 );
154 ButtonGroup3Layout->setSpacing( SPACING );
155 ButtonGroup3Layout->setMargin( MARGIN );
157 QLabel* TextLabel_Orientation_Color = new QLabel( tr( "Color" ), ButtonGroup3 );
158 btnOrientationColor = new QtxColorButton( ButtonGroup3 );
160 QLabel* TextLabel_Orientation_Scale = new QLabel( tr( "Scale" ), ButtonGroup3 );
161 SpinBox_Orientation_Scale = new SMESHGUI_SpinBox( ButtonGroup3 );
162 SpinBox_Orientation_Scale->setAcceptNames( false ); // No Notebook variables allowed
163 SpinBox_Orientation_Scale->RangeStepAndValidator( .05, .5, .05, "parametric_precision" );
164 SpinBox_Orientation_Scale->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
165 SpinBox_Orientation_Scale->setButtonSymbols( QSpinBox::PlusMinus );
167 CheckBox_Orientation_3DVectors = new QCheckBox( tr( "3D vectors" ), ButtonGroup3 );
169 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Color, 0, 0 );
170 ButtonGroup3Layout->addWidget( btnOrientationColor, 0, 1 );
171 ButtonGroup3Layout->addWidget( TextLabel_Orientation_Scale, 0, 2 );
172 ButtonGroup3Layout->addWidget( SpinBox_Orientation_Scale, 0, 3 );
173 ButtonGroup3Layout->addWidget( CheckBox_Orientation_3DVectors, 1, 0, 1, 4 );
175 // -------------------------------
176 QGroupBox* GroupButtons = new QGroupBox( this );
177 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
178 GroupButtonsLayout->setSpacing( SPACING );
179 GroupButtonsLayout->setMargin( MARGIN );
181 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
182 buttonOk->setAutoDefault( true );
183 buttonOk->setDefault( true );
185 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
186 buttonCancel->setAutoDefault( true );
188 GroupButtonsLayout->addWidget( buttonOk );
189 GroupButtonsLayout->addSpacing( 10 );
190 GroupButtonsLayout->addStretch();
191 GroupButtonsLayout->addWidget( buttonCancel );
193 // -------------------------------
194 topLayout->addWidget( ButtonGroup1 );
195 topLayout->addWidget( ButtonGroup2 );
196 topLayout->addWidget( ButtonGroup3 );
197 topLayout->addWidget( GroupButtons );
199 // -------------------------------
200 mySMESHGUI->SetActiveDialogBox( this );
202 /* signals and slots connections */
203 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
204 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
206 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ),
207 this, SLOT( DeactivateActiveDialog() ) );
208 /* to close dialog if study change */
209 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ),
210 this, SLOT( ClickOnCancel() ) );
213 //=================================================================================
214 // function : ~SMESHGUI_Preferences_ColorDlg()
215 // purpose : Destructor
216 //=================================================================================
217 SMESHGUI_Preferences_ColorDlg::~SMESHGUI_Preferences_ColorDlg()
221 //=================================================================================
222 // function : ClickOnOk()
224 //=================================================================================
225 void SMESHGUI_Preferences_ColorDlg::ClickOnOk()
227 mySMESHGUI->ResetState();
231 //=================================================================================
232 // function : ClickOnCancel()
234 //=================================================================================
235 void SMESHGUI_Preferences_ColorDlg::ClickOnCancel()
237 mySMESHGUI->ResetState();
241 //=================================================================================
242 // function : DeactivateActiveDialog()
244 //=================================================================================
245 void SMESHGUI_Preferences_ColorDlg::DeactivateActiveDialog()
249 //=================================================================================
250 // function : closeEvent()
252 //=================================================================================
253 void SMESHGUI_Preferences_ColorDlg::closeEvent( QCloseEvent* )
255 ClickOnCancel(); /* same than click on cancel button */
258 //=================================================================================
259 // function : ActivateThisDialog()
261 //=================================================================================
262 void SMESHGUI_Preferences_ColorDlg::ActivateThisDialog()
264 /* Emit a signal to deactivate any active dialog */
265 mySMESHGUI->EmitSignalDeactivateDialog();
268 //=================================================================================
269 // function : SetColor()
271 //=================================================================================
272 void SMESHGUI_Preferences_ColorDlg::SetColor( int type, const QColor& color )
275 case 1 : btnFillColor->setColor( color ); break; // fill
276 case 2 : btnOutlineColor->setColor( color ); break; // outline
277 case 3 : btnNodeColor->setColor( color ); break; // node
278 case 4 : btnBackFaceColor->setColor( color ); break; // back face
279 case 5 : btn0DElementsColor->setColor( color ); break; // 0d elements
280 case 6 : btnOrientationColor->setColor( color ); break; // orientation of faces
285 //=================================================================================
286 // function : GetColor()
288 //=================================================================================
289 QColor SMESHGUI_Preferences_ColorDlg::GetColor( int type )
293 case 1 : color = btnFillColor->color(); break; // fill
294 case 2 : color = btnOutlineColor->color(); break; // outline
295 case 3 : color = btnNodeColor->color(); break; // node
296 case 4 : color = btnBackFaceColor->color(); break; // back face
297 case 5 : color = btn0DElementsColor->color(); break; // 0d elements
298 case 6 : color = btnOrientationColor->color(); break; // orientation of faces
304 //=================================================================================
305 // function : SetIntValue()
307 //=================================================================================
308 void SMESHGUI_Preferences_ColorDlg::SetIntValue( int type, int value )
311 case 1 : SpinBox_Width->setValue( value ); break; // width
312 case 2 : SpinBox_Shrink->setValue( value ); break; // shrink coeff
313 case 3 : SpinBox_0DElements_Size->setValue( value ); break; // 0d elements
318 //=================================================================================
319 // function : GetIntValue()
321 //=================================================================================
322 int SMESHGUI_Preferences_ColorDlg::GetIntValue( int type )
326 case 1 : res = SpinBox_Width->value(); break; // width
327 case 2 : res = SpinBox_Shrink->value(); break; // shrink coeff
328 case 3 : res = SpinBox_0DElements_Size->value(); break; // 0d elements
334 //=================================================================================
335 // function : SetDoubleValue()
337 //=================================================================================
338 void SMESHGUI_Preferences_ColorDlg::SetDoubleValue( int type, double value )
341 case 1 : SpinBox_Orientation_Scale->setValue( value ); break; // orientation scale
346 //=================================================================================
347 // function : GetDoubleValue()
349 //=================================================================================
350 double SMESHGUI_Preferences_ColorDlg::GetDoubleValue( int type )
354 case 1 : res = SpinBox_Orientation_Scale->value(); break; // orientation scale
360 //=================================================================================
361 // function : SetBooleanValue()
363 //=================================================================================
364 void SMESHGUI_Preferences_ColorDlg::SetBooleanValue( int type, bool value )
367 case 1 : CheckBox_Orientation_3DVectors->setChecked( value ); break; // 3D vectors
372 //=================================================================================
373 // function : GetBooleanValue()
375 //=================================================================================
376 bool SMESHGUI_Preferences_ColorDlg::GetBooleanValue( int type )
380 case 1 : res = CheckBox_Orientation_3DVectors->isChecked(); break; // 3D vectors
386 //=================================================================================
387 // function : setCustomMarkerMap()
389 //=================================================================================
390 void SMESHGUI_Preferences_ColorDlg::setCustomMarkerMap( VTK::MarkerMap theMarkerMap )
392 MarkerWidget->setCustomMarkerMap( theMarkerMap );
395 //=================================================================================
396 // function : getCustomMarkerMap()
398 //=================================================================================
399 VTK::MarkerMap SMESHGUI_Preferences_ColorDlg::getCustomMarkerMap()
401 return MarkerWidget->getCustomMarkerMap();
404 //=================================================================================
405 // function : setStandardMarker()
407 //=================================================================================
408 void SMESHGUI_Preferences_ColorDlg::setStandardMarker( VTK::MarkerType theMarkerType,
409 VTK::MarkerScale theMarkerScale )
411 MarkerWidget->setStandardMarker( theMarkerType, theMarkerScale );
414 //=================================================================================
415 // function : setCustomMarker()
417 //=================================================================================
418 void SMESHGUI_Preferences_ColorDlg::setCustomMarker( int theId )
420 MarkerWidget->setCustomMarker( theId );
423 //=================================================================================
424 // function : getMarkerType()
426 //=================================================================================
427 VTK::MarkerType SMESHGUI_Preferences_ColorDlg::getMarkerType() const
429 return MarkerWidget->getMarkerType();
432 //=================================================================================
433 // function : getStandardMarkerScale()
435 //=================================================================================
436 VTK::MarkerScale SMESHGUI_Preferences_ColorDlg::getStandardMarkerScale() const
438 return MarkerWidget->getStandardMarkerScale();
441 //=================================================================================
442 // function : getCustomMarkerID()
444 //=================================================================================
445 int SMESHGUI_Preferences_ColorDlg::getCustomMarkerID() const
447 return MarkerWidget->getCustomMarkerID();