1 // Copyright (C) 2007-2013 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.
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>
77 #include <vtkConfigure.h>
78 #if !defined(VTK_XVERSION)
79 #define VTK_XVERSION (VTK_MAJOR_VERSION<<16)+(VTK_MINOR_VERSION<<8)+(VTK_BUILD_VERSION)
83 #include <QApplication>
87 #include <QListWidget>
88 #include <QPushButton>
89 #include <QRadioButton>
91 #include <QHBoxLayout>
92 #include <QVBoxLayout>
93 #include <QGridLayout>
95 #include <QButtonGroup>
103 { // to display in the viewer IDs of the selected elements
104 SVTK_ViewWindow* myViewWindow;
106 vtkUnstructuredGrid* myIdGrid;
107 SALOME_Actor* myIdActor;
109 vtkUnstructuredGrid* myPointsNumDataSet;
110 vtkMaskPoints* myPtsMaskPoints;
111 vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
112 vtkLabeledDataMapper* myPtsLabeledDataMapper;
113 vtkTextProperty* aPtsTextProp;
114 bool myIsPointsLabeled;
115 vtkActor2D* myPointLabels;
117 std::vector<int> myIDs;
120 TIdPreview(SVTK_ViewWindow* theViewWindow):
121 myViewWindow(theViewWindow)
123 myIdGrid = vtkUnstructuredGrid::New();
125 // Create and display actor
126 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
127 aMapper->SetInput( myIdGrid );
129 myIdActor = SALOME_Actor::New();
130 myIdActor->SetInfinitive(true);
131 myIdActor->VisibilityOff();
132 myIdActor->PickableOff();
134 myIdActor->SetMapper( aMapper );
137 myViewWindow->AddActor(myIdActor);
139 //Definition of points numbering pipeline
140 myPointsNumDataSet = vtkUnstructuredGrid::New();
142 myPtsMaskPoints = vtkMaskPoints::New();
143 myPtsMaskPoints->SetInput(myPointsNumDataSet);
144 myPtsMaskPoints->SetOnRatio(1);
146 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
147 myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput());
148 myPtsSelectVisiblePoints->SelectInvisibleOff();
149 myPtsSelectVisiblePoints->SetTolerance(0.1);
151 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
152 myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput());
153 #if (VTK_XVERSION < 0x050200)
154 myPtsLabeledDataMapper->SetLabelFormat("%g");
156 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
158 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
159 aPtsTextProp->SetFontFamilyToTimes();
160 static int aPointsFontSize = 12;
161 aPtsTextProp->SetFontSize(aPointsFontSize);
162 aPtsTextProp->SetBold(1);
163 aPtsTextProp->SetItalic(0);
164 aPtsTextProp->SetShadow(0);
165 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
166 aPtsTextProp->Delete();
168 myIsPointsLabeled = false;
170 myPointLabels = vtkActor2D::New();
171 myPointLabels->SetMapper(myPtsLabeledDataMapper);
172 myPointLabels->GetProperty()->SetColor(1,1,1);
173 myPointLabels->SetVisibility(myIsPointsLabeled);
175 AddToRender(myViewWindow->getRenderer());
178 void SetPointsData ( SMDS_Mesh* theMesh,
179 TColStd_MapOfInteger & theNodesIdMap )
181 vtkPoints* aPoints = vtkPoints::New();
182 aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
185 TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
186 for( int i = 0; idIter.More(); idIter.Next(), i++ ) {
187 const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
188 aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
189 myIDs.push_back(idIter.Key());
192 myIdGrid->SetPoints(aPoints);
196 myIdActor->GetMapper()->Update();
199 void SetElemsData( TColStd_MapOfInteger & theElemsIdMap,
200 std::list<gp_XYZ> & aGrCentersXYZ )
202 vtkPoints* aPoints = vtkPoints::New();
203 aPoints->SetNumberOfPoints(theElemsIdMap.Extent());
206 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
207 for( ; idIter.More(); idIter.Next() ) {
208 myIDs.push_back(idIter.Key());
212 std::list<gp_XYZ>::iterator coordIt = aGrCentersXYZ.begin();
213 for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ ) {
215 aPoints->SetPoint( i, aXYZ.X(), aXYZ.Y(), aXYZ.Z() );
217 myIdGrid->SetPoints(aPoints);
220 myIdActor->GetMapper()->Update();
223 void AddToRender(vtkRenderer* theRenderer)
225 myIdActor->AddToRender(theRenderer);
227 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
228 theRenderer->AddActor2D(myPointLabels);
231 void RemoveFromRender(vtkRenderer* theRenderer)
233 myIdActor->RemoveFromRender(theRenderer);
235 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
236 theRenderer->RemoveActor(myPointLabels);
239 void SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible = true )
241 myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
243 if ( myIsPointsLabeled ) {
244 myPointsNumDataSet->ShallowCopy(myIdGrid);
245 vtkDataSet *aDataSet = myPointsNumDataSet;
246 int aNbElem = myIDs.size();
247 vtkIntArray *anArray = vtkIntArray::New();
248 anArray->SetNumberOfValues( aNbElem );
249 for ( int i = 0; i < aNbElem; i++ )
250 anArray->SetValue( i, myIDs[i] );
251 aDataSet->GetPointData()->SetScalars( anArray );
253 myPtsMaskPoints->SetInput( aDataSet );
254 myPointLabels->SetVisibility( theIsActorVisible );
257 myPointLabels->SetVisibility( false );
263 RemoveFromRender(myViewWindow->getRenderer());
267 myViewWindow->RemoveActor(myIdActor);
270 //Deleting of points numbering pipeline
271 //---------------------------------------
272 myPointsNumDataSet->Delete();
274 //myPtsLabeledDataMapper->RemoveAllInputs(); //vtk 5.0 porting
275 myPtsLabeledDataMapper->Delete();
277 //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
278 myPtsSelectVisiblePoints->Delete();
280 //myPtsMaskPoints->UnRegisterAllOutputs(); //vtk 5.0 porting
281 myPtsMaskPoints->Delete();
283 myPointLabels->Delete();
285 // myTimeStamp->Delete();
290 static const char * IconFirst[] = {
305 //=================================================================================
306 // class : SMESHGUI_MergeDlg()
308 //=================================================================================
309 SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
310 : QDialog(SMESH::GetDesktop(theModule)),
311 mySMESHGUI(theModule),
312 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
316 setAttribute(Qt::WA_DeleteOnClose, true);
317 setWindowTitle(myAction == 1 ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
319 myIdPreview = new SMESH::TIdPreview(SMESH::GetViewWindow( mySMESHGUI ));
321 SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
322 QPixmap IconMergeNodes (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
323 QPixmap IconMergeElems (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_MERGE_ELEMENTS")));
324 QPixmap IconSelect (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
325 QPixmap IconAdd (aResMgr->loadPixmap("SMESH", tr("ICON_APPEND")));
326 QPixmap IconRemove (aResMgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
328 setSizeGripEnabled(true);
330 QVBoxLayout* DlgLayout = new QVBoxLayout(this);
331 DlgLayout->setSpacing(SPACING);
332 DlgLayout->setMargin(MARGIN);
334 /***************************************************************/
335 GroupConstructors = new QGroupBox(myAction == 1 ?
336 tr("SMESH_MERGE_ELEMENTS") :
337 tr("SMESH_MERGE_NODES"),
340 QButtonGroup* ButtonGroup = new QButtonGroup(this);
341 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
342 GroupConstructorsLayout->setSpacing(SPACING);
343 GroupConstructorsLayout->setMargin(MARGIN);
345 RadioButton = new QRadioButton(GroupConstructors);
346 RadioButton->setIcon(myAction == 1 ? IconMergeElems : IconMergeNodes);
347 RadioButton->setChecked(true);
348 GroupConstructorsLayout->addWidget(RadioButton);
349 ButtonGroup->addButton(RadioButton, 0);
351 /***************************************************************/
352 // Controls for mesh defining
353 GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), this);
354 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
355 GroupMeshLayout->setSpacing(SPACING);
356 GroupMeshLayout->setMargin(MARGIN);
358 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupMesh);
359 SelectMeshButton = new QPushButton(GroupMesh);
360 SelectMeshButton->setIcon(IconSelect);
361 LineEditMesh = new QLineEdit(GroupMesh);
362 LineEditMesh->setReadOnly(true);
364 GroupMeshLayout->addWidget(TextLabelName);
365 GroupMeshLayout->addWidget(SelectMeshButton);
366 GroupMeshLayout->addWidget(LineEditMesh);
368 /***************************************************************/
369 // Controls for switch dialog behaviour
371 TypeBox = new QGroupBox( tr( "SMESH_MODE" ), this );
372 GroupType = new QButtonGroup( this );
373 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( TypeBox );
374 aTypeBoxLayout->setMargin( MARGIN );
375 aTypeBoxLayout->setSpacing( SPACING );
377 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_AUTOMATIC" ), TypeBox );
378 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_MANUAL" ), TypeBox );
379 GroupType->addButton( rb1, 0 );
380 GroupType->addButton( rb2, 1 );
381 aTypeBoxLayout->addWidget( rb1 );
382 aTypeBoxLayout->addWidget( rb2 );
386 /***************************************************************/
387 // Controls for coincident elements detecting
388 GroupCoincident = new QGroupBox(myAction == 1 ?
389 tr("COINCIDENT_ELEMENTS") :
390 tr("COINCIDENT_NODES"),
393 QVBoxLayout* aCoincidentLayout = new QVBoxLayout(GroupCoincident);
394 aCoincidentLayout->setSpacing(SPACING);
395 aCoincidentLayout->setMargin(MARGIN);
397 if (myAction == 0) { // case merge nodes
398 QWidget* foo = new QWidget(GroupCoincident);
399 TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), foo);
400 SpinBoxTolerance = new SMESHGUI_SpinBox(foo);
401 SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
403 GroupExclude = new QGroupBox(tr("EXCLUDE_GROUPS"), foo);
404 GroupExclude->setCheckable( true );
405 GroupExclude->setChecked( false );
406 ListExclude = new QListWidget( GroupExclude );
407 QVBoxLayout* GroupExcludeLayout = new QVBoxLayout(GroupExclude);
408 GroupExcludeLayout->setSpacing(SPACING);
409 GroupExcludeLayout->setMargin(MARGIN);
410 GroupExcludeLayout->addWidget(ListExclude);
412 QGridLayout* fooLayout = new QGridLayout( foo );
413 fooLayout->setSpacing(SPACING);
414 fooLayout->setMargin(0);
415 fooLayout->addWidget(TextLabelTolerance, 0, 0 );
416 fooLayout->addWidget(SpinBoxTolerance, 0, 1 );
417 fooLayout->addWidget(GroupExclude, 1, 0, 1, 2 );
418 aCoincidentLayout->addWidget(foo);
421 TextLabelTolerance = 0;
422 SpinBoxTolerance = 0;
427 GroupCoincidentWidget = new QWidget(GroupCoincident);
428 QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincidentWidget);
429 GroupCoincidentLayout->setSpacing(SPACING);
430 GroupCoincidentLayout->setMargin(0);
432 ListCoincident = new QListWidget(GroupCoincidentWidget);
433 ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
435 DetectButton = new QPushButton(tr("DETECT"), GroupCoincidentWidget);
436 AddGroupButton = new QPushButton(tr("SMESH_BUT_ADD"), GroupCoincidentWidget);
437 RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincidentWidget);
439 SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincidentWidget);
441 GroupCoincidentLayout->addWidget(ListCoincident, 0, 0, 4, 2);
442 GroupCoincidentLayout->addWidget(DetectButton, 0, 2);
443 GroupCoincidentLayout->addWidget(AddGroupButton, 2, 2);
444 GroupCoincidentLayout->addWidget(RemoveGroupButton, 3, 2);
445 GroupCoincidentLayout->addWidget(SelectAllCB, 4, 0, 1, 3);
446 GroupCoincidentLayout->setRowMinimumHeight(1, 10);
447 GroupCoincidentLayout->setRowStretch(1, 5);
449 aCoincidentLayout->addWidget(GroupCoincidentWidget);
451 /***************************************************************/
452 // Controls for editing the selected group
453 GroupEdit = new QGroupBox(tr("EDIT_SELECTED_GROUP"), this);
454 QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
455 GroupEditLayout->setSpacing(SPACING);
456 GroupEditLayout->setMargin(MARGIN);
458 ListEdit = new QListWidget(GroupEdit);
459 //ListEdit->setRowMode(QListBox::FixedNumber);
460 //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
461 //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
462 ListEdit->setFlow( QListView::LeftToRight );
463 ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
465 AddElemButton = new QPushButton(GroupEdit);
466 AddElemButton->setIcon(IconAdd);
467 RemoveElemButton = new QPushButton(GroupEdit);
468 RemoveElemButton->setIcon(IconRemove);
469 SetFirstButton = new QPushButton(GroupEdit);
470 SetFirstButton->setIcon(QPixmap(IconFirst));
472 GroupEditLayout->addWidget(ListEdit, 0, 0, 2, 1);
473 GroupEditLayout->addWidget(AddElemButton, 0, 1);
474 GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
475 GroupEditLayout->addWidget(SetFirstButton, 1, 1, 1, 2);
477 /***************************************************************/
478 GroupButtons = new QGroupBox(this);
479 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
480 GroupButtonsLayout->setSpacing(SPACING);
481 GroupButtonsLayout->setMargin(MARGIN);
483 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
484 buttonOk->setAutoDefault(true);
485 buttonOk->setDefault(true);
486 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
487 buttonApply->setAutoDefault(true);
488 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
489 buttonCancel->setAutoDefault(true);
490 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
491 buttonHelp->setAutoDefault(true);
493 GroupButtonsLayout->addWidget(buttonOk);
494 GroupButtonsLayout->addSpacing(10);
495 GroupButtonsLayout->addWidget(buttonApply);
496 GroupButtonsLayout->addSpacing(10);
497 GroupButtonsLayout->addStretch();
498 GroupButtonsLayout->addWidget(buttonCancel);
499 GroupButtonsLayout->addWidget(buttonHelp);
501 /***************************************************************/
502 DlgLayout->addWidget(GroupConstructors);
503 DlgLayout->addWidget(GroupMesh);
504 DlgLayout->addWidget(TypeBox);
505 DlgLayout->addWidget(GroupCoincident);
506 DlgLayout->addWidget(GroupEdit);
507 DlgLayout->addWidget(GroupButtons);
509 GroupCoincidentWidget->setVisible( myAction != 0 );
510 GroupCoincident->setVisible( myAction == 0 );
511 //if GroupExclude->setVisible( myAction == 0 );
516 Init(); // Initialisations
519 //=================================================================================
520 // function : ~SMESHGUI_MergeDlg()
521 // purpose : Destroys the object and frees any allocated resources
522 //=================================================================================
523 SMESHGUI_MergeDlg::~SMESHGUI_MergeDlg()
528 //=================================================================================
531 //=================================================================================
532 void SMESHGUI_MergeDlg::Init()
535 SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision");
536 SpinBoxTolerance->SetValue(1e-05);
539 RadioButton->setChecked(true);
541 GroupType->button(0)->setChecked(true);
543 myEditCurrentArgument = (QWidget*)LineEditMesh;
546 mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
548 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
550 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
553 /* signals and slots connections */
554 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
555 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
556 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
557 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
559 connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
560 connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
561 connect(ListCoincident, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectGroup()));
562 connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
563 connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
564 connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
565 connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
566 connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
567 connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
568 connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst() ) );
569 connect(GroupType, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
571 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
572 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
573 /* to close dialog if study change */
574 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
576 // Init Mesh field from selection
577 SelectionIntoArgument();
583 myHelpFileName = "merging_nodes_page.html";
585 myHelpFileName = "merging_elements_page.html";
588 //=================================================================================
589 // function : FindGravityCenter()
591 //=================================================================================
592 void SMESHGUI_MergeDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap,
593 std::list< gp_XYZ > & theGrCentersXYZ)
598 SMDS_Mesh* aMesh = 0;
599 aMesh = myActor->GetObject()->GetMesh();
605 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
606 for( ; idIter.More(); idIter.Next() ) {
607 const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
611 gp_XYZ anXYZ(0., 0., 0.);
612 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
613 for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
614 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
615 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
617 anXYZ.Divide( nbNodes );
619 theGrCentersXYZ.push_back( anXYZ );
623 //=================================================================================
624 // function : ClickOnApply()
626 //=================================================================================
627 bool SMESHGUI_MergeDlg::ClickOnApply()
629 if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
636 SUIT_OverrideCursor aWaitCursor;
637 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
639 SMESH::long_array_var anIds = new SMESH::long_array;
640 SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
642 if ( ListCoincident->count() == 0) {
644 SUIT_MessageBox::warning(this,
646 tr("SMESH_NO_NODES_DETECTED"));
648 SUIT_MessageBox::warning(this,
650 tr("SMESH_NO_ELEMENTS_DETECTED"));
654 aGroupsOfElements->length(ListCoincident->count());
657 for (int i = 0; i < ListCoincident->count(); i++) {
658 QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
660 anIds->length(aListIds.count());
661 for (int i = 0; i < aListIds.count(); i++)
662 anIds[i] = aListIds[i].toInt();
664 aGroupsOfElements[anArrayNum++] = anIds.inout();
668 aMeshEditor->MergeNodes (aGroupsOfElements.inout());
670 aMeshEditor->MergeElements (aGroupsOfElements.inout());
672 if ( myTypeId == 0 ) {
674 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
675 tr("SMESH_MERGED_NODES").arg(QString::number(ListCoincident->count()).toLatin1().data()));
677 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
678 tr("SMESH_MERGED_ELEMENTS").arg(QString::number(ListCoincident->count()).toLatin1().data()));
685 ListCoincident->clear();
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();
840 //=================================================================================
841 // function : onSelectGroup()
843 //=================================================================================
844 void SMESHGUI_MergeDlg::onSelectGroup()
846 if (myIsBusy || !myActor)
848 myEditCurrentArgument = (QWidget*)ListCoincident;
852 TColStd_MapOfInteger anIndices;
853 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
854 QListWidgetItem* anItem;
855 QStringList aListIds;
859 foreach(anItem, selItems) {
860 aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
861 for (int i = 0; i < aListIds.count(); i++)
862 anIndices.Add(aListIds[i].toInt());
865 if (selItems.count() == 1) {
866 ListEdit->addItems(aListIds);
867 ListEdit->selectAll();
870 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
872 aList.Append(myActor->getIO());
873 mySelectionMgr->setSelectedObjects(aList,false);
876 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
877 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
880 std::list< gp_XYZ > aGrCentersXYZ;
881 FindGravityCenter(anIndices, aGrCentersXYZ);
882 myIdPreview->SetElemsData( anIndices, aGrCentersXYZ);
883 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
889 //=================================================================================
890 // function : onSelectAll()
892 //=================================================================================
893 void SMESHGUI_MergeDlg::onSelectAll (bool isToggled)
896 ListCoincident->selectAll();
898 ListCoincident->clearSelection();
901 //=================================================================================
902 // function : onSelectElementFromGroup()
904 //=================================================================================
905 void SMESHGUI_MergeDlg::onSelectElementFromGroup()
907 if (myIsBusy || !myActor)
910 TColStd_MapOfInteger anIndices;
911 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
912 QListWidgetItem* anItem;
914 foreach(anItem, selItems)
915 anIndices.Add(anItem->text().toInt());
917 SetFirstButton->setEnabled(selItems.count() == 1);
919 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
921 aList.Append(myActor->getIO());
922 mySelectionMgr->setSelectedObjects(aList);
925 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
926 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
929 std::list< gp_XYZ > aGrCentersXYZ;
930 FindGravityCenter(anIndices, aGrCentersXYZ);
931 myIdPreview->SetElemsData(anIndices, aGrCentersXYZ);
932 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
936 //=================================================================================
937 // function : onAddGroup()
939 //=================================================================================
940 void SMESHGUI_MergeDlg::onAddGroup()
942 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
947 aNbElements = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
952 ListCoincident->clearSelection();
953 ListCoincident->addItem(anIDs);
954 int nbGroups = ListCoincident->count();
956 ListCoincident->setCurrentRow(nbGroups-1);
957 ListCoincident->item(nbGroups-1)->setSelected(true);
960 // VSR ? this code seems to be never executed!!!
961 ListCoincident->setCurrentRow(0);
962 //ListCoincident->setSelected(0, true); // VSR: no items - no selection
968 //=================================================================================
969 // function : onRemoveGroup()
971 //=================================================================================
972 void SMESHGUI_MergeDlg::onRemoveGroup()
974 if (myEditCurrentArgument != (QWidget*)ListCoincident)
978 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
979 QListWidgetItem* anItem;
981 foreach(anItem, selItems)
990 //=================================================================================
991 // function : onAddElement()
993 //=================================================================================
994 void SMESHGUI_MergeDlg::onAddElement()
1000 QString aListStr = "";
1003 aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1007 QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
1009 for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
1010 QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
1011 if ( found.count() == 0 ) {
1012 QListWidgetItem* anItem = new QListWidgetItem(*it);
1013 ListEdit->addItem(anItem);
1014 anItem->setSelected(true);
1017 QListWidgetItem* anItem;
1018 foreach(anItem, found) anItem->setSelected(true);
1026 //=================================================================================
1027 // function : onRemoveElement()
1029 //=================================================================================
1030 void SMESHGUI_MergeDlg::onRemoveElement()
1032 if (myEditCurrentArgument != (QWidget*)ListCoincident)
1036 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1037 QListWidgetItem* anItem;
1039 foreach(anItem, selItems)
1046 //=================================================================================
1047 // function : onSetFirst()
1049 //=================================================================================
1050 void SMESHGUI_MergeDlg::onSetFirst()
1052 if (myEditCurrentArgument != (QWidget*)ListCoincident)
1056 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1057 QListWidgetItem* anItem;
1059 foreach(anItem, selItems) {
1060 ListEdit->takeItem(ListEdit->row(anItem));
1061 ListEdit->insertItem(0, anItem);
1068 //=================================================================================
1069 // function : SetEditCurrentArgument()
1071 //=================================================================================
1072 void SMESHGUI_MergeDlg::SetEditCurrentArgument()
1074 QPushButton* send = (QPushButton*)sender();
1076 disconnect(mySelectionMgr, 0, this, 0);
1077 mySelectionMgr->clearSelected();
1078 mySelectionMgr->clearFilters();
1080 if (send == SelectMeshButton) {
1081 myEditCurrentArgument = (QWidget*)LineEditMesh;
1082 SMESH::SetPointRepresentation(false);
1083 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1084 aViewWindow->SetSelectionMode(ActorSelection);
1086 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1089 myEditCurrentArgument->setFocus();
1090 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1091 SelectionIntoArgument();
1094 //=================================================================================
1095 // function : SelectionIntoArgument()
1096 // purpose : Called when selection as changed or other case
1097 //=================================================================================
1098 void SMESHGUI_MergeDlg::SelectionIntoArgument()
1100 if (myEditCurrentArgument == (QWidget*)LineEditMesh) {
1101 QString aString = "";
1102 LineEditMesh->setText(aString);
1104 ListCoincident->clear();
1107 QString aCurrentEntry = myEntry;
1109 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1111 myIdPreview->SetPointsLabeled(false);
1112 SMESH::SetPointRepresentation(false);
1113 mySelectionMgr->clearFilters();
1114 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1115 aViewWindow->SetSelectionMode(ActorSelection);
1119 SALOME_ListIO aList;
1120 mySelectionMgr->selectedObjects(aList);
1122 Handle(SALOME_InteractiveObject) IO = aList.First();
1123 myEntry = IO->getEntry();
1124 myMesh = SMESH::GetMeshByIO(IO);
1126 if (myMesh->_is_nil())
1129 LineEditMesh->setText(aString);
1131 myActor = SMESH::FindActorByEntry(IO->getEntry());
1133 myActor = SMESH::FindActorByObject(myMesh);
1135 if ( myActor && myTypeId ==1 ) {
1136 mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
1137 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1139 if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
1140 !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
1141 !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
1142 mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1144 if (myAction == 0) {
1145 SMESH::SetPointRepresentation(true);
1146 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1147 aViewWindow->SetSelectionMode(NodeSelection);
1150 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1151 aViewWindow->SetSelectionMode(CellSelection);
1155 if ( myAction == 0 && !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
1157 ListExclude->clear();
1158 SMESH::ListOfGroups_var aListOfGroups = myMesh->GetGroups();
1159 for( int i = 0, n = aListOfGroups->length(); i < n; i++ ) {
1160 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
1161 if ( !aGroup->_is_nil() ) { // && aGroup->GetType() == SMESH::NODE
1162 QString aGroupName( aGroup->GetName() );
1163 if ( !aGroupName.isEmpty() ) {
1164 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
1165 QListWidgetItem* item = new QListWidgetItem( aGroupName );
1166 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
1167 item->setCheckState( Qt::Unchecked );
1168 ListExclude->addItem( item );
1178 //=================================================================================
1179 // function : DeactivateActiveDialog()
1181 //=================================================================================
1182 void SMESHGUI_MergeDlg::DeactivateActiveDialog()
1184 if (GroupConstructors->isEnabled()) {
1185 GroupConstructors->setEnabled(false);
1186 TypeBox->setEnabled(false);
1187 GroupMesh->setEnabled(false);
1188 GroupCoincident->setEnabled(false);
1189 GroupEdit->setEnabled(false);
1190 GroupButtons->setEnabled(false);
1191 mySMESHGUI->ResetState();
1192 mySMESHGUI->SetActiveDialogBox(0);
1195 mySelectionMgr->clearSelected();
1196 disconnect(mySelectionMgr, 0, this, 0);
1199 //=================================================================================
1200 // function : ActivateThisDialog()
1202 //=================================================================================
1203 void SMESHGUI_MergeDlg::ActivateThisDialog()
1205 /* Emit a signal to deactivate the active dialog */
1206 mySMESHGUI->EmitSignalDeactivateDialog();
1207 GroupConstructors->setEnabled(true);
1208 TypeBox->setEnabled(true);
1209 GroupMesh->setEnabled(true);
1210 GroupCoincident->setEnabled(true);
1211 GroupEdit->setEnabled(true);
1212 GroupButtons->setEnabled(true);
1214 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1215 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1216 SelectionIntoArgument();
1219 //=================================================================================
1220 // function : enterEvent()
1222 //=================================================================================
1223 void SMESHGUI_MergeDlg::enterEvent(QEvent*)
1225 if (!GroupConstructors->isEnabled())
1226 ActivateThisDialog();
1229 //=================================================================================
1230 // function : keyPressEvent()
1232 //=================================================================================
1233 void SMESHGUI_MergeDlg::keyPressEvent( QKeyEvent* e)
1235 QDialog::keyPressEvent( e );
1236 if ( e->isAccepted() )
1239 if ( e->key() == Qt::Key_F1 ) {
1245 //=================================================================================
1246 // function : onTypeChanged()
1247 // purpose : the type radio button management
1248 //=================================================================================
1249 void SMESHGUI_MergeDlg::onTypeChanged (int id)
1257 case 0: // automatic
1258 myIdPreview->SetPointsLabeled(false);
1259 SMESH::SetPointRepresentation(false);
1260 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1261 aViewWindow->SetSelectionMode(ActorSelection);
1262 mySelectionMgr->clearFilters();
1264 GroupCoincidentWidget->hide();
1266 GroupCoincident->hide();
1271 SMESH::UpdateView();
1273 // Costruction of the logical filter
1274 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
1275 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
1277 QList<SUIT_SelectionFilter*> aListOfFilters;
1278 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
1279 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
1281 myMeshOrSubMeshOrGroupFilter =
1282 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
1284 if (myAction == 0) {
1285 GroupCoincidentWidget->show();
1286 SMESH::SetPointRepresentation(true);
1287 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1288 aViewWindow->SetSelectionMode(NodeSelection);
1291 GroupCoincident->show();
1292 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1293 aViewWindow->SetSelectionMode(CellSelection);
1300 qApp->processEvents();
1304 SelectionIntoArgument();