1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_GroupDlg.cxx
25 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
28 #include "SMESHGUI_GroupDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_GroupUtils.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
36 #include "SMESHGUI_FilterDlg.h"
37 #include "SMESHGUI_ShapeByMeshDlg.h"
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_Actor.h>
41 #include <SMESH_ActorUtils.h>
42 #include <SMESH_LogicalFilter.hxx>
44 // SALOME GEOM includes
46 #include <GEOM_SelectionFilter.h>
48 // SALOME GUI includes
49 #include <QtxColorButton.h>
51 #include <SUIT_Desktop.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SUIT_Session.h>
54 #include <SUIT_MessageBox.h>
56 #include <SalomeApp_Tools.h>
57 #include <SalomeApp_Application.h>
58 #include <SalomeApp_Study.h>
59 #include <LightApp_SelectionMgr.h>
61 #include <SALOME_ListIO.hxx>
62 #include <SALOME_ListIteratorOfListIO.hxx>
64 #include <SVTK_ViewWindow.h>
66 #include <VTKViewer_Algorithm.h>
68 // SALOME KERNEL includes
69 #include <SALOMEDSClient_Study.hxx>
72 #include <vtkRenderer.h>
73 #include <vtkActorCollection.h>
76 #include <TColStd_MapOfInteger.hxx>
79 #include <QButtonGroup>
83 #include <QPushButton>
84 #include <QToolButton>
85 #include <QRadioButton>
87 #include <QGridLayout>
88 #include <QHBoxLayout>
89 #include <QVBoxLayout>
90 #include <QListWidget>
91 #include <QStackedWidget>
103 enum grpSelectionMode {
105 grpNodeSelection = 0,
106 grpBallSelection = 1,
107 grpEdgeSelection = 2,
108 grpFaceSelection = 3,
109 grpVolumeSelection = 4,
110 grpSubMeshSelection = 5,
111 grpGroupSelection = 6,
112 grpMeshSelection = 7,
113 grpGeomSelection = 8,
117 //=================================================================================
118 // function : SMESHGUI_GroupDlg()
120 //=================================================================================
121 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
122 SMESH::SMESH_Mesh_ptr theMesh )
123 : QDialog( SMESH::GetDesktop( theModule ) ),
124 mySMESHGUI( theModule ),
125 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
126 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
128 myNameChanged( false ),
129 myIsApplyAndClose( false ),
130 myNbChangesOfContents(0)
133 if ( !theMesh->_is_nil() )
137 mySelectSubMesh->setEnabled( false );
138 mySelectGroup->setEnabled( false );
139 myGeomGroupBtn->setEnabled( false );
140 myGeomGroupLine->setEnabled( false );
144 //=================================================================================
145 // function : SMESHGUI_GroupDlg()
147 //=================================================================================
148 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
149 SMESH::SMESH_GroupBase_ptr theGroup,
150 const bool theIsConvert )
151 : QDialog( SMESH::GetDesktop( theModule ) ),
152 mySMESHGUI( theModule ),
153 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
154 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
156 myNameChanged( false ),
157 myNbChangesOfContents(0) // just not to use uninitialized variable
160 if ( !theGroup->_is_nil() )
161 init( theGroup, theIsConvert );
164 mySelectSubMesh->setEnabled( false );
165 mySelectGroup->setEnabled( false );
167 myCurrentLineEdit = myMeshGroupLine;
168 setSelectionMode( grpGroupSelection );
172 //=================================================================================
173 // function : SMESHGUI_GroupDlg()
175 //=================================================================================
176 void SMESHGUI_GroupDlg::initDialog( bool create)
179 setAttribute( Qt::WA_DeleteOnClose, true );
183 myCurrentLineEdit = 0;
187 myGeomObjects = new GEOM::ListOfGO();
188 myGeomObjects->length( 0 );
190 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
192 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
193 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
195 setSizeGripEnabled( true);
197 QGridLayout* aMainLayout = new QGridLayout( this );
198 aMainLayout->setMargin( MARGIN );
199 aMainLayout->setSpacing( SPACING );
201 /***************************************************************/
202 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
203 myMeshGroupBtn = new QPushButton( this );
204 myMeshGroupBtn->setIcon( image0 );
205 myMeshGroupLine = new QLineEdit( this );
206 myMeshGroupLine->setReadOnly( true );
208 /***************************************************************/
209 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
210 myTypeGroup = new QButtonGroup( this );
211 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
212 aTypeBoxLayout->setMargin( MARGIN );
213 aTypeBoxLayout->setSpacing( SPACING );
216 types.append( tr( "MESH_NODE" ) );
217 types.append( tr( "SMESH_BALL_ELEM" ) );
218 types.append( tr( "SMESH_EDGE" ) );
219 types.append( tr( "SMESH_FACE" ) );
220 types.append( tr( "SMESH_VOLUME" ) );
222 for ( int i = 0; i < types.count(); i++ )
224 rb = new QRadioButton( types[i], aTypeBox );
225 myTypeGroup->addButton( rb, i );
226 aTypeBoxLayout->addWidget( rb );
228 aTypeBox->setEnabled( create );
231 /***************************************************************/
232 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
233 aName->setMinimumWidth( 50 );
234 myName = new QLineEdit( this );
236 /***************************************************************/
237 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
238 myGrpTypeGroup = new QButtonGroup( this );
239 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
240 aGrpTypeBoxLayout->setMargin( MARGIN );
241 aGrpTypeBoxLayout->setSpacing( SPACING );
243 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
244 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
245 QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox );
246 myGrpTypeGroup->addButton( rb1, 0 );
247 myGrpTypeGroup->addButton( rb2, 1 );
248 myGrpTypeGroup->addButton( rb3, 2 );
249 aGrpTypeBoxLayout->addWidget( rb1 );
250 aGrpTypeBoxLayout->addWidget( rb2 );
251 aGrpTypeBoxLayout->addWidget( rb3 );
252 aGrpTypeBox->setEnabled( create );
255 /***************************************************************/
256 myWGStack = new QStackedWidget( this );
257 QWidget* wg1 = new QWidget( myWGStack );
258 QWidget* wg2 = new QWidget( myWGStack );
259 QWidget* wg3 = new QWidget( myWGStack );
261 /***************************************************************/
262 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
263 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
264 aContentBoxLayout->setMargin( MARGIN );
265 aContentBoxLayout->setSpacing( SPACING );
267 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
268 myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
270 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
271 myElements = new QListWidget( aContentBox );
272 myElements->setSelectionMode( QListWidget::ExtendedSelection );
274 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
275 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
276 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
277 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
279 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
280 aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
281 aContentBoxLayout->addWidget( myFilterBtn, 1, 1 );
282 aContentBoxLayout->addWidget( myElementsLab, 2, 0 );
283 aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 );
284 aContentBoxLayout->addWidget( myAddBtn, 3, 1 );
285 aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 );
286 aContentBoxLayout->addWidget( mySortBtn, 8, 1 );
288 aContentBoxLayout->setColumnStretch( 0, 1 );
289 aContentBoxLayout->setRowStretch( 3, 1 );
290 aContentBoxLayout->setRowStretch( 6, 1 );
292 /***************************************************************/
293 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
294 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
295 mySelectBoxLayout->setMargin( MARGIN );
296 mySelectBoxLayout->setSpacing( SPACING );
298 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
299 mySubMeshBtn = new QPushButton( mySelectBox );
300 mySubMeshBtn->setIcon( image0 );
301 mySubMeshLine = new QLineEdit( mySelectBox );
302 mySubMeshLine->setReadOnly( true );
303 onSelectSubMesh( false );
305 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
306 myGroupBtn = new QPushButton( mySelectBox );
307 myGroupBtn->setIcon( image0 );
308 myGroupLine = new QLineEdit( mySelectBox );
309 myGroupLine->setReadOnly( true );
310 onSelectGroup( false );
312 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
313 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
314 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
315 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
316 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
317 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
319 /***************************************************************/
320 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
321 wg1Layout->setMargin( 0 );
322 wg1Layout->setSpacing( SPACING );
323 wg1Layout->addWidget( aContentBox );
324 wg1Layout->addWidget( mySelectBox );
325 wg1Layout->setStretchFactor( aContentBox, 10 );
327 /***************************************************************/
328 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
329 myGeomGroupBtn = new QToolButton( wg2 );
330 myGeomGroupBtn->setIcon( image0 );
331 myGeomGroupBtn->setCheckable( true );
332 myGeomGroupLine = new QLineEdit( wg2 );
333 myGeomGroupLine->setReadOnly( true ); //VSR ???
334 onSelectGeomGroup( false );
336 myGeomGroupBtn->setEnabled( create );
337 myGeomGroupLine->setEnabled( create );
339 /***************************************************************/
340 QGridLayout* wg2Layout = new QGridLayout( wg2 );
341 wg2Layout->setMargin( 0 );
342 wg2Layout->setSpacing( SPACING );
343 wg2Layout->addWidget( geomObject, 0, 0 );
344 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
345 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
346 wg2Layout->setRowStretch( 1, 5 );
348 /***************************************************************/
349 QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
350 QGridLayout* wg3Layout = new QGridLayout( wg3 );
351 wg3Layout->setMargin( 0 );
352 wg3Layout->setSpacing( SPACING );
353 wg3Layout->addWidget( aFilter2, 0, 0 );
354 wg3Layout->setRowStretch( 1, 5 );
356 /***************************************************************/
357 myWGStack->insertWidget( 0, wg1 );
358 myWGStack->insertWidget( 1, wg2 );
359 myWGStack->insertWidget( 2, wg3 );
361 /***************************************************************/
362 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
363 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
364 aColorBoxLayout->setMargin(MARGIN);
365 aColorBoxLayout->setSpacing(SPACING);
367 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
368 myColorBtn = new QtxColorButton(aColorBox);
369 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
370 myColorBtn->sizePolicy().verticalPolicy() );
372 aColorBoxLayout->addWidget(aColorLab);
373 aColorBoxLayout->addWidget(myColorBtn);
375 /***************************************************************/
377 QFrame* aButtons = new QFrame(this);
378 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
379 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
380 aBtnLayout->setMargin(MARGIN);
381 aBtnLayout->setSpacing(SPACING);
383 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
384 myOKBtn->setAutoDefault(true);
385 myOKBtn->setDefault(true);
386 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
387 myApplyBtn->setAutoDefault(true);
388 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
389 myCloseBtn->setAutoDefault(true);
390 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
391 myHelpBtn->setAutoDefault(true);
393 aBtnLayout->addWidget(myOKBtn);
394 aBtnLayout->addSpacing(10);
395 aBtnLayout->addWidget(myApplyBtn);
396 aBtnLayout->addSpacing(10);
397 aBtnLayout->addStretch();
398 aBtnLayout->addWidget(myCloseBtn);
399 aBtnLayout->addWidget(myHelpBtn);
401 /***************************************************************/
402 aMainLayout->addWidget(meshGroupLab, 0, 0);
403 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
404 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
405 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
406 aMainLayout->addWidget(aName, 2, 0);
407 aMainLayout->addWidget(myName, 2, 2);
408 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
409 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
410 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
411 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
413 /* signals and slots connections */
414 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
415 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
416 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
418 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
419 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
421 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
422 connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters()));
423 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
424 connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
425 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
426 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
427 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
429 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
430 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
431 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
432 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
433 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
435 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
437 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
438 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
439 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
440 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
443 mySMESHGUI->SetActiveDialogBox(this);
444 mySMESHGUI->SetState(800);
446 mySelectionMode = grpNoSelection;
447 myMeshFilter = new SMESH_TypeFilter(SMESH::MESH);
448 mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
449 SMESH_LogicalFilter::LO_OR,
450 /*takeOwnership=*/true);
451 myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
452 SMESH_LogicalFilter::LO_OR,
453 /*takeOwnership=*/true);
454 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
455 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
457 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
458 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
459 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
460 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
462 rb1->setChecked(true); // VSR !!!
463 onGrpTypeChanged(0); // VSR!!!
465 if (myMesh->_is_nil() )
466 myTypeGroup->button(0)->setChecked(true);
468 onSelectAll(); //updateButtons();
471 //=================================================================================
472 // function : ~SMESHGUI_GroupDlg()
473 // purpose : Destroys the object and frees any allocated resources
474 //=================================================================================
475 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
477 // no need to delete child widgets, Qt does it all for us
478 if ( myFilterDlg != 0 ) {
479 myFilterDlg->setParent( 0 );
482 if ( myMeshFilter ) delete myMeshFilter;
483 if ( mySubMeshFilter ) delete mySubMeshFilter;
484 if ( myGroupFilter ) delete myGroupFilter;
485 if ( myGeomFilter ) delete myGeomFilter;
488 //=================================================================================
489 // function : GetDefaultName()
490 // purpose : Get the Group Name if Create new Group
491 //=================================================================================
492 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
496 // collect all object names of SMESH component
497 SalomeApp_Study* appStudy =
498 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
499 if ( !appStudy ) return aName;
500 _PTR(Study) aStudy = appStudy->studyDS();
502 std::set<std::string> aSet;
503 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
505 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
507 for (it->InitEx(true); it->More(); it->Next()) {
509 aSet.insert(obj->GetName());
513 // build a unique name
515 bool isUnique = false;
517 aName = theOperation + "_" + QString::number(++aNumber);
518 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
524 void SMESHGUI_GroupDlg::setDefaultName() const
527 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
529 QString aPrefix ="Group_";
533 aResName = aPrefix + QString::number( i++ );
534 anObj = aStudy->FindObject( aResName.toLatin1().data() );
537 myName->setText(aResName);
540 //=================================================================================
543 //=================================================================================
544 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
546 mySelectionMgr->installFilter(myMeshFilter);
548 /* init data from current selection */
549 restoreShowEntityMode();
550 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
552 myGroup = SMESH::SMESH_Group::_nil();
553 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
554 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
556 // NPAL19389: create a group with a selection in another group
557 // set actor of myMesh, if it is visible, else try
558 // any visible actor of group or submesh of myMesh
559 SetAppropriateActor();
561 setDefaultGroupColor();
566 mySelectionMgr->selectedObjects( aList );
567 if( !aList.IsEmpty() )
569 QString aName = aList.First()->getName();
570 myMeshGroupLine->setText(aName);
571 myMeshGroupLine->home( false );
574 myCurrentLineEdit = 0;
576 myTypeGroup->button(0)->setChecked(true);
580 //=================================================================================
583 //=================================================================================
584 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
585 const bool theIsConvert)
587 restoreShowEntityMode();
588 myMesh = theGroup->GetMesh();
591 myNameChanged = true;
592 myName->blockSignals(true);
593 myName->setText(theGroup->GetName());
594 myName->blockSignals(false);
597 SALOMEDS::Color aColor = theGroup->GetColor();
598 setGroupColor( aColor );
600 myMeshGroupLine->setText(theGroup->GetName());
603 switch(theGroup->GetType()) {
604 case SMESH::NODE: aType = 0; break;
605 case SMESH::BALL: aType = 1; break;
606 case SMESH::EDGE: aType = 2; break;
607 case SMESH::FACE: aType = 3; break;
608 case SMESH::VOLUME: aType = 4; break;
610 myTypeGroup->button(aType)->setChecked(true);
612 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
613 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
614 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
615 myFilter = SMESH::Filter::_nil();
617 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
620 // NPAL19389: create a group with a selection in another group
621 // set actor of myMesh, if it is visible, else set
622 // actor of theGroup, if it is visible, else try
623 // any visible actor of group or submesh of myMesh
624 // commented, because an attempt to set selection on not displayed cells leads to error
625 SetAppropriateActor();
627 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
629 anActor = SMESH::FindActorByObject(theGroup);
630 SMESH::SetPickable(anActor);*/
632 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
633 myGrpTypeGroup->button(grpType)->setChecked(true);
634 onGrpTypeChanged(grpType);
637 if ( grpType == 0 ) { // standalone group
638 myCurrentLineEdit = 0;
640 myAllowElemsModif->setChecked( true );
642 setSelectionMode(aType);
644 setShowEntityMode(); // depends on myTypeId
647 if (!theGroup->IsEmpty()) {
648 SMESH::long_array_var anElements = theGroup->GetListOfID();
649 int k = anElements->length();
650 for (int i = 0; i < k; i++) {
651 myIdList.append(anElements[i]);
652 myElements->addItem(QString::number(anElements[i]));
654 myElements->selectAll();
657 else if ( grpType == 1 ) // group on geom
659 QString aShapeName( "" );
660 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
661 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
662 if (!aGroupShape->_is_nil())
664 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
666 aShapeName = aGroupShapeSO->GetName().c_str();
668 myGeomGroupLine->setText( aShapeName );
670 else // group on filter
672 myFilter = myGroupOnFilter->GetFilter();
673 if ( !myFilter->_is_nil() ) {
674 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
675 if ( perdicate->_is_nil() )
676 myFilter = SMESH::Filter::_nil();
682 myNameChanged = true;
683 myName->blockSignals(true);
684 myName->setText(theGroup->GetName());
685 myName->blockSignals(false);
688 onSelectAll(); //updateButtons();
691 //=================================================================================
692 // function : updateButtons()
694 //=================================================================================
695 void SMESHGUI_GroupDlg::updateButtons()
697 bool enable = !myName->text().trimmed().isEmpty();
700 if (myGrpTypeId == 0) { // standalone
701 if ( !mySelectAll->isChecked() )
703 if ( myAllowElemsModif->isChecked() )
705 enable = ( myElements->count() > 0 );
707 else if ((enable = !myFilter->_is_nil() ))
709 SMESH::array_of_ElementType_var types = myFilter->GetTypes();
710 enable = types->length();
713 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
715 else if (myGrpTypeId == 1) // on geom
717 if (CORBA::is_nil(myGroupOnGeom)) // creation mode
718 enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
720 else if (myGrpTypeId == 2) // on filter
722 if (( enable = !myFilter->_is_nil() ))
723 if (CORBA::is_nil(myGroupOnFilter) ) // creation mode
724 enable = !myMesh->_is_nil();
728 myOKBtn->setEnabled(enable);
729 myApplyBtn->setEnabled(enable);
732 //=================================================================================
733 // function : onNameChanged()
735 //=================================================================================
736 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
738 myOldName = myName->text();
740 myNameChanged = !myName->text().trimmed().isEmpty();
743 //=================================================================================
744 // function : onTypeChanged()
745 // purpose : Group elements type radio button management
746 //=================================================================================
747 void SMESHGUI_GroupDlg::onTypeChanged (int id)
749 if (myTypeId != id) {
752 if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
753 setSelectionMode(id);
755 setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
757 onObjectSelectionChanged();
762 //=================================================================================
763 // function : onGrpTypeChanged()
764 // purpose : Group type radio button management
765 //=================================================================================
766 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
768 if (myGrpTypeId != id) {
770 myWGStack->setCurrentIndex( id );
771 myName->blockSignals(true);
772 myName->setText(myOldName);
773 myName->blockSignals(false);
774 onSelectGeomGroup(id != 0);
779 //=================================================================================
780 // function : onColorChanged()
781 // purpose : Color button management
782 //=================================================================================
783 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
788 //=================================================================================
789 // function : setSelectionMode()
790 // purpose : Radio button management
791 //=================================================================================
792 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
795 if (myMesh->_is_nil())
797 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
798 bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
799 if (mySelectionMode != theMode) {
800 // [PAL10408] mySelectionMgr->clearSelected();
801 mySelectionMgr->clearFilters();
802 SMESH::RemoveFilters();
804 if (myActorsList.count() > 0)
805 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
806 it.next()->SetPointRepresentation(false);
808 SMESH::SetPointRepresentation(false);
811 case grpNodeSelection:
812 if ( myGrpTypeId == 0 ) // standalone
814 if (myActorsList.count() > 0)
815 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
816 it.next()->SetPointRepresentation(true);
818 SMESH::SetPointRepresentation(true);
820 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
822 case grpEdgeSelection:
823 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
825 case grpBallSelection:
826 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
828 case grpFaceSelection:
829 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
831 case grpVolumeSelection:
832 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
834 case grpSubMeshSelection: {
836 SMESH_TypeFilter* f = 0;
838 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH); break;
839 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_EDGE); break;
840 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_FACE); break;
841 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_SOLID); break;
842 default: f = new SMESH_TypeFilter(SMESH::SUBMESH);
844 QList<SUIT_SelectionFilter*> filtList;
845 filtList.append( f );
846 filtList.append( new SMESH_TypeFilter(SMESH::SUBMESH_COMPOUND));
847 mySubMeshFilter->setFilters( filtList );
849 mySelectionMgr->installFilter( mySubMeshFilter );
851 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
854 case grpGroupSelection: {
856 SMESH_TypeFilter* f = 0;
858 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_NODE); break;
859 case grpBallSelection: f = new SMESH_TypeFilter(SMESH::GROUP_BALL); break;
860 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_EDGE); break;
861 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::GROUP_FACE); break;
862 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_VOLUME); break;
863 default: f = new SMESH_TypeFilter(SMESH::GROUP);
865 QList<SUIT_SelectionFilter*> filtList;
866 filtList.append( f );
867 myGroupFilter->setFilters( filtList );
869 mySelectionMgr->installFilter(myGroupFilter);
870 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
873 case grpMeshSelection:
874 mySelectionMgr->installFilter(myMeshFilter);
875 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
877 case grpGeomSelection:
878 mySelectionMgr->installFilter(myGeomFilter);
879 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
882 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
885 if ( aViewWindow ) aViewWindow->Repaint();
886 mySelectionMode = theMode;
890 //=================================================================================
891 // function : onApply()
893 //=================================================================================
894 bool SMESHGUI_GroupDlg::onApply()
896 if (mySMESHGUI->isActiveStudyLocked())
899 if (myName->text().trimmed().isEmpty())
902 SMESH::ElementType aType = SMESH::ALL;
904 case grpNodeSelection: aType = SMESH::NODE; break;
905 case grpBallSelection: aType = SMESH::BALL; break;
906 case grpEdgeSelection: aType = SMESH::EDGE; break;
907 case grpFaceSelection: aType = SMESH::FACE; break;
908 case grpVolumeSelection: aType = SMESH::VOLUME; break;
912 QStringList anEntryList;
914 SMESH::SMESH_GroupBase_var resultGroup;
917 if (myGrpTypeId == 0) // standalone
919 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
922 mySelectionMgr->clearSelected();
924 if (myGroup->_is_nil()) { // creation or conversion
925 // check if group on geometry is not null
926 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
927 if (myMesh->_is_nil())
929 if ( myGroupOnGeom->_is_nil() )
930 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
932 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
934 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
935 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
939 if (myGroup->_is_nil()) { // creation
940 if (myMesh->_is_nil())
943 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
945 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
948 if ( mySelectAll->isChecked() ) {
950 myGroup->AddFrom(myMesh.in());
955 if ( !myFilter->_is_nil() &&
956 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
958 myGroup->AddFrom( myFilter );
962 SMESH::long_array_var anIdList = new SMESH::long_array;
963 int i, k = myElements->count();
965 for (i = 0; i < k; i++) {
966 anIdList[i] = myElements->item(i)->text().toInt();
968 myGroup->Add(anIdList.inout());
975 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
978 if ( mySelectAll->isChecked() ) {
981 myGroup->AddFrom(myMesh.in());
986 int i, total = myElements->count();
987 for (i = 0; i < total; i++) {
988 int anId = myElements->item(i)->text().toInt();
989 int idx = myIdList.indexOf(anId);
991 aAddList.append(anId);
993 myIdList.removeAt(idx);
995 if (!aAddList.empty()) {
996 SMESH::long_array_var anIdList = new SMESH::long_array;
997 int added = aAddList.count();
998 anIdList->length(added);
999 for (i = 0; i < added; i++)
1000 anIdList[i] = aAddList[i];
1001 myGroup->Add(anIdList.inout());
1003 if (!myIdList.empty()) {
1004 SMESH::long_array_var anIdList = new SMESH::long_array;
1005 int removed = myIdList.count();
1006 anIdList->length(removed);
1007 for (i = 0; i < removed; i++)
1008 anIdList[i] = myIdList[i];
1009 myGroup->Remove(anIdList.inout());
1011 /* init for next operation */
1013 for (i = 0; i < total; i++) {
1014 myIdList.append(myElements->item(i)->text().toInt());
1021 else if (myGrpTypeId == 1) // on geom object
1023 if (CORBA::is_nil(myGroupOnGeom)) { // creation
1024 if (myMesh->_is_nil() || !myGeomObjects->length())
1027 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1028 GEOM::GEOM_IGroupOperations_var aGroupOp =
1029 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1031 if (myGeomObjects->length() == 1) {
1032 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1033 myName->text().toLatin1().data(),
1037 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1038 if ( aSMESHGen->_is_nil() )
1041 // create a geometry group
1042 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1043 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1045 if (geomGen->_is_nil() || !aStudy)
1048 GEOM::GEOM_IGroupOperations_var op =
1049 geomGen->GetIGroupOperations(aStudy->StudyId());
1053 // check and add all selected GEOM objects: they must be
1054 // a sub-shapes of the main GEOM and must be of one type
1055 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1056 for ( int i =0; i < myGeomObjects->length(); i++) {
1057 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1059 aGroupType = aSubShapeType;
1060 else if (aSubShapeType != aGroupType) {
1061 aGroupType = TopAbs_SHAPE;
1066 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1067 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1068 op->UnionList(aGroupVar, myGeomObjects);
1071 // publish the GEOM group in study
1072 QString aNewGeomGroupName ( "Auto_group_for_" );
1073 aNewGeomGroupName += myName->text();
1074 SALOMEDS::SObject_var aNewGroupSO =
1075 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
1076 aNewGeomGroupName.toLatin1().data(), aMeshShape);
1079 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1080 myName->text().toLatin1().data(),
1083 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1089 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1094 if (myGrpTypeId == 2) // group on filter
1096 if ( myFilter->_is_nil() ) return false;
1098 if (CORBA::is_nil(myGroupOnFilter)) { // creation
1099 if (myMesh->_is_nil())
1102 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1103 myName->text().toLatin1().data(),
1106 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1111 myGroupOnFilter->SetFilter( myFilter );
1113 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1121 SALOMEDS::Color aColor = getGroupColor();
1122 resultGroup->SetColor(aColor);
1124 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1126 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1130 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1132 /* init for the next operation */
1134 myElements->clear();
1135 myGroup = SMESH::SMESH_Group::_nil();
1136 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1137 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1138 myFilter = SMESH::Filter::_nil();
1142 resultGroup->SetName(myName->text().toLatin1().data());
1145 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
1146 anActor->setName(myName->text().toLatin1().data());
1149 switch ( myTypeId ) {
1150 case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1151 case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1152 case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1153 case grpVolumeSelection:
1154 SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
1155 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1157 case grpFaceSelection:
1159 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1160 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1165 SMESHGUI::Modified();
1166 mySMESHGUI->updateObjBrowser(true);
1167 SMESH::UpdateView(); // asv: fix of BUG PAL5515
1168 mySelectionMgr->clearSelected();
1170 if( LightApp_Application* anApp =
1171 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1172 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1177 //=================================================================================
1178 // function : onOK()
1180 //=================================================================================
1181 void SMESHGUI_GroupDlg::onOK()
1183 setIsApplyAndClose( true );
1186 setIsApplyAndClose( false );
1189 //=================================================================================
1190 // function : onListSelectionChanged()
1191 // purpose : Called when selection in element list is changed
1192 //=================================================================================
1193 void SMESHGUI_GroupDlg::onListSelectionChanged()
1195 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1196 if( myIsBusy || myActorsList.count() == 0 ) return;
1199 if (myCurrentLineEdit == 0) {
1200 mySelectionMgr->clearSelected();
1201 TColStd_MapOfInteger aIndexes;
1202 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1203 QListWidgetItem* anItem;
1204 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1205 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1206 SALOME_ListIO aList;
1207 aList.Append(myActorsList.first()->getIO());
1208 mySelectionMgr->setSelectedObjects(aList,false);
1213 //=================================================================================
1214 // function : onObjectSelectionChanged()
1215 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1216 //=================================================================================
1217 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1219 if ( myIsBusy || !isEnabled()) return;
1220 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1224 SALOME_ListIO aList;
1225 mySelectionMgr->selectedObjects( aList );
1227 int aNbSel = aList.Extent();
1228 myElements->clearSelection();
1230 if (myCurrentLineEdit)
1232 myCurrentLineEdit->setText( "" );
1233 QString aString = "";
1235 if (myCurrentLineEdit == myMeshGroupLine)
1237 mySelectSubMesh->setEnabled(false);
1238 mySelectGroup->setEnabled(false);
1239 myGroupLine->setText( "" );
1240 mySubMeshLine->setText( "" );
1242 myGeomGroupBtn->setEnabled(false);
1243 myGeomGroupLine->setEnabled(false);
1244 myGeomGroupLine->setText( "" );
1245 myGeomObjects = new GEOM::ListOfGO();
1246 myGeomObjects->length(0);
1248 if (myGeomGroupBtn->isChecked())
1249 myGeomGroupBtn->setChecked(false);
1251 myName->setText( "" );
1253 myElements->clear();
1256 myGroup = SMESH::SMESH_Group::_nil();
1257 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1258 restoreShowEntityMode();
1259 myMesh = SMESH::SMESH_Mesh::_nil();
1265 Handle(SALOME_InteractiveObject) IO = aList.First();
1268 restoreShowEntityMode();
1269 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1270 setShowEntityMode();
1272 if (myMesh->_is_nil())
1279 if ( myFilterDlg && !myMesh->_is_nil()){
1280 myFilterDlg->SetMesh( myMesh );
1282 myGroup = SMESH::SMESH_Group::_nil();
1284 // NPAL19389: create a group with a selection in another group
1285 // set actor of myMesh, if it is visible, else try
1286 // any visible actor of group or submesh of myMesh
1287 SetAppropriateActor();
1289 aString = aList.First()->getName();
1290 myMeshGroupLine->setText(aString);
1291 myMeshGroupLine->home( false );
1293 mySelectSubMesh->setEnabled(true);
1294 mySelectGroup->setEnabled(true);
1295 myGeomGroupBtn->setEnabled(true);
1296 myGeomGroupLine->setEnabled(true);
1300 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1301 if (aGroup->_is_nil())
1308 myGroup = SMESH::SMESH_Group::_nil();
1309 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1313 mySelectSubMesh->setEnabled(true);
1314 mySelectGroup->setEnabled(true);
1316 myCurrentLineEdit = 0;
1321 if (myGrpTypeId == 0)
1327 myElements->clear();
1328 setSelectionMode(myTypeId);
1336 else if (myCurrentLineEdit == myGeomGroupLine)
1338 myGeomObjects = new GEOM::ListOfGO();
1341 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1343 if (aNbSel == 0 || !aMeshSO)
1345 myGeomObjects->length(0);
1351 myGeomObjects->length(aNbSel);
1353 GEOM::GEOM_Object_var aGeomGroup;
1356 SALOME_ListIteratorOfListIO anIt (aList);
1357 for (; anIt.More(); anIt.Next())
1359 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1361 // Check if the object is a geometry group
1362 if (CORBA::is_nil(aGeomGroup))
1365 // Check if group constructed on the same shape as a mesh or on its child
1366 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1367 GEOM::GEOM_IGroupOperations_var anOp =
1368 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1370 // The main shape of the group
1371 GEOM::GEOM_Object_var aGroupMainShape;
1372 if (aGeomGroup->GetType() == 37)
1373 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1375 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1376 _PTR(SObject) aGroupMainShapeSO =
1377 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1379 _PTR(SObject) anObj, aRef;
1380 bool isRefOrSubShape = false;
1381 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1382 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1383 isRefOrSubShape = true;
1385 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1386 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1387 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1388 if (aRef->GetID() == aFather->GetID())
1389 isRefOrSubShape = true;
1391 aFather = aFather->GetFather();
1395 if (isRefOrSubShape)
1396 myGeomObjects[i++] = aGeomGroup;
1399 myGeomObjects->length(i);
1411 if (myCurrentLineEdit == mySubMeshLine)
1412 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1413 else if (myCurrentLineEdit == myGroupLine)
1414 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1415 else if (myCurrentLineEdit == myGeomGroupLine)
1416 aString = tr( "%1 Objects" ).arg(aNbSel);
1419 aString = aList.First()->getName();
1423 myCurrentLineEdit->setText(aString);
1424 myCurrentLineEdit->home(false);
1425 // 07.06.2008 skl for IPAL19574:
1426 // change name of group only if it is empty
1427 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1428 myOldName = myName->text();
1429 myName->blockSignals(true);
1430 myName->setText(aString);
1431 myName->blockSignals(false);
1436 else // !myCurrentLineEdit: local selection of nodes or elements
1438 if (aNbSel == 1 && myActorsList.count() > 0 )
1440 // NPAL19389: create a group with a selection in another group
1441 // Switch myActor to the newly selected one, if the last
1442 // is visible and belongs to group or submesh of myMesh
1443 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1444 Handle(SALOME_InteractiveObject) selIO = aList.First();
1445 if (curIO->hasEntry() && selIO->hasEntry()) {
1446 const char* selEntry = selIO->getEntry();
1447 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1448 // different objects: selected and myActor
1449 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1450 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1451 // newly selected actor is visible
1454 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1456 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1457 int len = strlen(meshEntry);
1459 if (strncmp(selEntry, meshEntry, len) == 0) {
1460 // selected object is myMesh or a part of it
1461 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1464 SMESH::SetPickable(myActor);
1473 QString aListStr = "";
1475 if (myTypeId == 0) {
1476 QListIterator<SMESH_Actor*> it( myActorsList );
1477 while ( it.hasNext() ) {
1479 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1483 QListIterator<SMESH_Actor*> it( myActorsList );
1484 while ( it.hasNext() ) {
1486 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1491 QListWidgetItem* anItem;
1492 QList<QListWidgetItem*> listItemsToSel;
1493 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1494 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1495 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1496 foreach(anItem, found)
1497 if (!anItem->isSelected())
1498 listItemsToSel.push_back(anItem);
1500 bool blocked = myElements->signalsBlocked();
1501 myElements->blockSignals(true);
1502 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1503 myElements->blockSignals(blocked);
1504 onListSelectionChanged();
1505 listItemsToSel.clear();
1510 if (myActorsList.count() == 0) {
1511 if (!myGroup->_is_nil()) {
1512 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1514 myActorsList.append( anActor );
1516 else if(!myGroupOnGeom->_is_nil()) {
1517 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1519 myActorsList.append( anActor );
1522 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1524 myActorsList.append( anActor );
1528 // somehow, if we display the mesh, while selecting from another actor,
1529 // the mesh becomes pickable, and there is no way to select any element
1530 if (myActorsList.count() > 0) {
1531 QListIterator<SMESH_Actor*> it( myActorsList );
1532 while ( it.hasNext() ) {
1533 SMESH_Actor* anActor = it.next();
1534 if ( IsActorVisible(anActor) )
1535 anActor->SetPickable(true);
1542 //=================================================================================
1543 // function : onSelectAll()
1544 // purpose : Called when "Select all" is checked
1545 //=================================================================================
1546 void SMESHGUI_GroupDlg::onSelectAll()
1548 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1550 myElementsLab->setEnabled( !noElemsModif );
1551 myElements->setEnabled ( !noElemsModif );
1552 myFilterBtn->setEnabled ( !mySelectAll->isChecked() );
1553 myAddBtn->setEnabled ( !noElemsModif );
1554 myRemoveBtn->setEnabled ( !noElemsModif );
1555 mySortBtn->setEnabled ( !noElemsModif );
1556 mySelectBox->setEnabled ( !noElemsModif );
1557 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1559 int selMode = mySelectionMode;
1560 mySelectionMode = grpNoSelection;
1561 setSelectionMode( selMode );
1565 //=================================================================================
1566 // function : onSelectSubMesh()
1567 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1568 //=================================================================================
1569 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1572 if (mySelectGroup->isChecked()) {
1573 mySelectGroup->setChecked(false);
1575 //VSR: else if (mySelectGeomGroup->isChecked()) {
1576 //VSR: mySelectGeomGroup->setChecked(false);
1578 myCurrentLineEdit = mySubMeshLine;
1579 setSelectionMode(grpSubMeshSelection);
1582 mySubMeshLine->setText( "" );
1583 myCurrentLineEdit = 0;
1585 setSelectionMode(myTypeId);
1587 mySubMeshBtn->setEnabled(on);
1588 mySubMeshLine->setEnabled(on);
1592 //=================================================================================
1593 // function : (onSelectGroup)
1594 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1595 //=================================================================================
1596 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1599 if (mySelectSubMesh->isChecked()) {
1600 mySelectSubMesh->setChecked(false);
1602 myCurrentLineEdit = myGroupLine;
1603 setSelectionMode(grpGroupSelection);
1606 myGroupLine->setText( "" );
1607 myCurrentLineEdit = 0;
1609 setSelectionMode(myTypeId);
1611 myGroupBtn->setEnabled(on);
1612 myGroupLine->setEnabled(on);
1616 //=================================================================================
1617 // function : (onSelectGeomGroup)
1618 // purpose : Called when group type changed. on == "on group" or "on filter"
1619 //=================================================================================
1620 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1623 if (mySelectSubMesh->isChecked()) {
1624 mySelectSubMesh->setChecked(false);
1626 else if (mySelectGroup->isChecked()) {
1627 mySelectGroup->setChecked(false);
1629 if ( myGrpTypeId == 1 ) { // on group
1630 myCurrentLineEdit = myGeomGroupLine;
1634 myCurrentLineEdit = 0;
1636 setSelectionMode(grpAllSelection);
1639 myGeomGroupBtn->setChecked(false);
1640 myGeomObjects->length(0);
1641 myGeomGroupLine->setText( "" );
1642 myCurrentLineEdit = 0;
1644 setSelectionMode( myTypeId );
1648 //=================================================================================
1649 // function : setCurrentSelection()
1651 //=================================================================================
1652 void SMESHGUI_GroupDlg::setCurrentSelection()
1654 QPushButton* send = (QPushButton*)sender();
1655 myCurrentLineEdit = 0;
1656 if (send == myMeshGroupBtn) {
1657 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1658 mySelectionMgr->clearSelected();
1660 setSelectionMode(grpMeshSelection);
1662 setSelectionMode(grpGroupSelection);
1663 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1664 myCurrentLineEdit = myMeshGroupLine;
1665 onObjectSelectionChanged();
1667 else if (send == mySubMeshBtn) {
1668 myCurrentLineEdit = mySubMeshLine;
1669 onObjectSelectionChanged();
1671 else if (send == myGroupBtn) {
1672 myCurrentLineEdit = myGroupLine;
1673 onObjectSelectionChanged();
1678 //=================================================================================
1679 // function : setFilters()
1680 // purpose : SLOT. Called when "Filter" button pressed.
1681 //=================================================================================
1682 void SMESHGUI_GroupDlg::setFilters()
1684 if(myMesh->_is_nil()) {
1685 SUIT_MessageBox::critical(this,
1687 tr("NO_MESH_SELECTED"));
1691 SMESH::ElementType aType = SMESH::ALL;
1694 case grpNodeSelection: aType = SMESH::NODE; break;
1695 case grpBallSelection: aType = SMESH::BALL; break;
1696 case grpEdgeSelection: aType = SMESH::EDGE; break;
1697 case grpFaceSelection: aType = SMESH::FACE; break;
1698 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1702 if ( myFilterDlg == 0 )
1704 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1705 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1708 myFilterDlg->Init( aType );
1710 if ( !myGroupOnFilter->_is_nil() )
1712 myFilterDlg->SetFilter( myFilter, aType );
1713 myFilterDlg->Init( aType );
1716 myFilterDlg->SetSelection();
1717 myFilterDlg->SetMesh( myMesh );
1718 myFilterDlg->SetSourceWg( myElements, false );
1720 myFilterDlg->show();
1723 //=================================================================================
1724 // function : onFilterAccepted()
1725 // purpose : SLOT. Called when Filter dlg closed with OK button.
1726 // Uncheck "Select submesh" and "Select group" checkboxes
1727 //=================================================================================
1728 void SMESHGUI_GroupDlg::onFilterAccepted()
1730 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1732 mySelectionMode = myTypeId;
1733 mySelectSubMesh->setChecked( false );
1734 mySelectGroup->setChecked( false );
1736 // get a filter from myFilterDlg
1737 myFilter = myFilterDlg->GetFilter();
1738 if ( !myFilter->_is_nil() ) {
1739 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1740 if ( perdicate->_is_nil() )
1741 myFilter = SMESH::Filter::_nil();
1743 // set mesh to myFilter
1744 if ( !myFilter->_is_nil() ) {
1745 SMESH::SMESH_Mesh_var mesh = myMesh;
1746 if ( mesh->_is_nil() ) {
1747 if ( !myGroup->_is_nil() )
1748 mesh = myGroup->GetMesh();
1749 else if ( !myGroupOnGeom->_is_nil() )
1750 mesh = myGroupOnGeom->GetMesh();
1751 else if ( !myGroupOnFilter->_is_nil() )
1752 mesh = myGroupOnFilter->GetMesh();
1754 myFilter->SetMesh( mesh );
1760 //=================================================================================
1761 // function : onAdd()
1763 //=================================================================================
1764 void SMESHGUI_GroupDlg::onAdd()
1766 SALOME_ListIO aList;
1767 mySelectionMgr->selectedObjects( aList );
1769 int aNbSel = aList.Extent();
1771 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1774 int sizeBefore = myElements->count();
1776 SMESH::ElementType aType = SMESH::ALL;
1778 case grpNodeSelection:
1779 aType = SMESH::NODE;
1780 mySelector->SetSelectionMode(NodeSelection);
1782 case grpBallSelection:
1783 aType = SMESH::BALL;
1784 mySelector->SetSelectionMode(BallSelection);
1786 case grpEdgeSelection:
1787 aType = SMESH::EDGE;
1788 mySelector->SetSelectionMode(EdgeSelection);
1790 case grpFaceSelection:
1791 aType = SMESH::FACE;
1792 mySelector->SetSelectionMode(FaceSelection);
1794 case grpVolumeSelection:
1795 aType = SMESH::VOLUME;
1796 mySelector->SetSelectionMode(VolumeSelection);
1799 mySelector->SetSelectionMode(ActorSelection);
1802 QListWidgetItem* anItem = 0;
1803 QList<QListWidgetItem*> listItemsToSel;
1805 if (myCurrentLineEdit == 0) {
1806 //if (aNbSel != 1) { myIsBusy = false; return; }
1807 QString aListStr = "";
1809 if (myTypeId == 0) {
1810 QListIterator<SMESH_Actor*> it( myActorsList );
1811 while ( it.hasNext() ) {
1813 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1818 QListIterator<SMESH_Actor*> it( myActorsList );
1819 while ( it.hasNext() ) {
1821 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1826 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1827 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1828 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1829 if (found.count() == 0) {
1830 anItem = new QListWidgetItem(*it);
1831 myElements->addItem(anItem);
1832 if (!anItem->isSelected())
1833 listItemsToSel.push_back(anItem);
1836 foreach(anItem, found)
1837 if (!anItem->isSelected())
1838 listItemsToSel.push_back(anItem);
1841 bool blocked = myElements->signalsBlocked();
1842 myElements->blockSignals(true);
1843 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1844 myElements->blockSignals(blocked);
1845 onListSelectionChanged();
1846 listItemsToSel.clear();
1848 } else if (myCurrentLineEdit == mySubMeshLine) {
1849 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1851 SALOME_ListIO aList;
1852 mySelectionMgr->selectedObjects( aList );
1854 SALOME_ListIteratorOfListIO anIt (aList);
1855 for ( ; anIt.More(); anIt.Next()) {
1856 SMESH::SMESH_subMesh_var aSubMesh =
1857 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1858 if (!aSubMesh->_is_nil()) {
1859 // check if mesh is the same
1860 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1862 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1863 int k = anElements->length();
1864 for (int i = 0; i < k; i++) {
1865 QString aText = QString::number(anElements[i]);
1866 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1867 if (found.count() == 0) {
1868 anItem = new QListWidgetItem(aText);
1869 myElements->addItem(anItem);
1870 if (!anItem->isSelected())
1871 listItemsToSel.push_back(anItem);
1874 foreach(anItem, found)
1875 if (!anItem->isSelected())
1876 listItemsToSel.push_back(anItem);
1879 bool blocked = myElements->signalsBlocked();
1880 myElements->blockSignals(true);
1881 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1882 myElements->blockSignals(blocked);
1883 onListSelectionChanged();
1884 listItemsToSel.clear();
1886 catch (const SALOME::SALOME_Exception& ex) {
1887 SalomeApp_Tools::QtCatchCorbaException(ex);
1892 mySelectSubMesh->setChecked(false);
1894 onListSelectionChanged();
1896 } else if (myCurrentLineEdit == myGroupLine) {
1897 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1898 SALOME_ListIO aList;
1899 mySelectionMgr->selectedObjects( aList );
1901 SALOME_ListIteratorOfListIO anIt (aList);
1902 for ( ; anIt.More(); anIt.Next()) {
1903 SMESH::SMESH_GroupBase_var aGroup =
1904 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1905 if (!aGroup->_is_nil()) {
1906 // check if mesh is the same
1907 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1908 SMESH::long_array_var anElements = aGroup->GetListOfID();
1909 int k = anElements->length();
1910 for (int i = 0; i < k; i++) {
1911 QString aText = QString::number(anElements[i]);
1912 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1913 if (found.count() == 0) {
1914 anItem = new QListWidgetItem(aText);
1915 myElements->addItem(anItem);
1916 if (!anItem->isSelected())
1917 listItemsToSel.push_back(anItem);
1920 foreach(anItem, found)
1921 if (!anItem->isSelected())
1922 listItemsToSel.push_back(anItem);
1925 bool blocked = myElements->signalsBlocked();
1926 myElements->blockSignals(true);
1927 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1928 myElements->blockSignals(blocked);
1929 onListSelectionChanged();
1930 listItemsToSel.clear();
1934 mySelectGroup->setChecked(false);
1936 onListSelectionChanged();
1938 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1939 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1940 GEOM::GEOM_IGroupOperations_var aGroupOp =
1941 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1943 SMESH::ElementType aGroupType = SMESH::ALL;
1944 switch(aGroupOp->GetType(myGeomObjects[0])) {
1945 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
1946 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
1947 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
1948 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
1949 default: myIsBusy = false; return;
1952 if (aGroupType == aType) {
1953 _PTR(SObject) aGroupSO =
1954 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1955 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1957 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1958 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1959 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
1960 aBelongToGeom->SetGeom(myGeomObjects[0]);
1961 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1962 aBelongToGeom->SetElementType(aType);
1963 aFilter->SetPredicate(aBelongToGeom);
1965 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1967 int k = anElements->length();
1968 for (int i = 0; i < k; i++) {
1969 QString aText = QString::number(anElements[i]);
1970 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1971 if (found.count() == 0) {
1972 anItem = new QListWidgetItem(aText);
1973 myElements->addItem(anItem);
1974 if (!anItem->isSelected())
1975 listItemsToSel.push_back(anItem);
1978 foreach(anItem, found)
1979 if (!anItem->isSelected())
1980 listItemsToSel.push_back(anItem);
1983 bool blocked = myElements->signalsBlocked();
1984 myElements->blockSignals(true);
1985 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1986 myElements->blockSignals(blocked);
1987 onListSelectionChanged();
1988 listItemsToSel.clear();
1991 //VSR: mySelectGeomGroup->setChecked(false);
1993 onListSelectionChanged();
1996 if ( sizeBefore < myElements->count() )
1997 ++myNbChangesOfContents;
1998 // mySelectionMgr->clearSelected();
2002 //=================================================================================
2003 // function : onRemove()
2005 //=================================================================================
2006 void SMESHGUI_GroupDlg::onRemove()
2009 int sizeBefore = myElements->count();
2011 if (myCurrentLineEdit == 0) {
2012 QList<QListWidgetItem*> selItems = myElements->selectedItems();
2013 QListWidgetItem* item;
2014 foreach(item, selItems) delete item;
2016 SALOME_ListIO aList;
2017 mySelectionMgr->selectedObjects( aList );
2019 int aNbSel = aList.Extent();
2021 if (aNbSel == 0) { myIsBusy = false; return; }
2023 SMESH::ElementType aType = SMESH::ALL;
2025 case grpNodeSelection: aType = SMESH::NODE; break;
2026 case grpBallSelection: aType = SMESH::BALL; break;
2027 case grpEdgeSelection: aType = SMESH::EDGE; break;
2028 case grpFaceSelection: aType = SMESH::FACE; break;
2029 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2032 if (myCurrentLineEdit == mySubMeshLine) {
2033 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2034 SALOME_ListIO aList;
2035 mySelectionMgr->selectedObjects( aList );
2037 SALOME_ListIteratorOfListIO anIt (aList);
2038 for ( ; anIt.More(); anIt.Next()) {
2039 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2040 if (!aSubMesh->_is_nil()) {
2041 // check if mesh is the same
2042 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2043 if (aType == SMESH::NODE) {
2045 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2046 int k = anElements->length();
2047 for (int i = 0; i < k; i++) {
2048 QList<QListWidgetItem*> found =
2049 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2050 QListWidgetItem* anItem;
2051 foreach(anItem, found) delete anItem;
2054 catch (const SALOME::SALOME_Exception& ex) {
2055 SalomeApp_Tools::QtCatchCorbaException(ex);
2060 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2061 int k = anElements->length();
2062 for (int i = 0; i < k; i++) {
2063 QList<QListWidgetItem*> found =
2064 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2065 QListWidgetItem* anItem;
2066 foreach(anItem, found) delete anItem;
2069 catch (const SALOME::SALOME_Exception& ex) {
2070 SalomeApp_Tools::QtCatchCorbaException(ex);
2077 else if (myCurrentLineEdit == myGroupLine) {
2078 Standard_Boolean aRes;
2079 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2080 SALOME_ListIO aList;
2081 mySelectionMgr->selectedObjects( aList );
2083 SALOME_ListIteratorOfListIO anIt (aList);
2084 for ( ; anIt.More(); anIt.Next()) {
2085 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2086 if (aRes && !aGroup->_is_nil()) {
2087 // check if mesh is the same
2088 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2089 SMESH::long_array_var anElements = aGroup->GetListOfID();
2090 int k = anElements->length();
2091 for (int i = 0; i < k; i++) {
2092 QList<QListWidgetItem*> found =
2093 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2094 QListWidgetItem* anItem;
2095 foreach(anItem, found) delete anItem;
2103 if ( sizeBefore > myElements->count() )
2104 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2108 //=================================================================================
2109 // function : onSort()
2111 //=================================================================================
2112 void SMESHGUI_GroupDlg::onSort()
2114 // PAL5412: sorts items in ascending by "string" value
2115 // myElements->sort(true);
2116 // myElements->update();
2117 int i, k = myElements->count();
2120 QList<int> aSelected;
2121 std::vector<int> anArray(k);
2122 // QMemArray<int> anArray(k);
2124 for (i = 0; i < k; i++) {
2125 int id = myElements->item(i)->text().toInt();
2127 if (myElements->item(i)->isSelected())
2128 aSelected.append(id);
2130 // sort & update list
2131 std::sort(anArray.begin(), anArray.end());
2133 myElements->clear();
2134 QListWidgetItem* anItem;
2135 QList<QListWidgetItem*> listItemsToSel;
2136 for (i = 0; i < k; i++) {
2137 anItem = new QListWidgetItem(QString::number(anArray[i]));
2138 myElements->addItem(anItem);
2139 if (aSelected.contains(anArray[i]))
2140 listItemsToSel.push_back(anItem);
2142 bool blocked = myElements->signalsBlocked();
2143 myElements->blockSignals(true);
2144 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2145 myElements->blockSignals(blocked);
2146 listItemsToSel.clear();
2151 //=================================================================================
2152 // function : closeEvent()
2154 //=================================================================================
2155 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
2160 //=================================================================================
2161 // function : onVisibilityChanged()
2163 //=================================================================================
2164 void SMESHGUI_GroupDlg::onVisibilityChanged()
2166 SetAppropriateActor();
2169 //=================================================================================
2170 // function : SMESHGUI_GroupDlg::onClose
2171 // purpose : SLOT called when "Close" button pressed. Close dialog
2172 //=================================================================================
2173 void SMESHGUI_GroupDlg::onClose()
2175 if (SMESH::GetCurrentVtkView()) {
2176 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2177 SMESH::SetPointRepresentation(false);
2178 SMESH::SetPickable();
2179 restoreShowEntityMode();
2182 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2183 SUIT_DataOwnerPtrList aList;
2184 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2185 mySelectionMgr->setSelected( aList );
2188 mySelectionMgr->clearSelected();
2189 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2190 aViewWindow->SetSelectionMode(ActorSelection);
2191 mySelectionMgr->clearFilters();
2192 mySMESHGUI->ResetState();
2197 //=================================================================================
2198 // function : onHelp()
2200 //=================================================================================
2201 void SMESHGUI_GroupDlg::onHelp()
2203 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2205 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2209 platform = "winapplication";
2211 platform = "application";
2213 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2214 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2215 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2217 arg(myHelpFileName));
2221 //=================================================================================
2222 // function : SMESHGUI_GroupDlg::onDeactivate
2223 // purpose : SLOT called when dialog must be deativated
2224 //=================================================================================
2225 void SMESHGUI_GroupDlg::onDeactivate()
2227 mySMESHGUI->ResetState();
2231 //=================================================================================
2232 // function : SMESHGUI_GroupDlg::enterEvent
2233 // purpose : Event filter
2234 //=================================================================================
2235 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2238 mySMESHGUI->EmitSignalDeactivateDialog();
2240 mySelectionMode = grpNoSelection;
2241 setSelectionMode(myTypeId);
2242 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2243 mySMESHGUI->SetActiveDialogBox(this);
2244 mySMESHGUI->SetState(800);
2248 //=================================================================================
2249 // function : hideEvent
2250 // purpose : caused by ESC key
2251 //=================================================================================
2252 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
2254 if (!isMinimized() && !myIsBusy)
2258 //=================================================================================
2259 // function : keyPressEvent()
2261 //=================================================================================
2262 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2264 QDialog::keyPressEvent( e );
2265 if ( e->isAccepted() )
2268 if ( e->key() == Qt::Key_F1 )
2275 //================================================================================
2277 * \brief Enable showing of the popup when Geometry selection btn is clicked
2278 * \param enable - true to enable
2280 //================================================================================
2282 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2284 void SMESHGUI_GroupDlg::updateGeomPopup()
2286 bool enable = false;
2288 if ( !myMesh->_is_nil() )
2289 enable = myMesh->NbEdges() > 0;
2291 if ( myGeomGroupBtn )
2293 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2295 if ( !myGeomPopup ) {
2296 myGeomPopup = new QMenu(this);
2297 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2298 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2299 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2301 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2307 //=================================================================================
2308 // function : onGeomSelectionButton()
2310 //=================================================================================
2311 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2313 if ( myGeomPopup && isBtnOn )
2315 myCurrentLineEdit = myGeomGroupLine;
2316 QAction* a = myGeomPopup->exec( QCursor::pos() );
2317 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2318 setSelectionMode(grpGeomSelection);
2322 myCurrentLineEdit = 0;
2323 setSelectionMode(grpAllSelection);
2327 //=================================================================================
2328 // function : onGeomPopup()
2330 //=================================================================================
2331 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2333 int index = myActions[a];
2334 if ( index == GEOM_BY_MESH_INDEX )
2336 mySelectionMode = grpNoSelection;
2337 if ( !myShapeByMeshOp ) {
2338 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2339 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2340 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2341 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2342 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2344 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2345 if ( !myMesh->_is_nil() ) {
2347 hide(); // stop processing selection
2349 myShapeByMeshOp->setModule( mySMESHGUI );
2350 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2351 myShapeByMeshOp->SetMesh( myMesh );
2352 myShapeByMeshOp->start();
2357 //================================================================================
2359 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2361 //================================================================================
2363 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2365 if ( myShapeByMeshOp == op ) {
2366 mySMESHGUI->getApp()->updateObjectBrowser();
2368 // Select a found geometry object
2369 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2370 if ( !aGeomVar->_is_nil() )
2372 QString ID = aGeomVar->GetStudyEntry();
2373 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2374 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2375 SALOME_ListIO anIOList;
2376 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2377 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2378 anIOList.Append( anIO );
2379 mySelectionMgr->setSelectedObjects( anIOList, false );
2380 onObjectSelectionChanged();
2386 //================================================================================
2388 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2390 //================================================================================
2392 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2394 if ( myShapeByMeshOp == op )
2397 setSelectionMode(grpGeomSelection);
2401 //=================================================================================
2402 // function : setGroupColor()
2404 //=================================================================================
2405 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2407 QColor aQColor( (int)( theColor.R * 255.0 ),
2408 (int)( theColor.G * 255.0 ),
2409 (int)( theColor.B * 255.0 ) );
2410 setGroupQColor( aQColor );
2413 //=================================================================================
2414 // function : getGroupColor()
2416 //=================================================================================
2417 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2419 QColor aQColor = getGroupQColor();
2421 SALOMEDS::Color aColor;
2422 aColor.R = (float)aQColor.red() / 255.0;
2423 aColor.G = (float)aQColor.green() / 255.0;
2424 aColor.B = (float)aQColor.blue() / 255.0;
2429 //=================================================================================
2430 // function : setGroupQColor()
2432 //=================================================================================
2433 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2435 if( theColor.isValid() )
2436 myColorBtn->setColor( theColor );
2439 //=================================================================================
2440 // function : getGroupQColor()
2442 //=================================================================================
2443 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2445 return myColorBtn->color();
2448 //=================================================================================
2449 // function : setDefaultGroupColor()
2451 //=================================================================================
2452 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2454 if( myMesh->_is_nil() )
2457 bool isAutoColor = myMesh->GetAutoColor();
2462 int r = 0, g = 0, b = 0;
2463 SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2464 aQColor.setRgb( r, g, b );
2468 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2470 QList<SALOMEDS::Color> aReservedColors;
2471 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2473 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2474 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2475 aReservedColors.append( aReservedColor );
2478 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2479 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2480 (int)( aColor.G * 255.0 ),
2481 (int)( aColor.B * 255.0 ) );
2485 setGroupQColor( aQColor );
2488 //=================================================================================
2489 // function : SetAppropriateActor()
2490 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2491 // NPAL19389: create a group with a selection in another group.
2492 // if mesh actor is not visible - find any first visible group or submesh
2493 //=================================================================================
2494 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2496 bool isActor = false;
2497 myActorsList.clear();
2499 if (myMesh->_is_nil()) return false;
2501 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2503 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2505 if (!myGroupOnGeom->_is_nil()) {
2506 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2507 if (anActor && anActor->hasIO())
2510 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2513 myActorsList.append(anActor);
2519 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2520 if (anActor && anActor->hasIO()) {
2522 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2525 myActorsList.append(anActor);
2529 if (!isActor && !myGroup->_is_nil()) {
2530 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2531 if (anActor && anActor->hasIO())
2532 myActorsList.append(anActor);
2535 // try any visible actor of group or submesh of current mesh
2538 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2540 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2541 int len = strlen(meshEntry);
2543 // iterate on all actors in current view window, search for
2544 // any visible actor, that belongs to group or submesh of current mesh
2545 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2546 vtkActorCollection *aCollection = aCopy.GetActors();
2547 int nbItems = aCollection->GetNumberOfItems();
2548 for (int i=0; i<nbItems && !isActor; i++)
2550 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2551 if (anActor && anActor->hasIO()) {
2552 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2553 if (aViewWindow->isVisible(anIO)) {
2554 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2555 myActorsList.append(anActor);
2563 if (myActorsList.count() > 0) {
2564 QListIterator<SMESH_Actor*> it( myActorsList );
2565 while ( it.hasNext() ) {
2566 SMESH_Actor* anActor = it.next();
2567 if ( IsActorVisible(anActor) )
2568 anActor->SetPickable(true);
2572 return ( isActor || (myActorsList.count() > 0) );
2575 //=======================================================================
2576 //function : setShowEntityMode
2577 //purpose : make shown only entity corresponding to my type
2578 //=======================================================================
2579 void SMESHGUI_GroupDlg::setShowEntityMode()
2581 if ( !myMesh->_is_nil() ) {
2582 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2583 if (!myStoredShownEntity)
2584 myStoredShownEntity = actor->GetEntityMode();
2585 switch ( myTypeId ) {
2586 case grpNodeSelection: restoreShowEntityMode(); break;
2587 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2588 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2589 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2590 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2596 //=======================================================================
2597 //function : restoreShowEntityMode
2598 //purpose : restore ShowEntity mode of myActor
2599 //=======================================================================
2600 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2602 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2603 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2604 actor->SetEntityMode(myStoredShownEntity);
2607 myStoredShownEntity = 0;
2610 //=======================================================================
2611 //function : IsActorVisible
2612 //purpose : return visibility of the actor
2613 //=======================================================================
2614 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2616 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2617 if (theActor && aViewWindow)
2618 return aViewWindow->isVisible(theActor->getIO());
2622 //================================================================
2623 //function : setIsApplyAndClose
2624 //purpose : Set value of the flag indicating that the dialog is
2625 // accepted by Apply & Close button
2626 //================================================================
2627 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2629 myIsApplyAndClose = theFlag;
2632 //================================================================
2633 //function : isApplyAndClose
2634 //purpose : Get value of the flag indicating that the dialog is
2635 // accepted by Apply & Close button
2636 //================================================================
2637 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2639 return myIsApplyAndClose;