1 // Copyright (C) 2007-2016 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)
89 enum { MANUAL_MODE = 0, SEARCH_MODE }; // how a node to move is specified
93 * \brief Dialog to publish a sub-shape of the mesh main shape
94 * by selecting mesh elements
96 SMESHGUI_MakeNodeAtPointDlg::SMESHGUI_MakeNodeAtPointDlg()
97 : SMESHGUI_Dialog( 0, false, true )
99 setWindowTitle(tr("CAPTION"));
101 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
102 aDlgLay->setMargin(0);
103 aDlgLay->setSpacing(SPACING);
104 myMainFrame = createMainFrame(mainFrame());
106 aDlgLay->addWidget(myMainFrame);
108 aDlgLay->setStretchFactor(myMainFrame, 1);
111 //=======================================================================
112 // function : createMainFrame()
113 // purpose : Create frame containing dialog's input fields
114 //=======================================================================
115 QWidget* SMESHGUI_MakeNodeAtPointDlg::createMainFrame (QWidget* theParent)
117 QWidget* aFrame = new QWidget(theParent);
119 SUIT_ResourceMgr* rm = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
120 QPixmap iconMoveNode (rm->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
121 QPixmap iconMoveWithoutNode (rm->loadPixmap("SMESH", tr("ICON_DLG_MOVE_WITHOUT_NODE")));
122 QPixmap iconSelect (rm->loadPixmap("SMESH", tr("ICON_SELECT")));
125 QGroupBox* aPixGrp = new QGroupBox(tr("MOVE_NODE"), this);
126 aPixGrp->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
127 myButtonGroup = new QButtonGroup(this);
128 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
129 aPixGrpLayout->setMargin(MARGIN);
130 aPixGrpLayout->setSpacing(SPACING);
132 myRButNodeToMove = new QRadioButton(aPixGrp);
133 myRButMoveWithoutNode = new QRadioButton(aPixGrp);
134 myRButNodeToMove->setIcon(iconMoveNode);
135 myRButMoveWithoutNode->setIcon(iconMoveWithoutNode);
136 myRButNodeToMove->setChecked(true);
138 aPixGrpLayout->addWidget(myRButNodeToMove);
139 aPixGrpLayout->addWidget(myRButMoveWithoutNode);
140 myButtonGroup->addButton(myRButNodeToMove, 0);
141 myButtonGroup->addButton(myRButMoveWithoutNode, 1);
145 myNodeToMoveGrp = new QGroupBox(tr("NODE_2MOVE"), aFrame);
146 myNodeToMoveGrp->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
147 QLabel* idLabel = new QLabel(tr("NODE_2MOVE_ID"), myNodeToMoveGrp);
148 myIdBtn = new QPushButton(myNodeToMoveGrp);
149 myIdBtn->setIcon(iconSelect);
150 myIdBtn->setCheckable(true);
151 myId = new QLineEdit(myNodeToMoveGrp);
152 myId->setValidator(new SMESHGUI_IdValidator(this, 1));
154 myUpdateBtn = new QPushButton(tr("UPDATE_DESTINATION"), myNodeToMoveGrp);
155 myUpdateBtn->setAutoDefault(true);
157 QWidget* aCoordWidget = new QWidget(myNodeToMoveGrp);
159 QLabel* aCurrentXLabel = new QLabel(tr("SMESH_X"), aCoordWidget);
160 myCurrentX = new SMESHGUI_SpinBox(aCoordWidget);
161 myCurrentX->setButtonSymbols(QAbstractSpinBox::NoButtons);
162 myCurrentX->setReadOnly(true);
164 QLabel* aCurrentYLabel = new QLabel(tr("SMESH_Y"), aCoordWidget);
165 myCurrentY = new SMESHGUI_SpinBox(aCoordWidget);
166 myCurrentY->setButtonSymbols(QAbstractSpinBox::NoButtons);
167 myCurrentY->setReadOnly(true);
169 QLabel* aCurrentZLabel = new QLabel(tr("SMESH_Z"), aCoordWidget);
170 myCurrentZ = new SMESHGUI_SpinBox(aCoordWidget);
171 myCurrentZ->setButtonSymbols(QAbstractSpinBox::NoButtons);
172 myCurrentZ->setReadOnly(true);
174 myCurrentX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
175 myCurrentY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
176 myCurrentZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
178 QGridLayout* aCoordLayout = new QGridLayout(aCoordWidget);
179 aCoordLayout->setMargin(0);
180 aCoordLayout->setSpacing(SPACING);
181 aCoordLayout->addWidget(aCurrentXLabel, 0, 0);
182 aCoordLayout->addWidget(myCurrentX, 0, 1);
183 aCoordLayout->addWidget(aCurrentYLabel, 0, 2);
184 aCoordLayout->addWidget(myCurrentY, 0, 3);
185 aCoordLayout->addWidget(aCurrentZLabel, 0, 4);
186 aCoordLayout->addWidget(myCurrentZ, 0, 5);
187 aCoordLayout->setColumnStretch(1, 1);
188 aCoordLayout->setColumnStretch(3, 1);
189 aCoordLayout->setColumnStretch(5, 1);
191 QGridLayout* myNodeToMoveGrpLayout = new QGridLayout(myNodeToMoveGrp);
192 myNodeToMoveGrpLayout->setSpacing(SPACING);
193 myNodeToMoveGrpLayout->setMargin(MARGIN);
195 myNodeToMoveGrpLayout->addWidget( idLabel, 0, 0 );
196 myNodeToMoveGrpLayout->addWidget( myIdBtn, 0, 1 );
197 myNodeToMoveGrpLayout->addWidget( myId, 0, 2 );
198 myNodeToMoveGrpLayout->addWidget( myUpdateBtn, 0, 3 );
199 myNodeToMoveGrpLayout->addWidget( aCoordWidget, 1, 0, 1, 4 );
203 myDestinationGrp = new QGroupBox(tr("DESTINATION"), aFrame);
204 myDestinationGrp->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
206 myDestBtn = new QPushButton(myDestinationGrp);
207 myDestBtn->setIcon(iconSelect);
208 myDestBtn->setCheckable(true);
210 QLabel* aDestinationXLabel = new QLabel(tr("SMESH_X"), myDestinationGrp);
211 myDestinationX = new SMESHGUI_SpinBox(myDestinationGrp);
213 QLabel* aDestinationYLabel = new QLabel(tr("SMESH_Y"), myDestinationGrp);
214 myDestinationY = new SMESHGUI_SpinBox(myDestinationGrp);
216 QLabel* aDestinationZLabel = new QLabel(tr("SMESH_Z"), myDestinationGrp);
217 myDestinationZ = new SMESHGUI_SpinBox(myDestinationGrp);
219 myDestDXLabel = new QLabel(tr("SMESH_DX"), myDestinationGrp);
220 myDestDX = new SMESHGUI_SpinBox(myDestinationGrp);
221 myDestDX->setReadOnly(true);
223 myDestDYLabel = new QLabel(tr("SMESH_DY"), myDestinationGrp);
224 myDestDY = new SMESHGUI_SpinBox(myDestinationGrp);
225 myDestDY->setReadOnly(true);
227 myDestDZLabel = new QLabel(tr("SMESH_DZ"), myDestinationGrp);
228 myDestDZ = new SMESHGUI_SpinBox(myDestinationGrp);
229 myDestDZ->setReadOnly(true);
231 myDestinationX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
232 myDestinationY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
233 myDestinationZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
234 myDestDX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
235 myDestDY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
236 myDestDZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
238 QGridLayout* aDestLayout = new QGridLayout(myDestinationGrp);
239 aDestLayout->setMargin(MARGIN);
240 aDestLayout->setSpacing(SPACING);
241 aDestLayout->addWidget(myDestBtn, 0, 0);
242 aDestLayout->addWidget(aDestinationXLabel, 0, 1);
243 aDestLayout->addWidget(myDestinationX, 0, 2);
244 aDestLayout->addWidget(aDestinationYLabel, 0, 3);
245 aDestLayout->addWidget(myDestinationY, 0, 4);
246 aDestLayout->addWidget(aDestinationZLabel, 0, 5);
247 aDestLayout->addWidget(myDestinationZ, 0, 6);
248 aDestLayout->addWidget(myDestDXLabel, 1, 1);
249 aDestLayout->addWidget(myDestDX, 1, 2);
250 aDestLayout->addWidget(myDestDYLabel, 1, 3);
251 aDestLayout->addWidget(myDestDY, 1, 4);
252 aDestLayout->addWidget(myDestDZLabel, 1, 5);
253 aDestLayout->addWidget(myDestDZ, 1, 6);
254 aDestLayout->setColumnStretch(2, 1);
255 aDestLayout->setColumnStretch(4, 1);
256 aDestLayout->setColumnStretch(6, 1);
260 myPreviewChkBox = new QCheckBox( tr("PREVIEW"), aFrame);
262 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
263 aLay->addWidget(aPixGrp);
264 aLay->addWidget(myNodeToMoveGrp);
265 aLay->addWidget(myDestinationGrp);
266 aLay->addWidget(myPreviewChkBox);
268 connect(myDestBtn, SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
269 connect(myIdBtn, SIGNAL (toggled(bool)), this, SLOT(ButtonToggled(bool)));
270 connect(myButtonGroup, SIGNAL (buttonClicked(int)), SLOT(ConstructorsClicked(int)));
272 myIdBtn->setChecked(true);
277 //================================================================================
279 * \brief SLOT called when any button is toggled
280 * \param bool - on or off
282 //================================================================================
284 void SMESHGUI_MakeNodeAtPointDlg::ButtonToggled (bool on)
286 const QObject* aSender = sender();
288 if ( aSender == myDestBtn ) // button to set coord by node selection
290 if ( myIdBtn->isEnabled() )
291 myIdBtn->setChecked( !on );
293 else if ( aSender == myIdBtn ) // button to select a node to move
295 myDestBtn->setChecked( !on );
299 //================================================================================
301 * \brief SLOT called when clicked radio button
302 * \param int - number of the button
304 //================================================================================
305 void SMESHGUI_MakeNodeAtPointDlg::ConstructorsClicked (int constructorId)
307 switch (constructorId) {
310 myDestDXLabel->show();
311 myDestDYLabel->show();
312 myDestDZLabel->show();
316 myCurrentX->SetValue(0);
317 myCurrentY->SetValue(0);
318 myCurrentZ->SetValue(0);
319 if (!myNodeToMoveGrp->isVisible()) myNodeToMoveGrp->show();
325 myCurrentX->SetValue(0);
326 myCurrentY->SetValue(0);
327 myCurrentZ->SetValue(0);
328 myDestDXLabel->hide();
329 myDestDYLabel->hide();
330 myDestDZLabel->hide();
334 if (myNodeToMoveGrp->isVisible()) myNodeToMoveGrp->hide();
335 myDestBtn->setChecked( true );
339 QApplication::instance()->processEvents();
343 resize(minimumSizeHint());
346 //================================================================================
350 //================================================================================
352 SMESHGUI_MakeNodeAtPointOp::SMESHGUI_MakeNodeAtPointOp()
356 myDlg = new SMESHGUI_MakeNodeAtPointDlg;
358 myHelpFileName = "mesh_through_point_page.html";
361 myUpdateDestination = false;
362 myDestCoordChanged = true;
364 // connect signals and slots
365 connect(myDlg->myDestinationX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
366 connect(myDlg->myDestinationY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
367 connect(myDlg->myDestinationZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
368 connect(myDlg->myDestDX, SIGNAL (valueChanged(double)), this, SLOT(onDestCoordChanged()));
369 connect(myDlg->myDestDY, SIGNAL (valueChanged(double)), this, SLOT(onDestCoordChanged()));
370 connect(myDlg->myDestDZ, SIGNAL (valueChanged(double)), this, SLOT(onDestCoordChanged()));
371 connect(myDlg->myId, SIGNAL (textChanged(const QString&)),SLOT(redisplayPreview()));
372 connect(myDlg->myPreviewChkBox, SIGNAL (toggled(bool)), SLOT(redisplayPreview()));
373 connect(myDlg->myButtonGroup, SIGNAL (buttonClicked(int)), SLOT(redisplayPreview()));
375 // IPAL22913: TC6.5.0: selected in "Move node" dialog box node is not highlighted
376 // note: this slot seems to be lost together with removed obsolete SMESHGUI_MoveNodesDlg class
377 connect(myDlg->myId,SIGNAL (textChanged(const QString&)),SLOT(onTextChange(const QString&)));
378 connect(myDlg->myUpdateBtn, SIGNAL (clicked()), this, SLOT(onUpdateDestination()));
381 void SMESHGUI_MakeNodeAtPointOp::onUpdateDestination()
383 myUpdateDestination = true;
385 myUpdateDestination = false;
388 void SMESHGUI_MakeNodeAtPointOp::onDestCoordChanged()
390 myDestCoordChanged = false;
392 myDestCoordChanged = true;
395 //=======================================================================
396 // function : startOperation()
397 // purpose : Init dialog fields, connect signals and slots, show dialog
398 //=======================================================================
399 void SMESHGUI_MakeNodeAtPointOp::startOperation()
404 // init simulation with a current View
405 if ( mySimulation ) delete mySimulation;
406 mySMESHGUI = getSMESHGUI();
407 mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ) );
408 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
409 connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
410 vtkProperty* aProp = vtkProperty::New();
411 aProp->SetRepresentationToWireframe();
412 aProp->SetColor(250, 0, 250);
413 aProp->SetPointSize(5);
414 aProp->SetLineWidth( SMESH::GetFloat("SMESH:element_width",1) + 1);
415 mySimulation->GetActor()->SetProperty(aProp);
418 // SalomeApp_TypeFilter depends on a current study
419 if ( myFilter ) delete myFilter;
420 QList<SUIT_SelectionFilter*> filters;
421 filters.append( new SalomeApp_TypeFilter((SalomeApp_Study*)study(), "SMESH" ));
422 TColStd_MapOfInteger vertexType;
423 vertexType.Add( TopAbs_VERTEX );
424 filters.append( new SMESH_NumberFilter("GEOM", TopAbs_VERTEX, 1, vertexType ));
425 myFilter = new SMESH_LogicalFilter( filters, SMESH_LogicalFilter::LO_OR );
428 SMESHGUI_SelectionOp::startOperation(); // this method should be called only after filter creation
429 //activateSelection(); // set filters // called inside of previous statement
430 myDlg->myId->setText("");
431 myDlg->myDestinationX->SetValue(0);
432 myDlg->myDestinationY->SetValue(0);
433 myDlg->myDestinationZ->SetValue(0);
434 myDlg->myDestDX->SetValue(0);
435 myDlg->myDestDY->SetValue(0);
436 myDlg->myDestDZ->SetValue(0);
437 myDlg->myCurrentX->SetValue(0);
438 myDlg->myCurrentY->SetValue(0);
439 myDlg->myCurrentZ->SetValue(0);
440 myDlg->myDestDX->setReadOnly(true);
441 myDlg->myDestDY->setReadOnly(true);
442 myDlg->myDestDZ->setReadOnly(true);
443 myDlg->myRButNodeToMove->setChecked(true);
445 myDlg->ConstructorsClicked( GetConstructorId() );
449 onSelectionDone(); // init myMeshActor
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);
479 SMESH::SetPointRepresentation( false );
480 SMESH::RepaintCurrentView();
482 disconnect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
483 disconnect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
484 selectionMgr()->removeFilter( myFilter );
485 SMESHGUI_SelectionOp::stopOperation();
488 //================================================================================
490 * \brief perform it's intention action: move or create a node
492 //================================================================================
494 bool SMESHGUI_MakeNodeAtPointOp::onApply()
496 if( isStudyLocked() )
499 if ( !myMeshActor ) {
500 SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
501 tr("INVALID_MESH") );
507 if ( !isValid( msg ) ) { // node id is invalid
509 SUIT_MessageBox::warning( dlg(), tr( "SMESH_WRN_WARNING" ),
515 QStringList aParameters;
516 aParameters << myDlg->myDestinationX->text();
517 aParameters << myDlg->myDestinationY->text();
518 aParameters << myDlg->myDestinationZ->text();
521 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
522 if (aMesh->_is_nil()) {
523 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
524 tr("SMESHG_NO_MESH") );
527 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
528 if (aMeshEditor->_is_nil())
531 aMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
534 int anId = myDlg->myId->text().toInt( &ok );
535 if( !ok || anId < 1 )
536 anId = aMeshEditor->FindNodeClosestTo(myDlg->myDestinationX->GetValue(),
537 myDlg->myDestinationY->GetValue(),
538 myDlg->myDestinationZ->GetValue());
540 int aResult = aMeshEditor->MoveNode(anId,
541 myDlg->myDestinationX->GetValue(),
542 myDlg->myDestinationY->GetValue(),
543 myDlg->myDestinationZ->GetValue() );
547 myDlg->myCurrentX->SetValue(0);
548 myDlg->myCurrentY->SetValue(0);
549 myDlg->myCurrentZ->SetValue(0);
550 myDlg->myDestDX->SetValue(0);
551 myDlg->myDestDY->SetValue(0);
552 myDlg->myDestDZ->SetValue(0);
555 selectionMgr()->setSelectedObjects(aList,false);
556 aList.Append(myMeshActor->getIO());
557 selectionMgr()->setSelectedObjects(aList,false);
559 SMESHGUI::Modified();
562 catch (const SALOME::SALOME_Exception& S_ex) {
563 SalomeApp_Tools::QtCatchCorbaException(S_ex);
571 //================================================================================
573 * \brief Check selected node id validity
575 //================================================================================
577 bool SMESHGUI_MakeNodeAtPointOp::isValid( QString& msg )
580 if ( myMeshActor && myDlg->myRButNodeToMove->isChecked() )
583 int id = myDlg->myId->text().toInt();
585 if (SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh())
586 ok = aMesh->FindNode( id );
588 msg += tr("INVALID_ID") + "\n";
591 ok = myDlg->myDestinationX->isValid( msg, !myNoPreview ) && ok;
592 ok = myDlg->myDestinationY->isValid( msg, !myNoPreview ) && ok;
593 ok = myDlg->myDestinationZ->isValid( msg, !myNoPreview ) && ok;
598 //================================================================================
600 * \brief SLOT called when selection changed
602 //================================================================================
604 void SMESHGUI_MakeNodeAtPointOp::onSelectionDone()
606 if ( !myDlg->isVisible() || !myDlg->isEnabled() )
612 selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type());
613 if (aList.Extent() != 1)
615 Handle(SALOME_InteractiveObject) anIO = aList.First();
616 SMESH_Actor* aMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
618 if (( myDlg->myIdBtn->isChecked() && myDlg->myIdBtn->isEnabled() ) ||
619 ( !myDlg->myNodeToMoveGrp->isVisible() ))
620 myMeshActor = aMeshActor;
622 if (!aMeshActor) { // coord by geom
623 if ( myDlg->myDestBtn->isChecked() ) {
624 GEOM::GEOM_Object_var geom = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
625 if ( !geom->_is_nil() ) {
626 TopoDS_Vertex aShape;
627 if ( GEOMBase::GetShape(geom, aShape) &&
628 aShape.ShapeType() == TopAbs_VERTEX ) {
629 gp_Pnt P = BRep_Tool::Pnt(aShape);
630 myDlg->myDestinationX->SetValue(P.X());
631 myDlg->myDestinationY->SetValue(P.Y());
632 myDlg->myDestinationZ->SetValue(P.Z());
642 int nbElems = SMESH::GetNameOfSelectedElements(selector(),anIO, aString);
644 if (SMDS_Mesh* aMesh = aMeshActor->GetObject()->GetMesh()) {
645 if (const SMDS_MeshNode* aNode = aMesh->FindNode(aString.toInt())) {
646 if ( myDlg->myDestBtn->isChecked() ) { // set coord
647 myDlg->myDestinationX->SetValue(aNode->X());
648 myDlg->myDestinationY->SetValue(aNode->Y());
649 myDlg->myDestinationZ->SetValue(aNode->Z());
651 else if ( myDlg->myIdBtn->isChecked() &&
652 myDlg->myIdBtn->isEnabled() ) { // set node to move
653 myDlg->myId->setText(aString);
654 myDlg->myCurrentX->SetValue( aNode->X() );
655 myDlg->myCurrentY->SetValue( aNode->Y() );
656 myDlg->myCurrentZ->SetValue( aNode->Z() );
660 double x = myDlg->myCurrentX->GetValue();
661 double y = myDlg->myCurrentY->GetValue();
662 double z = myDlg->myCurrentZ->GetValue();
663 double dx = myDlg->myDestinationX->GetValue() - x;
664 double dy = myDlg->myDestinationY->GetValue() - y;
665 double dz = myDlg->myDestinationZ->GetValue() - z;
666 myDlg->myDestDX->SetValue(dx);
667 myDlg->myDestDY->SetValue(dy);
668 myDlg->myDestDZ->SetValue(dz);
669 myDlg->myDestDX->setReadOnly(false);
670 myDlg->myDestDY->setReadOnly(false);
671 myDlg->myDestDZ->setReadOnly(false);
682 //================================================================================
684 * \brief update preview
686 //================================================================================
688 void SMESHGUI_MakeNodeAtPointOp::redisplayPreview()
694 if ( !myMeshActor && GetConstructorId() == SEARCH_MODE )
697 SMESH::MeshPreviewStruct_var aMeshPreviewStruct;
699 bool moveShown = false;
702 const bool isPreview = myDlg->myPreviewChkBox->isChecked();
703 const bool isMoveNode = myDlg->myRButMoveWithoutNode->isChecked();
705 if ( isValid( msg ) )
708 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
709 if (!aMesh->_is_nil()) {
710 SMESH::SMESH_MeshEditor_var aPreviewer = aMesh->GetMeshEditPreviewer();
711 if (!aPreviewer->_is_nil())
713 SUIT_OverrideCursor aWaitCursor;
715 int anId = myDlg->myId->text().toInt();
717 SMESH::double_array_var aXYZ = aMesh->GetNodeXYZ( anId );
718 if( &aXYZ.in() && aXYZ->length() >= 3 )
727 if ( myUpdateDestination ) {
728 myDlg->myDestinationX->SetValue(x);
729 myDlg->myDestinationY->SetValue(y);
730 myDlg->myDestinationZ->SetValue(z);
731 myDlg->myDestDX->SetValue(dx);
732 myDlg->myDestDY->SetValue(dy);
733 myDlg->myDestDZ->SetValue(dz);
737 if ( myDestCoordChanged ) {
738 dx = myDlg->myDestinationX->GetValue() - x;
739 dy = myDlg->myDestinationY->GetValue() - y;
740 dz = myDlg->myDestinationZ->GetValue() - z;
741 myDlg->myDestDX->SetValue(dx);
742 myDlg->myDestDY->SetValue(dy);
743 myDlg->myDestDZ->SetValue(dz);
746 dx = myDlg->myDestDX->GetValue() + x;
747 dy = myDlg->myDestDY->GetValue() + y;
748 dz = myDlg->myDestDZ->GetValue() + z;
749 myDlg->myDestinationX->SetValue(dx);
750 myDlg->myDestinationY->SetValue(dy);
751 myDlg->myDestinationZ->SetValue(dz);
754 myDlg->myCurrentX->SetValue(x);
755 myDlg->myCurrentY->SetValue(y);
756 myDlg->myCurrentZ->SetValue(z);
757 myDlg->myDestDX->setReadOnly(false);
758 myDlg->myDestDY->setReadOnly(false);
759 myDlg->myDestDZ->setReadOnly(false);
762 myDlg->myCurrentX->SetValue(0);
763 myDlg->myCurrentY->SetValue(0);
764 myDlg->myCurrentZ->SetValue(0);
765 myDlg->myDestDX->SetValue(0);
766 myDlg->myDestDY->SetValue(0);
767 myDlg->myDestDZ->SetValue(0);
768 myDlg->myDestDX->setReadOnly(true);
769 myDlg->myDestDY->setReadOnly(true);
770 myDlg->myDestDZ->setReadOnly(true);
772 if ( isPreview && isMoveNode && anId == 0 )
773 anId = aPreviewer->FindNodeClosestTo(myDlg->myDestinationX->GetValue(),
774 myDlg->myDestinationY->GetValue(),
775 myDlg->myDestinationZ->GetValue());
776 // find id and/or just compute preview
777 aPreviewer->MoveNode(anId,
778 myDlg->myDestinationX->GetValue(),
779 myDlg->myDestinationY->GetValue(),
780 myDlg->myDestinationZ->GetValue());
782 if ( isPreview ) { // fill preview data
783 aMeshPreviewStruct = aPreviewer->GetPreviewData();
784 moveShown = ( anId > 0 );
796 aMeshPreviewStruct = new SMESH::MeshPreviewStruct();
798 aMeshPreviewStruct->nodesXYZ.length(1);
799 aMeshPreviewStruct->nodesXYZ[0].x = myDlg->myDestinationX->GetValue();
800 aMeshPreviewStruct->nodesXYZ[0].y = myDlg->myDestinationY->GetValue();
801 aMeshPreviewStruct->nodesXYZ[0].z = myDlg->myDestinationZ->GetValue();
803 aMeshPreviewStruct->elementTypes.length(1);
804 aMeshPreviewStruct->elementTypes[0].SMDS_ElementType = SMESH::NODE;
805 aMeshPreviewStruct->elementTypes[0].isPoly = false;
806 aMeshPreviewStruct->elementTypes[0].nbNodesInElement = 1;
808 aMeshPreviewStruct->elementConnectivities.length(1);
809 aMeshPreviewStruct->elementConnectivities[0] = 0;
812 mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ));
814 if ( aMeshPreviewStruct.operator->() )
816 mySimulation->SetData(aMeshPreviewStruct._retn());
820 mySimulation->SetVisibility(false);
826 //=================================================================================
828 * \brief SLOT called when the viewer opened
830 //=================================================================================
831 void SMESHGUI_MakeNodeAtPointOp::onOpenView()
833 if ( mySimulation ) {
834 mySimulation->SetVisibility(false);
835 SMESH::SetPointRepresentation(false);
838 mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ));
842 //=================================================================================
844 * \brief SLOT called when the viewer closed
846 //=================================================================================
847 void SMESHGUI_MakeNodeAtPointOp::onCloseView()
853 //================================================================================
855 * \brief SLOT called when the node id is manually changed
857 //================================================================================
859 void SMESHGUI_MakeNodeAtPointOp::onTextChange( const QString& theText )
863 if( SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh() )
865 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
867 aList.Append( anIO );
868 selectionMgr()->setSelectedObjects( aList, false );
870 if( const SMDS_MeshNode* aNode = aMesh->FindNode( theText.toInt() ) )
872 TColStd_MapOfInteger aListInd;
873 aListInd.Add( aNode->GetID() );
874 selector()->AddOrRemoveIndex( anIO, aListInd, false );
875 if( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() ) )
876 aViewWindow->highlight( anIO, true, true );
882 //================================================================================
884 * \brief Activate Node selection
886 //================================================================================
888 void SMESHGUI_MakeNodeAtPointOp::activateSelection()
890 selectionMgr()->clearFilters();
891 SMESH::SetPointRepresentation( true );
892 selectionMgr()->installFilter( myFilter );
893 setSelectionMode( NodeSelection );
896 //================================================================================
900 //================================================================================
902 SMESHGUI_MakeNodeAtPointOp::~SMESHGUI_MakeNodeAtPointOp()
904 if ( myDlg ) delete myDlg;
905 if ( mySimulation ) delete mySimulation;
906 if ( myFilter ) delete myFilter;
909 //================================================================================
911 * \brief Gets dialog of this operation
912 * \retval LightApp_Dialog* - pointer to dialog of this operation
914 //================================================================================
916 LightApp_Dialog* SMESHGUI_MakeNodeAtPointOp::dlg() const