1 // Copyright (C) 2007-2022 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(SVTK_TVtkIDsMap & 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 SVTK_TVtkIDsMapIterator 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::smIdType_array_var anIdList = new SMESH::smIdType_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 SVTK_TVtkIDsMap 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 SVTK_TVtkIDsMap 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()
1150 if (myEditCurrentArgument == (QWidget*)LineEditMesh)
1152 QString aString = "";
1153 LineEditMesh->setText(aString);
1155 ListCoincident->clear();
1157 ListExclude->clear();
1159 myMesh = SMESH::SMESH_Mesh::_nil();
1160 QString aCurrentEntry = myEntry;
1162 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
1164 myIdPreview->SetPointsLabeled(false);
1165 SMESH::SetPointRepresentation(false);
1166 mySelectionMgr->clearFilters();
1167 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1168 aViewWindow->SetSelectionMode(ActorSelection);
1172 SALOME_ListIO aList;
1173 mySelectionMgr->selectedObjects(aList);
1175 Handle(SALOME_InteractiveObject) IO = aList.First();
1176 myEntry = IO->getEntry();
1177 myMesh = SMESH::GetMeshByIO(IO);
1179 if ( myEntry != aCurrentEntry && KeepList )
1182 if (myMesh->_is_nil())
1185 myActor = SMESH::FindActorByEntry(IO->getEntry());
1187 myActor = SMESH::FindActorByObject(myMesh);
1189 mySubMeshOrGroups->length( nbSel );
1191 bool isMeshSelected = false;
1192 while ( !aList.IsEmpty() )
1195 aList.RemoveFirst();
1196 SMESH::SMESH_IDSource_var idSrc = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
1197 if ( !idSrc->_is_nil() )
1199 SMESH::SMESH_Mesh_var mesh = idSrc->GetMesh();
1200 if ( !mesh->_is_equivalent( myMesh ))
1205 mySubMeshOrGroups[ nbSel++ ] = idSrc;
1206 if ( idSrc->_is_equivalent( myMesh ))
1208 isMeshSelected = true;
1209 mySubMeshOrGroups[ 0 ] = idSrc;
1210 aString = SMESH::GetName( IO );
1211 // break; -- to check if other selected belongs to myMesh
1216 if ( isMeshSelected && nbSel > 1 )
1218 mySubMeshOrGroups->length( nbSel );
1222 LineEditMesh->setText("");
1226 LineEditMesh->setText( aString );
1229 myIsBusy = true; // here selection can change
1231 if (myAction == MERGE_NODES) {
1232 SMESH::SetPointRepresentation(true);
1233 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1234 aViewWindow->SetSelectionMode(NodeSelection);
1237 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1238 aViewWindow->SetSelectionMode(CellSelection);
1244 ListExclude->clear();
1245 if ( isMeshSelected )
1247 SMESH::ListOfGroups_var aListOfGroups = myMesh->GetGroups();
1248 GroupExclude->setEnabled( aListOfGroups->length() > 0 );
1249 for ( int i = 0, n = aListOfGroups->length(); i < n; i++ ) {
1250 SMESH::SMESH_GroupBase_var aGroup = aListOfGroups[i];
1251 if ( !aGroup->_is_nil() ) {
1252 if ( myAction == MERGE_ELEMENTS && aGroup->GetType() == SMESH::NODE )
1254 QString aGroupName( aGroup->GetName() );
1255 if ( !aGroupName.isEmpty() ) {
1256 myGroups.append( aGroup );
1257 QListWidgetItem* item = new QListWidgetItem( aGroupName );
1258 item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
1259 item->setCheckState( Qt::Unchecked );
1260 ListExclude->addItem( item );
1269 else if (myEditCurrentArgument == (QWidget*)KeepList && KeepList)
1271 AddKeepButton->setEnabled( false );
1272 RemoveKeepButton->setEnabled( false );
1273 if ( isKeepIDsSelection() )
1275 if (!myMesh->_is_nil() && !myActor)
1276 myActor = SMESH::FindActorByObject(myMesh);
1278 if ( mySelector && myActor )
1280 KeepList->clearSelection();
1282 int aNbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
1285 QStringList anNodes = anIDs.split( " ", QString::SkipEmptyParts);
1286 QList<QListWidgetItem*> listItemsToSel;
1287 QListWidgetItem* anItem;
1289 for (QStringList::iterator it = anNodes.begin(); it != anNodes.end(); ++it)
1291 QList<QListWidgetItem*> found = KeepList->findItems(*it, Qt::MatchExactly);
1292 foreach(anItem, found)
1293 if (!anItem->isSelected())
1294 listItemsToSel.push_back(anItem);
1295 nbFound += found.count();
1297 bool blocked = KeepList->signalsBlocked();
1298 KeepList->blockSignals(true);
1299 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1300 KeepList->blockSignals(blocked);
1302 AddKeepButton->setEnabled( nbFound < aNbNodes );
1303 RemoveKeepButton->setEnabled( nbFound > 0 );
1307 else if ( !myMesh->_is_nil() )
1309 SALOME_ListIO aList;
1310 mySelectionMgr->selectedObjects(aList);
1311 bool hasNewSelected = false;
1312 SALOME_ListIteratorOfListIO anIt (aList);
1313 for ( ; anIt.More() && !hasNewSelected; anIt.Next())
1314 if ( anIt.Value()->hasEntry() )
1315 hasNewSelected = isNewKeepGroup( anIt.Value()->getEntry() );
1317 AddKeepButton->setEnabled( hasNewSelected );
1318 //RemoveKeepButton->setEnabled( KeepList->selectedItems().count() );
1323 //=================================================================================
1324 // function : DeactivateActiveDialog()
1326 //=================================================================================
1327 void SMESHGUI_MergeDlg::DeactivateActiveDialog()
1329 if (TypeBox->isEnabled()) {
1330 TypeBox->setEnabled(false);
1331 GroupMesh->setEnabled(false);
1332 GroupCoincident->setEnabled(false);
1333 GroupEdit->setEnabled(false);
1334 GroupButtons->setEnabled(false);
1335 //if (myAction == MERGE_NODES)
1337 GroupExclude->setEnabled(false);
1338 GroupKeep->setEnabled(false);
1340 mySMESHGUI->ResetState();
1341 mySMESHGUI->SetActiveDialogBox(0);
1344 mySelectionMgr->clearSelected();
1345 disconnect(mySelectionMgr, 0, this, 0);
1348 //=================================================================================
1349 // function : ActivateThisDialog()
1351 //=================================================================================
1352 void SMESHGUI_MergeDlg::ActivateThisDialog()
1354 /* Emit a signal to deactivate the active dialog */
1355 mySMESHGUI->EmitSignalDeactivateDialog();
1356 TypeBox->setEnabled(true);
1357 GroupMesh->setEnabled(true);
1358 GroupCoincident->setEnabled(true);
1359 GroupEdit->setEnabled(true);
1360 GroupButtons->setEnabled(true);
1361 //if (myAction == MERGE_NODES)
1363 GroupExclude->setEnabled(false);
1364 GroupKeep->setEnabled(false);
1367 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
1368 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1369 SelectionIntoArgument();
1372 //=================================================================================
1373 // function : enterEvent()
1375 //=================================================================================
1376 void SMESHGUI_MergeDlg::enterEvent (QEvent*)
1378 if ( !TypeBox->isEnabled() ) {
1379 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
1380 if ( aViewWindow && !mySelector) {
1381 mySelector = aViewWindow->GetSelector();
1383 ActivateThisDialog();
1387 //=================================================================================
1388 // function : keyPressEvent()
1390 //=================================================================================
1391 void SMESHGUI_MergeDlg::keyPressEvent( QKeyEvent* e)
1393 QDialog::keyPressEvent( e );
1394 if ( e->isAccepted() )
1397 if ( e->key() == Qt::Key_F1 ) {
1403 //=================================================================================
1404 // function : onTypeChanged()
1405 // purpose : the type radio button management
1406 //=================================================================================
1407 void SMESHGUI_MergeDlg::onTypeChanged (int id)
1415 case TYPE_AUTO: // automatic
1417 myIdPreview->SetPointsLabeled(false);
1418 SMESH::SetPointRepresentation(false);
1419 myIsBusy = true; // keep currently selected mesh
1420 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1421 aViewWindow->SetSelectionMode(ActorSelection);
1422 mySelectionMgr->clearFilters();
1424 GroupCoincident->hide();
1427 GroupMesh->hide(); // <--- a trick to make the dialog take a minimal size
1431 case TYPE_MANUAL: // manual
1433 SMESH::UpdateView();
1435 myMeshOrSubMeshOrGroupFilter = new SMESH_TypeFilter (SMESH::IDSOURCE);
1437 myIsBusy = true; // keep currently selected mesh
1438 if (myAction == MERGE_NODES) {
1439 SMESH::SetPointRepresentation(true);
1440 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1441 if( mySelector->IsSelectionEnabled() )
1442 aViewWindow->SetSelectionMode(NodeSelection);
1445 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1446 if( mySelector->IsSelectionEnabled() )
1447 aViewWindow->SetSelectionMode(CellSelection);
1450 GroupCoincident->show();
1455 if ( myMesh->_is_nil() )
1456 SelectionIntoArgument();
1460 qApp->processEvents();
1465 //=======================================================================
1466 //function : isKeepIDsSelection
1467 //purpose : Return true of Nodes to keep are selected by IDs
1468 //=======================================================================
1470 bool SMESHGUI_MergeDlg::isKeepIDsSelection()
1472 return KeepFromButGroup && KeepFromButGroup->checkedId() == 0;
1475 //=======================================================================
1476 //function : isNewKeepGroup
1477 //purpose : Return true if an object with given entry is NOT present in KeepList
1478 //=======================================================================
1480 bool SMESHGUI_MergeDlg::isNewKeepGroup( const char* entry )
1482 if ( !entry || isKeepIDsSelection() )
1485 for ( int i = 0; i < KeepList->count(); i++ )
1486 if ( KeepList->item( i )->data( Qt::UserRole ).toString() == entry )
1492 //=======================================================================
1493 //function : onAddKeep
1494 //purpose : SLOT called when [Add] of Nodes To Keep group is pressed
1495 //=======================================================================
1497 void SMESHGUI_MergeDlg::onAddKeep()
1503 if ( isKeepIDsSelection() )
1505 //KeepList->clearSelection();
1509 aNbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), anIDs);
1512 QStringList anNodes = anIDs.split( " ", QString::SkipEmptyParts);
1513 QList<QListWidgetItem*> listItemsToSel;
1514 QListWidgetItem* anItem;
1515 for (QStringList::iterator it = anNodes.begin(); it != anNodes.end(); ++it)
1517 QList<QListWidgetItem*> found = KeepList->findItems(*it, Qt::MatchExactly);
1518 if (found.count() == 0) {
1519 anItem = new QListWidgetItem(*it);
1520 KeepList->addItem(anItem);
1521 if (!anItem->isSelected())
1522 listItemsToSel.push_back(anItem);
1525 foreach(anItem, found)
1526 if (!anItem->isSelected())
1527 listItemsToSel.push_back(anItem);
1530 bool blocked = KeepList->signalsBlocked();
1531 KeepList->blockSignals(true);
1532 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1533 KeepList->blockSignals(blocked);
1536 RemoveKeepButton->setEnabled( aNbNodes > 0 );
1540 SALOME_ListIO aList;
1541 mySelectionMgr->selectedObjects(aList);
1542 SALOME_ListIteratorOfListIO anIt (aList);
1543 for ( ; anIt.More(); anIt.Next()) {
1544 Handle(SALOME_InteractiveObject) anIO = anIt.Value();
1545 if ( isNewKeepGroup( anIO->getEntry() ))
1547 QListWidgetItem* anItem = new QListWidgetItem( anIO->getName() );
1548 anItem->setData( Qt::UserRole, QString( anIO->getEntry() ));
1549 KeepList->addItem(anItem);
1552 //RemoveKeepButton->setEnabled( KeepList->selectedItems().count() );
1555 AddKeepButton->setEnabled( false );
1560 //=======================================================================
1561 //function : onRemoveKeep
1562 //purpose : SLOT called when [Remove] of Nodes To Keep group is pressed
1563 //=======================================================================
1565 void SMESHGUI_MergeDlg::onRemoveKeep()
1567 // if ( isKeepIDsSelection() )
1572 QList<QListWidgetItem*> selItems = KeepList->selectedItems();
1573 QListWidgetItem* item;
1574 foreach(item, selItems) delete item;
1576 if ( isKeepIDsSelection() )
1578 AddKeepButton->setEnabled( false );
1580 RemoveKeepButton->setEnabled( false );
1583 //=======================================================================
1584 //function : onSelectKeep
1585 //purpose : SLOT called when selection in KeepList changes
1586 //=======================================================================
1588 void SMESHGUI_MergeDlg::onSelectKeep()
1590 if ( myIsBusy || !isEnabled() ) return;
1593 if ( isKeepIDsSelection() )
1597 mySelectionMgr->clearSelected();
1598 SVTK_TVtkIDsMap aIndexes;
1599 QList<QListWidgetItem*> selItems = KeepList->selectedItems();
1600 QListWidgetItem* anItem;
1601 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1602 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
1603 SALOME_ListIO aList;
1604 aList.Append(myActor->getIO());
1605 mySelectionMgr->setSelectedObjects(aList,false);
1607 AddKeepButton->setEnabled( false );
1608 RemoveKeepButton->setEnabled( aIndexes.Extent() > 0 );
1613 RemoveKeepButton->setEnabled( KeepList->selectedItems().count() );
1618 //=======================================================================
1619 //function : onKeepSourceChanged
1620 //purpose : SLOT called when type of source of Nodes To Keep change from
1621 // IDs to groups or vice versa
1622 //=======================================================================
1624 void SMESHGUI_MergeDlg::onKeepSourceChanged(int /*isGroup*/)
1627 SelectKeepButton->click();