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 <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 SMESHGUI_Helper(theModule),
90 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
97 setWindowTitle(tr("CAPTION"));
99 QVBoxLayout* aDlgLay = new QVBoxLayout(this);
100 aDlgLay->setSpacing(SPACING);
101 aDlgLay->setMargin(MARGIN);
103 QWidget* aMainFrame = createMainFrame (this);
104 QWidget* aBtnFrame = createButtonFrame(this);
106 aDlgLay->addWidget(aMainFrame);
107 aDlgLay->addWidget(aBtnFrame);
109 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
111 myHelpFileName = "moving_nodes_page.html";
116 //=======================================================================
117 // name : SMESHGUI_MoveNodesDlg::createButtonFrame
118 // Purpose : Create frame containing buttons
119 //=======================================================================
120 QWidget* SMESHGUI_MoveNodesDlg::createButtonFrame (QWidget* theParent)
122 QFrame* aFrame = new QFrame(theParent);
123 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
125 myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
126 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
127 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
128 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
130 QHBoxLayout* aLay = new QHBoxLayout(aFrame);
131 aLay->setSpacing(SPACING);
132 aLay->setMargin(MARGIN);
134 aLay->addWidget(myOkBtn);
135 aLay->addSpacing(10);
136 aLay->addWidget(myApplyBtn);
137 aLay->addSpacing(10);
139 aLay->addWidget(myCloseBtn);
140 aLay->addWidget(myHelpBtn);
142 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
143 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
144 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
145 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
150 //=======================================================================
151 // name : SMESHGUI_MoveNodesDlg::createMainFrame
152 // Purpose : Create frame containing dialog's input fields
153 //=======================================================================
154 QWidget* SMESHGUI_MoveNodesDlg::createMainFrame (QWidget* theParent)
156 QWidget* aFrame = new QWidget(theParent);
158 QPixmap iconMoveNode (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
159 QPixmap iconSelect (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
161 //------------------------------------------------------------
162 QGroupBox* aPixGrp = new QGroupBox(tr("MESH_NODE"), aFrame);
163 QButtonGroup* aBtnGrp = new QButtonGroup(this);
164 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
165 aPixGrpLayout->setSpacing(SPACING);
166 aPixGrpLayout->setMargin(MARGIN);
168 QRadioButton* aRBut = new QRadioButton(aPixGrp);
169 aRBut->setIcon(iconMoveNode);
170 aRBut->setChecked(true);
172 aPixGrpLayout->addWidget(aRBut);
173 aBtnGrp->addButton(aRBut, 0);
175 //------------------------------------------------------------
176 QGroupBox* anIdGrp = new QGroupBox(tr("SMESH_MOVE"), aFrame);
177 QHBoxLayout* anIdGrpLayout = new QHBoxLayout(anIdGrp);
178 anIdGrpLayout->setSpacing(SPACING);
179 anIdGrpLayout->setMargin(MARGIN);
181 QLabel* idLabl = new QLabel(tr("NODE_ID"), anIdGrp);
182 QPushButton* idBtn = new QPushButton(anIdGrp);
183 idBtn->setIcon(iconSelect);
184 myId = new QLineEdit(anIdGrp);
185 myId->setValidator(new SMESHGUI_IdValidator(this, 1));
187 anIdGrpLayout->addWidget(idLabl);
188 anIdGrpLayout->addWidget(idBtn);
189 anIdGrpLayout->addWidget(myId);
191 //------------------------------------------------------------
192 QGroupBox* aCoordGrp = new QGroupBox(tr("SMESH_COORDINATES"), aFrame);
193 QHBoxLayout* aCoordGrpLayout = new QHBoxLayout(aCoordGrp);
194 aCoordGrpLayout->setSpacing(SPACING);
195 aCoordGrpLayout->setMargin(MARGIN);
197 QLabel* aXLabel = new QLabel(tr("SMESH_X"), aCoordGrp);
198 myX = new SMESHGUI_SpinBox(aCoordGrp);
200 QLabel* aYLabel = new QLabel(tr("SMESH_Y"), aCoordGrp);
201 myY = new SMESHGUI_SpinBox(aCoordGrp);
203 QLabel* aZLabel = new QLabel(tr("SMESH_Z"), aCoordGrp);
204 myZ = new SMESHGUI_SpinBox(aCoordGrp);
206 aCoordGrpLayout->addWidget(aXLabel);
207 aCoordGrpLayout->addWidget(myX);
208 aCoordGrpLayout->addWidget(aYLabel);
209 aCoordGrpLayout->addWidget(myY);
210 aCoordGrpLayout->addWidget(aZLabel);
211 aCoordGrpLayout->addWidget(myZ);
213 //------------------------------------------------------------
214 myX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, DBL_DIGITS_DISPLAY);
215 myY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, DBL_DIGITS_DISPLAY);
216 myZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, DBL_DIGITS_DISPLAY);
218 //------------------------------------------------------------
219 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
221 aLay->setMargin(SPACING);
222 aLay->addWidget(aPixGrp);
223 aLay->addWidget(anIdGrp);
224 aLay->addWidget(aCoordGrp);
226 //------------------------------------------------------------
227 // connect signale and slots
228 connect(myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
229 connect(myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
230 connect(myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
231 connect(myId, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
236 //=======================================================================
237 // name : SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg
239 //=======================================================================
240 SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg()
245 //=======================================================================
246 // name : SMESHGUI_MoveNodesDlg::Init
247 // Purpose : Init dialog fields
248 //=======================================================================
249 void SMESHGUI_MoveNodesDlg::Init()
255 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
257 // selection and SMESHGUI
258 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
259 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
260 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
265 // set selection mode
266 SMESH::SetPointRepresentation(true);
267 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
268 aViewWindow->SetSelectionMode(NodeSelection);
273 //=======================================================================
274 // name : SMESHGUI_MoveNodesDlg::isValid
275 // Purpose : Verify validity of entry information
276 //=======================================================================
277 bool SMESHGUI_MoveNodesDlg::isValid (const bool theMess)
279 if (myId->text().isEmpty()) {
281 SUIT_MessageBox::information(this, tr("SMESH_WARNING"),
282 tr("NODE_ID_IS_NOT_DEFINED"));
285 return checkParameters( theMess, 3, myX, myY, myZ );
288 //=======================================================================
289 // name : SMESHGUI_MoveNodesDlg::reset
290 // Purpose : Reset the dialog state
291 //=======================================================================
292 void SMESHGUI_MoveNodesDlg::reset()
302 //=======================================================================
303 // name : SMESHGUI_MoveNodesDlg::onApply
304 // Purpose : SLOT called when "Apply" button pressed.
305 //=======================================================================
306 bool SMESHGUI_MoveNodesDlg::onApply()
308 if (mySMESHGUI->isActiveStudyLocked())
314 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
315 if (aMesh->_is_nil()) {
316 SUIT_MessageBox::information(this, tr("SMESH_ERROR"),
317 tr("SMESHG_NO_MESH"));
321 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
322 if (aMeshEditor->_is_nil())
325 int anId = myId->text().toInt();
326 bool aResult = false;
328 aResult = aMeshEditor->MoveNode(anId, myX->GetValue(), myY->GetValue(), myZ->GetValue());
330 QStringList aParameters;
331 aParameters << myX->text();
332 aParameters << myY->text();
333 aParameters << myZ->text();
334 //asl: aMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
340 aList.Append(myMeshActor->getIO());
341 mySelectionMgr->setSelectedObjects(aList,false);
349 //=======================================================================
350 // name : SMESHGUI_MoveNodesDlg::onOk
351 // Purpose : SLOT called when "Ok" button pressed.
352 //=======================================================================
353 void SMESHGUI_MoveNodesDlg::onOk()
359 //=======================================================================
360 // name : SMESHGUI_MoveNodesDlg::onClose
361 // Purpose : SLOT called when "Close" button pressed. Close dialog
362 //=======================================================================
363 void SMESHGUI_MoveNodesDlg::onClose()
365 //mySelectionMgr->clearSelected();
366 SMESH::SetPointRepresentation(false);
367 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
368 aViewWindow->SetSelectionMode(ActorSelection);
369 disconnect(mySelectionMgr, 0, this, 0);
370 disconnect(mySMESHGUI, 0, this, 0);
372 mySMESHGUI->ResetState();
376 //=================================================================================
377 // function : onHelp()
379 //=================================================================================
380 void SMESHGUI_MoveNodesDlg::onHelp()
382 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
384 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
388 platform = "winapplication";
390 platform = "application";
392 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
393 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
394 arg(app->resourceMgr()->stringValue("ExternalBrowser",
396 arg(myHelpFileName));
400 //=======================================================================
401 // name : SMESHGUI_MoveNodesDlg::onTextChange
403 //=======================================================================
404 void SMESHGUI_MoveNodesDlg::onTextChange (const QString& theNewText)
408 myOkBtn->setEnabled(false);
409 myApplyBtn->setEnabled(false);
412 // select entered node
414 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()){
416 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
419 mySelectionMgr->setSelectedObjects(aList,false);
422 if(const SMDS_MeshElement *anElem = aMesh->FindElement(theNewText.toInt())) {
423 TColStd_MapOfInteger aListInd;
424 aListInd.Add(anElem->GetID());
425 mySelector->AddOrRemoveIndex(anIO,aListInd, false);
426 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
427 aViewWindow->highlight(anIO,true,true);
435 //=======================================================================
436 // name : SMESHGUI_MoveNodesDlg::onSelectionDone
437 // Purpose : SLOT called when selection changed
438 //=======================================================================
439 void SMESHGUI_MoveNodesDlg::onSelectionDone()
445 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
447 if (aList.Extent() == 1) {
448 Handle(SALOME_InteractiveObject) anIO = aList.First();
449 myMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
452 if (SMESH::GetNameOfSelectedNodes(mySelector,anIO,aText) == 1) {
453 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) {
454 if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
456 myId->setText(aText);
457 myX->SetValue(aNode->X());
458 myY->SetValue(aNode->Y());
459 myZ->SetValue(aNode->Z());
461 erasePreview(); // avoid overlapping of a selection and a preview
473 //=======================================================================
474 // name : SMESHGUI_MoveNodesDlg::onDeactivate
475 // Purpose : SLOT called when dialog must be deativated
476 //=======================================================================
477 void SMESHGUI_MoveNodesDlg::onDeactivate()
483 //=======================================================================
484 // name : SMESHGUI_MoveNodesDlg::enterEvent
485 // Purpose : Event filter
486 //=======================================================================
487 void SMESHGUI_MoveNodesDlg::enterEvent (QEvent*)
490 mySMESHGUI->EmitSignalDeactivateDialog();
492 // set selection mode
493 SMESH::SetPointRepresentation(true);
494 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
495 aViewWindow->SetSelectionMode(NodeSelection);
503 //=======================================================================
504 // name : SMESHGUI_MoveNodesDlg::closeEvent
506 //=======================================================================
507 void SMESHGUI_MoveNodesDlg::closeEvent (QCloseEvent*)
510 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
511 aViewWindow->Repaint();
514 //=======================================================================
515 // name : SMESHGUI_MoveNodesDlg::hideEvent
516 // Purpose : may be caused by ESC key
517 //=======================================================================
518 void SMESHGUI_MoveNodesDlg::hideEvent (QHideEvent*)
524 //=======================================================================
525 // name : SMESHGUI_MoveNodesDlg::updateButtons
526 // Purpose : Update buttons state
527 //=======================================================================
528 void SMESHGUI_MoveNodesDlg::updateButtons()
530 bool isEnabled = isValid(false);
531 myOkBtn->setEnabled(isEnabled);
532 myApplyBtn->setEnabled(isEnabled);
535 //=======================================================================
536 // name : SMESHGUI_MoveNodesDlg::erasePreview
537 // Purpose : Erase preview
538 //=======================================================================
539 void SMESHGUI_MoveNodesDlg::erasePreview()
541 if (myPreviewActor == 0)
544 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
546 aViewWindow->RemoveActor(myPreviewActor);
547 myPreviewActor->Delete();
550 aViewWindow->Repaint();
553 //=======================================================================
554 // name : SMESHGUI_MoveNodesDlg::redisplayPreview
555 // Purpose : Redisplay preview
556 //=======================================================================
557 void SMESHGUI_MoveNodesDlg::redisplayPreview()
562 if (myPreviewActor != 0)
568 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
570 vtkPoints* aPoints = vtkPoints::New();
571 aPoints->SetNumberOfPoints(1);
572 aPoints->SetPoint(0, myX->GetValue(), myY->GetValue(), myZ->GetValue());
576 vtkIdList *anIdList = vtkIdList::New();
577 anIdList->SetNumberOfIds(1);
579 vtkCellArray *aCells = vtkCellArray::New();
580 aCells->Allocate(2, 0);
582 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
583 aCellTypesArray->SetNumberOfComponents(1);
584 aCellTypesArray->Allocate(1);
586 anIdList->SetId(0, 0);
587 aCells->InsertNextCell(anIdList);
588 aCellTypesArray->InsertNextValue(VTK_VERTEX);
591 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
592 aCellLocationsArray->SetNumberOfComponents(1);
593 aCellLocationsArray->SetNumberOfTuples(1);
595 aCells->InitTraversal();
597 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
599 aGrid->SetPoints(aPoints);
602 aGrid->SetCells(aCellTypesArray,aCellLocationsArray,aCells);
603 aCellLocationsArray->Delete();
604 aCellTypesArray->Delete();
607 // Create and display actor
608 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
609 aMapper->SetInput(aGrid);
612 myPreviewActor = SALOME_Actor::New();
613 myPreviewActor->PickableOff();
614 myPreviewActor->SetMapper(aMapper);
617 vtkProperty* aProp = vtkProperty::New();
618 aProp->SetRepresentationToWireframe();
619 aProp->SetColor(250, 0, 250);
620 aProp->SetPointSize(5);
621 myPreviewActor->SetProperty(aProp);
624 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
626 aViewWindow->AddActor(myPreviewActor);
627 aViewWindow->Repaint();
631 //=================================================================================
632 // function : keyPressEvent()
634 //=================================================================================
635 void SMESHGUI_MoveNodesDlg::keyPressEvent( QKeyEvent* e )
637 QDialog::keyPressEvent( e );
638 if ( e->isAccepted() )
641 if ( e->key() == Qt::Key_F1 ) {