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_NodesDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESHGUI_NodesDlg.h"
32 #include "SMESHGUI_SpinBox.h"
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "utilities.h"
37 #include "QAD_MessageBox.h"
39 #include "SMESH_Actor.h"
40 #include <TColStd_MapOfInteger.hxx>
41 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
44 #include <vtkPoints.h>
45 #include <vtkPolyData.h>
46 #include <vtkPolyDataMapper.h>
47 #include <vtkDataSetMapper.h>
48 #include <vtkIdList.h>
49 #include <vtkVertex.h>
52 #include <qbuttongroup.h>
54 #include <qgroupbox.h>
56 #include <qlineedit.h>
57 #include <qpushbutton.h>
58 #include <qradiobutton.h>
62 #include <qwhatsthis.h>
65 #include <qvalidator.h>
69 //=================================================================================
70 // class : SMESHGUI_NodesDlg()
72 //=================================================================================
73 SMESHGUI_NodesDlg::SMESHGUI_NodesDlg( QWidget* parent,
75 SALOME_Selection* Sel,
78 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
81 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_NODE")));
83 setName( "SMESHGUI_NodesDlg" );
85 setCaption( tr( "MESH_NODE_TITLE" ) );
86 setSizeGripEnabled( TRUE );
87 SMESHGUI_NodesDlgLayout = new QGridLayout( this );
88 SMESHGUI_NodesDlgLayout->setSpacing( 6 );
89 SMESHGUI_NodesDlgLayout->setMargin( 11 );
91 /***************************************************************/
92 GroupButtons = new QGroupBox( this, "GroupButtons" );
93 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
94 GroupButtons->setTitle( tr( "" ) );
95 GroupButtons->setColumnLayout(0, Qt::Vertical );
96 GroupButtons->layout()->setSpacing( 0 );
97 GroupButtons->layout()->setMargin( 0 );
98 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
99 GroupButtonsLayout->setAlignment( Qt::AlignTop );
100 GroupButtonsLayout->setSpacing( 6 );
101 GroupButtonsLayout->setMargin( 11 );
102 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
103 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
104 buttonCancel->setAutoDefault( TRUE );
105 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
106 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
107 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
108 buttonApply->setAutoDefault( TRUE );
109 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
110 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
111 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
112 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
113 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
114 buttonOk->setAutoDefault( TRUE );
115 buttonOk->setDefault( TRUE );
116 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
117 SMESHGUI_NodesDlgLayout->addWidget( GroupButtons, 2, 0 );
119 /***************************************************************/
120 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
121 GroupConstructors->setTitle( tr( "MESH_NODE" ) );
122 GroupConstructors->setExclusive( TRUE );
123 GroupConstructors->setColumnLayout(0, Qt::Vertical );
124 GroupConstructors->layout()->setSpacing( 0 );
125 GroupConstructors->layout()->setMargin( 0 );
126 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
127 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
128 GroupConstructorsLayout->setSpacing( 6 );
129 GroupConstructorsLayout->setMargin( 11 );
130 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
131 Constructor1->setText( tr( "" ) );
132 Constructor1->setPixmap( image0 );
133 Constructor1->setChecked( TRUE );
134 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
135 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
136 GroupConstructorsLayout->addItem( spacer_2, 0, 1 );
137 SMESHGUI_NodesDlgLayout->addWidget( GroupConstructors, 0, 0 );
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 );
156 TextLabel_Z = new QLabel( GroupCoordinates, "TextLabel_Z" );
157 TextLabel_Z->setText( tr( "SMESH_Z" ) );
158 GroupCoordinatesLayout->addWidget( TextLabel_Z, 0, 4 );
160 SpinBox_X = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_X" ) ;
161 GroupCoordinatesLayout->addWidget( SpinBox_X, 0, 1 );
163 SpinBox_Y = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_Y" ) ;
164 GroupCoordinatesLayout->addWidget( SpinBox_Y, 0, 3 );
166 SpinBox_Z = new SMESHGUI_SpinBox( GroupCoordinates, "SpinBox_Z" ) ;
167 GroupCoordinatesLayout->addWidget( SpinBox_Z, 0, 5 );
169 SMESHGUI_NodesDlgLayout->addWidget( GroupCoordinates, 1, 0 );
171 /* Initialisation and display */
176 //=======================================================================
177 // function : ~SMESHGUI_NodesDlg()
178 // purpose : Destructor
179 //=======================================================================
180 SMESHGUI_NodesDlg::~SMESHGUI_NodesDlg()
184 //=================================================================================
187 //=================================================================================
188 void SMESHGUI_NodesDlg::Init(SALOME_Selection* Sel)
190 /* Get setting of step value from file configuration */
192 // QString St = QAD_CONFIG->getSetting( "xxxxxxxxxxxxx" ) ; TODO
193 // step = St.toDouble() ; TODO
196 /* min, max, step and decimals for spin boxes */
197 SpinBox_X->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
198 SpinBox_Y->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
199 SpinBox_Z->RangeStepAndValidator( -999.999, +999.999, step, 3 ) ;
200 SpinBox_X->SetValue( 0.0 ) ;
201 SpinBox_Y->SetValue( 0.0 ) ;
202 SpinBox_Z->SetValue( 0.0 ) ;
205 myMeshGUI = SMESHGUI::GetSMESHGUI() ;
206 myMeshGUI->SetActiveDialogBox( (QDialog*)this ) ;
208 /* signals and slots connections */
209 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
210 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
211 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
213 connect( SpinBox_X, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
214 connect( SpinBox_Y, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
215 connect( SpinBox_Z, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
217 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
218 connect( myMeshGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
219 /* to close dialog if study change */
220 connect( myMeshGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
222 /* Move widget on the botton right corner of main widget */
224 myMeshGUI->DefineDlgPosition( this, x, y ) ;
228 SelectionIntoArgument();
231 //=================================================================================
232 // function : ValueChangedInSpinBox()
234 //=================================================================================
235 void SMESHGUI_NodesDlg::ValueChangedInSpinBox( double newValue )
237 double vx = SpinBox_X->GetValue() ;
238 double vy = SpinBox_Y->GetValue() ;
239 double vz = SpinBox_Z->GetValue() ;
240 myMeshGUI->DisplaySimulationNode( myMesh, vx, vy, vz );
241 //myMeshGUI->ViewNodes();
246 //=================================================================================
247 // function : ClickOnOk()
249 //=================================================================================
250 void SMESHGUI_NodesDlg::ClickOnOk()
252 this->ClickOnApply() ;
253 this->ClickOnCancel() ;
258 //=======================================================================
259 // function : ClickOnApply()
261 //=======================================================================
262 void SMESHGUI_NodesDlg::ClickOnApply()
264 if ( myMeshGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_VTK ) {
268 if ( Constructor1->isChecked() ) {
269 /* Recup args and call method */
270 double x = SpinBox_X->GetValue() ;
271 double y = SpinBox_Y->GetValue() ;
272 double z = SpinBox_Z->GetValue() ;
273 myMeshGUI->EraseSimulationActors() ;
274 myMeshGUI->AddNode( myMesh, x, y, z ) ;
275 myMeshGUI->ViewNodes();
276 mySelection->ClearIObjects();
281 //=======================================================================
282 // function : ClickOnCancel()
284 //=======================================================================
285 void SMESHGUI_NodesDlg::ClickOnCancel()
287 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
288 disconnect( mySelection, 0, this, 0 );
289 myMeshGUI->ResetState() ;
290 myMeshGUI->EraseSimulationActors() ;
296 //=================================================================================
297 // function : SelectionIntoArgument()
298 // purpose : Called when selection as changed or other case
299 //=================================================================================
300 void SMESHGUI_NodesDlg::SelectionIntoArgument()
302 int nbSel = mySelection->IObjectCount();
304 SpinBox_X->SetValue(0.0) ;
305 SpinBox_Y->SetValue(0.0) ;
306 SpinBox_Z->SetValue(0.0) ;
310 Standard_Boolean res;
311 myMesh = myMeshGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
313 SpinBox_X->SetValue(0.0) ;
314 SpinBox_Y->SetValue(0.0) ;
315 SpinBox_Z->SetValue(0.0) ;
319 if ( mySelection->SelectionMode() != NodeSelection ) {
320 SpinBox_X->SetValue(0.0) ;
321 SpinBox_Y->SetValue(0.0) ;
322 SpinBox_Z->SetValue(0.0) ;
323 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
324 tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_OK") );
328 QString aString = "";
329 int nbNodes = myMeshGUI->GetNameOfSelectedNodes(mySelection, aString) ;
331 SpinBox_X->SetValue(0.0) ;
332 SpinBox_Y->SetValue(0.0) ;
333 SpinBox_Z->SetValue(0.0) ;
337 if ( nbNodes == 1 ) {
338 TColStd_MapOfInteger myMapIndex;
339 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
340 TColStd_MapIteratorOfMapOfInteger ite( myMapIndex );
342 for ( ; ite.More(); ite.Next() ) {
343 idNodes[0] = ite.Key();
346 Standard_Boolean result;
347 SMESH_Actor* ac = myMeshGUI->FindActor( myMesh, result, true );
348 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->GetUnstructuredGrid() );
349 float *p0 = ugrid->GetPoint(idNodes[0]);
351 SpinBox_X->SetValue( p0[0] ) ;
352 SpinBox_Y->SetValue( p0[1] ) ;
353 SpinBox_Z->SetValue( p0[2] ) ;
355 myMeshGUI->DisplaySimulationNode( myMesh, p0[0], p0[1], p0[2] );
356 // myMeshGUI->ViewNodes();
363 //=======================================================================
364 // function : closeEvent()
366 //=======================================================================
367 void SMESHGUI_NodesDlg::closeEvent(QCloseEvent* e)
369 this->ClickOnCancel() ; /* same than click on cancel button */
374 //=================================================================================
375 // function : enterEvent()
376 // purpose : to reactivate this dialog box when mouse enter onto the window
377 //=================================================================================
378 void SMESHGUI_NodesDlg::enterEvent( QEvent* e)
380 if ( GroupConstructors->isEnabled() )
382 ActivateThisDialog() ;
387 //=================================================================================
388 // function : DeactivateActiveDialog()
389 // purpose : public slot to deactivate if active
390 //=================================================================================
391 void SMESHGUI_NodesDlg::DeactivateActiveDialog()
393 if ( GroupConstructors->isEnabled() ) {
394 GroupConstructors->setEnabled(false) ;
395 GroupCoordinates->setEnabled(false) ;
396 GroupButtons->setEnabled(false) ;
397 myMeshGUI->EraseSimulationActors() ;
398 myMeshGUI->ResetState() ;
399 myMeshGUI->SetActiveDialogBox(0) ;
405 //=================================================================================
406 // function : ActivateThisDialog()
408 //=================================================================================
409 void SMESHGUI_NodesDlg::ActivateThisDialog( )
411 myMeshGUI->EmitSignalDeactivateDialog() ;
412 GroupConstructors->setEnabled(true) ;
413 GroupCoordinates->setEnabled(true) ;
414 GroupButtons->setEnabled(true) ;