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,
107 grpBallSelection = 2,
108 grpEdgeSelection = 3,
109 grpFaceSelection = 4,
110 grpVolumeSelection = 5,
111 grpSubMeshSelection = 6,
112 grpGroupSelection = 7,
113 grpMeshSelection = 8,
114 grpGeomSelection = 9,
115 grpAllSelection = 10,
118 //=================================================================================
119 // function : SMESHGUI_GroupDlg()
121 //=================================================================================
122 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
123 SMESH::SMESH_Mesh_ptr theMesh )
124 : QDialog( SMESH::GetDesktop( theModule ) ),
125 mySMESHGUI( theModule ),
126 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
127 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
129 myNameChanged( false ),
130 myIsApplyAndClose( false ),
131 myNbChangesOfContents(0)
134 if ( !theMesh->_is_nil() )
138 mySelectSubMesh->setEnabled( false );
139 mySelectGroup->setEnabled( false );
140 myGeomGroupBtn->setEnabled( false );
141 myGeomGroupLine->setEnabled( false );
145 //=================================================================================
146 // function : SMESHGUI_GroupDlg()
148 //=================================================================================
149 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
150 SMESH::SMESH_GroupBase_ptr theGroup,
151 const bool theIsConvert )
152 : QDialog( SMESH::GetDesktop( theModule ) ),
153 mySMESHGUI( theModule ),
154 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
155 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
157 myNameChanged( false ),
158 myNbChangesOfContents(0) // just not to use uninitialized variable
161 if ( !theGroup->_is_nil() )
162 init( theGroup, theIsConvert );
165 mySelectSubMesh->setEnabled( false );
166 mySelectGroup->setEnabled( false );
168 myCurrentLineEdit = myMeshGroupLine;
169 setSelectionMode( grpGroupSelection );
173 //=================================================================================
174 // function : SMESHGUI_GroupDlg()
176 //=================================================================================
177 void SMESHGUI_GroupDlg::initDialog( bool create)
180 setAttribute( Qt::WA_DeleteOnClose, true );
184 myCurrentLineEdit = 0;
188 myGeomObjects = new GEOM::ListOfGO();
189 myGeomObjects->length( 0 );
191 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
193 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
194 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
196 setSizeGripEnabled( true);
198 QGridLayout* aMainLayout = new QGridLayout( this );
199 aMainLayout->setMargin( MARGIN );
200 aMainLayout->setSpacing( SPACING );
202 /***************************************************************/
203 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
204 myMeshGroupBtn = new QPushButton( this );
205 myMeshGroupBtn->setIcon( image0 );
206 myMeshGroupLine = new QLineEdit( this );
207 myMeshGroupLine->setReadOnly( true );
209 /***************************************************************/
210 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
211 myTypeGroup = new QButtonGroup( this );
212 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
213 aTypeBoxLayout->setMargin( MARGIN );
214 aTypeBoxLayout->setSpacing( SPACING );
217 types.append( tr( "MESH_NODE" ) );
218 types.append( tr( "SMESH_ELEM0D" ) );
219 types.append( tr( "SMESH_BALL_ELEM" ) );
220 types.append( tr( "SMESH_EDGE" ) );
221 types.append( tr( "SMESH_FACE" ) );
222 types.append( tr( "SMESH_VOLUME" ) );
224 for ( int i = 0; i < types.count(); i++ )
226 rb = new QRadioButton( types[i], aTypeBox );
227 myTypeGroup->addButton( rb, i );
228 aTypeBoxLayout->addWidget( rb );
230 aTypeBox->setEnabled( create );
233 /***************************************************************/
234 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
235 aName->setMinimumWidth( 50 );
236 myName = new QLineEdit( this );
238 /***************************************************************/
239 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
240 myGrpTypeGroup = new QButtonGroup( this );
241 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
242 aGrpTypeBoxLayout->setMargin( MARGIN );
243 aGrpTypeBoxLayout->setSpacing( SPACING );
245 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
246 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
247 QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox );
248 myGrpTypeGroup->addButton( rb1, 0 );
249 myGrpTypeGroup->addButton( rb2, 1 );
250 myGrpTypeGroup->addButton( rb3, 2 );
251 aGrpTypeBoxLayout->addWidget( rb1 );
252 aGrpTypeBoxLayout->addWidget( rb2 );
253 aGrpTypeBoxLayout->addWidget( rb3 );
254 aGrpTypeBox->setEnabled( create );
257 /***************************************************************/
258 myWGStack = new QStackedWidget( this );
259 QWidget* wg1 = new QWidget( myWGStack );
260 QWidget* wg2 = new QWidget( myWGStack );
261 QWidget* wg3 = new QWidget( myWGStack );
263 /***************************************************************/
264 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
265 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
266 aContentBoxLayout->setMargin( MARGIN );
267 aContentBoxLayout->setSpacing( SPACING );
269 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
270 myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
272 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
273 myElements = new QListWidget( aContentBox );
274 myElements->setSelectionMode( QListWidget::ExtendedSelection );
276 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
277 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
278 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
279 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
281 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
282 aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
283 aContentBoxLayout->addWidget( myFilterBtn, 1, 1 );
284 aContentBoxLayout->addWidget( myElementsLab, 2, 0 );
285 aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 );
286 aContentBoxLayout->addWidget( myAddBtn, 3, 1 );
287 aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 );
288 aContentBoxLayout->addWidget( mySortBtn, 8, 1 );
290 aContentBoxLayout->setColumnStretch( 0, 1 );
291 aContentBoxLayout->setRowStretch( 3, 1 );
292 aContentBoxLayout->setRowStretch( 6, 1 );
294 /***************************************************************/
295 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
296 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
297 mySelectBoxLayout->setMargin( MARGIN );
298 mySelectBoxLayout->setSpacing( SPACING );
300 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
301 mySubMeshBtn = new QPushButton( mySelectBox );
302 mySubMeshBtn->setIcon( image0 );
303 mySubMeshLine = new QLineEdit( mySelectBox );
304 mySubMeshLine->setReadOnly( true );
305 onSelectSubMesh( false );
307 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
308 myGroupBtn = new QPushButton( mySelectBox );
309 myGroupBtn->setIcon( image0 );
310 myGroupLine = new QLineEdit( mySelectBox );
311 myGroupLine->setReadOnly( true );
312 onSelectGroup( false );
314 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
315 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
316 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
317 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
318 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
319 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
321 /***************************************************************/
322 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
323 wg1Layout->setMargin( 0 );
324 wg1Layout->setSpacing( SPACING );
325 wg1Layout->addWidget( aContentBox );
326 wg1Layout->addWidget( mySelectBox );
327 wg1Layout->setStretchFactor( aContentBox, 10 );
329 /***************************************************************/
330 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
331 myGeomGroupBtn = new QToolButton( wg2 );
332 myGeomGroupBtn->setIcon( image0 );
333 myGeomGroupBtn->setCheckable( true );
334 myGeomGroupLine = new QLineEdit( wg2 );
335 myGeomGroupLine->setReadOnly( true ); //VSR ???
336 onSelectGeomGroup( false );
338 myGeomGroupBtn->setEnabled( create );
339 myGeomGroupLine->setEnabled( create );
341 /***************************************************************/
342 QGridLayout* wg2Layout = new QGridLayout( wg2 );
343 wg2Layout->setMargin( 0 );
344 wg2Layout->setSpacing( SPACING );
345 wg2Layout->addWidget( geomObject, 0, 0 );
346 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
347 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
348 wg2Layout->setRowStretch( 1, 5 );
350 /***************************************************************/
351 QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
352 QGridLayout* wg3Layout = new QGridLayout( wg3 );
353 wg3Layout->setMargin( 0 );
354 wg3Layout->setSpacing( SPACING );
355 wg3Layout->addWidget( aFilter2, 0, 0 );
356 wg3Layout->setRowStretch( 1, 5 );
358 /***************************************************************/
359 myWGStack->insertWidget( 0, wg1 );
360 myWGStack->insertWidget( 1, wg2 );
361 myWGStack->insertWidget( 2, wg3 );
363 /***************************************************************/
364 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
365 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
366 aColorBoxLayout->setMargin(MARGIN);
367 aColorBoxLayout->setSpacing(SPACING);
369 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
370 myColorBtn = new QtxColorButton(aColorBox);
371 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
372 myColorBtn->sizePolicy().verticalPolicy() );
374 aColorBoxLayout->addWidget(aColorLab);
375 aColorBoxLayout->addWidget(myColorBtn);
377 /***************************************************************/
379 QFrame* aButtons = new QFrame(this);
380 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
381 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
382 aBtnLayout->setMargin(MARGIN);
383 aBtnLayout->setSpacing(SPACING);
385 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
386 myOKBtn->setAutoDefault(true);
387 myOKBtn->setDefault(true);
388 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
389 myApplyBtn->setAutoDefault(true);
390 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
391 myCloseBtn->setAutoDefault(true);
392 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
393 myHelpBtn->setAutoDefault(true);
395 aBtnLayout->addWidget(myOKBtn);
396 aBtnLayout->addSpacing(10);
397 aBtnLayout->addWidget(myApplyBtn);
398 aBtnLayout->addSpacing(10);
399 aBtnLayout->addStretch();
400 aBtnLayout->addWidget(myCloseBtn);
401 aBtnLayout->addWidget(myHelpBtn);
403 /***************************************************************/
404 aMainLayout->addWidget(meshGroupLab, 0, 0);
405 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
406 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
407 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
408 aMainLayout->addWidget(aName, 2, 0);
409 aMainLayout->addWidget(myName, 2, 2);
410 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
411 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
412 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
413 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
415 /* signals and slots connections */
416 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
417 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
418 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
420 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
421 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
423 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
424 connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters()));
425 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
426 connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
427 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
428 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
429 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
431 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
432 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
433 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
434 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
435 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
437 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
439 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
440 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
441 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
442 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
445 mySMESHGUI->SetActiveDialogBox(this);
446 mySMESHGUI->SetState(800);
448 mySelectionMode = grpNoSelection;
449 myMeshFilter = new SMESH_TypeFilter(SMESH::MESH);
450 mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
451 SMESH_LogicalFilter::LO_OR,
452 /*takeOwnership=*/true);
453 myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
454 SMESH_LogicalFilter::LO_OR,
455 /*takeOwnership=*/true);
456 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
457 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
459 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
460 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
461 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
462 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
464 rb1->setChecked(true); // VSR !!!
465 onGrpTypeChanged(0); // VSR!!!
467 if (myMesh->_is_nil() )
468 myTypeGroup->button(0)->setChecked(true);
470 onSelectAll(); //updateButtons();
473 //=================================================================================
474 // function : ~SMESHGUI_GroupDlg()
475 // purpose : Destroys the object and frees any allocated resources
476 //=================================================================================
477 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
479 // no need to delete child widgets, Qt does it all for us
480 if ( myFilterDlg != 0 ) {
481 myFilterDlg->setParent( 0 );
484 if ( myMeshFilter ) delete myMeshFilter;
485 if ( mySubMeshFilter ) delete mySubMeshFilter;
486 if ( myGroupFilter ) delete myGroupFilter;
487 if ( myGeomFilter ) delete myGeomFilter;
490 //=================================================================================
491 // function : GetDefaultName()
492 // purpose : Get the Group Name if Create new Group
493 //=================================================================================
494 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
498 // collect all object names of SMESH component
499 SalomeApp_Study* appStudy =
500 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
501 if ( !appStudy ) return aName;
502 _PTR(Study) aStudy = appStudy->studyDS();
504 std::set<std::string> aSet;
505 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
507 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
509 for (it->InitEx(true); it->More(); it->Next()) {
511 aSet.insert(obj->GetName());
515 // build a unique name
517 bool isUnique = false;
519 aName = theOperation + "_" + QString::number(++aNumber);
520 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
526 void SMESHGUI_GroupDlg::setDefaultName() const
529 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
531 QString aPrefix ="Group_";
535 aResName = aPrefix + QString::number( i++ );
536 anObj = aStudy->FindObject( aResName.toLatin1().data() );
539 myName->setText(aResName);
542 //=================================================================================
545 //=================================================================================
546 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
548 mySelectionMgr->installFilter(myMeshFilter);
550 /* init data from current selection */
551 restoreShowEntityMode();
552 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
554 myGroup = SMESH::SMESH_Group::_nil();
555 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
556 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
558 // NPAL19389: create a group with a selection in another group
559 // set actor of myMesh, if it is visible, else try
560 // any visible actor of group or submesh of myMesh
561 SetAppropriateActor();
563 setDefaultGroupColor();
568 mySelectionMgr->selectedObjects( aList );
569 if( !aList.IsEmpty() )
571 QString aName = aList.First()->getName();
572 myMeshGroupLine->setText(aName);
573 myMeshGroupLine->home( false );
576 myCurrentLineEdit = 0;
578 myTypeGroup->button(0)->setChecked(true);
582 //=================================================================================
585 //=================================================================================
586 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
587 const bool theIsConvert)
589 restoreShowEntityMode();
590 myMesh = theGroup->GetMesh();
593 myNameChanged = true;
594 myName->blockSignals(true);
595 myName->setText(theGroup->GetName());
596 myName->blockSignals(false);
599 SALOMEDS::Color aColor = theGroup->GetColor();
600 setGroupColor( aColor );
602 myMeshGroupLine->setText(theGroup->GetName());
605 switch(theGroup->GetType()) {
606 case SMESH::NODE: aType = grpNodeSelection; break;
607 case SMESH::ELEM0D: aType = grp0DSelection; break;
608 case SMESH::BALL: aType = grpBallSelection; break;
609 case SMESH::EDGE: aType = grpEdgeSelection; break;
610 case SMESH::FACE: aType = grpFaceSelection; break;
611 case SMESH::VOLUME: aType = grpVolumeSelection; break;
613 myTypeGroup->button(aType)->setChecked(true);
615 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
616 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
617 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
618 myFilter = SMESH::Filter::_nil();
620 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
623 // NPAL19389: create a group with a selection in another group
624 // set actor of myMesh, if it is visible, else set
625 // actor of theGroup, if it is visible, else try
626 // any visible actor of group or submesh of myMesh
627 // commented, because an attempt to set selection on not displayed cells leads to error
628 SetAppropriateActor();
630 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
632 anActor = SMESH::FindActorByObject(theGroup);
633 SMESH::SetPickable(anActor);*/
635 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
636 myGrpTypeGroup->button(grpType)->setChecked(true);
637 onGrpTypeChanged(grpType);
640 if ( grpType == 0 ) { // standalone group
641 myCurrentLineEdit = 0;
643 myAllowElemsModif->setChecked( true );
645 setSelectionMode(aType);
647 setShowEntityMode(); // depends on myTypeId
650 if (!theGroup->IsEmpty()) {
651 SMESH::long_array_var anElements = theGroup->GetListOfID();
652 int k = anElements->length();
653 for (int i = 0; i < k; i++) {
654 myIdList.append(anElements[i]);
655 myElements->addItem(QString::number(anElements[i]));
657 myElements->selectAll();
660 else if ( grpType == 1 ) // group on geom
662 QString aShapeName( "" );
663 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
664 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
665 if (!aGroupShape->_is_nil())
667 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
669 aShapeName = aGroupShapeSO->GetName().c_str();
671 myGeomGroupLine->setText( aShapeName );
673 else // group on filter
675 myFilter = myGroupOnFilter->GetFilter();
676 if ( !myFilter->_is_nil() ) {
677 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
678 if ( perdicate->_is_nil() )
679 myFilter = SMESH::Filter::_nil();
685 myNameChanged = true;
686 myName->blockSignals(true);
687 myName->setText(theGroup->GetName());
688 myName->blockSignals(false);
691 onSelectAll(); //updateButtons();
694 //=================================================================================
695 // function : updateButtons()
697 //=================================================================================
698 void SMESHGUI_GroupDlg::updateButtons()
700 bool enable = !myName->text().trimmed().isEmpty();
703 if (myGrpTypeId == 0) { // standalone
704 if ( !mySelectAll->isChecked() )
706 if ( myAllowElemsModif->isChecked() )
708 enable = ( myElements->count() > 0 );
710 else if ((enable = !myFilter->_is_nil() ))
712 SMESH::array_of_ElementType_var types = myFilter->GetTypes();
713 enable = types->length();
716 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
718 else if (myGrpTypeId == 1) // on geom
720 if (CORBA::is_nil(myGroupOnGeom)) // creation mode
721 enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
723 else if (myGrpTypeId == 2) // on filter
725 if (( enable = !myFilter->_is_nil() ))
726 if (CORBA::is_nil(myGroupOnFilter) ) // creation mode
727 enable = !myMesh->_is_nil();
731 myOKBtn->setEnabled(enable);
732 myApplyBtn->setEnabled(enable);
735 //=================================================================================
736 // function : onNameChanged()
738 //=================================================================================
739 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
741 myOldName = myName->text();
743 myNameChanged = !myName->text().trimmed().isEmpty();
746 //=================================================================================
747 // function : onTypeChanged()
748 // purpose : Group elements type radio button management
749 //=================================================================================
750 void SMESHGUI_GroupDlg::onTypeChanged (int id)
752 if (myTypeId != id) {
755 if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
756 setSelectionMode(id);
758 setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
760 onObjectSelectionChanged();
765 //=================================================================================
766 // function : onGrpTypeChanged()
767 // purpose : Group type radio button management
768 //=================================================================================
769 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
771 if (myGrpTypeId != id) {
773 myWGStack->setCurrentIndex( id );
774 myName->blockSignals(true);
775 myName->setText(myOldName);
776 myName->blockSignals(false);
777 onSelectGeomGroup(id != 0);
782 //=================================================================================
783 // function : onColorChanged()
784 // purpose : Color button management
785 //=================================================================================
786 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
791 //=================================================================================
792 // function : setSelectionMode()
793 // purpose : Radio button management
794 //=================================================================================
795 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
798 if (myMesh->_is_nil())
800 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
801 bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
802 if (mySelectionMode != theMode) {
803 // [PAL10408] mySelectionMgr->clearSelected();
804 mySelectionMgr->clearFilters();
805 SMESH::RemoveFilters();
807 if (myActorsList.count() > 0)
808 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
809 it.next()->SetPointRepresentation(false);
811 SMESH::SetPointRepresentation(false);
814 case grpNodeSelection:
815 if ( myGrpTypeId == 0 ) // standalone
817 if (myActorsList.count() > 0)
818 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
819 it.next()->SetPointRepresentation(true);
821 SMESH::SetPointRepresentation(true);
823 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
825 case grpEdgeSelection:
826 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
828 case grpBallSelection:
829 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
832 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : Elem0DSelection);
834 case grpFaceSelection:
835 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
837 case grpVolumeSelection:
838 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
840 case grpSubMeshSelection: {
842 SMESH_TypeFilter* f = 0;
844 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH); break;
845 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_EDGE); break;
846 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_FACE); break;
847 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_SOLID); break;
848 default: f = new SMESH_TypeFilter(SMESH::SUBMESH);
850 QList<SUIT_SelectionFilter*> filtList;
851 filtList.append( f );
852 filtList.append( new SMESH_TypeFilter(SMESH::SUBMESH_COMPOUND));
853 mySubMeshFilter->setFilters( filtList );
855 mySelectionMgr->installFilter( mySubMeshFilter );
857 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
860 case grpGroupSelection: {
862 SMESH_TypeFilter* f = 0;
864 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_NODE); break;
865 case grp0DSelection: f = new SMESH_TypeFilter(SMESH::GROUP_0D); break;
866 case grpBallSelection: f = new SMESH_TypeFilter(SMESH::GROUP_BALL); break;
867 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_EDGE); break;
868 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::GROUP_FACE); break;
869 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_VOLUME); break;
870 default: f = new SMESH_TypeFilter(SMESH::GROUP);
872 QList<SUIT_SelectionFilter*> filtList;
873 filtList.append( f );
874 myGroupFilter->setFilters( filtList );
876 mySelectionMgr->installFilter(myGroupFilter);
877 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
880 case grpMeshSelection:
881 mySelectionMgr->installFilter(myMeshFilter);
882 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
884 case grpGeomSelection:
885 mySelectionMgr->installFilter(myGeomFilter);
886 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
889 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
892 if ( aViewWindow ) aViewWindow->Repaint();
893 mySelectionMode = theMode;
897 //=================================================================================
898 // function : onApply()
900 //=================================================================================
901 bool SMESHGUI_GroupDlg::onApply()
903 if (mySMESHGUI->isActiveStudyLocked())
906 if (myName->text().trimmed().isEmpty())
909 SMESH::ElementType aType = SMESH::ALL;
911 case grpNodeSelection: aType = SMESH::NODE; break;
912 case grp0DSelection: aType = SMESH::ELEM0D; break;
913 case grpBallSelection: aType = SMESH::BALL; break;
914 case grpEdgeSelection: aType = SMESH::EDGE; break;
915 case grpFaceSelection: aType = SMESH::FACE; break;
916 case grpVolumeSelection: aType = SMESH::VOLUME; break;
920 QStringList anEntryList;
922 SMESH::SMESH_GroupBase_var resultGroup;
925 if (myGrpTypeId == 0) // standalone
927 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
930 mySelectionMgr->clearSelected();
932 if (myGroup->_is_nil()) { // creation or conversion
933 // check if group on geometry is not null
934 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
935 if (myMesh->_is_nil())
937 if ( myGroupOnGeom->_is_nil() )
938 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
940 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
942 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
943 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
947 if (myGroup->_is_nil()) { // creation
948 if (myMesh->_is_nil())
951 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
953 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
956 if ( mySelectAll->isChecked() ) {
958 myGroup->AddFrom(myMesh.in());
963 if ( !myFilter->_is_nil() &&
964 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
966 myGroup->AddFrom( myFilter );
970 SMESH::long_array_var anIdList = new SMESH::long_array;
971 int i, k = myElements->count();
973 for (i = 0; i < k; i++) {
974 anIdList[i] = myElements->item(i)->text().toInt();
976 myGroup->Add(anIdList.inout());
983 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
986 if ( mySelectAll->isChecked() ) {
989 myGroup->AddFrom(myMesh.in());
994 int i, total = myElements->count();
995 for (i = 0; i < total; i++) {
996 int anId = myElements->item(i)->text().toInt();
997 int idx = myIdList.indexOf(anId);
999 aAddList.append(anId);
1001 myIdList.removeAt(idx);
1003 if (!aAddList.empty()) {
1004 SMESH::long_array_var anIdList = new SMESH::long_array;
1005 int added = aAddList.count();
1006 anIdList->length(added);
1007 for (i = 0; i < added; i++)
1008 anIdList[i] = aAddList[i];
1009 myGroup->Add(anIdList.inout());
1011 if (!myIdList.empty()) {
1012 SMESH::long_array_var anIdList = new SMESH::long_array;
1013 int removed = myIdList.count();
1014 anIdList->length(removed);
1015 for (i = 0; i < removed; i++)
1016 anIdList[i] = myIdList[i];
1017 myGroup->Remove(anIdList.inout());
1019 /* init for next operation */
1021 for (i = 0; i < total; i++) {
1022 myIdList.append(myElements->item(i)->text().toInt());
1029 else if (myGrpTypeId == 1) // on geom object
1031 if (CORBA::is_nil(myGroupOnGeom)) { // creation
1032 if (myMesh->_is_nil() || !myGeomObjects->length())
1035 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1036 GEOM::GEOM_IGroupOperations_var aGroupOp =
1037 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1039 if (myGeomObjects->length() == 1) {
1040 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1041 myName->text().toLatin1().data(),
1045 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1046 if ( aSMESHGen->_is_nil() )
1049 // create a geometry group
1050 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1051 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1053 if (geomGen->_is_nil() || !aStudy)
1056 GEOM::GEOM_IGroupOperations_var op =
1057 geomGen->GetIGroupOperations(aStudy->StudyId());
1061 // check and add all selected GEOM objects: they must be
1062 // a sub-shapes of the main GEOM and must be of one type
1063 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1064 for ( int i =0; i < myGeomObjects->length(); i++) {
1065 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1067 aGroupType = aSubShapeType;
1068 else if (aSubShapeType != aGroupType) {
1069 aGroupType = TopAbs_SHAPE;
1074 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1075 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1076 op->UnionList(aGroupVar, myGeomObjects);
1079 // publish the GEOM group in study
1080 QString aNewGeomGroupName ( "Auto_group_for_" );
1081 aNewGeomGroupName += myName->text();
1082 SALOMEDS::SObject_var aNewGroupSO =
1083 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
1084 aNewGeomGroupName.toLatin1().data(), aMeshShape);
1087 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1088 myName->text().toLatin1().data(),
1091 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1097 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1102 if (myGrpTypeId == 2) // group on filter
1104 if ( myFilter->_is_nil() ) return false;
1106 if (CORBA::is_nil(myGroupOnFilter)) { // creation
1107 if (myMesh->_is_nil())
1110 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1111 myName->text().toLatin1().data(),
1114 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1119 myGroupOnFilter->SetFilter( myFilter );
1121 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1129 SALOMEDS::Color aColor = getGroupColor();
1130 resultGroup->SetColor(aColor);
1132 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1134 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1138 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1140 /* init for the next operation */
1142 myElements->clear();
1143 myGroup = SMESH::SMESH_Group::_nil();
1144 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1145 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1146 myFilter = SMESH::Filter::_nil();
1150 resultGroup->SetName(myName->text().toLatin1().data());
1153 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
1154 anActor->setName(myName->text().toLatin1().data());
1157 switch ( myTypeId ) {
1158 case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1159 case grp0DSelection: anActor->Set0DColor ( aColor.R, aColor.G, aColor.B ); break;
1160 case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1161 case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1162 case grpVolumeSelection:
1163 SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
1164 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1166 case grpFaceSelection:
1168 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1169 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1174 SMESHGUI::Modified();
1175 mySMESHGUI->updateObjBrowser(true);
1176 SMESH::UpdateView(); // asv: fix of BUG PAL5515
1177 mySelectionMgr->clearSelected();
1179 if( LightApp_Application* anApp =
1180 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1181 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1186 //=================================================================================
1187 // function : onOK()
1189 //=================================================================================
1190 void SMESHGUI_GroupDlg::onOK()
1192 setIsApplyAndClose( true );
1195 setIsApplyAndClose( false );
1198 //=================================================================================
1199 // function : onListSelectionChanged()
1200 // purpose : Called when selection in element list is changed
1201 //=================================================================================
1202 void SMESHGUI_GroupDlg::onListSelectionChanged()
1204 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1205 if( myIsBusy || myActorsList.count() == 0 ) return;
1208 if (myCurrentLineEdit == 0) {
1209 mySelectionMgr->clearSelected();
1210 TColStd_MapOfInteger aIndexes;
1211 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1212 QListWidgetItem* anItem;
1213 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1214 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1215 SALOME_ListIO aList;
1216 aList.Append(myActorsList.first()->getIO());
1217 mySelectionMgr->setSelectedObjects(aList,false);
1222 //=================================================================================
1223 // function : onObjectSelectionChanged()
1224 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1225 //=================================================================================
1226 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1228 if ( myIsBusy || !isEnabled()) return;
1229 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1233 SALOME_ListIO aList;
1234 mySelectionMgr->selectedObjects( aList );
1236 int aNbSel = aList.Extent();
1237 myElements->clearSelection();
1239 if (myCurrentLineEdit)
1241 myCurrentLineEdit->setText( "" );
1242 QString aString = "";
1244 if (myCurrentLineEdit == myMeshGroupLine)
1246 mySelectSubMesh->setEnabled(false);
1247 mySelectGroup->setEnabled(false);
1248 myGroupLine->setText( "" );
1249 mySubMeshLine->setText( "" );
1251 myGeomGroupBtn->setEnabled(false);
1252 myGeomGroupLine->setEnabled(false);
1253 myGeomGroupLine->setText( "" );
1254 myGeomObjects = new GEOM::ListOfGO();
1255 myGeomObjects->length(0);
1257 if (myGeomGroupBtn->isChecked())
1258 myGeomGroupBtn->setChecked(false);
1260 myName->setText( "" );
1262 myElements->clear();
1265 myGroup = SMESH::SMESH_Group::_nil();
1266 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1267 restoreShowEntityMode();
1268 myMesh = SMESH::SMESH_Mesh::_nil();
1274 Handle(SALOME_InteractiveObject) IO = aList.First();
1277 restoreShowEntityMode();
1278 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1279 setShowEntityMode();
1281 if (myMesh->_is_nil())
1288 if ( myFilterDlg && !myMesh->_is_nil()){
1289 myFilterDlg->SetMesh( myMesh );
1291 myGroup = SMESH::SMESH_Group::_nil();
1293 // NPAL19389: create a group with a selection in another group
1294 // set actor of myMesh, if it is visible, else try
1295 // any visible actor of group or submesh of myMesh
1296 SetAppropriateActor();
1298 aString = aList.First()->getName();
1299 myMeshGroupLine->setText(aString);
1300 myMeshGroupLine->home( false );
1302 mySelectSubMesh->setEnabled(true);
1303 mySelectGroup->setEnabled(true);
1304 myGeomGroupBtn->setEnabled(true);
1305 myGeomGroupLine->setEnabled(true);
1309 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1310 if (aGroup->_is_nil())
1317 myGroup = SMESH::SMESH_Group::_nil();
1318 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1322 mySelectSubMesh->setEnabled(true);
1323 mySelectGroup->setEnabled(true);
1325 myCurrentLineEdit = 0;
1330 if (myGrpTypeId == 0)
1336 myElements->clear();
1337 setSelectionMode(myTypeId);
1345 else if (myCurrentLineEdit == myGeomGroupLine)
1347 myGeomObjects = new GEOM::ListOfGO();
1350 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1352 if (aNbSel == 0 || !aMeshSO)
1354 myGeomObjects->length(0);
1360 myGeomObjects->length(aNbSel);
1362 GEOM::GEOM_Object_var aGeomGroup;
1365 SALOME_ListIteratorOfListIO anIt (aList);
1366 for (; anIt.More(); anIt.Next())
1368 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1370 // Check if the object is a geometry group
1371 if (CORBA::is_nil(aGeomGroup))
1374 // Check if group constructed on the same shape as a mesh or on its child
1375 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1376 GEOM::GEOM_IGroupOperations_var anOp =
1377 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1379 // The main shape of the group
1380 GEOM::GEOM_Object_var aGroupMainShape;
1381 if (aGeomGroup->GetType() == 37)
1382 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1384 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1385 _PTR(SObject) aGroupMainShapeSO =
1386 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1388 _PTR(SObject) anObj, aRef;
1389 bool isRefOrSubShape = false;
1390 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1391 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1392 isRefOrSubShape = true;
1394 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1395 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1396 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1397 if (aRef->GetID() == aFather->GetID())
1398 isRefOrSubShape = true;
1400 aFather = aFather->GetFather();
1404 if (isRefOrSubShape)
1405 myGeomObjects[i++] = aGeomGroup;
1408 myGeomObjects->length(i);
1420 if (myCurrentLineEdit == mySubMeshLine)
1421 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1422 else if (myCurrentLineEdit == myGroupLine)
1423 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1424 else if (myCurrentLineEdit == myGeomGroupLine)
1425 aString = tr( "%1 Objects" ).arg(aNbSel);
1428 aString = aList.First()->getName();
1432 myCurrentLineEdit->setText(aString);
1433 myCurrentLineEdit->home(false);
1434 // 07.06.2008 skl for IPAL19574:
1435 // change name of group only if it is empty
1436 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1437 myOldName = myName->text();
1438 myName->blockSignals(true);
1439 myName->setText(aString);
1440 myName->blockSignals(false);
1445 else // !myCurrentLineEdit: local selection of nodes or elements
1447 if (aNbSel == 1 && myActorsList.count() > 0 )
1449 // NPAL19389: create a group with a selection in another group
1450 // Switch myActor to the newly selected one, if the last
1451 // is visible and belongs to group or submesh of myMesh
1452 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1453 Handle(SALOME_InteractiveObject) selIO = aList.First();
1454 if (curIO->hasEntry() && selIO->hasEntry()) {
1455 const char* selEntry = selIO->getEntry();
1456 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1457 // different objects: selected and myActor
1458 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1459 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1460 // newly selected actor is visible
1463 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1465 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1466 int len = strlen(meshEntry);
1468 if (strncmp(selEntry, meshEntry, len) == 0) {
1469 // selected object is myMesh or a part of it
1470 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1473 SMESH::SetPickable(myActor);
1482 QString aListStr = "";
1484 if (myTypeId == 0) {
1485 QListIterator<SMESH_Actor*> it( myActorsList );
1486 while ( it.hasNext() ) {
1488 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1492 QListIterator<SMESH_Actor*> it( myActorsList );
1493 while ( it.hasNext() ) {
1495 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1500 QListWidgetItem* anItem;
1501 QList<QListWidgetItem*> listItemsToSel;
1502 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1503 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1504 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1505 foreach(anItem, found)
1506 if (!anItem->isSelected())
1507 listItemsToSel.push_back(anItem);
1509 bool blocked = myElements->signalsBlocked();
1510 myElements->blockSignals(true);
1511 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1512 myElements->blockSignals(blocked);
1513 onListSelectionChanged();
1514 listItemsToSel.clear();
1519 if (myActorsList.count() == 0) {
1520 if (!myGroup->_is_nil()) {
1521 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1523 myActorsList.append( anActor );
1525 else if(!myGroupOnGeom->_is_nil()) {
1526 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1528 myActorsList.append( anActor );
1531 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1533 myActorsList.append( anActor );
1537 // somehow, if we display the mesh, while selecting from another actor,
1538 // the mesh becomes pickable, and there is no way to select any element
1539 if (myActorsList.count() > 0) {
1540 QListIterator<SMESH_Actor*> it( myActorsList );
1541 while ( it.hasNext() ) {
1542 SMESH_Actor* anActor = it.next();
1543 if ( IsActorVisible(anActor) )
1544 anActor->SetPickable(true);
1551 //=================================================================================
1552 // function : onSelectAll()
1553 // purpose : Called when "Select all" is checked
1554 //=================================================================================
1555 void SMESHGUI_GroupDlg::onSelectAll()
1557 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1559 myElementsLab->setEnabled( !noElemsModif );
1560 myElements->setEnabled ( !noElemsModif );
1561 myFilterBtn->setEnabled ( !mySelectAll->isChecked() );
1562 myAddBtn->setEnabled ( !noElemsModif );
1563 myRemoveBtn->setEnabled ( !noElemsModif );
1564 mySortBtn->setEnabled ( !noElemsModif );
1565 mySelectBox->setEnabled ( !noElemsModif );
1566 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1568 int selMode = mySelectionMode;
1569 mySelectionMode = grpNoSelection;
1570 setSelectionMode( selMode );
1574 //=================================================================================
1575 // function : onSelectSubMesh()
1576 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1577 //=================================================================================
1578 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1581 if (mySelectGroup->isChecked()) {
1582 mySelectGroup->setChecked(false);
1584 //VSR: else if (mySelectGeomGroup->isChecked()) {
1585 //VSR: mySelectGeomGroup->setChecked(false);
1587 myCurrentLineEdit = mySubMeshLine;
1588 setSelectionMode(grpSubMeshSelection);
1591 mySubMeshLine->setText( "" );
1592 myCurrentLineEdit = 0;
1594 setSelectionMode(myTypeId);
1596 mySubMeshBtn->setEnabled(on);
1597 mySubMeshLine->setEnabled(on);
1601 //=================================================================================
1602 // function : (onSelectGroup)
1603 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1604 //=================================================================================
1605 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1608 if (mySelectSubMesh->isChecked()) {
1609 mySelectSubMesh->setChecked(false);
1611 myCurrentLineEdit = myGroupLine;
1612 setSelectionMode(grpGroupSelection);
1615 myGroupLine->setText( "" );
1616 myCurrentLineEdit = 0;
1618 setSelectionMode(myTypeId);
1620 myGroupBtn->setEnabled(on);
1621 myGroupLine->setEnabled(on);
1625 //=================================================================================
1626 // function : (onSelectGeomGroup)
1627 // purpose : Called when group type changed. on == "on group" or "on filter"
1628 //=================================================================================
1629 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1632 if (mySelectSubMesh->isChecked()) {
1633 mySelectSubMesh->setChecked(false);
1635 else if (mySelectGroup->isChecked()) {
1636 mySelectGroup->setChecked(false);
1638 if ( myGrpTypeId == 1 ) { // on group
1639 myCurrentLineEdit = myGeomGroupLine;
1643 myCurrentLineEdit = 0;
1645 setSelectionMode(grpAllSelection);
1648 myGeomGroupBtn->setChecked(false);
1649 myGeomObjects->length(0);
1650 myGeomGroupLine->setText( "" );
1651 myCurrentLineEdit = 0;
1653 setSelectionMode( myTypeId );
1657 //=================================================================================
1658 // function : setCurrentSelection()
1660 //=================================================================================
1661 void SMESHGUI_GroupDlg::setCurrentSelection()
1663 QPushButton* send = (QPushButton*)sender();
1664 myCurrentLineEdit = 0;
1665 if (send == myMeshGroupBtn) {
1666 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1667 mySelectionMgr->clearSelected();
1669 setSelectionMode(grpMeshSelection);
1671 setSelectionMode(grpGroupSelection);
1672 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1673 myCurrentLineEdit = myMeshGroupLine;
1674 onObjectSelectionChanged();
1676 else if (send == mySubMeshBtn) {
1677 myCurrentLineEdit = mySubMeshLine;
1678 onObjectSelectionChanged();
1680 else if (send == myGroupBtn) {
1681 myCurrentLineEdit = myGroupLine;
1682 onObjectSelectionChanged();
1687 //=================================================================================
1688 // function : setFilters()
1689 // purpose : SLOT. Called when "Filter" button pressed.
1690 //=================================================================================
1691 void SMESHGUI_GroupDlg::setFilters()
1693 if(myMesh->_is_nil()) {
1694 SUIT_MessageBox::critical(this,
1696 tr("NO_MESH_SELECTED"));
1700 SMESH::ElementType aType = SMESH::ALL;
1703 case grpNodeSelection: aType = SMESH::NODE; break;
1704 case grp0DSelection: aType = SMESH::ELEM0D; break;
1705 case grpBallSelection: aType = SMESH::BALL; break;
1706 case grpEdgeSelection: aType = SMESH::EDGE; break;
1707 case grpFaceSelection: aType = SMESH::FACE; break;
1708 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1712 if ( myFilterDlg == 0 )
1714 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1715 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1718 myFilterDlg->Init( aType );
1720 if ( !myGroupOnFilter->_is_nil() )
1722 myFilterDlg->SetFilter( myFilter, aType );
1723 myFilterDlg->Init( aType );
1726 myFilterDlg->SetSelection();
1727 myFilterDlg->SetMesh( myMesh );
1728 myFilterDlg->SetSourceWg( myElements, false );
1730 myFilterDlg->show();
1733 //=================================================================================
1734 // function : onFilterAccepted()
1735 // purpose : SLOT. Called when Filter dlg closed with OK button.
1736 // Uncheck "Select submesh" and "Select group" checkboxes
1737 //=================================================================================
1738 void SMESHGUI_GroupDlg::onFilterAccepted()
1740 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1742 mySelectionMode = myTypeId;
1743 mySelectSubMesh->setChecked( false );
1744 mySelectGroup->setChecked( false );
1746 // get a filter from myFilterDlg
1747 myFilter = myFilterDlg->GetFilter();
1748 if ( !myFilter->_is_nil() ) {
1749 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1750 if ( perdicate->_is_nil() )
1751 myFilter = SMESH::Filter::_nil();
1753 // set mesh to myFilter
1754 if ( !myFilter->_is_nil() ) {
1755 SMESH::SMESH_Mesh_var mesh = myMesh;
1756 if ( mesh->_is_nil() ) {
1757 if ( !myGroup->_is_nil() )
1758 mesh = myGroup->GetMesh();
1759 else if ( !myGroupOnGeom->_is_nil() )
1760 mesh = myGroupOnGeom->GetMesh();
1761 else if ( !myGroupOnFilter->_is_nil() )
1762 mesh = myGroupOnFilter->GetMesh();
1764 myFilter->SetMesh( mesh );
1770 //=================================================================================
1771 // function : onAdd()
1773 //=================================================================================
1774 void SMESHGUI_GroupDlg::onAdd()
1776 SALOME_ListIO aList;
1777 mySelectionMgr->selectedObjects( aList );
1779 int aNbSel = aList.Extent();
1781 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1784 int sizeBefore = myElements->count();
1786 SMESH::ElementType aType = SMESH::ALL;
1788 case grpNodeSelection:
1789 aType = SMESH::NODE;
1790 mySelector->SetSelectionMode(NodeSelection);
1792 case grpBallSelection:
1793 aType = SMESH::BALL;
1794 mySelector->SetSelectionMode(BallSelection);
1796 case grp0DSelection:
1797 aType = SMESH::ELEM0D;
1798 mySelector->SetSelectionMode(Elem0DSelection);
1800 case grpEdgeSelection:
1801 aType = SMESH::EDGE;
1802 mySelector->SetSelectionMode(EdgeSelection);
1804 case grpFaceSelection:
1805 aType = SMESH::FACE;
1806 mySelector->SetSelectionMode(FaceSelection);
1808 case grpVolumeSelection:
1809 aType = SMESH::VOLUME;
1810 mySelector->SetSelectionMode(VolumeSelection);
1813 mySelector->SetSelectionMode(ActorSelection);
1816 QListWidgetItem* anItem = 0;
1817 QList<QListWidgetItem*> listItemsToSel;
1819 if (myCurrentLineEdit == 0) {
1820 //if (aNbSel != 1) { myIsBusy = false; return; }
1821 QString aListStr = "";
1823 if (myTypeId == 0) {
1824 QListIterator<SMESH_Actor*> it( myActorsList );
1825 while ( it.hasNext() ) {
1827 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1832 QListIterator<SMESH_Actor*> it( myActorsList );
1833 while ( it.hasNext() ) {
1835 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1840 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1841 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1842 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1843 if (found.count() == 0) {
1844 anItem = new QListWidgetItem(*it);
1845 myElements->addItem(anItem);
1846 if (!anItem->isSelected())
1847 listItemsToSel.push_back(anItem);
1850 foreach(anItem, found)
1851 if (!anItem->isSelected())
1852 listItemsToSel.push_back(anItem);
1855 bool blocked = myElements->signalsBlocked();
1856 myElements->blockSignals(true);
1857 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1858 myElements->blockSignals(blocked);
1859 onListSelectionChanged();
1860 listItemsToSel.clear();
1862 } else if (myCurrentLineEdit == mySubMeshLine) {
1863 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1865 SALOME_ListIO aList;
1866 mySelectionMgr->selectedObjects( aList );
1868 SALOME_ListIteratorOfListIO anIt (aList);
1869 for ( ; anIt.More(); anIt.Next()) {
1870 SMESH::SMESH_subMesh_var aSubMesh =
1871 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1872 if (!aSubMesh->_is_nil()) {
1873 // check if mesh is the same
1874 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1876 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1877 int k = anElements->length();
1878 for (int i = 0; i < k; i++) {
1879 QString aText = QString::number(anElements[i]);
1880 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1881 if (found.count() == 0) {
1882 anItem = new QListWidgetItem(aText);
1883 myElements->addItem(anItem);
1884 if (!anItem->isSelected())
1885 listItemsToSel.push_back(anItem);
1888 foreach(anItem, found)
1889 if (!anItem->isSelected())
1890 listItemsToSel.push_back(anItem);
1893 bool blocked = myElements->signalsBlocked();
1894 myElements->blockSignals(true);
1895 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1896 myElements->blockSignals(blocked);
1897 onListSelectionChanged();
1898 listItemsToSel.clear();
1900 catch (const SALOME::SALOME_Exception& ex) {
1901 SalomeApp_Tools::QtCatchCorbaException(ex);
1906 mySelectSubMesh->setChecked(false);
1908 onListSelectionChanged();
1910 } else if (myCurrentLineEdit == myGroupLine) {
1911 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1912 SALOME_ListIO aList;
1913 mySelectionMgr->selectedObjects( aList );
1915 SALOME_ListIteratorOfListIO anIt (aList);
1916 for ( ; anIt.More(); anIt.Next()) {
1917 SMESH::SMESH_GroupBase_var aGroup =
1918 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1919 if (!aGroup->_is_nil()) {
1920 // check if mesh is the same
1921 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1922 SMESH::long_array_var anElements = aGroup->GetListOfID();
1923 int k = anElements->length();
1924 for (int i = 0; i < k; i++) {
1925 QString aText = QString::number(anElements[i]);
1926 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1927 if (found.count() == 0) {
1928 anItem = new QListWidgetItem(aText);
1929 myElements->addItem(anItem);
1930 if (!anItem->isSelected())
1931 listItemsToSel.push_back(anItem);
1934 foreach(anItem, found)
1935 if (!anItem->isSelected())
1936 listItemsToSel.push_back(anItem);
1939 bool blocked = myElements->signalsBlocked();
1940 myElements->blockSignals(true);
1941 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1942 myElements->blockSignals(blocked);
1943 onListSelectionChanged();
1944 listItemsToSel.clear();
1948 mySelectGroup->setChecked(false);
1950 onListSelectionChanged();
1952 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1953 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1954 GEOM::GEOM_IGroupOperations_var aGroupOp =
1955 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1957 SMESH::ElementType aGroupType = SMESH::ALL;
1958 switch(aGroupOp->GetType(myGeomObjects[0])) {
1959 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
1960 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
1961 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
1962 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
1963 default: myIsBusy = false; return;
1966 if (aGroupType == aType) {
1967 _PTR(SObject) aGroupSO =
1968 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1969 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1971 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1972 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1973 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
1974 aBelongToGeom->SetGeom(myGeomObjects[0]);
1975 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1976 aBelongToGeom->SetElementType(aType);
1977 aFilter->SetPredicate(aBelongToGeom);
1979 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1981 int k = anElements->length();
1982 for (int i = 0; i < k; i++) {
1983 QString aText = QString::number(anElements[i]);
1984 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1985 if (found.count() == 0) {
1986 anItem = new QListWidgetItem(aText);
1987 myElements->addItem(anItem);
1988 if (!anItem->isSelected())
1989 listItemsToSel.push_back(anItem);
1992 foreach(anItem, found)
1993 if (!anItem->isSelected())
1994 listItemsToSel.push_back(anItem);
1997 bool blocked = myElements->signalsBlocked();
1998 myElements->blockSignals(true);
1999 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2000 myElements->blockSignals(blocked);
2001 onListSelectionChanged();
2002 listItemsToSel.clear();
2005 //VSR: mySelectGeomGroup->setChecked(false);
2007 onListSelectionChanged();
2010 if ( sizeBefore < myElements->count() )
2011 ++myNbChangesOfContents;
2012 // mySelectionMgr->clearSelected();
2016 //=================================================================================
2017 // function : onRemove()
2019 //=================================================================================
2020 void SMESHGUI_GroupDlg::onRemove()
2023 int sizeBefore = myElements->count();
2025 if (myCurrentLineEdit == 0) {
2026 QList<QListWidgetItem*> selItems = myElements->selectedItems();
2027 QListWidgetItem* item;
2028 foreach(item, selItems) delete item;
2030 SALOME_ListIO aList;
2031 mySelectionMgr->selectedObjects( aList );
2033 int aNbSel = aList.Extent();
2035 if (aNbSel == 0) { myIsBusy = false; return; }
2037 SMESH::ElementType aType = SMESH::ALL;
2039 case grpNodeSelection: aType = SMESH::NODE; break;
2040 case grp0DSelection: aType = SMESH::ELEM0D; break;
2041 case grpBallSelection: aType = SMESH::BALL; break;
2042 case grpEdgeSelection: aType = SMESH::EDGE; break;
2043 case grpFaceSelection: aType = SMESH::FACE; break;
2044 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2047 if (myCurrentLineEdit == mySubMeshLine) {
2048 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2049 SALOME_ListIO aList;
2050 mySelectionMgr->selectedObjects( aList );
2052 SALOME_ListIteratorOfListIO anIt (aList);
2053 for ( ; anIt.More(); anIt.Next()) {
2054 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2055 if (!aSubMesh->_is_nil()) {
2056 // check if mesh is the same
2057 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2058 if (aType == SMESH::NODE) {
2060 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
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);
2075 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2076 int k = anElements->length();
2077 for (int i = 0; i < k; i++) {
2078 QList<QListWidgetItem*> found =
2079 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2080 QListWidgetItem* anItem;
2081 foreach(anItem, found) delete anItem;
2084 catch (const SALOME::SALOME_Exception& ex) {
2085 SalomeApp_Tools::QtCatchCorbaException(ex);
2092 else if (myCurrentLineEdit == myGroupLine) {
2093 Standard_Boolean aRes;
2094 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2095 SALOME_ListIO aList;
2096 mySelectionMgr->selectedObjects( aList );
2098 SALOME_ListIteratorOfListIO anIt (aList);
2099 for ( ; anIt.More(); anIt.Next()) {
2100 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2101 if (aRes && !aGroup->_is_nil()) {
2102 // check if mesh is the same
2103 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2104 SMESH::long_array_var anElements = aGroup->GetListOfID();
2105 int k = anElements->length();
2106 for (int i = 0; i < k; i++) {
2107 QList<QListWidgetItem*> found =
2108 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2109 QListWidgetItem* anItem;
2110 foreach(anItem, found) delete anItem;
2118 if ( sizeBefore > myElements->count() )
2119 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2123 //=================================================================================
2124 // function : onSort()
2126 //=================================================================================
2127 void SMESHGUI_GroupDlg::onSort()
2129 // PAL5412: sorts items in ascending by "string" value
2130 // myElements->sort(true);
2131 // myElements->update();
2132 int i, k = myElements->count();
2135 QList<int> aSelected;
2136 std::vector<int> anArray(k);
2137 // QMemArray<int> anArray(k);
2139 for (i = 0; i < k; i++) {
2140 int id = myElements->item(i)->text().toInt();
2142 if (myElements->item(i)->isSelected())
2143 aSelected.append(id);
2145 // sort & update list
2146 std::sort(anArray.begin(), anArray.end());
2148 myElements->clear();
2149 QListWidgetItem* anItem;
2150 QList<QListWidgetItem*> listItemsToSel;
2151 for (i = 0; i < k; i++) {
2152 anItem = new QListWidgetItem(QString::number(anArray[i]));
2153 myElements->addItem(anItem);
2154 if (aSelected.contains(anArray[i]))
2155 listItemsToSel.push_back(anItem);
2157 bool blocked = myElements->signalsBlocked();
2158 myElements->blockSignals(true);
2159 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2160 myElements->blockSignals(blocked);
2161 listItemsToSel.clear();
2166 //=================================================================================
2167 // function : closeEvent()
2169 //=================================================================================
2170 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
2175 //=================================================================================
2176 // function : onVisibilityChanged()
2178 //=================================================================================
2179 void SMESHGUI_GroupDlg::onVisibilityChanged()
2181 SetAppropriateActor();
2184 //=================================================================================
2185 // function : SMESHGUI_GroupDlg::onClose
2186 // purpose : SLOT called when "Close" button pressed. Close dialog
2187 //=================================================================================
2188 void SMESHGUI_GroupDlg::onClose()
2190 if (SMESH::GetCurrentVtkView()) {
2191 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2192 SMESH::SetPointRepresentation(false);
2193 SMESH::SetPickable();
2194 restoreShowEntityMode();
2197 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2198 SUIT_DataOwnerPtrList aList;
2199 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2200 mySelectionMgr->setSelected( aList );
2203 mySelectionMgr->clearSelected();
2204 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2205 aViewWindow->SetSelectionMode(ActorSelection);
2206 mySelectionMgr->clearFilters();
2207 mySMESHGUI->ResetState();
2212 //=================================================================================
2213 // function : onHelp()
2215 //=================================================================================
2216 void SMESHGUI_GroupDlg::onHelp()
2218 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2220 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2224 platform = "winapplication";
2226 platform = "application";
2228 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2229 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2230 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2232 arg(myHelpFileName));
2236 //=================================================================================
2237 // function : SMESHGUI_GroupDlg::onDeactivate
2238 // purpose : SLOT called when dialog must be deativated
2239 //=================================================================================
2240 void SMESHGUI_GroupDlg::onDeactivate()
2242 mySMESHGUI->ResetState();
2246 //=================================================================================
2247 // function : SMESHGUI_GroupDlg::enterEvent
2248 // purpose : Event filter
2249 //=================================================================================
2250 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2253 mySMESHGUI->EmitSignalDeactivateDialog();
2255 mySelectionMode = grpNoSelection;
2256 setSelectionMode(myTypeId);
2257 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2258 mySMESHGUI->SetActiveDialogBox(this);
2259 mySMESHGUI->SetState(800);
2263 //=================================================================================
2264 // function : hideEvent
2265 // purpose : caused by ESC key
2266 //=================================================================================
2267 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
2269 if (!isMinimized() && !myIsBusy)
2273 //=================================================================================
2274 // function : keyPressEvent()
2276 //=================================================================================
2277 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2279 QDialog::keyPressEvent( e );
2280 if ( e->isAccepted() )
2283 if ( e->key() == Qt::Key_F1 )
2290 //================================================================================
2292 * \brief Enable showing of the popup when Geometry selection btn is clicked
2293 * \param enable - true to enable
2295 //================================================================================
2297 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2299 void SMESHGUI_GroupDlg::updateGeomPopup()
2301 bool enable = false;
2303 if ( !myMesh->_is_nil() )
2304 enable = myMesh->NbEdges() > 0;
2306 if ( myGeomGroupBtn )
2308 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2310 if ( !myGeomPopup ) {
2311 myGeomPopup = new QMenu(this);
2312 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2313 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2314 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2316 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2322 //=================================================================================
2323 // function : onGeomSelectionButton()
2325 //=================================================================================
2326 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2328 if ( myGeomPopup && isBtnOn )
2330 myCurrentLineEdit = myGeomGroupLine;
2331 QAction* a = myGeomPopup->exec( QCursor::pos() );
2332 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2333 setSelectionMode(grpGeomSelection);
2337 myCurrentLineEdit = 0;
2338 setSelectionMode(grpAllSelection);
2342 //=================================================================================
2343 // function : onGeomPopup()
2345 //=================================================================================
2346 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2348 int index = myActions[a];
2349 if ( index == GEOM_BY_MESH_INDEX )
2351 mySelectionMode = grpNoSelection;
2352 if ( !myShapeByMeshOp ) {
2353 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2354 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2355 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2356 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2357 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2359 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2360 if ( !myMesh->_is_nil() ) {
2362 hide(); // stop processing selection
2364 myShapeByMeshOp->setModule( mySMESHGUI );
2365 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2366 myShapeByMeshOp->SetMesh( myMesh );
2367 myShapeByMeshOp->start();
2372 //================================================================================
2374 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2376 //================================================================================
2378 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2380 if ( myShapeByMeshOp == op ) {
2381 mySMESHGUI->getApp()->updateObjectBrowser();
2383 // Select a found geometry object
2384 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2385 if ( !aGeomVar->_is_nil() )
2387 QString ID = aGeomVar->GetStudyEntry();
2388 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2389 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2390 SALOME_ListIO anIOList;
2391 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2392 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2393 anIOList.Append( anIO );
2394 mySelectionMgr->setSelectedObjects( anIOList, false );
2395 onObjectSelectionChanged();
2401 //================================================================================
2403 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2405 //================================================================================
2407 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2409 if ( myShapeByMeshOp == op )
2412 setSelectionMode(grpGeomSelection);
2416 //=================================================================================
2417 // function : setGroupColor()
2419 //=================================================================================
2420 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2422 QColor aQColor( (int)( theColor.R * 255.0 ),
2423 (int)( theColor.G * 255.0 ),
2424 (int)( theColor.B * 255.0 ) );
2425 setGroupQColor( aQColor );
2428 //=================================================================================
2429 // function : getGroupColor()
2431 //=================================================================================
2432 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2434 QColor aQColor = getGroupQColor();
2436 SALOMEDS::Color aColor;
2437 aColor.R = (float)aQColor.red() / 255.0;
2438 aColor.G = (float)aQColor.green() / 255.0;
2439 aColor.B = (float)aQColor.blue() / 255.0;
2444 //=================================================================================
2445 // function : setGroupQColor()
2447 //=================================================================================
2448 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2450 if( theColor.isValid() )
2451 myColorBtn->setColor( theColor );
2454 //=================================================================================
2455 // function : getGroupQColor()
2457 //=================================================================================
2458 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2460 return myColorBtn->color();
2463 //=================================================================================
2464 // function : setDefaultGroupColor()
2466 //=================================================================================
2467 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2469 if( myMesh->_is_nil() )
2472 bool isAutoColor = myMesh->GetAutoColor();
2477 int r = 0, g = 0, b = 0;
2478 SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2479 aQColor.setRgb( r, g, b );
2483 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2485 QList<SALOMEDS::Color> aReservedColors;
2486 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2488 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2489 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2490 aReservedColors.append( aReservedColor );
2493 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2494 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2495 (int)( aColor.G * 255.0 ),
2496 (int)( aColor.B * 255.0 ) );
2500 setGroupQColor( aQColor );
2503 //=================================================================================
2504 // function : SetAppropriateActor()
2505 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2506 // NPAL19389: create a group with a selection in another group.
2507 // if mesh actor is not visible - find any first visible group or submesh
2508 //=================================================================================
2509 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2511 bool isActor = false;
2512 myActorsList.clear();
2514 if (myMesh->_is_nil()) return false;
2516 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2518 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2520 if (!myGroupOnGeom->_is_nil()) {
2521 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2522 if (anActor && anActor->hasIO())
2525 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2528 myActorsList.append(anActor);
2534 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2535 if (anActor && anActor->hasIO()) {
2537 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2540 myActorsList.append(anActor);
2544 if (!isActor && !myGroup->_is_nil()) {
2545 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2546 if (anActor && anActor->hasIO())
2547 myActorsList.append(anActor);
2550 // try any visible actor of group or submesh of current mesh
2553 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2555 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2556 int len = strlen(meshEntry);
2558 // iterate on all actors in current view window, search for
2559 // any visible actor, that belongs to group or submesh of current mesh
2560 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2561 vtkActorCollection *aCollection = aCopy.GetActors();
2562 int nbItems = aCollection->GetNumberOfItems();
2563 for (int i=0; i<nbItems && !isActor; i++)
2565 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2566 if (anActor && anActor->hasIO()) {
2567 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2568 if (aViewWindow->isVisible(anIO)) {
2569 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2570 myActorsList.append(anActor);
2578 if (myActorsList.count() > 0) {
2579 QListIterator<SMESH_Actor*> it( myActorsList );
2580 while ( it.hasNext() ) {
2581 SMESH_Actor* anActor = it.next();
2582 if ( IsActorVisible(anActor) )
2583 anActor->SetPickable(true);
2587 return ( isActor || (myActorsList.count() > 0) );
2590 //=======================================================================
2591 //function : setShowEntityMode
2592 //purpose : make shown only entity corresponding to my type
2593 //=======================================================================
2594 void SMESHGUI_GroupDlg::setShowEntityMode()
2596 if ( !myMesh->_is_nil() ) {
2597 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2598 if (!myStoredShownEntity)
2599 myStoredShownEntity = actor->GetEntityMode();
2600 switch ( myTypeId ) {
2601 case grpNodeSelection: restoreShowEntityMode(); break;
2602 case grp0DSelection: actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
2603 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2604 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2605 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2606 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2612 //=======================================================================
2613 //function : restoreShowEntityMode
2614 //purpose : restore ShowEntity mode of myActor
2615 //=======================================================================
2616 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2618 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2619 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2620 actor->SetEntityMode(myStoredShownEntity);
2623 myStoredShownEntity = 0;
2626 //=======================================================================
2627 //function : IsActorVisible
2628 //purpose : return visibility of the actor
2629 //=======================================================================
2630 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2632 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2633 if (theActor && aViewWindow)
2634 return aViewWindow->isVisible(theActor->getIO());
2638 //================================================================
2639 //function : setIsApplyAndClose
2640 //purpose : Set value of the flag indicating that the dialog is
2641 // accepted by Apply & Close button
2642 //================================================================
2643 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2645 myIsApplyAndClose = theFlag;
2648 //================================================================
2649 //function : isApplyAndClose
2650 //purpose : Get value of the flag indicating that the dialog is
2651 // accepted by Apply & Close button
2652 //================================================================
2653 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2655 return myIsApplyAndClose;