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
29 #include "SMESHGUI_MoveNodesDlg.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESH_Actor.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>
58 //=================================================================================
59 // class : SMESHGUI_MoveNodesDlg()
61 //=================================================================================
62 SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
63 bool modal, WFlags fl )
64 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
66 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_MOVE_NODE")));
67 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
70 setName( "SMESHGUI_MoveNodesDlg" );
72 setCaption( tr( "SMESH_MOVE_NODES_TITLE" ) );
73 setSizeGripEnabled( TRUE );
74 SMESHGUI_MoveNodesDlgLayout = new QGridLayout( this );
75 SMESHGUI_MoveNodesDlgLayout->setSpacing( 6 );
76 SMESHGUI_MoveNodesDlgLayout->setMargin( 11 );
78 /***************************************************************/
79 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
80 GroupConstructors->setTitle( tr( "SMESH_NODES" ) );
81 GroupConstructors->setExclusive( TRUE );
82 GroupConstructors->setColumnLayout(0, Qt::Vertical );
83 GroupConstructors->layout()->setSpacing( 0 );
84 GroupConstructors->layout()->setMargin( 0 );
85 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
86 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
87 GroupConstructorsLayout->setSpacing( 6 );
88 GroupConstructorsLayout->setMargin( 11 );
89 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
90 Constructor1->setText( tr( "" ) );
91 Constructor1->setPixmap( image0 );
92 Constructor1->setChecked( TRUE );
93 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
94 Constructor1->setMinimumSize( QSize( 50, 0 ) );
95 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
96 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
97 GroupConstructorsLayout->addItem( spacer, 0, 1 );
98 SMESHGUI_MoveNodesDlgLayout->addWidget( GroupConstructors, 0, 0 );
100 /***************************************************************/
101 GroupButtons = new QGroupBox( this, "GroupButtons" );
102 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
103 GroupButtons->setTitle( tr( "" ) );
104 GroupButtons->setColumnLayout(0, Qt::Vertical );
105 GroupButtons->layout()->setSpacing( 0 );
106 GroupButtons->layout()->setMargin( 0 );
107 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
108 GroupButtonsLayout->setAlignment( Qt::AlignTop );
109 GroupButtonsLayout->setSpacing( 6 );
110 GroupButtonsLayout->setMargin( 11 );
111 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
112 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
113 buttonCancel->setAutoDefault( TRUE );
114 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
115 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
116 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
117 buttonApply->setAutoDefault( TRUE );
118 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
119 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
120 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
121 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
122 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
123 buttonOk->setAutoDefault( TRUE );
124 buttonOk->setDefault( TRUE );
125 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
126 SMESHGUI_MoveNodesDlgLayout->addWidget( GroupButtons, 3, 0 );
128 /***************************************************************/
129 GroupC1 = new QGroupBox( this, "GroupC1" );
130 GroupC1->setTitle( tr( "SMESH_MOVE" ) );
131 GroupC1->setMinimumSize( QSize( 0, 0 ) );
132 GroupC1->setFrameShape( QGroupBox::Box );
133 GroupC1->setFrameShadow( QGroupBox::Sunken );
134 GroupC1->setColumnLayout(0, Qt::Vertical );
135 GroupC1->layout()->setSpacing( 0 );
136 GroupC1->layout()->setMargin( 0 );
137 GroupC1Layout = new QGridLayout( GroupC1->layout() );
138 GroupC1Layout->setAlignment( Qt::AlignTop );
139 GroupC1Layout->setSpacing( 6 );
140 GroupC1Layout->setMargin( 11 );
141 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
142 TextLabelC1A1->setText( tr( "SMESH_ID_NODES" ) );
143 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
144 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
145 TextLabelC1A1->setFrameShadow( QLabel::Plain );
146 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
147 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
148 SelectButtonC1A1->setText( tr( "" ) );
149 SelectButtonC1A1->setPixmap( image1 );
150 SelectButtonC1A1->setToggleButton( FALSE );
151 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
152 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
153 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
155 SMESHGUI_MoveNodesDlgLayout->addWidget( GroupC1, 1, 0 );
157 /***************************************************************/
158 GroupCoordinates = new QGroupBox( this, "GroupCoordinates" );
159 GroupCoordinates->setTitle( tr( "SMESH_COORDINATES" ) );
160 GroupCoordinates->setColumnLayout(0, Qt::Vertical );
161 GroupCoordinates->layout()->setSpacing( 0 );
162 GroupCoordinates->layout()->setMargin( 0 );
163 GroupCoordinatesLayout = new QGridLayout( GroupCoordinates->layout() );
164 GroupCoordinatesLayout->setAlignment( Qt::AlignTop );
165 GroupCoordinatesLayout->setSpacing( 6 );
166 GroupCoordinatesLayout->setMargin( 11 );
167 TextLabel_X = new QLabel( GroupCoordinates, "TextLabel_X" );
168 TextLabel_X->setText( tr( "SMESH_X" ) );
169 GroupCoordinatesLayout->addWidget( TextLabel_X, 0, 0 );
170 TextLabel_Y = new QLabel( GroupCoordinates, "TextLabel_Y" );
171 TextLabel_Y->setText( tr( "SMESH_Y" ) );
172 GroupCoordinatesLayout->addWidget( TextLabel_Y, 0, 2 );
174 SpinBox_X = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_X" ) ;
175 GroupCoordinatesLayout->addWidget( SpinBox_X, 0, 1 );
177 SpinBox_Y = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_Y" ) ;
178 GroupCoordinatesLayout->addWidget( SpinBox_Y, 0, 3 );
180 SpinBox_Z = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_Z" ) ;
181 GroupCoordinatesLayout->addWidget( SpinBox_Z, 0, 5 );
184 TextLabel_Z = new QLabel( GroupCoordinates, "TextLabel_Z" );
185 TextLabel_Z->setText( tr( "SMESH_Z" ) );
186 GroupCoordinatesLayout->addWidget( TextLabel_Z, 0, 4 );
188 SMESHGUI_MoveNodesDlgLayout->addWidget( GroupCoordinates, 2, 0 );
190 Init(Sel) ; /* Initialisations */
193 //=================================================================================
194 // function : ~SMESHGUI_MoveNodesDlg()
195 // purpose : Destroys the object and frees any allocated resources
196 //=================================================================================
197 SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg()
199 // no need to delete child widgets, Qt does it all for us
203 //=================================================================================
206 //=================================================================================
207 void SMESHGUI_MoveNodesDlg::Init( SALOME_Selection* Sel )
210 /* Get setting of step value from file configuration */
212 // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ; TODO
213 // step = St.toDouble() ; TODO
217 myConstructorId = 0 ;
218 Constructor1->setChecked( TRUE );
219 myEditCurrentArgument = LineEditC1A1 ;
221 this->myOkNodes = false ;
222 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
223 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
225 /* min, max, step and decimals for spin boxes */
226 SpinBox_X->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
227 SpinBox_Y->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
228 SpinBox_Z->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
229 SpinBox_X->SetValue( 0.0 ) ;
230 SpinBox_Y->SetValue( 0.0 ) ;
231 SpinBox_Z->SetValue( 0.0 ) ;
233 /* signals and slots connections */
234 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
235 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
236 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
237 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
239 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
240 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
241 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
242 /* to close dialog if study change */
243 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
245 connect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
246 connect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
247 connect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
249 /* Move widget on the botton right corner of main widget */
251 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
253 this->show() ; /* displays Dialog */
255 SelectionIntoArgument();
261 //=================================================================================
262 // function : ConstructorsClicked()
263 // purpose : Radio button management
264 //=================================================================================
265 void SMESHGUI_MoveNodesDlg::ConstructorsClicked(int constructorId)
271 //=================================================================================
272 // function : ClickOnApply()
274 //=================================================================================
275 void SMESHGUI_MoveNodesDlg::ClickOnApply()
277 switch(myConstructorId)
282 mySMESHGUI->EraseSimulationActors();
283 // mySMESHGUI->MoveNode( myMesh, myIdnode, LineEdit_X->text().toFloat(), LineEdit_Y->text().toFloat(), LineEdit_Z->text().toFloat() ) ;
284 // mySelection->ClearIObjects();
292 //=================================================================================
293 // function : ClickOnOk()
295 //=================================================================================
296 void SMESHGUI_MoveNodesDlg::ClickOnOk()
298 this->ClickOnApply() ;
299 this->ClickOnCancel() ;
305 //=================================================================================
306 // function : ClickOnCancel()
308 //=================================================================================
309 void SMESHGUI_MoveNodesDlg::ClickOnCancel()
311 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
312 disconnect( mySelection, 0, this, 0 );
313 mySMESHGUI->ResetState() ;
314 mySMESHGUI->EraseSimulationActors();
320 //=================================================================================
321 // function : SelectionIntoArgument()
322 // purpose : Called when selection as changed or other case
323 //=================================================================================
324 void SMESHGUI_MoveNodesDlg::SelectionIntoArgument()
327 disconnect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
328 disconnect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
329 disconnect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
331 mySMESHGUI->EraseSimulationActors();
333 myEditCurrentArgument->setText("") ;
335 QString aString = "";
337 int nbSel = mySelection->IObjectCount();
341 int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
343 SpinBox_X->SetValue(0.0) ;
344 SpinBox_Y->SetValue(0.0) ;
345 SpinBox_Z->SetValue(0.0) ;
349 if ( mySelection->SelectionMode() != NodeSelection ){
350 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
351 tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_OK") );
355 myEditCurrentArgument->setText(aString) ;
356 Standard_Boolean res;
357 myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
361 SMESH_Actor* ac = mySMESHGUI->FindActorByEntry( mySelection->firstIObject()->getEntry(), res, false );
365 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
367 TColStd_MapIteratorOfMapOfInteger ite( myMapIndex );
369 myIdnode = ite.Key();
370 mySimulationActor = mySMESHGUI->SimulationMoveNode( ac, myIdnode );
374 MESSAGE ( " myIdnode " << myIdnode );
376 float *pt = ac->GetMapper()->GetInput()->GetPoint(myIdnode);
377 MESSAGE ( " pt " << pt[0] << ";" << pt[1] << ";" << pt[2] )
379 SpinBox_X->SetValue( (double)pt[0] ) ;
380 SpinBox_Y->SetValue( (double)pt[1] ) ;
381 SpinBox_Z->SetValue( (double)pt[2] ) ;
383 connect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
384 connect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
385 connect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
392 //=================================================================================
393 // function : SetEditCurrentArgument()
395 //=================================================================================
396 void SMESHGUI_MoveNodesDlg::SetEditCurrentArgument()
398 QPushButton* send = (QPushButton*)sender();
399 switch (myConstructorId)
401 case 0: /* default constructor */
403 if(send == SelectButtonC1A1) {
404 LineEditC1A1->setFocus() ;
405 myEditCurrentArgument = LineEditC1A1;
407 SelectionIntoArgument() ;
414 //=================================================================================
415 // function : DeactivateActiveDialog()
417 //=================================================================================
418 void SMESHGUI_MoveNodesDlg::DeactivateActiveDialog()
420 if ( GroupConstructors->isEnabled() ) {
421 GroupConstructors->setEnabled(false) ;
422 GroupC1->setEnabled(false) ;
423 GroupButtons->setEnabled(false) ;
424 mySMESHGUI->EraseSimulationActors() ;
425 mySMESHGUI->ResetState() ;
426 mySMESHGUI->SetActiveDialogBox(0) ;
432 //=================================================================================
433 // function : ActivateThisDialog()
435 //=================================================================================
436 void SMESHGUI_MoveNodesDlg::ActivateThisDialog()
438 /* Emit a signal to deactivate the active dialog */
439 mySMESHGUI->EmitSignalDeactivateDialog() ;
440 GroupConstructors->setEnabled(true) ;
441 GroupC1->setEnabled(true) ;
442 GroupButtons->setEnabled(true) ;
444 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
449 //=================================================================================
450 // function : enterEvent()
452 //=================================================================================
453 void SMESHGUI_MoveNodesDlg::enterEvent(QEvent* e)
455 if ( GroupConstructors->isEnabled() )
457 ActivateThisDialog() ;
462 //=================================================================================
463 // function : closeEvent()
465 //=================================================================================
466 void SMESHGUI_MoveNodesDlg::closeEvent( QCloseEvent* e )
468 /* same than click on cancel button */
469 this->ClickOnCancel() ;
474 //=================================================================================
475 // function : ValueChangedInSpinBox()
477 //=================================================================================
478 void SMESHGUI_MoveNodesDlg::ValueChangedInSpinBox( double newValue )
480 double vx = SpinBox_X->GetValue() ;
481 double vy = SpinBox_Y->GetValue() ;
482 double vz = SpinBox_Z->GetValue() ;
484 mySMESHGUI->DisplaySimulationMoveNode( mySimulationActor, myIdnode, vx, vy , vz );