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