Salome HOME
NRI : First integration.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MoveNodesDlg.cxx
1 using namespace std;
2 //  File      : SMESHGUI_MoveNodesDlg.cxx
3 //  Created   : Thu Jun 20 22:30:09 2002
4 //  Author    : Nicolas REJNERI
5
6 //  Project   : SALOME
7 //  Module    : SMESH
8 //  Copyright : Open CASCADE 2002
9 //  $Header$
10
11 #include "SMESHGUI_MoveNodesDlg.h"
12 #include "SMESHGUI.h"
13 #include "SMESHGUI_SpinBox.h"
14
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "QAD_MessageBox.h"
18 #include "utilities.h"
19
20 // QT Includes
21 #include <qbuttongroup.h>
22 #include <qgroupbox.h>
23 #include <qlabel.h>
24 #include <qlineedit.h>
25 #include <qpushbutton.h>
26 #include <qradiobutton.h>
27 #include <qlayout.h>
28 #include <qvariant.h>
29 #include <qtooltip.h>
30 #include <qwhatsthis.h>
31 #include <qimage.h>
32 #include <qpixmap.h>
33
34 // Open CASCADE Include
35 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
36
37 // VTK Include
38 #include <vtkActor.h>
39
40 //=================================================================================
41 // class    : SMESHGUI_MoveNodesDlg()
42 // purpose  : 
43 //=================================================================================
44 SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
45                                               bool modal, WFlags fl )
46     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
47 {
48     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_DLG_MOVE_NODE")));
49     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_SELECT")));
50
51     if ( !name )
52         setName( "SMESHGUI_MoveNodesDlg" );
53     resize( 303, 185 ); 
54     setCaption( tr( "SMESH_MOVE_NODES_TITLE"  ) );
55     setSizeGripEnabled( TRUE );
56     SMESHGUI_MoveNodesDlgLayout = new QGridLayout( this ); 
57     SMESHGUI_MoveNodesDlgLayout->setSpacing( 6 );
58     SMESHGUI_MoveNodesDlgLayout->setMargin( 11 );
59
60     /***************************************************************/
61     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
62     GroupConstructors->setTitle( tr( "SMESH_NODES"  ) );
63     GroupConstructors->setExclusive( TRUE );
64     GroupConstructors->setColumnLayout(0, Qt::Vertical );
65     GroupConstructors->layout()->setSpacing( 0 );
66     GroupConstructors->layout()->setMargin( 0 );
67     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
68     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
69     GroupConstructorsLayout->setSpacing( 6 );
70     GroupConstructorsLayout->setMargin( 11 );
71     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
72     Constructor1->setText( tr( ""  ) );
73     Constructor1->setPixmap( image0 );
74     Constructor1->setChecked( TRUE );
75     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
76     Constructor1->setMinimumSize( QSize( 50, 0 ) );
77     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
78     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
79     GroupConstructorsLayout->addItem( spacer, 0, 1 );
80     SMESHGUI_MoveNodesDlgLayout->addWidget( GroupConstructors, 0, 0 );
81     
82     /***************************************************************/
83     GroupButtons = new QGroupBox( this, "GroupButtons" );
84     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
85     GroupButtons->setTitle( tr( ""  ) );
86     GroupButtons->setColumnLayout(0, Qt::Vertical );
87     GroupButtons->layout()->setSpacing( 0 );
88     GroupButtons->layout()->setMargin( 0 );
89     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
90     GroupButtonsLayout->setAlignment( Qt::AlignTop );
91     GroupButtonsLayout->setSpacing( 6 );
92     GroupButtonsLayout->setMargin( 11 );
93     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
94     buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
95     buttonCancel->setAutoDefault( TRUE );
96     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
97     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
98     buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
99     buttonApply->setAutoDefault( TRUE );
100     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
101     QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
102     GroupButtonsLayout->addItem( spacer_9, 0, 2 );
103     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
104     buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
105     buttonOk->setAutoDefault( TRUE );
106     buttonOk->setDefault( TRUE );
107     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
108     SMESHGUI_MoveNodesDlgLayout->addWidget( GroupButtons, 3, 0 );
109
110     /***************************************************************/
111     GroupC1 = new QGroupBox( this, "GroupC1" );
112     GroupC1->setTitle( tr( "SMESH_MOVE"  ) );
113     GroupC1->setMinimumSize( QSize( 0, 0 ) );
114     GroupC1->setFrameShape( QGroupBox::Box );
115     GroupC1->setFrameShadow( QGroupBox::Sunken );
116     GroupC1->setColumnLayout(0, Qt::Vertical );
117     GroupC1->layout()->setSpacing( 0 );
118     GroupC1->layout()->setMargin( 0 );
119     GroupC1Layout = new QGridLayout( GroupC1->layout() );
120     GroupC1Layout->setAlignment( Qt::AlignTop );
121     GroupC1Layout->setSpacing( 6 );
122     GroupC1Layout->setMargin( 11 );
123     TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
124     TextLabelC1A1->setText( tr( "SMESH_ID_NODES"  ) );
125     TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
126     TextLabelC1A1->setFrameShape( QLabel::NoFrame );
127     TextLabelC1A1->setFrameShadow( QLabel::Plain );
128     GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
129     SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
130     SelectButtonC1A1->setText( tr( ""  ) );
131     SelectButtonC1A1->setPixmap( image1 );
132     SelectButtonC1A1->setToggleButton( FALSE );
133     GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
134     LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
135     GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
136
137     SMESHGUI_MoveNodesDlgLayout->addWidget( GroupC1, 1, 0 );
138
139     /***************************************************************/
140     GroupCoordinates = new QGroupBox( this, "GroupCoordinates" );
141     GroupCoordinates->setTitle( tr( "SMESH_COORDINATES"  ) );
142     GroupCoordinates->setColumnLayout(0, Qt::Vertical );
143     GroupCoordinates->layout()->setSpacing( 0 );
144     GroupCoordinates->layout()->setMargin( 0 );
145     GroupCoordinatesLayout = new QGridLayout( GroupCoordinates->layout() );
146     GroupCoordinatesLayout->setAlignment( Qt::AlignTop );
147     GroupCoordinatesLayout->setSpacing( 6 );
148     GroupCoordinatesLayout->setMargin( 11 );
149     TextLabel_X = new QLabel( GroupCoordinates, "TextLabel_X" );
150     TextLabel_X->setText( tr( "SMESH_X"  ) );
151     GroupCoordinatesLayout->addWidget( TextLabel_X, 0, 0 );
152     TextLabel_Y = new QLabel( GroupCoordinates, "TextLabel_Y" );
153     TextLabel_Y->setText( tr( "SMESH_Y"  ) );
154     GroupCoordinatesLayout->addWidget( TextLabel_Y, 0, 2 );
155   
156     SpinBox_X = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_X" ) ;
157     GroupCoordinatesLayout->addWidget( SpinBox_X, 0, 1 );
158     
159     SpinBox_Y = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_Y" ) ;
160     GroupCoordinatesLayout->addWidget( SpinBox_Y, 0, 3 );
161     
162     SpinBox_Z = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_Z" ) ;
163     GroupCoordinatesLayout->addWidget( SpinBox_Z, 0, 5 );
164
165
166     TextLabel_Z = new QLabel( GroupCoordinates, "TextLabel_Z" );
167     TextLabel_Z->setText( tr( "SMESH_Z"  ) );
168     GroupCoordinatesLayout->addWidget( TextLabel_Z, 0, 4 );
169
170     SMESHGUI_MoveNodesDlgLayout->addWidget( GroupCoordinates, 2, 0 );
171
172     Init(Sel) ; /* Initialisations */
173 }
174
175 //=================================================================================
176 // function : ~SMESHGUI_MoveNodesDlg()
177 // purpose  : Destroys the object and frees any allocated resources
178 //=================================================================================
179 SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg()
180 {
181     // no need to delete child widgets, Qt does it all for us
182 }
183
184
185 //=================================================================================
186 // function : Init()
187 // purpose  :
188 //=================================================================================
189 void SMESHGUI_MoveNodesDlg::Init( SALOME_Selection* Sel )
190 {
191
192   /* Get setting of step value from file configuration */
193   double step ;
194   // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ;  TODO
195   // step = St.toDouble() ;                                    TODO
196   step = 25.0 ;
197   
198   GroupC1->show();
199   myConstructorId = 0 ;
200   Constructor1->setChecked( TRUE );
201   myEditCurrentArgument = LineEditC1A1 ;        
202   mySelection = Sel;  
203   this->myOkNodes = false ;
204   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
205   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
206
207   /* min, max, step and decimals for spin boxes */
208   SpinBox_X->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
209   SpinBox_Y->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
210   SpinBox_Z->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;  
211   SpinBox_X->SetValue( 0.0 ) ;
212   SpinBox_Y->SetValue( 0.0 ) ;
213   SpinBox_Z->SetValue( 0.0 ) ;
214
215   /* signals and slots connections */
216   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
217   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
218   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
219   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
220
221   connect( SelectButtonC1A1, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
222   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
223   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
224   /* to close dialog if study change */
225   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
226
227   connect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
228   connect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
229   connect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
230
231   /* Move widget on the botton right corner of main widget */
232   int x, y ;
233   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
234   this->move( x, y ) ;
235   this->show() ; /* displays Dialog */
236
237   SelectionIntoArgument();
238   
239   return ;
240 }
241
242
243 //=================================================================================
244 // function : ConstructorsClicked()
245 // purpose  : Radio button management
246 //=================================================================================
247 void SMESHGUI_MoveNodesDlg::ConstructorsClicked(int constructorId)
248 {
249   return ;
250 }
251
252
253 //=================================================================================
254 // function : ClickOnApply()
255 // purpose  :
256 //=================================================================================
257 void SMESHGUI_MoveNodesDlg::ClickOnApply()
258 {
259   switch(myConstructorId)
260     { 
261     case 0 :
262       { 
263         if(myOkNodes) {   
264           mySMESHGUI->EraseSimulationActors();
265 //        mySMESHGUI->MoveNode( myMesh, myIdnode, LineEdit_X->text().toFloat(), LineEdit_Y->text().toFloat(), LineEdit_Z->text().toFloat() ) ;
266 //        mySelection->ClearIObjects();
267         }
268         break ;
269       }
270     }
271   return ;
272 }
273
274 //=================================================================================
275 // function : ClickOnOk()
276 // purpose  :
277 //=================================================================================
278 void SMESHGUI_MoveNodesDlg::ClickOnOk()
279 {
280   this->ClickOnApply() ;
281   this->ClickOnCancel() ;
282
283   return ;
284 }
285
286         
287 //=================================================================================
288 // function : ClickOnCancel()
289 // purpose  :
290 //=================================================================================
291 void SMESHGUI_MoveNodesDlg::ClickOnCancel()
292 {
293   QAD_Application::getDesktop()->SetSelectionMode( 4 );
294   disconnect( mySelection, 0, this, 0 );
295   mySMESHGUI->ResetState() ;
296   mySMESHGUI->EraseSimulationActors();
297   reject() ;
298   return ;
299 }
300
301
302 //=================================================================================
303 // function : SelectionIntoArgument()
304 // purpose  : Called when selection as changed or other case
305 //=================================================================================
306 void SMESHGUI_MoveNodesDlg::SelectionIntoArgument()
307 {
308
309   disconnect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
310   disconnect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
311   disconnect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
312
313   mySMESHGUI->EraseSimulationActors();
314
315   myEditCurrentArgument->setText("") ;
316   myOkNodes = false;
317   QString aString = "";
318
319   int nbSel = mySelection->IObjectCount();
320   if(nbSel != 1)
321     return ;
322
323   int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
324   if(nbNodes != 1) {
325     SpinBox_X->SetValue(0.0) ;
326     SpinBox_Y->SetValue(0.0) ;
327     SpinBox_Z->SetValue(0.0) ;
328     return ;
329   }
330   
331   if ( mySelection->SelectionMode() != 1 ){
332     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
333                             tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_YES") );
334     return;
335   }
336
337   myEditCurrentArgument->setText(aString) ;
338   Standard_Boolean res;
339   myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
340   if (!res)
341     return ;
342
343   SMESH_Actor* ac = mySMESHGUI->FindActorByEntry( mySelection->firstIObject()->getEntry(), res, false );
344   if ( !res )
345     return ;
346
347   mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
348
349   TColStd_MapIteratorOfMapOfInteger ite( myMapIndex );
350   if ( ite.More() ) {
351     myIdnode = ite.Key();
352     mySimulationActor = mySMESHGUI->SimulationMoveNode( ac, myIdnode );
353   } else
354     return ;
355
356   MESSAGE ( " myIdnode " << myIdnode );
357
358   float *pt  = ac->GetMapper()->GetInput()->GetPoint(myIdnode);
359   MESSAGE ( " pt " << pt[0] << ";" << pt[1] << ";" << pt[2] )
360
361   SpinBox_X->SetValue( (double)pt[0] ) ;
362   SpinBox_Y->SetValue( (double)pt[1] ) ;
363   SpinBox_Z->SetValue( (double)pt[2] ) ;
364
365   connect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
366   connect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
367   connect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
368
369   myOkNodes = true ;
370   return ;
371 }
372
373
374 //=================================================================================
375 // function : SetEditCurrentArgument()
376 // purpose  :
377 //=================================================================================
378 void SMESHGUI_MoveNodesDlg::SetEditCurrentArgument()
379 {
380   QPushButton* send = (QPushButton*)sender();
381   switch (myConstructorId)
382     {
383     case 0: /* default constructor */
384       { 
385         if(send == SelectButtonC1A1) {
386           LineEditC1A1->setFocus() ;
387           myEditCurrentArgument = LineEditC1A1;
388         }
389         SelectionIntoArgument() ;
390         break;
391       }
392     }
393   return ;
394 }
395
396 //=================================================================================
397 // function : DeactivateActiveDialog()
398 // purpose  :
399 //=================================================================================
400 void SMESHGUI_MoveNodesDlg::DeactivateActiveDialog()
401 {
402   if ( GroupConstructors->isEnabled() ) {
403     GroupConstructors->setEnabled(false) ;
404     GroupC1->setEnabled(false) ;
405     GroupButtons->setEnabled(false) ;
406     mySMESHGUI->EraseSimulationActors() ;
407     mySMESHGUI->ResetState() ;    
408     mySMESHGUI->SetActiveDialogBox(0) ;
409   }
410   return ;
411 }
412
413
414 //=================================================================================
415 // function : ActivateThisDialog()
416 // purpose  :
417 //=================================================================================
418 void SMESHGUI_MoveNodesDlg::ActivateThisDialog()
419 {
420   /* Emit a signal to deactivate the active dialog */
421   mySMESHGUI->EmitSignalDeactivateDialog() ;   
422   GroupConstructors->setEnabled(true) ;
423   GroupC1->setEnabled(true) ;
424   GroupButtons->setEnabled(true) ;
425   
426   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
427   return ;
428 }
429
430
431 //=================================================================================
432 // function : enterEvent()
433 // purpose  :
434 //=================================================================================
435 void SMESHGUI_MoveNodesDlg::enterEvent(QEvent* e)
436 {
437   if ( GroupConstructors->isEnabled() )
438     return ;  
439   ActivateThisDialog() ;
440   return ;
441 }
442
443
444 //=================================================================================
445 // function : closeEvent()
446 // purpose  :
447 //=================================================================================
448 void SMESHGUI_MoveNodesDlg::closeEvent( QCloseEvent* e )
449 {
450   /* same than click on cancel button */
451   this->ClickOnCancel() ;
452   return ;
453 }
454
455
456 //=================================================================================
457 // function : ValueChangedInSpinBox()
458 // purpose  :
459 //=================================================================================
460 void SMESHGUI_MoveNodesDlg::ValueChangedInSpinBox( double newValue )
461 {
462   double vx = SpinBox_X->GetValue() ;
463   double vy = SpinBox_Y->GetValue() ;
464   double vz = SpinBox_Z->GetValue() ;
465   
466   mySMESHGUI->DisplaySimulationMoveNode( mySimulationActor, myIdnode, vx, vy , vz );
467 }