Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_NodesDlg.cxx
1 using namespace std;
2 //  File      : SMESHGUI_NodesDlg.cxx
3 //  Created   : Tue May 14 21:35:46 2002
4 //  Author    : Nicolas REJNERI
5
6 //  Project   : SALOME
7 //  Module    : SMESH
8 //  Copyright : Open CASCADE 2002
9 //  $Header$
10
11 #include "SMESHGUI_NodesDlg.h"
12 #include "SMESHGUI.h"
13 #include "SMESHGUI_SpinBox.h"
14
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "utilities.h"
18 #include "QAD_MessageBox.h"
19
20 #include "SMESH_Actor.h"
21 #include <TColStd_MapOfInteger.hxx>
22 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
23
24 // VTK Includes
25 #include <vtkPoints.h>
26 #include <vtkPolyData.h>
27 #include <vtkPolyDataMapper.h>
28 #include <vtkDataSetMapper.h>
29 #include <vtkIdList.h>
30 #include <vtkVertex.h>
31
32 // QT Includes
33 #include <qbuttongroup.h>
34 #include <qframe.h>
35 #include <qgroupbox.h>
36 #include <qlabel.h>
37 #include <qlineedit.h>
38 #include <qpushbutton.h>
39 #include <qradiobutton.h>
40 #include <qlayout.h>
41 #include <qvariant.h>
42 #include <qtooltip.h>
43 #include <qwhatsthis.h>
44 #include <qimage.h>
45 #include <qpixmap.h>
46 #include <qvalidator.h>
47 #include <qevent.h>
48
49
50 //=================================================================================
51 // class    : SMESHGUI_NodesDlg()
52 // purpose  : 
53 //=================================================================================
54 SMESHGUI_NodesDlg::SMESHGUI_NodesDlg( QWidget* parent,
55                                       const char* name,
56                                       SALOME_Selection* Sel,
57                                       bool modal,
58                                       WFlags fl )
59   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
60 {
61   
62   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_NODE")));
63   if ( !name )
64     setName( "SMESHGUI_NodesDlg" );
65   resize( 303, 185 ); 
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 );
71
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 );
99
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 );
119
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 );
136   
137   TextLabel_Z = new QLabel( GroupCoordinates, "TextLabel_Z" );
138   TextLabel_Z->setText( tr( "SMESH_Z"  ) );
139   GroupCoordinatesLayout->addWidget( TextLabel_Z, 0, 4 );
140   
141   SpinBox_X = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_X" ) ;
142   GroupCoordinatesLayout->addWidget( SpinBox_X, 0, 1 );
143
144   SpinBox_Y = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_Y" ) ;
145   GroupCoordinatesLayout->addWidget( SpinBox_Y, 0, 3 );
146  
147   SpinBox_Z = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_Z" ) ;
148   GroupCoordinatesLayout->addWidget( SpinBox_Z, 0, 5 );
149
150   SMESHGUI_NodesDlgLayout->addWidget( GroupCoordinates, 1, 0 );
151  
152   /* Initialisation and display */
153   Init(Sel) ;
154 }
155
156
157 //=======================================================================
158 // function : ~SMESHGUI_NodesDlg()
159 // purpose  : Destructor
160 //=======================================================================
161 SMESHGUI_NodesDlg::~SMESHGUI_NodesDlg()
162 {}
163
164
165 //=================================================================================
166 // function : Init()
167 // purpose  :
168 //=================================================================================
169 void SMESHGUI_NodesDlg::Init(SALOME_Selection* Sel)
170 {
171   /* Get setting of step value from file configuration */
172   double step ;
173   // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ;  TODO
174   // step = St.toDouble() ;                                    TODO
175   step = 25.0 ;
176   
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 ) ;
184   
185   mySelection = Sel ;
186   myMeshGUI = SMESHGUI::GetSMESHGUI() ;   
187   myMeshGUI->SetActiveDialogBox( (QDialog*)this ) ;
188   
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() ) );
193   
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) ) ) ;
197
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() ) ) ;
202  
203   /* Move widget on the botton right corner of main widget */
204   int x, y ;
205   myMeshGUI->DefineDlgPosition( this, x, y ) ;
206   this->move( x, y ) ;
207   this->show() ;
208
209   SelectionIntoArgument();
210 }
211
212 //=================================================================================
213 // function : ValueChangedInSpinBox()
214 // purpose  :
215 //=================================================================================
216 void SMESHGUI_NodesDlg::ValueChangedInSpinBox( double newValue )
217 {
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();
223
224   return ;
225 }
226
227 //=================================================================================
228 // function : ClickOnOk()
229 // purpose  :
230 //=================================================================================
231 void SMESHGUI_NodesDlg::ClickOnOk()
232 {
233   this->ClickOnApply() ;
234   this->ClickOnCancel() ;
235
236   return ;
237 }
238
239 //=======================================================================
240 // function : ClickOnApply()
241 // purpose  :
242 //=======================================================================
243 void SMESHGUI_NodesDlg::ClickOnApply()
244 {
245   if ( myMeshGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_VTK ) {
246     return;
247   }
248   
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();
258   }
259 }
260
261
262 //=======================================================================
263 // function : ClickOnCancel()
264 // purpose  :
265 //=======================================================================
266 void SMESHGUI_NodesDlg::ClickOnCancel()
267 {
268   QAD_Application::getDesktop()->SetSelectionMode( 4 );
269   disconnect( mySelection, 0, this, 0 );
270   myMeshGUI->ResetState() ;
271   myMeshGUI->EraseSimulationActors() ;
272   reject() ;
273   return ;
274 }
275
276
277 //=================================================================================
278 // function : SelectionIntoArgument()
279 // purpose  : Called when selection as changed or other case
280 //=================================================================================
281 void SMESHGUI_NodesDlg::SelectionIntoArgument()
282 {
283   int nbSel = mySelection->IObjectCount();
284   if(nbSel != 1) {
285     SpinBox_X->SetValue(0.0) ;
286     SpinBox_Y->SetValue(0.0) ;
287     SpinBox_Z->SetValue(0.0) ;
288     return;
289   }
290
291   Standard_Boolean res;
292   myMesh = myMeshGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
293   if (!res) {
294     SpinBox_X->SetValue(0.0) ;
295     SpinBox_Y->SetValue(0.0) ;
296     SpinBox_Z->SetValue(0.0) ;
297     return ;
298   }
299   
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") );
306     return;
307   }
308
309   QString aString = "";
310   int nbNodes = myMeshGUI->GetNameOfSelectedNodes(mySelection, aString) ;
311   if(nbNodes != 1) {
312     SpinBox_X->SetValue(0.0) ;
313     SpinBox_Y->SetValue(0.0) ;
314     SpinBox_Z->SetValue(0.0) ;
315     return ;
316   } 
317
318   if ( nbNodes == 1 ) {
319     TColStd_MapOfInteger myMapIndex;
320     mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
321     TColStd_MapIteratorOfMapOfInteger ite( myMapIndex );
322     int idNodes[1];
323     for ( ; ite.More(); ite.Next() ) {
324       idNodes[0] = ite.Key();
325     }
326
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]);
331
332     SpinBox_X->SetValue( p0[0] ) ;
333     SpinBox_Y->SetValue( p0[1] ) ;
334     SpinBox_Z->SetValue( p0[2] ) ;
335        
336     myMeshGUI->DisplaySimulationNode( myMesh, p0[0], p0[1], p0[2] );
337     //  myMeshGUI->ViewNodes();
338   } 
339
340   return ;
341 }
342
343
344 //=======================================================================
345 // function : closeEvent()
346 // purpose  :
347 //=======================================================================
348 void SMESHGUI_NodesDlg::closeEvent(QCloseEvent* e)
349 {
350   this->ClickOnCancel() ; /* same than click on cancel button */
351   return ;
352 }
353
354
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)
360 {
361   if ( GroupConstructors->isEnabled() )
362     return ;  
363   ActivateThisDialog() ;
364   return ;  
365 }
366
367
368 //=================================================================================
369 // function : DeactivateActiveDialog()
370 // purpose  : public slot to deactivate if active
371 //=================================================================================
372 void SMESHGUI_NodesDlg::DeactivateActiveDialog()
373 {
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) ;
381   }
382   return ;
383 }
384
385
386 //=================================================================================
387 // function : ActivateThisDialog()
388 // purpose  :
389 //=================================================================================
390 void SMESHGUI_NodesDlg::ActivateThisDialog( )
391 {
392   myMeshGUI->EmitSignalDeactivateDialog() ;
393   GroupConstructors->setEnabled(true) ;
394   GroupCoordinates->setEnabled(true) ;
395   GroupButtons->setEnabled(true) ;
396   return ;
397 }