2 // File : SMESHGUI_NodesDlg.cxx
3 // Created : Tue May 14 21:35:46 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
11 #include "SMESHGUI_NodesDlg.h"
13 #include "SMESHGUI_SpinBox.h"
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "utilities.h"
18 #include "QAD_MessageBox.h"
20 #include "SMESH_Actor.h"
21 #include <TColStd_MapOfInteger.hxx>
22 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
25 #include <vtkPoints.h>
26 #include <vtkPolyData.h>
27 #include <vtkPolyDataMapper.h>
28 #include <vtkDataSetMapper.h>
29 #include <vtkIdList.h>
30 #include <vtkVertex.h>
33 #include <qbuttongroup.h>
35 #include <qgroupbox.h>
37 #include <qlineedit.h>
38 #include <qpushbutton.h>
39 #include <qradiobutton.h>
43 #include <qwhatsthis.h>
46 #include <qvalidator.h>
50 //=================================================================================
51 // class : SMESHGUI_NodesDlg()
53 //=================================================================================
54 SMESHGUI_NodesDlg::SMESHGUI_NodesDlg( QWidget* parent,
56 SALOME_Selection* Sel,
59 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
62 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_NODE")));
64 setName( "SMESHGUI_NodesDlg" );
66 setCaption( tr( "MESH_NODE_TITLE" ) );
67 setSizeGripEnabled( TRUE );
68 SMESHGUI_NodesDlgLayout = new QGridLayout( this );
69 SMESHGUI_NodesDlgLayout->setSpacing( 6 );
70 SMESHGUI_NodesDlgLayout->setMargin( 11 );
72 /***************************************************************/
73 GroupButtons = new QGroupBox( this, "GroupButtons" );
74 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
75 GroupButtons->setTitle( tr( "" ) );
76 GroupButtons->setColumnLayout(0, Qt::Vertical );
77 GroupButtons->layout()->setSpacing( 0 );
78 GroupButtons->layout()->setMargin( 0 );
79 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
80 GroupButtonsLayout->setAlignment( Qt::AlignTop );
81 GroupButtonsLayout->setSpacing( 6 );
82 GroupButtonsLayout->setMargin( 11 );
83 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
84 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
85 buttonCancel->setAutoDefault( TRUE );
86 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
87 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
88 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
89 buttonApply->setAutoDefault( TRUE );
90 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
91 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
92 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
93 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
94 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
95 buttonOk->setAutoDefault( TRUE );
96 buttonOk->setDefault( TRUE );
97 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
98 SMESHGUI_NodesDlgLayout->addWidget( GroupButtons, 2, 0 );
100 /***************************************************************/
101 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
102 GroupConstructors->setTitle( tr( "MESH_NODE" ) );
103 GroupConstructors->setExclusive( TRUE );
104 GroupConstructors->setColumnLayout(0, Qt::Vertical );
105 GroupConstructors->layout()->setSpacing( 0 );
106 GroupConstructors->layout()->setMargin( 0 );
107 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
108 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
109 GroupConstructorsLayout->setSpacing( 6 );
110 GroupConstructorsLayout->setMargin( 11 );
111 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
112 Constructor1->setText( tr( "" ) );
113 Constructor1->setPixmap( image0 );
114 Constructor1->setChecked( TRUE );
115 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
116 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
117 GroupConstructorsLayout->addItem( spacer_2, 0, 1 );
118 SMESHGUI_NodesDlgLayout->addWidget( GroupConstructors, 0, 0 );
120 /***************************************************************/
121 GroupCoordinates = new QGroupBox( this, "GroupCoordinates" );
122 GroupCoordinates->setTitle( tr( "SMESH_COORDINATES" ) );
123 GroupCoordinates->setColumnLayout(0, Qt::Vertical );
124 GroupCoordinates->layout()->setSpacing( 0 );
125 GroupCoordinates->layout()->setMargin( 0 );
126 GroupCoordinatesLayout = new QGridLayout( GroupCoordinates->layout() );
127 GroupCoordinatesLayout->setAlignment( Qt::AlignTop );
128 GroupCoordinatesLayout->setSpacing( 6 );
129 GroupCoordinatesLayout->setMargin( 11 );
130 TextLabel_X = new QLabel( GroupCoordinates, "TextLabel_X" );
131 TextLabel_X->setText( tr( "SMESH_X" ) );
132 GroupCoordinatesLayout->addWidget( TextLabel_X, 0, 0 );
133 TextLabel_Y = new QLabel( GroupCoordinates, "TextLabel_Y" );
134 TextLabel_Y->setText( tr( "SMESH_Y" ) );
135 GroupCoordinatesLayout->addWidget( TextLabel_Y, 0, 2 );
137 TextLabel_Z = new QLabel( GroupCoordinates, "TextLabel_Z" );
138 TextLabel_Z->setText( tr( "SMESH_Z" ) );
139 GroupCoordinatesLayout->addWidget( TextLabel_Z, 0, 4 );
141 SpinBox_X = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_X" ) ;
142 GroupCoordinatesLayout->addWidget( SpinBox_X, 0, 1 );
144 SpinBox_Y = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_Y" ) ;
145 GroupCoordinatesLayout->addWidget( SpinBox_Y, 0, 3 );
147 SpinBox_Z = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_Z" ) ;
148 GroupCoordinatesLayout->addWidget( SpinBox_Z, 0, 5 );
150 SMESHGUI_NodesDlgLayout->addWidget( GroupCoordinates, 1, 0 );
152 /* Initialisation and display */
157 //=======================================================================
158 // function : ~SMESHGUI_NodesDlg()
159 // purpose : Destructor
160 //=======================================================================
161 SMESHGUI_NodesDlg::~SMESHGUI_NodesDlg()
165 //=================================================================================
168 //=================================================================================
169 void SMESHGUI_NodesDlg::Init(SALOME_Selection* Sel)
171 /* Get setting of step value from file configuration */
173 // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ; TODO
174 // step = St.toDouble() ; TODO
177 /* min, max, step and decimals for spin boxes */
178 SpinBox_X->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
179 SpinBox_Y->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
180 SpinBox_Z->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
181 SpinBox_X->SetValue( 0.0 ) ;
182 SpinBox_Y->SetValue( 0.0 ) ;
183 SpinBox_Z->SetValue( 0.0 ) ;
186 myMeshGUI = SMESHGUI::GetSMESHGUI() ;
187 myMeshGUI->SetActiveDialogBox( (QDialog*)this ) ;
189 /* signals and slots connections */
190 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
191 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
192 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
194 connect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
195 connect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
196 connect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
198 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
199 connect( myMeshGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
200 /* to close dialog if study change */
201 connect( myMeshGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
203 /* Move widget on the botton right corner of main widget */
205 myMeshGUI->DefineDlgPosition( this, x, y ) ;
209 SelectionIntoArgument();
212 //=================================================================================
213 // function : ValueChangedInSpinBox()
215 //=================================================================================
216 void SMESHGUI_NodesDlg::ValueChangedInSpinBox( double newValue )
218 double vx = SpinBox_X->GetValue() ;
219 double vy = SpinBox_Y->GetValue() ;
220 double vz = SpinBox_Z->GetValue() ;
221 myMeshGUI->DisplaySimulationNode( myMesh, vx, vy, vz );
222 //myMeshGUI->ViewNodes();
227 //=================================================================================
228 // function : ClickOnOk()
230 //=================================================================================
231 void SMESHGUI_NodesDlg::ClickOnOk()
233 this->ClickOnApply() ;
234 this->ClickOnCancel() ;
239 //=======================================================================
240 // function : ClickOnApply()
242 //=======================================================================
243 void SMESHGUI_NodesDlg::ClickOnApply()
245 if ( myMeshGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_VTK ) {
249 if ( Constructor1->isChecked() ) {
250 /* Recup args and call method */
251 double x = SpinBox_X->GetValue() ;
252 double y = SpinBox_Y->GetValue() ;
253 double z = SpinBox_Z->GetValue() ;
254 myMeshGUI->EraseSimulationActors() ;
255 myMeshGUI->AddNode( myMesh, x, y, z ) ;
256 myMeshGUI->ViewNodes();
257 mySelection->ClearIObjects();
262 //=======================================================================
263 // function : ClickOnCancel()
265 //=======================================================================
266 void SMESHGUI_NodesDlg::ClickOnCancel()
268 QAD_Application::getDesktop()->SetSelectionMode( 4 );
269 disconnect( mySelection, 0, this, 0 );
270 myMeshGUI->ResetState() ;
271 myMeshGUI->EraseSimulationActors() ;
277 //=================================================================================
278 // function : SelectionIntoArgument()
279 // purpose : Called when selection as changed or other case
280 //=================================================================================
281 void SMESHGUI_NodesDlg::SelectionIntoArgument()
283 int nbSel = mySelection->IObjectCount();
285 SpinBox_X->SetValue(0.0) ;
286 SpinBox_Y->SetValue(0.0) ;
287 SpinBox_Z->SetValue(0.0) ;
291 Standard_Boolean res;
292 myMesh = myMeshGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
294 SpinBox_X->SetValue(0.0) ;
295 SpinBox_Y->SetValue(0.0) ;
296 SpinBox_Z->SetValue(0.0) ;
300 if ( mySelection->SelectionMode() != 1 ) {
301 SpinBox_X->SetValue(0.0) ;
302 SpinBox_Y->SetValue(0.0) ;
303 SpinBox_Z->SetValue(0.0) ;
304 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
305 tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_YES") );
309 QString aString = "";
310 int nbNodes = myMeshGUI->GetNameOfSelectedNodes(mySelection, aString) ;
312 SpinBox_X->SetValue(0.0) ;
313 SpinBox_Y->SetValue(0.0) ;
314 SpinBox_Z->SetValue(0.0) ;
318 if ( nbNodes == 1 ) {
319 TColStd_MapOfInteger myMapIndex;
320 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
321 TColStd_MapIteratorOfMapOfInteger ite( myMapIndex );
323 for ( ; ite.More(); ite.Next() ) {
324 idNodes[0] = ite.Key();
327 Standard_Boolean result;
328 SMESH_Actor* ac = myMeshGUI->FindActor( myMesh, result, true );
329 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
330 float *p0 = ugrid->GetPoint(idNodes[0]);
332 SpinBox_X->SetValue( p0[0] ) ;
333 SpinBox_Y->SetValue( p0[1] ) ;
334 SpinBox_Z->SetValue( p0[2] ) ;
336 myMeshGUI->DisplaySimulationNode( myMesh, p0[0], p0[1], p0[2] );
337 // myMeshGUI->ViewNodes();
344 //=======================================================================
345 // function : closeEvent()
347 //=======================================================================
348 void SMESHGUI_NodesDlg::closeEvent(QCloseEvent* e)
350 this->ClickOnCancel() ; /* same than click on cancel button */
355 //=================================================================================
356 // function : enterEvent()
357 // purpose : to reactivate this dialog box when mouse enter onto the window
358 //=================================================================================
359 void SMESHGUI_NodesDlg::enterEvent( QEvent* e)
361 if ( GroupConstructors->isEnabled() )
363 ActivateThisDialog() ;
368 //=================================================================================
369 // function : DeactivateActiveDialog()
370 // purpose : public slot to deactivate if active
371 //=================================================================================
372 void SMESHGUI_NodesDlg::DeactivateActiveDialog()
374 if ( GroupConstructors->isEnabled() ) {
375 GroupConstructors->setEnabled(false) ;
376 GroupCoordinates->setEnabled(false) ;
377 GroupButtons->setEnabled(false) ;
378 myMeshGUI->EraseSimulationActors() ;
379 myMeshGUI->ResetState() ;
380 myMeshGUI->SetActiveDialogBox(0) ;
386 //=================================================================================
387 // function : ActivateThisDialog()
389 //=================================================================================
390 void SMESHGUI_NodesDlg::ActivateThisDialog( )
392 myMeshGUI->EmitSignalDeactivateDialog() ;
393 GroupConstructors->setEnabled(true) ;
394 GroupCoordinates->setEnabled(true) ;
395 GroupButtons->setEnabled(true) ;