Salome HOME
Merge from V6_main_20120808 08Aug12
[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 //     myMeshActor->SetRepresentation( VTK_WIREFRAME );
383     myMeshActor->SetPointRepresentation(true);
384     SMESH::RepaintCurrentView();
385     redisplayPreview();
386   }
387 }
388
389 //================================================================================
390 /*!
391  * \brief Stops operation
392  */
393 //================================================================================
394
395 void SMESHGUI_MakeNodeAtPointOp::stopOperation()
396 {
397   myNoPreview = true;
398   mySimulation->SetVisibility(false);
399   if ( myMeshActor ) {
400     myMeshActor->SetPointRepresentation(false);
401     SMESH::RepaintCurrentView();
402     myMeshActor = 0;
403   }
404   selectionMgr()->removeFilter( myFilter );
405   SMESHGUI_SelectionOp::stopOperation();
406 }
407
408 //================================================================================
409 /*!
410  * \brief perform it's intention action: move or create a node
411  */
412 //================================================================================
413
414 bool SMESHGUI_MakeNodeAtPointOp::onApply()
415 {
416   if( isStudyLocked() )
417     return false;
418
419   if ( !myMeshActor ) {
420     SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
421                               tr("INVALID_MESH") );
422     dlg()->show();
423     return false;
424   }
425
426   QString msg;
427   if ( !isValid( msg ) ) { // node id is invalid
428     if( !msg.isEmpty() )
429       SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
430                                 tr("INVALID_ID") );
431     dlg()->show();
432     return false;
433   }
434
435   QStringList aParameters;
436   aParameters << myDlg->myX->text();
437   aParameters << myDlg->myY->text();
438   aParameters << myDlg->myZ->text();
439
440   try {
441     SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
442     if (aMesh->_is_nil()) {
443       SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
444                                    tr("SMESHG_NO_MESH") );
445       return true;
446     }
447     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
448     if (aMeshEditor->_is_nil())
449       return true;
450
451     aMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
452
453     bool ok;
454     int anId = myDlg->myId->text().toInt( &ok );
455     if( !ok || anId < 1 )
456       anId = aMeshEditor->FindNodeClosestTo(myDlg->myX->GetValue(),
457                                             myDlg->myY->GetValue(),
458                                             myDlg->myZ->GetValue());
459
460     int aResult = aMeshEditor->MoveNode(anId,
461                                         myDlg->myX->GetValue(),
462                                         myDlg->myY->GetValue(),
463                                         myDlg->myZ->GetValue() );
464
465     if (aResult)
466     {
467       myDlg->myCurrentX->SetValue(0);
468       myDlg->myCurrentY->SetValue(0);
469       myDlg->myCurrentZ->SetValue(0);
470       myDlg->myDX->SetValue(0);
471       myDlg->myDY->SetValue(0);
472       myDlg->myDZ->SetValue(0);
473       myDlg->myId->setText("");
474
475       SALOME_ListIO aList;
476       selectionMgr()->setSelectedObjects(aList,false);
477       aList.Append(myMeshActor->getIO());
478       selectionMgr()->setSelectedObjects(aList,false);
479       SMESH::UpdateView();
480       SMESHGUI::Modified();
481     }
482   }
483   catch (const SALOME::SALOME_Exception& S_ex) {
484     SalomeApp_Tools::QtCatchCorbaException(S_ex);
485   }
486   catch (...) {
487   }
488
489   return true;
490 }
491
492 //================================================================================
493 /*!
494  * \brief Check selected node id validity
495  */
496 //================================================================================
497
498 bool SMESHGUI_MakeNodeAtPointOp::isValid( QString& msg )
499 {
500   bool ok = true;
501   if ( myMeshActor &&
502        !myDlg->myAutoSearchChkBox->isChecked() )
503   {
504     ok = false;
505     int id = myDlg->myId->text().toInt();
506     if ( id > 0 )
507       if (SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh())
508         ok = aMesh->FindNode( id );
509     if( !ok )
510       msg += tr("INVALID_ID") + "\n";
511   }
512
513   ok = myDlg->myX->isValid( msg, !myNoPreview ) && ok;
514   ok = myDlg->myY->isValid( msg, !myNoPreview ) && ok;
515   ok = myDlg->myZ->isValid( msg, !myNoPreview ) && ok;
516
517   return ok;
518 }
519
520 //================================================================================
521 /*!
522  * \brief SLOT called when selection changed
523  */
524 //================================================================================
525
526 void SMESHGUI_MakeNodeAtPointOp::onSelectionDone()
527 {
528   if ( !myDlg->isVisible() || !myDlg->isEnabled() )
529     return;
530   try {
531     SALOME_ListIO aList;
532     selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type());
533     if (aList.Extent() != 1)
534       return;
535     Handle(SALOME_InteractiveObject) anIO = aList.First();
536     SMESH_Actor* aMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
537
538     if (!aMeshActor) { // coord by geom
539       if ( myDlg->myCoordBtn->isChecked() ) {
540         GEOM::GEOM_Object_var geom = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
541         if ( !geom->_is_nil() ) {
542           TopoDS_Vertex aShape;
543           if ( GEOMBase::GetShape(geom, aShape) &&
544                aShape.ShapeType() == TopAbs_VERTEX ) {
545             gp_Pnt P = BRep_Tool::Pnt(aShape);
546             myNoPreview = true;
547             myDlg->myX->SetValue(P.X());
548             myDlg->myY->SetValue(P.Y());
549             myDlg->myZ->SetValue(P.Z());
550             myNoPreview = false;
551             redisplayPreview();
552           }
553         }
554         return;
555       }
556     }
557
558     if ( !myMeshActor )
559       myMeshActor = aMeshActor;
560
561     QString aString;
562     int nbElems = SMESH::GetNameOfSelectedElements(selector(),anIO, aString);
563     if (nbElems == 1) {
564       if (SMDS_Mesh* aMesh = aMeshActor->GetObject()->GetMesh()) {
565         if (const SMDS_MeshNode* aNode = aMesh->FindNode(aString.toInt())) {
566           myNoPreview = true;
567           if ( myDlg->myCoordBtn->isChecked() ) { // set coord
568             myDlg->myX->SetValue(aNode->X());
569             myDlg->myY->SetValue(aNode->Y());
570             myDlg->myZ->SetValue(aNode->Z());
571             myNoPreview = false;
572             redisplayPreview();
573           }
574           else if ( myDlg->myIdBtn->isChecked() &&
575                     myDlg->myIdBtn->isEnabled() ) { // set node to move
576             myDlg->myId->setText(aString);
577             myNoPreview = false;
578             redisplayPreview();
579           }
580
581           if (const SMDS_MeshNode* aCurrentNode = aMesh->FindNode(myDlg->myId->text().toInt())) {
582             double x = aCurrentNode->X();
583             double y = aCurrentNode->Y();
584             double z = aCurrentNode->Z();
585             double dx = myDlg->myX->GetValue() - x;
586             double dy = myDlg->myY->GetValue() - y;
587             double dz = myDlg->myZ->GetValue() - z;
588             myDlg->myCurrentX->SetValue(x);
589             myDlg->myCurrentY->SetValue(y);
590             myDlg->myCurrentZ->SetValue(z);
591             myDlg->myDX->SetValue(dx);
592             myDlg->myDY->SetValue(dy);
593             myDlg->myDZ->SetValue(dz);
594           }
595         }
596       }
597     }
598   } catch (...) {
599   }
600 }
601
602 //================================================================================
603 /*!
604  * \brief update preview
605  */
606 //================================================================================
607
608 void SMESHGUI_MakeNodeAtPointOp::redisplayPreview()
609 {
610   if ( myNoPreview )
611     return;
612   myNoPreview = true;
613
614   SMESH::MeshPreviewStruct_var aMeshPreviewStruct;
615
616   bool moveShown = false;
617   if ( myMeshActor)
618   {
619     const bool autoSearch = myDlg->myAutoSearchChkBox->isChecked();
620     const bool preview    = myDlg->myPreviewChkBox->isChecked();
621     if ( autoSearch )
622     {
623       myDlg->myCurrentX->SetValue(0);
624       myDlg->myCurrentY->SetValue(0);
625       myDlg->myCurrentZ->SetValue(0);
626       myDlg->myDX->SetValue(0);
627       myDlg->myDY->SetValue(0);
628       myDlg->myDZ->SetValue(0);
629       myDlg->myId->setText("");
630     }
631     QString msg;
632     if ( autoSearch || isValid( msg ) )
633     {
634       try {
635         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
636         if (!aMesh->_is_nil()) {
637           SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer();
638           if (!aPreviewer->_is_nil())
639           {
640             SUIT_OverrideCursor aWaitCursor;
641
642             int anId = 0;
643             if ( autoSearch )
644               anId = aPreviewer->FindNodeClosestTo(myDlg->myX->GetValue(),
645                                                    myDlg->myY->GetValue(),
646                                                    myDlg->myZ->GetValue());
647             else
648               anId = myDlg->myId->text().toInt();
649
650             // find id and/or just compute preview
651             aPreviewer->MoveNode(anId,
652                                  myDlg->myX->GetValue(),
653                                  myDlg->myY->GetValue(),
654                                  myDlg->myZ->GetValue());
655             if ( autoSearch ) { // set found id
656               QString idTxt("%1");
657               if ( anId > 0 )
658                 idTxt = idTxt.arg( anId );
659               else
660                 idTxt = "";
661               myDlg->myId->setText( idTxt );
662             }
663
664             SMESH::double_array* aXYZ = aMesh->GetNodeXYZ( anId );
665             if( aXYZ && aXYZ->length() >= 3 )
666             {
667               double x = aXYZ->operator[](0);
668               double y = aXYZ->operator[](1);
669               double z = aXYZ->operator[](2);
670               double dx = myDlg->myX->GetValue() - x;
671               double dy = myDlg->myY->GetValue() - y;
672               double dz = myDlg->myZ->GetValue() - z;
673               myDlg->myCurrentX->SetValue(x);
674               myDlg->myCurrentY->SetValue(y);
675               myDlg->myCurrentZ->SetValue(z);
676               myDlg->myDX->SetValue(dx);
677               myDlg->myDY->SetValue(dy);
678               myDlg->myDZ->SetValue(dz);
679             }
680
681             if ( preview ) { // fill preview data
682               aMeshPreviewStruct = aPreviewer->GetPreviewData();
683               moveShown = ( anId > 0 );
684             }
685           }
686         }
687       }catch (...) {
688       }
689     }
690   }
691
692   if ( !moveShown )
693   {
694     aMeshPreviewStruct = new SMESH::MeshPreviewStruct();
695
696     aMeshPreviewStruct->nodesXYZ.length(1);
697     aMeshPreviewStruct->nodesXYZ[0].x = myDlg->myX->GetValue();
698     aMeshPreviewStruct->nodesXYZ[0].y = myDlg->myY->GetValue();
699     aMeshPreviewStruct->nodesXYZ[0].z = myDlg->myZ->GetValue();
700
701     aMeshPreviewStruct->elementTypes.length(1);
702     aMeshPreviewStruct->elementTypes[0].SMDS_ElementType = SMESH::NODE;
703     aMeshPreviewStruct->elementTypes[0].isPoly = false;
704     aMeshPreviewStruct->elementTypes[0].nbNodesInElement = 1;
705
706     aMeshPreviewStruct->elementConnectivities.length(1);
707     aMeshPreviewStruct->elementConnectivities[0] = 0;
708   }
709
710   // display data
711   if ( aMeshPreviewStruct.operator->() )
712   {
713     mySimulation->SetData(aMeshPreviewStruct._retn());
714   }
715   else
716 {
717     mySimulation->SetVisibility(false);
718   }
719
720   myNoPreview = false;
721 }
722
723 //================================================================================
724 /*!
725  * \brief SLOT called when the node id is manually changed
726  */
727 //================================================================================
728
729 void SMESHGUI_MakeNodeAtPointOp::onTextChange( const QString& theText )
730 {
731   if( myMeshActor )
732   {
733     if( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh() )
734     {
735       Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
736       SALOME_ListIO aList;
737       aList.Append( anIO );
738       selectionMgr()->setSelectedObjects( aList, false );
739
740       if( const SMDS_MeshNode* aNode = aMesh->FindNode( theText.toInt() ) )
741       {
742         TColStd_MapOfInteger aListInd;
743         aListInd.Add( aNode->GetID() );
744         selector()->AddOrRemoveIndex( anIO, aListInd, false );
745         if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() ) )
746           aViewWindow->highlight( anIO, true, true );
747       }
748     }
749   }
750 }
751
752 //================================================================================
753 /*!
754  * \brief Activate Node selection
755  */
756 //================================================================================
757
758 void SMESHGUI_MakeNodeAtPointOp::activateSelection()
759 {
760   selectionMgr()->clearFilters();
761   SMESH::SetPointRepresentation(false);
762   selectionMgr()->installFilter( myFilter );
763   setSelectionMode( NodeSelection );
764 }
765
766 //================================================================================
767 /*!
768  * \brief Destructor
769 */
770 //================================================================================
771
772 SMESHGUI_MakeNodeAtPointOp::~SMESHGUI_MakeNodeAtPointOp()
773 {
774   if ( myDlg )        delete myDlg;
775   if ( mySimulation ) delete mySimulation;
776   if ( myFilter )     delete myFilter;
777 }
778
779 //================================================================================
780 /*!
781  * \brief Gets dialog of this operation
782  * \retval LightApp_Dialog* - pointer to dialog of this operation
783  */
784 //================================================================================
785
786 LightApp_Dialog* SMESHGUI_MakeNodeAtPointOp::dlg() const
787 {
788   return myDlg;
789 }
790