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_NodesDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_NodesDlg.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_MeshUtils.h"
37 #include "SMESH_Actor.h"
38 #include "SMESH_ActorUtils.h"
39 #include "SMESH_ObjectDef.h"
41 #include "SMDS_Mesh.hxx"
42 #include "SMDS_MeshNode.hxx"
44 #include "SUIT_Session.h"
45 #include "SUIT_OverrideCursor.h"
46 #include "SUIT_ViewWindow.h"
47 #include "SUIT_ViewManager.h"
48 #include "SUIT_MessageBox.h"
49 #include "SUIT_Desktop.h"
51 #include "SalomeApp_Study.h"
52 #include "LightApp_SelectionMgr.h"
54 #include "SVTK_Selector.h"
55 #include "SVTK_ViewWindow.h"
57 #include "SALOME_Actor.h"
58 #include "SALOME_ListIO.hxx"
60 #include "utilities.h"
64 #include <vtkIdList.h>
65 #include <vtkIntArray.h>
66 #include <vtkCellArray.h>
67 #include <vtkUnsignedCharArray.h>
68 #include <vtkUnstructuredGrid.h>
69 #include <vtkDataSetMapper.h>
70 #include <vtkActorCollection.h>
71 #include <vtkRenderer.h>
74 #include <qbuttongroup.h>
76 #include <qgroupbox.h>
78 #include <qlineedit.h>
79 #include <qpushbutton.h>
80 #include <qradiobutton.h>
84 #include <qwhatsthis.h>
87 #include <qvalidator.h>
95 void AddNode (SMESH::SMESH_Mesh_ptr theMesh, float x, float y, float z)
97 SUIT_OverrideCursor wc;
99 _PTR(SObject) aSobj = SMESH::FindSObject(theMesh);
100 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
101 aMeshEditor->AddNode(x,y,z);
102 _PTR(Study) aStudy = GetActiveStudyDocument();
103 CORBA::Long anId = aStudy->StudyId();
104 if (TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId, aSobj->GetID().c_str())) {
105 aVisualObj->Update(true);
107 } catch (SALOME::SALOME_Exception& exc) {
108 INFOS("Follow exception was cought:\n\t" << exc.details.text);
109 } catch (const std::exception& exc) {
110 INFOS("Follow exception was cought:\n\t" << exc.what());
112 INFOS("Unknown exception was cought !!!");
116 class TNodeSimulation {
117 SVTK_ViewWindow* myViewWindow;
119 SALOME_Actor *myPreviewActor;
120 vtkDataSetMapper* myMapper;
124 TNodeSimulation(SVTK_ViewWindow* theViewWindow):
125 myViewWindow(theViewWindow)
127 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
130 myPoints = vtkPoints::New();
131 myPoints->SetNumberOfPoints(1);
132 myPoints->SetPoint(0,0.0,0.0,0.0);
135 vtkIdList *anIdList = vtkIdList::New();
136 anIdList->SetNumberOfIds(1);
138 vtkCellArray *aCells = vtkCellArray::New();
139 aCells->Allocate(2, 0);
141 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
142 aCellTypesArray->SetNumberOfComponents(1);
143 aCellTypesArray->Allocate(1);
145 anIdList->SetId(0, 0);
146 aCells->InsertNextCell(anIdList);
147 aCellTypesArray->InsertNextValue(VTK_VERTEX);
149 vtkIntArray* aCellLocationsArray = vtkIntArray::New();
150 aCellLocationsArray->SetNumberOfComponents(1);
151 aCellLocationsArray->SetNumberOfTuples(1);
153 aCells->InitTraversal();
155 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
157 aGrid->SetCells(aCellTypesArray, aCellLocationsArray, aCells);
159 aGrid->SetPoints(myPoints);
160 aGrid->SetCells(aCellTypesArray, aCellLocationsArray,aCells);
161 aCellLocationsArray->Delete();
162 aCellTypesArray->Delete();
166 // Create and display actor
167 myMapper = vtkDataSetMapper::New();
168 myMapper->SetInput(aGrid);
171 myPreviewActor = SALOME_Actor::New();
172 myPreviewActor->SetInfinitive(true);
173 myPreviewActor->VisibilityOff();
174 myPreviewActor->PickableOff();
175 myPreviewActor->SetMapper(myMapper);
177 vtkProperty* aProp = vtkProperty::New();
178 aProp->SetRepresentationToPoints();
181 GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 0 ) );
182 aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
184 float aPointSize = GetFloat( "SMESH:node_size", 3 );
185 aProp->SetPointSize( aPointSize );
187 myPreviewActor->SetProperty( aProp );
190 myViewWindow->AddActor(myPreviewActor);
193 void SetPosition (float x, float y, float z)
195 myPoints->SetPoint(0,x,y,z);
196 myPoints->Modified();
200 void SetVisibility (bool theVisibility)
202 myPreviewActor->SetVisibility(theVisibility);
203 RepaintCurrentView();
208 myViewWindow->RemoveActor(myPreviewActor);
209 myPreviewActor->Delete();
211 myMapper->RemoveAllInputs();
219 //=================================================================================
220 // class : SMESHGUI_NodesDlg()
222 //=================================================================================
223 SMESHGUI_NodesDlg::SMESHGUI_NodesDlg (SMESHGUI* theModule,
227 QDialog(SMESH::GetDesktop(theModule),
230 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
231 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
232 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
233 mySMESHGUI(theModule)
235 mySimulation = new SMESH::TNodeSimulation(SMESH::GetViewWindow( mySMESHGUI ));
237 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_NODE")));
239 setName("SMESHGUI_NodesDlg");
241 setCaption(tr("MESH_NODE_TITLE"));
242 setSizeGripEnabled(TRUE);
243 SMESHGUI_NodesDlgLayout = new QGridLayout(this);
244 SMESHGUI_NodesDlgLayout->setSpacing(6);
245 SMESHGUI_NodesDlgLayout->setMargin(11);
247 /***************************************************************/
248 GroupButtons = new QGroupBox(this, "GroupButtons");
249 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
250 GroupButtons->setTitle(tr("" ));
251 GroupButtons->setColumnLayout(0, Qt::Vertical);
252 GroupButtons->layout()->setSpacing(0);
253 GroupButtons->layout()->setMargin(0);
254 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
255 GroupButtonsLayout->setAlignment(Qt::AlignTop);
256 GroupButtonsLayout->setSpacing(6);
257 GroupButtonsLayout->setMargin(11);
258 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
259 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
260 buttonCancel->setAutoDefault(TRUE);
261 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
262 buttonApply = new QPushButton(GroupButtons, "buttonApply");
263 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
264 buttonApply->setAutoDefault(TRUE);
265 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
266 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
267 GroupButtonsLayout->addItem(spacer_9, 0, 2);
268 buttonOk = new QPushButton(GroupButtons, "buttonOk");
269 buttonOk->setText(tr("SMESH_BUT_OK" ));
270 buttonOk->setAutoDefault(TRUE);
271 buttonOk->setDefault(TRUE);
272 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
273 SMESHGUI_NodesDlgLayout->addWidget(GroupButtons, 2, 0);
275 /***************************************************************/
276 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
277 GroupConstructors->setTitle(tr("MESH_NODE" ));
278 GroupConstructors->setExclusive(TRUE);
279 GroupConstructors->setColumnLayout(0, Qt::Vertical);
280 GroupConstructors->layout()->setSpacing(0);
281 GroupConstructors->layout()->setMargin(0);
282 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
283 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
284 GroupConstructorsLayout->setSpacing(6);
285 GroupConstructorsLayout->setMargin(11);
286 Constructor1 = new QRadioButton(GroupConstructors, "Constructor1");
287 Constructor1->setText(tr("" ));
288 Constructor1->setPixmap(image0);
289 Constructor1->setChecked(TRUE);
290 GroupConstructorsLayout->addWidget(Constructor1, 0, 0);
291 QSpacerItem* spacer_2 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
292 GroupConstructorsLayout->addItem(spacer_2, 0, 1);
293 SMESHGUI_NodesDlgLayout->addWidget(GroupConstructors, 0, 0);
295 /***************************************************************/
296 GroupCoordinates = new QGroupBox(this, "GroupCoordinates");
297 GroupCoordinates->setTitle(tr("SMESH_COORDINATES" ));
298 GroupCoordinates->setColumnLayout(0, Qt::Vertical);
299 GroupCoordinates->layout()->setSpacing(0);
300 GroupCoordinates->layout()->setMargin(0);
301 GroupCoordinatesLayout = new QGridLayout(GroupCoordinates->layout());
302 GroupCoordinatesLayout->setAlignment(Qt::AlignTop);
303 GroupCoordinatesLayout->setSpacing(6);
304 GroupCoordinatesLayout->setMargin(11);
305 TextLabel_X = new QLabel(GroupCoordinates, "TextLabel_X");
306 TextLabel_X->setText(tr("SMESH_X" ));
307 GroupCoordinatesLayout->addWidget(TextLabel_X, 0, 0);
308 TextLabel_Y = new QLabel(GroupCoordinates, "TextLabel_Y");
309 TextLabel_Y->setText(tr("SMESH_Y" ));
310 GroupCoordinatesLayout->addWidget(TextLabel_Y, 0, 2);
312 TextLabel_Z = new QLabel(GroupCoordinates, "TextLabel_Z");
313 TextLabel_Z->setText(tr("SMESH_Z" ));
314 GroupCoordinatesLayout->addWidget(TextLabel_Z, 0, 4);
316 SpinBox_X = new SMESHGUI_SpinBox(GroupCoordinates, "SpinBox_X");
317 GroupCoordinatesLayout->addWidget(SpinBox_X, 0, 1);
319 SpinBox_Y = new SMESHGUI_SpinBox(GroupCoordinates, "SpinBox_Y");
320 GroupCoordinatesLayout->addWidget(SpinBox_Y, 0, 3);
322 SpinBox_Z = new SMESHGUI_SpinBox(GroupCoordinates, "SpinBox_Z");
323 GroupCoordinatesLayout->addWidget(SpinBox_Z, 0, 5);
325 SMESHGUI_NodesDlgLayout->addWidget(GroupCoordinates, 1, 0);
327 /* Initialisation and display */
331 //=======================================================================
332 // function : ~SMESHGUI_NodesDlg()
333 // purpose : Destructor
334 //=======================================================================
335 SMESHGUI_NodesDlg::~SMESHGUI_NodesDlg()
340 //=================================================================================
343 //=================================================================================
344 void SMESHGUI_NodesDlg::Init ()
346 /* Get setting of step value from file configuration */
348 // QString St = SUIT_CONFIG->getSetting("xxxxxxxxxxxxx"); TODO
349 // step = St.toDouble(); TODO
352 /* min, max, step and decimals for spin boxes */
353 SpinBox_X->RangeStepAndValidator(-999.999, +999.999, step, 3);
354 SpinBox_Y->RangeStepAndValidator(-999.999, +999.999, step, 3);
355 SpinBox_Z->RangeStepAndValidator(-999.999, +999.999, step, 3);
356 SpinBox_X->SetValue(0.0);
357 SpinBox_Y->SetValue(0.0);
358 SpinBox_Z->SetValue(0.0);
360 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
362 /* signals and slots connections */
363 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
364 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
365 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
367 connect(SpinBox_X, SIGNAL (valueChanged(double)), SLOT(ValueChangedInSpinBox(double)));
368 connect(SpinBox_Y, SIGNAL (valueChanged(double)), SLOT(ValueChangedInSpinBox(double)));
369 connect(SpinBox_Z, SIGNAL (valueChanged(double)), SLOT(ValueChangedInSpinBox(double)));
371 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
372 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
373 /* to close dialog if study frame change */
374 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
376 /* Move widget on the botton right corner of main widget */
378 mySMESHGUI->DefineDlgPosition(this, x, y);
382 // set selection mode
383 SMESH::SetPointRepresentation(true);
384 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
385 aViewWindow->SetSelectionMode(NodeSelection);
387 SelectionIntoArgument();
390 //=================================================================================
391 // function : ValueChangedInSpinBox()
393 //=================================================================================
394 void SMESHGUI_NodesDlg::ValueChangedInSpinBox (double newValue)
396 if (!myMesh->_is_nil()) {
397 double vx = SpinBox_X->GetValue();
398 double vy = SpinBox_Y->GetValue();
399 double vz = SpinBox_Z->GetValue();
401 mySimulation->SetPosition(vx,vy,vz);
405 //=================================================================================
406 // function : ClickOnOk()
408 //=================================================================================
409 void SMESHGUI_NodesDlg::ClickOnOk()
415 //=================================================================================
416 // function : ClickOnApply()
418 //=================================================================================
419 bool SMESHGUI_NodesDlg::ClickOnApply()
421 if (mySMESHGUI->isActiveStudyLocked())
424 if (myMesh->_is_nil()) {
425 SUIT_MessageBox::warn1(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"),
426 tr("MESH_IS_NOT_SELECTED"), tr("SMESH_BUT_OK"));
430 /* Recup args and call method */
431 double x = SpinBox_X->GetValue();
432 double y = SpinBox_Y->GetValue();
433 double z = SpinBox_Z->GetValue();
434 mySimulation->SetVisibility(false);
435 SMESH::AddNode(myMesh,x,y,z);
436 SMESH::SetPointRepresentation(true);
440 mySelectionMgr->selectedObjects(aList);
441 if (aList.Extent() != 1) {
442 if (SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView()) {
443 vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
444 aCollection->InitTraversal();
445 while (vtkActor *anAct = aCollection->GetNextActor()) {
446 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
447 if (anActor->hasIO()) {
448 if (SMESH_MeshObj *aMeshObj = dynamic_cast<SMESH_MeshObj*>(anActor->GetObject().get())) {
449 if (myMesh->_is_equivalent(aMeshObj->GetMeshServer())) {
451 aList.Append(anActor->getIO());
452 mySelectionMgr->setSelectedObjects(aList, false);
464 //=================================================================================
465 // function : ClickOnCancel()
467 //=================================================================================
468 void SMESHGUI_NodesDlg::ClickOnCancel()
470 disconnect(mySelectionMgr, 0, this, 0);
471 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
472 aViewWindow->SetSelectionMode(ActorSelection);
474 mySimulation->SetVisibility(false);
475 SMESH::SetPointRepresentation(false);
476 mySMESHGUI->ResetState();
481 //=================================================================================
482 // function : SelectionIntoArgument()
483 // purpose : Called when selection as changed or other case
484 //=================================================================================
485 void SMESHGUI_NodesDlg::SelectionIntoArgument()
487 if (!GroupConstructors->isEnabled())
490 mySimulation->SetVisibility(false);
491 SMESH::SetPointRepresentation(true);
493 const SALOME_ListIO& aList = mySelector->StoredIObjects();
494 if (aList.Extent() == 1) {
495 Handle(SALOME_InteractiveObject) anIO = aList.First();
496 if (anIO->hasEntry()) {
497 myMesh = SMESH::GetMeshByIO(anIO);
498 if (myMesh->_is_nil()) return;
500 if (SMESH::GetNameOfSelectedNodes(mySelector,anIO,aText) == 1) {
501 if (SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh.in())) {
502 if (SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh()) {
503 if (const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
504 SpinBox_X->SetValue(aNode->X());
505 SpinBox_Y->SetValue(aNode->Y());
506 SpinBox_Z->SetValue(aNode->Z());
511 mySimulation->SetPosition(SpinBox_X->GetValue(),
512 SpinBox_Y->GetValue(),
513 SpinBox_Z->GetValue());
518 //=================================================================================
519 // function : closeEvent()
521 //=================================================================================
522 void SMESHGUI_NodesDlg::closeEvent (QCloseEvent*)
524 this->ClickOnCancel(); /* same than click on cancel button */
527 //=================================================================================
528 // function : hideEvent()
529 // purpose : caused by ESC key
530 //=================================================================================
531 void SMESHGUI_NodesDlg::hideEvent (QHideEvent*)
537 //=================================================================================
538 // function : enterEvent()
539 // purpose : to reactivate this dialog box when mouse enter onto the window
540 //=================================================================================
541 void SMESHGUI_NodesDlg::enterEvent(QEvent*)
543 if (!GroupConstructors->isEnabled())
544 ActivateThisDialog();
547 //=================================================================================
548 // function : DeactivateActiveDialog()
549 // purpose : public slot to deactivate if active
550 //=================================================================================
551 void SMESHGUI_NodesDlg::DeactivateActiveDialog()
553 if (GroupConstructors->isEnabled()) {
554 GroupConstructors->setEnabled(false);
555 GroupCoordinates->setEnabled(false);
556 GroupButtons->setEnabled(false);
557 mySimulation->SetVisibility(false);
558 mySMESHGUI->ResetState();
559 mySMESHGUI->SetActiveDialogBox(0);
563 //=================================================================================
564 // function : ActivateThisDialog()
566 //=================================================================================
567 void SMESHGUI_NodesDlg::ActivateThisDialog()
569 mySMESHGUI->EmitSignalDeactivateDialog();
570 GroupConstructors->setEnabled(true);
571 GroupCoordinates->setEnabled(true);
572 GroupButtons->setEnabled(true);
574 SMESH::SetPointRepresentation(true);
575 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
576 aViewWindow->SetSelectionMode(NodeSelection);
578 SelectionIntoArgument();