1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESHGUI_MakeNodeAtPointDlg.cxx
24 // Author : Edward AGAPOV, Open CASCADE S.A.S.
27 #include "SMESHGUI_MakeNodeAtPointDlg.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"
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>
42 // SALOME GEOM includes
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>
58 #include <TColStd_MapOfInteger.hxx>
59 #include <TopoDS_Vertex.hxx>
60 #include <BRep_Tool.hxx>
64 #include <QApplication>
66 #include <QGridLayout>
67 #include <QHBoxLayout>
68 #include <QVBoxLayout>
70 #include <QPushButton>
72 #include <QRadioButton>
74 #include <QButtonGroup>
77 #include <vtkProperty.h>
80 #include <SALOMEconfig.h>
81 #include CORBA_SERVER_HEADER(SMESH_Mesh)
82 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
88 * \brief Dialog to publish a sub-shape of the mesh main shape
89 * by selecting mesh elements
91 SMESHGUI_MakeNodeAtPointDlg::SMESHGUI_MakeNodeAtPointDlg()
92 : SMESHGUI_Dialog( 0, false, true )
94 setWindowTitle(tr("CAPTION"));
96 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
97 aDlgLay->setMargin(0);
98 aDlgLay->setSpacing(SPACING);
99 myMainFrame = createMainFrame(mainFrame());
101 aDlgLay->addWidget(myMainFrame);
103 aDlgLay->setStretchFactor(myMainFrame, 1);
106 //=======================================================================
107 // function : createMainFrame()
108 // purpose : Create frame containing dialog's input fields
109 //=======================================================================
110 QWidget* SMESHGUI_MakeNodeAtPointDlg::createMainFrame (QWidget* theParent)
112 QWidget* aFrame = new QWidget(theParent);
114 SUIT_ResourceMgr* rm = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
115 QPixmap iconMoveNode (rm->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
116 QPixmap iconMoveWithoutNode (rm->loadPixmap("SMESH", tr("ICON_DLG_MOVE_WITHOUT_NODE")));
117 QPixmap iconSelect (rm->loadPixmap("SMESH", tr("ICON_SELECT")));
120 QGroupBox* aPixGrp = new QGroupBox(tr("MOVE_NODE"), this);
121 aPixGrp->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
122 myButtonGroup = new QButtonGroup(this);
123 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
124 aPixGrpLayout->setMargin(MARGIN);
125 aPixGrpLayout->setSpacing(SPACING);
127 myRButNodeToMove = new QRadioButton(aPixGrp);
128 myRButMoveWithoutNode = new QRadioButton(aPixGrp);
129 myRButNodeToMove->setIcon(iconMoveNode);
130 myRButMoveWithoutNode->setIcon(iconMoveWithoutNode);
131 myRButNodeToMove->setChecked(true);
133 aPixGrpLayout->addWidget(myRButNodeToMove);
134 aPixGrpLayout->addWidget(myRButMoveWithoutNode);
135 myButtonGroup->addButton(myRButNodeToMove, 0);
136 myButtonGroup->addButton(myRButMoveWithoutNode, 1);
140 myNodeToMoveGrp = new QGroupBox(tr("NODE_2MOVE"), aFrame);
141 myNodeToMoveGrp->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
142 QLabel* idLabel = new QLabel(tr("NODE_2MOVE_ID"), myNodeToMoveGrp);
143 myIdBtn = new QPushButton(myNodeToMoveGrp);
144 myIdBtn->setIcon(iconSelect);
145 myIdBtn->setCheckable(true);
146 myId = new QLineEdit(myNodeToMoveGrp);
147 myId->setValidator(new SMESHGUI_IdValidator(this, 1));
149 myUpdateBtn = new QPushButton(tr("UPDATE_DESTINATION"), myNodeToMoveGrp);
150 myUpdateBtn->setAutoDefault(true);
152 QWidget* aCoordWidget = new QWidget(myNodeToMoveGrp);
154 QLabel* aCurrentXLabel = new QLabel(tr("SMESH_X"), aCoordWidget);
155 myCurrentX = new SMESHGUI_SpinBox(aCoordWidget);
156 myCurrentX->setButtonSymbols(QAbstractSpinBox::NoButtons);
157 myCurrentX->setReadOnly(true);
159 QLabel* aCurrentYLabel = new QLabel(tr("SMESH_Y"), aCoordWidget);
160 myCurrentY = new SMESHGUI_SpinBox(aCoordWidget);
161 myCurrentY->setButtonSymbols(QAbstractSpinBox::NoButtons);
162 myCurrentY->setReadOnly(true);
164 QLabel* aCurrentZLabel = new QLabel(tr("SMESH_Z"), aCoordWidget);
165 myCurrentZ = new SMESHGUI_SpinBox(aCoordWidget);
166 myCurrentZ->setButtonSymbols(QAbstractSpinBox::NoButtons);
167 myCurrentZ->setReadOnly(true);
169 myCurrentX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
170 myCurrentY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
171 myCurrentZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
173 QGridLayout* aCoordLayout = new QGridLayout(aCoordWidget);
174 aCoordLayout->setMargin(0);
175 aCoordLayout->setSpacing(SPACING);
176 aCoordLayout->addWidget(aCurrentXLabel, 0, 0);
177 aCoordLayout->addWidget(myCurrentX, 0, 1);
178 aCoordLayout->addWidget(aCurrentYLabel, 0, 2);
179 aCoordLayout->addWidget(myCurrentY, 0, 3);
180 aCoordLayout->addWidget(aCurrentZLabel, 0, 4);
181 aCoordLayout->addWidget(myCurrentZ, 0, 5);
182 aCoordLayout->setColumnStretch(1, 1);
183 aCoordLayout->setColumnStretch(3, 1);
184 aCoordLayout->setColumnStretch(5, 1);
186 QGridLayout* myNodeToMoveGrpLayout = new QGridLayout(myNodeToMoveGrp);
187 myNodeToMoveGrpLayout->setSpacing(SPACING);
188 myNodeToMoveGrpLayout->setMargin(MARGIN);
190 myNodeToMoveGrpLayout->addWidget( idLabel, 0, 0 );
191 myNodeToMoveGrpLayout->addWidget( myIdBtn, 0, 1 );
192 myNodeToMoveGrpLayout->addWidget( myId, 0, 2 );
193 myNodeToMoveGrpLayout->addWidget( myUpdateBtn, 0, 3 );
194 myNodeToMoveGrpLayout->addWidget( aCoordWidget, 1, 0, 1, 4 );
198 myDestinationGrp = new QGroupBox(tr("DESTINATION"), aFrame);
199 myDestinationGrp->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
201 myDestBtn = new QPushButton(myDestinationGrp);
202 myDestBtn->setIcon(iconSelect);
203 myDestBtn->setCheckable(true);
205 QLabel* aDestinationXLabel = new QLabel(tr("SMESH_X"), myDestinationGrp);
206 myDestinationX = new SMESHGUI_SpinBox(myDestinationGrp);
208 QLabel* aDestinationYLabel = new QLabel(tr("SMESH_Y"), myDestinationGrp);
209 myDestinationY = new SMESHGUI_SpinBox(myDestinationGrp);
211 QLabel* aDestinationZLabel = new QLabel(tr("SMESH_Z"), myDestinationGrp);
212 myDestinationZ = new SMESHGUI_SpinBox(myDestinationGrp);
214 myDestDXLabel = new QLabel(tr("SMESH_DX"), myDestinationGrp);
215 myDestDX = new SMESHGUI_SpinBox(myDestinationGrp);
216 myDestDX->setReadOnly(true);
218 myDestDYLabel = new QLabel(tr("SMESH_DY"), myDestinationGrp);
219 myDestDY = new SMESHGUI_SpinBox(myDestinationGrp);
220 myDestDY->setReadOnly(true);
222 myDestDZLabel = new QLabel(tr("SMESH_DZ"), myDestinationGrp);
223 myDestDZ = new SMESHGUI_SpinBox(myDestinationGrp);
224 myDestDZ->setReadOnly(true);
226 myDestinationX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
227 myDestinationY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
228 myDestinationZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
229 myDestDX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
230 myDestDY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
231 myDestDZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
233 QGridLayout* aDestLayout = new QGridLayout(myDestinationGrp);
234 aDestLayout->setMargin(MARGIN);
235 aDestLayout->setSpacing(SPACING);
236 aDestLayout->addWidget(myDestBtn, 0, 0);
237 aDestLayout->addWidget(aDestinationXLabel, 0, 1);
238 aDestLayout->addWidget(myDestinationX, 0, 2);
239 aDestLayout->addWidget(aDestinationYLabel, 0, 3);
240 aDestLayout->addWidget(myDestinationY, 0, 4);
241 aDestLayout->addWidget(aDestinationZLabel, 0, 5);
242 aDestLayout->addWidget(myDestinationZ, 0, 6);
243 aDestLayout->addWidget(myDestDXLabel, 1, 1);
244 aDestLayout->addWidget(myDestDX, 1, 2);
245 aDestLayout->addWidget(myDestDYLabel, 1, 3);
246 aDestLayout->addWidget(myDestDY, 1, 4);
247 aDestLayout->addWidget(myDestDZLabel, 1, 5);
248 aDestLayout->addWidget(myDestDZ, 1, 6);
249 aDestLayout->setColumnStretch(2, 1);
250 aDestLayout->setColumnStretch(4, 1);
251 aDestLayout->setColumnStretch(6, 1);
255 myPreviewChkBox = new QCheckBox( tr("PREVIEW"), aFrame);
257 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
258 aLay->addWidget(aPixGrp);
259 aLay->addWidget(myNodeToMoveGrp);
260 aLay->addWidget(myDestinationGrp);
261 aLay->addWidget(myPreviewChkBox);
263 connect(myDestBtn, SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
264 connect(myIdBtn, SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
265 connect(myButtonGroup, SIGNAL (buttonClicked(int)), SLOT(ConstructorsClicked(int)));
267 myIdBtn->setChecked(true);
272 //================================================================================
274 * \brief SLOT called when any button is toggled
275 * \param bool - on or off
277 //================================================================================
279 void SMESHGUI_MakeNodeAtPointDlg::ButtonToggled (bool on)
281 const QObject* aSender = sender();
283 if ( aSender == myDestBtn ) // button to set coord by node selection
285 if ( myIdBtn->isEnabled() )
286 myIdBtn->setChecked( !on );
288 else if ( aSender == myIdBtn ) // button to select a node to move
290 myDestBtn->setChecked( !on );
294 //================================================================================
296 * \brief SLOT called when clicked radio button
297 * \param int - number of the button
299 //================================================================================
300 void SMESHGUI_MakeNodeAtPointDlg::ConstructorsClicked (int constructorId)
302 switch (constructorId) {
305 myDestDXLabel->show();
306 myDestDYLabel->show();
307 myDestDZLabel->show();
311 myCurrentX->SetValue(0);
312 myCurrentY->SetValue(0);
313 myCurrentZ->SetValue(0);
314 if (!myNodeToMoveGrp->isVisible()) myNodeToMoveGrp->show();
320 myCurrentX->SetValue(0);
321 myCurrentY->SetValue(0);
322 myCurrentZ->SetValue(0);
323 myDestDXLabel->hide();
324 myDestDYLabel->hide();
325 myDestDZLabel->hide();
329 if (myNodeToMoveGrp->isVisible()) {myNodeToMoveGrp->hide();}
333 QApplication::instance()->processEvents();
337 resize(minimumSizeHint());
340 //================================================================================
344 //================================================================================
346 SMESHGUI_MakeNodeAtPointOp::SMESHGUI_MakeNodeAtPointOp()
349 myDlg = new SMESHGUI_MakeNodeAtPointDlg;
351 myHelpFileName = "mesh_through_point_page.html";
354 myUpdateDestination = false;
355 myDestCoordChanged = true;
357 // connect signals and slots
358 connect(myDlg->myDestinationX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
359 connect(myDlg->myDestinationY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
360 connect(myDlg->myDestinationZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
361 connect(myDlg->myDestDX, SIGNAL (valueChanged(double)), this, SLOT(onDestCoordChanged()));
362 connect(myDlg->myDestDY, SIGNAL (valueChanged(double)), this, SLOT(onDestCoordChanged()));
363 connect(myDlg->myDestDZ, SIGNAL (valueChanged(double)), this, SLOT(onDestCoordChanged()));
364 connect(myDlg->myId,SIGNAL (textChanged(const QString&)),SLOT(redisplayPreview()));
365 connect(myDlg->myPreviewChkBox, SIGNAL (toggled(bool)),SLOT(redisplayPreview()));
367 // IPAL22913: TC6.5.0: selected in "Move node" dialog box node is not highlighted
368 // note: this slot seems to be lost together with removed obsolete SMESHGUI_MoveNodesDlg class
369 connect(myDlg->myId,SIGNAL (textChanged(const QString&)),SLOT(onTextChange(const QString&)));
370 connect(myDlg->myUpdateBtn, SIGNAL (clicked()), this, SLOT(onUpdateDestination()));
373 void SMESHGUI_MakeNodeAtPointOp::onUpdateDestination()
375 myUpdateDestination = true;
377 myUpdateDestination = false;
380 void SMESHGUI_MakeNodeAtPointOp::onDestCoordChanged()
382 myDestCoordChanged = false;
384 myDestCoordChanged = true;
387 //=======================================================================
388 // function : startOperation()
389 // purpose : Init dialog fields, connect signals and slots, show dialog
390 //=======================================================================
391 void SMESHGUI_MakeNodeAtPointOp::startOperation()
396 // init simulation with a current View
397 if ( mySimulation ) delete mySimulation;
398 mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( getSMESHGUI() ));
399 vtkProperty* aProp = vtkProperty::New();
400 aProp->SetRepresentationToWireframe();
401 aProp->SetColor(250, 0, 250);
402 aProp->SetPointSize(5);
403 aProp->SetLineWidth( SMESH::GetFloat("SMESH:element_width",1) + 1);
404 mySimulation->GetActor()->SetProperty(aProp);
407 // SalomeApp_TypeFilter depends on a current study
408 if ( myFilter ) delete myFilter;
409 QList<SUIT_SelectionFilter*> filters;
410 filters.append( new SalomeApp_TypeFilter((SalomeApp_Study*)study(), "SMESH" ));
411 TColStd_MapOfInteger vertexType;
412 vertexType.Add( TopAbs_VERTEX );
413 filters.append( new SMESH_NumberFilter("GEOM", TopAbs_VERTEX, 1, vertexType ));
414 myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
417 SMESHGUI_SelectionOp::startOperation(); // this method should be called only after filter creation
418 //activateSelection(); // set filters // called inside of previous statement
419 myDlg->myId->setText("");
420 myDlg->myDestinationX->SetValue(0);
421 myDlg->myDestinationY->SetValue(0);
422 myDlg->myDestinationZ->SetValue(0);
423 myDlg->myDestDX->SetValue(0);
424 myDlg->myDestDY->SetValue(0);
425 myDlg->myDestDZ->SetValue(0);
426 myDlg->myCurrentX->SetValue(0);
427 myDlg->myCurrentY->SetValue(0);
428 myDlg->myCurrentZ->SetValue(0);
429 myDlg->myDestDX->setReadOnly(true);
430 myDlg->myDestDY->setReadOnly(true);
431 myDlg->myDestDZ->setReadOnly(true);
432 myDlg->myRButNodeToMove->setChecked(true);
434 myDlg->ConstructorsClicked(GetConstructorId());
438 onSelectionDone(); // init myMeshActor
441 // myMeshActor->SetRepresentation( VTK_WIREFRAME );
442 myMeshActor->SetPointRepresentation(true);
443 SMESH::RepaintCurrentView();
448 //=================================================================================
449 // function : GetConstructorId()
451 //=================================================================================
452 int SMESHGUI_MakeNodeAtPointOp::GetConstructorId()
454 return myDlg->myButtonGroup->checkedId();
457 //================================================================================
459 * \brief Stops operation
461 //================================================================================
463 void SMESHGUI_MakeNodeAtPointOp::stopOperation()
466 mySimulation->SetVisibility(false);
468 myMeshActor->SetPointRepresentation(false);
469 SMESH::RepaintCurrentView();
472 selectionMgr()->removeFilter( myFilter );
473 SMESHGUI_SelectionOp::stopOperation();
476 //================================================================================
478 * \brief perform it's intention action: move or create a node
480 //================================================================================
482 bool SMESHGUI_MakeNodeAtPointOp::onApply()
484 if( isStudyLocked() )
487 if ( !myMeshActor ) {
488 SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
489 tr("INVALID_MESH") );
495 if ( !isValid( msg ) ) { // node id is invalid
497 SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
503 QStringList aParameters;
504 aParameters << myDlg->myDestinationX->text();
505 aParameters << myDlg->myDestinationY->text();
506 aParameters << myDlg->myDestinationZ->text();
509 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
510 if (aMesh->_is_nil()) {
511 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
512 tr("SMESHG_NO_MESH") );
515 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
516 if (aMeshEditor->_is_nil())
519 aMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
522 int anId = myDlg->myId->text().toInt( &ok );
523 if( !ok || anId < 1 )
524 anId = aMeshEditor->FindNodeClosestTo(myDlg->myDestinationX->GetValue(),
525 myDlg->myDestinationY->GetValue(),
526 myDlg->myDestinationZ->GetValue());
528 int aResult = aMeshEditor->MoveNode(anId,
529 myDlg->myDestinationX->GetValue(),
530 myDlg->myDestinationY->GetValue(),
531 myDlg->myDestinationZ->GetValue() );
535 myDlg->myCurrentX->SetValue(0);
536 myDlg->myCurrentY->SetValue(0);
537 myDlg->myCurrentZ->SetValue(0);
538 myDlg->myDestDX->SetValue(0);
539 myDlg->myDestDY->SetValue(0);
540 myDlg->myDestDZ->SetValue(0);
543 selectionMgr()->setSelectedObjects(aList,false);
544 aList.Append(myMeshActor->getIO());
545 selectionMgr()->setSelectedObjects(aList,false);
547 SMESHGUI::Modified();
550 catch (const SALOME::SALOME_Exception& S_ex) {
551 SalomeApp_Tools::QtCatchCorbaException(S_ex);
559 //================================================================================
561 * \brief Check selected node id validity
563 //================================================================================
565 bool SMESHGUI_MakeNodeAtPointOp::isValid( QString& msg )
568 if ( myMeshActor && myDlg->myRButNodeToMove->isChecked() )
571 int id = myDlg->myId->text().toInt();
573 if (SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh())
574 ok = aMesh->FindNode( id );
576 msg += tr("INVALID_ID") + "\n";
579 ok = myDlg->myDestinationX->isValid( msg, !myNoPreview ) && ok;
580 ok = myDlg->myDestinationY->isValid( msg, !myNoPreview ) && ok;
581 ok = myDlg->myDestinationZ->isValid( msg, !myNoPreview ) && ok;
586 //================================================================================
588 * \brief SLOT called when selection changed
590 //================================================================================
592 void SMESHGUI_MakeNodeAtPointOp::onSelectionDone()
594 if ( !myDlg->isVisible() || !myDlg->isEnabled() )
598 selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type());
599 if (aList.Extent() != 1)
601 Handle(SALOME_InteractiveObject) anIO = aList.First();
602 SMESH_Actor* aMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
604 if (!aMeshActor) { // coord by geom
605 if ( myDlg->myDestBtn->isChecked() ) {
606 GEOM::GEOM_Object_var geom = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
607 if ( !geom->_is_nil() ) {
608 TopoDS_Vertex aShape;
609 if ( GEOMBase::GetShape(geom, aShape) &&
610 aShape.ShapeType() == TopAbs_VERTEX ) {
611 gp_Pnt P = BRep_Tool::Pnt(aShape);
613 myDlg->myDestinationX->SetValue(P.X());
614 myDlg->myDestinationY->SetValue(P.Y());
615 myDlg->myDestinationZ->SetValue(P.Z());
625 myMeshActor = aMeshActor;
628 int nbElems = SMESH::GetNameOfSelectedElements(selector(),anIO, aString);
630 if (SMDS_Mesh* aMesh = aMeshActor->GetObject()->GetMesh()) {
631 if (const SMDS_MeshNode* aNode = aMesh->FindNode(aString.toInt())) {
633 if ( myDlg->myDestBtn->isChecked() ) { // set coord
634 myDlg->myDestinationX->SetValue(aNode->X());
635 myDlg->myDestinationY->SetValue(aNode->Y());
636 myDlg->myDestinationZ->SetValue(aNode->Z());
640 else if ( myDlg->myIdBtn->isChecked() &&
641 myDlg->myIdBtn->isEnabled() ) { // set node to move
642 myDlg->myId->setText(aString);
647 if (const SMDS_MeshNode* aCurrentNode = aMesh->FindNode(myDlg->myId->text().toInt())) {
648 double x = aCurrentNode->X();
649 double y = aCurrentNode->Y();
650 double z = aCurrentNode->Z();
651 double dx = myDlg->myDestinationX->GetValue() - x;
652 double dy = myDlg->myDestinationY->GetValue() - y;
653 double dz = myDlg->myDestinationZ->GetValue() - z;
654 myDlg->myCurrentX->SetValue(x);
655 myDlg->myCurrentY->SetValue(y);
656 myDlg->myCurrentZ->SetValue(z);
657 myDlg->myDestDX->SetValue(dx);
658 myDlg->myDestDY->SetValue(dy);
659 myDlg->myDestDZ->SetValue(dz);
660 myDlg->myDestDX->setReadOnly(false);
661 myDlg->myDestDY->setReadOnly(false);
662 myDlg->myDestDZ->setReadOnly(false);
671 //================================================================================
673 * \brief update preview
675 //================================================================================
677 void SMESHGUI_MakeNodeAtPointOp::redisplayPreview()
683 SMESH::MeshPreviewStruct_var aMeshPreviewStruct;
685 bool moveShown = false;
688 const bool isPreview = myDlg->myPreviewChkBox->isChecked();
689 const bool isMoveNode = myDlg->myRButMoveWithoutNode->isChecked();
691 if ( isValid( msg ) )
694 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
695 if (!aMesh->_is_nil()) {
696 SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer();
697 if (!aPreviewer->_is_nil())
699 SUIT_OverrideCursor aWaitCursor;
701 int anId = myDlg->myId->text().toInt();
703 SMESH::double_array_var aXYZ = aMesh->GetNodeXYZ( anId );
704 if( &aXYZ.in() && aXYZ->length() >= 3 )
713 if ( myUpdateDestination ) {
714 myDlg->myDestinationX->SetValue(x);
715 myDlg->myDestinationY->SetValue(y);
716 myDlg->myDestinationZ->SetValue(z);
718 if ( myDestCoordChanged ) {
719 dx = myDlg->myDestinationX->GetValue() - x;
720 dy = myDlg->myDestinationY->GetValue() - y;
721 dz = myDlg->myDestinationZ->GetValue() - z;
722 myDlg->myDestDX->SetValue(dx);
723 myDlg->myDestDY->SetValue(dy);
724 myDlg->myDestDZ->SetValue(dz);
727 dx = myDlg->myDestDX->GetValue() + x;
728 dy = myDlg->myDestDY->GetValue() + y;
729 dz = myDlg->myDestDZ->GetValue() + z;
730 myDlg->myDestinationX->SetValue(dx);
731 myDlg->myDestinationY->SetValue(dy);
732 myDlg->myDestinationZ->SetValue(dz);
734 myDlg->myCurrentX->SetValue(x);
735 myDlg->myCurrentY->SetValue(y);
736 myDlg->myCurrentZ->SetValue(z);
737 myDlg->myDestDX->setReadOnly(false);
738 myDlg->myDestDY->setReadOnly(false);
739 myDlg->myDestDZ->setReadOnly(false);
742 myDlg->myCurrentX->SetValue(0);
743 myDlg->myCurrentY->SetValue(0);
744 myDlg->myCurrentZ->SetValue(0);
745 myDlg->myDestDX->SetValue(0);
746 myDlg->myDestDY->SetValue(0);
747 myDlg->myDestDZ->SetValue(0);
748 myDlg->myDestDX->setReadOnly(true);
749 myDlg->myDestDY->setReadOnly(true);
750 myDlg->myDestDZ->setReadOnly(true);
752 if ( isPreview && isMoveNode && anId == 0 )
753 anId = aPreviewer->FindNodeClosestTo(myDlg->myDestinationX->GetValue(),
754 myDlg->myDestinationY->GetValue(),
755 myDlg->myDestinationZ->GetValue());
756 // find id and/or just compute preview
757 aPreviewer->MoveNode(anId,
758 myDlg->myDestinationX->GetValue(),
759 myDlg->myDestinationY->GetValue(),
760 myDlg->myDestinationZ->GetValue());
762 if ( isPreview ) { // fill preview data
763 aMeshPreviewStruct = aPreviewer->GetPreviewData();
764 moveShown = ( anId > 0 );
775 aMeshPreviewStruct = new SMESH::MeshPreviewStruct();
777 aMeshPreviewStruct->nodesXYZ.length(1);
778 aMeshPreviewStruct->nodesXYZ[0].x = myDlg->myDestinationX->GetValue();
779 aMeshPreviewStruct->nodesXYZ[0].y = myDlg->myDestinationY->GetValue();
780 aMeshPreviewStruct->nodesXYZ[0].z = myDlg->myDestinationZ->GetValue();
782 aMeshPreviewStruct->elementTypes.length(1);
783 aMeshPreviewStruct->elementTypes[0].SMDS_ElementType = SMESH::NODE;
784 aMeshPreviewStruct->elementTypes[0].isPoly = false;
785 aMeshPreviewStruct->elementTypes[0].nbNodesInElement = 1;
787 aMeshPreviewStruct->elementConnectivities.length(1);
788 aMeshPreviewStruct->elementConnectivities[0] = 0;
792 if ( aMeshPreviewStruct.operator->() )
794 mySimulation->SetData(aMeshPreviewStruct._retn());
798 mySimulation->SetVisibility(false);
804 //================================================================================
806 * \brief SLOT called when the node id is manually changed
808 //================================================================================
810 void SMESHGUI_MakeNodeAtPointOp::onTextChange( const QString& theText )
814 if( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh() )
816 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
818 aList.Append( anIO );
819 selectionMgr()->setSelectedObjects( aList, false );
821 if( const SMDS_MeshNode* aNode = aMesh->FindNode( theText.toInt() ) )
823 TColStd_MapOfInteger aListInd;
824 aListInd.Add( aNode->GetID() );
825 selector()->AddOrRemoveIndex( anIO, aListInd, false );
826 if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() ) )
827 aViewWindow->highlight( anIO, true, true );
833 //================================================================================
835 * \brief Activate Node selection
837 //================================================================================
839 void SMESHGUI_MakeNodeAtPointOp::activateSelection()
841 selectionMgr()->clearFilters();
842 SMESH::SetPointRepresentation(false);
843 selectionMgr()->installFilter( myFilter );
844 setSelectionMode( NodeSelection );
847 //================================================================================
851 //================================================================================
853 SMESHGUI_MakeNodeAtPointOp::~SMESHGUI_MakeNodeAtPointOp()
855 if ( myDlg ) delete myDlg;
856 if ( mySimulation ) delete mySimulation;
857 if ( myFilter ) delete myFilter;
860 //================================================================================
862 * \brief Gets dialog of this operation
863 * \retval LightApp_Dialog* - pointer to dialog of this operation
865 //================================================================================
867 LightApp_Dialog* SMESHGUI_MakeNodeAtPointOp::dlg() const