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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_MoveNodesDlg.cxx
23 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
27 #include "SMESHGUI_MoveNodesDlg.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_IdValidator.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
36 #include <SMESH_Actor.h>
37 #include <SMDS_Mesh.hxx>
39 // SALOME GUI includes
40 #include <LightApp_SelectionMgr.h>
41 #include <LightApp_Application.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
47 #include <SVTK_ViewModel.h>
48 #include <SVTK_ViewWindow.h>
49 #include <SALOME_ListIO.hxx>
51 #include <VTKViewer_CellLocationsArray.h>
54 #include <TColStd_MapOfInteger.hxx>
57 #include <vtkIdList.h>
58 #include <vtkCellArray.h>
59 #include <vtkUnsignedCharArray.h>
60 #include <vtkUnstructuredGrid.h>
61 #include <vtkDataSetMapper.h>
62 #include <vtkProperty.h>
68 #include <QPushButton>
69 #include <QRadioButton>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
73 #include <QButtonGroup>
76 #include <SALOMEconfig.h>
77 #include CORBA_SERVER_HEADER(SMESH_Mesh)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
83 //=================================================================================
84 // name : SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg
86 //=================================================================================
87 SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg(SMESHGUI* theModule):
88 QDialog(SMESH::GetDesktop(theModule)),
89 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
96 setWindowTitle(tr("CAPTION"));
98 QVBoxLayout* aDlgLay = new QVBoxLayout(this);
99 aDlgLay->setSpacing(SPACING);
100 aDlgLay->setMargin(MARGIN);
102 QWidget* aMainFrame = createMainFrame (this);
103 QWidget* aBtnFrame = createButtonFrame(this);
105 aDlgLay->addWidget(aMainFrame);
106 aDlgLay->addWidget(aBtnFrame);
108 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
110 myHelpFileName = "moving_nodes_page.html";
115 //=======================================================================
116 // name : SMESHGUI_MoveNodesDlg::createButtonFrame
117 // Purpose : Create frame containing buttons
118 //=======================================================================
119 QWidget* SMESHGUI_MoveNodesDlg::createButtonFrame (QWidget* theParent)
121 QFrame* aFrame = new QFrame(theParent);
122 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
124 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), aFrame);
125 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
126 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
127 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
129 QHBoxLayout* aLay = new QHBoxLayout(aFrame);
130 aLay->setSpacing(SPACING);
131 aLay->setMargin(MARGIN);
133 aLay->addWidget(myOkBtn);
134 aLay->addSpacing(10);
135 aLay->addWidget(myApplyBtn);
136 aLay->addSpacing(10);
138 aLay->addWidget(myCloseBtn);
139 aLay->addWidget(myHelpBtn);
141 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
142 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
143 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
144 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
149 //=======================================================================
150 // name : SMESHGUI_MoveNodesDlg::createMainFrame
151 // Purpose : Create frame containing dialog's input fields
152 //=======================================================================
153 QWidget* SMESHGUI_MoveNodesDlg::createMainFrame (QWidget* theParent)
155 QWidget* aFrame = new QWidget(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 //------------------------------------------------------------
161 QGroupBox* aPixGrp = new QGroupBox(tr("MESH_NODE"), aFrame);
162 QButtonGroup* aBtnGrp = new QButtonGroup(this);
163 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
164 aPixGrpLayout->setSpacing(SPACING);
165 aPixGrpLayout->setMargin(MARGIN);
167 QRadioButton* aRBut = new QRadioButton(aPixGrp);
168 aRBut->setIcon(iconMoveNode);
169 aRBut->setChecked(true);
171 aPixGrpLayout->addWidget(aRBut);
172 aBtnGrp->addButton(aRBut, 0);
174 //------------------------------------------------------------
175 QGroupBox* anIdGrp = new QGroupBox(tr("SMESH_MOVE"), aFrame);
176 QHBoxLayout* anIdGrpLayout = new QHBoxLayout(anIdGrp);
177 anIdGrpLayout->setSpacing(SPACING);
178 anIdGrpLayout->setMargin(MARGIN);
180 QLabel* idLabl = new QLabel(tr("NODE_ID"), anIdGrp);
181 QPushButton* idBtn = new QPushButton(anIdGrp);
182 idBtn->setIcon(iconSelect);
183 myId = new QLineEdit(anIdGrp);
184 myId->setValidator(new SMESHGUI_IdValidator(this, 1));
186 anIdGrpLayout->addWidget(idLabl);
187 anIdGrpLayout->addWidget(idBtn);
188 anIdGrpLayout->addWidget(myId);
190 //------------------------------------------------------------
191 QGroupBox* aCoordGrp = new QGroupBox(tr("SMESH_COORDINATES"), aFrame);
192 QHBoxLayout* aCoordGrpLayout = new QHBoxLayout(aCoordGrp);
193 aCoordGrpLayout->setSpacing(SPACING);
194 aCoordGrpLayout->setMargin(MARGIN);
196 QLabel* aXLabel = new QLabel(tr("SMESH_X"), aCoordGrp);
197 myX = new SMESHGUI_SpinBox(aCoordGrp);
199 QLabel* aYLabel = new QLabel(tr("SMESH_Y"), aCoordGrp);
200 myY = new SMESHGUI_SpinBox(aCoordGrp);
202 QLabel* aZLabel = new QLabel(tr("SMESH_Z"), aCoordGrp);
203 myZ = new SMESHGUI_SpinBox(aCoordGrp);
205 aCoordGrpLayout->addWidget(aXLabel);
206 aCoordGrpLayout->addWidget(myX);
207 aCoordGrpLayout->addWidget(aYLabel);
208 aCoordGrpLayout->addWidget(myY);
209 aCoordGrpLayout->addWidget(aZLabel);
210 aCoordGrpLayout->addWidget(myZ);
212 //------------------------------------------------------------
213 myX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, DBL_DIGITS_DISPLAY);
214 myY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, DBL_DIGITS_DISPLAY);
215 myZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, DBL_DIGITS_DISPLAY);
217 //------------------------------------------------------------
218 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
220 aLay->setMargin(SPACING);
221 aLay->addWidget(aPixGrp);
222 aLay->addWidget(anIdGrp);
223 aLay->addWidget(aCoordGrp);
225 //------------------------------------------------------------
226 // connect signale and slots
227 connect(myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
228 connect(myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
229 connect(myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
230 connect(myId, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
235 //=======================================================================
236 // name : SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg
238 //=======================================================================
239 SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg()
244 //=======================================================================
245 // name : SMESHGUI_MoveNodesDlg::Init
246 // Purpose : Init dialog fields
247 //=======================================================================
248 void SMESHGUI_MoveNodesDlg::Init()
254 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
256 // selection and SMESHGUI
257 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
258 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
259 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
264 // set selection mode
265 SMESH::SetPointRepresentation(true);
266 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
267 aViewWindow->SetSelectionMode(NodeSelection);
272 //=======================================================================
273 // name : SMESHGUI_MoveNodesDlg::isValid
274 // Purpose : Verify validity of entry information
275 //=======================================================================
276 bool SMESHGUI_MoveNodesDlg::isValid (const bool theMess)
278 if (myId->text().isEmpty()) {
280 SUIT_MessageBox::information(this, tr("SMESH_WARNING"),
281 tr("NODE_ID_IS_NOT_DEFINED"));
287 //=======================================================================
288 // name : SMESHGUI_MoveNodesDlg::reset
289 // Purpose : Reset the dialog state
290 //=======================================================================
291 void SMESHGUI_MoveNodesDlg::reset()
301 //=======================================================================
302 // name : SMESHGUI_MoveNodesDlg::onApply
303 // Purpose : SLOT called when "Apply" button pressed.
304 //=======================================================================
305 bool SMESHGUI_MoveNodesDlg::onApply()
307 if (mySMESHGUI->isActiveStudyLocked())
313 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
314 if (aMesh->_is_nil()) {
315 SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
316 tr("SMESHG_NO_MESH"));
320 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
321 if (aMeshEditor->_is_nil())
324 int anId = myId->text().toInt();
325 bool aResult = false;
327 aResult = aMeshEditor->MoveNode(anId, myX->GetValue(), myY->GetValue(), myZ->GetValue());
333 aList.Append(myMeshActor->getIO());
334 mySelectionMgr->setSelectedObjects(aList,false);
342 //=======================================================================
343 // name : SMESHGUI_MoveNodesDlg::onOk
344 // Purpose : SLOT called when "Ok" button pressed.
345 //=======================================================================
346 void SMESHGUI_MoveNodesDlg::onOk()
352 //=======================================================================
353 // name : SMESHGUI_MoveNodesDlg::onClose
354 // Purpose : SLOT called when "Close" button pressed. Close dialog
355 //=======================================================================
356 void SMESHGUI_MoveNodesDlg::onClose()
358 //mySelectionMgr->clearSelected();
359 SMESH::SetPointRepresentation(false);
360 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
361 aViewWindow->SetSelectionMode(ActorSelection);
362 disconnect(mySelectionMgr, 0, this, 0);
363 disconnect(mySMESHGUI, 0, this, 0);
365 mySMESHGUI->ResetState();
369 //=================================================================================
370 // function : onHelp()
372 //=================================================================================
373 void SMESHGUI_MoveNodesDlg::onHelp()
375 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
377 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
381 platform = "winapplication";
383 platform = "application";
385 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
386 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
387 arg(app->resourceMgr()->stringValue("ExternalBrowser",
389 arg(myHelpFileName));
393 //=======================================================================
394 // name : SMESHGUI_MoveNodesDlg::onTextChange
396 //=======================================================================
397 void SMESHGUI_MoveNodesDlg::onTextChange (const QString& theNewText)
401 myOkBtn->setEnabled(false);
402 myApplyBtn->setEnabled(false);
405 // select entered node
407 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()){
409 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
412 mySelectionMgr->setSelectedObjects(aList,false);
415 if(const SMDS_MeshElement *anElem = aMesh->FindElement(theNewText.toInt())) {
416 TColStd_MapOfInteger aListInd;
417 aListInd.Add(anElem->GetID());
418 mySelector->AddOrRemoveIndex(anIO,aListInd, false);
419 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
420 aViewWindow->highlight(anIO,true,true);
428 //=======================================================================
429 // name : SMESHGUI_MoveNodesDlg::onSelectionDone
430 // Purpose : SLOT called when selection changed
431 //=======================================================================
432 void SMESHGUI_MoveNodesDlg::onSelectionDone()
438 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
440 if (aList.Extent() == 1) {
441 Handle(SALOME_InteractiveObject) anIO = aList.First();
442 myMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
445 if (SMESH::GetNameOfSelectedNodes(mySelector,anIO,aText) == 1) {
446 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) {
447 if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
449 myId->setText(aText);
450 myX->SetValue(aNode->X());
451 myY->SetValue(aNode->Y());
452 myZ->SetValue(aNode->Z());
454 erasePreview(); // avoid overlapping of a selection and a preview
466 //=======================================================================
467 // name : SMESHGUI_MoveNodesDlg::onDeactivate
468 // Purpose : SLOT called when dialog must be deativated
469 //=======================================================================
470 void SMESHGUI_MoveNodesDlg::onDeactivate()
476 //=======================================================================
477 // name : SMESHGUI_MoveNodesDlg::enterEvent
478 // Purpose : Event filter
479 //=======================================================================
480 void SMESHGUI_MoveNodesDlg::enterEvent (QEvent*)
483 mySMESHGUI->EmitSignalDeactivateDialog();
485 // set selection mode
486 SMESH::SetPointRepresentation(true);
487 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
488 aViewWindow->SetSelectionMode(NodeSelection);
496 //=======================================================================
497 // name : SMESHGUI_MoveNodesDlg::closeEvent
499 //=======================================================================
500 void SMESHGUI_MoveNodesDlg::closeEvent (QCloseEvent*)
503 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
504 aViewWindow->Repaint();
507 //=======================================================================
508 // name : SMESHGUI_MoveNodesDlg::hideEvent
509 // Purpose : may be caused by ESC key
510 //=======================================================================
511 void SMESHGUI_MoveNodesDlg::hideEvent (QHideEvent*)
517 //=======================================================================
518 // name : SMESHGUI_MoveNodesDlg::updateButtons
519 // Purpose : Update buttons state
520 //=======================================================================
521 void SMESHGUI_MoveNodesDlg::updateButtons()
523 bool isEnabled = isValid(false);
524 myOkBtn->setEnabled(isEnabled);
525 myApplyBtn->setEnabled(isEnabled);
528 //=======================================================================
529 // name : SMESHGUI_MoveNodesDlg::erasePreview
530 // Purpose : Erase preview
531 //=======================================================================
532 void SMESHGUI_MoveNodesDlg::erasePreview()
534 if (myPreviewActor == 0)
537 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
539 aViewWindow->RemoveActor(myPreviewActor);
540 myPreviewActor->Delete();
543 aViewWindow->Repaint();
546 //=======================================================================
547 // name : SMESHGUI_MoveNodesDlg::redisplayPreview
548 // Purpose : Redisplay preview
549 //=======================================================================
550 void SMESHGUI_MoveNodesDlg::redisplayPreview()
555 if (myPreviewActor != 0)
561 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
563 vtkPoints* aPoints = vtkPoints::New();
564 aPoints->SetNumberOfPoints(1);
565 aPoints->SetPoint(0, myX->GetValue(), myY->GetValue(), myZ->GetValue());
569 vtkIdList *anIdList = vtkIdList::New();
570 anIdList->SetNumberOfIds(1);
572 vtkCellArray *aCells = vtkCellArray::New();
573 aCells->Allocate(2, 0);
575 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
576 aCellTypesArray->SetNumberOfComponents(1);
577 aCellTypesArray->Allocate(1);
579 anIdList->SetId(0, 0);
580 aCells->InsertNextCell(anIdList);
581 aCellTypesArray->InsertNextValue(VTK_VERTEX);
584 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
585 aCellLocationsArray->SetNumberOfComponents(1);
586 aCellLocationsArray->SetNumberOfTuples(1);
588 aCells->InitTraversal();
590 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
592 aGrid->SetPoints(aPoints);
595 aGrid->SetCells(aCellTypesArray,aCellLocationsArray,aCells);
596 aCellLocationsArray->Delete();
597 aCellTypesArray->Delete();
600 // Create and display actor
601 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
602 aMapper->SetInput(aGrid);
605 myPreviewActor = SALOME_Actor::New();
606 myPreviewActor->PickableOff();
607 myPreviewActor->SetMapper(aMapper);
610 vtkProperty* aProp = vtkProperty::New();
611 aProp->SetRepresentationToWireframe();
612 aProp->SetColor(250, 0, 250);
613 aProp->SetPointSize(5);
614 myPreviewActor->SetProperty(aProp);
617 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
619 aViewWindow->AddActor(myPreviewActor);
620 aViewWindow->Repaint();
624 //=================================================================================
625 // function : keyPressEvent()
627 //=================================================================================
628 void SMESHGUI_MoveNodesDlg::keyPressEvent( QKeyEvent* e )
630 QDialog::keyPressEvent( e );
631 if ( e->isAccepted() )
634 if ( e->key() == Qt::Key_F1 ) {