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_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_Application.h"
53 #include "LightApp_SelectionMgr.h"
55 #include "SVTK_Selector.h"
56 #include "SVTK_ViewWindow.h"
57 #include "VTKViewer_CellLocationsArray.h"
59 #include "SALOME_Actor.h"
60 #include "SALOME_ListIO.hxx"
62 #include "utilities.h"
66 #include <vtkIdList.h>
67 #include <vtkCellArray.h>
68 #include <vtkUnsignedCharArray.h>
69 #include <vtkUnstructuredGrid.h>
70 #include <vtkDataSetMapper.h>
71 #include <vtkActorCollection.h>
72 #include <vtkRenderer.h>
73 #include <vtkProperty.h>
76 #include <qbuttongroup.h>
78 #include <qgroupbox.h>
80 #include <qlineedit.h>
81 #include <qpushbutton.h>
82 #include <qradiobutton.h>
86 #include <qwhatsthis.h>
89 #include <qvalidator.h>
92 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
99 void AddNode (SMESH::SMESH_Mesh_ptr theMesh, float x, float y, float z)
101 SUIT_OverrideCursor wc;
103 _PTR(SObject) aSobj = SMESH::FindSObject(theMesh);
104 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
105 aMeshEditor->AddNode(x,y,z);
106 _PTR(Study) aStudy = GetActiveStudyDocument();
107 CORBA::Long anId = aStudy->StudyId();
108 if (TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId, aSobj->GetID().c_str())) {
109 aVisualObj->Update(true);
111 } catch (SALOME::SALOME_Exception& exc) {
112 INFOS("Follow exception was cought:\n\t" << exc.details.text);
113 } catch (const std::exception& exc) {
114 INFOS("Follow exception was cought:\n\t" << exc.what());
116 INFOS("Unknown exception was cought !!!");
120 class TNodeSimulation {
121 SVTK_ViewWindow* myViewWindow;
123 SALOME_Actor *myPreviewActor;
124 vtkDataSetMapper* myMapper;
128 TNodeSimulation(SVTK_ViewWindow* theViewWindow):
129 myViewWindow(theViewWindow)
131 vtkUnstructuredGrid* aGrid = vtkUnstructuredGrid::New();
134 myPoints = vtkPoints::New();
135 myPoints->SetNumberOfPoints(1);
136 myPoints->SetPoint(0,0.0,0.0,0.0);
139 vtkIdList *anIdList = vtkIdList::New();
140 anIdList->SetNumberOfIds(1);
142 vtkCellArray *aCells = vtkCellArray::New();
143 aCells->Allocate(2, 0);
145 vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
146 aCellTypesArray->SetNumberOfComponents(1);
147 aCellTypesArray->Allocate(1);
149 anIdList->SetId(0, 0);
150 aCells->InsertNextCell(anIdList);
151 aCellTypesArray->InsertNextValue(VTK_VERTEX);
153 VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
154 aCellLocationsArray->SetNumberOfComponents(1);
155 aCellLocationsArray->SetNumberOfTuples(1);
157 aCells->InitTraversal();
159 aCellLocationsArray->SetValue(0, aCells->GetTraversalLocation(npts));
161 aGrid->SetCells(aCellTypesArray, aCellLocationsArray, aCells);
163 aGrid->SetPoints(myPoints);
164 aGrid->SetCells(aCellTypesArray, aCellLocationsArray,aCells);
165 aCellLocationsArray->Delete();
166 aCellTypesArray->Delete();
170 // Create and display actor
171 myMapper = vtkDataSetMapper::New();
172 myMapper->SetInput(aGrid);
175 myPreviewActor = SALOME_Actor::New();
176 myPreviewActor->SetInfinitive(true);
177 myPreviewActor->VisibilityOff();
178 myPreviewActor->PickableOff();
179 myPreviewActor->SetMapper(myMapper);
181 vtkProperty* aProp = vtkProperty::New();
182 aProp->SetRepresentationToPoints();
184 vtkFloatingPointType anRGB[3];
185 GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 0 ) );
186 aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
188 vtkFloatingPointType aPointSize = GetFloat( "SMESH:node_size", 3 );
189 aProp->SetPointSize( aPointSize );
191 myPreviewActor->SetProperty( aProp );
194 myViewWindow->AddActor(myPreviewActor);
197 void SetPosition (float x, float y, float z)
199 myPoints->SetPoint(0,x,y,z);
200 myPoints->Modified();
204 void SetVisibility (bool theVisibility)
206 myPreviewActor->SetVisibility(theVisibility);
207 RepaintCurrentView();
212 myViewWindow->RemoveActor(myPreviewActor);
213 myPreviewActor->Delete();
215 myMapper->RemoveAllInputs();
223 //=================================================================================
224 // class : SMESHGUI_NodesDlg()
226 //=================================================================================
227 SMESHGUI_NodesDlg::SMESHGUI_NodesDlg (SMESHGUI* theModule,
231 QDialog(SMESH::GetDesktop(theModule),
234 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
235 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
236 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
237 mySMESHGUI(theModule)
239 mySimulation = new SMESH::TNodeSimulation(SMESH::GetViewWindow( mySMESHGUI ));
241 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_NODE")));
243 setName("SMESHGUI_NodesDlg");
245 setCaption(tr("MESH_NODE_TITLE"));
246 setSizeGripEnabled(TRUE);
247 SMESHGUI_NodesDlgLayout = new QGridLayout(this);
248 SMESHGUI_NodesDlgLayout->setSpacing(6);
249 SMESHGUI_NodesDlgLayout->setMargin(11);
251 /***************************************************************/
252 GroupButtons = new QGroupBox(this, "GroupButtons");
253 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
254 GroupButtons->setTitle(tr("" ));
255 GroupButtons->setColumnLayout(0, Qt::Vertical);
256 GroupButtons->layout()->setSpacing(0);
257 GroupButtons->layout()->setMargin(0);
258 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
259 GroupButtonsLayout->setAlignment(Qt::AlignTop);
260 GroupButtonsLayout->setSpacing(6);
261 GroupButtonsLayout->setMargin(11);
262 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
263 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
264 buttonHelp->setAutoDefault(TRUE);
265 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
266 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
267 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
268 buttonCancel->setAutoDefault(TRUE);
269 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
270 buttonApply = new QPushButton(GroupButtons, "buttonApply");
271 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
272 buttonApply->setAutoDefault(TRUE);
273 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
274 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
275 GroupButtonsLayout->addItem(spacer_9, 0, 2);
276 buttonOk = new QPushButton(GroupButtons, "buttonOk");
277 buttonOk->setText(tr("SMESH_BUT_OK" ));
278 buttonOk->setAutoDefault(TRUE);
279 buttonOk->setDefault(TRUE);
280 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
281 SMESHGUI_NodesDlgLayout->addWidget(GroupButtons, 2, 0);
283 /***************************************************************/
284 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
285 GroupConstructors->setTitle(tr("MESH_NODE" ));
286 GroupConstructors->setExclusive(TRUE);
287 GroupConstructors->setColumnLayout(0, Qt::Vertical);
288 GroupConstructors->layout()->setSpacing(0);
289 GroupConstructors->layout()->setMargin(0);
290 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
291 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
292 GroupConstructorsLayout->setSpacing(6);
293 GroupConstructorsLayout->setMargin(11);
294 Constructor1 = new QRadioButton(GroupConstructors, "Constructor1");
295 Constructor1->setText(tr("" ));
296 Constructor1->setPixmap(image0);
297 Constructor1->setChecked(TRUE);
298 GroupConstructorsLayout->addWidget(Constructor1, 0, 0);
299 QSpacerItem* spacer_2 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
300 GroupConstructorsLayout->addItem(spacer_2, 0, 1);
301 SMESHGUI_NodesDlgLayout->addWidget(GroupConstructors, 0, 0);
303 /***************************************************************/
304 GroupCoordinates = new QGroupBox(this, "GroupCoordinates");
305 GroupCoordinates->setTitle(tr("SMESH_COORDINATES" ));
306 GroupCoordinates->setColumnLayout(0, Qt::Vertical);
307 GroupCoordinates->layout()->setSpacing(0);
308 GroupCoordinates->layout()->setMargin(0);
309 GroupCoordinatesLayout = new QGridLayout(GroupCoordinates->layout());
310 GroupCoordinatesLayout->setAlignment(Qt::AlignTop);
311 GroupCoordinatesLayout->setSpacing(6);
312 GroupCoordinatesLayout->setMargin(11);
314 TextLabel_X = new QLabel(GroupCoordinates, "TextLabel_X");
315 TextLabel_X->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
316 TextLabel_X->setText(tr("SMESH_X" ));
317 GroupCoordinatesLayout->addWidget(TextLabel_X, 0, 0);
319 TextLabel_Y = new QLabel(GroupCoordinates, "TextLabel_Y");
320 //TextLabel_Y->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
321 TextLabel_Y->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
322 TextLabel_Y->setText(tr("SMESH_Y" ));
323 GroupCoordinatesLayout->addWidget(TextLabel_Y, 0, 2);
325 TextLabel_Z = new QLabel(GroupCoordinates, "TextLabel_Z");
326 //TextLabel_Z->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs );
327 TextLabel_Z->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
328 TextLabel_Z->setText(tr("SMESH_Z" ));
329 GroupCoordinatesLayout->addWidget(TextLabel_Z, 0, 4);
331 SpinBox_X = new SMESHGUI_SpinBox(GroupCoordinates, "SpinBox_X");
332 GroupCoordinatesLayout->addWidget(SpinBox_X, 0, 1);
334 SpinBox_Y = new SMESHGUI_SpinBox(GroupCoordinates, "SpinBox_Y");
335 GroupCoordinatesLayout->addWidget(SpinBox_Y, 0, 3);
337 SpinBox_Z = new SMESHGUI_SpinBox(GroupCoordinates, "SpinBox_Z");
338 GroupCoordinatesLayout->addWidget(SpinBox_Z, 0, 5);
340 SMESHGUI_NodesDlgLayout->addWidget(GroupCoordinates, 1, 0);
342 myHelpFileName = "/files/adding_nodes_and_elements.htm#Adding_nodes";
344 /* Initialisation and display */
348 //=======================================================================
349 // function : ~SMESHGUI_NodesDlg()
350 // purpose : Destructor
351 //=======================================================================
352 SMESHGUI_NodesDlg::~SMESHGUI_NodesDlg()
357 //=================================================================================
360 //=================================================================================
361 void SMESHGUI_NodesDlg::Init ()
363 /* Get setting of step value from file configuration */
365 // QString St = SUIT_CONFIG->getSetting("xxxxxxxxxxxxx"); TODO
366 // step = St.toDouble(); TODO
369 /* min, max, step and decimals for spin boxes */
370 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
371 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
372 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, step, DBL_DIGITS_DISPLAY);
373 SpinBox_X->SetValue(0.0);
374 SpinBox_Y->SetValue(0.0);
375 SpinBox_Z->SetValue(0.0);
377 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
379 /* signals and slots connections */
380 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
381 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
382 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
383 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
385 connect(SpinBox_X, SIGNAL (valueChanged(double)), SLOT(ValueChangedInSpinBox(double)));
386 connect(SpinBox_Y, SIGNAL (valueChanged(double)), SLOT(ValueChangedInSpinBox(double)));
387 connect(SpinBox_Z, SIGNAL (valueChanged(double)), SLOT(ValueChangedInSpinBox(double)));
389 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
390 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
391 /* to close dialog if study frame change */
392 connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
396 // set selection mode
397 SMESH::SetPointRepresentation(true);
398 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
399 aViewWindow->SetSelectionMode(NodeSelection);
401 SelectionIntoArgument();
404 //=================================================================================
405 // function : ValueChangedInSpinBox()
407 //=================================================================================
408 void SMESHGUI_NodesDlg::ValueChangedInSpinBox (double newValue)
410 if (!myMesh->_is_nil()) {
411 double vx = SpinBox_X->GetValue();
412 double vy = SpinBox_Y->GetValue();
413 double vz = SpinBox_Z->GetValue();
415 mySimulation->SetPosition(vx,vy,vz);
419 //=================================================================================
420 // function : ClickOnOk()
422 //=================================================================================
423 void SMESHGUI_NodesDlg::ClickOnOk()
429 //=================================================================================
430 // function : ClickOnApply()
432 //=================================================================================
433 bool SMESHGUI_NodesDlg::ClickOnApply()
435 if (mySMESHGUI->isActiveStudyLocked())
438 if (myMesh->_is_nil()) {
439 SUIT_MessageBox::warn1(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"),
440 tr("MESH_IS_NOT_SELECTED"), tr("SMESH_BUT_OK"));
444 /* Recup args and call method */
445 double x = SpinBox_X->GetValue();
446 double y = SpinBox_Y->GetValue();
447 double z = SpinBox_Z->GetValue();
448 mySimulation->SetVisibility(false);
449 SMESH::AddNode(myMesh,x,y,z);
450 SMESH::SetPointRepresentation(true);
454 mySelectionMgr->selectedObjects(aList);
455 if (aList.Extent() != 1) {
456 if (SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView()) {
457 vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
458 aCollection->InitTraversal();
459 while (vtkActor *anAct = aCollection->GetNextActor()) {
460 if (SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)) {
461 if (anActor->hasIO()) {
462 if (SMESH_MeshObj *aMeshObj = dynamic_cast<SMESH_MeshObj*>(anActor->GetObject().get())) {
463 if (myMesh->_is_equivalent(aMeshObj->GetMeshServer())) {
465 aList.Append(anActor->getIO());
466 mySelectionMgr->setSelectedObjects(aList, false);
478 //=================================================================================
479 // function : ClickOnCancel()
481 //=================================================================================
482 void SMESHGUI_NodesDlg::ClickOnCancel()
484 disconnect(mySelectionMgr, 0, this, 0);
485 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
486 aViewWindow->SetSelectionMode(ActorSelection);
488 mySimulation->SetVisibility(false);
489 SMESH::SetPointRepresentation(false);
490 mySMESHGUI->ResetState();
495 //=================================================================================
496 // function : ClickOnHelp()
498 //=================================================================================
499 void SMESHGUI_NodesDlg::ClickOnHelp()
501 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
503 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
507 platform = "winapplication";
509 platform = "application";
511 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
512 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
513 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
514 QObject::tr("BUT_OK"));
518 //=================================================================================
519 // function : SelectionIntoArgument()
520 // purpose : Called when selection as changed or other case
521 //=================================================================================
522 void SMESHGUI_NodesDlg::SelectionIntoArgument()
524 if (!GroupConstructors->isEnabled())
527 mySimulation->SetVisibility(false);
528 SMESH::SetPointRepresentation(true);
530 const SALOME_ListIO& aList = mySelector->StoredIObjects();
531 if (aList.Extent() == 1) {
532 Handle(SALOME_InteractiveObject) anIO = aList.First();
533 if (anIO->hasEntry()) {
534 myMesh = SMESH::GetMeshByIO(anIO);
535 if (myMesh->_is_nil()) return;
537 if (SMESH::GetNameOfSelectedNodes(mySelector,anIO,aText) == 1) {
538 if (SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh.in())) {
539 if (SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh()) {
540 if (const SMDS_MeshNode* aNode = aMesh->FindNode(aText.toInt())) {
541 SpinBox_X->SetValue(aNode->X());
542 SpinBox_Y->SetValue(aNode->Y());
543 SpinBox_Z->SetValue(aNode->Z());
548 mySimulation->SetPosition(SpinBox_X->GetValue(),
549 SpinBox_Y->GetValue(),
550 SpinBox_Z->GetValue());
555 //=================================================================================
556 // function : closeEvent()
558 //=================================================================================
559 void SMESHGUI_NodesDlg::closeEvent (QCloseEvent*)
561 this->ClickOnCancel(); /* same than click on cancel button */
564 //=================================================================================
565 // function : hideEvent()
566 // purpose : caused by ESC key
567 //=================================================================================
568 void SMESHGUI_NodesDlg::hideEvent (QHideEvent*)
574 //=================================================================================
575 // function : enterEvent()
576 // purpose : to reactivate this dialog box when mouse enter onto the window
577 //=================================================================================
578 void SMESHGUI_NodesDlg::enterEvent(QEvent*)
580 if (!GroupConstructors->isEnabled())
581 ActivateThisDialog();
584 //=================================================================================
585 // function : DeactivateActiveDialog()
586 // purpose : public slot to deactivate if active
587 //=================================================================================
588 void SMESHGUI_NodesDlg::DeactivateActiveDialog()
590 if (GroupConstructors->isEnabled()) {
591 GroupConstructors->setEnabled(false);
592 GroupCoordinates->setEnabled(false);
593 GroupButtons->setEnabled(false);
594 mySimulation->SetVisibility(false);
595 mySMESHGUI->ResetState();
596 mySMESHGUI->SetActiveDialogBox(0);
600 //=================================================================================
601 // function : ActivateThisDialog()
603 //=================================================================================
604 void SMESHGUI_NodesDlg::ActivateThisDialog()
606 mySMESHGUI->EmitSignalDeactivateDialog();
607 GroupConstructors->setEnabled(true);
608 GroupCoordinates->setEnabled(true);
609 GroupButtons->setEnabled(true);
611 SMESH::SetPointRepresentation(true);
612 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
613 aViewWindow->SetSelectionMode(NodeSelection);
615 SelectionIntoArgument();
618 //=================================================================================
619 // function : keyPressEvent()
621 //=================================================================================
622 void SMESHGUI_NodesDlg::keyPressEvent( QKeyEvent* e )
624 QDialog::keyPressEvent( e );
625 if ( e->isAccepted() )
628 if ( e->key() == Key_F1 )