1 // Copyright (C) 2007-2019 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_IdPreview.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_SpinBox.h"
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_VTKUtils.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.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 <QApplication>
66 #include <QButtonGroup>
68 #include <QGridLayout>
70 #include <QHBoxLayout>
74 #include <QListWidget>
75 #include <QPushButton>
76 #include <QRadioButton>
77 #include <QVBoxLayout>
84 enum ActionType { MERGE_NODES, MERGE_ELEMENTS, TYPE_AUTO=0, TYPE_MANUAL };
88 QPixmap SMESHGUI_MergeDlg::IconFirst()
90 static const char * iconFirst[] = {
104 return QPixmap( iconFirst );
107 //=================================================================================
108 // class : SMESHGUI_MergeDlg()
110 //=================================================================================
111 SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
112 : QDialog(SMESH::GetDesktop(theModule)),
113 mySMESHGUI(theModule),
114 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
117 const bool isElems = ( myAction == MERGE_ELEMENTS );
119 setAttribute(Qt::WA_DeleteOnClose, true);
120 setWindowTitle( isElems ? tr("SMESH_MERGE_ELEMENTS") : tr("SMESH_MERGE_NODES"));
122 myIdPreview = new SMESHGUI_IdPreview(SMESH::GetViewWindow( mySMESHGUI ));
124 SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
125 // QPixmap IconMergeNodes (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_MERGE_NODES")));
126 // QPixmap IconMergeElems (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_MERGE_ELEMENTS")));
127 QPixmap IconSelect (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
128 QPixmap IconAdd (aResMgr->loadPixmap("SMESH", tr("ICON_APPEND")));
129 QPixmap IconRemove (aResMgr->loadPixmap("SMESH", tr("ICON_REMOVE")));
131 setSizeGripEnabled(true);
133 /***************************************************************/
134 // Controls to switch dialog behaviour (myTypeId)
136 TypeBox = new QGroupBox( tr("SMESH_MODE"), this );
137 GroupType = new QButtonGroup( this );
138 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( TypeBox );
139 aTypeBoxLayout->setMargin( MARGIN );
140 aTypeBoxLayout->setSpacing( SPACING );
142 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_AUTOMATIC" ), TypeBox );
143 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_MANUAL" ), TypeBox );
144 GroupType->addButton( rb1, 0 );
145 GroupType->addButton( rb2, 1 );
146 aTypeBoxLayout->addWidget( rb1 );
147 aTypeBoxLayout->addWidget( rb2 );
149 myTypeId = TYPE_AUTO;
151 /***************************************************************/
152 // Controls for mesh defining
154 GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), this);
155 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
156 GroupMeshLayout->setSpacing(SPACING);
157 GroupMeshLayout->setMargin(MARGIN);
159 TextLabelName = new QLabel(tr("SMESH_NAMES"), GroupMesh);
160 SelectMeshButton = new QPushButton(GroupMesh);
161 SelectMeshButton->setIcon(IconSelect);
162 LineEditMesh = new QLineEdit(GroupMesh);
163 LineEditMesh->setReadOnly(true);
165 GroupMeshLayout->addWidget(TextLabelName);
166 GroupMeshLayout->addWidget(SelectMeshButton);
167 GroupMeshLayout->addWidget(LineEditMesh);
169 /***************************************************************/
170 // Controls for coincident elements detecting
172 GroupCoincident = new QGroupBox(tr(isElems ? "COINCIDENT_ELEMENTS" : "COINCIDENT_NODES"), this);
174 QGridLayout* aCoincidentLayout = new QGridLayout(GroupCoincident);
175 aCoincidentLayout->setSpacing(SPACING);
176 aCoincidentLayout->setMargin(MARGIN);
178 if (myAction == MERGE_NODES) // case merge nodes
180 /***************************************************************/
181 // Node specific Controls: tolerance, ...
183 NodeSpecWidget = new QWidget( this );
185 QLabel* TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), NodeSpecWidget);
186 SpinBoxTolerance = new SMESHGUI_SpinBox( NodeSpecWidget );
187 SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
189 SeparateCornersAndMedium = new QCheckBox(tr("SEPARATE_CORNERS_AND_MEDIUM"), NodeSpecWidget );
190 SeparateCornersAndMedium->setEnabled( false );
192 AvoidMakingHoles = new QCheckBox(tr("AVOID_MAKING_HOLES"), NodeSpecWidget );
193 AvoidMakingHoles->setChecked( false );
195 QGridLayout* NodeSpecLayout = new QGridLayout(NodeSpecWidget);
196 NodeSpecLayout->setSpacing(SPACING);
197 NodeSpecLayout->setMargin(0);
199 NodeSpecLayout->addWidget(TextLabelTolerance, 0, 0 );
200 NodeSpecLayout->addWidget(SpinBoxTolerance, 0, 1 );
201 NodeSpecLayout->addWidget(SeparateCornersAndMedium, 1, 0, 1, 2 );
202 NodeSpecLayout->addWidget(AvoidMakingHoles, 2, 0, 1, 2 );
206 SpinBoxTolerance = 0;
209 KeepFromButGroup = 0;
210 SelectKeepButton = 0;
212 RemoveKeepButton = 0;
214 mySubMeshOrGroupFilter = 0;
217 /***************************************************************/
220 GroupExclude = new QGroupBox(tr("EXCLUDE_GROUPS"), this );
221 GroupExclude->setCheckable( true );
222 GroupExclude->setChecked( false );
223 ListExclude = new QListWidget( GroupExclude );
224 QVBoxLayout* GroupExcludeLayout = new QVBoxLayout(GroupExclude);
225 GroupExcludeLayout->setSpacing(SPACING);
226 GroupExcludeLayout->setMargin(MARGIN);
227 GroupExcludeLayout->addWidget(ListExclude);
229 /***************************************************************/
230 // Nodes/elements to keep
232 GroupKeep = new QGroupBox(tr( isElems ? "KEEP_ELEMENTS" : "KEEP_NODES"), this);
233 SelectKeepButton = new QPushButton( GroupKeep );
234 SelectKeepButton->setIcon( IconSelect );
235 QLabel* selectLabel = new QLabel(tr("SELECT"));
236 QRadioButton* idsButton = new QRadioButton(tr(isElems ? "SMESH_ELEMENTS" : "SMESH_NODES"),
238 QRadioButton* groupButton = new QRadioButton(tr("GROUP_SUBMESH"), GroupKeep);
239 KeepFromButGroup = new QButtonGroup( this );
240 KeepFromButGroup->addButton( idsButton, 0 );
241 KeepFromButGroup->addButton( groupButton, 1 );
242 groupButton->setChecked( true );
243 KeepList = new QListWidget( GroupKeep );
244 KeepList->setSelectionMode(QAbstractItemView::ExtendedSelection);
245 KeepList->setFlow(QListView::TopToBottom);
246 AddKeepButton = new QPushButton(tr("SMESH_BUT_ADD"), GroupKeep );
247 RemoveKeepButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupKeep );
248 QGridLayout* GroupKeepLayout = new QGridLayout(GroupKeep);
249 GroupKeepLayout->setSpacing( SPACING );
250 GroupKeepLayout->setMargin ( MARGIN );
251 GroupKeepLayout->addWidget( SelectKeepButton, 0, 0 );
252 GroupKeepLayout->addWidget( selectLabel, 0, 1 );
253 GroupKeepLayout->addWidget( idsButton, 0, 2 );
254 GroupKeepLayout->addWidget( groupButton, 0, 3, 1, 2 );
255 GroupKeepLayout->addWidget( KeepList, 1, 0, 3, 4 );
256 GroupKeepLayout->addWidget( AddKeepButton, 1, 4, 1, 1 );
257 GroupKeepLayout->addWidget( RemoveKeepButton, 2, 4, 1, 1 );
258 GroupKeepLayout->setRowStretch(3, 5);
260 // Costruction of the logical filter
261 QList<SUIT_SelectionFilter*> aListOfFilters;
262 aListOfFilters << new SMESH_TypeFilter (SMESH::SUBMESH)
263 << new SMESH_TypeFilter (SMESH::GROUP);
264 mySubMeshOrGroupFilter =
265 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
267 ListCoincident = new QListWidget(GroupCoincident);
268 ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
270 DetectButton = new QPushButton(tr("DETECT"), GroupCoincident);
271 AddGroupButton = new QPushButton(tr("SMESH_BUT_ADD"), GroupCoincident);
272 RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincident);
274 SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincident);
275 ShowIDs = new QCheckBox( isElems ? tr("SHOW_ELEMS_IDS") : tr("SHOW_NODES_IDS"), GroupCoincident);
277 aCoincidentLayout->addWidget(ListCoincident, 0, 0, 4, 2);
278 aCoincidentLayout->addWidget(DetectButton, 0, 2);
279 aCoincidentLayout->addWidget(AddGroupButton, 2, 2);
280 aCoincidentLayout->addWidget(RemoveGroupButton, 3, 2);
281 aCoincidentLayout->addWidget(SelectAllCB, 4, 0);
282 aCoincidentLayout->addWidget(ShowIDs, 4, 1);
283 aCoincidentLayout->setRowMinimumHeight(1, 10);
284 aCoincidentLayout->setRowStretch(1, 5);
286 /***************************************************************/
287 // Controls for editing the selected group
289 GroupEdit = new QGroupBox( tr(isElems ? "EDIT_SELECTED_ELEM_GROUP" : "EDIT_SELECTED_NODE_GROUP"), this);
290 QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
291 GroupEditLayout->setSpacing(SPACING);
292 GroupEditLayout->setMargin(MARGIN);
294 ListEdit = new QListWidget(GroupEdit);
295 //ListEdit->setRowMode(QListBox::FixedNumber);
296 //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
297 //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
298 ListEdit->setFlow( QListView::LeftToRight );
299 ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
301 AddElemButton = new QPushButton(GroupEdit);
302 AddElemButton->setIcon(IconAdd);
303 RemoveElemButton = new QPushButton(GroupEdit);
304 RemoveElemButton->setIcon(IconRemove);
305 SetFirstButton = new QPushButton(GroupEdit);
306 SetFirstButton->setIcon(IconFirst());
308 GroupEditLayout->addWidget(ListEdit, 0, 0, 2, 1);
309 GroupEditLayout->addWidget(AddElemButton, 0, 1);
310 GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
311 GroupEditLayout->addWidget(SetFirstButton, 1, 1, 1, 2);
313 /***************************************************************/
314 GroupButtons = new QGroupBox(this);
315 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
316 GroupButtonsLayout->setSpacing(SPACING);
317 GroupButtonsLayout->setMargin(MARGIN);
319 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
320 buttonOk->setAutoDefault(true);
321 buttonOk->setDefault(true);
322 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
323 buttonApply->setAutoDefault(true);
324 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
325 buttonCancel->setAutoDefault(true);
326 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
327 buttonHelp->setAutoDefault(true);
329 GroupButtonsLayout->addWidget(buttonOk);
330 GroupButtonsLayout->addSpacing(10);
331 GroupButtonsLayout->addWidget(buttonApply);
332 GroupButtonsLayout->addSpacing(10);
333 GroupButtonsLayout->addStretch();
334 GroupButtonsLayout->addWidget(buttonCancel);
335 GroupButtonsLayout->addWidget(buttonHelp);
337 /***************************************************************/
338 //if (myAction == MERGE_NODES)
340 QWidget* LeftWdg = new QWidget( this );
341 QVBoxLayout* LeftLayout = new QVBoxLayout(LeftWdg);
342 LeftLayout->setSpacing(SPACING);
343 LeftLayout->setMargin(0);
344 LeftLayout->addWidget(TypeBox);
345 LeftLayout->addWidget(GroupMesh);
347 LeftLayout->addWidget(NodeSpecWidget);
348 LeftLayout->addWidget(GroupCoincident);
349 LeftLayout->addStretch();
350 LeftLayout->addWidget(GroupButtons);
351 LeftLayout->setStretch( 3, 10 );
353 QWidget* RightWdg = new QWidget( this );
354 QVBoxLayout* RightLayout = new QVBoxLayout(RightWdg);
355 RightLayout->setSpacing(SPACING);
356 RightLayout->setMargin(0);
357 RightLayout->addWidget(GroupExclude);
358 RightLayout->addWidget(GroupKeep);
359 RightLayout->addWidget(GroupEdit);
360 RightLayout->setStretch( 0, 4 );
361 RightLayout->setStretch( 1, 5 );
363 QHBoxLayout* DlgLayout = new QHBoxLayout(this);
364 DlgLayout->setSpacing(SPACING*2);
365 DlgLayout->setMargin(MARGIN);
366 DlgLayout->addWidget( LeftWdg );
367 DlgLayout->addWidget( RightWdg );
371 // QVBoxLayout* DlgLayout = new QVBoxLayout(this);
372 // DlgLayout->setSpacing(SPACING);
373 // DlgLayout->setMargin(MARGIN);
374 // DlgLayout->addWidget(TypeBox);
375 // DlgLayout->addWidget(GroupMesh);
376 // DlgLayout->addWidget(GroupCoincident);
377 // DlgLayout->addWidget(GroupEdit);
378 // DlgLayout->addWidget(GroupButtons);
381 GroupCoincident->hide();
386 ShowIDs->setChecked( true );
388 Init(); // Initialisations
391 //=================================================================================
392 // function : ~SMESHGUI_MergeDlg()
393 // purpose : Destroys the object and frees any allocated resources
394 //=================================================================================
395 SMESHGUI_MergeDlg::~SMESHGUI_MergeDlg()
400 //=================================================================================
403 //=================================================================================
404 void SMESHGUI_MergeDlg::Init()
406 if ( myAction == MERGE_NODES ) {
407 SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision");
408 SpinBoxTolerance->SetValue(1e-05);
411 GroupType->button(0)->setChecked(true);
413 myEditCurrentArgument = (QWidget*)LineEditMesh;
416 mySubMeshOrGroups = new SMESH::ListOfIDSources;
418 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
420 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
423 /* signals and slots connections */
424 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
425 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
426 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
427 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
431 connect(SelectKeepButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
432 connect(KeepFromButGroup, SIGNAL (buttonClicked(int)), SLOT(onKeepSourceChanged(int)));
433 connect(AddKeepButton, SIGNAL (clicked()), this, SLOT(onAddKeep()));
434 connect(RemoveKeepButton, SIGNAL (clicked()), this, SLOT(onRemoveKeep()));
435 connect(KeepList, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectKeep()));
437 connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
438 connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
439 connect(ListCoincident, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectGroup()));
440 connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
441 connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
442 connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
443 connect(ShowIDs, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup()));
444 connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
445 connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
446 connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
447 connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst()));
448 connect(GroupType, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
450 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
451 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
452 /* to close dialog if study change */
453 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
454 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
455 connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
456 // Init Mesh field from selection
457 SelectionIntoArgument();
462 if ( myAction == MERGE_NODES )
463 myHelpFileName = "merging_nodes.html";
465 myHelpFileName = "merging_elements.html";
468 //=================================================================================
469 // function : FindGravityCenter()
471 //=================================================================================
472 void SMESHGUI_MergeDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap,
473 std::vector<int>& theIDs,
474 std::list< gp_XYZ > & theGrCentersXYZ)
479 SMDS_Mesh* aMesh = 0;
480 aMesh = myActor->GetObject()->GetMesh();
486 theIDs.reserve( theElemsIdMap.Extent() );
487 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
488 for( ; idIter.More(); idIter.Next() ) {
489 const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
492 theIDs.push_back( idIter.Key() );
494 gp_XYZ anXYZ(0., 0., 0.);
495 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
496 for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
497 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
498 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
500 anXYZ.Divide( nbNodes );
502 theGrCentersXYZ.push_back( anXYZ );
506 //=================================================================================
507 // function : ClickOnApply()
509 //=================================================================================
510 bool SMESHGUI_MergeDlg::ClickOnApply()
512 if (SMESHGUI::isStudyLocked() || myMesh->_is_nil())
516 if (myTypeId == TYPE_AUTO)
519 SUIT_OverrideCursor aWaitCursor;
520 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
522 SMESH::long_array_var anIds = new SMESH::long_array;
523 SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
525 if ( ListCoincident->count() == 0) {
526 if ( myAction == MERGE_NODES )
527 SUIT_MessageBox::warning(this,
529 tr("SMESH_NO_NODES_DETECTED"));
531 SUIT_MessageBox::warning(this,
533 tr("SMESH_NO_ELEMENTS_DETECTED"));
537 aGroupsOfElements->length(ListCoincident->count());
540 for (int i = 0; i < ListCoincident->count(); i++)
542 QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
544 anIds->length(aListIds.count());
545 for (int i = 0; i < aListIds.count(); i++)
546 anIds[i] = aListIds[i].toInt();
548 aGroupsOfElements[anArrayNum++] = anIds.inout();
551 SMESH::ListOfIDSources_var toKeep;
552 SMESH::IDSource_wrap tmpIdSource;
553 //if ( myAction == MERGE_NODES )
555 toKeep = new SMESH::ListOfIDSources();
556 int i, nb = KeepList->count();
557 if ( isKeepIDsSelection() )
559 SMESH::long_array_var anIdList = new SMESH::long_array();
560 anIdList->length(nb);
561 for (i = 0; i < nb; i++)
562 anIdList[i] = KeepList->item(i)->text().toInt();
566 tmpIdSource = aMeshEditor->MakeIDSource( anIdList, SMESH::NODE );
568 toKeep[0] = SMESH::SMESH_IDSource::_duplicate( tmpIdSource.in() );
573 toKeep->length( nb );
575 for (i = 0; i < nb; i++)
577 QString entry = KeepList->item( i )->data( Qt::UserRole ).toString();
578 Handle(SALOME_InteractiveObject) anIO =
579 new SALOME_InteractiveObject( entry.toStdString().c_str(), "SMESH" );
580 SMESH::SMESH_IDSource_var idSrc =
581 SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( anIO );
582 if ( !idSrc->_is_nil() )
583 toKeep[ nbObj++ ] = SMESH::SMESH_IDSource::_duplicate( idSrc );
585 toKeep->length( nbObj );
590 if( myAction == MERGE_NODES )
591 aMeshEditor->MergeNodes( aGroupsOfElements.inout(), toKeep, AvoidMakingHoles->isChecked() );
593 aMeshEditor->MergeElements( aGroupsOfElements.inout(), toKeep );
595 if ( myTypeId == TYPE_AUTO ) {
596 if ( myAction == MERGE_NODES )
597 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
598 tr("SMESH_MERGED_NODES").arg(QString::number(ListCoincident->count()).toLatin1().data()));
600 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
601 tr("SMESH_MERGED_ELEMENTS").arg(QString::number(ListCoincident->count()).toLatin1().data()));
604 toKeep->length(0); // release before tmpIdSource calls UnRegister()
610 ListCoincident->clear();
612 myEditCurrentArgument = (QWidget*)LineEditMesh;
615 SMESHGUI::Modified();
620 //=================================================================================
621 // function : ClickOnOk()
623 //=================================================================================
624 void SMESHGUI_MergeDlg::ClickOnOk()
630 //=================================================================================
631 // function : reject()
633 //=================================================================================
634 void SMESHGUI_MergeDlg::reject()
636 myIdPreview->SetPointsLabeled(false);
637 SMESH::SetPointRepresentation(false);
638 disconnect(mySelectionMgr, 0, this, 0);
639 disconnect(mySMESHGUI, 0, this, 0);
640 mySMESHGUI->ResetState();
642 mySelectionMgr->clearFilters();
643 //mySelectionMgr->clearSelected();
645 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
646 aViewWindow->SetSelectionMode(ActorSelection);
651 //=================================================================================
652 // function : onOpenView()
654 //=================================================================================
655 void SMESHGUI_MergeDlg::onOpenView()
658 SMESH::SetPointRepresentation(false);
661 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
662 ActivateThisDialog();
666 //=================================================================================
667 // function : onCloseView()
669 //=================================================================================
670 void SMESHGUI_MergeDlg::onCloseView()
672 DeactivateActiveDialog();
676 //=================================================================================
677 // function : ClickOnHelp()
679 //=================================================================================
680 void SMESHGUI_MergeDlg::ClickOnHelp()
682 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
684 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
688 platform = "winapplication";
690 platform = "application";
692 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
693 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
694 arg(app->resourceMgr()->stringValue("ExternalBrowser",
696 arg(myHelpFileName));
700 //=================================================================================
701 // function : onEditGroup()
703 //=================================================================================
704 void SMESHGUI_MergeDlg::onEditGroup()
706 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
707 if ( selItems.count() != 1 ) {
714 for (int i = 0; i < ListEdit->count(); i++ )
715 aNewIds.append(ListEdit->item(i)->text());
717 ListCoincident->clearSelection();
718 selItems.first()->setText(aNewIds.join(" "));
719 selItems.first()->setSelected(true);
722 //=================================================================================
723 // function : updateControls()
725 //=================================================================================
726 void SMESHGUI_MergeDlg::updateControls()
728 if (ListEdit->count() == 0)
729 SetFirstButton->setEnabled(false);
731 bool groupsEmpty = ( myTypeId != TYPE_AUTO );
732 for (int i = 0; i < ListCoincident->count() && groupsEmpty; i++) {
733 QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
734 groupsEmpty = ( aListIds.count() < 2 );
736 bool enable = ( !myMesh->_is_nil() && !groupsEmpty );
737 buttonOk->setEnabled(enable);
738 buttonApply->setEnabled(enable);
739 DetectButton->setEnabled( !myMesh->_is_nil() );
741 if ( myAction == MERGE_NODES )
743 bool has2ndOrder = (( !myMesh->_is_nil() ) &&
744 ( myMesh->NbEdgesOfOrder( SMESH::ORDER_QUADRATIC ) > 0 ||
745 myMesh->NbFacesOfOrder( SMESH::ORDER_QUADRATIC ) > 0 ||
746 myMesh->NbVolumesOfOrder( SMESH::ORDER_QUADRATIC ) > 0 ));
748 SeparateCornersAndMedium->setEnabled( has2ndOrder );
751 if ( myEditCurrentArgument != KeepList )
753 AddKeepButton->setEnabled( false );
754 RemoveKeepButton->setEnabled( false );
755 KeepList->clearSelection();
760 //=================================================================================
761 // function : onDetect()
763 //=================================================================================
764 void SMESHGUI_MergeDlg::onDetect()
766 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
770 SUIT_OverrideCursor aWaitCursor;
771 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
773 ListCoincident->clear();
776 SMESH::array_of_long_array_var aGroupsArray;
777 SMESH::ListOfIDSources_var aExcludeGroups = new SMESH::ListOfIDSources;
779 for ( int i = 0; GroupExclude->isChecked() && i < ListExclude->count(); i++ ) {
780 if ( ListExclude->item( i )->checkState() == Qt::Checked ) {
781 aExcludeGroups->length( aExcludeGroups->length()+1 );
782 aExcludeGroups[ aExcludeGroups->length()-1 ] = SMESH::SMESH_IDSource::_narrow( myGroups[i] );
788 aMeshEditor->FindCoincidentNodesOnPartBut(mySubMeshOrGroups.in(),
789 SpinBoxTolerance->GetValue(),
792 SeparateCornersAndMedium->isEnabled() &&
793 SeparateCornersAndMedium->isChecked());
795 case MERGE_ELEMENTS :
796 aMeshEditor->FindEqualElements(mySubMeshOrGroups.in(),
802 for ( CORBA::ULong i = 0; i < aGroupsArray->length(); i++)
804 SMESH::long_array& aGroup = aGroupsArray[i];
807 for ( CORBA::ULong j = 0; j < aGroup.length(); j++ )
808 anIDs.append( QString::number( aGroup[j] ));
810 ListCoincident->addItem( anIDs.join(" "));
815 ListCoincident->selectAll();
820 //=================================================================================
821 // function : onSelectGroup()
823 //=================================================================================
824 void SMESHGUI_MergeDlg::onSelectGroup()
826 if (myIsBusy || !myActor)
829 if( ListCoincident->count() != ListCoincident->selectedItems().count() )
830 SelectAllCB->setChecked( false );
832 if ( myEditCurrentArgument == (QWidget*)KeepList && KeepList &&
833 !isKeepIDsSelection() )
835 // restore selection of nodes after selection of sub-meshes
836 mySelectionMgr->clearFilters();
837 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
838 aViewWindow->SetSelectionMode( NodeSelection );
839 SMESH::SetPointRepresentation( true );
840 myEditCurrentArgument = ListCoincident;
843 myEditCurrentArgument = (QWidget*)ListCoincident;
848 TColStd_MapOfInteger anIndices;
849 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
850 QListWidgetItem* anItem;
851 QStringList aListIds;
855 foreach(anItem, selItems) {
856 aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
857 for (int i = 0; i < aListIds.count(); i++)
858 anIndices.Add(aListIds[i].toInt());
861 if (selItems.count() == 1) {
862 ListEdit->addItems(aListIds);
863 ListEdit->selectAll();
866 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
868 aList.Append(myActor->getIO());
869 mySelectionMgr->setSelectedObjects(aList,false);
871 if (ShowIDs->isChecked())
872 if ( myAction == MERGE_NODES ) {
873 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
874 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
877 std::list< gp_XYZ > aGrCentersXYZ;
878 std::vector<int> anIDs;
879 FindGravityCenter(anIndices, anIDs, aGrCentersXYZ);
880 myIdPreview->SetElemsData( anIDs, aGrCentersXYZ );
881 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
884 myIdPreview->SetPointsLabeled(false);
890 //=================================================================================
891 // function : onSelectAll()
893 //=================================================================================
894 void SMESHGUI_MergeDlg::onSelectAll (bool isToggled)
897 ListCoincident->selectAll();
899 ListCoincident->clearSelection();
902 //=================================================================================
903 // function : onSelectElementFromGroup()
905 //=================================================================================
906 void SMESHGUI_MergeDlg::onSelectElementFromGroup()
908 if (myIsBusy || !myActor)
911 TColStd_MapOfInteger anIndices;
912 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
913 QListWidgetItem* anItem;
915 foreach(anItem, selItems)
916 anIndices.Add(anItem->text().toInt());
918 SetFirstButton->setEnabled(selItems.count() == 1);
920 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
922 aList.Append(myActor->getIO());
923 mySelectionMgr->setSelectedObjects(aList);
925 if (ShowIDs->isChecked())
926 if (myAction == MERGE_NODES) {
927 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
928 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
931 std::list< gp_XYZ > aGrCentersXYZ;
932 std::vector<int> anIDs;
933 FindGravityCenter(anIndices, anIDs, aGrCentersXYZ);
934 myIdPreview->SetElemsData(anIDs, aGrCentersXYZ);
935 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
938 myIdPreview->SetPointsLabeled(false);
940 if ( myEditCurrentArgument == (QWidget*)KeepList && KeepList &&
941 !isKeepIDsSelection() )
943 // restore selection of nodes after selection of sub-meshes
944 mySelectionMgr->clearFilters();
945 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
946 aViewWindow->SetSelectionMode( NodeSelection );
947 SMESH::SetPointRepresentation( true );
948 myEditCurrentArgument = ListCoincident;
952 //=================================================================================
953 // function : onAddGroup()
955 //=================================================================================
956 void SMESHGUI_MergeDlg::onAddGroup()
958 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
963 aNbElements = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
968 ListCoincident->clearSelection();
969 ListCoincident->addItem(anIDs);
970 int nbGroups = ListCoincident->count();
972 ListCoincident->setCurrentRow(nbGroups-1);
973 ListCoincident->item(nbGroups-1)->setSelected(true);
976 // VSR ? this code seems to be never executed!!!
977 ListCoincident->setCurrentRow(0);
978 //ListCoincident->setSelected(0, true); // VSR: no items - no selection
984 //=================================================================================
985 // function : onRemoveGroup()
987 //=================================================================================
988 void SMESHGUI_MergeDlg::onRemoveGroup()
990 if (myEditCurrentArgument != (QWidget*)ListCoincident)
994 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
995 QListWidgetItem* anItem;
997 foreach(anItem, selItems)
1001 myIdPreview->SetPointsLabeled(false);
1003 SMESH::UpdateView();
1006 if( ListCoincident->count() == 0 ) {
1007 myEditCurrentArgument = (QWidget*)LineEditMesh;
1008 SelectAllCB->setChecked( false );
1012 //=================================================================================
1013 // function : onAddElement()
1015 //=================================================================================
1016 void SMESHGUI_MergeDlg::onAddElement()
1022 QString aListStr = "";
1025 aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1029 QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
1031 for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
1032 QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
1033 if ( found.count() == 0 ) {
1034 QListWidgetItem* anItem = new QListWidgetItem(*it);
1035 ListEdit->addItem(anItem);
1036 anItem->setSelected(true);
1039 QListWidgetItem* anItem;
1040 foreach(anItem, found) anItem->setSelected(true);
1048 //=================================================================================
1049 // function : onRemoveElement()
1051 //=================================================================================
1052 void SMESHGUI_MergeDlg::onRemoveElement()
1054 if (myEditCurrentArgument != (QWidget*)ListCoincident)
1058 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1059 QListWidgetItem* anItem;
1061 foreach(anItem, selItems)
1067 if( ListCoincident->count() == 0 ) {
1068 myEditCurrentArgument = (QWidget*)LineEditMesh;
1069 SelectAllCB->setChecked( false );
1073 //=================================================================================
1074 // function : onSetFirst()
1076 //=================================================================================
1077 void SMESHGUI_MergeDlg::onSetFirst()
1079 if (myEditCurrentArgument != (QWidget*)ListCoincident)
1083 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1084 QListWidgetItem* anItem;
1086 foreach(anItem, selItems) {
1087 ListEdit->takeItem(ListEdit->row(anItem));
1088 ListEdit->insertItem(0, anItem);
1095 //=================================================================================
1096 // function : SetEditCurrentArgument()
1098 //=================================================================================
1099 void SMESHGUI_MergeDlg::SetEditCurrentArgument()
1101 QPushButton* send = (QPushButton*)sender();
1103 disconnect(mySelectionMgr, 0, this, 0);
1104 mySelectionMgr->clearSelected();
1105 mySelectionMgr->clearFilters();
1107 if (send == SelectMeshButton)
1109 myEditCurrentArgument = (QWidget*)LineEditMesh;
1110 SMESH::SetPointRepresentation(false);
1111 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1112 aViewWindow->SetSelectionMode(ActorSelection);
1113 if (myTypeId == TYPE_MANUAL)
1114 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1116 else if ( send == SelectKeepButton && send )
1118 myEditCurrentArgument = (QWidget*)KeepList;
1119 KeepList->setWrapping( isKeepIDsSelection() );
1120 if ( isKeepIDsSelection() )
1122 bool isElems = ( myAction == MERGE_ELEMENTS );
1123 SMESH::SetPointRepresentation( !isElems );
1124 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1125 aViewWindow->SetSelectionMode( isElems ? CellSelection : NodeSelection );
1129 SMESH::SetPointRepresentation( false );
1130 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1131 aViewWindow->SetSelectionMode( ActorSelection );
1132 mySelectionMgr->installFilter( mySubMeshOrGroupFilter );
1136 myEditCurrentArgument->setFocus();
1137 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1138 SelectionIntoArgument();
1141 //=================================================================================
1142 // function : SelectionIntoArgument()
1143 // purpose : Called when selection has changed or other case
1144 //=================================================================================
1145 void SMESHGUI_MergeDlg::SelectionIntoArgument()
1147 if (myEditCurrentArgument == (QWidget*)LineEditMesh)
1149 QString aString = "";
1150 LineEditMesh->setText(aString);
1152 ListCoincident->clear();
1154 ListExclude->clear();
1156 myMesh = SMESH::SMESH_Mesh::_nil();
1157 QString aCurrentEntry = myEntry;
1159 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1161 myIdPreview->SetPointsLabeled(false);
1162 SMESH::SetPointRepresentation(false);
1163 mySelectionMgr->clearFilters();
1164 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1165 aViewWindow->SetSelectionMode(ActorSelection);
1169 SALOME_ListIO aList;
1170 mySelectionMgr->selectedObjects(aList);
1172 Handle(SALOME_InteractiveObject) IO = aList.First();
1173 myEntry = IO->getEntry();
1174 myMesh = SMESH::GetMeshByIO(IO);
1176 if ( myEntry != aCurrentEntry && KeepList )
1179 if (myMesh->_is_nil())
1182 myActor = SMESH::FindActorByEntry(IO->getEntry());
1184 myActor = SMESH::FindActorByObject(myMesh);
1186 mySubMeshOrGroups->length( nbSel );
1188 bool isMeshSelected = false;
1189 while ( !aList.IsEmpty() )
1192 aList.RemoveFirst();
1193 SMESH::SMESH_IDSource_var idSrc = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1194 if ( !idSrc->_is_nil() )
1196 SMESH::SMESH_Mesh_var mesh = idSrc->GetMesh();
1197 if ( !mesh->_is_equivalent( myMesh ))
1202 mySubMeshOrGroups[ nbSel++ ] = idSrc;
1203 if ( idSrc->_is_equivalent( myMesh ))
1205 isMeshSelected = true;
1206 mySubMeshOrGroups[ 0 ] = idSrc;
1207 aString = SMESH::GetName( IO );
1208 // break; -- to check if other selected belongs to myMesh
1213 if ( isMeshSelected && nbSel > 1 )
1215 mySubMeshOrGroups->length( nbSel );
1219 LineEditMesh->setText("");
1223 LineEditMesh->setText( aString );
1225 if (myAction == MERGE_NODES) {
1226 SMESH::SetPointRepresentation(true);
1227 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1228 aViewWindow->SetSelectionMode(NodeSelection);
1231 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1232 aViewWindow->SetSelectionMode(CellSelection);
1236 ListExclude->clear();
1237 if ( isMeshSelected )
1239 SMESH::ListOfGroups_var aListOfGroups = myMesh->GetGroups();
1240 GroupExclude->setEnabled( aListOfGroups->length() > 0 );
1241 for ( int i = 0, n = aListOfGroups->length(); i < n; i++ ) {
1242 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
1243 if ( !aGroup->_is_nil() ) {
1244 if ( myAction == MERGE_ELEMENTS && aGroup->GetType() == SMESH::NODE )
1246 QString aGroupName( aGroup->GetName() );
1247 if ( !aGroupName.isEmpty() ) {
1248 myGroups.append( aGroup );
1249 QListWidgetItem* item = new QListWidgetItem( aGroupName );
1250 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
1251 item->setCheckState( Qt::Unchecked );
1252 ListExclude->addItem( item );
1261 else if (myEditCurrentArgument == (QWidget*)KeepList && KeepList)
1263 AddKeepButton->setEnabled( false );
1264 RemoveKeepButton->setEnabled( false );
1265 if ( isKeepIDsSelection() )
1267 if (!myMesh->_is_nil() && !myActor)
1268 myActor = SMESH::FindActorByObject(myMesh);
1270 if ( mySelector && myActor )
1272 KeepList->clearSelection();
1274 int aNbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
1277 QStringList anNodes = anIDs.split( " ", QString::SkipEmptyParts);
1278 QList<QListWidgetItem*> listItemsToSel;
1279 QListWidgetItem* anItem;
1281 for (QStringList::iterator it = anNodes.begin(); it != anNodes.end(); ++it)
1283 QList<QListWidgetItem*> found = KeepList->findItems(*it, Qt::MatchExactly);
1284 foreach(anItem, found)
1285 if (!anItem->isSelected())
1286 listItemsToSel.push_back(anItem);
1287 nbFound += found.count();
1289 bool blocked = KeepList->signalsBlocked();
1290 KeepList->blockSignals(true);
1291 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1292 KeepList->blockSignals(blocked);
1294 AddKeepButton->setEnabled( nbFound < aNbNodes );
1295 RemoveKeepButton->setEnabled( nbFound > 0 );
1299 else if ( !myMesh->_is_nil() )
1301 SALOME_ListIO aList;
1302 mySelectionMgr->selectedObjects(aList);
1303 bool hasNewSelected = false;
1304 SALOME_ListIteratorOfListIO anIt (aList);
1305 for ( ; anIt.More() && !hasNewSelected; anIt.Next())
1306 if ( anIt.Value()->hasEntry() )
1307 hasNewSelected = isNewKeepGroup( anIt.Value()->getEntry() );
1309 AddKeepButton->setEnabled( hasNewSelected );
1310 //RemoveKeepButton->setEnabled( KeepList->selectedItems().count() );
1315 //=================================================================================
1316 // function : DeactivateActiveDialog()
1318 //=================================================================================
1319 void SMESHGUI_MergeDlg::DeactivateActiveDialog()
1321 if (TypeBox->isEnabled()) {
1322 TypeBox->setEnabled(false);
1323 GroupMesh->setEnabled(false);
1324 GroupCoincident->setEnabled(false);
1325 GroupEdit->setEnabled(false);
1326 GroupButtons->setEnabled(false);
1327 //if (myAction == MERGE_NODES)
1329 GroupExclude->setEnabled(false);
1330 GroupKeep->setEnabled(false);
1332 mySMESHGUI->ResetState();
1333 mySMESHGUI->SetActiveDialogBox(0);
1336 mySelectionMgr->clearSelected();
1337 disconnect(mySelectionMgr, 0, this, 0);
1340 //=================================================================================
1341 // function : ActivateThisDialog()
1343 //=================================================================================
1344 void SMESHGUI_MergeDlg::ActivateThisDialog()
1346 /* Emit a signal to deactivate the active dialog */
1347 mySMESHGUI->EmitSignalDeactivateDialog();
1348 TypeBox->setEnabled(true);
1349 GroupMesh->setEnabled(true);
1350 GroupCoincident->setEnabled(true);
1351 GroupEdit->setEnabled(true);
1352 GroupButtons->setEnabled(true);
1353 //if (myAction == MERGE_NODES)
1355 GroupExclude->setEnabled(false);
1356 GroupKeep->setEnabled(false);
1359 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1360 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1361 SelectionIntoArgument();
1364 //=================================================================================
1365 // function : enterEvent()
1367 //=================================================================================
1368 void SMESHGUI_MergeDlg::enterEvent (QEvent*)
1370 if ( !TypeBox->isEnabled() ) {
1371 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
1372 if ( aViewWindow && !mySelector) {
1373 mySelector = aViewWindow->GetSelector();
1375 ActivateThisDialog();
1379 //=================================================================================
1380 // function : keyPressEvent()
1382 //=================================================================================
1383 void SMESHGUI_MergeDlg::keyPressEvent( QKeyEvent* e)
1385 QDialog::keyPressEvent( e );
1386 if ( e->isAccepted() )
1389 if ( e->key() == Qt::Key_F1 ) {
1395 //=================================================================================
1396 // function : onTypeChanged()
1397 // purpose : the type radio button management
1398 //=================================================================================
1399 void SMESHGUI_MergeDlg::onTypeChanged (int id)
1407 case TYPE_AUTO: // automatic
1409 myIdPreview->SetPointsLabeled(false);
1410 SMESH::SetPointRepresentation(false);
1411 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1412 aViewWindow->SetSelectionMode(ActorSelection);
1413 mySelectionMgr->clearFilters();
1414 GroupCoincident->hide();
1417 GroupMesh->hide(); // <--- a trick to make the dialog take a minimal size
1421 case TYPE_MANUAL: // manual
1423 SMESH::UpdateView();
1425 myMeshOrSubMeshOrGroupFilter = new SMESH_TypeFilter (SMESH::IDSOURCE);
1427 if (myAction == MERGE_NODES) {
1428 SMESH::SetPointRepresentation(true);
1429 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1430 if( mySelector->IsSelectionEnabled() )
1431 aViewWindow->SetSelectionMode(NodeSelection);
1434 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1435 if( mySelector->IsSelectionEnabled() )
1436 aViewWindow->SetSelectionMode(CellSelection);
1438 GroupCoincident->show();
1442 SelectionIntoArgument();
1446 qApp->processEvents();
1451 //=======================================================================
1452 //function : isKeepIDsSelection
1453 //purpose : Return true of Nodes to keep are selected by IDs
1454 //=======================================================================
1456 bool SMESHGUI_MergeDlg::isKeepIDsSelection()
1458 return KeepFromButGroup && KeepFromButGroup->checkedId() == 0;
1461 //=======================================================================
1462 //function : isNewKeepGroup
1463 //purpose : Return true if an object with given entry is NOT present in KeepList
1464 //=======================================================================
1466 bool SMESHGUI_MergeDlg::isNewKeepGroup( const char* entry )
1468 if ( !entry || isKeepIDsSelection() )
1471 for ( int i = 0; i < KeepList->count(); i++ )
1472 if ( KeepList->item( i )->data( Qt::UserRole ).toString() == entry )
1478 //=======================================================================
1479 //function : onAddKeep
1480 //purpose : SLOT called when [Add] of Nodes To Keep group is pressed
1481 //=======================================================================
1483 void SMESHGUI_MergeDlg::onAddKeep()
1489 if ( isKeepIDsSelection() )
1491 //KeepList->clearSelection();
1495 aNbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
1498 QStringList anNodes = anIDs.split( " ", QString::SkipEmptyParts);
1499 QList<QListWidgetItem*> listItemsToSel;
1500 QListWidgetItem* anItem;
1501 for (QStringList::iterator it = anNodes.begin(); it != anNodes.end(); ++it)
1503 QList<QListWidgetItem*> found = KeepList->findItems(*it, Qt::MatchExactly);
1504 if (found.count() == 0) {
1505 anItem = new QListWidgetItem(*it);
1506 KeepList->addItem(anItem);
1507 if (!anItem->isSelected())
1508 listItemsToSel.push_back(anItem);
1511 foreach(anItem, found)
1512 if (!anItem->isSelected())
1513 listItemsToSel.push_back(anItem);
1516 bool blocked = KeepList->signalsBlocked();
1517 KeepList->blockSignals(true);
1518 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1519 KeepList->blockSignals(blocked);
1522 RemoveKeepButton->setEnabled( aNbNodes > 0 );
1526 SALOME_ListIO aList;
1527 mySelectionMgr->selectedObjects(aList);
1528 SALOME_ListIteratorOfListIO anIt (aList);
1529 for ( ; anIt.More(); anIt.Next()) {
1530 Handle(SALOME_InteractiveObject) anIO = anIt.Value();
1531 if ( isNewKeepGroup( anIO->getEntry() ))
1533 QListWidgetItem* anItem = new QListWidgetItem( anIO->getName() );
1534 anItem->setData( Qt::UserRole, QString( anIO->getEntry() ));
1535 KeepList->addItem(anItem);
1538 //RemoveKeepButton->setEnabled( KeepList->selectedItems().count() );
1541 AddKeepButton->setEnabled( false );
1546 //=======================================================================
1547 //function : onRemoveKeep
1548 //purpose : SLOT called when [Remove] of Nodes To Keep group is pressed
1549 //=======================================================================
1551 void SMESHGUI_MergeDlg::onRemoveKeep()
1553 // if ( isKeepIDsSelection() )
1558 QList<QListWidgetItem*> selItems = KeepList->selectedItems();
1559 QListWidgetItem* item;
1560 foreach(item, selItems) delete item;
1562 if ( isKeepIDsSelection() )
1564 AddKeepButton->setEnabled( false );
1566 RemoveKeepButton->setEnabled( false );
1569 //=======================================================================
1570 //function : onSelectKeep
1571 //purpose : SLOT called when selection in KeepList changes
1572 //=======================================================================
1574 void SMESHGUI_MergeDlg::onSelectKeep()
1576 if ( myIsBusy || !isEnabled() ) return;
1579 if ( isKeepIDsSelection() )
1583 mySelectionMgr->clearSelected();
1584 TColStd_MapOfInteger aIndexes;
1585 QList<QListWidgetItem*> selItems = KeepList->selectedItems();
1586 QListWidgetItem* anItem;
1587 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1588 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
1589 SALOME_ListIO aList;
1590 aList.Append(myActor->getIO());
1591 mySelectionMgr->setSelectedObjects(aList,false);
1593 AddKeepButton->setEnabled( false );
1594 RemoveKeepButton->setEnabled( aIndexes.Extent() > 0 );
1599 RemoveKeepButton->setEnabled( KeepList->selectedItems().count() );
1604 //=======================================================================
1605 //function : onKeepSourceChanged
1606 //purpose : SLOT called when type of source of Nodes To Keep change from
1607 // IDs to groups or vice versa
1608 //=======================================================================
1610 void SMESHGUI_MergeDlg::onKeepSourceChanged(int isGroup)
1613 SelectKeepButton->click();