Salome HOME
8d36fe1b974f52a1e3bc42aaf4c863c055ef066d
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MakeNodeAtPointDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : SMESHGUI_MakeNodeAtPointDlg.cxx
24 // Author : Edward AGAPOV, Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "SMESHGUI_MakeNodeAtPointDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_IdValidator.h"
31 #include "SMESHGUI_MeshUtils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_SpinBox.h"
34 #include "SMESHGUI_MeshEditPreview.h"
35
36 #include <SMDS_Mesh.hxx>
37 #include <SMESH_Actor.h>
38 #include <SMESH_ActorUtils.h>
39 #include <SMESH_NumberFilter.hxx>
40 #include <SMESH_LogicalFilter.hxx>
41
42 // SALOME GEOM includes
43 #include <GEOMBase.h>
44
45 // SALOME GUI includes
46 #include <LightApp_SelectionMgr.h>
47 #include <SALOME_ListIO.hxx>
48 #include <SUIT_Desktop.h>
49 #include <SVTK_ViewModel.h>
50 #include <SVTK_ViewWindow.h>
51 #include <SalomeApp_Tools.h>
52 #include <SalomeApp_TypeFilter.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SUIT_OverrideCursor.h>
55 #include <SUIT_MessageBox.h>
56
57 // OCCT includes
58 #include <TColStd_MapOfInteger.hxx>
59 #include <TopoDS_Vertex.hxx>
60 #include <BRep_Tool.hxx>
61 #include <gp_Pnt.hxx>
62
63 // Qt includes
64 #include <QGroupBox>
65 #include <QGridLayout>
66 #include <QHBoxLayout>
67 #include <QVBoxLayout>
68 #include <QLineEdit>
69 #include <QPushButton>
70 #include <QLabel>
71 #include <QRadioButton>
72 #include <QCheckBox>
73 #include <QButtonGroup>
74
75 // VTK includes
76 #include <vtkProperty.h>
77
78 // IDL includes
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_Mesh)
81 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82
83 #define SPACING 6
84 #define MARGIN  11
85
86 /*!
87  * \brief Dialog to publish a sub-shape of the mesh main shape
88  *        by selecting mesh elements
89  */
90 SMESHGUI_MakeNodeAtPointDlg::SMESHGUI_MakeNodeAtPointDlg()
91   : SMESHGUI_Dialog( 0, false, true )
92 {
93   setWindowTitle(tr("CAPTION"));
94
95   QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
96   aDlgLay->setMargin(0);
97   aDlgLay->setSpacing(SPACING);
98
99   QWidget* aMainFrame = createMainFrame  (mainFrame());
100
101   aDlgLay->addWidget(aMainFrame);
102
103   aDlgLay->setStretchFactor(aMainFrame, 1);
104 }
105
106 //=======================================================================
107 // function : createMainFrame()
108 // purpose  : Create frame containing dialog's input fields
109 //=======================================================================
110 QWidget* SMESHGUI_MakeNodeAtPointDlg::createMainFrame (QWidget* theParent)
111 {
112   QWidget* aFrame = new QWidget(theParent);
113
114   SUIT_ResourceMgr* rm = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
115   QPixmap iconMoveNode (rm->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
116   QPixmap iconSelect   (rm->loadPixmap("SMESH", tr("ICON_SELECT")));
117
118   // constructor
119
120   QGroupBox* aPixGrp = new QGroupBox(tr("MOVE_NODE"), aFrame);
121   QButtonGroup* aBtnGrp = new QButtonGroup(this);
122   QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
123   aPixGrpLayout->setMargin(MARGIN);
124   aPixGrpLayout->setSpacing(SPACING);
125
126   QRadioButton* aRBut = new QRadioButton(aPixGrp);
127   aRBut->setIcon(iconMoveNode);
128   aRBut->setChecked(true);
129   aPixGrpLayout->addWidget(aRBut);
130   aBtnGrp->addButton(aRBut, 0);
131
132   // coordinates
133
134   QGroupBox* aCoordGrp = new QGroupBox(tr("DESTINATION"), aFrame);
135   QHBoxLayout* aCoordGrpLayout = new QHBoxLayout(aCoordGrp);
136   aCoordGrpLayout->setMargin(MARGIN);
137   aCoordGrpLayout->setSpacing(SPACING);
138
139   myCoordBtn = new QPushButton(aCoordGrp);
140   myCoordBtn->setIcon(iconSelect);
141   myCoordBtn->setCheckable(true);
142
143   QLabel* aXLabel = new QLabel(tr("SMESH_X"), aCoordGrp);
144   myX = new SMESHGUI_SpinBox(aCoordGrp);
145
146   QLabel* aYLabel = new QLabel(tr("SMESH_Y"), aCoordGrp);
147   myY = new SMESHGUI_SpinBox(aCoordGrp);
148
149   QLabel* aZLabel = new QLabel(tr("SMESH_Z"), aCoordGrp);
150   myZ = new SMESHGUI_SpinBox(aCoordGrp);
151
152   myX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
153   myY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
154   myZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
155
156   aCoordGrpLayout->addWidget(myCoordBtn);
157   aCoordGrpLayout->addWidget(aXLabel);
158   aCoordGrpLayout->addWidget(myX);
159   aCoordGrpLayout->addWidget(aYLabel);
160   aCoordGrpLayout->addWidget(myY);
161   aCoordGrpLayout->addWidget(aZLabel);
162   aCoordGrpLayout->addWidget(myZ);
163   aCoordGrpLayout->setStretchFactor(myX, 1);
164   aCoordGrpLayout->setStretchFactor(myY, 1);
165   aCoordGrpLayout->setStretchFactor(myZ, 1);
166
167   // node ID
168
169   myNodeToMoveGrp = new QGroupBox(tr("NODE_2MOVE"), aFrame);
170
171   QLabel* idLabel = new QLabel(tr("NODE_2MOVE_ID"), myNodeToMoveGrp);
172   myIdBtn = new QPushButton(myNodeToMoveGrp);
173   myIdBtn->setIcon(iconSelect);
174   myIdBtn->setCheckable(true);
175   myId = new QLineEdit(myNodeToMoveGrp);
176   myId->setValidator(new SMESHGUI_IdValidator(this, 1));
177
178   QWidget* aCoordWidget = new QWidget(myNodeToMoveGrp);
179
180   QLabel* aCurrentXLabel = new QLabel(tr("SMESH_X"), aCoordWidget);
181   myCurrentX = new SMESHGUI_SpinBox(aCoordWidget);
182   myCurrentX->setButtonSymbols(QAbstractSpinBox::NoButtons);
183   myCurrentX->setReadOnly(true);
184
185   QLabel* aCurrentYLabel = new QLabel(tr("SMESH_Y"), aCoordWidget);
186   myCurrentY = new SMESHGUI_SpinBox(aCoordWidget);
187   myCurrentY->setButtonSymbols(QAbstractSpinBox::NoButtons);
188   myCurrentY->setReadOnly(true);
189
190   QLabel* aCurrentZLabel = new QLabel(tr("SMESH_Z"), aCoordWidget);
191   myCurrentZ = new SMESHGUI_SpinBox(aCoordWidget);
192   myCurrentZ->setButtonSymbols(QAbstractSpinBox::NoButtons);
193   myCurrentZ->setReadOnly(true);
194
195   QLabel* aDXLabel = new QLabel(tr("SMESH_DX"), aCoordWidget);
196   myDX = new SMESHGUI_SpinBox(aCoordWidget);
197   myDX->setButtonSymbols(QAbstractSpinBox::NoButtons);
198   myDX->setReadOnly(true);
199
200   QLabel* aDYLabel = new QLabel(tr("SMESH_DY"), aCoordWidget);
201   myDY = new SMESHGUI_SpinBox(aCoordWidget);
202   myDY->setButtonSymbols(QAbstractSpinBox::NoButtons);
203   myDY->setReadOnly(true);
204
205   QLabel* aDZLabel = new QLabel(tr("SMESH_DZ"), aCoordWidget);
206   myDZ = new SMESHGUI_SpinBox(aCoordWidget);
207   myDZ->setButtonSymbols(QAbstractSpinBox::NoButtons);
208   myDZ->setReadOnly(true);
209
210   myCurrentX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
211   myCurrentY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
212   myCurrentZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
213   myDX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
214   myDY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
215   myDZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
216
217   QGridLayout* aCoordLayout = new QGridLayout(aCoordWidget);
218   aCoordLayout->setMargin(0);
219   aCoordLayout->setSpacing(SPACING);
220   aCoordLayout->addWidget(aCurrentXLabel, 0, 0);
221   aCoordLayout->addWidget(myCurrentX,     0, 1);
222   aCoordLayout->addWidget(aCurrentYLabel, 0, 2);
223   aCoordLayout->addWidget(myCurrentY,     0, 3);
224   aCoordLayout->addWidget(aCurrentZLabel, 0, 4);
225   aCoordLayout->addWidget(myCurrentZ,     0, 5);
226   aCoordLayout->addWidget(aDXLabel,       1, 0);
227   aCoordLayout->addWidget(myDX,           1, 1);
228   aCoordLayout->addWidget(aDYLabel,       1, 2);
229   aCoordLayout->addWidget(myDY,           1, 3);
230   aCoordLayout->addWidget(aDZLabel,       1, 4);
231   aCoordLayout->addWidget(myDZ,           1, 5);
232   aCoordLayout->setColumnStretch(1, 1);
233   aCoordLayout->setColumnStretch(3, 1);
234   aCoordLayout->setColumnStretch(5, 1);
235
236   myAutoSearchChkBox = new QCheckBox( tr("AUTO_SEARCH"), myNodeToMoveGrp);
237   myPreviewChkBox = new QCheckBox( tr("PREVIEW"), myNodeToMoveGrp);
238
239   QGridLayout* myNodeToMoveGrpLayout = new QGridLayout(myNodeToMoveGrp);
240   myNodeToMoveGrpLayout->setSpacing(SPACING);
241   myNodeToMoveGrpLayout->setMargin(MARGIN);
242
243   myNodeToMoveGrpLayout->addWidget( idLabel, 0, 0 );
244   myNodeToMoveGrpLayout->addWidget( myIdBtn, 0, 1 );
245   myNodeToMoveGrpLayout->addWidget( myId,    0, 2 );
246   myNodeToMoveGrpLayout->addWidget( aCoordWidget,       1, 0, 1, 3 );
247   myNodeToMoveGrpLayout->addWidget( myAutoSearchChkBox, 2, 0, 1, 3 );
248   myNodeToMoveGrpLayout->addWidget( myPreviewChkBox,    3, 0, 1, 3 );
249
250   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
251   aLay->addWidget(aPixGrp);
252   aLay->addWidget(aCoordGrp);
253   aLay->addWidget(myNodeToMoveGrp);
254
255   connect(myCoordBtn,         SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
256   connect(myIdBtn,            SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
257   connect(myAutoSearchChkBox, SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
258
259   myIdBtn->setChecked(true);
260   myAutoSearchChkBox->setChecked(true);
261
262   return aFrame;
263 }
264
265 //================================================================================
266 /*!
267  * \brief SLOT called when any button is toggled
268   * \param bool - on or off
269  */
270 //================================================================================
271
272 void SMESHGUI_MakeNodeAtPointDlg::ButtonToggled (bool on)
273 {
274   const QObject* aSender = sender();
275   if ( on ) {
276     if ( aSender == myCoordBtn ) // button to set coord by node selection
277     {
278       if ( myIdBtn->isEnabled() )
279         myIdBtn->setChecked( !on );
280     }
281     else if ( aSender == myIdBtn ) // button to select a node to move
282     {
283       myCoordBtn->setChecked( !on );
284     }
285   }      
286   if ( aSender == myAutoSearchChkBox ) // automatic node search
287   {
288     if ( on ) {
289       myCurrentX->SetValue(0);
290       myCurrentY->SetValue(0);
291       myCurrentZ->SetValue(0);
292       myDX->SetValue(0);
293       myDY->SetValue(0);
294       myDZ->SetValue(0);
295       myId->setText("");
296       myId->setReadOnly ( true );
297       myIdBtn->setChecked( false );
298       myIdBtn->setEnabled( false );
299       myCoordBtn->setChecked( true );
300     }
301     else {
302       myId->setReadOnly ( false );
303       myIdBtn->setEnabled( true );
304     }
305   }
306 }
307
308 //================================================================================
309 /*!
310  * \brief Constructor
311 */
312 //================================================================================
313
314 SMESHGUI_MakeNodeAtPointOp::SMESHGUI_MakeNodeAtPointOp()
315 {
316   mySimulation = 0;
317   myDlg = new SMESHGUI_MakeNodeAtPointDlg;
318   myFilter = 0;
319   myHelpFileName = "mesh_through_point_page.html";
320
321   // connect signals and slots
322   connect(myDlg->myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
323   connect(myDlg->myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
324   connect(myDlg->myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
325   connect(myDlg->myId,SIGNAL (textChanged(const QString&)),SLOT(redisplayPreview()));
326   connect(myDlg->myPreviewChkBox,   SIGNAL (toggled(bool)),SLOT(redisplayPreview()));
327   connect(myDlg->myAutoSearchChkBox,SIGNAL (toggled(bool)),SLOT(redisplayPreview()));
328
329   // IPAL22913: TC6.5.0: selected in "Move node" dialog box node is not highlighted
330   // note: this slot seems to be lost together with removed obsolete SMESHGUI_MoveNodesDlg class
331   connect(myDlg->myId,SIGNAL (textChanged(const QString&)),SLOT(onTextChange(const QString&)));
332 }
333
334 //=======================================================================
335 // function : startOperation()
336 // purpose  : Init dialog fields, connect signals and slots, show dialog
337 //=======================================================================
338 void SMESHGUI_MakeNodeAtPointOp::startOperation()
339 {
340   myNoPreview = false;
341   myMeshActor = 0;
342
343   // init simulation with a current View
344   if ( mySimulation ) delete mySimulation;
345   mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( getSMESHGUI() ));
346   vtkProperty* aProp = vtkProperty::New();
347   aProp->SetRepresentationToWireframe();
348   aProp->SetColor(250, 0, 250);
349   aProp->SetPointSize(5);
350   aProp->SetLineWidth( SMESH::GetFloat("SMESH:element_width",1) + 1);
351   mySimulation->GetActor()->SetProperty(aProp);
352   aProp->Delete();
353
354   // SalomeApp_TypeFilter depends on a current study
355   if ( myFilter ) delete myFilter;
356   QList<SUIT_SelectionFilter*> filters;
357   filters.append( new SalomeApp_TypeFilter((SalomeApp_Study*)study(), "SMESH" ));
358   TColStd_MapOfInteger vertexType;
359   vertexType.Add( TopAbs_VERTEX );
360   filters.append( new SMESH_NumberFilter("GEOM", TopAbs_VERTEX, 1, vertexType ));
361   myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
362
363   // IPAL19360
364   SMESHGUI_SelectionOp::startOperation(); // this method should be called only after filter creation
365   //activateSelection(); // set filters   // called inside of previous statement
366
367   myDlg->myX->SetValue(0);
368   myDlg->myY->SetValue(0);
369   myDlg->myZ->SetValue(0);
370   myDlg->myCurrentX->SetValue(0);
371   myDlg->myCurrentY->SetValue(0);
372   myDlg->myCurrentZ->SetValue(0);
373   myDlg->myDX->SetValue(0);
374   myDlg->myDY->SetValue(0);
375   myDlg->myDZ->SetValue(0);
376   myDlg->myId->setText("");
377   myDlg->show();
378
379   onSelectionDone(); // init myMeshActor
380
381   if ( myMeshActor ) {
382 //     myMeshOldDisplayMode = myMeshActor->GetRepresentation();
383 //     myMeshActor->SetRepresentation( VTK_WIREFRAME );
384     myMeshActor->SetPointRepresentation(true);
385     SMESH::RepaintCurrentView();
386     redisplayPreview();
387   }
388 }
389
390 //================================================================================
391 /*!
392  * \brief Stops operation
393  */
394 //================================================================================
395
396 void SMESHGUI_MakeNodeAtPointOp::stopOperation()
397 {
398   myNoPreview = true;
399   mySimulation->SetVisibility(false);
400   if ( myMeshActor ) {
401 //     myMeshActor->SetRepresentation( myMeshOldDisplayMode );
402     myMeshActor->SetPointRepresentation(false);
403     SMESH::RepaintCurrentView();
404     myMeshActor = 0;
405   }
406   selectionMgr()->removeFilter( myFilter );
407   SMESHGUI_SelectionOp::stopOperation();
408 }
409
410 //================================================================================
411 /*!
412  * \brief perform it's intention action: move or create a node
413  */
414 //================================================================================
415
416 bool SMESHGUI_MakeNodeAtPointOp::onApply()
417 {
418   if( isStudyLocked() )
419     return false;
420
421   if ( !myMeshActor ) {
422     SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
423                               tr("INVALID_MESH") );
424     dlg()->show();
425     return false;
426   }
427
428   QString msg;
429   if ( !isValid( msg ) ) { // node id is invalid
430     if( !msg.isEmpty() )
431       SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
432                                 tr("INVALID_ID") );
433     dlg()->show();
434     return false;
435   }
436
437   QStringList aParameters;
438   aParameters << myDlg->myX->text();
439   aParameters << myDlg->myY->text();
440   aParameters << myDlg->myZ->text();
441
442   try {
443     SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
444     if (aMesh->_is_nil()) {
445       SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
446                                    tr("SMESHG_NO_MESH") );
447       return true;
448     }
449     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
450     if (aMeshEditor->_is_nil())
451       return true;
452
453     aMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
454
455     bool ok;
456     int anId = myDlg->myId->text().toInt( &ok );
457     if( !ok || anId < 1 )
458       anId = aMeshEditor->FindNodeClosestTo(myDlg->myX->GetValue(),
459                                             myDlg->myY->GetValue(),
460                                             myDlg->myZ->GetValue());
461
462     int aResult = aMeshEditor->MoveNode(anId,
463                                         myDlg->myX->GetValue(),
464                                         myDlg->myY->GetValue(),
465                                         myDlg->myZ->GetValue() );
466
467     if (aResult)
468     {
469       myDlg->myCurrentX->SetValue(0);
470       myDlg->myCurrentY->SetValue(0);
471       myDlg->myCurrentZ->SetValue(0);
472       myDlg->myDX->SetValue(0);
473       myDlg->myDY->SetValue(0);
474       myDlg->myDZ->SetValue(0);
475       myDlg->myId->setText("");
476
477       SALOME_ListIO aList;
478       selectionMgr()->setSelectedObjects(aList,false);
479       aList.Append(myMeshActor->getIO());
480       selectionMgr()->setSelectedObjects(aList,false);
481       SMESH::UpdateView();
482       SMESHGUI::Modified();
483     }
484   }
485   catch (const SALOME::SALOME_Exception& S_ex) {
486     SalomeApp_Tools::QtCatchCorbaException(S_ex);
487   }
488   catch (...) {
489   }
490
491   return true;
492 }
493
494 //================================================================================
495 /*!
496  * \brief Check selected node id validity
497  */
498 //================================================================================
499
500 bool SMESHGUI_MakeNodeAtPointOp::isValid( QString& msg )
501 {
502   bool ok = true;
503   if ( myMeshActor &&
504        !myDlg->myAutoSearchChkBox->isChecked() )
505   {
506     ok = false;
507     int id = myDlg->myId->text().toInt();
508     if ( id > 0 )
509       if (SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh())
510         ok = aMesh->FindNode( id );
511     if( !ok )
512       msg += tr("INVALID_ID") + "\n";
513   }
514
515   ok = myDlg->myX->isValid( msg, !myNoPreview ) && ok;
516   ok = myDlg->myY->isValid( msg, !myNoPreview ) && ok;
517   ok = myDlg->myZ->isValid( msg, !myNoPreview ) && ok;
518
519   return ok;
520 }
521
522 //================================================================================
523 /*!
524  * \brief SLOT called when selection changed
525  */
526 //================================================================================
527
528 void SMESHGUI_MakeNodeAtPointOp::onSelectionDone()
529 {
530   if ( !myDlg->isVisible() || !myDlg->isEnabled() )
531     return;
532   try {
533     SALOME_ListIO aList;
534     selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type());
535     if (aList.Extent() != 1)
536       return;
537     Handle(SALOME_InteractiveObject) anIO = aList.First();
538     SMESH_Actor* aMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
539
540     if (!aMeshActor) { // coord by geom
541       if ( myDlg->myCoordBtn->isChecked() ) {
542         GEOM::GEOM_Object_var geom = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
543         if ( !geom->_is_nil() ) {
544           TopoDS_Vertex aShape;
545           if ( GEOMBase::GetShape(geom, aShape) &&
546                aShape.ShapeType() == TopAbs_VERTEX ) {
547             gp_Pnt P = BRep_Tool::Pnt(aShape);
548             myNoPreview = true;
549             myDlg->myX->SetValue(P.X());
550             myDlg->myY->SetValue(P.Y());
551             myDlg->myZ->SetValue(P.Z());
552             myNoPreview = false;
553             redisplayPreview();
554           }
555         }
556         return;
557       }
558     }
559
560     if ( !myMeshActor )
561       myMeshActor = aMeshActor;
562
563     QString aString;
564     int nbElems = SMESH::GetNameOfSelectedElements(selector(),anIO, aString);
565     if (nbElems == 1) {
566       if (SMDS_Mesh* aMesh = aMeshActor->GetObject()->GetMesh()) {
567         if (const SMDS_MeshNode* aNode = aMesh->FindNode(aString.toInt())) {
568           myNoPreview = true;
569           if ( myDlg->myCoordBtn->isChecked() ) { // set coord
570             myDlg->myX->SetValue(aNode->X());
571             myDlg->myY->SetValue(aNode->Y());
572             myDlg->myZ->SetValue(aNode->Z());
573             myNoPreview = false;
574             redisplayPreview();
575           }
576           else if ( myDlg->myIdBtn->isChecked() &&
577                     myDlg->myIdBtn->isEnabled() ) { // set node to move
578             myDlg->myId->setText(aString);
579             myNoPreview = false;
580             redisplayPreview();
581           }
582
583           if (const SMDS_MeshNode* aCurrentNode = aMesh->FindNode(myDlg->myId->text().toInt())) {
584             double x = aCurrentNode->X();
585             double y = aCurrentNode->Y();
586             double z = aCurrentNode->Z();
587             double dx = myDlg->myX->GetValue() - x;
588             double dy = myDlg->myY->GetValue() - y;
589             double dz = myDlg->myZ->GetValue() - z;
590             myDlg->myCurrentX->SetValue(x);
591             myDlg->myCurrentY->SetValue(y);
592             myDlg->myCurrentZ->SetValue(z);
593             myDlg->myDX->SetValue(dx);
594             myDlg->myDY->SetValue(dy);
595             myDlg->myDZ->SetValue(dz);
596           }
597         }
598       }
599     }
600   } catch (...) {
601   }
602 }
603
604 //================================================================================
605 /*!
606  * \brief update preview
607  */
608 //================================================================================
609
610 void SMESHGUI_MakeNodeAtPointOp::redisplayPreview()
611 {
612   if ( myNoPreview )
613     return;
614   myNoPreview = true;
615
616   SMESH::MeshPreviewStruct_var aMeshPreviewStruct;
617
618   bool moveShown = false;
619   if ( myMeshActor)
620   {
621     const bool autoSearch = myDlg->myAutoSearchChkBox->isChecked();
622     const bool preview    = myDlg->myPreviewChkBox->isChecked();
623     if ( autoSearch )
624     {
625       myDlg->myCurrentX->SetValue(0);
626       myDlg->myCurrentY->SetValue(0);
627       myDlg->myCurrentZ->SetValue(0);
628       myDlg->myDX->SetValue(0);
629       myDlg->myDY->SetValue(0);
630       myDlg->myDZ->SetValue(0);
631       myDlg->myId->setText("");
632     }
633     QString msg;
634     if ( autoSearch || isValid( msg ) )
635     {
636       try {
637         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
638         if (!aMesh->_is_nil()) {
639           SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer();
640           if (!aPreviewer->_is_nil())
641           {
642             SUIT_OverrideCursor aWaitCursor;
643
644             int anId = 0;
645             if ( autoSearch )
646               anId = aPreviewer->FindNodeClosestTo(myDlg->myX->GetValue(),
647                                                    myDlg->myY->GetValue(),
648                                                    myDlg->myZ->GetValue());
649             else
650               anId = myDlg->myId->text().toInt();
651
652             // find id and/or just compute preview
653             aPreviewer->MoveNode(anId,
654                                  myDlg->myX->GetValue(),
655                                  myDlg->myY->GetValue(),
656                                  myDlg->myZ->GetValue());
657             if ( autoSearch ) { // set found id
658               QString idTxt("%1");
659               if ( anId > 0 )
660                 idTxt = idTxt.arg( anId );
661               else
662                 idTxt = "";
663               myDlg->myId->setText( idTxt );
664             }
665
666             SMESH::double_array* aXYZ = aMesh->GetNodeXYZ( anId );
667             if( aXYZ && aXYZ->length() >= 3 )
668             {
669               double x = aXYZ->operator[](0);
670               double y = aXYZ->operator[](1);
671               double z = aXYZ->operator[](2);
672               double dx = myDlg->myX->GetValue() - x;
673               double dy = myDlg->myY->GetValue() - y;
674               double dz = myDlg->myZ->GetValue() - z;
675               myDlg->myCurrentX->SetValue(x);
676               myDlg->myCurrentY->SetValue(y);
677               myDlg->myCurrentZ->SetValue(z);
678               myDlg->myDX->SetValue(dx);
679               myDlg->myDY->SetValue(dy);
680               myDlg->myDZ->SetValue(dz);
681             }
682
683             if ( preview ) { // fill preview data
684               aMeshPreviewStruct = aPreviewer->GetPreviewData();
685               moveShown = ( anId > 0 );
686             }
687           }
688         }
689       }catch (...) {
690       }
691     }
692   }
693
694   if ( !moveShown )
695   {
696     aMeshPreviewStruct = new SMESH::MeshPreviewStruct();
697
698     aMeshPreviewStruct->nodesXYZ.length(1);
699     aMeshPreviewStruct->nodesXYZ[0].x = myDlg->myX->GetValue();
700     aMeshPreviewStruct->nodesXYZ[0].y = myDlg->myY->GetValue();
701     aMeshPreviewStruct->nodesXYZ[0].z = myDlg->myZ->GetValue();
702
703     aMeshPreviewStruct->elementTypes.length(1);
704     aMeshPreviewStruct->elementTypes[0].SMDS_ElementType = SMESH::NODE;
705     aMeshPreviewStruct->elementTypes[0].isPoly = false;
706     aMeshPreviewStruct->elementTypes[0].nbNodesInElement = 1;
707
708     aMeshPreviewStruct->elementConnectivities.length(1);
709     aMeshPreviewStruct->elementConnectivities[0] = 0;
710   }
711
712   // display data
713   if ( aMeshPreviewStruct.operator->() )
714   {
715     mySimulation->SetData(aMeshPreviewStruct._retn());
716   }
717   else
718 {
719     mySimulation->SetVisibility(false);
720   }
721
722   myNoPreview = false;
723 }
724
725 //================================================================================
726 /*!
727  * \brief SLOT called when the node id is manually changed
728  */
729 //================================================================================
730
731 void SMESHGUI_MakeNodeAtPointOp::onTextChange( const QString& theText )
732 {
733   if( myMeshActor )
734   {
735     if( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh() )
736     {
737       Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
738       SALOME_ListIO aList;
739       aList.Append( anIO );
740       selectionMgr()->setSelectedObjects( aList, false );
741
742       if( const SMDS_MeshNode* aNode = aMesh->FindNode( theText.toInt() ) )
743       {
744         TColStd_MapOfInteger aListInd;
745         aListInd.Add( aNode->GetID() );
746         selector()->AddOrRemoveIndex( anIO, aListInd, false );
747         if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() ) )
748           aViewWindow->highlight( anIO, true, true );
749       }
750     }
751   }
752 }
753
754 //================================================================================
755 /*!
756  * \brief Activate Node selection
757  */
758 //================================================================================
759
760 void SMESHGUI_MakeNodeAtPointOp::activateSelection()
761 {
762   selectionMgr()->clearFilters();
763   SMESH::SetPointRepresentation(false);
764   selectionMgr()->installFilter( myFilter );
765   setSelectionMode( NodeSelection );
766 }
767
768 //================================================================================
769 /*!
770  * \brief Destructor
771 */
772 //================================================================================
773
774 SMESHGUI_MakeNodeAtPointOp::~SMESHGUI_MakeNodeAtPointOp()
775 {
776   if ( myDlg )        delete myDlg;
777   if ( mySimulation ) delete mySimulation;
778   if ( myFilter )     delete myFilter;
779 }
780
781 //================================================================================
782 /*!
783  * \brief Gets dialog of this operation
784  * \retval LightApp_Dialog* - pointer to dialog of this operation
785  */
786 //================================================================================
787
788 LightApp_Dialog* SMESHGUI_MakeNodeAtPointOp::dlg() const
789 {
790   return myDlg;
791 }
792