1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2005 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 // File : SMESHGUI_EditMeshDlg.cxx
23 // Author : Open CASCADE S.A.S.
27 #include "SMESHGUI_EditMeshDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_SpinBox.h"
35 #include <SMESH_Actor.h>
36 #include <SMESH_TypeFilter.hxx>
37 #include <SMESH_LogicalFilter.hxx>
38 #include <SMDS_Mesh.hxx>
40 // SALOME GUI includes
41 #include <SUIT_Desktop.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
46 #include <LightApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
49 #include <SVTK_ViewModel.h>
50 #include <SVTK_ViewWindow.h>
51 #include <SALOME_ListIO.hxx>
54 #include <TColStd_MapOfInteger.hxx>
55 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
58 #include <SALOMEconfig.h>
59 #include CORBA_SERVER_HEADER(SMESH_Group)
60 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
63 #include <vtkUnstructuredGrid.h>
64 #include <vtkRenderer.h>
65 #include <vtkActor2D.h>
66 #include <vtkPoints.h>
67 #include <vtkDataSetMapper.h>
68 #include <vtkMaskPoints.h>
69 #include <vtkSelectVisiblePoints.h>
70 #include <vtkLabeledDataMapper.h>
71 #include <vtkTextProperty.h>
72 #include <vtkIntArray.h>
73 #include <vtkProperty2D.h>
74 #include <vtkPointData.h>
77 #include <QApplication>
81 #include <QListWidget>
82 #include <QPushButton>
83 #include <QRadioButton>
85 #include <QHBoxLayout>
86 #include <QVBoxLayout>
87 #include <QGridLayout>
89 #include <QButtonGroup>
97 { // to display in the viewer IDs of the selected elements
98 SVTK_ViewWindow* myViewWindow;
100 vtkUnstructuredGrid* myIdGrid;
101 SALOME_Actor* myIdActor;
103 vtkUnstructuredGrid* myPointsNumDataSet;
104 vtkMaskPoints* myPtsMaskPoints;
105 vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
106 vtkLabeledDataMapper* myPtsLabeledDataMapper;
107 vtkTextProperty* aPtsTextProp;
108 bool myIsPointsLabeled;
109 vtkActor2D* myPointLabels;
111 std::vector<int> myIDs;
114 TIdPreview(SVTK_ViewWindow* theViewWindow):
115 myViewWindow(theViewWindow)
117 myIdGrid = vtkUnstructuredGrid::New();
119 // Create and display actor
120 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
121 aMapper->SetInput( myIdGrid );
123 myIdActor = SALOME_Actor::New();
124 myIdActor->SetInfinitive(true);
125 myIdActor->VisibilityOff();
126 myIdActor->PickableOff();
128 myIdActor->SetMapper( aMapper );
131 myViewWindow->AddActor(myIdActor);
133 //Definition of points numbering pipeline
134 myPointsNumDataSet = vtkUnstructuredGrid::New();
136 myPtsMaskPoints = vtkMaskPoints::New();
137 myPtsMaskPoints->SetInput(myPointsNumDataSet);
138 myPtsMaskPoints->SetOnRatio(1);
140 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
141 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
142 myPtsSelectVisiblePoints->SelectInvisibleOff();
143 myPtsSelectVisiblePoints->SetTolerance(0.1);
145 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
146 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
147 myPtsLabeledDataMapper->SetLabelFormat("%g");
148 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
150 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
151 aPtsTextProp->SetFontFamilyToTimes();
152 static int aPointsFontSize = 12;
153 aPtsTextProp->SetFontSize(aPointsFontSize);
154 aPtsTextProp->SetBold(1);
155 aPtsTextProp->SetItalic(0);
156 aPtsTextProp->SetShadow(0);
157 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
158 aPtsTextProp->Delete();
160 myIsPointsLabeled = false;
162 myPointLabels = vtkActor2D::New();
163 myPointLabels->SetMapper(myPtsLabeledDataMapper);
164 myPointLabels->GetProperty()->SetColor(1,1,1);
165 myPointLabels->SetVisibility(myIsPointsLabeled);
167 AddToRender(myViewWindow->getRenderer());
170 void SetPointsData ( SMDS_Mesh* theMesh,
171 TColStd_MapOfInteger & theNodesIdMap )
173 vtkPoints* aPoints = vtkPoints::New();
174 aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
177 TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
178 for( int i = 0; idIter.More(); idIter.Next(), i++ ) {
179 const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
180 aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
181 myIDs.push_back(idIter.Key());
184 myIdGrid->SetPoints(aPoints);
188 myIdActor->GetMapper()->Update();
191 void SetElemsData( TColStd_MapOfInteger & theElemsIdMap,
192 std::list<gp_XYZ> & aGrCentersXYZ )
194 vtkPoints* aPoints = vtkPoints::New();
195 aPoints->SetNumberOfPoints(theElemsIdMap.Extent());
198 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
199 for( ; idIter.More(); idIter.Next() ) {
200 myIDs.push_back(idIter.Key());
204 std::list<gp_XYZ>::iterator coordIt = aGrCentersXYZ.begin();
205 for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ ) {
207 aPoints->SetPoint( i, aXYZ.X(), aXYZ.Y(), aXYZ.Z() );
209 myIdGrid->SetPoints(aPoints);
212 myIdActor->GetMapper()->Update();
215 void AddToRender(vtkRenderer* theRenderer)
217 myIdActor->AddToRender(theRenderer);
219 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
220 theRenderer->AddActor2D(myPointLabels);
223 void RemoveFromRender(vtkRenderer* theRenderer)
225 myIdActor->RemoveFromRender(theRenderer);
227 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
228 theRenderer->RemoveActor(myPointLabels);
231 void SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible = true )
233 myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
235 if ( myIsPointsLabeled ) {
236 myPointsNumDataSet->ShallowCopy(myIdGrid);
237 vtkDataSet *aDataSet = myPointsNumDataSet;
238 int aNbElem = myIDs.size();
239 vtkIntArray *anArray = vtkIntArray::New();
240 anArray->SetNumberOfValues( aNbElem );
241 for ( int i = 0; i < aNbElem; i++ )
242 anArray->SetValue( i, myIDs[i] );
243 aDataSet->GetPointData()->SetScalars( anArray );
245 myPtsMaskPoints->SetInput( aDataSet );
246 myPointLabels->SetVisibility( theIsActorVisible );
249 myPointLabels->SetVisibility( false );
255 RemoveFromRender(myViewWindow->getRenderer());
259 myViewWindow->RemoveActor(myIdActor);
262 //Deleting of points numbering pipeline
263 //---------------------------------------
264 myPointsNumDataSet->Delete();
266 //myPtsLabeledDataMapper->RemoveAllInputs(); //vtk 5.0 porting
267 myPtsLabeledDataMapper->Delete();
269 //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
270 myPtsSelectVisiblePoints->Delete();
272 //myPtsMaskPoints->UnRegisterAllOutputs(); //vtk 5.0 porting
273 myPtsMaskPoints->Delete();
275 myPointLabels->Delete();
277 // myTimeStamp->Delete();
282 static const char * IconFirst[] = {
297 //=================================================================================
298 // class : SMESHGUI_EditMeshDlg()
300 //=================================================================================
301 SMESHGUI_EditMeshDlg::SMESHGUI_EditMeshDlg (SMESHGUI* theModule,
303 : QDialog(SMESH::GetDesktop(theModule)),
304 mySMESHGUI(theModule),
305 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
309 setAttribute(Qt::WA_DeleteOnClose, true);
310 setWindowTitle(myAction == 1 ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
312 myIdPreview = new SMESH::TIdPreview(SMESH::GetViewWindow( mySMESHGUI ));
314 SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
315 QPixmap IconMergeNodes (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
316 QPixmap IconMergeElems (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_MERGE_ELEMENTS")));
317 QPixmap IconSelect (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
318 QPixmap IconAdd (aResMgr->loadPixmap("SMESH", tr("ICON_APPEND")));
319 QPixmap IconRemove (aResMgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
321 setSizeGripEnabled(true);
323 QVBoxLayout* DlgLayout = new QVBoxLayout(this);
324 DlgLayout->setSpacing(SPACING);
325 DlgLayout->setMargin(MARGIN);
327 /***************************************************************/
328 GroupConstructors = new QGroupBox(myAction == 1 ?
329 tr("SMESH_MERGE_ELEMENTS") :
330 tr("SMESH_MERGE_NODES"),
333 QButtonGroup* ButtonGroup = new QButtonGroup(this);
334 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
335 GroupConstructorsLayout->setSpacing(SPACING);
336 GroupConstructorsLayout->setMargin(MARGIN);
338 RadioButton = new QRadioButton(GroupConstructors);
339 RadioButton->setIcon(myAction == 1 ? IconMergeElems : IconMergeNodes);
340 RadioButton->setChecked(true);
341 GroupConstructorsLayout->addWidget(RadioButton);
342 ButtonGroup->addButton(RadioButton, 0);
344 /***************************************************************/
345 // Controls for mesh defining
346 GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), this);
347 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
348 GroupMeshLayout->setSpacing(SPACING);
349 GroupMeshLayout->setMargin(MARGIN);
351 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupMesh);
352 SelectMeshButton = new QPushButton(GroupMesh);
353 SelectMeshButton->setIcon(IconSelect);
354 LineEditMesh = new QLineEdit(GroupMesh);
355 LineEditMesh->setReadOnly(true);
357 GroupMeshLayout->addWidget(TextLabelName);
358 GroupMeshLayout->addWidget(SelectMeshButton);
359 GroupMeshLayout->addWidget(LineEditMesh);
361 /***************************************************************/
362 // Controls for coincident elements detecting
363 GroupCoincident = new QGroupBox(myAction == 1 ?
364 tr("COINCIDENT_ELEMENTS") :
365 tr("COINCIDENT_NODES"),
368 QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincident);
369 GroupCoincidentLayout->setSpacing(SPACING);
370 GroupCoincidentLayout->setMargin(MARGIN);
372 if (myAction == 0) { // case merge nodes
373 TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), GroupCoincident);
374 SpinBoxTolerance = new SMESHGUI_SpinBox(GroupCoincident);
375 SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
377 GroupCoincidentLayout->addWidget(TextLabelTolerance, 0, 0);
378 GroupCoincidentLayout->addWidget(SpinBoxTolerance, 0, 1);
381 TextLabelTolerance = 0;
382 SpinBoxTolerance = 0;
385 int row = GroupCoincidentLayout->rowCount();
387 ListCoincident = new QListWidget(GroupCoincident);
388 ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
390 DetectButton = new QPushButton(tr("DETECT"), GroupCoincident);
391 AddGroupButton = new QPushButton(tr("SMESH_BUT_ADD"), GroupCoincident);
392 RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincident);
394 SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincident);
396 GroupCoincidentLayout->addWidget(ListCoincident, row, 0, 4, 2);
397 GroupCoincidentLayout->addWidget(DetectButton, row, 2);
398 GroupCoincidentLayout->addWidget(AddGroupButton, row+2, 2);
399 GroupCoincidentLayout->addWidget(RemoveGroupButton, row+3, 2);
400 GroupCoincidentLayout->addWidget(SelectAllCB, row+4, 0, 1, 3);
401 GroupCoincidentLayout->setRowMinimumHeight(row+1, 10);
402 GroupCoincidentLayout->setRowStretch(row+1, 5);
404 /***************************************************************/
405 // Controls for editing the selected group
406 GroupEdit = new QGroupBox(tr("EDIT_SELECTED_GROUP"), this);
407 QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
408 GroupEditLayout->setSpacing(SPACING);
409 GroupEditLayout->setMargin(MARGIN);
411 ListEdit = new QListWidget(GroupEdit);
412 //ListEdit->setRowMode(QListBox::FixedNumber);
413 //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
414 //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
415 ListEdit->setFlow( QListView::LeftToRight );
416 ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
418 AddElemButton = new QPushButton(GroupEdit);
419 AddElemButton->setIcon(IconAdd);
420 RemoveElemButton = new QPushButton(GroupEdit);
421 RemoveElemButton->setIcon(IconRemove);
422 SetFirstButton = new QPushButton(GroupEdit);
423 SetFirstButton->setIcon(QPixmap(IconFirst));
425 GroupEditLayout->addWidget(ListEdit, 0, 0, 2, 1);
426 GroupEditLayout->addWidget(AddElemButton, 0, 1);
427 GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
428 GroupEditLayout->addWidget(SetFirstButton, 1, 1, 1, 2);
430 /***************************************************************/
431 GroupButtons = new QGroupBox(this);
432 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
433 GroupButtonsLayout->setSpacing(SPACING);
434 GroupButtonsLayout->setMargin(MARGIN);
436 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
437 buttonOk->setAutoDefault(true);
438 buttonOk->setDefault(true);
439 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
440 buttonApply->setAutoDefault(true);
441 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
442 buttonCancel->setAutoDefault(true);
443 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
444 buttonHelp->setAutoDefault(true);
446 GroupButtonsLayout->addWidget(buttonOk);
447 GroupButtonsLayout->addSpacing(10);
448 GroupButtonsLayout->addWidget(buttonApply);
449 GroupButtonsLayout->addSpacing(10);
450 GroupButtonsLayout->addStretch();
451 GroupButtonsLayout->addWidget(buttonCancel);
452 GroupButtonsLayout->addWidget(buttonHelp);
454 /***************************************************************/
455 DlgLayout->addWidget(GroupConstructors);
456 DlgLayout->addWidget(GroupMesh);
457 DlgLayout->addWidget(GroupCoincident);
458 DlgLayout->addWidget(GroupEdit);
459 DlgLayout->addWidget(GroupButtons);
461 Init(); // Initialisations
464 //=================================================================================
465 // function : ~SMESHGUI_EditMeshDlg()
466 // purpose : Destroys the object and frees any allocated resources
467 //=================================================================================
468 SMESHGUI_EditMeshDlg::~SMESHGUI_EditMeshDlg()
473 //=================================================================================
476 //=================================================================================
477 void SMESHGUI_EditMeshDlg::Init()
480 SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, 5);
481 SpinBoxTolerance->SetValue(1e-05);
484 RadioButton->setChecked(true);
486 myEditCurrentArgument = (QWidget*)LineEditMesh;
489 mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
491 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
493 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
496 // Costruction of the logical filter
497 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
498 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
500 QList<SUIT_SelectionFilter*> aListOfFilters;
501 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
502 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
504 myMeshOrSubMeshOrGroupFilter =
505 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
507 /* signals and slots connections */
508 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
509 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
510 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
511 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
513 connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
514 connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
515 connect(ListCoincident, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectGroup()));
516 connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
517 connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
518 connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
519 connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
520 connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
521 connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
522 connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst() ) );
524 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
525 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
526 /* to close dialog if study change */
527 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
529 SetFirstButton->setEnabled(false);
530 buttonOk->setEnabled(false);
531 buttonApply->setEnabled(false);
533 // Init Mesh field from selection
534 SelectionIntoArgument();
536 myHelpFileName = "merging_elements_page.html";
539 //=================================================================================
540 // function : FindGravityCenter()
542 //=================================================================================
543 void SMESHGUI_EditMeshDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap,
544 std::list< gp_XYZ > & theGrCentersXYZ)
549 SMDS_Mesh* aMesh = 0;
550 aMesh = myActor->GetObject()->GetMesh();
556 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
557 for( ; idIter.More(); idIter.Next() ) {
558 const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
562 gp_XYZ anXYZ(0., 0., 0.);
563 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
564 for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
565 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
566 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
568 anXYZ.Divide( nbNodes );
570 theGrCentersXYZ.push_back( anXYZ );
574 //=================================================================================
575 // function : ClickOnApply()
577 //=================================================================================
578 bool SMESHGUI_EditMeshDlg::ClickOnApply()
580 if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
584 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
586 QApplication::setOverrideCursor(Qt::WaitCursor);
588 SMESH::long_array_var anIds = new SMESH::long_array;
589 SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
591 aGroupsOfElements->length(ListCoincident->count());
594 for (int i = 0; i < ListCoincident->count(); i++) {
595 QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
597 anIds->length(aListIds.count());
598 for (int i = 0; i < aListIds.count(); i++)
599 anIds[i] = aListIds[i].toInt();
601 aGroupsOfElements[anArrayNum++] = anIds.inout();
605 aMeshEditor->MergeNodes (aGroupsOfElements.inout());
607 aMeshEditor->MergeElements (aGroupsOfElements.inout());
609 QApplication::restoreOverrideCursor();
619 //=================================================================================
620 // function : ClickOnOk()
622 //=================================================================================
623 void SMESHGUI_EditMeshDlg::ClickOnOk()
629 //=================================================================================
630 // function : ClickOnCancel()
632 //=================================================================================
633 void SMESHGUI_EditMeshDlg::ClickOnCancel()
635 myIdPreview->SetPointsLabeled(false);
636 mySelectionMgr->clearFilters();
637 //mySelectionMgr->clearSelected();
638 SMESH::SetPointRepresentation(false);
639 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
640 aViewWindow->SetSelectionMode(ActorSelection);
641 disconnect(mySelectionMgr, 0, this, 0);
642 mySMESHGUI->ResetState();
646 //=================================================================================
647 // function : ClickOnHelp()
649 //=================================================================================
650 void SMESHGUI_EditMeshDlg::ClickOnHelp()
652 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
654 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
658 platform = "winapplication";
660 platform = "application";
662 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
663 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
664 arg(app->resourceMgr()->stringValue("ExternalBrowser",
666 arg(myHelpFileName));
670 //=================================================================================
671 // function : onEditGroup()
673 //=================================================================================
674 void SMESHGUI_EditMeshDlg::onEditGroup()
676 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
677 if ( selItems.count() != 1 ) {
684 for (int i = 0; i < ListEdit->count(); i++ )
685 aNewIds.append(ListEdit->item(i)->text());
687 ListCoincident->clearSelection();
688 selItems.first()->setText(aNewIds.join(" "));
689 selItems.first()->setSelected(true);
692 //=================================================================================
693 // function : updateControls()
695 //=================================================================================
696 void SMESHGUI_EditMeshDlg::updateControls()
698 if (ListEdit->count() == 0)
699 SetFirstButton->setEnabled(false);
700 bool enable = !(myMesh->_is_nil()) && ListCoincident->count();
701 buttonOk->setEnabled(enable);
702 buttonApply->setEnabled(enable);
705 //=================================================================================
706 // function : onDetect()
708 //=================================================================================
709 void SMESHGUI_EditMeshDlg::onDetect()
711 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
715 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
717 QApplication::setOverrideCursor(Qt::WaitCursor);
718 ListCoincident->clear();
721 SMESH::array_of_long_array_var aGroupsArray;
725 if(!mySubMeshOrGroup->_is_nil())
726 aMeshEditor->FindCoincidentNodesOnPart(mySubMeshOrGroup, SpinBoxTolerance->GetValue(), aGroupsArray);
728 aMeshEditor->FindCoincidentNodes(SpinBoxTolerance->GetValue(), aGroupsArray);
731 if(!mySubMeshOrGroup->_is_nil())
732 aMeshEditor->FindEqualElements(mySubMeshOrGroup, aGroupsArray);
734 aMeshEditor->FindEqualElements(myMesh, aGroupsArray);
738 for (int i = 0; i < aGroupsArray->length(); i++) {
739 SMESH::long_array& aGroup = aGroupsArray[i];
742 for (int j = 0; j < aGroup.length(); j++)
743 anIDs.append(QString::number(aGroup[j]));
745 ListCoincident->addItem(anIDs.join(" "));
747 QApplication::restoreOverrideCursor();
751 ListCoincident->selectAll();
755 //=================================================================================
756 // function : onSelectGroup()
758 //=================================================================================
759 void SMESHGUI_EditMeshDlg::onSelectGroup()
761 if (myIsBusy || !myActor)
763 myEditCurrentArgument = (QWidget*)ListCoincident;
767 TColStd_MapOfInteger anIndices;
768 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
769 QListWidgetItem* anItem;
770 QStringList aListIds;
774 foreach(anItem, selItems) {
775 aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
776 for (int i = 0; i < aListIds.count(); i++)
777 anIndices.Add(aListIds[i].toInt());
780 if (selItems.count() == 1) {
781 ListEdit->addItems(aListIds);
782 ListEdit->selectAll();
785 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
787 aList.Append(myActor->getIO());
788 mySelectionMgr->setSelectedObjects(aList,false);
791 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
792 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
795 std::list< gp_XYZ > aGrCentersXYZ;
796 FindGravityCenter(anIndices, aGrCentersXYZ);
797 myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
798 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
804 //=================================================================================
805 // function : onSelectAll()
807 //=================================================================================
808 void SMESHGUI_EditMeshDlg::onSelectAll (bool isToggled)
811 ListCoincident->selectAll();
813 ListCoincident->clearSelection();
816 //=================================================================================
817 // function : onSelectElementFromGroup()
819 //=================================================================================
820 void SMESHGUI_EditMeshDlg::onSelectElementFromGroup()
822 if (myIsBusy || !myActor)
825 TColStd_MapOfInteger anIndices;
826 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
827 QListWidgetItem* anItem;
829 foreach(anItem, selItems)
830 anIndices.Add(anItem->text().toInt());
832 SetFirstButton->setEnabled(selItems.count() == 1);
834 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
836 aList.Append(myActor->getIO());
837 mySelectionMgr->setSelectedObjects(aList);
840 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
841 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
844 std::list< gp_XYZ > aGrCentersXYZ;
845 FindGravityCenter(anIndices, aGrCentersXYZ);
846 myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
847 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
851 //=================================================================================
852 // function : onAddGroup()
854 //=================================================================================
855 void SMESHGUI_EditMeshDlg::onAddGroup()
857 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
861 SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
863 ListCoincident->clearSelection();
864 ListCoincident->addItem(anIDs);
865 int nbGroups = ListCoincident->count();
867 ListCoincident->setCurrentRow(nbGroups-1);
868 ListCoincident->item(nbGroups-1)->setSelected(true);
871 // VSR ? this code seems to be never executed!!!
872 ListCoincident->setCurrentRow(0);
873 //ListCoincident->setSelected(0, true); // VSR: no items - no selection
879 //=================================================================================
880 // function : onRemoveGroup()
882 //=================================================================================
883 void SMESHGUI_EditMeshDlg::onRemoveGroup()
885 if (myEditCurrentArgument != (QWidget*)ListCoincident)
889 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
890 QListWidgetItem* anItem;
892 foreach(anItem, selItems)
901 //=================================================================================
902 // function : onAddElement()
904 //=================================================================================
905 void SMESHGUI_EditMeshDlg::onAddElement()
911 QString aListStr = "";
914 aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
918 QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
920 for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
921 QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
922 if ( found.count() == 0 ) {
923 QListWidgetItem* anItem = new QListWidgetItem(*it);
924 ListEdit->addItem(anItem);
925 anItem->setSelected(true);
928 QListWidgetItem* anItem;
929 foreach(anItem, found) anItem->setSelected(true);
937 //=================================================================================
938 // function : onRemoveElement()
940 //=================================================================================
941 void SMESHGUI_EditMeshDlg::onRemoveElement()
943 if (myEditCurrentArgument != (QWidget*)ListCoincident)
947 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
948 QListWidgetItem* anItem;
950 foreach(anItem, selItems)
957 //=================================================================================
958 // function : onSetFirst()
960 //=================================================================================
961 void SMESHGUI_EditMeshDlg::onSetFirst()
963 if (myEditCurrentArgument != (QWidget*)ListCoincident)
967 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
968 QListWidgetItem* anItem;
970 foreach(anItem, selItems) {
971 ListEdit->takeItem(ListEdit->row(anItem));
972 ListEdit->insertItem(0, anItem);
979 //=================================================================================
980 // function : SetEditCurrentArgument()
982 //=================================================================================
983 void SMESHGUI_EditMeshDlg::SetEditCurrentArgument()
985 QPushButton* send = (QPushButton*)sender();
987 disconnect(mySelectionMgr, 0, this, 0);
988 mySelectionMgr->clearSelected();
989 mySelectionMgr->clearFilters();
991 if (send == SelectMeshButton) {
992 myEditCurrentArgument = (QWidget*)LineEditMesh;
993 SMESH::SetPointRepresentation(false);
994 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
995 aViewWindow->SetSelectionMode(ActorSelection);
996 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
999 myEditCurrentArgument->setFocus();
1000 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1001 SelectionIntoArgument();
1004 //=================================================================================
1005 // function : SelectionIntoArgument()
1006 // purpose : Called when selection as changed or other case
1007 //=================================================================================
1008 void SMESHGUI_EditMeshDlg::SelectionIntoArgument()
1010 if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
1011 QString aString = "";
1012 LineEditMesh->setText(aString);
1014 ListCoincident->clear();
1018 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1022 SALOME_ListIO aList;
1023 mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
1025 Handle(SALOME_InteractiveObject) IO = aList.First();
1026 myMesh = SMESH::GetMeshByIO(IO);
1028 if (myMesh->_is_nil())
1031 myActor = SMESH::FindActorByEntry(IO->getEntry());
1033 myActor = SMESH::FindActorByObject(myMesh);
1037 mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
1039 if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
1040 !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
1041 !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
1042 mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1044 LineEditMesh->setText(aString);
1046 if (myAction == 0) {
1047 SMESH::SetPointRepresentation(true);
1048 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1049 aViewWindow->SetSelectionMode(NodeSelection);
1052 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1053 aViewWindow->SetSelectionMode(CellSelection);
1057 //=================================================================================
1058 // function : DeactivateActiveDialog()
1060 //=================================================================================
1061 void SMESHGUI_EditMeshDlg::DeactivateActiveDialog()
1063 if (GroupConstructors->isEnabled()) {
1064 GroupConstructors->setEnabled(false);
1065 GroupMesh->setEnabled(false);
1066 GroupCoincident->setEnabled(false);
1067 GroupEdit->setEnabled(false);
1068 GroupButtons->setEnabled(false);
1069 mySMESHGUI->ResetState();
1070 mySMESHGUI->SetActiveDialogBox(0);
1074 //=================================================================================
1075 // function : ActivateThisDialog()
1077 //=================================================================================
1078 void SMESHGUI_EditMeshDlg::ActivateThisDialog()
1080 /* Emit a signal to deactivate the active dialog */
1081 mySMESHGUI->EmitSignalDeactivateDialog();
1082 GroupConstructors->setEnabled(true);
1083 GroupMesh->setEnabled(true);
1084 GroupCoincident->setEnabled(true);
1085 GroupEdit->setEnabled(true);
1086 GroupButtons->setEnabled(true);
1088 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1089 SelectionIntoArgument();
1092 //=================================================================================
1093 // function : enterEvent()
1095 //=================================================================================
1096 void SMESHGUI_EditMeshDlg::enterEvent(QEvent*)
1098 if (!GroupConstructors->isEnabled())
1099 ActivateThisDialog();
1102 //=================================================================================
1103 // function : closeEvent()
1105 //=================================================================================
1106 void SMESHGUI_EditMeshDlg::closeEvent(QCloseEvent*)
1108 /* same than click on cancel button */
1112 //=======================================================================
1113 //function : hideEvent
1114 //purpose : caused by ESC key
1115 //=======================================================================
1116 void SMESHGUI_EditMeshDlg::hideEvent (QHideEvent *)
1122 //=================================================================================
1123 // function : keyPressEvent()
1125 //=================================================================================
1126 void SMESHGUI_EditMeshDlg::keyPressEvent( QKeyEvent* e)
1128 QDialog::keyPressEvent( e );
1129 if ( e->isAccepted() )
1132 if ( e->key() == Qt::Key_F1 ) {