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 "SalomeApp_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>
68 #include <qgroupbox.h>
70 #include <qlineedit.h>
71 #include <qpushbutton.h>
72 #include <qradiobutton.h>
75 #include <qmessagebox.h>
76 #include <qbuttongroup.h>
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_Mesh)
86 //=================================================================================
87 // name : SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg
89 //=================================================================================
90 SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg (SMESHGUI* theModule,
92 QDialog(SMESH::GetDesktop(theModule),
95 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
96 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
97 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
98 myViewWindow(SMESH::GetViewWindow(theModule)),
104 setCaption(tr("CAPTION"));
106 QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
108 QFrame* aMainFrame = createMainFrame (this);
109 QFrame* aBtnFrame = createButtonFrame(this);
111 aDlgLay->addWidget(aMainFrame);
112 aDlgLay->addWidget(aBtnFrame);
114 aDlgLay->setStretchFactor(aMainFrame, 1);
119 //=======================================================================
120 // name : SMESHGUI_MoveNodesDlg::createButtonFrame
121 // Purpose : Create frame containing buttons
122 //=======================================================================
123 QFrame* SMESHGUI_MoveNodesDlg::createButtonFrame (QWidget* theParent)
125 QFrame* aFrame = new QFrame(theParent);
126 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
128 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), aFrame);
129 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
130 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
132 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
134 QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING);
136 aLay->addWidget(myOkBtn);
137 aLay->addWidget(myApplyBtn);
138 aLay->addItem(aSpacer);
139 aLay->addWidget(myCloseBtn);
141 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
142 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
143 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
148 //=======================================================================
149 // name : SMESHGUI_MoveNodesDlg::createMainFrame
150 // Purpose : Create frame containing dialog's input fields
151 //=======================================================================
152 QFrame* SMESHGUI_MoveNodesDlg::createMainFrame (QWidget* theParent)
154 QFrame* aFrame = new QFrame(theParent);
156 QPixmap iconMoveNode (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
157 QPixmap iconSelect (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
159 QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("MESH_NODE"), aFrame);
160 aPixGrp->setExclusive(TRUE);
161 QRadioButton* aRBut = new QRadioButton(aPixGrp);
162 aRBut->setPixmap(iconMoveNode);
163 aRBut->setChecked(TRUE);
165 QGroupBox* anIdGrp = new QGroupBox(1, Qt::Vertical, tr("SMESH_MOVE"), aFrame);
166 new QLabel(tr("NODE_ID"), anIdGrp);
167 (new QPushButton(anIdGrp))->setPixmap(iconSelect);
168 myId = new QLineEdit(anIdGrp);
169 myId->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
171 QGroupBox* aCoordGrp = new QGroupBox(1, Qt::Vertical, tr("SMESH_COORDINATES"), aFrame);
172 new QLabel(tr("SMESH_X"), aCoordGrp);
173 myX = new SMESHGUI_SpinBox(aCoordGrp);
174 new QLabel(tr("SMESH_Y"), aCoordGrp);
175 myY = new SMESHGUI_SpinBox(aCoordGrp);
176 new QLabel(tr("SMESH_Z"), aCoordGrp);
177 myZ = new SMESHGUI_SpinBox(aCoordGrp);
179 myX->RangeStepAndValidator(-999999.999, +999999.999, 25.0, 3);
180 myY->RangeStepAndValidator(-999999.999, +999999.999, 25.0, 3);
181 myZ->RangeStepAndValidator(-999999.999, +999999.999, 25.0, 3);
183 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
184 aLay->addWidget(aPixGrp);
185 aLay->addWidget(anIdGrp);
186 aLay->addWidget(aCoordGrp);
188 // connect signale and slots
189 connect(myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
190 connect(myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
191 connect(myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
192 connect(myId, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
197 //=======================================================================
198 // name : SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg
200 //=======================================================================
201 SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg()
206 //=======================================================================
207 // name : SMESHGUI_MoveNodesDlg::Init
208 // Purpose : Init dialog fields
209 //=======================================================================
210 void SMESHGUI_MoveNodesDlg::Init()
216 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
218 // selection and SMESHGUI
219 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
220 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
221 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
227 mySMESHGUI->DefineDlgPosition(this, x, y);
231 // set selection mode
232 SMESH::SetPointRepresentation(true);
233 myViewWindow->SetSelectionMode(NodeSelection);
238 //=======================================================================
239 // name : SMESHGUI_MoveNodesDlg::isValid
240 // Purpose : Verify validity of entry information
241 //=======================================================================
242 bool SMESHGUI_MoveNodesDlg::isValid (const bool theMess) const
244 if (myId->text().isEmpty()) {
246 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_WARNING"),
247 tr("NODE_ID_IS_NOT_DEFINED"), QMessageBox::Ok);
253 //=======================================================================
254 // name : SMESHGUI_MoveNodesDlg::reset
255 // Purpose : Reset the dialog state
256 //=======================================================================
257 void SMESHGUI_MoveNodesDlg::reset()
267 //=======================================================================
268 // name : SMESHGUI_MoveNodesDlg::onApply
269 // Purpose : SLOT called when "Apply" button pressed.
270 //=======================================================================
271 bool SMESHGUI_MoveNodesDlg::onApply()
273 if (mySMESHGUI->isActiveStudyLocked())
279 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
280 if (aMesh->_is_nil()) {
281 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
282 tr("SMESHG_NO_MESH"), QMessageBox::Ok);
286 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
287 if (aMeshEditor->_is_nil())
290 int anId = myId->text().toInt();
291 bool aResult = false;
293 aResult = aMeshEditor->MoveNode(anId, myX->GetValue(), myY->GetValue(), myZ->GetValue());
299 aList.Append(myMeshActor->getIO());
300 mySelectionMgr->setSelectedObjects(aList,false);
308 //=======================================================================
309 // name : SMESHGUI_MoveNodesDlg::onOk
310 // Purpose : SLOT called when "Ok" button pressed.
311 //=======================================================================
312 void SMESHGUI_MoveNodesDlg::onOk()
318 //=======================================================================
319 // name : SMESHGUI_MoveNodesDlg::onClose
320 // Purpose : SLOT called when "Close" button pressed. Close dialog
321 //=======================================================================
322 void SMESHGUI_MoveNodesDlg::onClose()
324 mySelectionMgr->clearSelected();
325 SMESH::SetPointRepresentation(false);
326 myViewWindow->SetSelectionMode(ActorSelection);
327 disconnect(mySelectionMgr, 0, this, 0);
328 disconnect(mySMESHGUI, 0, this, 0);
329 mySMESHGUI->ResetState();
333 //=======================================================================
334 // name : SMESHGUI_MoveNodesDlg::onTextChange
336 //=======================================================================
337 void SMESHGUI_MoveNodesDlg::onTextChange (const QString& theNewText)
341 myOkBtn->setEnabled(false);
342 myApplyBtn->setEnabled(false);
345 // select entered node
347 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()){
349 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
352 mySelectionMgr->setSelectedObjects(aList,false);
355 if(const SMDS_MeshElement *anElem = aMesh->FindElement(theNewText.toInt())) {
356 TColStd_MapOfInteger aListInd;
357 aListInd.Add(anElem->GetID());
358 mySelector->AddOrRemoveIndex(anIO,aListInd, false);
359 myViewWindow->highlight(anIO,true,true);
367 //=======================================================================
368 // name : SMESHGUI_MoveNodesDlg::onSelectionDone
369 // Purpose : SLOT called when selection changed
370 //=======================================================================
371 void SMESHGUI_MoveNodesDlg::onSelectionDone()
377 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
379 if (aList.Extent() == 1) {
380 Handle(SALOME_InteractiveObject) anIO = aList.First();
381 myMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
384 if (SMESH::GetNameOfSelectedNodes(mySelector,anIO,aText) == 1) {
385 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) {
386 if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
388 myId->setText(aText);
389 myX->SetValue(aNode->X());
390 myY->SetValue(aNode->Y());
391 myZ->SetValue(aNode->Z());
393 erasePreview(); // avoid overlapping of a selection and a preview
405 //=======================================================================
406 // name : SMESHGUI_MoveNodesDlg::onDeactivate
407 // Purpose : SLOT called when dialog must be deativated
408 //=======================================================================
409 void SMESHGUI_MoveNodesDlg::onDeactivate()
415 //=======================================================================
416 // name : SMESHGUI_MoveNodesDlg::enterEvent
417 // Purpose : Event filter
418 //=======================================================================
419 void SMESHGUI_MoveNodesDlg::enterEvent (QEvent*)
422 mySMESHGUI->EmitSignalDeactivateDialog();
424 // set selection mode
425 SMESH::SetPointRepresentation(true);
426 myViewWindow->SetSelectionMode(NodeSelection);
434 //=======================================================================
435 // name : SMESHGUI_MoveNodesDlg::closeEvent
437 //=======================================================================
438 void SMESHGUI_MoveNodesDlg::closeEvent (QCloseEvent*)
441 myViewWindow->Repaint();
444 //=======================================================================
445 // name : SMESHGUI_MoveNodesDlg::hideEvent
446 // Purpose : may be caused by ESC key
447 //=======================================================================
448 void SMESHGUI_MoveNodesDlg::hideEvent (QHideEvent*)
454 //=======================================================================
455 // name : SMESHGUI_MoveNodesDlg::updateButtons
456 // Purpose : Update buttons state
457 //=======================================================================
458 void SMESHGUI_MoveNodesDlg::updateButtons()
460 bool isEnabled = isValid(false);
461 myOkBtn->setEnabled(isEnabled);
462 myApplyBtn->setEnabled(isEnabled);
465 //=======================================================================
466 // name : SMESHGUI_MoveNodesDlg::erasePreview
467 // Purpose : Erase preview
468 //=======================================================================
469 void SMESHGUI_MoveNodesDlg::erasePreview()
471 if (myPreviewActor == 0)
474 myViewWindow->RemoveActor(myPreviewActor);
475 myPreviewActor->Delete();
477 myViewWindow->Repaint();
480 //=======================================================================
481 // name : SMESHGUI_MoveNodesDlg::redisplayPreview
482 // Purpose : Redisplay preview
483 //=======================================================================
484 void SMESHGUI_MoveNodesDlg::redisplayPreview()
489 if (myPreviewActor != 0)
495 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
497 vtkPoints* aPoints = vtkPoints::New();
498 aPoints->SetNumberOfPoints(1);
499 aPoints->SetPoint(0, myX->GetValue(), myY->GetValue(), myZ->GetValue());
503 vtkIdList *anIdList = vtkIdList::New();
504 anIdList->SetNumberOfIds(1);
506 vtkCellArray *aCells = vtkCellArray::New();
507 aCells->Allocate(2, 0);
509 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
510 aCellTypesArray->SetNumberOfComponents(1);
511 aCellTypesArray->Allocate(1);
513 anIdList->SetId(0, 0);
514 aCells->InsertNextCell(anIdList);
515 aCellTypesArray->InsertNextValue(VTK_VERTEX);
518 vtkIntArray* aCellLocationsArray = vtkIntArray::New();
519 aCellLocationsArray->SetNumberOfComponents(1);
520 aCellLocationsArray->SetNumberOfTuples(1);
522 aCells->InitTraversal();
524 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
526 aGrid->SetPoints(aPoints);
529 aGrid->SetCells(aCellTypesArray,aCellLocationsArray,aCells);
530 aCellLocationsArray->Delete();
531 aCellTypesArray->Delete();
534 // Create and display actor
535 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
536 aMapper->SetInput(aGrid);
539 myPreviewActor = SALOME_Actor::New();
540 myPreviewActor->PickableOff();
541 myPreviewActor->SetMapper(aMapper);
544 vtkProperty* aProp = vtkProperty::New();
545 aProp->SetRepresentationToWireframe();
546 aProp->SetColor(250, 0, 250);
547 aProp->SetPointSize(5);
548 myPreviewActor->SetProperty(aProp);
551 myViewWindow->AddActor(myPreviewActor);
552 myViewWindow->Repaint();