1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_MoveNodesDlg.cxx
24 // 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 <SalomeApp_Notebook.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_MessageBox.h>
48 #include <SVTK_ViewModel.h>
49 #include <SVTK_ViewWindow.h>
50 #include <SALOME_ListIO.hxx>
52 #include <VTKViewer_CellLocationsArray.h>
55 #include <TColStd_MapOfInteger.hxx>
58 #include <vtkIdList.h>
59 #include <vtkCellArray.h>
60 #include <vtkUnsignedCharArray.h>
61 #include <vtkUnstructuredGrid.h>
62 #include <vtkDataSetMapper.h>
63 #include <vtkProperty.h>
69 #include <QPushButton>
70 #include <QRadioButton>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
74 #include <QButtonGroup>
77 #include <SALOMEconfig.h>
78 #include CORBA_SERVER_HEADER(SMESH_Mesh)
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
84 //=================================================================================
85 // name : SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg
87 //=================================================================================
88 SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg(SMESHGUI* theModule):
89 QDialog(SMESH::GetDesktop(theModule)),
90 SMESHGUI_Helper(theModule),
91 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
98 setWindowTitle(tr("CAPTION"));
100 QVBoxLayout* aDlgLay = new QVBoxLayout(this);
101 aDlgLay->setSpacing(SPACING);
102 aDlgLay->setMargin(MARGIN);
104 QWidget* aMainFrame = createMainFrame (this);
105 QWidget* aBtnFrame = createButtonFrame(this);
107 aDlgLay->addWidget(aMainFrame);
108 aDlgLay->addWidget(aBtnFrame);
110 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
112 myHelpFileName = "moving_nodes_page.html";
117 //=======================================================================
118 // name : SMESHGUI_MoveNodesDlg::createButtonFrame
119 // Purpose : Create frame containing buttons
120 //=======================================================================
121 QWidget* SMESHGUI_MoveNodesDlg::createButtonFrame (QWidget* theParent)
123 QFrame* aFrame = new QFrame(theParent);
124 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
126 myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
127 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
128 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
129 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
131 QHBoxLayout* aLay = new QHBoxLayout(aFrame);
132 aLay->setSpacing(SPACING);
133 aLay->setMargin(MARGIN);
135 aLay->addWidget(myOkBtn);
136 aLay->addSpacing(10);
137 aLay->addWidget(myApplyBtn);
138 aLay->addSpacing(10);
140 aLay->addWidget(myCloseBtn);
141 aLay->addWidget(myHelpBtn);
143 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
144 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
145 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
146 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
151 //=======================================================================
152 // name : SMESHGUI_MoveNodesDlg::createMainFrame
153 // Purpose : Create frame containing dialog's input fields
154 //=======================================================================
155 QWidget* SMESHGUI_MoveNodesDlg::createMainFrame (QWidget* theParent)
157 QWidget* aFrame = new QWidget(theParent);
159 QPixmap iconMoveNode (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
160 QPixmap iconSelect (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
162 //------------------------------------------------------------
163 QGroupBox* aPixGrp = new QGroupBox(tr("MESH_NODE"), aFrame);
164 QButtonGroup* aBtnGrp = new QButtonGroup(this);
165 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
166 aPixGrpLayout->setSpacing(SPACING);
167 aPixGrpLayout->setMargin(MARGIN);
169 QRadioButton* aRBut = new QRadioButton(aPixGrp);
170 aRBut->setIcon(iconMoveNode);
171 aRBut->setChecked(true);
173 aPixGrpLayout->addWidget(aRBut);
174 aBtnGrp->addButton(aRBut, 0);
176 //------------------------------------------------------------
177 QGroupBox* anIdGrp = new QGroupBox(tr("SMESH_MOVE"), aFrame);
178 QHBoxLayout* anIdGrpLayout = new QHBoxLayout(anIdGrp);
179 anIdGrpLayout->setSpacing(SPACING);
180 anIdGrpLayout->setMargin(MARGIN);
182 QLabel* idLabl = new QLabel(tr("NODE_ID"), anIdGrp);
183 QPushButton* idBtn = new QPushButton(anIdGrp);
184 idBtn->setIcon(iconSelect);
185 myId = new QLineEdit(anIdGrp);
186 myId->setValidator(new SMESHGUI_IdValidator(this, 1));
188 anIdGrpLayout->addWidget(idLabl);
189 anIdGrpLayout->addWidget(idBtn);
190 anIdGrpLayout->addWidget(myId);
192 //------------------------------------------------------------
193 QGroupBox* aCoordGrp = new QGroupBox(tr("SMESH_COORDINATES"), aFrame);
194 QHBoxLayout* aCoordGrpLayout = new QHBoxLayout(aCoordGrp);
195 aCoordGrpLayout->setSpacing(SPACING);
196 aCoordGrpLayout->setMargin(MARGIN);
198 QLabel* aXLabel = new QLabel(tr("SMESH_X"), aCoordGrp);
199 myX = new SMESHGUI_SpinBox(aCoordGrp);
201 QLabel* aYLabel = new QLabel(tr("SMESH_Y"), aCoordGrp);
202 myY = new SMESHGUI_SpinBox(aCoordGrp);
204 QLabel* aZLabel = new QLabel(tr("SMESH_Z"), aCoordGrp);
205 myZ = new SMESHGUI_SpinBox(aCoordGrp);
207 aCoordGrpLayout->addWidget(aXLabel);
208 aCoordGrpLayout->addWidget(myX);
209 aCoordGrpLayout->addWidget(aYLabel);
210 aCoordGrpLayout->addWidget(myY);
211 aCoordGrpLayout->addWidget(aZLabel);
212 aCoordGrpLayout->addWidget(myZ);
214 //------------------------------------------------------------
215 myX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, DBL_DIGITS_DISPLAY);
216 myY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, DBL_DIGITS_DISPLAY);
217 myZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, DBL_DIGITS_DISPLAY);
219 //------------------------------------------------------------
220 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
222 aLay->setMargin(SPACING);
223 aLay->addWidget(aPixGrp);
224 aLay->addWidget(anIdGrp);
225 aLay->addWidget(aCoordGrp);
227 //------------------------------------------------------------
228 // connect signale and slots
229 connect(myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
230 connect(myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
231 connect(myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
232 connect(myId, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
237 //=======================================================================
238 // name : SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg
240 //=======================================================================
241 SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg()
246 //=======================================================================
247 // name : SMESHGUI_MoveNodesDlg::Init
248 // Purpose : Init dialog fields
249 //=======================================================================
250 void SMESHGUI_MoveNodesDlg::Init()
256 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
258 // selection and SMESHGUI
259 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
260 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
261 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
266 // set selection mode
267 SMESH::SetPointRepresentation(true);
268 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
269 aViewWindow->SetSelectionMode(NodeSelection);
274 //=======================================================================
275 // name : SMESHGUI_MoveNodesDlg::isValid
276 // Purpose : Verify validity of entry information
277 //=======================================================================
278 bool SMESHGUI_MoveNodesDlg::isValid (const bool theMess)
280 if (myId->text().isEmpty()) {
282 SUIT_MessageBox::information(this, tr("SMESH_WARNING"),
283 tr("NODE_ID_IS_NOT_DEFINED"));
286 return checkParameters( theMess, 3, myX, myY, myZ );
289 //=======================================================================
290 // name : SMESHGUI_MoveNodesDlg::reset
291 // Purpose : Reset the dialog state
292 //=======================================================================
293 void SMESHGUI_MoveNodesDlg::reset()
303 //=======================================================================
304 // name : SMESHGUI_MoveNodesDlg::onApply
305 // Purpose : SLOT called when "Apply" button pressed.
306 //=======================================================================
307 bool SMESHGUI_MoveNodesDlg::onApply()
309 if (mySMESHGUI->isActiveStudyLocked())
315 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
316 if (aMesh->_is_nil()) {
317 SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
318 tr("SMESHG_NO_MESH"));
322 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
323 if (aMeshEditor->_is_nil())
326 int anId = myId->text().toInt();
327 bool aResult = false;
329 aResult = aMeshEditor->MoveNode(anId, myX->GetValue(), myY->GetValue(), myZ->GetValue());
330 getNotebook()->setParameters( aMesh, 3, myX, myY, myZ );
336 aList.Append(myMeshActor->getIO());
337 mySelectionMgr->setSelectedObjects(aList,false);
345 //=======================================================================
346 // name : SMESHGUI_MoveNodesDlg::onOk
347 // Purpose : SLOT called when "Ok" button pressed.
348 //=======================================================================
349 void SMESHGUI_MoveNodesDlg::onOk()
355 //=======================================================================
356 // name : SMESHGUI_MoveNodesDlg::onClose
357 // Purpose : SLOT called when "Close" button pressed. Close dialog
358 //=======================================================================
359 void SMESHGUI_MoveNodesDlg::onClose()
361 //mySelectionMgr->clearSelected();
362 SMESH::SetPointRepresentation(false);
363 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
364 aViewWindow->SetSelectionMode(ActorSelection);
365 disconnect(mySelectionMgr, 0, this, 0);
366 disconnect(mySMESHGUI, 0, this, 0);
368 mySMESHGUI->ResetState();
372 //=================================================================================
373 // function : onHelp()
375 //=================================================================================
376 void SMESHGUI_MoveNodesDlg::onHelp()
378 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
380 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
384 platform = "winapplication";
386 platform = "application";
388 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
389 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
390 arg(app->resourceMgr()->stringValue("ExternalBrowser",
392 arg(myHelpFileName));
396 //=======================================================================
397 // name : SMESHGUI_MoveNodesDlg::onTextChange
399 //=======================================================================
400 void SMESHGUI_MoveNodesDlg::onTextChange (const QString& theNewText)
404 myOkBtn->setEnabled(false);
405 myApplyBtn->setEnabled(false);
408 // select entered node
410 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()){
412 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
415 mySelectionMgr->setSelectedObjects(aList,false);
418 if(const SMDS_MeshElement *anElem = aMesh->FindElement(theNewText.toInt())) {
419 TColStd_MapOfInteger aListInd;
420 aListInd.Add(anElem->GetID());
421 mySelector->AddOrRemoveIndex(anIO,aListInd, false);
422 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
423 aViewWindow->highlight(anIO,true,true);
431 //=======================================================================
432 // name : SMESHGUI_MoveNodesDlg::onSelectionDone
433 // Purpose : SLOT called when selection changed
434 //=======================================================================
435 void SMESHGUI_MoveNodesDlg::onSelectionDone()
441 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
443 if (aList.Extent() == 1) {
444 Handle(SALOME_InteractiveObject) anIO = aList.First();
445 myMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
448 if (SMESH::GetNameOfSelectedNodes(mySelector,anIO,aText) == 1) {
449 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) {
450 if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
452 myId->setText(aText);
453 myX->SetValue(aNode->X());
454 myY->SetValue(aNode->Y());
455 myZ->SetValue(aNode->Z());
457 erasePreview(); // avoid overlapping of a selection and a preview
469 //=======================================================================
470 // name : SMESHGUI_MoveNodesDlg::onDeactivate
471 // Purpose : SLOT called when dialog must be deativated
472 //=======================================================================
473 void SMESHGUI_MoveNodesDlg::onDeactivate()
479 //=======================================================================
480 // name : SMESHGUI_MoveNodesDlg::enterEvent
481 // Purpose : Event filter
482 //=======================================================================
483 void SMESHGUI_MoveNodesDlg::enterEvent (QEvent*)
486 mySMESHGUI->EmitSignalDeactivateDialog();
488 // set selection mode
489 SMESH::SetPointRepresentation(true);
490 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
491 aViewWindow->SetSelectionMode(NodeSelection);
499 //=======================================================================
500 // name : SMESHGUI_MoveNodesDlg::closeEvent
502 //=======================================================================
503 void SMESHGUI_MoveNodesDlg::closeEvent (QCloseEvent*)
506 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
507 aViewWindow->Repaint();
510 //=======================================================================
511 // name : SMESHGUI_MoveNodesDlg::hideEvent
512 // Purpose : may be caused by ESC key
513 //=======================================================================
514 void SMESHGUI_MoveNodesDlg::hideEvent (QHideEvent*)
520 //=======================================================================
521 // name : SMESHGUI_MoveNodesDlg::updateButtons
522 // Purpose : Update buttons state
523 //=======================================================================
524 void SMESHGUI_MoveNodesDlg::updateButtons()
526 bool isEnabled = isValid(false);
527 myOkBtn->setEnabled(isEnabled);
528 myApplyBtn->setEnabled(isEnabled);
531 //=======================================================================
532 // name : SMESHGUI_MoveNodesDlg::erasePreview
533 // Purpose : Erase preview
534 //=======================================================================
535 void SMESHGUI_MoveNodesDlg::erasePreview()
537 if (myPreviewActor == 0)
540 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
542 aViewWindow->RemoveActor(myPreviewActor);
543 myPreviewActor->Delete();
546 aViewWindow->Repaint();
549 //=======================================================================
550 // name : SMESHGUI_MoveNodesDlg::redisplayPreview
551 // Purpose : Redisplay preview
552 //=======================================================================
553 void SMESHGUI_MoveNodesDlg::redisplayPreview()
558 if (myPreviewActor != 0)
564 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
566 vtkPoints* aPoints = vtkPoints::New();
567 aPoints->SetNumberOfPoints(1);
568 aPoints->SetPoint(0, myX->GetValue(), myY->GetValue(), myZ->GetValue());
572 vtkIdList *anIdList = vtkIdList::New();
573 anIdList->SetNumberOfIds(1);
575 vtkCellArray *aCells = vtkCellArray::New();
576 aCells->Allocate(2, 0);
578 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
579 aCellTypesArray->SetNumberOfComponents(1);
580 aCellTypesArray->Allocate(1);
582 anIdList->SetId(0, 0);
583 aCells->InsertNextCell(anIdList);
584 aCellTypesArray->InsertNextValue(VTK_VERTEX);
587 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
588 aCellLocationsArray->SetNumberOfComponents(1);
589 aCellLocationsArray->SetNumberOfTuples(1);
591 aCells->InitTraversal();
593 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
595 aGrid->SetPoints(aPoints);
598 aGrid->SetCells(aCellTypesArray,aCellLocationsArray,aCells);
599 aCellLocationsArray->Delete();
600 aCellTypesArray->Delete();
603 // Create and display actor
604 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
605 aMapper->SetInput(aGrid);
608 myPreviewActor = SALOME_Actor::New();
609 myPreviewActor->PickableOff();
610 myPreviewActor->SetMapper(aMapper);
613 vtkProperty* aProp = vtkProperty::New();
614 aProp->SetRepresentationToWireframe();
615 aProp->SetColor(250, 0, 250);
616 aProp->SetPointSize(5);
617 myPreviewActor->SetProperty(aProp);
620 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
622 aViewWindow->AddActor(myPreviewActor);
623 aViewWindow->Repaint();
627 //=================================================================================
628 // function : keyPressEvent()
630 //=================================================================================
631 void SMESHGUI_MoveNodesDlg::keyPressEvent( QKeyEvent* e )
633 QDialog::keyPressEvent( e );
634 if ( e->isAccepted() )
637 if ( e->key() == Qt::Key_F1 ) {