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 "LightApp_Application.h"
44 #include "SUIT_ResourceMgr.h"
45 #include "SUIT_Desktop.h"
46 #include "SUIT_Session.h"
47 #include "SUIT_MessageBox.h"
49 #include "SVTK_Selector.h"
50 #include "SVTK_ViewModel.h"
51 #include "SVTK_ViewWindow.h"
52 #include "SALOME_ListIO.hxx"
54 #include "SVTK_ViewWindow.h"
55 #include "VTKViewer_CellLocationsArray.h"
57 #include "utilities.h"
60 #include <TColStd_MapOfInteger.hxx>
64 #include <vtkIdList.h>
65 #include <vtkCellArray.h>
66 #include <vtkUnsignedCharArray.h>
67 #include <vtkUnstructuredGrid.h>
68 #include <vtkDataSetMapper.h>
69 #include <vtkProperty.h>
72 #include <qgroupbox.h>
74 #include <qlineedit.h>
75 #include <qpushbutton.h>
76 #include <qradiobutton.h>
79 #include <qmessagebox.h>
80 #include <qbuttongroup.h>
83 #include <SALOMEconfig.h>
84 #include CORBA_SERVER_HEADER(SMESH_Mesh)
90 //=================================================================================
91 // name : SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg
93 //=================================================================================
94 SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg (SMESHGUI* theModule,
96 QDialog(SMESH::GetDesktop(theModule),
99 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
100 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
101 mySMESHGUI(theModule)
106 setCaption(tr("CAPTION"));
108 QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
110 QFrame* aMainFrame = createMainFrame (this);
111 QFrame* aBtnFrame = createButtonFrame(this);
113 aDlgLay->addWidget(aMainFrame);
114 aDlgLay->addWidget(aBtnFrame);
116 aDlgLay->setStretchFactor(aMainFrame, 1);
118 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
120 myHelpFileName = "/files/displacing_nodes.htm";
125 //=======================================================================
126 // name : SMESHGUI_MoveNodesDlg::createButtonFrame
127 // Purpose : Create frame containing buttons
128 //=======================================================================
129 QFrame* SMESHGUI_MoveNodesDlg::createButtonFrame (QWidget* theParent)
131 QFrame* aFrame = new QFrame(theParent);
132 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
134 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), aFrame);
135 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
136 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
137 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
139 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
141 QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING);
143 aLay->addWidget(myOkBtn);
144 aLay->addWidget(myApplyBtn);
145 aLay->addItem(aSpacer);
146 aLay->addWidget(myCloseBtn);
147 aLay->addWidget(myHelpBtn);
149 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
150 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
151 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
152 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
157 //=======================================================================
158 // name : SMESHGUI_MoveNodesDlg::createMainFrame
159 // Purpose : Create frame containing dialog's input fields
160 //=======================================================================
161 QFrame* SMESHGUI_MoveNodesDlg::createMainFrame (QWidget* theParent)
163 QFrame* aFrame = new QFrame(theParent);
165 QPixmap iconMoveNode (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
166 QPixmap iconSelect (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
168 QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("MESH_NODE"), aFrame);
169 aPixGrp->setExclusive(TRUE);
170 QRadioButton* aRBut = new QRadioButton(aPixGrp);
171 aRBut->setPixmap(iconMoveNode);
172 aRBut->setChecked(TRUE);
174 QGroupBox* anIdGrp = new QGroupBox(1, Qt::Vertical, tr("SMESH_MOVE"), aFrame);
175 new QLabel(tr("NODE_ID"), anIdGrp);
176 (new QPushButton(anIdGrp))->setPixmap(iconSelect);
177 myId = new QLineEdit(anIdGrp);
178 myId->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
180 QGroupBox* aCoordGrp = new QGroupBox(1, Qt::Vertical, tr("SMESH_COORDINATES"), aFrame);
181 new QLabel(tr("SMESH_X"), aCoordGrp);
182 myX = new SMESHGUI_SpinBox(aCoordGrp);
183 new QLabel(tr("SMESH_Y"), aCoordGrp);
184 myY = new SMESHGUI_SpinBox(aCoordGrp);
185 new QLabel(tr("SMESH_Z"), aCoordGrp);
186 myZ = new SMESHGUI_SpinBox(aCoordGrp);
188 myX->RangeStepAndValidator(-999999.999, +999999.999, 25.0, 3);
189 myY->RangeStepAndValidator(-999999.999, +999999.999, 25.0, 3);
190 myZ->RangeStepAndValidator(-999999.999, +999999.999, 25.0, 3);
192 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
193 aLay->addWidget(aPixGrp);
194 aLay->addWidget(anIdGrp);
195 aLay->addWidget(aCoordGrp);
197 // connect signale and slots
198 connect(myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
199 connect(myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
200 connect(myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
201 connect(myId, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
206 //=======================================================================
207 // name : SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg
209 //=======================================================================
210 SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg()
215 //=======================================================================
216 // name : SMESHGUI_MoveNodesDlg::Init
217 // Purpose : Init dialog fields
218 //=======================================================================
219 void SMESHGUI_MoveNodesDlg::Init()
225 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
227 // selection and SMESHGUI
228 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
229 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
230 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
237 // set selection mode
238 SMESH::SetPointRepresentation(true);
239 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
240 aViewWindow->SetSelectionMode(NodeSelection);
245 //=======================================================================
246 // name : SMESHGUI_MoveNodesDlg::isValid
247 // Purpose : Verify validity of entry information
248 //=======================================================================
249 bool SMESHGUI_MoveNodesDlg::isValid (const bool theMess) const
251 if (myId->text().isEmpty()) {
253 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_WARNING"),
254 tr("NODE_ID_IS_NOT_DEFINED"), QMessageBox::Ok);
260 //=======================================================================
261 // name : SMESHGUI_MoveNodesDlg::reset
262 // Purpose : Reset the dialog state
263 //=======================================================================
264 void SMESHGUI_MoveNodesDlg::reset()
274 //=======================================================================
275 // name : SMESHGUI_MoveNodesDlg::onApply
276 // Purpose : SLOT called when "Apply" button pressed.
277 //=======================================================================
278 bool SMESHGUI_MoveNodesDlg::onApply()
280 if (mySMESHGUI->isActiveStudyLocked())
286 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
287 if (aMesh->_is_nil()) {
288 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
289 tr("SMESHG_NO_MESH"), QMessageBox::Ok);
293 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
294 if (aMeshEditor->_is_nil())
297 int anId = myId->text().toInt();
298 bool aResult = false;
300 aResult = aMeshEditor->MoveNode(anId, myX->GetValue(), myY->GetValue(), myZ->GetValue());
306 aList.Append(myMeshActor->getIO());
307 mySelectionMgr->setSelectedObjects(aList,false);
315 //=======================================================================
316 // name : SMESHGUI_MoveNodesDlg::onOk
317 // Purpose : SLOT called when "Ok" button pressed.
318 //=======================================================================
319 void SMESHGUI_MoveNodesDlg::onOk()
325 //=======================================================================
326 // name : SMESHGUI_MoveNodesDlg::onClose
327 // Purpose : SLOT called when "Close" button pressed. Close dialog
328 //=======================================================================
329 void SMESHGUI_MoveNodesDlg::onClose()
331 //mySelectionMgr->clearSelected();
332 SMESH::SetPointRepresentation(false);
333 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
334 aViewWindow->SetSelectionMode(ActorSelection);
335 disconnect(mySelectionMgr, 0, this, 0);
336 disconnect(mySMESHGUI, 0, this, 0);
338 mySMESHGUI->ResetState();
342 //=================================================================================
343 // function : onHelp()
345 //=================================================================================
346 void SMESHGUI_MoveNodesDlg::onHelp()
348 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
350 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
352 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
353 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
354 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
355 QObject::tr("BUT_OK"));
359 //=======================================================================
360 // name : SMESHGUI_MoveNodesDlg::onTextChange
362 //=======================================================================
363 void SMESHGUI_MoveNodesDlg::onTextChange (const QString& theNewText)
367 myOkBtn->setEnabled(false);
368 myApplyBtn->setEnabled(false);
371 // select entered node
373 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()){
375 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
378 mySelectionMgr->setSelectedObjects(aList,false);
381 if(const SMDS_MeshElement *anElem = aMesh->FindElement(theNewText.toInt())) {
382 TColStd_MapOfInteger aListInd;
383 aListInd.Add(anElem->GetID());
384 mySelector->AddOrRemoveIndex(anIO,aListInd, false);
385 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
386 aViewWindow->highlight(anIO,true,true);
394 //=======================================================================
395 // name : SMESHGUI_MoveNodesDlg::onSelectionDone
396 // Purpose : SLOT called when selection changed
397 //=======================================================================
398 void SMESHGUI_MoveNodesDlg::onSelectionDone()
404 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
406 if (aList.Extent() == 1) {
407 Handle(SALOME_InteractiveObject) anIO = aList.First();
408 myMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
411 if (SMESH::GetNameOfSelectedNodes(mySelector,anIO,aText) == 1) {
412 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) {
413 if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
415 myId->setText(aText);
416 myX->SetValue(aNode->X());
417 myY->SetValue(aNode->Y());
418 myZ->SetValue(aNode->Z());
420 erasePreview(); // avoid overlapping of a selection and a preview
432 //=======================================================================
433 // name : SMESHGUI_MoveNodesDlg::onDeactivate
434 // Purpose : SLOT called when dialog must be deativated
435 //=======================================================================
436 void SMESHGUI_MoveNodesDlg::onDeactivate()
442 //=======================================================================
443 // name : SMESHGUI_MoveNodesDlg::enterEvent
444 // Purpose : Event filter
445 //=======================================================================
446 void SMESHGUI_MoveNodesDlg::enterEvent (QEvent*)
449 mySMESHGUI->EmitSignalDeactivateDialog();
451 // set selection mode
452 SMESH::SetPointRepresentation(true);
453 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
454 aViewWindow->SetSelectionMode(NodeSelection);
462 //=======================================================================
463 // name : SMESHGUI_MoveNodesDlg::closeEvent
465 //=======================================================================
466 void SMESHGUI_MoveNodesDlg::closeEvent (QCloseEvent*)
469 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
470 aViewWindow->Repaint();
473 //=======================================================================
474 // name : SMESHGUI_MoveNodesDlg::hideEvent
475 // Purpose : may be caused by ESC key
476 //=======================================================================
477 void SMESHGUI_MoveNodesDlg::hideEvent (QHideEvent*)
483 //=======================================================================
484 // name : SMESHGUI_MoveNodesDlg::updateButtons
485 // Purpose : Update buttons state
486 //=======================================================================
487 void SMESHGUI_MoveNodesDlg::updateButtons()
489 bool isEnabled = isValid(false);
490 myOkBtn->setEnabled(isEnabled);
491 myApplyBtn->setEnabled(isEnabled);
494 //=======================================================================
495 // name : SMESHGUI_MoveNodesDlg::erasePreview
496 // Purpose : Erase preview
497 //=======================================================================
498 void SMESHGUI_MoveNodesDlg::erasePreview()
500 if (myPreviewActor == 0)
503 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
505 aViewWindow->RemoveActor(myPreviewActor);
506 myPreviewActor->Delete();
509 aViewWindow->Repaint();
512 //=======================================================================
513 // name : SMESHGUI_MoveNodesDlg::redisplayPreview
514 // Purpose : Redisplay preview
515 //=======================================================================
516 void SMESHGUI_MoveNodesDlg::redisplayPreview()
521 if (myPreviewActor != 0)
527 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
529 vtkPoints* aPoints = vtkPoints::New();
530 aPoints->SetNumberOfPoints(1);
531 aPoints->SetPoint(0, myX->GetValue(), myY->GetValue(), myZ->GetValue());
535 vtkIdList *anIdList = vtkIdList::New();
536 anIdList->SetNumberOfIds(1);
538 vtkCellArray *aCells = vtkCellArray::New();
539 aCells->Allocate(2, 0);
541 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
542 aCellTypesArray->SetNumberOfComponents(1);
543 aCellTypesArray->Allocate(1);
545 anIdList->SetId(0, 0);
546 aCells->InsertNextCell(anIdList);
547 aCellTypesArray->InsertNextValue(VTK_VERTEX);
550 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
551 aCellLocationsArray->SetNumberOfComponents(1);
552 aCellLocationsArray->SetNumberOfTuples(1);
554 aCells->InitTraversal();
556 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
558 aGrid->SetPoints(aPoints);
561 aGrid->SetCells(aCellTypesArray,aCellLocationsArray,aCells);
562 aCellLocationsArray->Delete();
563 aCellTypesArray->Delete();
566 // Create and display actor
567 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
568 aMapper->SetInput(aGrid);
571 myPreviewActor = SALOME_Actor::New();
572 myPreviewActor->PickableOff();
573 myPreviewActor->SetMapper(aMapper);
576 vtkProperty* aProp = vtkProperty::New();
577 aProp->SetRepresentationToWireframe();
578 aProp->SetColor(250, 0, 250);
579 aProp->SetPointSize(5);
580 myPreviewActor->SetProperty(aProp);
583 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
585 aViewWindow->AddActor(myPreviewActor);
586 aViewWindow->Repaint();