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>
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 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
102 setCaption(tr("CAPTION"));
104 QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
106 QFrame* aMainFrame = createMainFrame (this);
107 QFrame* aBtnFrame = createButtonFrame(this);
109 aDlgLay->addWidget(aMainFrame);
110 aDlgLay->addWidget(aBtnFrame);
112 aDlgLay->setStretchFactor(aMainFrame, 1);
114 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
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 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
234 aViewWindow->SetSelectionMode(NodeSelection);
239 //=======================================================================
240 // name : SMESHGUI_MoveNodesDlg::isValid
241 // Purpose : Verify validity of entry information
242 //=======================================================================
243 bool SMESHGUI_MoveNodesDlg::isValid (const bool theMess) const
245 if (myId->text().isEmpty()) {
247 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_WARNING"),
248 tr("NODE_ID_IS_NOT_DEFINED"), QMessageBox::Ok);
254 //=======================================================================
255 // name : SMESHGUI_MoveNodesDlg::reset
256 // Purpose : Reset the dialog state
257 //=======================================================================
258 void SMESHGUI_MoveNodesDlg::reset()
268 //=======================================================================
269 // name : SMESHGUI_MoveNodesDlg::onApply
270 // Purpose : SLOT called when "Apply" button pressed.
271 //=======================================================================
272 bool SMESHGUI_MoveNodesDlg::onApply()
274 if (mySMESHGUI->isActiveStudyLocked())
280 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
281 if (aMesh->_is_nil()) {
282 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
283 tr("SMESHG_NO_MESH"), QMessageBox::Ok);
287 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
288 if (aMeshEditor->_is_nil())
291 int anId = myId->text().toInt();
292 bool aResult = false;
294 aResult = aMeshEditor->MoveNode(anId, myX->GetValue(), myY->GetValue(), myZ->GetValue());
300 aList.Append(myMeshActor->getIO());
301 mySelectionMgr->setSelectedObjects(aList,false);
309 //=======================================================================
310 // name : SMESHGUI_MoveNodesDlg::onOk
311 // Purpose : SLOT called when "Ok" button pressed.
312 //=======================================================================
313 void SMESHGUI_MoveNodesDlg::onOk()
319 //=======================================================================
320 // name : SMESHGUI_MoveNodesDlg::onClose
321 // Purpose : SLOT called when "Close" button pressed. Close dialog
322 //=======================================================================
323 void SMESHGUI_MoveNodesDlg::onClose()
325 //mySelectionMgr->clearSelected();
326 SMESH::SetPointRepresentation(false);
327 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
328 aViewWindow->SetSelectionMode(ActorSelection);
329 disconnect(mySelectionMgr, 0, this, 0);
330 disconnect(mySMESHGUI, 0, this, 0);
332 mySMESHGUI->ResetState();
336 //=======================================================================
337 // name : SMESHGUI_MoveNodesDlg::onTextChange
339 //=======================================================================
340 void SMESHGUI_MoveNodesDlg::onTextChange (const QString& theNewText)
344 myOkBtn->setEnabled(false);
345 myApplyBtn->setEnabled(false);
348 // select entered node
350 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()){
352 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
355 mySelectionMgr->setSelectedObjects(aList,false);
358 if(const SMDS_MeshElement *anElem = aMesh->FindElement(theNewText.toInt())) {
359 TColStd_MapOfInteger aListInd;
360 aListInd.Add(anElem->GetID());
361 mySelector->AddOrRemoveIndex(anIO,aListInd, false);
362 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
363 aViewWindow->highlight(anIO,true,true);
371 //=======================================================================
372 // name : SMESHGUI_MoveNodesDlg::onSelectionDone
373 // Purpose : SLOT called when selection changed
374 //=======================================================================
375 void SMESHGUI_MoveNodesDlg::onSelectionDone()
381 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
383 if (aList.Extent() == 1) {
384 Handle(SALOME_InteractiveObject) anIO = aList.First();
385 myMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
388 if (SMESH::GetNameOfSelectedNodes(mySelector,anIO,aText) == 1) {
389 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) {
390 if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
392 myId->setText(aText);
393 myX->SetValue(aNode->X());
394 myY->SetValue(aNode->Y());
395 myZ->SetValue(aNode->Z());
397 erasePreview(); // avoid overlapping of a selection and a preview
409 //=======================================================================
410 // name : SMESHGUI_MoveNodesDlg::onDeactivate
411 // Purpose : SLOT called when dialog must be deativated
412 //=======================================================================
413 void SMESHGUI_MoveNodesDlg::onDeactivate()
419 //=======================================================================
420 // name : SMESHGUI_MoveNodesDlg::enterEvent
421 // Purpose : Event filter
422 //=======================================================================
423 void SMESHGUI_MoveNodesDlg::enterEvent (QEvent*)
426 mySMESHGUI->EmitSignalDeactivateDialog();
428 // set selection mode
429 SMESH::SetPointRepresentation(true);
430 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
431 aViewWindow->SetSelectionMode(NodeSelection);
439 //=======================================================================
440 // name : SMESHGUI_MoveNodesDlg::closeEvent
442 //=======================================================================
443 void SMESHGUI_MoveNodesDlg::closeEvent (QCloseEvent*)
446 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
447 aViewWindow->Repaint();
450 //=======================================================================
451 // name : SMESHGUI_MoveNodesDlg::hideEvent
452 // Purpose : may be caused by ESC key
453 //=======================================================================
454 void SMESHGUI_MoveNodesDlg::hideEvent (QHideEvent*)
460 //=======================================================================
461 // name : SMESHGUI_MoveNodesDlg::updateButtons
462 // Purpose : Update buttons state
463 //=======================================================================
464 void SMESHGUI_MoveNodesDlg::updateButtons()
466 bool isEnabled = isValid(false);
467 myOkBtn->setEnabled(isEnabled);
468 myApplyBtn->setEnabled(isEnabled);
471 //=======================================================================
472 // name : SMESHGUI_MoveNodesDlg::erasePreview
473 // Purpose : Erase preview
474 //=======================================================================
475 void SMESHGUI_MoveNodesDlg::erasePreview()
477 if (myPreviewActor == 0)
480 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
482 aViewWindow->RemoveActor(myPreviewActor);
483 myPreviewActor->Delete();
486 aViewWindow->Repaint();
489 //=======================================================================
490 // name : SMESHGUI_MoveNodesDlg::redisplayPreview
491 // Purpose : Redisplay preview
492 //=======================================================================
493 void SMESHGUI_MoveNodesDlg::redisplayPreview()
498 if (myPreviewActor != 0)
504 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
506 vtkPoints* aPoints = vtkPoints::New();
507 aPoints->SetNumberOfPoints(1);
508 aPoints->SetPoint(0, myX->GetValue(), myY->GetValue(), myZ->GetValue());
512 vtkIdList *anIdList = vtkIdList::New();
513 anIdList->SetNumberOfIds(1);
515 vtkCellArray *aCells = vtkCellArray::New();
516 aCells->Allocate(2, 0);
518 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
519 aCellTypesArray->SetNumberOfComponents(1);
520 aCellTypesArray->Allocate(1);
522 anIdList->SetId(0, 0);
523 aCells->InsertNextCell(anIdList);
524 aCellTypesArray->InsertNextValue(VTK_VERTEX);
527 vtkIntArray* aCellLocationsArray = vtkIntArray::New();
528 aCellLocationsArray->SetNumberOfComponents(1);
529 aCellLocationsArray->SetNumberOfTuples(1);
531 aCells->InitTraversal();
533 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
535 aGrid->SetPoints(aPoints);
538 aGrid->SetCells(aCellTypesArray,aCellLocationsArray,aCells);
539 aCellLocationsArray->Delete();
540 aCellTypesArray->Delete();
543 // Create and display actor
544 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
545 aMapper->SetInput(aGrid);
548 myPreviewActor = SALOME_Actor::New();
549 myPreviewActor->PickableOff();
550 myPreviewActor->SetMapper(aMapper);
553 vtkProperty* aProp = vtkProperty::New();
554 aProp->SetRepresentationToWireframe();
555 aProp->SetColor(250, 0, 250);
556 aProp->SetPointSize(5);
557 myPreviewActor->SetProperty(aProp);
560 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
562 aViewWindow->AddActor(myPreviewActor);
563 aViewWindow->Repaint();