Salome HOME
untabify
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MakeNodeAtPointDlg.cxx
1 // Copyright (C) 2007-2013  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   myUpdateBtn = new QPushButton(tr("UPDATE_DESTINATION"), myNodeToMoveGrp);
179   myUpdateBtn->setAutoDefault(true);
180
181   QWidget* aCoordWidget = new QWidget(myNodeToMoveGrp);
182
183   QLabel* aCurrentXLabel = new QLabel(tr("SMESH_X"), aCoordWidget);
184   myCurrentX = new SMESHGUI_SpinBox(aCoordWidget);
185   myCurrentX->setButtonSymbols(QAbstractSpinBox::NoButtons);
186   myCurrentX->setReadOnly(true);
187
188   QLabel* aCurrentYLabel = new QLabel(tr("SMESH_Y"), aCoordWidget);
189   myCurrentY = new SMESHGUI_SpinBox(aCoordWidget);
190   myCurrentY->setButtonSymbols(QAbstractSpinBox::NoButtons);
191   myCurrentY->setReadOnly(true);
192
193   QLabel* aCurrentZLabel = new QLabel(tr("SMESH_Z"), aCoordWidget);
194   myCurrentZ = new SMESHGUI_SpinBox(aCoordWidget);
195   myCurrentZ->setButtonSymbols(QAbstractSpinBox::NoButtons);
196   myCurrentZ->setReadOnly(true);
197
198   QLabel* aDXLabel = new QLabel(tr("SMESH_DX"), aCoordWidget);
199   myDX = new SMESHGUI_SpinBox(aCoordWidget);
200   myDX->setButtonSymbols(QAbstractSpinBox::NoButtons);
201   myDX->setReadOnly(true);
202
203   QLabel* aDYLabel = new QLabel(tr("SMESH_DY"), aCoordWidget);
204   myDY = new SMESHGUI_SpinBox(aCoordWidget);
205   myDY->setButtonSymbols(QAbstractSpinBox::NoButtons);
206   myDY->setReadOnly(true);
207
208   QLabel* aDZLabel = new QLabel(tr("SMESH_DZ"), aCoordWidget);
209   myDZ = new SMESHGUI_SpinBox(aCoordWidget);
210   myDZ->setButtonSymbols(QAbstractSpinBox::NoButtons);
211   myDZ->setReadOnly(true);
212
213   myCurrentX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
214   myCurrentY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
215   myCurrentZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
216   myDX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
217   myDY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
218   myDZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
219
220   QGridLayout* aCoordLayout = new QGridLayout(aCoordWidget);
221   aCoordLayout->setMargin(0);
222   aCoordLayout->setSpacing(SPACING);
223   aCoordLayout->addWidget(aCurrentXLabel, 0, 0);
224   aCoordLayout->addWidget(myCurrentX,     0, 1);
225   aCoordLayout->addWidget(aCurrentYLabel, 0, 2);
226   aCoordLayout->addWidget(myCurrentY,     0, 3);
227   aCoordLayout->addWidget(aCurrentZLabel, 0, 4);
228   aCoordLayout->addWidget(myCurrentZ,     0, 5);
229   aCoordLayout->addWidget(aDXLabel,       1, 0);
230   aCoordLayout->addWidget(myDX,           1, 1);
231   aCoordLayout->addWidget(aDYLabel,       1, 2);
232   aCoordLayout->addWidget(myDY,           1, 3);
233   aCoordLayout->addWidget(aDZLabel,       1, 4);
234   aCoordLayout->addWidget(myDZ,           1, 5);
235   aCoordLayout->setColumnStretch(1, 1);
236   aCoordLayout->setColumnStretch(3, 1);
237   aCoordLayout->setColumnStretch(5, 1);
238
239   myAutoSearchChkBox = new QCheckBox( tr("AUTO_SEARCH"), myNodeToMoveGrp);
240   myPreviewChkBox = new QCheckBox( tr("PREVIEW"), myNodeToMoveGrp);
241
242   QGridLayout* myNodeToMoveGrpLayout = new QGridLayout(myNodeToMoveGrp);
243   myNodeToMoveGrpLayout->setSpacing(SPACING);
244   myNodeToMoveGrpLayout->setMargin(MARGIN);
245
246   myNodeToMoveGrpLayout->addWidget( idLabel, 0, 0 );
247   myNodeToMoveGrpLayout->addWidget( myIdBtn, 0, 1 );
248   myNodeToMoveGrpLayout->addWidget( myId,    0, 2 );
249   myNodeToMoveGrpLayout->addWidget( myUpdateBtn, 0, 3 );
250   myNodeToMoveGrpLayout->addWidget( aCoordWidget,       1, 0, 1, 4 );
251   myNodeToMoveGrpLayout->addWidget( myAutoSearchChkBox, 2, 0, 1, 4 );
252   myNodeToMoveGrpLayout->addWidget( myPreviewChkBox,    3, 0, 1, 4 );
253
254   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
255   aLay->addWidget(aPixGrp);
256   aLay->addWidget(aCoordGrp);
257   aLay->addWidget(myNodeToMoveGrp);
258
259   connect(myCoordBtn,         SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
260   connect(myIdBtn,            SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
261   connect(myAutoSearchChkBox, SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
262
263   myIdBtn->setChecked(true);
264   myAutoSearchChkBox->setChecked(true);
265
266   return aFrame;
267 }
268
269 //================================================================================
270 /*!
271  * \brief SLOT called when any button is toggled
272   * \param bool - on or off
273  */
274 //================================================================================
275
276 void SMESHGUI_MakeNodeAtPointDlg::ButtonToggled (bool on)
277 {
278   const QObject* aSender = sender();
279   if ( on ) {
280     if ( aSender == myCoordBtn ) // button to set coord by node selection
281     {
282       if ( myIdBtn->isEnabled() )
283         myIdBtn->setChecked( !on );
284     }
285     else if ( aSender == myIdBtn ) // button to select a node to move
286     {
287       myCoordBtn->setChecked( !on );
288     }
289   }      
290   if ( aSender == myAutoSearchChkBox ) // automatic node search
291   {
292     if ( on ) {
293       myCurrentX->SetValue(0);
294       myCurrentY->SetValue(0);
295       myCurrentZ->SetValue(0);
296       myDX->SetValue(0);
297       myDY->SetValue(0);
298       myDZ->SetValue(0);
299       myId->setText("");
300       myId->setReadOnly ( true );
301       myIdBtn->setChecked( false );
302       myIdBtn->setEnabled( false );
303       myCoordBtn->setChecked( true );
304       myUpdateBtn->setEnabled( false );
305     }
306     else {
307       myId->setReadOnly ( false );
308       myIdBtn->setEnabled( true );
309       myUpdateBtn->setEnabled( true );
310     }
311   }
312 }
313
314 //================================================================================
315 /*!
316  * \brief Constructor
317 */
318 //================================================================================
319
320 SMESHGUI_MakeNodeAtPointOp::SMESHGUI_MakeNodeAtPointOp()
321 {
322   mySimulation = 0;
323   myDlg = new SMESHGUI_MakeNodeAtPointDlg;
324   myFilter = 0;
325   myHelpFileName = "mesh_through_point_page.html";
326
327   myNoPreview = false;
328   myUpdateDestination = false;
329
330   // connect signals and slots
331   connect(myDlg->myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
332   connect(myDlg->myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
333   connect(myDlg->myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
334   connect(myDlg->myId,SIGNAL (textChanged(const QString&)),SLOT(redisplayPreview()));
335   connect(myDlg->myPreviewChkBox,   SIGNAL (toggled(bool)),SLOT(redisplayPreview()));
336   connect(myDlg->myAutoSearchChkBox,SIGNAL (toggled(bool)),SLOT(redisplayPreview()));
337
338   // IPAL22913: TC6.5.0: selected in "Move node" dialog box node is not highlighted
339   // note: this slot seems to be lost together with removed obsolete SMESHGUI_MoveNodesDlg class
340   connect(myDlg->myId,SIGNAL (textChanged(const QString&)),SLOT(onTextChange(const QString&)));
341   connect(myDlg->myUpdateBtn, SIGNAL (clicked()), this, SLOT(onUpdateDestination()));
342 }
343
344 void SMESHGUI_MakeNodeAtPointOp::onUpdateDestination()
345 {
346   myUpdateDestination = true;
347   redisplayPreview();
348   myUpdateDestination = false;
349 }
350
351 //=======================================================================
352 // function : startOperation()
353 // purpose  : Init dialog fields, connect signals and slots, show dialog
354 //=======================================================================
355 void SMESHGUI_MakeNodeAtPointOp::startOperation()
356 {
357   myNoPreview = false;
358   myMeshActor = 0;
359
360   // init simulation with a current View
361   if ( mySimulation ) delete mySimulation;
362   mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( getSMESHGUI() ));
363   vtkProperty* aProp = vtkProperty::New();
364   aProp->SetRepresentationToWireframe();
365   aProp->SetColor(250, 0, 250);
366   aProp->SetPointSize(5);
367   aProp->SetLineWidth( SMESH::GetFloat("SMESH:element_width",1) + 1);
368   mySimulation->GetActor()->SetProperty(aProp);
369   aProp->Delete();
370
371   // SalomeApp_TypeFilter depends on a current study
372   if ( myFilter ) delete myFilter;
373   QList<SUIT_SelectionFilter*> filters;
374   filters.append( new SalomeApp_TypeFilter((SalomeApp_Study*)study(), "SMESH" ));
375   TColStd_MapOfInteger vertexType;
376   vertexType.Add( TopAbs_VERTEX );
377   filters.append( new SMESH_NumberFilter("GEOM", TopAbs_VERTEX, 1, vertexType ));
378   myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
379
380   // IPAL19360
381   SMESHGUI_SelectionOp::startOperation(); // this method should be called only after filter creation
382   //activateSelection(); // set filters   // called inside of previous statement
383
384   myDlg->myX->SetValue(0);
385   myDlg->myY->SetValue(0);
386   myDlg->myZ->SetValue(0);
387   myDlg->myCurrentX->SetValue(0);
388   myDlg->myCurrentY->SetValue(0);
389   myDlg->myCurrentZ->SetValue(0);
390   myDlg->myDX->SetValue(0);
391   myDlg->myDY->SetValue(0);
392   myDlg->myDZ->SetValue(0);
393   myDlg->myId->setText("");
394   myDlg->show();
395
396   onSelectionDone(); // init myMeshActor
397
398   if ( myMeshActor ) {
399 //     myMeshActor->SetRepresentation( VTK_WIREFRAME );
400     myMeshActor->SetPointRepresentation(true);
401     SMESH::RepaintCurrentView();
402     redisplayPreview();
403   }
404 }
405
406 //================================================================================
407 /*!
408  * \brief Stops operation
409  */
410 //================================================================================
411
412 void SMESHGUI_MakeNodeAtPointOp::stopOperation()
413 {
414   myNoPreview = true;
415   mySimulation->SetVisibility(false);
416   if ( myMeshActor ) {
417     myMeshActor->SetPointRepresentation(false);
418     SMESH::RepaintCurrentView();
419     myMeshActor = 0;
420   }
421   selectionMgr()->removeFilter( myFilter );
422   SMESHGUI_SelectionOp::stopOperation();
423 }
424
425 //================================================================================
426 /*!
427  * \brief perform it's intention action: move or create a node
428  */
429 //================================================================================
430
431 bool SMESHGUI_MakeNodeAtPointOp::onApply()
432 {
433   if( isStudyLocked() )
434     return false;
435
436   if ( !myMeshActor ) {
437     SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
438                               tr("INVALID_MESH") );
439     dlg()->show();
440     return false;
441   }
442
443   QString msg;
444   if ( !isValid( msg ) ) { // node id is invalid
445     if( !msg.isEmpty() )
446       SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
447                                 tr("INVALID_ID") );
448     dlg()->show();
449     return false;
450   }
451
452   QStringList aParameters;
453   aParameters << myDlg->myX->text();
454   aParameters << myDlg->myY->text();
455   aParameters << myDlg->myZ->text();
456
457   try {
458     SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
459     if (aMesh->_is_nil()) {
460       SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
461                                    tr("SMESHG_NO_MESH") );
462       return true;
463     }
464     SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
465     if (aMeshEditor->_is_nil())
466       return true;
467
468     aMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
469
470     bool ok;
471     int anId = myDlg->myId->text().toInt( &ok );
472     if( !ok || anId < 1 )
473       anId = aMeshEditor->FindNodeClosestTo(myDlg->myX->GetValue(),
474                                             myDlg->myY->GetValue(),
475                                             myDlg->myZ->GetValue());
476
477     int aResult = aMeshEditor->MoveNode(anId,
478                                         myDlg->myX->GetValue(),
479                                         myDlg->myY->GetValue(),
480                                         myDlg->myZ->GetValue() );
481
482     if (aResult)
483     {
484       myDlg->myCurrentX->SetValue(0);
485       myDlg->myCurrentY->SetValue(0);
486       myDlg->myCurrentZ->SetValue(0);
487       myDlg->myDX->SetValue(0);
488       myDlg->myDY->SetValue(0);
489       myDlg->myDZ->SetValue(0);
490       myDlg->myId->setText("");
491
492       SALOME_ListIO aList;
493       selectionMgr()->setSelectedObjects(aList,false);
494       aList.Append(myMeshActor->getIO());
495       selectionMgr()->setSelectedObjects(aList,false);
496       SMESH::UpdateView();
497       SMESHGUI::Modified();
498     }
499   }
500   catch (const SALOME::SALOME_Exception& S_ex) {
501     SalomeApp_Tools::QtCatchCorbaException(S_ex);
502   }
503   catch (...) {
504   }
505
506   return true;
507 }
508
509 //================================================================================
510 /*!
511  * \brief Check selected node id validity
512  */
513 //================================================================================
514
515 bool SMESHGUI_MakeNodeAtPointOp::isValid( QString& msg )
516 {
517   bool ok = true;
518   if ( myMeshActor &&
519        !myDlg->myAutoSearchChkBox->isChecked() )
520   {
521     ok = false;
522     int id = myDlg->myId->text().toInt();
523     if ( id > 0 )
524       if (SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh())
525         ok = aMesh->FindNode( id );
526     if( !ok )
527       msg += tr("INVALID_ID") + "\n";
528   }
529
530   ok = myDlg->myX->isValid( msg, !myNoPreview ) && ok;
531   ok = myDlg->myY->isValid( msg, !myNoPreview ) && ok;
532   ok = myDlg->myZ->isValid( msg, !myNoPreview ) && ok;
533
534   return ok;
535 }
536
537 //================================================================================
538 /*!
539  * \brief SLOT called when selection changed
540  */
541 //================================================================================
542
543 void SMESHGUI_MakeNodeAtPointOp::onSelectionDone()
544 {
545   if ( !myDlg->isVisible() || !myDlg->isEnabled() )
546     return;
547   try {
548     SALOME_ListIO aList;
549     selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type());
550     if (aList.Extent() != 1)
551       return;
552     Handle(SALOME_InteractiveObject) anIO = aList.First();
553     SMESH_Actor* aMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
554
555     if (!aMeshActor) { // coord by geom
556       if ( myDlg->myCoordBtn->isChecked() ) {
557         GEOM::GEOM_Object_var geom = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
558         if ( !geom->_is_nil() ) {
559           TopoDS_Vertex aShape;
560           if ( GEOMBase::GetShape(geom, aShape) &&
561                aShape.ShapeType() == TopAbs_VERTEX ) {
562             gp_Pnt P = BRep_Tool::Pnt(aShape);
563             myNoPreview = true;
564             myDlg->myX->SetValue(P.X());
565             myDlg->myY->SetValue(P.Y());
566             myDlg->myZ->SetValue(P.Z());
567             myNoPreview = false;
568             redisplayPreview();
569           }
570         }
571         return;
572       }
573     }
574
575     if ( !myMeshActor )
576       myMeshActor = aMeshActor;
577
578     QString aString;
579     int nbElems = SMESH::GetNameOfSelectedElements(selector(),anIO, aString);
580     if (nbElems == 1) {
581       if (SMDS_Mesh* aMesh = aMeshActor->GetObject()->GetMesh()) {
582         if (const SMDS_MeshNode* aNode = aMesh->FindNode(aString.toInt())) {
583           myNoPreview = true;
584           if ( myDlg->myCoordBtn->isChecked() ) { // set coord
585             myDlg->myX->SetValue(aNode->X());
586             myDlg->myY->SetValue(aNode->Y());
587             myDlg->myZ->SetValue(aNode->Z());
588             myNoPreview = false;
589             redisplayPreview();
590           }
591           else if ( myDlg->myIdBtn->isChecked() &&
592                     myDlg->myIdBtn->isEnabled() ) { // set node to move
593             myDlg->myId->setText(aString);
594             myNoPreview = false;
595             redisplayPreview();
596           }
597
598           if (const SMDS_MeshNode* aCurrentNode = aMesh->FindNode(myDlg->myId->text().toInt())) {
599             double x = aCurrentNode->X();
600             double y = aCurrentNode->Y();
601             double z = aCurrentNode->Z();
602             double dx = myDlg->myX->GetValue() - x;
603             double dy = myDlg->myY->GetValue() - y;
604             double dz = myDlg->myZ->GetValue() - z;
605             myDlg->myCurrentX->SetValue(x);
606             myDlg->myCurrentY->SetValue(y);
607             myDlg->myCurrentZ->SetValue(z);
608             myDlg->myDX->SetValue(dx);
609             myDlg->myDY->SetValue(dy);
610             myDlg->myDZ->SetValue(dz);
611           }
612         }
613       }
614     }
615   } catch (...) {
616   }
617 }
618
619 //================================================================================
620 /*!
621  * \brief update preview
622  */
623 //================================================================================
624
625 void SMESHGUI_MakeNodeAtPointOp::redisplayPreview()
626 {
627   if ( myNoPreview )
628     return;
629   myNoPreview = true;
630
631   SMESH::MeshPreviewStruct_var aMeshPreviewStruct;
632
633   bool moveShown = false;
634   if ( myMeshActor)
635   {
636     const bool autoSearch = myDlg->myAutoSearchChkBox->isChecked();
637     const bool preview    = myDlg->myPreviewChkBox->isChecked();
638     if ( autoSearch )
639     {
640       myDlg->myCurrentX->SetValue(0);
641       myDlg->myCurrentY->SetValue(0);
642       myDlg->myCurrentZ->SetValue(0);
643       myDlg->myDX->SetValue(0);
644       myDlg->myDY->SetValue(0);
645       myDlg->myDZ->SetValue(0);
646       myDlg->myId->setText("");
647     }
648     QString msg;
649     if ( autoSearch || isValid( msg ) )
650     {
651       try {
652         SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
653         if (!aMesh->_is_nil()) {
654           SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer();
655           if (!aPreviewer->_is_nil())
656           {
657             SUIT_OverrideCursor aWaitCursor;
658
659             int anId = 0;
660             if ( autoSearch )
661               anId = aPreviewer->FindNodeClosestTo(myDlg->myX->GetValue(),
662                                                    myDlg->myY->GetValue(),
663                                                    myDlg->myZ->GetValue());
664             else
665               anId = myDlg->myId->text().toInt();
666
667             // find id and/or just compute preview
668             aPreviewer->MoveNode(anId,
669                                  myDlg->myX->GetValue(),
670                                  myDlg->myY->GetValue(),
671                                  myDlg->myZ->GetValue());
672             if ( autoSearch ) { // set found id
673               QString idTxt("%1");
674               if ( anId > 0 )
675                 idTxt = idTxt.arg( anId );
676               else
677                 idTxt = "";
678               myDlg->myId->setText( idTxt );
679             }
680
681             SMESH::double_array* aXYZ = aMesh->GetNodeXYZ( anId );
682             if( aXYZ && aXYZ->length() >= 3 )
683             {
684               double x = aXYZ->operator[](0);
685               double y = aXYZ->operator[](1);
686               double z = aXYZ->operator[](2);
687
688               if ( myUpdateDestination ) {
689                 myDlg->myX->SetValue(x);
690                 myDlg->myY->SetValue(y);
691                 myDlg->myZ->SetValue(z);
692               }
693
694               double dx = myDlg->myX->GetValue() - x;
695               double dy = myDlg->myY->GetValue() - y;
696               double dz = myDlg->myZ->GetValue() - z;
697               myDlg->myCurrentX->SetValue(x);
698               myDlg->myCurrentY->SetValue(y);
699               myDlg->myCurrentZ->SetValue(z);
700               myDlg->myDX->SetValue(dx);
701               myDlg->myDY->SetValue(dy);
702               myDlg->myDZ->SetValue(dz);
703             }
704
705             if ( preview ) { // fill preview data
706               aMeshPreviewStruct = aPreviewer->GetPreviewData();
707               moveShown = ( anId > 0 );
708             }
709           }
710         }
711       }catch (...) {
712       }
713     }
714   }
715
716   if ( !moveShown )
717   {
718     aMeshPreviewStruct = new SMESH::MeshPreviewStruct();
719
720     aMeshPreviewStruct->nodesXYZ.length(1);
721     aMeshPreviewStruct->nodesXYZ[0].x = myDlg->myX->GetValue();
722     aMeshPreviewStruct->nodesXYZ[0].y = myDlg->myY->GetValue();
723     aMeshPreviewStruct->nodesXYZ[0].z = myDlg->myZ->GetValue();
724
725     aMeshPreviewStruct->elementTypes.length(1);
726     aMeshPreviewStruct->elementTypes[0].SMDS_ElementType = SMESH::NODE;
727     aMeshPreviewStruct->elementTypes[0].isPoly = false;
728     aMeshPreviewStruct->elementTypes[0].nbNodesInElement = 1;
729
730     aMeshPreviewStruct->elementConnectivities.length(1);
731     aMeshPreviewStruct->elementConnectivities[0] = 0;
732   }
733
734   // display data
735   if ( aMeshPreviewStruct.operator->() )
736   {
737     mySimulation->SetData(aMeshPreviewStruct._retn());
738   }
739   else
740 {
741     mySimulation->SetVisibility(false);
742   }
743
744   myNoPreview = false;
745 }
746
747 //================================================================================
748 /*!
749  * \brief SLOT called when the node id is manually changed
750  */
751 //================================================================================
752
753 void SMESHGUI_MakeNodeAtPointOp::onTextChange( const QString& theText )
754 {
755   if( myMeshActor )
756   {
757     if( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh() )
758     {
759       Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
760       SALOME_ListIO aList;
761       aList.Append( anIO );
762       selectionMgr()->setSelectedObjects( aList, false );
763
764       if( const SMDS_MeshNode* aNode = aMesh->FindNode( theText.toInt() ) )
765       {
766         TColStd_MapOfInteger aListInd;
767         aListInd.Add( aNode->GetID() );
768         selector()->AddOrRemoveIndex( anIO, aListInd, false );
769         if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() ) )
770           aViewWindow->highlight( anIO, true, true );
771       }
772     }
773   }
774 }
775
776 //================================================================================
777 /*!
778  * \brief Activate Node selection
779  */
780 //================================================================================
781
782 void SMESHGUI_MakeNodeAtPointOp::activateSelection()
783 {
784   selectionMgr()->clearFilters();
785   SMESH::SetPointRepresentation(false);
786   selectionMgr()->installFilter( myFilter );
787   setSelectionMode( NodeSelection );
788 }
789
790 //================================================================================
791 /*!
792  * \brief Destructor
793 */
794 //================================================================================
795
796 SMESHGUI_MakeNodeAtPointOp::~SMESHGUI_MakeNodeAtPointOp()
797 {
798   if ( myDlg )        delete myDlg;
799   if ( mySimulation ) delete mySimulation;
800   if ( myFilter )     delete myFilter;
801 }
802
803 //================================================================================
804 /*!
805  * \brief Gets dialog of this operation
806  * \retval LightApp_Dialog* - pointer to dialog of this operation
807  */
808 //================================================================================
809
810 LightApp_Dialog* SMESHGUI_MakeNodeAtPointOp::dlg() const
811 {
812   return myDlg;
813 }
814