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()));
229 // set selection mode
230 SMESH::SetPointRepresentation(true);
231 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
232 aViewWindow->SetSelectionMode(NodeSelection);
237 //=======================================================================
238 // name : SMESHGUI_MoveNodesDlg::isValid
239 // Purpose : Verify validity of entry information
240 //=======================================================================
241 bool SMESHGUI_MoveNodesDlg::isValid (const bool theMess) const
243 if (myId->text().isEmpty()) {
245 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_WARNING"),
246 tr("NODE_ID_IS_NOT_DEFINED"), QMessageBox::Ok);
252 //=======================================================================
253 // name : SMESHGUI_MoveNodesDlg::reset
254 // Purpose : Reset the dialog state
255 //=======================================================================
256 void SMESHGUI_MoveNodesDlg::reset()
266 //=======================================================================
267 // name : SMESHGUI_MoveNodesDlg::onApply
268 // Purpose : SLOT called when "Apply" button pressed.
269 //=======================================================================
270 bool SMESHGUI_MoveNodesDlg::onApply()
272 if (mySMESHGUI->isActiveStudyLocked())
278 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
279 if (aMesh->_is_nil()) {
280 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
281 tr("SMESHG_NO_MESH"), QMessageBox::Ok);
285 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
286 if (aMeshEditor->_is_nil())
289 int anId = myId->text().toInt();
290 bool aResult = false;
292 aResult = aMeshEditor->MoveNode(anId, myX->GetValue(), myY->GetValue(), myZ->GetValue());
298 aList.Append(myMeshActor->getIO());
299 mySelectionMgr->setSelectedObjects(aList,false);
307 //=======================================================================
308 // name : SMESHGUI_MoveNodesDlg::onOk
309 // Purpose : SLOT called when "Ok" button pressed.
310 //=======================================================================
311 void SMESHGUI_MoveNodesDlg::onOk()
317 //=======================================================================
318 // name : SMESHGUI_MoveNodesDlg::onClose
319 // Purpose : SLOT called when "Close" button pressed. Close dialog
320 //=======================================================================
321 void SMESHGUI_MoveNodesDlg::onClose()
323 //mySelectionMgr->clearSelected();
324 SMESH::SetPointRepresentation(false);
325 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
326 aViewWindow->SetSelectionMode(ActorSelection);
327 disconnect(mySelectionMgr, 0, this, 0);
328 disconnect(mySMESHGUI, 0, this, 0);
330 mySMESHGUI->ResetState();
334 //=======================================================================
335 // name : SMESHGUI_MoveNodesDlg::onTextChange
337 //=======================================================================
338 void SMESHGUI_MoveNodesDlg::onTextChange (const QString& theNewText)
342 myOkBtn->setEnabled(false);
343 myApplyBtn->setEnabled(false);
346 // select entered node
348 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()){
350 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
353 mySelectionMgr->setSelectedObjects(aList,false);
356 if(const SMDS_MeshElement *anElem = aMesh->FindElement(theNewText.toInt())) {
357 TColStd_MapOfInteger aListInd;
358 aListInd.Add(anElem->GetID());
359 mySelector->AddOrRemoveIndex(anIO,aListInd, false);
360 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
361 aViewWindow->highlight(anIO,true,true);
369 //=======================================================================
370 // name : SMESHGUI_MoveNodesDlg::onSelectionDone
371 // Purpose : SLOT called when selection changed
372 //=======================================================================
373 void SMESHGUI_MoveNodesDlg::onSelectionDone()
379 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
381 if (aList.Extent() == 1) {
382 Handle(SALOME_InteractiveObject) anIO = aList.First();
383 myMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
386 if (SMESH::GetNameOfSelectedNodes(mySelector,anIO,aText) == 1) {
387 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) {
388 if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
390 myId->setText(aText);
391 myX->SetValue(aNode->X());
392 myY->SetValue(aNode->Y());
393 myZ->SetValue(aNode->Z());
395 erasePreview(); // avoid overlapping of a selection and a preview
407 //=======================================================================
408 // name : SMESHGUI_MoveNodesDlg::onDeactivate
409 // Purpose : SLOT called when dialog must be deativated
410 //=======================================================================
411 void SMESHGUI_MoveNodesDlg::onDeactivate()
417 //=======================================================================
418 // name : SMESHGUI_MoveNodesDlg::enterEvent
419 // Purpose : Event filter
420 //=======================================================================
421 void SMESHGUI_MoveNodesDlg::enterEvent (QEvent*)
424 mySMESHGUI->EmitSignalDeactivateDialog();
426 // set selection mode
427 SMESH::SetPointRepresentation(true);
428 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
429 aViewWindow->SetSelectionMode(NodeSelection);
437 //=======================================================================
438 // name : SMESHGUI_MoveNodesDlg::closeEvent
440 //=======================================================================
441 void SMESHGUI_MoveNodesDlg::closeEvent (QCloseEvent*)
444 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
445 aViewWindow->Repaint();
448 //=======================================================================
449 // name : SMESHGUI_MoveNodesDlg::hideEvent
450 // Purpose : may be caused by ESC key
451 //=======================================================================
452 void SMESHGUI_MoveNodesDlg::hideEvent (QHideEvent*)
458 //=======================================================================
459 // name : SMESHGUI_MoveNodesDlg::updateButtons
460 // Purpose : Update buttons state
461 //=======================================================================
462 void SMESHGUI_MoveNodesDlg::updateButtons()
464 bool isEnabled = isValid(false);
465 myOkBtn->setEnabled(isEnabled);
466 myApplyBtn->setEnabled(isEnabled);
469 //=======================================================================
470 // name : SMESHGUI_MoveNodesDlg::erasePreview
471 // Purpose : Erase preview
472 //=======================================================================
473 void SMESHGUI_MoveNodesDlg::erasePreview()
475 if (myPreviewActor == 0)
478 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
480 aViewWindow->RemoveActor(myPreviewActor);
481 myPreviewActor->Delete();
484 aViewWindow->Repaint();
487 //=======================================================================
488 // name : SMESHGUI_MoveNodesDlg::redisplayPreview
489 // Purpose : Redisplay preview
490 //=======================================================================
491 void SMESHGUI_MoveNodesDlg::redisplayPreview()
496 if (myPreviewActor != 0)
502 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
504 vtkPoints* aPoints = vtkPoints::New();
505 aPoints->SetNumberOfPoints(1);
506 aPoints->SetPoint(0, myX->GetValue(), myY->GetValue(), myZ->GetValue());
510 vtkIdList *anIdList = vtkIdList::New();
511 anIdList->SetNumberOfIds(1);
513 vtkCellArray *aCells = vtkCellArray::New();
514 aCells->Allocate(2, 0);
516 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
517 aCellTypesArray->SetNumberOfComponents(1);
518 aCellTypesArray->Allocate(1);
520 anIdList->SetId(0, 0);
521 aCells->InsertNextCell(anIdList);
522 aCellTypesArray->InsertNextValue(VTK_VERTEX);
525 vtkIntArray* aCellLocationsArray = vtkIntArray::New();
526 aCellLocationsArray->SetNumberOfComponents(1);
527 aCellLocationsArray->SetNumberOfTuples(1);
529 aCells->InitTraversal();
531 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
533 aGrid->SetPoints(aPoints);
536 aGrid->SetCells(aCellTypesArray,aCellLocationsArray,aCells);
537 aCellLocationsArray->Delete();
538 aCellTypesArray->Delete();
541 // Create and display actor
542 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
543 aMapper->SetInput(aGrid);
546 myPreviewActor = SALOME_Actor::New();
547 myPreviewActor->PickableOff();
548 myPreviewActor->SetMapper(aMapper);
551 vtkProperty* aProp = vtkProperty::New();
552 aProp->SetRepresentationToWireframe();
553 aProp->SetColor(250, 0, 250);
554 aProp->SetPointSize(5);
555 myPreviewActor->SetProperty(aProp);
558 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
560 aViewWindow->AddActor(myPreviewActor);
561 aViewWindow->Repaint();