1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_MoveNodesDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESHGUI_MoveNodesDlg.h"
32 #include "SMESHGUI_SpinBox.h"
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "QAD_MessageBox.h"
37 #include "utilities.h"
40 #include <qbuttongroup.h>
41 #include <qgroupbox.h>
43 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
49 #include <qwhatsthis.h>
53 // Open CASCADE Include
54 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
59 //=================================================================================
60 // class : SMESHGUI_MoveNodesDlg()
62 //=================================================================================
63 SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
64 bool modal, WFlags fl )
65 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
67 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_MOVE_NODE")));
68 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
71 setName( "SMESHGUI_MoveNodesDlg" );
73 setCaption( tr( "SMESH_MOVE_NODES_TITLE" ) );
74 setSizeGripEnabled( TRUE );
75 SMESHGUI_MoveNodesDlgLayout = new QGridLayout( this );
76 SMESHGUI_MoveNodesDlgLayout->setSpacing( 6 );
77 SMESHGUI_MoveNodesDlgLayout->setMargin( 11 );
79 /***************************************************************/
80 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
81 GroupConstructors->setTitle( tr( "SMESH_NODES" ) );
82 GroupConstructors->setExclusive( TRUE );
83 GroupConstructors->setColumnLayout(0, Qt::Vertical );
84 GroupConstructors->layout()->setSpacing( 0 );
85 GroupConstructors->layout()->setMargin( 0 );
86 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
87 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
88 GroupConstructorsLayout->setSpacing( 6 );
89 GroupConstructorsLayout->setMargin( 11 );
90 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
91 Constructor1->setText( tr( "" ) );
92 Constructor1->setPixmap( image0 );
93 Constructor1->setChecked( TRUE );
94 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
95 Constructor1->setMinimumSize( QSize( 50, 0 ) );
96 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
97 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
98 GroupConstructorsLayout->addItem( spacer, 0, 1 );
99 SMESHGUI_MoveNodesDlgLayout->addWidget( GroupConstructors, 0, 0 );
101 /***************************************************************/
102 GroupButtons = new QGroupBox( this, "GroupButtons" );
103 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
104 GroupButtons->setTitle( tr( "" ) );
105 GroupButtons->setColumnLayout(0, Qt::Vertical );
106 GroupButtons->layout()->setSpacing( 0 );
107 GroupButtons->layout()->setMargin( 0 );
108 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
109 GroupButtonsLayout->setAlignment( Qt::AlignTop );
110 GroupButtonsLayout->setSpacing( 6 );
111 GroupButtonsLayout->setMargin( 11 );
112 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
113 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
114 buttonCancel->setAutoDefault( TRUE );
115 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
116 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
117 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
118 buttonApply->setAutoDefault( TRUE );
119 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
120 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
121 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
122 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
123 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
124 buttonOk->setAutoDefault( TRUE );
125 buttonOk->setDefault( TRUE );
126 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
127 SMESHGUI_MoveNodesDlgLayout->addWidget( GroupButtons, 3, 0 );
129 /***************************************************************/
130 GroupC1 = new QGroupBox( this, "GroupC1" );
131 GroupC1->setTitle( tr( "SMESH_MOVE" ) );
132 GroupC1->setMinimumSize( QSize( 0, 0 ) );
133 GroupC1->setFrameShape( QGroupBox::Box );
134 GroupC1->setFrameShadow( QGroupBox::Sunken );
135 GroupC1->setColumnLayout(0, Qt::Vertical );
136 GroupC1->layout()->setSpacing( 0 );
137 GroupC1->layout()->setMargin( 0 );
138 GroupC1Layout = new QGridLayout( GroupC1->layout() );
139 GroupC1Layout->setAlignment( Qt::AlignTop );
140 GroupC1Layout->setSpacing( 6 );
141 GroupC1Layout->setMargin( 11 );
142 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
143 TextLabelC1A1->setText( tr( "SMESH_ID_NODES" ) );
144 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
145 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
146 TextLabelC1A1->setFrameShadow( QLabel::Plain );
147 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
148 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
149 SelectButtonC1A1->setText( tr( "" ) );
150 SelectButtonC1A1->setPixmap( image1 );
151 SelectButtonC1A1->setToggleButton( FALSE );
152 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
153 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
154 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
156 SMESHGUI_MoveNodesDlgLayout->addWidget( GroupC1, 1, 0 );
158 /***************************************************************/
159 GroupCoordinates = new QGroupBox( this, "GroupCoordinates" );
160 GroupCoordinates->setTitle( tr( "SMESH_COORDINATES" ) );
161 GroupCoordinates->setColumnLayout(0, Qt::Vertical );
162 GroupCoordinates->layout()->setSpacing( 0 );
163 GroupCoordinates->layout()->setMargin( 0 );
164 GroupCoordinatesLayout = new QGridLayout( GroupCoordinates->layout() );
165 GroupCoordinatesLayout->setAlignment( Qt::AlignTop );
166 GroupCoordinatesLayout->setSpacing( 6 );
167 GroupCoordinatesLayout->setMargin( 11 );
168 TextLabel_X = new QLabel( GroupCoordinates, "TextLabel_X" );
169 TextLabel_X->setText( tr( "SMESH_X" ) );
170 GroupCoordinatesLayout->addWidget( TextLabel_X, 0, 0 );
171 TextLabel_Y = new QLabel( GroupCoordinates, "TextLabel_Y" );
172 TextLabel_Y->setText( tr( "SMESH_Y" ) );
173 GroupCoordinatesLayout->addWidget( TextLabel_Y, 0, 2 );
175 SpinBox_X = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_X" ) ;
176 GroupCoordinatesLayout->addWidget( SpinBox_X, 0, 1 );
178 SpinBox_Y = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_Y" ) ;
179 GroupCoordinatesLayout->addWidget( SpinBox_Y, 0, 3 );
181 SpinBox_Z = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_Z" ) ;
182 GroupCoordinatesLayout->addWidget( SpinBox_Z, 0, 5 );
185 TextLabel_Z = new QLabel( GroupCoordinates, "TextLabel_Z" );
186 TextLabel_Z->setText( tr( "SMESH_Z" ) );
187 GroupCoordinatesLayout->addWidget( TextLabel_Z, 0, 4 );
189 SMESHGUI_MoveNodesDlgLayout->addWidget( GroupCoordinates, 2, 0 );
191 Init(Sel) ; /* Initialisations */
194 //=================================================================================
195 // function : ~SMESHGUI_MoveNodesDlg()
196 // purpose : Destroys the object and frees any allocated resources
197 //=================================================================================
198 SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg()
200 // no need to delete child widgets, Qt does it all for us
204 //=================================================================================
207 //=================================================================================
208 void SMESHGUI_MoveNodesDlg::Init( SALOME_Selection* Sel )
211 /* Get setting of step value from file configuration */
213 // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ; TODO
214 // step = St.toDouble() ; TODO
218 myConstructorId = 0 ;
219 Constructor1->setChecked( TRUE );
220 myEditCurrentArgument = LineEditC1A1 ;
222 this->myOkNodes = false ;
223 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
224 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
226 /* min, max, step and decimals for spin boxes */
227 SpinBox_X->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
228 SpinBox_Y->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
229 SpinBox_Z->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
230 SpinBox_X->SetValue( 0.0 ) ;
231 SpinBox_Y->SetValue( 0.0 ) ;
232 SpinBox_Z->SetValue( 0.0 ) ;
234 /* signals and slots connections */
235 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
236 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
237 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
238 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
240 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
241 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
242 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
243 /* to close dialog if study change */
244 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
246 connect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
247 connect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
248 connect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
250 /* Move widget on the botton right corner of main widget */
252 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
254 this->show() ; /* displays Dialog */
256 SelectionIntoArgument();
262 //=================================================================================
263 // function : ConstructorsClicked()
264 // purpose : Radio button management
265 //=================================================================================
266 void SMESHGUI_MoveNodesDlg::ConstructorsClicked(int constructorId)
272 //=================================================================================
273 // function : ClickOnApply()
275 //=================================================================================
276 void SMESHGUI_MoveNodesDlg::ClickOnApply()
278 switch(myConstructorId)
283 mySMESHGUI->EraseSimulationActors();
284 // mySMESHGUI->MoveNode( myMesh, myIdnode, LineEdit_X->text().toFloat(), LineEdit_Y->text().toFloat(), LineEdit_Z->text().toFloat() ) ;
285 // mySelection->ClearIObjects();
293 //=================================================================================
294 // function : ClickOnOk()
296 //=================================================================================
297 void SMESHGUI_MoveNodesDlg::ClickOnOk()
299 this->ClickOnApply() ;
300 this->ClickOnCancel() ;
306 //=================================================================================
307 // function : ClickOnCancel()
309 //=================================================================================
310 void SMESHGUI_MoveNodesDlg::ClickOnCancel()
312 QAD_Application::getDesktop()->SetSelectionMode( 4 );
313 disconnect( mySelection, 0, this, 0 );
314 mySMESHGUI->ResetState() ;
315 mySMESHGUI->EraseSimulationActors();
321 //=================================================================================
322 // function : SelectionIntoArgument()
323 // purpose : Called when selection as changed or other case
324 //=================================================================================
325 void SMESHGUI_MoveNodesDlg::SelectionIntoArgument()
328 disconnect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
329 disconnect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
330 disconnect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
332 mySMESHGUI->EraseSimulationActors();
334 myEditCurrentArgument->setText("") ;
336 QString aString = "";
338 int nbSel = mySelection->IObjectCount();
342 int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
344 SpinBox_X->SetValue(0.0) ;
345 SpinBox_Y->SetValue(0.0) ;
346 SpinBox_Z->SetValue(0.0) ;
350 if ( mySelection->SelectionMode() != 1 ){
351 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
352 tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_YES") );
356 myEditCurrentArgument->setText(aString) ;
357 Standard_Boolean res;
358 myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
362 SMESH_Actor* ac = mySMESHGUI->FindActorByEntry( mySelection->firstIObject()->getEntry(), res, false );
366 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
368 TColStd_MapIteratorOfMapOfInteger ite( myMapIndex );
370 myIdnode = ite.Key();
371 mySimulationActor = mySMESHGUI->SimulationMoveNode( ac, myIdnode );
375 MESSAGE ( " myIdnode " << myIdnode );
377 float *pt = ac->GetMapper()->GetInput()->GetPoint(myIdnode);
378 MESSAGE ( " pt " << pt[0] << ";" << pt[1] << ";" << pt[2] )
380 SpinBox_X->SetValue( (double)pt[0] ) ;
381 SpinBox_Y->SetValue( (double)pt[1] ) ;
382 SpinBox_Z->SetValue( (double)pt[2] ) ;
384 connect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
385 connect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
386 connect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
393 //=================================================================================
394 // function : SetEditCurrentArgument()
396 //=================================================================================
397 void SMESHGUI_MoveNodesDlg::SetEditCurrentArgument()
399 QPushButton* send = (QPushButton*)sender();
400 switch (myConstructorId)
402 case 0: /* default constructor */
404 if(send == SelectButtonC1A1) {
405 LineEditC1A1->setFocus() ;
406 myEditCurrentArgument = LineEditC1A1;
408 SelectionIntoArgument() ;
415 //=================================================================================
416 // function : DeactivateActiveDialog()
418 //=================================================================================
419 void SMESHGUI_MoveNodesDlg::DeactivateActiveDialog()
421 if ( GroupConstructors->isEnabled() ) {
422 GroupConstructors->setEnabled(false) ;
423 GroupC1->setEnabled(false) ;
424 GroupButtons->setEnabled(false) ;
425 mySMESHGUI->EraseSimulationActors() ;
426 mySMESHGUI->ResetState() ;
427 mySMESHGUI->SetActiveDialogBox(0) ;
433 //=================================================================================
434 // function : ActivateThisDialog()
436 //=================================================================================
437 void SMESHGUI_MoveNodesDlg::ActivateThisDialog()
439 /* Emit a signal to deactivate the active dialog */
440 mySMESHGUI->EmitSignalDeactivateDialog() ;
441 GroupConstructors->setEnabled(true) ;
442 GroupC1->setEnabled(true) ;
443 GroupButtons->setEnabled(true) ;
445 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
450 //=================================================================================
451 // function : enterEvent()
453 //=================================================================================
454 void SMESHGUI_MoveNodesDlg::enterEvent(QEvent* e)
456 if ( GroupConstructors->isEnabled() )
458 ActivateThisDialog() ;
463 //=================================================================================
464 // function : closeEvent()
466 //=================================================================================
467 void SMESHGUI_MoveNodesDlg::closeEvent( QCloseEvent* e )
469 /* same than click on cancel button */
470 this->ClickOnCancel() ;
475 //=================================================================================
476 // function : ValueChangedInSpinBox()
478 //=================================================================================
479 void SMESHGUI_MoveNodesDlg::ValueChangedInSpinBox( double newValue )
481 double vx = SpinBox_X->GetValue() ;
482 double vy = SpinBox_Y->GetValue() ;
483 double vz = SpinBox_Z->GetValue() ;
485 mySMESHGUI->DisplaySimulationMoveNode( mySimulationActor, myIdnode, vx, vy , vz );