1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_MoveNodesDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_MoveNodesDlg.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_IdValidator.h"
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_VTKUtils.h"
36 #include "SMESHGUI_MeshUtils.h"
38 #include "SMESH_Actor.h"
39 #include "SMDS_Mesh.hxx"
40 #include "SMDS_MeshNode.hxx"
42 #include "LightApp_SelectionMgr.h"
43 #include "SUIT_ResourceMgr.h"
44 #include "SUIT_Desktop.h"
46 #include "SVTK_Selector.h"
47 #include "SVTK_ViewModel.h"
48 #include "SVTK_ViewWindow.h"
49 #include "SALOME_ListIO.hxx"
51 #include "SVTK_ViewWindow.h"
53 #include "utilities.h"
56 #include <TColStd_MapOfInteger.hxx>
60 #include <vtkIdList.h>
61 #include <vtkIntArray.h>
62 #include <vtkCellArray.h>
63 #include <vtkUnsignedCharArray.h>
64 #include <vtkUnstructuredGrid.h>
65 #include <vtkDataSetMapper.h>
66 #include <vtkProperty.h>
69 #include <qgroupbox.h>
71 #include <qlineedit.h>
72 #include <qpushbutton.h>
73 #include <qradiobutton.h>
76 #include <qmessagebox.h>
77 #include <qbuttongroup.h>
80 #include <SALOMEconfig.h>
81 #include CORBA_SERVER_HEADER(SMESH_Mesh)
87 //=================================================================================
88 // name : SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg
90 //=================================================================================
91 SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg (SMESHGUI* theModule,
93 QDialog(SMESH::GetDesktop(theModule),
96 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
97 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
103 setCaption(tr("CAPTION"));
105 QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
107 QFrame* aMainFrame = createMainFrame (this);
108 QFrame* aBtnFrame = createButtonFrame(this);
110 aDlgLay->addWidget(aMainFrame);
111 aDlgLay->addWidget(aBtnFrame);
113 aDlgLay->setStretchFactor(aMainFrame, 1);
115 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
120 //=======================================================================
121 // name : SMESHGUI_MoveNodesDlg::createButtonFrame
122 // Purpose : Create frame containing buttons
123 //=======================================================================
124 QFrame* SMESHGUI_MoveNodesDlg::createButtonFrame (QWidget* theParent)
126 QFrame* aFrame = new QFrame(theParent);
127 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
129 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), aFrame);
130 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
131 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
133 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
135 QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING);
137 aLay->addWidget(myOkBtn);
138 aLay->addWidget(myApplyBtn);
139 aLay->addItem(aSpacer);
140 aLay->addWidget(myCloseBtn);
142 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
143 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
144 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
149 //=======================================================================
150 // name : SMESHGUI_MoveNodesDlg::createMainFrame
151 // Purpose : Create frame containing dialog's input fields
152 //=======================================================================
153 QFrame* SMESHGUI_MoveNodesDlg::createMainFrame (QWidget* theParent)
155 QFrame* aFrame = new QFrame(theParent);
157 QPixmap iconMoveNode (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
158 QPixmap iconSelect (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
160 QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("MESH_NODE"), aFrame);
161 aPixGrp->setExclusive(TRUE);
162 QRadioButton* aRBut = new QRadioButton(aPixGrp);
163 aRBut->setPixmap(iconMoveNode);
164 aRBut->setChecked(TRUE);
166 QGroupBox* anIdGrp = new QGroupBox(1, Qt::Vertical, tr("SMESH_MOVE"), aFrame);
167 new QLabel(tr("NODE_ID"), anIdGrp);
168 (new QPushButton(anIdGrp))->setPixmap(iconSelect);
169 myId = new QLineEdit(anIdGrp);
170 myId->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
172 QGroupBox* aCoordGrp = new QGroupBox(1, Qt::Vertical, tr("SMESH_COORDINATES"), aFrame);
173 new QLabel(tr("SMESH_X"), aCoordGrp);
174 myX = new SMESHGUI_SpinBox(aCoordGrp);
175 new QLabel(tr("SMESH_Y"), aCoordGrp);
176 myY = new SMESHGUI_SpinBox(aCoordGrp);
177 new QLabel(tr("SMESH_Z"), aCoordGrp);
178 myZ = new SMESHGUI_SpinBox(aCoordGrp);
180 myX->RangeStepAndValidator(-999999.999, +999999.999, 25.0, 3);
181 myY->RangeStepAndValidator(-999999.999, +999999.999, 25.0, 3);
182 myZ->RangeStepAndValidator(-999999.999, +999999.999, 25.0, 3);
184 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
185 aLay->addWidget(aPixGrp);
186 aLay->addWidget(anIdGrp);
187 aLay->addWidget(aCoordGrp);
189 // connect signale and slots
190 connect(myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
191 connect(myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
192 connect(myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
193 connect(myId, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
198 //=======================================================================
199 // name : SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg
201 //=======================================================================
202 SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg()
207 //=======================================================================
208 // name : SMESHGUI_MoveNodesDlg::Init
209 // Purpose : Init dialog fields
210 //=======================================================================
211 void SMESHGUI_MoveNodesDlg::Init()
217 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
219 // selection and SMESHGUI
220 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
221 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
222 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
228 mySMESHGUI->DefineDlgPosition(this, x, y);
232 // set selection mode
233 SMESH::SetPointRepresentation(true);
234 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
235 aViewWindow->SetSelectionMode(NodeSelection);
240 //=======================================================================
241 // name : SMESHGUI_MoveNodesDlg::isValid
242 // Purpose : Verify validity of entry information
243 //=======================================================================
244 bool SMESHGUI_MoveNodesDlg::isValid (const bool theMess) const
246 if (myId->text().isEmpty()) {
248 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_WARNING"),
249 tr("NODE_ID_IS_NOT_DEFINED"), QMessageBox::Ok);
255 //=======================================================================
256 // name : SMESHGUI_MoveNodesDlg::reset
257 // Purpose : Reset the dialog state
258 //=======================================================================
259 void SMESHGUI_MoveNodesDlg::reset()
269 //=======================================================================
270 // name : SMESHGUI_MoveNodesDlg::onApply
271 // Purpose : SLOT called when "Apply" button pressed.
272 //=======================================================================
273 bool SMESHGUI_MoveNodesDlg::onApply()
275 if (mySMESHGUI->isActiveStudyLocked())
281 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
282 if (aMesh->_is_nil()) {
283 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
284 tr("SMESHG_NO_MESH"), QMessageBox::Ok);
288 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
289 if (aMeshEditor->_is_nil())
292 int anId = myId->text().toInt();
293 bool aResult = false;
295 aResult = aMeshEditor->MoveNode(anId, myX->GetValue(), myY->GetValue(), myZ->GetValue());
301 aList.Append(myMeshActor->getIO());
302 mySelectionMgr->setSelectedObjects(aList,false);
310 //=======================================================================
311 // name : SMESHGUI_MoveNodesDlg::onOk
312 // Purpose : SLOT called when "Ok" button pressed.
313 //=======================================================================
314 void SMESHGUI_MoveNodesDlg::onOk()
320 //=======================================================================
321 // name : SMESHGUI_MoveNodesDlg::onClose
322 // Purpose : SLOT called when "Close" button pressed. Close dialog
323 //=======================================================================
324 void SMESHGUI_MoveNodesDlg::onClose()
326 //mySelectionMgr->clearSelected();
327 SMESH::SetPointRepresentation(false);
328 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
329 aViewWindow->SetSelectionMode(ActorSelection);
330 disconnect(mySelectionMgr, 0, this, 0);
331 disconnect(mySMESHGUI, 0, this, 0);
333 mySMESHGUI->ResetState();
337 //=======================================================================
338 // name : SMESHGUI_MoveNodesDlg::onTextChange
340 //=======================================================================
341 void SMESHGUI_MoveNodesDlg::onTextChange (const QString& theNewText)
345 myOkBtn->setEnabled(false);
346 myApplyBtn->setEnabled(false);
349 // select entered node
351 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()){
353 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
356 mySelectionMgr->setSelectedObjects(aList,false);
359 if(const SMDS_MeshElement *anElem = aMesh->FindElement(theNewText.toInt())) {
360 TColStd_MapOfInteger aListInd;
361 aListInd.Add(anElem->GetID());
362 mySelector->AddOrRemoveIndex(anIO,aListInd, false);
363 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
364 aViewWindow->highlight(anIO,true,true);
372 //=======================================================================
373 // name : SMESHGUI_MoveNodesDlg::onSelectionDone
374 // Purpose : SLOT called when selection changed
375 //=======================================================================
376 void SMESHGUI_MoveNodesDlg::onSelectionDone()
382 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
384 if (aList.Extent() == 1) {
385 Handle(SALOME_InteractiveObject) anIO = aList.First();
386 myMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
389 if (SMESH::GetNameOfSelectedNodes(mySelector,anIO,aText) == 1) {
390 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) {
391 if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
393 myId->setText(aText);
394 myX->SetValue(aNode->X());
395 myY->SetValue(aNode->Y());
396 myZ->SetValue(aNode->Z());
398 erasePreview(); // avoid overlapping of a selection and a preview
410 //=======================================================================
411 // name : SMESHGUI_MoveNodesDlg::onDeactivate
412 // Purpose : SLOT called when dialog must be deativated
413 //=======================================================================
414 void SMESHGUI_MoveNodesDlg::onDeactivate()
420 //=======================================================================
421 // name : SMESHGUI_MoveNodesDlg::enterEvent
422 // Purpose : Event filter
423 //=======================================================================
424 void SMESHGUI_MoveNodesDlg::enterEvent (QEvent*)
427 mySMESHGUI->EmitSignalDeactivateDialog();
429 // set selection mode
430 SMESH::SetPointRepresentation(true);
431 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
432 aViewWindow->SetSelectionMode(NodeSelection);
440 //=======================================================================
441 // name : SMESHGUI_MoveNodesDlg::closeEvent
443 //=======================================================================
444 void SMESHGUI_MoveNodesDlg::closeEvent (QCloseEvent*)
447 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
448 aViewWindow->Repaint();
451 //=======================================================================
452 // name : SMESHGUI_MoveNodesDlg::hideEvent
453 // Purpose : may be caused by ESC key
454 //=======================================================================
455 void SMESHGUI_MoveNodesDlg::hideEvent (QHideEvent*)
461 //=======================================================================
462 // name : SMESHGUI_MoveNodesDlg::updateButtons
463 // Purpose : Update buttons state
464 //=======================================================================
465 void SMESHGUI_MoveNodesDlg::updateButtons()
467 bool isEnabled = isValid(false);
468 myOkBtn->setEnabled(isEnabled);
469 myApplyBtn->setEnabled(isEnabled);
472 //=======================================================================
473 // name : SMESHGUI_MoveNodesDlg::erasePreview
474 // Purpose : Erase preview
475 //=======================================================================
476 void SMESHGUI_MoveNodesDlg::erasePreview()
478 if (myPreviewActor == 0)
481 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
483 aViewWindow->RemoveActor(myPreviewActor);
484 myPreviewActor->Delete();
487 aViewWindow->Repaint();
490 //=======================================================================
491 // name : SMESHGUI_MoveNodesDlg::redisplayPreview
492 // Purpose : Redisplay preview
493 //=======================================================================
494 void SMESHGUI_MoveNodesDlg::redisplayPreview()
499 if (myPreviewActor != 0)
505 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
507 vtkPoints* aPoints = vtkPoints::New();
508 aPoints->SetNumberOfPoints(1);
509 aPoints->SetPoint(0, myX->GetValue(), myY->GetValue(), myZ->GetValue());
513 vtkIdList *anIdList = vtkIdList::New();
514 anIdList->SetNumberOfIds(1);
516 vtkCellArray *aCells = vtkCellArray::New();
517 aCells->Allocate(2, 0);
519 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
520 aCellTypesArray->SetNumberOfComponents(1);
521 aCellTypesArray->Allocate(1);
523 anIdList->SetId(0, 0);
524 aCells->InsertNextCell(anIdList);
525 aCellTypesArray->InsertNextValue(VTK_VERTEX);
528 vtkIntArray* aCellLocationsArray = vtkIntArray::New();
529 aCellLocationsArray->SetNumberOfComponents(1);
530 aCellLocationsArray->SetNumberOfTuples(1);
532 aCells->InitTraversal();
534 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
536 aGrid->SetPoints(aPoints);
539 aGrid->SetCells(aCellTypesArray,aCellLocationsArray,aCells);
540 aCellLocationsArray->Delete();
541 aCellTypesArray->Delete();
544 // Create and display actor
545 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
546 aMapper->SetInput(aGrid);
549 myPreviewActor = SALOME_Actor::New();
550 myPreviewActor->PickableOff();
551 myPreviewActor->SetMapper(aMapper);
554 vtkProperty* aProp = vtkProperty::New();
555 aProp->SetRepresentationToWireframe();
556 aProp->SetColor(250, 0, 250);
557 aProp->SetPointSize(5);
558 myPreviewActor->SetProperty(aProp);
561 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
563 aViewWindow->AddActor(myPreviewActor);
564 aViewWindow->Repaint();