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