1 // Copyright (C) 2007-2015 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_MapOfInteger.hxx>
58 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
61 #include <SALOMEconfig.h>
62 #include CORBA_SERVER_HEADER(SMESH_Group)
63 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
66 #include <QApplication>
67 #include <QButtonGroup>
69 #include <QGridLayout>
71 #include <QHBoxLayout>
75 #include <QListWidget>
76 #include <QPushButton>
77 #include <QRadioButton>
78 #include <QVBoxLayout>
85 enum ActionType { MERGE_NODES, MERGE_ELEMENTS, TYPE_AUTO=0, TYPE_MANUAL };
89 QPixmap SMESHGUI_MergeDlg::IconFirst()
91 static const char * iconFirst[] = {
108 //=================================================================================
109 // class : SMESHGUI_MergeDlg()
111 //=================================================================================
112 SMESHGUI_MergeDlg::SMESHGUI_MergeDlg (SMESHGUI* theModule, int theAction)
113 : QDialog(SMESH::GetDesktop(theModule)),
114 mySMESHGUI(theModule),
115 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
119 setAttribute(Qt::WA_DeleteOnClose, true);
120 setWindowTitle(myAction == MERGE_ELEMENTS ? 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 QVBoxLayout* DlgLayout = new QVBoxLayout(this);
134 DlgLayout->setSpacing(SPACING);
135 DlgLayout->setMargin(MARGIN);
137 /***************************************************************/
138 GroupConstructors = new QGroupBox(myAction == MERGE_ELEMENTS ?
139 tr("SMESH_MERGE_ELEMENTS") :
140 tr("SMESH_MERGE_NODES"),
143 QButtonGroup* ButtonGroup = new QButtonGroup(this);
144 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
145 GroupConstructorsLayout->setSpacing(SPACING);
146 GroupConstructorsLayout->setMargin(MARGIN);
148 RadioButton = new QRadioButton(GroupConstructors);
149 RadioButton->setIcon(myAction == MERGE_ELEMENTS ? IconMergeElems : IconMergeNodes);
150 RadioButton->setChecked(true);
151 GroupConstructorsLayout->addWidget(RadioButton);
152 ButtonGroup->addButton(RadioButton, 0);
154 /***************************************************************/
155 // Controls for mesh defining
156 GroupMesh = new QGroupBox(tr("SMESH_SELECT_WHOLE_MESH"), this);
157 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
158 GroupMeshLayout->setSpacing(SPACING);
159 GroupMeshLayout->setMargin(MARGIN);
161 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupMesh);
162 SelectMeshButton = new QPushButton(GroupMesh);
163 SelectMeshButton->setIcon(IconSelect);
164 LineEditMesh = new QLineEdit(GroupMesh);
165 LineEditMesh->setReadOnly(true);
167 GroupMeshLayout->addWidget(TextLabelName);
168 GroupMeshLayout->addWidget(SelectMeshButton);
169 GroupMeshLayout->addWidget(LineEditMesh);
171 /***************************************************************/
172 // Controls for switch dialog behaviour (myTypeId)
174 TypeBox = new QGroupBox( tr( "SMESH_MODE" ), this );
175 GroupType = new QButtonGroup( this );
176 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( TypeBox );
177 aTypeBoxLayout->setMargin( MARGIN );
178 aTypeBoxLayout->setSpacing( SPACING );
180 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_AUTOMATIC" ), TypeBox );
181 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_MANUAL" ), TypeBox );
182 GroupType->addButton( rb1, 0 );
183 GroupType->addButton( rb2, 1 );
184 aTypeBoxLayout->addWidget( rb1 );
185 aTypeBoxLayout->addWidget( rb2 );
187 myTypeId = TYPE_AUTO;
189 /***************************************************************/
190 // Controls for coincident elements detecting
191 GroupCoincident = new QGroupBox(myAction == MERGE_ELEMENTS ?
192 tr("COINCIDENT_ELEMENTS") :
193 tr("COINCIDENT_NODES"),
196 QVBoxLayout* aCoincidentLayout = new QVBoxLayout(GroupCoincident);
197 aCoincidentLayout->setSpacing(SPACING);
198 aCoincidentLayout->setMargin(MARGIN);
200 if (myAction == MERGE_NODES) // case merge nodes
202 QWidget* foo = new QWidget(GroupCoincident);
203 TextLabelTolerance = new QLabel(tr("SMESH_TOLERANCE"), foo);
204 SpinBoxTolerance = new SMESHGUI_SpinBox(foo);
205 SpinBoxTolerance->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
207 SeparateCornersAndMedium = new QCheckBox(tr("SEPARATE_CORNERS_AND_MEDIUM"), foo);
208 SeparateCornersAndMedium->setEnabled( false );
210 GroupExclude = new QGroupBox(tr("EXCLUDE_GROUPS"), foo);
211 GroupExclude->setCheckable( true );
212 GroupExclude->setChecked( false );
213 ListExclude = new QListWidget( GroupExclude );
214 QVBoxLayout* GroupExcludeLayout = new QVBoxLayout(GroupExclude);
215 GroupExcludeLayout->setSpacing(SPACING);
216 GroupExcludeLayout->setMargin(MARGIN);
217 GroupExcludeLayout->addWidget(ListExclude);
219 QGroupBox* GroupKeep = new QGroupBox(tr("KEEP_NODES"), foo);
220 SelectKeepNodesButton = new QPushButton( GroupKeep );
221 SelectKeepNodesButton->setIcon( IconSelect );
222 QLabel* selectLabel = new QLabel(tr("SELECT"));
223 QRadioButton* idsButton = new QRadioButton(tr("NODE_IDS"), GroupKeep);
224 QRadioButton* groupButton = new QRadioButton(tr("GROUP_SUBMESH"), GroupKeep);
225 KeepFromButGroup = new QButtonGroup( this );
226 KeepFromButGroup->addButton( idsButton, 0 );
227 KeepFromButGroup->addButton( groupButton, 1 );
228 groupButton->setChecked( true );
229 KeepList = new QListWidget( GroupKeep );
230 KeepList->setSelectionMode(QAbstractItemView::ExtendedSelection);
231 KeepList->setFlow(QListView::TopToBottom);
232 AddKeepNodesButton = new QPushButton(tr("SMESH_BUT_ADD"), GroupKeep );
233 RemoveKeepNodesButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupKeep );
234 QGridLayout* GroupKeepLayout = new QGridLayout(GroupKeep);
235 GroupKeepLayout->setSpacing( SPACING );
236 GroupKeepLayout->setMargin ( MARGIN );
237 GroupKeepLayout->addWidget( SelectKeepNodesButton, 0, 0 );
238 GroupKeepLayout->addWidget( selectLabel, 0, 1 );
239 GroupKeepLayout->addWidget( idsButton, 0, 2 );
240 GroupKeepLayout->addWidget( groupButton, 0, 3, 1, 2 );
241 GroupKeepLayout->addWidget( KeepList, 1, 0, 2, 4 );
242 GroupKeepLayout->addWidget( AddKeepNodesButton, 1, 4, 1, 1 );
243 GroupKeepLayout->addWidget( RemoveKeepNodesButton, 2, 4, 1, 1 );
245 QGridLayout* fooLayout = new QGridLayout( foo );
246 fooLayout->setSpacing(SPACING);
247 fooLayout->setMargin(0);
248 fooLayout->addWidget(TextLabelTolerance, 0, 0 );
249 fooLayout->addWidget(SpinBoxTolerance, 0, 1 );
250 fooLayout->addWidget(SeparateCornersAndMedium, 1, 0 );
251 fooLayout->addWidget(GroupExclude, 2, 0, 1, 2 );
252 fooLayout->addWidget(GroupKeep, 3, 0, 1, 2 );
253 aCoincidentLayout->addWidget(foo);
255 // Costruction of the logical filter
256 QList<SUIT_SelectionFilter*> aListOfFilters;
257 aListOfFilters << new SMESH_TypeFilter (SMESH::SUBMESH)
258 << new SMESH_TypeFilter (SMESH::GROUP);
259 mySubMeshOrGroupFilter =
260 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
263 TextLabelTolerance = 0;
264 SpinBoxTolerance = 0;
267 KeepFromButGroup = 0;
268 SelectKeepNodesButton = 0;
269 AddKeepNodesButton = 0;
270 RemoveKeepNodesButton = 0;
272 mySubMeshOrGroupFilter = 0;
275 GroupCoincidentWidget = new QWidget(GroupCoincident);
276 QGridLayout* GroupCoincidentLayout = new QGridLayout(GroupCoincidentWidget);
277 GroupCoincidentLayout->setSpacing(SPACING);
278 GroupCoincidentLayout->setMargin(0);
280 ListCoincident = new QListWidget(GroupCoincidentWidget);
281 ListCoincident->setSelectionMode(QListWidget::ExtendedSelection);
283 DetectButton = new QPushButton(tr("DETECT"), GroupCoincidentWidget);
284 AddGroupButton = new QPushButton(tr("SMESH_BUT_ADD"), GroupCoincidentWidget);
285 RemoveGroupButton = new QPushButton(tr("SMESH_BUT_REMOVE"), GroupCoincidentWidget);
287 SelectAllCB = new QCheckBox(tr("SELECT_ALL"), GroupCoincidentWidget);
288 ShowIDs = new QCheckBox(myAction == MERGE_ELEMENTS ? tr("SHOW_ELEMS_IDS") : tr("SHOW_NODES_IDS"), GroupCoincidentWidget);
290 GroupCoincidentLayout->addWidget(ListCoincident, 0, 0, 4, 2);
291 GroupCoincidentLayout->addWidget(DetectButton, 0, 2);
292 GroupCoincidentLayout->addWidget(AddGroupButton, 2, 2);
293 GroupCoincidentLayout->addWidget(RemoveGroupButton, 3, 2);
294 GroupCoincidentLayout->addWidget(SelectAllCB, 4, 0);
295 GroupCoincidentLayout->addWidget(ShowIDs, 4, 1);
296 GroupCoincidentLayout->setRowMinimumHeight(1, 10);
297 GroupCoincidentLayout->setRowStretch(1, 5);
299 aCoincidentLayout->addWidget(GroupCoincidentWidget);
301 /***************************************************************/
302 // Controls for editing the selected group
303 GroupEdit = new QGroupBox(tr("EDIT_SELECTED_GROUP"), this);
304 QGridLayout* GroupEditLayout = new QGridLayout(GroupEdit);
305 GroupEditLayout->setSpacing(SPACING);
306 GroupEditLayout->setMargin(MARGIN);
308 ListEdit = new QListWidget(GroupEdit);
309 //ListEdit->setRowMode(QListBox::FixedNumber);
310 //ListEdit->setHScrollBarMode(QScrollView::AlwaysOn);
311 //ListEdit->setVScrollBarMode(QScrollView::AlwaysOff);
312 ListEdit->setFlow( QListView::LeftToRight );
313 ListEdit->setSelectionMode(QListWidget::ExtendedSelection);
315 AddElemButton = new QPushButton(GroupEdit);
316 AddElemButton->setIcon(IconAdd);
317 RemoveElemButton = new QPushButton(GroupEdit);
318 RemoveElemButton->setIcon(IconRemove);
319 SetFirstButton = new QPushButton(GroupEdit);
320 SetFirstButton->setIcon(IconFirst());
322 GroupEditLayout->addWidget(ListEdit, 0, 0, 2, 1);
323 GroupEditLayout->addWidget(AddElemButton, 0, 1);
324 GroupEditLayout->addWidget(RemoveElemButton, 0, 2);
325 GroupEditLayout->addWidget(SetFirstButton, 1, 1, 1, 2);
327 /***************************************************************/
328 GroupButtons = new QGroupBox(this);
329 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
330 GroupButtonsLayout->setSpacing(SPACING);
331 GroupButtonsLayout->setMargin(MARGIN);
333 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
334 buttonOk->setAutoDefault(true);
335 buttonOk->setDefault(true);
336 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
337 buttonApply->setAutoDefault(true);
338 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
339 buttonCancel->setAutoDefault(true);
340 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
341 buttonHelp->setAutoDefault(true);
343 GroupButtonsLayout->addWidget(buttonOk);
344 GroupButtonsLayout->addSpacing(10);
345 GroupButtonsLayout->addWidget(buttonApply);
346 GroupButtonsLayout->addSpacing(10);
347 GroupButtonsLayout->addStretch();
348 GroupButtonsLayout->addWidget(buttonCancel);
349 GroupButtonsLayout->addWidget(buttonHelp);
351 /***************************************************************/
352 DlgLayout->addWidget(GroupConstructors);
353 DlgLayout->addWidget(GroupMesh);
354 DlgLayout->addWidget(TypeBox);
355 DlgLayout->addWidget(GroupCoincident);
356 DlgLayout->addWidget(GroupEdit);
357 DlgLayout->addWidget(GroupButtons);
359 GroupCoincidentWidget->setVisible( myAction != MERGE_NODES );
360 GroupCoincident ->setVisible( myAction == MERGE_NODES );
361 //if GroupExclude->setVisible( myAction == MERGE_NODES );
366 ShowIDs->setChecked( true );
368 Init(); // Initialisations
371 //=================================================================================
372 // function : ~SMESHGUI_MergeDlg()
373 // purpose : Destroys the object and frees any allocated resources
374 //=================================================================================
375 SMESHGUI_MergeDlg::~SMESHGUI_MergeDlg()
380 //=================================================================================
383 //=================================================================================
384 void SMESHGUI_MergeDlg::Init()
386 if ( myAction == MERGE_NODES ) {
387 SpinBoxTolerance->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision");
388 SpinBoxTolerance->SetValue(1e-05);
391 RadioButton->setChecked(true);
393 GroupType->button(0)->setChecked(true);
395 myEditCurrentArgument = (QWidget*)LineEditMesh;
398 mySubMeshOrGroup = SMESH::SMESH_subMesh::_nil();
400 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
402 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
405 /* signals and slots connections */
406 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
407 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
408 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
409 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
413 connect(SelectKeepNodesButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
414 connect(KeepFromButGroup, SIGNAL (buttonClicked(int)), SLOT(onKeepNodeSourceChanged(int)));
415 connect(AddKeepNodesButton, SIGNAL (clicked()), this, SLOT(onAddKeepNode()));
416 connect(RemoveKeepNodesButton, SIGNAL (clicked()), this, SLOT(onRemoveKeepNode()));
417 connect(KeepList, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectKeepNode()));
419 connect(SelectMeshButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
420 connect(DetectButton, SIGNAL (clicked()), this, SLOT(onDetect()));
421 connect(ListCoincident, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectGroup()));
422 connect(AddGroupButton, SIGNAL (clicked()), this, SLOT(onAddGroup()));
423 connect(RemoveGroupButton, SIGNAL (clicked()), this, SLOT(onRemoveGroup()));
424 connect(SelectAllCB, SIGNAL(toggled(bool)), this, SLOT(onSelectAll(bool)));
425 connect(ShowIDs, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup()));
426 connect(ListEdit, SIGNAL (itemSelectionChanged()), this, SLOT(onSelectElementFromGroup()));
427 connect(AddElemButton, SIGNAL (clicked()), this, SLOT(onAddElement()));
428 connect(RemoveElemButton, SIGNAL (clicked()), this, SLOT(onRemoveElement()));
429 connect(SetFirstButton, SIGNAL( clicked() ), this, SLOT( onSetFirst()));
430 connect(GroupType, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
432 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
433 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
434 /* to close dialog if study change */
435 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
436 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
437 connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
438 // Init Mesh field from selection
439 SelectionIntoArgument();
444 if ( myAction == MERGE_NODES )
445 myHelpFileName = "merging_nodes_page.html";
447 myHelpFileName = "merging_elements_page.html";
450 //=================================================================================
451 // function : FindGravityCenter()
453 //=================================================================================
454 void SMESHGUI_MergeDlg::FindGravityCenter(TColStd_MapOfInteger & theElemsIdMap,
455 std::vector<int>& theIDs,
456 std::list< gp_XYZ > & theGrCentersXYZ)
461 SMDS_Mesh* aMesh = 0;
462 aMesh = myActor->GetObject()->GetMesh();
468 theIDs.reserve( theElemsIdMap.Extent() );
469 TColStd_MapIteratorOfMapOfInteger idIter( theElemsIdMap );
470 for( ; idIter.More(); idIter.Next() ) {
471 const SMDS_MeshElement* anElem = aMesh->FindElement(idIter.Key());
474 theIDs.push_back( idIter.Key() );
476 gp_XYZ anXYZ(0., 0., 0.);
477 SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
478 for ( nbNodes = 0; nodeIt->more(); nbNodes++ ) {
479 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
480 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
482 anXYZ.Divide( nbNodes );
484 theGrCentersXYZ.push_back( anXYZ );
488 //=================================================================================
489 // function : ClickOnApply()
491 //=================================================================================
492 bool SMESHGUI_MergeDlg::ClickOnApply()
494 if (mySMESHGUI->isActiveStudyLocked() || myMesh->_is_nil())
498 if (myTypeId == TYPE_AUTO)
501 SUIT_OverrideCursor aWaitCursor;
502 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
504 SMESH::long_array_var anIds = new SMESH::long_array;
505 SMESH::array_of_long_array_var aGroupsOfElements = new SMESH::array_of_long_array;
507 if ( ListCoincident->count() == 0) {
508 if ( myAction == MERGE_NODES )
509 SUIT_MessageBox::warning(this,
511 tr("SMESH_NO_NODES_DETECTED"));
513 SUIT_MessageBox::warning(this,
515 tr("SMESH_NO_ELEMENTS_DETECTED"));
519 aGroupsOfElements->length(ListCoincident->count());
522 for (int i = 0; i < ListCoincident->count(); i++) {
523 QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
525 anIds->length(aListIds.count());
526 for (int i = 0; i < aListIds.count(); i++)
527 anIds[i] = aListIds[i].toInt();
529 aGroupsOfElements[anArrayNum++] = anIds.inout();
532 SMESH::ListOfIDSources_var nodesToKeep;
533 SMESH::IDSource_wrap tmpIdSource;
534 if ( myAction == MERGE_NODES )
536 nodesToKeep = new SMESH::ListOfIDSources();
537 int i, nb = KeepList->count();
538 if ( isKeepNodesIDsSelection() )
540 SMESH::long_array_var anIdList = new SMESH::long_array();
541 anIdList->length(nb);
542 for (i = 0; i < nb; i++)
543 anIdList[i] = KeepList->item(i)->text().toInt();
547 tmpIdSource = aMeshEditor->MakeIDSource( anIdList, SMESH::NODE );
548 nodesToKeep->length( 1 );
549 nodesToKeep[0] = SMESH::SMESH_IDSource::_duplicate( tmpIdSource.in() );
554 nodesToKeep->length( nb );
556 for (i = 0; i < nb; i++)
558 QString entry = KeepList->item( i )->data( Qt::UserRole ).toString();
559 Handle(SALOME_InteractiveObject) anIO =
560 new SALOME_InteractiveObject( entry.toStdString().c_str(), "SMESH" );
561 SMESH::SMESH_IDSource_var idSrc =
562 SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( anIO );
563 if ( !idSrc->_is_nil() )
564 nodesToKeep[ nbObj++ ] = SMESH::SMESH_IDSource::_duplicate( idSrc );
566 nodesToKeep->length( nbObj );
571 if( myAction == MERGE_NODES )
572 aMeshEditor->MergeNodes (aGroupsOfElements.inout(), nodesToKeep);
574 aMeshEditor->MergeElements (aGroupsOfElements.inout());
576 if ( myTypeId == TYPE_AUTO ) {
577 if (myAction == MERGE_NODES )
578 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
579 tr("SMESH_MERGED_NODES").arg(QString::number(ListCoincident->count()).toLatin1().data()));
581 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INFORMATION"),
582 tr("SMESH_MERGED_ELEMENTS").arg(QString::number(ListCoincident->count()).toLatin1().data()));
584 nodesToKeep->length(0); // release before tmpIdSource calls UnRegister()
590 ListCoincident->clear();
592 myEditCurrentArgument = (QWidget*)LineEditMesh;
595 SMESHGUI::Modified();
600 //=================================================================================
601 // function : ClickOnOk()
603 //=================================================================================
604 void SMESHGUI_MergeDlg::ClickOnOk()
610 //=================================================================================
611 // function : reject()
613 //=================================================================================
614 void SMESHGUI_MergeDlg::reject()
616 myIdPreview->SetPointsLabeled(false);
617 SMESH::SetPointRepresentation(false);
618 disconnect(mySelectionMgr, 0, this, 0);
619 disconnect(mySMESHGUI, 0, this, 0);
620 mySMESHGUI->ResetState();
622 mySelectionMgr->clearFilters();
623 //mySelectionMgr->clearSelected();
625 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
626 aViewWindow->SetSelectionMode(ActorSelection);
631 //=================================================================================
632 // function : onOpenView()
634 //=================================================================================
635 void SMESHGUI_MergeDlg::onOpenView()
638 SMESH::SetPointRepresentation(false);
641 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
642 ActivateThisDialog();
646 //=================================================================================
647 // function : onCloseView()
649 //=================================================================================
650 void SMESHGUI_MergeDlg::onCloseView()
652 DeactivateActiveDialog();
656 //=================================================================================
657 // function : ClickOnHelp()
659 //=================================================================================
660 void SMESHGUI_MergeDlg::ClickOnHelp()
662 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
664 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
668 platform = "winapplication";
670 platform = "application";
672 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
673 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
674 arg(app->resourceMgr()->stringValue("ExternalBrowser",
676 arg(myHelpFileName));
680 //=================================================================================
681 // function : onEditGroup()
683 //=================================================================================
684 void SMESHGUI_MergeDlg::onEditGroup()
686 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
687 if ( selItems.count() != 1 ) {
694 for (int i = 0; i < ListEdit->count(); i++ )
695 aNewIds.append(ListEdit->item(i)->text());
697 ListCoincident->clearSelection();
698 selItems.first()->setText(aNewIds.join(" "));
699 selItems.first()->setSelected(true);
702 //=================================================================================
703 // function : updateControls()
705 //=================================================================================
706 void SMESHGUI_MergeDlg::updateControls()
708 if (ListEdit->count() == 0)
709 SetFirstButton->setEnabled(false);
711 bool groupsEmpty = ( myTypeId != TYPE_AUTO );
712 for (int i = 0; i < ListCoincident->count() && groupsEmpty; i++) {
713 QStringList aListIds = ListCoincident->item(i)->text().split(" ", QString::SkipEmptyParts);
714 groupsEmpty = ( aListIds.count() < 2 );
716 bool enable = ( !myMesh->_is_nil() && !groupsEmpty );
717 buttonOk->setEnabled(enable);
718 buttonApply->setEnabled(enable);
719 DetectButton->setEnabled( !myMesh->_is_nil() );
721 if ( myAction == MERGE_NODES )
723 bool has2ndOrder = (( !myMesh->_is_nil() ) &&
724 ( myMesh->NbEdgesOfOrder( SMESH::ORDER_QUADRATIC ) > 0 ||
725 myMesh->NbFacesOfOrder( SMESH::ORDER_QUADRATIC ) > 0 ||
726 myMesh->NbVolumesOfOrder( SMESH::ORDER_QUADRATIC ) > 0 ));
728 SeparateCornersAndMedium->setEnabled( has2ndOrder );
730 if ( myEditCurrentArgument != KeepList )
732 AddKeepNodesButton->setEnabled( false );
733 RemoveKeepNodesButton->setEnabled( false );
734 KeepList->clearSelection();
739 //=================================================================================
740 // function : onDetect()
742 //=================================================================================
743 void SMESHGUI_MergeDlg::onDetect()
745 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
749 SUIT_OverrideCursor aWaitCursor;
750 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
752 ListCoincident->clear();
755 SMESH::array_of_long_array_var aGroupsArray;
756 SMESH::ListOfIDSources_var aExcludeGroups = new SMESH::ListOfIDSources;
758 SMESH::SMESH_IDSource_var src;
759 if ( mySubMeshOrGroup->_is_nil() ) src = SMESH::SMESH_IDSource::_duplicate( myMesh );
760 else src = SMESH::SMESH_IDSource::_duplicate( mySubMeshOrGroup );
764 for ( int i = 0; GroupExclude->isChecked() && i < ListExclude->count(); i++ ) {
765 if ( ListExclude->item( i )->checkState() == Qt::Checked ) {
766 aExcludeGroups->length( aExcludeGroups->length()+1 );
767 aExcludeGroups[ aExcludeGroups->length()-1 ] = SMESH::SMESH_IDSource::_duplicate( myGroups[i] );
770 aMeshEditor->FindCoincidentNodesOnPartBut(src.in(),
771 SpinBoxTolerance->GetValue(),
774 SeparateCornersAndMedium->isEnabled() &&
775 SeparateCornersAndMedium->isChecked());
777 case MERGE_ELEMENTS :
778 aMeshEditor->FindEqualElements(src.in(), aGroupsArray.out());
782 for (int i = 0; i < aGroupsArray->length(); i++) {
783 SMESH::long_array& aGroup = aGroupsArray[i];
786 for (int j = 0; j < aGroup.length(); j++)
787 anIDs.append(QString::number(aGroup[j]));
789 ListCoincident->addItem(anIDs.join(" "));
794 ListCoincident->selectAll();
799 //=================================================================================
800 // function : onSelectGroup()
802 //=================================================================================
803 void SMESHGUI_MergeDlg::onSelectGroup()
805 if (myIsBusy || !myActor)
808 if( ListCoincident->count() != ListCoincident->selectedItems().count() )
809 SelectAllCB->setChecked( false );
811 myEditCurrentArgument = (QWidget*)ListCoincident;
816 TColStd_MapOfInteger anIndices;
817 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
818 QListWidgetItem* anItem;
819 QStringList aListIds;
823 foreach(anItem, selItems) {
824 aListIds = anItem->text().split(" ", QString::SkipEmptyParts);
825 for (int i = 0; i < aListIds.count(); i++)
826 anIndices.Add(aListIds[i].toInt());
829 if (selItems.count() == 1) {
830 ListEdit->addItems(aListIds);
831 ListEdit->selectAll();
834 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
836 aList.Append(myActor->getIO());
837 mySelectionMgr->setSelectedObjects(aList,false);
839 if (ShowIDs->isChecked())
840 if ( myAction == MERGE_NODES ) {
841 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
842 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
845 std::list< gp_XYZ > aGrCentersXYZ;
846 std::vector<int> anIDs;
847 FindGravityCenter(anIndices, anIDs, aGrCentersXYZ);
848 myIdPreview->SetElemsData( anIDs, aGrCentersXYZ );
849 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
852 myIdPreview->SetPointsLabeled(false);
858 //=================================================================================
859 // function : onSelectAll()
861 //=================================================================================
862 void SMESHGUI_MergeDlg::onSelectAll (bool isToggled)
865 ListCoincident->selectAll();
867 ListCoincident->clearSelection();
870 //=================================================================================
871 // function : onSelectElementFromGroup()
873 //=================================================================================
874 void SMESHGUI_MergeDlg::onSelectElementFromGroup()
876 if (myIsBusy || !myActor)
879 TColStd_MapOfInteger anIndices;
880 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
881 QListWidgetItem* anItem;
883 foreach(anItem, selItems)
884 anIndices.Add(anItem->text().toInt());
886 SetFirstButton->setEnabled(selItems.count() == 1);
888 mySelector->AddOrRemoveIndex(myActor->getIO(), anIndices, false);
890 aList.Append(myActor->getIO());
891 mySelectionMgr->setSelectedObjects(aList);
893 if (ShowIDs->isChecked())
894 if (myAction == MERGE_NODES) {
895 myIdPreview->SetPointsData(myActor->GetObject()->GetMesh(), anIndices);
896 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
899 std::list< gp_XYZ > aGrCentersXYZ;
900 std::vector<int> anIDs;
901 FindGravityCenter(anIndices, anIDs, aGrCentersXYZ);
902 myIdPreview->SetElemsData(anIDs, aGrCentersXYZ);
903 myIdPreview->SetPointsLabeled(!anIndices.IsEmpty(), myActor->GetVisibility());
906 myIdPreview->SetPointsLabeled(false);
909 //=================================================================================
910 // function : onAddGroup()
912 //=================================================================================
913 void SMESHGUI_MergeDlg::onAddGroup()
915 if ( myMesh->_is_nil() || LineEditMesh->text().isEmpty() )
920 aNbElements = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
925 ListCoincident->clearSelection();
926 ListCoincident->addItem(anIDs);
927 int nbGroups = ListCoincident->count();
929 ListCoincident->setCurrentRow(nbGroups-1);
930 ListCoincident->item(nbGroups-1)->setSelected(true);
933 // VSR ? this code seems to be never executed!!!
934 ListCoincident->setCurrentRow(0);
935 //ListCoincident->setSelected(0, true); // VSR: no items - no selection
941 //=================================================================================
942 // function : onRemoveGroup()
944 //=================================================================================
945 void SMESHGUI_MergeDlg::onRemoveGroup()
947 if (myEditCurrentArgument != (QWidget*)ListCoincident)
951 QList<QListWidgetItem*> selItems = ListCoincident->selectedItems();
952 QListWidgetItem* anItem;
954 foreach(anItem, selItems)
958 myIdPreview->SetPointsLabeled(false);
963 if( ListCoincident->count() == 0 ) {
964 myEditCurrentArgument = (QWidget*)LineEditMesh;
965 SelectAllCB->setChecked( false );
969 //=================================================================================
970 // function : onAddElement()
972 //=================================================================================
973 void SMESHGUI_MergeDlg::onAddElement()
979 QString aListStr = "";
982 aNbNnodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
986 QStringList aNodes = aListStr.split(" ", QString::SkipEmptyParts);
988 for (QStringList::iterator it = aNodes.begin(); it != aNodes.end(); ++it) {
989 QList<QListWidgetItem*> found = ListEdit->findItems(*it, Qt::MatchExactly);
990 if ( found.count() == 0 ) {
991 QListWidgetItem* anItem = new QListWidgetItem(*it);
992 ListEdit->addItem(anItem);
993 anItem->setSelected(true);
996 QListWidgetItem* anItem;
997 foreach(anItem, found) anItem->setSelected(true);
1005 //=================================================================================
1006 // function : onRemoveElement()
1008 //=================================================================================
1009 void SMESHGUI_MergeDlg::onRemoveElement()
1011 if (myEditCurrentArgument != (QWidget*)ListCoincident)
1015 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1016 QListWidgetItem* anItem;
1018 foreach(anItem, selItems)
1024 if( ListCoincident->count() == 0 ) {
1025 myEditCurrentArgument = (QWidget*)LineEditMesh;
1026 SelectAllCB->setChecked( false );
1030 //=================================================================================
1031 // function : onSetFirst()
1033 //=================================================================================
1034 void SMESHGUI_MergeDlg::onSetFirst()
1036 if (myEditCurrentArgument != (QWidget*)ListCoincident)
1040 QList<QListWidgetItem*> selItems = ListEdit->selectedItems();
1041 QListWidgetItem* anItem;
1043 foreach(anItem, selItems) {
1044 ListEdit->takeItem(ListEdit->row(anItem));
1045 ListEdit->insertItem(0, anItem);
1052 //=================================================================================
1053 // function : SetEditCurrentArgument()
1055 //=================================================================================
1056 void SMESHGUI_MergeDlg::SetEditCurrentArgument()
1058 QPushButton* send = (QPushButton*)sender();
1060 disconnect(mySelectionMgr, 0, this, 0);
1061 mySelectionMgr->clearSelected();
1062 mySelectionMgr->clearFilters();
1064 if (send == SelectMeshButton)
1066 myEditCurrentArgument = (QWidget*)LineEditMesh;
1067 SMESH::SetPointRepresentation(false);
1068 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1069 aViewWindow->SetSelectionMode(ActorSelection);
1070 if (myTypeId == TYPE_MANUAL)
1071 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1073 else if ( send == SelectKeepNodesButton && send )
1075 myEditCurrentArgument = (QWidget*)KeepList;
1076 KeepList->setWrapping( isKeepNodesIDsSelection() );
1077 if ( isKeepNodesIDsSelection() )
1079 SMESH::SetPointRepresentation( true );
1080 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1081 aViewWindow->SetSelectionMode( NodeSelection );
1085 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1086 aViewWindow->SetSelectionMode( ActorSelection );
1087 mySelectionMgr->installFilter( mySubMeshOrGroupFilter );
1091 myEditCurrentArgument->setFocus();
1092 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1093 SelectionIntoArgument();
1096 //=================================================================================
1097 // function : SelectionIntoArgument()
1098 // purpose : Called when selection has changed or other case
1099 //=================================================================================
1100 void SMESHGUI_MergeDlg::SelectionIntoArgument()
1102 if (myEditCurrentArgument == (QWidget*)LineEditMesh)
1104 QString aString = "";
1105 LineEditMesh->setText(aString);
1107 ListCoincident->clear();
1110 myMesh = SMESH::SMESH_Mesh::_nil();
1111 QString aCurrentEntry = myEntry;
1113 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1115 myIdPreview->SetPointsLabeled(false);
1116 SMESH::SetPointRepresentation(false);
1117 mySelectionMgr->clearFilters();
1118 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1119 aViewWindow->SetSelectionMode(ActorSelection);
1123 SALOME_ListIO aList;
1124 mySelectionMgr->selectedObjects(aList);
1126 Handle(SALOME_InteractiveObject) IO = aList.First();
1127 myEntry = IO->getEntry();
1128 myMesh = SMESH::GetMeshByIO(IO);
1130 if ( myEntry != aCurrentEntry && KeepList )
1133 if (myMesh->_is_nil())
1136 LineEditMesh->setText(aString);
1138 myActor = SMESH::FindActorByEntry(IO->getEntry());
1140 myActor = SMESH::FindActorByObject(myMesh);
1142 if ( myActor && myTypeId == TYPE_MANUAL && mySelector->IsSelectionEnabled() ) {
1143 mySubMeshOrGroup = SMESH::SMESH_IDSource::_nil();
1144 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1146 if ((!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil() || //SUBMESH OR GROUP
1147 !SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) &&
1148 !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil())
1149 mySubMeshOrGroup = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1151 if (myAction == MERGE_NODES) {
1152 SMESH::SetPointRepresentation(true);
1153 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1154 aViewWindow->SetSelectionMode(NodeSelection);
1157 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1158 aViewWindow->SetSelectionMode(CellSelection);
1162 if ( myAction == MERGE_NODES && !myMesh->_is_nil() && myEntry != aCurrentEntry ) {
1164 ListExclude->clear();
1165 SMESH::ListOfGroups_var aListOfGroups = myMesh->GetGroups();
1166 for( int i = 0, n = aListOfGroups->length(); i < n; i++ ) {
1167 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
1168 if ( !aGroup->_is_nil() ) { // && aGroup->GetType() == SMESH::NODE
1169 QString aGroupName( aGroup->GetName() );
1170 if ( !aGroupName.isEmpty() ) {
1171 myGroups.append(SMESH::SMESH_GroupBase::_duplicate(aGroup));
1172 QListWidgetItem* item = new QListWidgetItem( aGroupName );
1173 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
1174 item->setCheckState( Qt::Unchecked );
1175 ListExclude->addItem( item );
1184 else if (myEditCurrentArgument == (QWidget*)KeepList && KeepList)
1186 AddKeepNodesButton->setEnabled( false );
1187 RemoveKeepNodesButton->setEnabled( false );
1188 if ( isKeepNodesIDsSelection() )
1190 if (!myMesh->_is_nil() && !myActor)
1191 myActor = SMESH::FindActorByObject(myMesh);
1193 if ( mySelector && myActor )
1195 KeepList->clearSelection();
1197 int aNbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
1200 QStringList anNodes = anIDs.split( " ", QString::SkipEmptyParts);
1201 QList<QListWidgetItem*> listItemsToSel;
1202 QListWidgetItem* anItem;
1204 for (QStringList::iterator it = anNodes.begin(); it != anNodes.end(); ++it)
1206 QList<QListWidgetItem*> found = KeepList->findItems(*it, Qt::MatchExactly);
1207 foreach(anItem, found)
1208 if (!anItem->isSelected())
1209 listItemsToSel.push_back(anItem);
1210 nbFound += found.count();
1212 bool blocked = KeepList->signalsBlocked();
1213 KeepList->blockSignals(true);
1214 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1215 KeepList->blockSignals(blocked);
1216 //onSelectKeepNode();
1217 AddKeepNodesButton->setEnabled( nbFound < aNbNodes );
1218 RemoveKeepNodesButton->setEnabled( nbFound > 0 );
1222 else if ( !myMesh->_is_nil() )
1224 SALOME_ListIO aList;
1225 mySelectionMgr->selectedObjects(aList);
1226 bool hasNewSelected = false;
1227 SALOME_ListIteratorOfListIO anIt (aList);
1228 for ( ; anIt.More() && !hasNewSelected; anIt.Next())
1229 if ( anIt.Value()->hasEntry() )
1230 hasNewSelected = isNewKeepNodesGroup( anIt.Value()->getEntry() );
1232 AddKeepNodesButton->setEnabled( hasNewSelected );
1233 //RemoveKeepNodesButton->setEnabled( KeepList->selectedItems().count() );
1238 //=================================================================================
1239 // function : DeactivateActiveDialog()
1241 //=================================================================================
1242 void SMESHGUI_MergeDlg::DeactivateActiveDialog()
1244 if (GroupConstructors->isEnabled()) {
1245 GroupConstructors->setEnabled(false);
1246 TypeBox->setEnabled(false);
1247 GroupMesh->setEnabled(false);
1248 GroupCoincident->setEnabled(false);
1249 GroupEdit->setEnabled(false);
1250 GroupButtons->setEnabled(false);
1251 mySMESHGUI->ResetState();
1252 mySMESHGUI->SetActiveDialogBox(0);
1255 mySelectionMgr->clearSelected();
1256 disconnect(mySelectionMgr, 0, this, 0);
1259 //=================================================================================
1260 // function : ActivateThisDialog()
1262 //=================================================================================
1263 void SMESHGUI_MergeDlg::ActivateThisDialog()
1265 /* Emit a signal to deactivate the active dialog */
1266 mySMESHGUI->EmitSignalDeactivateDialog();
1267 GroupConstructors->setEnabled(true);
1268 TypeBox->setEnabled(true);
1269 GroupMesh->setEnabled(true);
1270 GroupCoincident->setEnabled(true);
1271 GroupEdit->setEnabled(true);
1272 GroupButtons->setEnabled(true);
1274 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1275 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1276 SelectionIntoArgument();
1279 //=================================================================================
1280 // function : enterEvent()
1282 //=================================================================================
1283 void SMESHGUI_MergeDlg::enterEvent (QEvent*)
1285 if ( !GroupConstructors->isEnabled() ) {
1286 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
1287 if ( aViewWindow && !mySelector) {
1288 mySelector = aViewWindow->GetSelector();
1290 ActivateThisDialog();
1294 //=================================================================================
1295 // function : keyPressEvent()
1297 //=================================================================================
1298 void SMESHGUI_MergeDlg::keyPressEvent( QKeyEvent* e)
1300 QDialog::keyPressEvent( e );
1301 if ( e->isAccepted() )
1304 if ( e->key() == Qt::Key_F1 ) {
1310 //=================================================================================
1311 // function : onTypeChanged()
1312 // purpose : the type radio button management
1313 //=================================================================================
1314 void SMESHGUI_MergeDlg::onTypeChanged (int id)
1322 case TYPE_AUTO: // automatic
1324 myIdPreview->SetPointsLabeled(false);
1325 SMESH::SetPointRepresentation(false);
1326 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1327 aViewWindow->SetSelectionMode(ActorSelection);
1328 mySelectionMgr->clearFilters();
1329 if (myAction == MERGE_NODES)
1330 GroupCoincidentWidget->hide();
1332 GroupCoincident->hide();
1336 case TYPE_MANUAL: // manual
1338 SMESH::UpdateView();
1340 // Costruction of the logical filter
1341 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
1342 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
1344 QList<SUIT_SelectionFilter*> aListOfFilters;
1345 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
1346 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
1348 myMeshOrSubMeshOrGroupFilter =
1349 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
1351 if (myAction == MERGE_NODES) {
1352 GroupCoincidentWidget->show();
1353 SMESH::SetPointRepresentation(true);
1354 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1355 if( mySelector->IsSelectionEnabled() )
1356 aViewWindow->SetSelectionMode(NodeSelection);
1359 GroupCoincident->show();
1360 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1361 if( mySelector->IsSelectionEnabled() )
1362 aViewWindow->SetSelectionMode(CellSelection);
1369 qApp->processEvents();
1373 SelectionIntoArgument();
1376 //=======================================================================
1377 //function : isKeepNodesIDsSelection
1378 //purpose : Return true of Nodes to keep are selected by IDs
1379 //=======================================================================
1381 bool SMESHGUI_MergeDlg::isKeepNodesIDsSelection()
1383 return KeepFromButGroup && KeepFromButGroup->checkedId() == 0;
1386 //=======================================================================
1387 //function : isNewKeepNodesGroup
1388 //purpose : Return true if an object with given entry is NOT present in KeepList
1389 //=======================================================================
1391 bool SMESHGUI_MergeDlg::isNewKeepNodesGroup( const char* entry )
1393 if ( !entry || isKeepNodesIDsSelection() )
1396 for ( int i = 0; i < KeepList->count(); i++ )
1397 if ( KeepList->item( i )->data( Qt::UserRole ).toString() == entry )
1403 //=======================================================================
1404 //function : onAddKeepNode
1405 //purpose : SLOT called when [Add] of Nodes To Keep group is pressed
1406 //=======================================================================
1408 void SMESHGUI_MergeDlg::onAddKeepNode()
1414 if ( isKeepNodesIDsSelection() )
1416 //KeepList->clearSelection();
1420 aNbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
1423 QStringList anNodes = anIDs.split( " ", QString::SkipEmptyParts);
1424 QList<QListWidgetItem*> listItemsToSel;
1425 QListWidgetItem* anItem;
1426 for (QStringList::iterator it = anNodes.begin(); it != anNodes.end(); ++it)
1428 QList<QListWidgetItem*> found = KeepList->findItems(*it, Qt::MatchExactly);
1429 if (found.count() == 0) {
1430 anItem = new QListWidgetItem(*it);
1431 KeepList->addItem(anItem);
1432 if (!anItem->isSelected())
1433 listItemsToSel.push_back(anItem);
1436 foreach(anItem, found)
1437 if (!anItem->isSelected())
1438 listItemsToSel.push_back(anItem);
1441 bool blocked = KeepList->signalsBlocked();
1442 KeepList->blockSignals(true);
1443 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1444 KeepList->blockSignals(blocked);
1445 //onSelectKeepNode();
1447 RemoveKeepNodesButton->setEnabled( aNbNodes > 0 );
1451 SALOME_ListIO aList;
1452 mySelectionMgr->selectedObjects(aList);
1453 SALOME_ListIteratorOfListIO anIt (aList);
1454 for ( ; anIt.More(); anIt.Next()) {
1455 Handle(SALOME_InteractiveObject) anIO = anIt.Value();
1456 if ( isNewKeepNodesGroup( anIO->getEntry() ))
1458 QListWidgetItem* anItem = new QListWidgetItem( anIO->getName() );
1459 anItem->setData( Qt::UserRole, QString( anIO->getEntry() ));
1460 KeepList->addItem(anItem);
1463 //RemoveKeepNodesButton->setEnabled( KeepList->selectedItems().count() );
1466 AddKeepNodesButton->setEnabled( false );
1471 //=======================================================================
1472 //function : onRemoveKeepNode
1473 //purpose : SLOT called when [Remove] of Nodes To Keep group is pressed
1474 //=======================================================================
1476 void SMESHGUI_MergeDlg::onRemoveKeepNode()
1478 // if ( isKeepNodesIDsSelection() )
1483 QList<QListWidgetItem*> selItems = KeepList->selectedItems();
1484 QListWidgetItem* item;
1485 foreach(item, selItems) delete item;
1487 if ( isKeepNodesIDsSelection() )
1489 AddKeepNodesButton->setEnabled( false );
1491 RemoveKeepNodesButton->setEnabled( false );
1494 //=======================================================================
1495 //function : onSelectKeepNode
1496 //purpose : SLOT called when selection in KeepList changes
1497 //=======================================================================
1499 void SMESHGUI_MergeDlg::onSelectKeepNode()
1501 if ( myIsBusy || !isEnabled() ) return;
1504 if ( isKeepNodesIDsSelection() )
1508 mySelectionMgr->clearSelected();
1509 TColStd_MapOfInteger aIndexes;
1510 QList<QListWidgetItem*> selItems = KeepList->selectedItems();
1511 QListWidgetItem* anItem;
1512 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1513 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
1514 SALOME_ListIO aList;
1515 aList.Append(myActor->getIO());
1516 mySelectionMgr->setSelectedObjects(aList,false);
1518 AddKeepNodesButton->setEnabled( false );
1519 RemoveKeepNodesButton->setEnabled( aIndexes.Extent() > 0 );
1524 RemoveKeepNodesButton->setEnabled( KeepList->selectedItems().count() );
1529 //=======================================================================
1530 //function : onKeepNodeSourceChanged
1531 //purpose : SLOT called when type of source of Nodes To Keep change from
1532 // IDs to groups or vice versa
1533 //=======================================================================
1535 void SMESHGUI_MergeDlg::onKeepNodeSourceChanged(int isGroup)
1538 SelectKeepNodesButton->click();