1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_MergeDlg.cxx
25 // Author : Open CASCADE S.A.S.
28 #include "SMESHGUI_MergeDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_SpinBox.h"
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_OverrideCursor.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
56 #include <TColStd_MapOfInteger.hxx>
57 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
60 #include <SALOMEconfig.h>
61 #include CORBA_SERVER_HEADER(SMESH_Group)
62 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
65 #include <vtkUnstructuredGrid.h>
66 #include <vtkRenderer.h>
67 #include <vtkActor2D.h>
68 #include <vtkPoints.h>
69 #include <vtkDataSetMapper.h>
70 #include <vtkMaskPoints.h>
71 #include <vtkSelectVisiblePoints.h>
72 #include <vtkLabeledDataMapper.h>
73 #include <vtkTextProperty.h>
74 #include <vtkIntArray.h>
75 #include <vtkProperty2D.h>
76 #include <vtkPointData.h>
79 #include <QApplication>
83 #include <QListWidget>
84 #include <QPushButton>
85 #include <QRadioButton>
87 #include <QHBoxLayout>
88 #include <QVBoxLayout>
89 #include <QGridLayout>
91 #include <QButtonGroup>
99 { // to display in the viewer IDs of the selected elements
100 SVTK_ViewWindow* myViewWindow;
102 vtkUnstructuredGrid* myIdGrid;
103 SALOME_Actor* myIdActor;
105 vtkUnstructuredGrid* myPointsNumDataSet;
106 vtkMaskPoints* myPtsMaskPoints;
107 vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
108 vtkLabeledDataMapper* myPtsLabeledDataMapper;
109 vtkTextProperty* aPtsTextProp;
110 bool myIsPointsLabeled;
111 vtkActor2D* myPointLabels;
113 std::vector<int> myIDs;
116 TIdPreview(SVTK_ViewWindow* theViewWindow):
117 myViewWindow(theViewWindow)
119 myIdGrid = vtkUnstructuredGrid::New();
121 // Create and display actor
122 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
123 aMapper->SetInputData( myIdGrid );
125 myIdActor = SALOME_Actor::New();
126 myIdActor->SetInfinitive(true);
127 myIdActor->VisibilityOff();
128 myIdActor->PickableOff();
130 myIdActor->SetMapper( aMapper );
133 myViewWindow->AddActor(myIdActor);
135 //Definition of points numbering pipeline
136 myPointsNumDataSet = vtkUnstructuredGrid::New();
138 myPtsMaskPoints = vtkMaskPoints::New();
139 myPtsMaskPoints->SetInputData(myPointsNumDataSet);
140 myPtsMaskPoints->SetOnRatio(1);
142 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
143 myPtsSelectVisiblePoints->SetInputConnection(myPtsMaskPoints->GetOutputPort());
144 myPtsSelectVisiblePoints->SelectInvisibleOff();
145 myPtsSelectVisiblePoints->SetTolerance(0.1);
147 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
148 myPtsLabeledDataMapper->SetInputConnection(myPtsSelectVisiblePoints->GetOutputPort());
149 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
151 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
152 aPtsTextProp->SetFontFamilyToTimes();
153 static int aPointsFontSize = 12;
154 aPtsTextProp->SetFontSize(aPointsFontSize);
155 aPtsTextProp->SetBold(1);
156 aPtsTextProp->SetItalic(0);
157 aPtsTextProp->SetShadow(0);
158 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
159 aPtsTextProp->Delete();
161 myIsPointsLabeled = false;
163 myPointLabels = vtkActor2D::New();
164 myPointLabels->SetMapper(myPtsLabeledDataMapper);
165 myPointLabels->GetProperty()->SetColor(1,1,1);
166 myPointLabels->SetVisibility(myIsPointsLabeled);
168 AddToRender(myViewWindow->getRenderer());
171 void SetPointsData ( SMDS_Mesh* theMesh,
172 TColStd_MapOfInteger & theNodesIdMap )
174 vtkPoints* aPoints = vtkPoints::New();
175 aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
178 TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
179 for( int i = 0; idIter.More(); idIter.Next(), i++ ) {
180 const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
181 aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
182 myIDs.push_back(idIter.Key());
185 myIdGrid->SetPoints(aPoints);
189 myIdActor->GetMapper()->Update();
192 void SetElemsData( TColStd_MapOfInteger & theElemsIdMap,
193 std::list<gp_XYZ> & aGrCentersXYZ )
195 vtkPoints* aPoints = vtkPoints::New();
196 aPoints->SetNumberOfPoints(theElemsIdMap.Extent());
199 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
200 for( ; idIter.More(); idIter.Next() ) {
201 myIDs.push_back(idIter.Key());
205 std::list<gp_XYZ>::iterator coordIt = aGrCentersXYZ.begin();
206 for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ ) {
208 aPoints->SetPoint( i, aXYZ.X(), aXYZ.Y(), aXYZ.Z() );
210 myIdGrid->SetPoints(aPoints);
213 myIdActor->GetMapper()->Update();
216 void AddToRender(vtkRenderer* theRenderer)
218 myIdActor->AddToRender(theRenderer);
220 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
221 theRenderer->AddActor2D(myPointLabels);
224 void RemoveFromRender(vtkRenderer* theRenderer)
226 myIdActor->RemoveFromRender(theRenderer);
228 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
229 theRenderer->RemoveActor(myPointLabels);
232 void SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible = true )
234 myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
236 if ( myIsPointsLabeled ) {
237 myPointsNumDataSet->ShallowCopy(myIdGrid);
238 vtkDataSet *aDataSet = myPointsNumDataSet;
239 int aNbElem = myIDs.size();
240 vtkIntArray *anArray = vtkIntArray::New();
241 anArray->SetNumberOfValues( aNbElem );
242 for ( int i = 0; i < aNbElem; i++ )
243 anArray->SetValue( i, myIDs[i] );
244 aDataSet->GetPointData()->SetScalars( anArray );
246 myPtsMaskPoints->SetInputData( aDataSet );
247 myPointLabels->SetVisibility( theIsActorVisible );
250 myPointLabels->SetVisibility( false );
256 RemoveFromRender(myViewWindow->getRenderer());
260 myViewWindow->RemoveActor(myIdActor);
263 //Deleting of points numbering pipeline
264 //---------------------------------------
265 myPointsNumDataSet->Delete();
267 //myPtsLabeledDataMapper->RemoveAllInputs(); //vtk 5.0 porting
268 myPtsLabeledDataMapper->Delete();
270 //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
271 myPtsSelectVisiblePoints->Delete();
273 //myPtsMaskPoints->UnRegisterAllOutputs(); //vtk 5.0 porting
274 myPtsMaskPoints->Delete();
276 myPointLabels->Delete();
278 // myTimeStamp->Delete();
283 static const char * IconFirst[] = {
298 //=================================================================================
299 // class : SMESHGUI_MergeDlg()
301 //=================================================================================
302 SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
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 switch dialog behaviour
364 TypeBox = new QGroupBox( tr( "SMESH_MODE" ), this );
365 GroupType = new QButtonGroup( this );
366 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( TypeBox );
367 aTypeBoxLayout->setMargin( MARGIN );
368 aTypeBoxLayout->setSpacing( SPACING );
370 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_AUTOMATIC" ), TypeBox );
371 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_MANUAL" ), TypeBox );
372 GroupType->addButton( rb1, 0 );
373 GroupType->addButton( rb2, 1 );
374 aTypeBoxLayout->addWidget( rb1 );
375 aTypeBoxLayout->addWidget( rb2 );
379 /***************************************************************/
380 // Controls for coincident elements detecting
381 GroupCoincident = new QGroupBox(myAction == 1 ?
382 tr("COINCIDENT_ELEMENTS") :
383 tr("COINCIDENT_NODES"),
386 QVBoxLayout* aCoincidentLayout = new QVBoxLayout(GroupCoincident);
387 aCoincidentLayout->setSpacing(SPACING);
388 aCoincidentLayout->setMargin(MARGIN);
390 if (myAction == 0) { // case merge nodes
391 QWidget* foo = new QWidget(GroupCoincident);
392 TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), foo);
393 SpinBoxTolerance = new SMESHGUI_SpinBox(foo);
394 SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
396 GroupExclude = new QGroupBox(tr("EXCLUDE_GROUPS"), foo);
397 GroupExclude->setCheckable( true );
398 GroupExclude->setChecked( false );
399 ListExclude = new QListWidget( GroupExclude );
400 QVBoxLayout* GroupExcludeLayout = new QVBoxLayout(GroupExclude);
401 GroupExcludeLayout->setSpacing(SPACING);
402 GroupExcludeLayout->setMargin(MARGIN);
403 GroupExcludeLayout->addWidget(ListExclude);
405 QGridLayout* fooLayout = new QGridLayout( foo );
406 fooLayout->setSpacing(SPACING);
407 fooLayout->setMargin(0);
408 fooLayout->addWidget(TextLabelTolerance, 0, 0 );
409 fooLayout->addWidget(SpinBoxTolerance, 0, 1 );
410 fooLayout->addWidget(GroupExclude, 1, 0, 1, 2 );
411 aCoincidentLayout->addWidget(foo);
414 TextLabelTolerance = 0;
415 SpinBoxTolerance = 0;
420 GroupCoincidentWidget = new QWidget(GroupCoincident);
421 QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincidentWidget);
422 GroupCoincidentLayout->setSpacing(SPACING);
423 GroupCoincidentLayout->setMargin(0);
425 ListCoincident = new QListWidget(GroupCoincidentWidget);
426 ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
428 DetectButton = new QPushButton(tr("DETECT"), GroupCoincidentWidget);
429 AddGroupButton = new QPushButton(tr("SMESH_BUT_ADD"), GroupCoincidentWidget);
430 RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincidentWidget);
432 SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincidentWidget);
433 ShowIDs = new QCheckBox(myAction == 1 ? tr("SHOW_ELEMS_IDS") : tr("SHOW_NODES_IDS"), GroupCoincidentWidget);
435 GroupCoincidentLayout->addWidget(ListCoincident, 0, 0, 4, 2);
436 GroupCoincidentLayout->addWidget(DetectButton, 0, 2);
437 GroupCoincidentLayout->addWidget(AddGroupButton, 2, 2);
438 GroupCoincidentLayout->addWidget(RemoveGroupButton, 3, 2);
439 GroupCoincidentLayout->addWidget(SelectAllCB, 4, 0);
440 GroupCoincidentLayout->addWidget(ShowIDs, 4, 1);
441 GroupCoincidentLayout->setRowMinimumHeight(1, 10);
442 GroupCoincidentLayout->setRowStretch(1, 5);
444 aCoincidentLayout->addWidget(GroupCoincidentWidget);
446 /***************************************************************/
447 // Controls for editing the selected group
448 GroupEdit = new QGroupBox(tr("EDIT_SELECTED_GROUP"), this);
449 QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
450 GroupEditLayout->setSpacing(SPACING);
451 GroupEditLayout->setMargin(MARGIN);
453 ListEdit = new QListWidget(GroupEdit);
454 //ListEdit->setRowMode(QListBox::FixedNumber);
455 //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
456 //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
457 ListEdit->setFlow( QListView::LeftToRight );
458 ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
460 AddElemButton = new QPushButton(GroupEdit);
461 AddElemButton->setIcon(IconAdd);
462 RemoveElemButton = new QPushButton(GroupEdit);
463 RemoveElemButton->setIcon(IconRemove);
464 SetFirstButton = new QPushButton(GroupEdit);
465 SetFirstButton->setIcon(QPixmap(IconFirst));
467 GroupEditLayout->addWidget(ListEdit, 0, 0, 2, 1);
468 GroupEditLayout->addWidget(AddElemButton, 0, 1);
469 GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
470 GroupEditLayout->addWidget(SetFirstButton, 1, 1, 1, 2);
472 /***************************************************************/
473 GroupButtons = new QGroupBox(this);
474 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
475 GroupButtonsLayout->setSpacing(SPACING);
476 GroupButtonsLayout->setMargin(MARGIN);
478 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
479 buttonOk->setAutoDefault(true);
480 buttonOk->setDefault(true);
481 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
482 buttonApply->setAutoDefault(true);
483 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
484 buttonCancel->setAutoDefault(true);
485 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
486 buttonHelp->setAutoDefault(true);
488 GroupButtonsLayout->addWidget(buttonOk);
489 GroupButtonsLayout->addSpacing(10);
490 GroupButtonsLayout->addWidget(buttonApply);
491 GroupButtonsLayout->addSpacing(10);
492 GroupButtonsLayout->addStretch();
493 GroupButtonsLayout->addWidget(buttonCancel);
494 GroupButtonsLayout->addWidget(buttonHelp);
496 /***************************************************************/
497 DlgLayout->addWidget(GroupConstructors);
498 DlgLayout->addWidget(GroupMesh);
499 DlgLayout->addWidget(TypeBox);
500 DlgLayout->addWidget(GroupCoincident);
501 DlgLayout->addWidget(GroupEdit);
502 DlgLayout->addWidget(GroupButtons);
504 GroupCoincidentWidget->setVisible( myAction != 0 );
505 GroupCoincident->setVisible( myAction == 0 );
506 //if GroupExclude->setVisible( myAction == 0 );
511 ShowIDs->setChecked( true );
513 Init(); // Initialisations
516 //=================================================================================
517 // function : ~SMESHGUI_MergeDlg()
518 // purpose : Destroys the object and frees any allocated resources
519 //=================================================================================
520 SMESHGUI_MergeDlg::~SMESHGUI_MergeDlg()
525 //=================================================================================
528 //=================================================================================
529 void SMESHGUI_MergeDlg::Init()
532 SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision");
533 SpinBoxTolerance->SetValue(1e-05);
536 RadioButton->setChecked(true);
538 GroupType->button(0)->setChecked(true);
540 myEditCurrentArgument = (QWidget*)LineEditMesh;
543 mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
545 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
547 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
550 /* signals and slots connections */
551 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
552 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
553 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
554 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
556 connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
557 connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
558 connect(ListCoincident, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectGroup()));
559 connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
560 connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
561 connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
562 connect(ShowIDs, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup()));
563 connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
564 connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
565 connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
566 connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst() ) );
567 connect(GroupType, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
569 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
570 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
571 /* to close dialog if study change */
572 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
574 // Init Mesh field from selection
575 SelectionIntoArgument();
581 myHelpFileName = "merging_nodes_page.html";
583 myHelpFileName = "merging_elements_page.html";
586 //=================================================================================
587 // function : FindGravityCenter()
589 //=================================================================================
590 void SMESHGUI_MergeDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap,
591 std::list< gp_XYZ > & theGrCentersXYZ)
596 SMDS_Mesh* aMesh = 0;
597 aMesh = myActor->GetObject()->GetMesh();
603 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
604 for( ; idIter.More(); idIter.Next() ) {
605 const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
609 gp_XYZ anXYZ(0., 0., 0.);
610 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
611 for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
612 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
613 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
615 anXYZ.Divide( nbNodes );
617 theGrCentersXYZ.push_back( anXYZ );
621 //=================================================================================
622 // function : ClickOnApply()
624 //=================================================================================
625 bool SMESHGUI_MergeDlg::ClickOnApply()
627 if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
634 SUIT_OverrideCursor aWaitCursor;
635 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
637 SMESH::long_array_var anIds = new SMESH::long_array;
638 SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
640 if ( ListCoincident->count() == 0) {
642 SUIT_MessageBox::warning(this,
644 tr("SMESH_NO_NODES_DETECTED"));
646 SUIT_MessageBox::warning(this,
648 tr("SMESH_NO_ELEMENTS_DETECTED"));
652 aGroupsOfElements->length(ListCoincident->count());
655 for (int i = 0; i < ListCoincident->count(); i++) {
656 QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
658 anIds->length(aListIds.count());
659 for (int i = 0; i < aListIds.count(); i++)
660 anIds[i] = aListIds[i].toInt();
662 aGroupsOfElements[anArrayNum++] = anIds.inout();
666 aMeshEditor->MergeNodes (aGroupsOfElements.inout());
668 aMeshEditor->MergeElements (aGroupsOfElements.inout());
670 if ( myTypeId == 0 ) {
672 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
673 tr("SMESH_MERGED_NODES").arg(QString::number(ListCoincident->count()).toLatin1().data()));
675 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
676 tr("SMESH_MERGED_ELEMENTS").arg(QString::number(ListCoincident->count()).toLatin1().data()));
683 ListCoincident->clear();
685 myEditCurrentArgument = (QWidget*)LineEditMesh;
688 SMESHGUI::Modified();
693 //=================================================================================
694 // function : ClickOnOk()
696 //=================================================================================
697 void SMESHGUI_MergeDlg::ClickOnOk()
703 //=================================================================================
704 // function : reject()
706 //=================================================================================
707 void SMESHGUI_MergeDlg::reject()
709 myIdPreview->SetPointsLabeled(false);
710 SMESH::SetPointRepresentation(false);
711 disconnect(mySelectionMgr, 0, this, 0);
712 disconnect(mySMESHGUI, 0, this, 0);
713 mySMESHGUI->ResetState();
715 mySelectionMgr->clearFilters();
716 //mySelectionMgr->clearSelected();
718 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
719 aViewWindow->SetSelectionMode(ActorSelection);
724 //=================================================================================
725 // function : ClickOnHelp()
727 //=================================================================================
728 void SMESHGUI_MergeDlg::ClickOnHelp()
730 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
732 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
736 platform = "winapplication";
738 platform = "application";
740 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
741 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
742 arg(app->resourceMgr()->stringValue("ExternalBrowser",
744 arg(myHelpFileName));
748 //=================================================================================
749 // function : onEditGroup()
751 //=================================================================================
752 void SMESHGUI_MergeDlg::onEditGroup()
754 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
755 if ( selItems.count() != 1 ) {
762 for (int i = 0; i < ListEdit->count(); i++ )
763 aNewIds.append(ListEdit->item(i)->text());
765 ListCoincident->clearSelection();
766 selItems.first()->setText(aNewIds.join(" "));
767 selItems.first()->setSelected(true);
770 //=================================================================================
771 // function : updateControls()
773 //=================================================================================
774 void SMESHGUI_MergeDlg::updateControls()
776 if (ListEdit->count() == 0)
777 SetFirstButton->setEnabled(false);
778 bool enable = !(myMesh->_is_nil()) && (ListCoincident->count() || (myTypeId == 0));
779 buttonOk->setEnabled(enable);
780 buttonApply->setEnabled(enable);
783 //=================================================================================
784 // function : onDetect()
786 //=================================================================================
787 void SMESHGUI_MergeDlg::onDetect()
789 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
793 SUIT_OverrideCursor aWaitCursor;
794 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
796 ListCoincident->clear();
799 SMESH::array_of_long_array_var aGroupsArray;
800 SMESH::ListOfIDSources_var aExcludeGroups = new SMESH::ListOfIDSources;
802 SMESH::SMESH_IDSource_var src;
803 if ( mySubMeshOrGroup->_is_nil() ) src = SMESH::SMESH_IDSource::_duplicate( myMesh );
804 else src = SMESH::SMESH_IDSource::_duplicate( mySubMeshOrGroup );
808 for ( int i = 0; GroupExclude->isChecked() && i < ListExclude->count(); i++ ) {
809 if ( ListExclude->item( i )->checkState() == Qt::Checked ) {
810 aExcludeGroups->length( aExcludeGroups->length()+1 );
811 aExcludeGroups[ aExcludeGroups->length()-1 ] = SMESH::SMESH_IDSource::_duplicate( myGroups[i] );
814 aMeshEditor->FindCoincidentNodesOnPartBut(src.in(),
815 SpinBoxTolerance->GetValue(),
817 aExcludeGroups.in());
820 aMeshEditor->FindEqualElements(src.in(), aGroupsArray.out());
824 for (int i = 0; i < aGroupsArray->length(); i++) {
825 SMESH::long_array& aGroup = aGroupsArray[i];
828 for (int j = 0; j < aGroup.length(); j++)
829 anIDs.append(QString::number(aGroup[j]));
831 ListCoincident->addItem(anIDs.join(" "));
836 ListCoincident->selectAll();
841 //=================================================================================
842 // function : onSelectGroup()
844 //=================================================================================
845 void SMESHGUI_MergeDlg::onSelectGroup()
847 if (myIsBusy || !myActor)
850 if( ListCoincident->count() != ListCoincident->selectedItems().count() )
851 SelectAllCB->setChecked( false );
853 myEditCurrentArgument = (QWidget*)ListCoincident;
858 TColStd_MapOfInteger anIndices;
859 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
860 QListWidgetItem* anItem;
861 QStringList aListIds;
865 foreach(anItem, selItems) {
866 aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
867 for (int i = 0; i < aListIds.count(); i++)
868 anIndices.Add(aListIds[i].toInt());
871 if (selItems.count() == 1) {
872 ListEdit->addItems(aListIds);
873 ListEdit->selectAll();
876 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
878 aList.Append(myActor->getIO());
879 mySelectionMgr->setSelectedObjects(aList,false);
881 if (ShowIDs->isChecked())
883 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
884 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
887 std::list< gp_XYZ > aGrCentersXYZ;
888 FindGravityCenter(anIndices, aGrCentersXYZ);
889 myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
890 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
893 myIdPreview->SetPointsLabeled(false);
899 //=================================================================================
900 // function : onSelectAll()
902 //=================================================================================
903 void SMESHGUI_MergeDlg::onSelectAll (bool isToggled)
906 ListCoincident->selectAll();
908 ListCoincident->clearSelection();
911 //=================================================================================
912 // function : onSelectElementFromGroup()
914 //=================================================================================
915 void SMESHGUI_MergeDlg::onSelectElementFromGroup()
917 if (myIsBusy || !myActor)
920 TColStd_MapOfInteger anIndices;
921 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
922 QListWidgetItem* anItem;
924 foreach(anItem, selItems)
925 anIndices.Add(anItem->text().toInt());
927 SetFirstButton->setEnabled(selItems.count() == 1);
929 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
931 aList.Append(myActor->getIO());
932 mySelectionMgr->setSelectedObjects(aList);
934 if (ShowIDs->isChecked())
936 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
937 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
940 std::list< gp_XYZ > aGrCentersXYZ;
941 FindGravityCenter(anIndices, aGrCentersXYZ);
942 myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
943 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
946 myIdPreview->SetPointsLabeled(false);
949 //=================================================================================
950 // function : onAddGroup()
952 //=================================================================================
953 void SMESHGUI_MergeDlg::onAddGroup()
955 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
960 aNbElements = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
965 ListCoincident->clearSelection();
966 ListCoincident->addItem(anIDs);
967 int nbGroups = ListCoincident->count();
969 ListCoincident->setCurrentRow(nbGroups-1);
970 ListCoincident->item(nbGroups-1)->setSelected(true);
973 // VSR ? this code seems to be never executed!!!
974 ListCoincident->setCurrentRow(0);
975 //ListCoincident->setSelected(0, true); // VSR: no items - no selection
981 //=================================================================================
982 // function : onRemoveGroup()
984 //=================================================================================
985 void SMESHGUI_MergeDlg::onRemoveGroup()
987 if (myEditCurrentArgument != (QWidget*)ListCoincident)
991 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
992 QListWidgetItem* anItem;
994 foreach(anItem, selItems)
998 myIdPreview->SetPointsLabeled(false);
1000 SMESH::UpdateView();
1003 if( ListCoincident->count() == 0 ) {
1004 myEditCurrentArgument = (QWidget*)LineEditMesh;
1005 SelectAllCB->setChecked( false );
1009 //=================================================================================
1010 // function : onAddElement()
1012 //=================================================================================
1013 void SMESHGUI_MergeDlg::onAddElement()
1019 QString aListStr = "";
1022 aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1026 QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
1028 for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
1029 QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
1030 if ( found.count() == 0 ) {
1031 QListWidgetItem* anItem = new QListWidgetItem(*it);
1032 ListEdit->addItem(anItem);
1033 anItem->setSelected(true);
1036 QListWidgetItem* anItem;
1037 foreach(anItem, found) anItem->setSelected(true);
1045 //=================================================================================
1046 // function : onRemoveElement()
1048 //=================================================================================
1049 void SMESHGUI_MergeDlg::onRemoveElement()
1051 if (myEditCurrentArgument != (QWidget*)ListCoincident)
1055 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1056 QListWidgetItem* anItem;
1058 foreach(anItem, selItems)
1064 if( ListCoincident->count() == 0 ) {
1065 myEditCurrentArgument = (QWidget*)LineEditMesh;
1066 SelectAllCB->setChecked( false );
1070 //=================================================================================
1071 // function : onSetFirst()
1073 //=================================================================================
1074 void SMESHGUI_MergeDlg::onSetFirst()
1076 if (myEditCurrentArgument != (QWidget*)ListCoincident)
1080 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1081 QListWidgetItem* anItem;
1083 foreach(anItem, selItems) {
1084 ListEdit->takeItem(ListEdit->row(anItem));
1085 ListEdit->insertItem(0, anItem);
1092 //=================================================================================
1093 // function : SetEditCurrentArgument()
1095 //=================================================================================
1096 void SMESHGUI_MergeDlg::SetEditCurrentArgument()
1098 QPushButton* send = (QPushButton*)sender();
1100 disconnect(mySelectionMgr, 0, this, 0);
1101 mySelectionMgr->clearSelected();
1102 mySelectionMgr->clearFilters();
1104 if (send == SelectMeshButton) {
1105 myEditCurrentArgument = (QWidget*)LineEditMesh;
1106 SMESH::SetPointRepresentation(false);
1107 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1108 aViewWindow->SetSelectionMode(ActorSelection);
1110 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1113 myEditCurrentArgument->setFocus();
1114 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1115 SelectionIntoArgument();
1118 //=================================================================================
1119 // function : SelectionIntoArgument()
1120 // purpose : Called when selection as changed or other case
1121 //=================================================================================
1122 void SMESHGUI_MergeDlg::SelectionIntoArgument()
1124 if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
1125 QString aString = "";
1126 LineEditMesh->setText(aString);
1128 ListCoincident->clear();
1131 QString aCurrentEntry = myEntry;
1133 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1135 myIdPreview->SetPointsLabeled(false);
1136 SMESH::SetPointRepresentation(false);
1137 mySelectionMgr->clearFilters();
1138 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1139 aViewWindow->SetSelectionMode(ActorSelection);
1143 SALOME_ListIO aList;
1144 mySelectionMgr->selectedObjects(aList);
1146 Handle(SALOME_InteractiveObject) IO = aList.First();
1147 myEntry = IO->getEntry();
1148 myMesh = SMESH::GetMeshByIO(IO);
1150 if (myMesh->_is_nil())
1153 LineEditMesh->setText(aString);
1155 myActor = SMESH::FindActorByEntry(IO->getEntry());
1157 myActor = SMESH::FindActorByObject(myMesh);
1159 if ( myActor && myTypeId == 1 && mySelector->IsSelectionEnabled() ) {
1160 mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
1161 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1163 if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
1164 !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
1165 !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
1166 mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1168 if (myAction == 0) {
1169 SMESH::SetPointRepresentation(true);
1170 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1171 aViewWindow->SetSelectionMode(NodeSelection);
1174 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1175 aViewWindow->SetSelectionMode(CellSelection);
1179 if ( myAction == 0 && !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
1181 ListExclude->clear();
1182 SMESH::ListOfGroups_var aListOfGroups = myMesh->GetGroups();
1183 for( int i = 0, n = aListOfGroups->length(); i < n; i++ ) {
1184 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
1185 if ( !aGroup->_is_nil() ) { // && aGroup->GetType() == SMESH::NODE
1186 QString aGroupName( aGroup->GetName() );
1187 if ( !aGroupName.isEmpty() ) {
1188 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
1189 QListWidgetItem* item = new QListWidgetItem( aGroupName );
1190 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
1191 item->setCheckState( Qt::Unchecked );
1192 ListExclude->addItem( item );
1202 //=================================================================================
1203 // function : DeactivateActiveDialog()
1205 //=================================================================================
1206 void SMESHGUI_MergeDlg::DeactivateActiveDialog()
1208 if (GroupConstructors->isEnabled()) {
1209 GroupConstructors->setEnabled(false);
1210 TypeBox->setEnabled(false);
1211 GroupMesh->setEnabled(false);
1212 GroupCoincident->setEnabled(false);
1213 GroupEdit->setEnabled(false);
1214 GroupButtons->setEnabled(false);
1215 mySMESHGUI->ResetState();
1216 mySMESHGUI->SetActiveDialogBox(0);
1219 mySelectionMgr->clearSelected();
1220 disconnect(mySelectionMgr, 0, this, 0);
1223 //=================================================================================
1224 // function : ActivateThisDialog()
1226 //=================================================================================
1227 void SMESHGUI_MergeDlg::ActivateThisDialog()
1229 /* Emit a signal to deactivate the active dialog */
1230 mySMESHGUI->EmitSignalDeactivateDialog();
1231 GroupConstructors->setEnabled(true);
1232 TypeBox->setEnabled(true);
1233 GroupMesh->setEnabled(true);
1234 GroupCoincident->setEnabled(true);
1235 GroupEdit->setEnabled(true);
1236 GroupButtons->setEnabled(true);
1238 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1239 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1240 SelectionIntoArgument();
1243 //=================================================================================
1244 // function : enterEvent()
1246 //=================================================================================
1247 void SMESHGUI_MergeDlg::enterEvent(QEvent*)
1249 if (!GroupConstructors->isEnabled())
1250 ActivateThisDialog();
1253 //=================================================================================
1254 // function : keyPressEvent()
1256 //=================================================================================
1257 void SMESHGUI_MergeDlg::keyPressEvent( QKeyEvent* e)
1259 QDialog::keyPressEvent( e );
1260 if ( e->isAccepted() )
1263 if ( e->key() == Qt::Key_F1 ) {
1269 //=================================================================================
1270 // function : onTypeChanged()
1271 // purpose : the type radio button management
1272 //=================================================================================
1273 void SMESHGUI_MergeDlg::onTypeChanged (int id)
1281 case 0: // automatic
1282 myIdPreview->SetPointsLabeled(false);
1283 SMESH::SetPointRepresentation(false);
1284 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1285 aViewWindow->SetSelectionMode(ActorSelection);
1286 mySelectionMgr->clearFilters();
1288 GroupCoincidentWidget->hide();
1290 GroupCoincident->hide();
1295 SMESH::UpdateView();
1297 // Costruction of the logical filter
1298 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
1299 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
1301 QList<SUIT_SelectionFilter*> aListOfFilters;
1302 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
1303 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
1305 myMeshOrSubMeshOrGroupFilter =
1306 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
1308 if (myAction == 0) {
1309 GroupCoincidentWidget->show();
1310 SMESH::SetPointRepresentation(true);
1311 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1312 if( mySelector->IsSelectionEnabled() )
1313 aViewWindow->SetSelectionMode(NodeSelection);
1316 GroupCoincident->show();
1317 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1318 if( mySelector->IsSelectionEnabled() )
1319 aViewWindow->SetSelectionMode(CellSelection);
1326 qApp->processEvents();
1330 SelectionIntoArgument();