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
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)
85 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
91 //=================================================================================
92 // name : SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg
94 //=================================================================================
95 SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg (SMESHGUI* theModule,
97 QDialog(SMESH::GetDesktop(theModule),
100 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
101 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
102 mySMESHGUI(theModule)
107 setCaption(tr("CAPTION"));
109 QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
111 QFrame* aMainFrame = createMainFrame (this);
112 QFrame* aBtnFrame = createButtonFrame(this);
114 aDlgLay->addWidget(aMainFrame);
115 aDlgLay->addWidget(aBtnFrame);
117 aDlgLay->setStretchFactor(aMainFrame, 1);
119 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
121 myHelpFileName = "moving_nodes_page.html";
126 //=======================================================================
127 // name : SMESHGUI_MoveNodesDlg::createButtonFrame
128 // Purpose : Create frame containing buttons
129 //=======================================================================
130 QFrame* SMESHGUI_MoveNodesDlg::createButtonFrame (QWidget* theParent)
132 QFrame* aFrame = new QFrame(theParent);
133 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
135 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), aFrame);
136 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
137 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
138 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
140 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
142 QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING);
144 aLay->addWidget(myOkBtn);
145 aLay->addWidget(myApplyBtn);
146 aLay->addItem(aSpacer);
147 aLay->addWidget(myCloseBtn);
148 aLay->addWidget(myHelpBtn);
150 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
151 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
152 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
153 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
158 //=======================================================================
159 // name : SMESHGUI_MoveNodesDlg::createMainFrame
160 // Purpose : Create frame containing dialog's input fields
161 //=======================================================================
162 QFrame* SMESHGUI_MoveNodesDlg::createMainFrame (QWidget* theParent)
164 QFrame* aFrame = new QFrame(theParent);
166 QPixmap iconMoveNode (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
167 QPixmap iconSelect (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
169 QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("MESH_NODE"), aFrame);
170 aPixGrp->setExclusive(TRUE);
171 QRadioButton* aRBut = new QRadioButton(aPixGrp);
172 aRBut->setPixmap(iconMoveNode);
173 aRBut->setChecked(TRUE);
175 QGroupBox* anIdGrp = new QGroupBox(1, Qt::Vertical, tr("SMESH_MOVE"), aFrame);
176 new QLabel(tr("NODE_ID"), anIdGrp);
177 (new QPushButton(anIdGrp))->setPixmap(iconSelect);
178 myId = new QLineEdit(anIdGrp);
179 myId->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
181 QGroupBox* aCoordGrp = new QGroupBox(1, Qt::Vertical, tr("SMESH_COORDINATES"), aFrame);
182 QLabel* aXLabel = new QLabel(tr("SMESH_X"), aCoordGrp);
183 aXLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
184 myX = new SMESHGUI_SpinBox(aCoordGrp);
186 QLabel* aYLabel = new QLabel(tr("SMESH_Y"), aCoordGrp);
187 //aYLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
188 aYLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
189 myY = new SMESHGUI_SpinBox(aCoordGrp);
191 QLabel* aZLabel = new QLabel(tr("SMESH_Z"), aCoordGrp);
192 //aZLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
193 aZLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
194 myZ = new SMESHGUI_SpinBox(aCoordGrp);
196 myX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, DBL_DIGITS_DISPLAY);
197 myY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, DBL_DIGITS_DISPLAY);
198 myZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 25.0, DBL_DIGITS_DISPLAY);
200 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
201 aLay->addWidget(aPixGrp);
202 aLay->addWidget(anIdGrp);
203 aLay->addWidget(aCoordGrp);
205 // connect signale and slots
206 connect(myX, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
207 connect(myY, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
208 connect(myZ, SIGNAL (valueChanged(double)), this, SLOT(redisplayPreview()));
209 connect(myId, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
214 //=======================================================================
215 // name : SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg
217 //=======================================================================
218 SMESHGUI_MoveNodesDlg::~SMESHGUI_MoveNodesDlg()
223 //=======================================================================
224 // name : SMESHGUI_MoveNodesDlg::Init
225 // Purpose : Init dialog fields
226 //=======================================================================
227 void SMESHGUI_MoveNodesDlg::Init()
233 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
235 // selection and SMESHGUI
236 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
237 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
238 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
245 // set selection mode
246 SMESH::SetPointRepresentation(true);
247 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
248 aViewWindow->SetSelectionMode(NodeSelection);
253 //=======================================================================
254 // name : SMESHGUI_MoveNodesDlg::isValid
255 // Purpose : Verify validity of entry information
256 //=======================================================================
257 bool SMESHGUI_MoveNodesDlg::isValid (const bool theMess) const
259 if (myId->text().isEmpty()) {
261 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_WARNING"),
262 tr("NODE_ID_IS_NOT_DEFINED"), QMessageBox::Ok);
268 //=======================================================================
269 // name : SMESHGUI_MoveNodesDlg::reset
270 // Purpose : Reset the dialog state
271 //=======================================================================
272 void SMESHGUI_MoveNodesDlg::reset()
282 //=======================================================================
283 // name : SMESHGUI_MoveNodesDlg::onApply
284 // Purpose : SLOT called when "Apply" button pressed.
285 //=======================================================================
286 bool SMESHGUI_MoveNodesDlg::onApply()
288 if (mySMESHGUI->isActiveStudyLocked())
294 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(myMeshActor->getIO());
295 if (aMesh->_is_nil()) {
296 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"),
297 tr("SMESHG_NO_MESH"), QMessageBox::Ok);
301 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
302 if (aMeshEditor->_is_nil())
305 int anId = myId->text().toInt();
306 bool aResult = false;
308 aResult = aMeshEditor->MoveNode(anId, myX->GetValue(), myY->GetValue(), myZ->GetValue());
314 aList.Append(myMeshActor->getIO());
315 mySelectionMgr->setSelectedObjects(aList,false);
323 //=======================================================================
324 // name : SMESHGUI_MoveNodesDlg::onOk
325 // Purpose : SLOT called when "Ok" button pressed.
326 //=======================================================================
327 void SMESHGUI_MoveNodesDlg::onOk()
333 //=======================================================================
334 // name : SMESHGUI_MoveNodesDlg::onClose
335 // Purpose : SLOT called when "Close" button pressed. Close dialog
336 //=======================================================================
337 void SMESHGUI_MoveNodesDlg::onClose()
339 //mySelectionMgr->clearSelected();
340 SMESH::SetPointRepresentation(false);
341 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
342 aViewWindow->SetSelectionMode(ActorSelection);
343 disconnect(mySelectionMgr, 0, this, 0);
344 disconnect(mySMESHGUI, 0, this, 0);
346 mySMESHGUI->ResetState();
350 //=================================================================================
351 // function : onHelp()
353 //=================================================================================
354 void SMESHGUI_MoveNodesDlg::onHelp()
356 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
358 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
362 platform = "winapplication";
364 platform = "application";
366 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
367 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
368 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
369 QObject::tr("BUT_OK"));
373 //=======================================================================
374 // name : SMESHGUI_MoveNodesDlg::onTextChange
376 //=======================================================================
377 void SMESHGUI_MoveNodesDlg::onTextChange (const QString& theNewText)
381 myOkBtn->setEnabled(false);
382 myApplyBtn->setEnabled(false);
385 // select entered node
387 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()){
389 Handle(SALOME_InteractiveObject) anIO = myMeshActor->getIO();
392 mySelectionMgr->setSelectedObjects(aList,false);
395 if(const SMDS_MeshElement *anElem = aMesh->FindElement(theNewText.toInt())) {
396 TColStd_MapOfInteger aListInd;
397 aListInd.Add(anElem->GetID());
398 mySelector->AddOrRemoveIndex(anIO,aListInd, false);
399 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
400 aViewWindow->highlight(anIO,true,true);
408 //=======================================================================
409 // name : SMESHGUI_MoveNodesDlg::onSelectionDone
410 // Purpose : SLOT called when selection changed
411 //=======================================================================
412 void SMESHGUI_MoveNodesDlg::onSelectionDone()
418 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
420 if (aList.Extent() == 1) {
421 Handle(SALOME_InteractiveObject) anIO = aList.First();
422 myMeshActor = SMESH::FindActorByEntry(anIO->getEntry());
425 if (SMESH::GetNameOfSelectedNodes(mySelector,anIO,aText) == 1) {
426 if(SMDS_Mesh* aMesh = myMeshActor->GetObject()->GetMesh()) {
427 if(const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
429 myId->setText(aText);
430 myX->SetValue(aNode->X());
431 myY->SetValue(aNode->Y());
432 myZ->SetValue(aNode->Z());
434 erasePreview(); // avoid overlapping of a selection and a preview
446 //=======================================================================
447 // name : SMESHGUI_MoveNodesDlg::onDeactivate
448 // Purpose : SLOT called when dialog must be deativated
449 //=======================================================================
450 void SMESHGUI_MoveNodesDlg::onDeactivate()
456 //=======================================================================
457 // name : SMESHGUI_MoveNodesDlg::enterEvent
458 // Purpose : Event filter
459 //=======================================================================
460 void SMESHGUI_MoveNodesDlg::enterEvent (QEvent*)
463 mySMESHGUI->EmitSignalDeactivateDialog();
465 // set selection mode
466 SMESH::SetPointRepresentation(true);
467 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
468 aViewWindow->SetSelectionMode(NodeSelection);
476 //=======================================================================
477 // name : SMESHGUI_MoveNodesDlg::closeEvent
479 //=======================================================================
480 void SMESHGUI_MoveNodesDlg::closeEvent (QCloseEvent*)
483 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
484 aViewWindow->Repaint();
487 //=======================================================================
488 // name : SMESHGUI_MoveNodesDlg::hideEvent
489 // Purpose : may be caused by ESC key
490 //=======================================================================
491 void SMESHGUI_MoveNodesDlg::hideEvent (QHideEvent*)
497 //=======================================================================
498 // name : SMESHGUI_MoveNodesDlg::updateButtons
499 // Purpose : Update buttons state
500 //=======================================================================
501 void SMESHGUI_MoveNodesDlg::updateButtons()
503 bool isEnabled = isValid(false);
504 myOkBtn->setEnabled(isEnabled);
505 myApplyBtn->setEnabled(isEnabled);
508 //=======================================================================
509 // name : SMESHGUI_MoveNodesDlg::erasePreview
510 // Purpose : Erase preview
511 //=======================================================================
512 void SMESHGUI_MoveNodesDlg::erasePreview()
514 if (myPreviewActor == 0)
517 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
519 aViewWindow->RemoveActor(myPreviewActor);
520 myPreviewActor->Delete();
523 aViewWindow->Repaint();
526 //=======================================================================
527 // name : SMESHGUI_MoveNodesDlg::redisplayPreview
528 // Purpose : Redisplay preview
529 //=======================================================================
530 void SMESHGUI_MoveNodesDlg::redisplayPreview()
535 if (myPreviewActor != 0)
541 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
543 vtkPoints* aPoints = vtkPoints::New();
544 aPoints->SetNumberOfPoints(1);
545 aPoints->SetPoint(0, myX->GetValue(), myY->GetValue(), myZ->GetValue());
549 vtkIdList *anIdList = vtkIdList::New();
550 anIdList->SetNumberOfIds(1);
552 vtkCellArray *aCells = vtkCellArray::New();
553 aCells->Allocate(2, 0);
555 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
556 aCellTypesArray->SetNumberOfComponents(1);
557 aCellTypesArray->Allocate(1);
559 anIdList->SetId(0, 0);
560 aCells->InsertNextCell(anIdList);
561 aCellTypesArray->InsertNextValue(VTK_VERTEX);
564 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
565 aCellLocationsArray->SetNumberOfComponents(1);
566 aCellLocationsArray->SetNumberOfTuples(1);
568 aCells->InitTraversal();
570 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
572 aGrid->SetPoints(aPoints);
575 aGrid->SetCells(aCellTypesArray,aCellLocationsArray,aCells);
576 aCellLocationsArray->Delete();
577 aCellTypesArray->Delete();
580 // Create and display actor
581 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
582 aMapper->SetInput(aGrid);
585 myPreviewActor = SALOME_Actor::New();
586 myPreviewActor->PickableOff();
587 myPreviewActor->SetMapper(aMapper);
590 vtkProperty* aProp = vtkProperty::New();
591 aProp->SetRepresentationToWireframe();
592 aProp->SetColor(250, 0, 250);
593 aProp->SetPointSize(5);
594 myPreviewActor->SetProperty(aProp);
597 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
599 aViewWindow->AddActor(myPreviewActor);
600 aViewWindow->Repaint();
604 //=================================================================================
605 // function : keyPressEvent()
607 //=================================================================================
608 void SMESHGUI_MoveNodesDlg::keyPressEvent( QKeyEvent* e )
610 QDialog::keyPressEvent( e );
611 if ( e->isAccepted() )
614 if ( e->key() == Key_F1 )