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()
350 myDlg = new SMESHGUI_MakeNodeAtPointDlg;
352 myHelpFileName = "mesh_through_point_page.html";
355 myUpdateDestination = false;
356 myDestCoordChanged = true;
358 // connect signals and slots
359 connect(myDlg->myDestinationX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
360 connect(myDlg->myDestinationY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
361 connect(myDlg->myDestinationZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
362 connect(myDlg->myDestDX, SIGNAL (valueChanged(double)), this, SLOT(onDestCoordChanged()));
363 connect(myDlg->myDestDY, SIGNAL (valueChanged(double)), this, SLOT(onDestCoordChanged()));
364 connect(myDlg->myDestDZ, SIGNAL (valueChanged(double)), this, SLOT(onDestCoordChanged()));
365 connect(myDlg->myId,SIGNAL (textChanged(const QString&)),SLOT(redisplayPreview()));
366 connect(myDlg->myPreviewChkBox, SIGNAL (toggled(bool)),SLOT(redisplayPreview()));
368 // IPAL22913: TC6.5.0: selected in "Move node" dialog box node is not highlighted
369 // note: this slot seems to be lost together with removed obsolete SMESHGUI_MoveNodesDlg class
370 connect(myDlg->myId,SIGNAL (textChanged(const QString&)),SLOT(onTextChange(const QString&)));
371 connect(myDlg->myUpdateBtn, SIGNAL (clicked()), this, SLOT(onUpdateDestination()));
374 void SMESHGUI_MakeNodeAtPointOp::onUpdateDestination()
376 myUpdateDestination = true;
378 myUpdateDestination = false;
381 void SMESHGUI_MakeNodeAtPointOp::onDestCoordChanged()
383 myDestCoordChanged = false;
385 myDestCoordChanged = true;
388 //=======================================================================
389 // function : startOperation()
390 // purpose : Init dialog fields, connect signals and slots, show dialog
391 //=======================================================================
392 void SMESHGUI_MakeNodeAtPointOp::startOperation()
397 // init simulation with a current View
398 if ( mySimulation ) delete mySimulation;
399 mySMESHGUI = getSMESHGUI();
400 mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ) );
401 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
402 connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
403 vtkProperty* aProp = vtkProperty::New();
404 aProp->SetRepresentationToWireframe();
405 aProp->SetColor(250, 0, 250);
406 aProp->SetPointSize(5);
407 aProp->SetLineWidth( SMESH::GetFloat("SMESH:element_width",1) + 1);
408 mySimulation->GetActor()->SetProperty(aProp);
411 // SalomeApp_TypeFilter depends on a current study
412 if ( myFilter ) delete myFilter;
413 QList<SUIT_SelectionFilter*> filters;
414 filters.append( new SalomeApp_TypeFilter((SalomeApp_Study*)study(), "SMESH" ));
415 TColStd_MapOfInteger vertexType;
416 vertexType.Add( TopAbs_VERTEX );
417 filters.append( new SMESH_NumberFilter("GEOM", TopAbs_VERTEX, 1, vertexType ));
418 myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
421 SMESHGUI_SelectionOp::startOperation(); // this method should be called only after filter creation
422 //activateSelection(); // set filters // called inside of previous statement
423 myDlg->myId->setText("");
424 myDlg->myDestinationX->SetValue(0);
425 myDlg->myDestinationY->SetValue(0);
426 myDlg->myDestinationZ->SetValue(0);
427 myDlg->myDestDX->SetValue(0);
428 myDlg->myDestDY->SetValue(0);
429 myDlg->myDestDZ->SetValue(0);
430 myDlg->myCurrentX->SetValue(0);
431 myDlg->myCurrentY->SetValue(0);
432 myDlg->myCurrentZ->SetValue(0);
433 myDlg->myDestDX->setReadOnly(true);
434 myDlg->myDestDY->setReadOnly(true);
435 myDlg->myDestDZ->setReadOnly(true);
436 myDlg->myRButNodeToMove->setChecked(true);
438 myDlg->ConstructorsClicked(GetConstructorId());
442 onSelectionDone(); // init myMeshActor
445 // myMeshActor->SetRepresentation( VTK_WIREFRAME );
446 myMeshActor->SetPointRepresentation(true);
447 SMESH::RepaintCurrentView();
452 //=================================================================================
453 // function : GetConstructorId()
455 //=================================================================================
456 int SMESHGUI_MakeNodeAtPointOp::GetConstructorId()
458 return myDlg->myButtonGroup->checkedId();
461 //================================================================================
463 * \brief Stops operation
465 //================================================================================
467 void SMESHGUI_MakeNodeAtPointOp::stopOperation()
472 mySimulation->SetVisibility(false);
477 myMeshActor->SetPointRepresentation(false);
478 SMESH::RepaintCurrentView();
481 disconnect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
482 disconnect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
483 selectionMgr()->removeFilter( myFilter );
484 SMESHGUI_SelectionOp::stopOperation();
487 //================================================================================
489 * \brief perform it's intention action: move or create a node
491 //================================================================================
493 bool SMESHGUI_MakeNodeAtPointOp::onApply()
495 if( isStudyLocked() )
498 if ( !myMeshActor ) {
499 SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
500 tr("INVALID_MESH") );
506 if ( !isValid( msg ) ) { // node id is invalid
508 SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
514 QStringList aParameters;
515 aParameters << myDlg->myDestinationX->text();
516 aParameters << myDlg->myDestinationY->text();
517 aParameters << myDlg->myDestinationZ->text();
520 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
521 if (aMesh->_is_nil()) {
522 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
523 tr("SMESHG_NO_MESH") );
526 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
527 if (aMeshEditor->_is_nil())
530 aMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
533 int anId = myDlg->myId->text().toInt( &ok );
534 if( !ok || anId < 1 )
535 anId = aMeshEditor->FindNodeClosestTo(myDlg->myDestinationX->GetValue(),
536 myDlg->myDestinationY->GetValue(),
537 myDlg->myDestinationZ->GetValue());
539 int aResult = aMeshEditor->MoveNode(anId,
540 myDlg->myDestinationX->GetValue(),
541 myDlg->myDestinationY->GetValue(),
542 myDlg->myDestinationZ->GetValue() );
546 myDlg->myCurrentX->SetValue(0);
547 myDlg->myCurrentY->SetValue(0);
548 myDlg->myCurrentZ->SetValue(0);
549 myDlg->myDestDX->SetValue(0);
550 myDlg->myDestDY->SetValue(0);
551 myDlg->myDestDZ->SetValue(0);
554 selectionMgr()->setSelectedObjects(aList,false);
555 aList.Append(myMeshActor->getIO());
556 selectionMgr()->setSelectedObjects(aList,false);
558 SMESHGUI::Modified();
561 catch (const SALOME::SALOME_Exception& S_ex) {
562 SalomeApp_Tools::QtCatchCorbaException(S_ex);
570 //================================================================================
572 * \brief Check selected node id validity
574 //================================================================================
576 bool SMESHGUI_MakeNodeAtPointOp::isValid( QString& msg )
579 if ( myMeshActor && myDlg->myRButNodeToMove->isChecked() )
582 int id = myDlg->myId->text().toInt();
584 if (SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh())
585 ok = aMesh->FindNode( id );
587 msg += tr("INVALID_ID") + "\n";
590 ok = myDlg->myDestinationX->isValid( msg, !myNoPreview ) && ok;
591 ok = myDlg->myDestinationY->isValid( msg, !myNoPreview ) && ok;
592 ok = myDlg->myDestinationZ->isValid( msg, !myNoPreview ) && ok;
597 //================================================================================
599 * \brief SLOT called when selection changed
601 //================================================================================
603 void SMESHGUI_MakeNodeAtPointOp::onSelectionDone()
605 if ( !myDlg->isVisible() || !myDlg->isEnabled() )
609 selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type());
610 if (aList.Extent() != 1)
612 Handle(SALOME_InteractiveObject) anIO = aList.First();
613 SMESH_Actor* aMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
615 if (!aMeshActor) { // coord by geom
616 if ( myDlg->myDestBtn->isChecked() ) {
617 GEOM::GEOM_Object_var geom = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
618 if ( !geom->_is_nil() ) {
619 TopoDS_Vertex aShape;
620 if ( GEOMBase::GetShape(geom, aShape) &&
621 aShape.ShapeType() == TopAbs_VERTEX ) {
622 gp_Pnt P = BRep_Tool::Pnt(aShape);
624 myDlg->myDestinationX->SetValue(P.X());
625 myDlg->myDestinationY->SetValue(P.Y());
626 myDlg->myDestinationZ->SetValue(P.Z());
636 myMeshActor = aMeshActor;
639 int nbElems = SMESH::GetNameOfSelectedElements(selector(),anIO, aString);
641 if (SMDS_Mesh* aMesh = aMeshActor->GetObject()->GetMesh()) {
642 if (const SMDS_MeshNode* aNode = aMesh->FindNode(aString.toInt())) {
644 if ( myDlg->myDestBtn->isChecked() ) { // set coord
645 myDlg->myDestinationX->SetValue(aNode->X());
646 myDlg->myDestinationY->SetValue(aNode->Y());
647 myDlg->myDestinationZ->SetValue(aNode->Z());
651 else if ( myDlg->myIdBtn->isChecked() &&
652 myDlg->myIdBtn->isEnabled() ) { // set node to move
653 myDlg->myId->setText(aString);
658 if (const SMDS_MeshNode* aCurrentNode = aMesh->FindNode(myDlg->myId->text().toInt())) {
659 double x = aCurrentNode->X();
660 double y = aCurrentNode->Y();
661 double z = aCurrentNode->Z();
662 double dx = myDlg->myDestinationX->GetValue() - x;
663 double dy = myDlg->myDestinationY->GetValue() - y;
664 double dz = myDlg->myDestinationZ->GetValue() - z;
665 myDlg->myCurrentX->SetValue(x);
666 myDlg->myCurrentY->SetValue(y);
667 myDlg->myCurrentZ->SetValue(z);
668 myDlg->myDestDX->SetValue(dx);
669 myDlg->myDestDY->SetValue(dy);
670 myDlg->myDestDZ->SetValue(dz);
671 myDlg->myDestDX->setReadOnly(false);
672 myDlg->myDestDY->setReadOnly(false);
673 myDlg->myDestDZ->setReadOnly(false);
682 //================================================================================
684 * \brief update preview
686 //================================================================================
688 void SMESHGUI_MakeNodeAtPointOp::redisplayPreview()
694 SMESH::MeshPreviewStruct_var aMeshPreviewStruct;
696 bool moveShown = false;
699 const bool isPreview = myDlg->myPreviewChkBox->isChecked();
700 const bool isMoveNode = myDlg->myRButMoveWithoutNode->isChecked();
702 if ( isValid( msg ) )
705 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
706 if (!aMesh->_is_nil()) {
707 SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer();
708 if (!aPreviewer->_is_nil())
710 SUIT_OverrideCursor aWaitCursor;
712 int anId = myDlg->myId->text().toInt();
714 SMESH::double_array_var aXYZ = aMesh->GetNodeXYZ( anId );
715 if( &aXYZ.in() && aXYZ->length() >= 3 )
724 if ( myUpdateDestination ) {
725 myDlg->myDestinationX->SetValue(x);
726 myDlg->myDestinationY->SetValue(y);
727 myDlg->myDestinationZ->SetValue(z);
729 if ( myDestCoordChanged ) {
730 dx = myDlg->myDestinationX->GetValue() - x;
731 dy = myDlg->myDestinationY->GetValue() - y;
732 dz = myDlg->myDestinationZ->GetValue() - z;
733 myDlg->myDestDX->SetValue(dx);
734 myDlg->myDestDY->SetValue(dy);
735 myDlg->myDestDZ->SetValue(dz);
738 dx = myDlg->myDestDX->GetValue() + x;
739 dy = myDlg->myDestDY->GetValue() + y;
740 dz = myDlg->myDestDZ->GetValue() + z;
741 myDlg->myDestinationX->SetValue(dx);
742 myDlg->myDestinationY->SetValue(dy);
743 myDlg->myDestinationZ->SetValue(dz);
745 myDlg->myCurrentX->SetValue(x);
746 myDlg->myCurrentY->SetValue(y);
747 myDlg->myCurrentZ->SetValue(z);
748 myDlg->myDestDX->setReadOnly(false);
749 myDlg->myDestDY->setReadOnly(false);
750 myDlg->myDestDZ->setReadOnly(false);
753 myDlg->myCurrentX->SetValue(0);
754 myDlg->myCurrentY->SetValue(0);
755 myDlg->myCurrentZ->SetValue(0);
756 myDlg->myDestDX->SetValue(0);
757 myDlg->myDestDY->SetValue(0);
758 myDlg->myDestDZ->SetValue(0);
759 myDlg->myDestDX->setReadOnly(true);
760 myDlg->myDestDY->setReadOnly(true);
761 myDlg->myDestDZ->setReadOnly(true);
763 if ( isPreview && isMoveNode && anId == 0 )
764 anId = aPreviewer->FindNodeClosestTo(myDlg->myDestinationX->GetValue(),
765 myDlg->myDestinationY->GetValue(),
766 myDlg->myDestinationZ->GetValue());
767 // find id and/or just compute preview
768 aPreviewer->MoveNode(anId,
769 myDlg->myDestinationX->GetValue(),
770 myDlg->myDestinationY->GetValue(),
771 myDlg->myDestinationZ->GetValue());
773 if ( isPreview ) { // fill preview data
774 aMeshPreviewStruct = aPreviewer->GetPreviewData();
775 moveShown = ( anId > 0 );
786 aMeshPreviewStruct = new SMESH::MeshPreviewStruct();
788 aMeshPreviewStruct->nodesXYZ.length(1);
789 aMeshPreviewStruct->nodesXYZ[0].x = myDlg->myDestinationX->GetValue();
790 aMeshPreviewStruct->nodesXYZ[0].y = myDlg->myDestinationY->GetValue();
791 aMeshPreviewStruct->nodesXYZ[0].z = myDlg->myDestinationZ->GetValue();
793 aMeshPreviewStruct->elementTypes.length(1);
794 aMeshPreviewStruct->elementTypes[0].SMDS_ElementType = SMESH::NODE;
795 aMeshPreviewStruct->elementTypes[0].isPoly = false;
796 aMeshPreviewStruct->elementTypes[0].nbNodesInElement = 1;
798 aMeshPreviewStruct->elementConnectivities.length(1);
799 aMeshPreviewStruct->elementConnectivities[0] = 0;
802 mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ));
804 if ( aMeshPreviewStruct.operator->() )
806 mySimulation->SetData(aMeshPreviewStruct._retn());
810 mySimulation->SetVisibility(false);
816 //=================================================================================
818 * \brief SLOT called when the viewer opened
820 //=================================================================================
821 void SMESHGUI_MakeNodeAtPointOp::onOpenView()
823 if ( mySimulation ) {
824 mySimulation->SetVisibility(false);
825 SMESH::SetPointRepresentation(false);
828 mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ));
832 //=================================================================================
834 * \brief SLOT called when the viewer closed
836 //=================================================================================
837 void SMESHGUI_MakeNodeAtPointOp::onCloseView()
843 //================================================================================
845 * \brief SLOT called when the node id is manually changed
847 //================================================================================
849 void SMESHGUI_MakeNodeAtPointOp::onTextChange( const QString& theText )
853 if( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh() )
855 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
857 aList.Append( anIO );
858 selectionMgr()->setSelectedObjects( aList, false );
860 if( const SMDS_MeshNode* aNode = aMesh->FindNode( theText.toInt() ) )
862 TColStd_MapOfInteger aListInd;
863 aListInd.Add( aNode->GetID() );
864 selector()->AddOrRemoveIndex( anIO, aListInd, false );
865 if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() ) )
866 aViewWindow->highlight( anIO, true, true );
872 //================================================================================
874 * \brief Activate Node selection
876 //================================================================================
878 void SMESHGUI_MakeNodeAtPointOp::activateSelection()
880 selectionMgr()->clearFilters();
881 SMESH::SetPointRepresentation(false);
882 selectionMgr()->installFilter( myFilter );
883 setSelectionMode( NodeSelection );
886 //================================================================================
890 //================================================================================
892 SMESHGUI_MakeNodeAtPointOp::~SMESHGUI_MakeNodeAtPointOp()
894 if ( myDlg ) delete myDlg;
895 if ( mySimulation ) delete mySimulation;
896 if ( myFilter ) delete myFilter;
899 //================================================================================
901 * \brief Gets dialog of this operation
902 * \retval LightApp_Dialog* - pointer to dialog of this operation
904 //================================================================================
906 LightApp_Dialog* SMESHGUI_MakeNodeAtPointOp::dlg() const