1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_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>
47 #include <GEOM_wrap.hxx>
49 // SALOME GUI includes
50 #include <QtxColorButton.h>
52 #include <SUIT_Desktop.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SUIT_Session.h>
55 #include <SUIT_MessageBox.h>
56 #include <SUIT_OverrideCursor.h>
58 #include <SalomeApp_Tools.h>
59 #include <SalomeApp_Application.h>
60 #include <SalomeApp_Study.h>
61 #include <LightApp_SelectionMgr.h>
63 #include <SALOME_ListIO.hxx>
65 #include <SVTK_ViewWindow.h>
67 #include <VTKViewer_Algorithm.h>
69 // SALOME KERNEL includes
70 #include <SALOMEDSClient_Study.hxx>
73 #include <vtkRenderer.h>
74 #include <vtkActorCollection.h>
77 #include <TColStd_MapOfInteger.hxx>
80 #include <QButtonGroup>
84 #include <QPushButton>
85 #include <QToolButton>
86 #include <QRadioButton>
88 #include <QGridLayout>
89 #include <QHBoxLayout>
90 #include <QVBoxLayout>
91 #include <QListWidget>
92 #include <QStackedWidget>
104 enum grpSelectionMode {
106 grpNodeSelection = 0,
108 grpBallSelection = 2,
109 grpEdgeSelection = 3,
110 grpFaceSelection = 4,
111 grpVolumeSelection = 5,
112 grpSubMeshSelection = 6,
113 grpGroupSelection = 7,
114 grpMeshSelection = 8,
115 grpGeomSelection = 9,
116 grpAllSelection = 10,
119 //=================================================================================
120 // function : SMESHGUI_GroupDlg()
122 //=================================================================================
123 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
124 SMESH::SMESH_Mesh_ptr theMesh )
125 : QDialog( SMESH::GetDesktop( theModule ) ),
126 mySMESHGUI( theModule ),
127 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
128 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
130 myNameChanged( false ),
131 myIsApplyAndClose( false ),
132 myNbChangesOfContents(0)
135 if ( !theMesh->_is_nil() )
139 mySelectSubMesh->setEnabled( false );
140 mySelectGroup->setEnabled( false );
141 myGeomGroupBtn->setEnabled( false );
142 myGeomGroupLine->setEnabled( false );
146 //=================================================================================
147 // function : SMESHGUI_GroupDlg()
149 //=================================================================================
150 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
151 SMESH::SMESH_GroupBase_ptr theGroup,
152 const bool theIsConvert )
153 : QDialog( SMESH::GetDesktop( theModule ) ),
154 mySMESHGUI( theModule ),
155 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
156 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
158 myNameChanged( false ),
159 myNbChangesOfContents(0) // just not to use uninitialized variable
162 if ( !theGroup->_is_nil() )
163 init( theGroup, theIsConvert );
166 mySelectSubMesh->setEnabled( false );
167 mySelectGroup->setEnabled( false );
169 myCurrentLineEdit = myMeshGroupLine;
170 setSelectionMode( grpGroupSelection );
174 //=================================================================================
175 // function : SMESHGUI_GroupDlg()
177 //=================================================================================
178 void SMESHGUI_GroupDlg::initDialog( bool create)
181 setAttribute( Qt::WA_DeleteOnClose, true );
185 myCurrentLineEdit = 0;
189 myGeomObjects = new GEOM::ListOfGO();
190 myGeomObjects->length( 0 );
192 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
194 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
195 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
197 setSizeGripEnabled( true);
199 QGridLayout* aMainLayout = new QGridLayout( this );
200 aMainLayout->setMargin( MARGIN );
201 aMainLayout->setSpacing( SPACING );
203 /***************************************************************/
204 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
205 myMeshGroupBtn = new QPushButton( this );
206 myMeshGroupBtn->setIcon( image0 );
207 myMeshGroupLine = new QLineEdit( this );
208 myMeshGroupLine->setReadOnly( true );
210 /***************************************************************/
211 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
212 myTypeGroup = new QButtonGroup( this );
213 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
214 aTypeBoxLayout->setMargin( MARGIN );
215 aTypeBoxLayout->setSpacing( SPACING );
218 types.append( tr( "MESH_NODE" ) );
219 types.append( tr( "SMESH_ELEM0D" ) );
220 types.append( tr( "SMESH_BALL_ELEM" ) );
221 types.append( tr( "SMESH_EDGE" ) );
222 types.append( tr( "SMESH_FACE" ) );
223 types.append( tr( "SMESH_VOLUME" ) );
225 for ( int i = 0; i < types.count(); i++ )
227 rb = new QRadioButton( types[i], aTypeBox );
228 myTypeGroup->addButton( rb, i );
229 aTypeBoxLayout->addWidget( rb );
231 aTypeBox->setEnabled( create );
234 /***************************************************************/
235 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
236 aName->setMinimumWidth( 50 );
237 myName = new QLineEdit( this );
239 /***************************************************************/
240 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
241 myGrpTypeGroup = new QButtonGroup( this );
242 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
243 aGrpTypeBoxLayout->setMargin( MARGIN );
244 aGrpTypeBoxLayout->setSpacing( SPACING );
246 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
247 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
248 QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox );
249 myGrpTypeGroup->addButton( rb1, 0 );
250 myGrpTypeGroup->addButton( rb2, 1 );
251 myGrpTypeGroup->addButton( rb3, 2 );
252 aGrpTypeBoxLayout->addWidget( rb1 );
253 aGrpTypeBoxLayout->addWidget( rb2 );
254 aGrpTypeBoxLayout->addWidget( rb3 );
255 aGrpTypeBox->setEnabled( create );
258 /***************************************************************/
259 myWGStack = new QStackedWidget( this );
260 QWidget* wg1 = new QWidget( myWGStack );
261 QWidget* wg2 = new QWidget( myWGStack );
262 QWidget* wg3 = new QWidget( myWGStack );
264 /***************************************************************/
265 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
266 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
267 aContentBoxLayout->setMargin( MARGIN );
268 aContentBoxLayout->setSpacing( SPACING );
270 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
271 myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
273 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
274 myElements = new QListWidget( aContentBox );
275 myElements->setSelectionMode( QListWidget::ExtendedSelection );
277 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
278 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
279 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
280 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
282 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
283 aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
284 aContentBoxLayout->addWidget( myFilterBtn, 1, 1 );
285 aContentBoxLayout->addWidget( myElementsLab, 2, 0 );
286 aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 );
287 aContentBoxLayout->addWidget( myAddBtn, 3, 1 );
288 aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 );
289 aContentBoxLayout->addWidget( mySortBtn, 8, 1 );
291 aContentBoxLayout->setColumnStretch( 0, 1 );
292 aContentBoxLayout->setRowStretch( 3, 1 );
293 aContentBoxLayout->setRowStretch( 6, 1 );
295 /***************************************************************/
296 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
297 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
298 mySelectBoxLayout->setMargin( MARGIN );
299 mySelectBoxLayout->setSpacing( SPACING );
301 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
302 mySubMeshBtn = new QPushButton( mySelectBox );
303 mySubMeshBtn->setIcon( image0 );
304 mySubMeshLine = new QLineEdit( mySelectBox );
305 mySubMeshLine->setReadOnly( true );
306 onSelectSubMesh( false );
308 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
309 myGroupBtn = new QPushButton( mySelectBox );
310 myGroupBtn->setIcon( image0 );
311 myGroupLine = new QLineEdit( mySelectBox );
312 myGroupLine->setReadOnly( true );
313 onSelectGroup( false );
315 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
316 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
317 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
318 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
319 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
320 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
322 /***************************************************************/
323 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
324 wg1Layout->setMargin( 0 );
325 wg1Layout->setSpacing( SPACING );
326 wg1Layout->addWidget( aContentBox );
327 wg1Layout->addWidget( mySelectBox );
328 wg1Layout->setStretchFactor( aContentBox, 10 );
330 /***************************************************************/
331 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
332 myGeomGroupBtn = new QToolButton( wg2 );
333 myGeomGroupBtn->setIcon( image0 );
334 myGeomGroupBtn->setCheckable( true );
335 myGeomGroupLine = new QLineEdit( wg2 );
336 myGeomGroupLine->setReadOnly( true ); //VSR ???
337 onSelectGeomGroup( false );
339 myGeomGroupBtn->setEnabled( create );
340 myGeomGroupLine->setEnabled( create );
342 /***************************************************************/
343 QGridLayout* wg2Layout = new QGridLayout( wg2 );
344 wg2Layout->setMargin( 0 );
345 wg2Layout->setSpacing( SPACING );
346 wg2Layout->addWidget( geomObject, 0, 0 );
347 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
348 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
349 wg2Layout->setRowStretch( 1, 5 );
351 /***************************************************************/
352 QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
353 QGridLayout* wg3Layout = new QGridLayout( wg3 );
354 wg3Layout->setMargin( 0 );
355 wg3Layout->setSpacing( SPACING );
356 wg3Layout->addWidget( aFilter2, 0, 0 );
357 wg3Layout->setRowStretch( 1, 5 );
359 /***************************************************************/
360 myWGStack->insertWidget( 0, wg1 );
361 myWGStack->insertWidget( 1, wg2 );
362 myWGStack->insertWidget( 2, wg3 );
364 /***************************************************************/
365 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
366 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
367 aColorBoxLayout->setMargin(MARGIN);
368 aColorBoxLayout->setSpacing(SPACING);
370 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
371 myColorBtn = new QtxColorButton(aColorBox);
372 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
373 myColorBtn->sizePolicy().verticalPolicy() );
375 aColorBoxLayout->addWidget(aColorLab);
376 aColorBoxLayout->addWidget(myColorBtn);
378 /***************************************************************/
380 QFrame* aButtons = new QFrame(this);
381 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
382 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
383 aBtnLayout->setMargin(MARGIN);
384 aBtnLayout->setSpacing(SPACING);
386 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
387 myOKBtn->setAutoDefault(true);
388 myOKBtn->setDefault(true);
389 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
390 myApplyBtn->setAutoDefault(true);
391 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
392 myCloseBtn->setAutoDefault(true);
393 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
394 myHelpBtn->setAutoDefault(true);
396 aBtnLayout->addWidget(myOKBtn);
397 aBtnLayout->addSpacing(10);
398 aBtnLayout->addWidget(myApplyBtn);
399 aBtnLayout->addSpacing(10);
400 aBtnLayout->addStretch();
401 aBtnLayout->addWidget(myCloseBtn);
402 aBtnLayout->addWidget(myHelpBtn);
404 /***************************************************************/
405 aMainLayout->addWidget(meshGroupLab, 0, 0);
406 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
407 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
408 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
409 aMainLayout->addWidget(aName, 2, 0);
410 aMainLayout->addWidget(myName, 2, 2);
411 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
412 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
413 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
414 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
416 /* signals and slots connections */
417 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
418 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
419 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
421 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
422 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
424 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
425 connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters()));
426 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
427 connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
428 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
429 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
430 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
432 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
433 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
434 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
435 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
436 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
438 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
440 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
441 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
442 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
443 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
446 mySMESHGUI->SetActiveDialogBox(this);
447 mySMESHGUI->SetState(800);
449 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
450 mySelectionMode = grpNoSelection;
452 myMeshFilter = new SMESH_TypeFilter(SMESH::MESH);
453 mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
454 SMESH_LogicalFilter::LO_OR,
455 /*takeOwnership=*/true);
456 myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
457 SMESH_LogicalFilter::LO_OR,
458 /*takeOwnership=*/true);
459 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
461 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
462 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
463 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
464 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
466 rb1->setChecked(true); // VSR !!!
467 onGrpTypeChanged(0); // VSR!!!
469 if (myMesh->_is_nil() )
470 myTypeGroup->button(0)->setChecked(true);
472 onSelectAll(); //updateButtons();
475 //=================================================================================
476 // function : ~SMESHGUI_GroupDlg()
477 // purpose : Destroys the object and frees any allocated resources
478 //=================================================================================
479 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
481 // no need to delete child widgets, Qt does it all for us
482 if ( myFilterDlg != 0 ) {
483 myFilterDlg->setParent( 0 );
486 if ( myMeshFilter ) delete myMeshFilter;
487 if ( mySubMeshFilter ) delete mySubMeshFilter;
488 if ( myGroupFilter ) delete myGroupFilter;
489 if ( myGeomFilter ) delete myGeomFilter;
492 //=================================================================================
493 // function : GetDefaultName()
494 // purpose : Get the Group Name if Create new Group
495 //=================================================================================
496 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
500 // collect all object names of SMESH component
501 SalomeApp_Study* appStudy =
502 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
503 if ( !appStudy ) return aName;
504 _PTR(Study) aStudy = appStudy->studyDS();
506 std::set<std::string> aSet;
507 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
509 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
511 for (it->InitEx(true); it->More(); it->Next()) {
513 aSet.insert(obj->GetName());
517 // build a unique name
519 bool isUnique = false;
521 aName = theOperation + "_" + QString::number(++aNumber);
522 isUnique = (aSet.count(aName.toUtf8().data()) == 0);
528 void SMESHGUI_GroupDlg::setDefaultName() const
531 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
533 QString aPrefix ="Group_";
537 aResName = aPrefix + QString::number( i++ );
538 anObj = aStudy->FindObject( aResName.toUtf8().data() );
541 myName->setText(aResName);
544 //=================================================================================
547 //=================================================================================
548 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
550 mySelectionMgr->installFilter(myMeshFilter);
552 /* init data from current selection */
553 restoreShowEntityMode();
554 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
556 myGroup = SMESH::SMESH_Group::_nil();
557 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
558 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
560 // NPAL19389: create a group with a selection in another group
561 // set actor of myMesh, if it is visible, else try
562 // any visible actor of group or submesh of myMesh
563 SetAppropriateActor();
565 setDefaultGroupColor();
570 mySelectionMgr->selectedObjects( aList );
571 if( !aList.IsEmpty() )
573 QString aName = aList.First()->getName();
574 myMeshGroupLine->setText(aName);//??????
575 myMeshGroupLine->home( false );
578 myCurrentLineEdit = 0;
580 myTypeGroup->button(0)->setChecked(true);
584 //=================================================================================
587 //=================================================================================
588 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
589 const bool theIsConvert)
591 restoreShowEntityMode();
592 myMesh = theGroup->GetMesh();
595 myNameChanged = true;
596 myName->blockSignals(true);
597 myName->setText(QString::fromUtf8(theGroup->GetName()));
598 myName->blockSignals(false);
601 SALOMEDS::Color aColor = theGroup->GetColor();
602 setGroupColor( aColor );
604 myMeshGroupLine->setText(QString::fromUtf8(theGroup->GetName()));
607 switch(theGroup->GetType()) {
608 case SMESH::NODE: aType = grpNodeSelection; break;
609 case SMESH::ELEM0D: aType = grp0DSelection; break;
610 case SMESH::BALL: aType = grpBallSelection; break;
611 case SMESH::EDGE: aType = grpEdgeSelection; break;
612 case SMESH::FACE: aType = grpFaceSelection; break;
613 case SMESH::VOLUME: aType = grpVolumeSelection; break;
615 myTypeGroup->button(aType)->setChecked(true);
617 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
618 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
619 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
620 myFilter = SMESH::Filter::_nil();
622 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
625 // NPAL19389: create a group with a selection in another group
626 // set actor of myMesh, if it is visible, else set
627 // actor of theGroup, if it is visible, else try
628 // any visible actor of group or submesh of myMesh
629 // commented, because an attempt to set selection on not displayed cells leads to error
630 SetAppropriateActor();
632 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
634 anActor = SMESH::FindActorByObject(theGroup);
635 SMESH::SetPickable(anActor);*/
637 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
638 myGrpTypeGroup->button(grpType)->setChecked(true);
639 onGrpTypeChanged(grpType);
642 if ( grpType == 0 ) { // standalone group
643 myCurrentLineEdit = 0;
645 myAllowElemsModif->setChecked( true );
647 setSelectionMode(aType);
649 setShowEntityMode(); // depends on myTypeId
652 if (!theGroup->IsEmpty()) {
653 SMESH::long_array_var anElements = theGroup->GetListOfID();
654 int k = anElements->length();
655 for (int i = 0; i < k; i++) {
656 myIdList.append(anElements[i]);
657 myElements->addItem(QString::number(anElements[i]));
659 myElements->selectAll();
662 else if ( grpType == 1 ) // group on geom
664 QString aShapeName( "" );
665 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
666 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
667 if (!aGroupShape->_is_nil())
669 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
671 aShapeName = aGroupShapeSO->GetName().c_str();
673 myGeomGroupLine->setText( aShapeName );
675 else // group on filter
677 myFilter = myGroupOnFilter->GetFilter();
678 if ( !myFilter->_is_nil() ) {
679 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
680 if ( perdicate->_is_nil() )
681 myFilter = SMESH::Filter::_nil();
687 myNameChanged = true;
688 myName->blockSignals(true);
689 myName->setText(QString::fromUtf8(theGroup->GetName()));
690 myName->blockSignals(false);
693 onSelectAll(); //updateButtons();
696 //=================================================================================
697 // function : updateButtons()
699 //=================================================================================
700 void SMESHGUI_GroupDlg::updateButtons()
702 bool enable = !myName->text().trimmed().isEmpty();
705 if (myGrpTypeId == 0) { // standalone
706 if ( !mySelectAll->isChecked() )
708 if ( myAllowElemsModif->isChecked() )
710 enable = ( myElements->count() > 0 );
712 else if ((enable = !myFilter->_is_nil() ))
714 SMESH::array_of_ElementType_var types = myFilter->GetTypes();
715 enable = types->length();
718 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
720 else if (myGrpTypeId == 1) // on geom
722 if (CORBA::is_nil(myGroupOnGeom)) // creation mode
723 enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
725 else if (myGrpTypeId == 2) // on filter
727 if (( enable = !myFilter->_is_nil() ))
728 if (CORBA::is_nil(myGroupOnFilter) ) // creation mode
729 enable = !myMesh->_is_nil();
733 myOKBtn->setEnabled(enable);
734 myApplyBtn->setEnabled(enable);
737 //=================================================================================
738 // function : onNameChanged()
740 //=================================================================================
741 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
743 myOldName = myName->text();
745 myNameChanged = !myName->text().trimmed().isEmpty();
748 //=================================================================================
749 // function : onTypeChanged()
750 // purpose : Group elements type radio button management
751 //=================================================================================
752 void SMESHGUI_GroupDlg::onTypeChanged (int id)
754 if (myTypeId != id) {
757 if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
758 setSelectionMode(id);
760 setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
762 onObjectSelectionChanged();
767 //=================================================================================
768 // function : onGrpTypeChanged()
769 // purpose : Group type radio button management
770 //=================================================================================
771 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
773 if (myGrpTypeId != id) {
775 myWGStack->setCurrentIndex( id );
776 myName->blockSignals(true);
777 myName->setText(myOldName);
778 myName->blockSignals(false);
779 onSelectGeomGroup(id != 0);
784 //=================================================================================
785 // function : onColorChanged()
786 // purpose : Color button management
787 //=================================================================================
788 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
793 //=================================================================================
794 // function : setSelectionMode()
795 // purpose : Radio button management
796 //=================================================================================
797 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
800 if (myMesh->_is_nil())
802 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
803 bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
804 if (mySelectionMode != theMode) {
805 // [PAL10408] mySelectionMgr->clearSelected();
806 mySelectionMgr->clearFilters();
807 SMESH::RemoveFilters();
809 if (myActorsList.count() > 0)
810 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
811 it.next()->SetPointRepresentation(false);
813 SMESH::SetPointRepresentation(false);
816 case grpNodeSelection:
817 if ( myGrpTypeId == 0 ) // standalone
819 if (myActorsList.count() > 0)
820 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
821 it.next()->SetPointRepresentation(true);
823 SMESH::SetPointRepresentation(true);
825 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
827 case grpEdgeSelection:
828 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
830 case grpBallSelection:
831 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
834 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : Elem0DSelection);
836 case grpFaceSelection:
837 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
839 case grpVolumeSelection:
840 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
842 case grpSubMeshSelection: {
844 SMESH_TypeFilter* f = 0;
846 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH); break;
847 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_EDGE); break;
848 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_FACE); break;
849 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_SOLID); break;
850 default: f = new SMESH_TypeFilter(SMESH::SUBMESH);
852 QList<SUIT_SelectionFilter*> filtList;
853 filtList.append( f );
854 filtList.append( new SMESH_TypeFilter(SMESH::SUBMESH_COMPOUND));
855 mySubMeshFilter->setFilters( filtList );
857 mySelectionMgr->installFilter( mySubMeshFilter );
859 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
862 case grpGroupSelection: {
864 SMESH_TypeFilter* f = 0;
866 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_NODE); break;
867 case grp0DSelection: f = new SMESH_TypeFilter(SMESH::GROUP_0D); break;
868 case grpBallSelection: f = new SMESH_TypeFilter(SMESH::GROUP_BALL); break;
869 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_EDGE); break;
870 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::GROUP_FACE); break;
871 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_VOLUME); break;
872 default: f = new SMESH_TypeFilter(SMESH::GROUP);
874 QList<SUIT_SelectionFilter*> filtList;
875 filtList.append( f );
876 myGroupFilter->setFilters( filtList );
878 mySelectionMgr->installFilter(myGroupFilter);
879 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
882 case grpMeshSelection:
883 mySelectionMgr->installFilter(myMeshFilter);
884 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
886 case grpGeomSelection:
887 mySelectionMgr->installFilter(myGeomFilter);
888 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
891 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
894 if ( aViewWindow ) aViewWindow->Repaint();
895 mySelectionMode = theMode;
899 //=================================================================================
900 // function : onApply()
902 //=================================================================================
903 bool SMESHGUI_GroupDlg::onApply()
905 if (mySMESHGUI->isActiveStudyLocked())
908 if (myName->text().trimmed().isEmpty())
911 SMESH::ElementType aType = SMESH::ALL;
913 case grpNodeSelection: aType = SMESH::NODE; break;
914 case grp0DSelection: aType = SMESH::ELEM0D; break;
915 case grpBallSelection: aType = SMESH::BALL; break;
916 case grpEdgeSelection: aType = SMESH::EDGE; break;
917 case grpFaceSelection: aType = SMESH::FACE; break;
918 case grpVolumeSelection: aType = SMESH::VOLUME; break;
922 QStringList anEntryList;
924 SMESH::SMESH_GroupBase_var resultGroup;
925 bool isCreation, isConversion = false;
927 SUIT_OverrideCursor wc;
929 if (myGrpTypeId == 0) // standalone
931 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
934 mySelectionMgr->clearSelected();
936 if (myGroup->_is_nil()) { // creation or conversion
937 // check if group on geometry is not null
938 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
939 if (myMesh->_is_nil())
941 if ( myGroupOnGeom->_is_nil() )
942 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
944 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
946 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
947 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
952 if (myGroup->_is_nil()) { // creation
953 if (myMesh->_is_nil())
956 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
958 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
961 if ( mySelectAll->isChecked() ) {
963 myGroup->AddFrom(myMesh.in());
968 if ( !myFilter->_is_nil() &&
969 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
971 myGroup->AddFrom( myFilter );
975 SMESH::long_array_var anIdList = new SMESH::long_array;
976 int i, k = myElements->count();
978 for (i = 0; i < k; i++) {
979 anIdList[i] = myElements->item(i)->text().toInt();
981 myGroup->Add(anIdList.inout());
988 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
991 if ( mySelectAll->isChecked() ) {
994 myGroup->AddFrom(myMesh.in());
999 int i, total = myElements->count();
1000 for (i = 0; i < total; i++) {
1001 int anId = myElements->item(i)->text().toInt();
1002 int idx = myIdList.indexOf(anId);
1004 aAddList.append(anId);
1006 myIdList.removeAt(idx);
1008 if (!aAddList.empty()) {
1009 SMESH::long_array_var anIdList = new SMESH::long_array;
1010 int added = aAddList.count();
1011 anIdList->length(added);
1012 for (i = 0; i < added; i++)
1013 anIdList[i] = aAddList[i];
1014 myGroup->Add(anIdList.inout());
1016 if (!myIdList.empty()) {
1017 SMESH::long_array_var anIdList = new SMESH::long_array;
1018 int removed = myIdList.count();
1019 anIdList->length(removed);
1020 for (i = 0; i < removed; i++)
1021 anIdList[i] = myIdList[i];
1022 myGroup->Remove(anIdList.inout());
1024 /* init for next operation */
1026 for (i = 0; i < total; i++) {
1027 myIdList.append(myElements->item(i)->text().toInt());
1034 else if (myGrpTypeId == 1) // on geom object
1036 if (CORBA::is_nil(myGroupOnGeom)) { // creation
1037 if (myMesh->_is_nil() || !myGeomObjects->length())
1040 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1042 if (myGeomObjects->length() == 1) {
1043 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1044 myName->text().toUtf8().data(),
1048 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1049 if ( aSMESHGen->_is_nil() )
1052 // create a geometry group
1053 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1054 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1056 if (geomGen->_is_nil() || !aStudy)
1059 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
1063 // check and add all selected GEOM objects: they must be
1064 // a sub-shapes of the main GEOM and must be of one type
1065 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1066 for ( int i =0; i < myGeomObjects->length(); i++) {
1067 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1069 aGroupType = aSubShapeType;
1070 else if (aSubShapeType != aGroupType) {
1071 aGroupType = TopAbs_SHAPE;
1076 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1077 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1078 op->UnionList(aGroupVar, myGeomObjects);
1081 // publish the GEOM group in study
1082 QString aNewGeomGroupName ( "Auto_group_for_" );
1083 aNewGeomGroupName += myName->text();
1084 SALOMEDS::SObject_var aNewGroupSO =
1085 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
1086 aNewGeomGroupName.toUtf8().data(), aMeshShape);
1089 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1090 myName->text().toUtf8().data(),
1093 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1099 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1104 if (myGrpTypeId == 2) // group on filter
1106 if ( myFilter->_is_nil() ) return false;
1108 if (CORBA::is_nil(myGroupOnFilter)) { // creation
1109 if (myMesh->_is_nil())
1112 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1113 myName->text().toUtf8().data(),
1116 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1121 myGroupOnFilter->SetFilter( myFilter );
1123 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1131 SALOMEDS::Color aColor = getGroupColor();
1132 resultGroup->SetColor(aColor);
1134 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1136 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1140 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1142 /* init for the next operation */
1144 myElements->clear();
1145 myGroup = SMESH::SMESH_Group::_nil();
1146 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1147 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1148 myFilter = SMESH::Filter::_nil();
1150 setDefaultGroupColor(); // reset color for case if 'auto-color' feature is enabled.
1154 resultGroup->SetName(myName->text().toUtf8().data());
1158 if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
1160 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1161 if ( isConversion ) { // need to reset TVisualObj and actor
1162 SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
1163 SMESH::Update( anIO,true);
1164 myActorsList.clear();
1165 anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1166 if ( !anActor ) return false;
1167 myActorsList.append( anActor );
1169 anActor->setName(myName->text().toUtf8().data());
1172 switch ( myTypeId ) {
1173 case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1174 case grp0DSelection: anActor->Set0DColor ( aColor.R, aColor.G, aColor.B ); break;
1175 case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1176 case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1177 case grpVolumeSelection:
1178 SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
1179 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1181 case grpFaceSelection:
1183 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1184 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1187 // update a visible group accoding to a changed contents
1188 if ( !isConversion && anActor->GetVisibility() )
1189 SMESH::Update( anIO, true );
1193 SMESHGUI::Modified();
1194 mySMESHGUI->updateObjBrowser(true);
1195 mySelectionMgr->clearSelected();
1197 if( LightApp_Application* anApp =
1198 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1199 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1204 //=================================================================================
1205 // function : onOK()
1207 //=================================================================================
1208 void SMESHGUI_GroupDlg::onOK()
1210 setIsApplyAndClose( true );
1213 setIsApplyAndClose( false );
1215 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
1218 //=================================================================================
1219 // function : onListSelectionChanged()
1220 // purpose : Called when selection in element list is changed
1221 //=================================================================================
1222 void SMESHGUI_GroupDlg::onListSelectionChanged()
1224 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1225 if( myIsBusy || myActorsList.count() == 0 ) return;
1228 if (myCurrentLineEdit == 0) {
1229 mySelectionMgr->clearSelected();
1230 TColStd_MapOfInteger aIndexes;
1231 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1232 QListWidgetItem* anItem;
1233 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1234 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1235 SALOME_ListIO aList;
1236 aList.Append(myActorsList.first()->getIO());
1237 mySelectionMgr->setSelectedObjects(aList,false);
1242 //=================================================================================
1243 // function : onObjectSelectionChanged()
1244 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1245 //=================================================================================
1246 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1248 if ( myIsBusy || !isEnabled()) return;
1249 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1253 SALOME_ListIO aList;
1254 mySelectionMgr->selectedObjects( aList );
1256 int aNbSel = aList.Extent();
1257 myElements->clearSelection();
1259 if (myCurrentLineEdit)
1261 myCurrentLineEdit->setText( "" );
1262 QString aString = "";
1264 if (myCurrentLineEdit == myMeshGroupLine)
1266 mySelectSubMesh->setEnabled(false);
1267 mySelectGroup->setEnabled(false);
1268 myGroupLine->setText( "" );
1269 mySubMeshLine->setText( "" );
1271 myGeomGroupBtn->setEnabled(false);
1272 myGeomGroupLine->setEnabled(false);
1273 myGeomGroupLine->setText( "" );
1274 myGeomObjects = new GEOM::ListOfGO();
1275 myGeomObjects->length(0);
1277 if (myGeomGroupBtn->isChecked())
1278 myGeomGroupBtn->setChecked(false);
1280 myName->setText( "" );
1282 myElements->clear();
1285 myGroup = SMESH::SMESH_Group::_nil();
1286 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1287 restoreShowEntityMode();
1288 myMesh = SMESH::SMESH_Mesh::_nil();
1294 Handle(SALOME_InteractiveObject) IO = aList.First();
1297 restoreShowEntityMode();
1298 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1299 setShowEntityMode();
1301 if (myMesh->_is_nil())
1308 if ( myFilterDlg && !myMesh->_is_nil()){
1309 myFilterDlg->SetMesh( myMesh );
1311 myGroup = SMESH::SMESH_Group::_nil();
1313 // NPAL19389: create a group with a selection in another group
1314 // set actor of myMesh, if it is visible, else try
1315 // any visible actor of group or submesh of myMesh
1316 SetAppropriateActor();
1318 aString = aList.First()->getName();
1319 myMeshGroupLine->setText(aString);
1320 myMeshGroupLine->home( false );
1322 mySelectSubMesh->setEnabled(true);
1323 mySelectGroup->setEnabled(true);
1324 myGeomGroupBtn->setEnabled(true);
1325 myGeomGroupLine->setEnabled(true);
1329 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1330 if (aGroup->_is_nil())
1337 myGroup = SMESH::SMESH_Group::_nil();
1338 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1342 mySelectSubMesh->setEnabled(true);
1343 mySelectGroup->setEnabled(true);
1345 myCurrentLineEdit = 0;
1350 if (myGrpTypeId == 0)
1356 myElements->clear();
1357 setSelectionMode(myTypeId);
1365 else if (myCurrentLineEdit == myGeomGroupLine)
1367 myGeomObjects = new GEOM::ListOfGO();
1370 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1372 if (aNbSel == 0 || !aMeshSO)
1374 myGeomObjects->length(0);
1380 myGeomObjects->length(aNbSel);
1382 GEOM::GEOM_Object_var aGeomGroup;
1385 SALOME_ListIteratorOfListIO anIt (aList);
1386 for (; anIt.More(); anIt.Next())
1388 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1390 // Check if the object is a geometry group
1391 if (CORBA::is_nil(aGeomGroup))
1394 // Check if group constructed on the same shape as a mesh or on its child
1395 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1397 // The main shape of the group
1398 GEOM::GEOM_Object_var aGroupMainShape;
1399 if (aGeomGroup->GetType() == 37) {
1400 GEOM::GEOM_IGroupOperations_wrap anOp =
1401 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1402 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1403 // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
1406 aGroupMainShape = aGeomGroup;
1407 aGroupMainShape->Register();
1409 _PTR(SObject) aGroupMainShapeSO =
1410 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1412 _PTR(SObject) anObj, aRef;
1413 bool isRefOrSubShape = false;
1414 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1415 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1416 isRefOrSubShape = true;
1418 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1419 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1420 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1421 if (aRef->GetID() == aFather->GetID())
1422 isRefOrSubShape = true;
1424 aFather = aFather->GetFather();
1428 if (isRefOrSubShape)
1429 myGeomObjects[i++] = aGeomGroup;
1432 myGeomObjects->length(i);
1444 if (myCurrentLineEdit == mySubMeshLine)
1445 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1446 else if (myCurrentLineEdit == myGroupLine)
1447 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1448 else if (myCurrentLineEdit == myGeomGroupLine)
1449 aString = tr( "%1 Objects" ).arg(aNbSel);
1452 aString = aList.First()->getName();
1456 myCurrentLineEdit->setText(aString);
1457 myCurrentLineEdit->home(false);
1458 // 07.06.2008 skl for IPAL19574:
1459 // change name of group only if it is empty
1460 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1461 myOldName = myName->text();
1462 myName->blockSignals(true);
1463 myName->setText(aString);
1464 myName->blockSignals(false);
1469 else // !myCurrentLineEdit: local selection of nodes or elements
1471 if (aNbSel == 1 && myActorsList.count() > 0 )
1473 // NPAL19389: create a group with a selection in another group
1474 // Switch myActor to the newly selected one, if the last
1475 // is visible and belongs to group or submesh of myMesh
1476 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1477 Handle(SALOME_InteractiveObject) selIO = aList.First();
1478 if (curIO->hasEntry() && selIO->hasEntry()) {
1479 const char* selEntry = selIO->getEntry();
1480 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1481 // different objects: selected and myActor
1482 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1483 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1484 // newly selected actor is visible
1487 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1489 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1490 int len = strlen(meshEntry);
1492 if (strncmp(selEntry, meshEntry, len) == 0) {
1493 // selected object is myMesh or a part of it
1494 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1497 SMESH::SetPickable(myActor);
1506 QString aListStr = "";
1508 if (myTypeId == 0) {
1509 QListIterator<SMESH_Actor*> it( myActorsList );
1510 while ( it.hasNext() ) {
1512 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1516 QListIterator<SMESH_Actor*> it( myActorsList );
1517 while ( it.hasNext() ) {
1519 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1524 QListWidgetItem* anItem;
1525 QList<QListWidgetItem*> listItemsToSel;
1526 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1527 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1528 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1529 foreach(anItem, found)
1530 if (!anItem->isSelected())
1531 listItemsToSel.push_back(anItem);
1533 bool blocked = myElements->signalsBlocked();
1534 myElements->blockSignals(true);
1535 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1536 myElements->blockSignals(blocked);
1537 onListSelectionChanged();
1538 listItemsToSel.clear();
1543 if (myActorsList.count() == 0) {
1544 if (!myGroup->_is_nil()) {
1545 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1547 myActorsList.append( anActor );
1549 else if(!myGroupOnGeom->_is_nil()) {
1550 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1552 myActorsList.append( anActor );
1555 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1557 myActorsList.append( anActor );
1561 // somehow, if we display the mesh, while selecting from another actor,
1562 // the mesh becomes pickable, and there is no way to select any element
1563 if (myActorsList.count() > 0) {
1564 QListIterator<SMESH_Actor*> it( myActorsList );
1565 while ( it.hasNext() ) {
1566 SMESH_Actor* anActor = it.next();
1567 if ( IsActorVisible(anActor) )
1568 anActor->SetPickable(true);
1575 //=================================================================================
1576 // function : onSelectAll()
1577 // purpose : Called when "Select all" is checked
1578 //=================================================================================
1579 void SMESHGUI_GroupDlg::onSelectAll()
1581 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1583 myElementsLab->setEnabled( !noElemsModif );
1584 myElements->setEnabled ( !noElemsModif );
1585 myFilterBtn->setEnabled ( !noElemsModif );
1586 myAddBtn->setEnabled ( !noElemsModif );
1587 myRemoveBtn->setEnabled ( !noElemsModif );
1588 mySortBtn->setEnabled ( !noElemsModif );
1589 mySelectBox->setEnabled ( !noElemsModif );
1590 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1592 int selMode = mySelectionMode;
1593 mySelectionMode = grpNoSelection;
1594 setSelectionMode( selMode );
1598 //=================================================================================
1599 // function : onSelectSubMesh()
1600 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1601 //=================================================================================
1602 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1605 if (mySelectGroup->isChecked()) {
1606 mySelectGroup->setChecked(false);
1608 //VSR: else if (mySelectGeomGroup->isChecked()) {
1609 //VSR: mySelectGeomGroup->setChecked(false);
1611 myCurrentLineEdit = mySubMeshLine;
1612 setSelectionMode(grpSubMeshSelection);
1615 mySubMeshLine->setText( "" );
1616 myCurrentLineEdit = 0;
1618 setSelectionMode(myTypeId);
1620 mySubMeshBtn->setEnabled(on);
1621 mySubMeshLine->setEnabled(on);
1625 //=================================================================================
1626 // function : (onSelectGroup)
1627 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1628 //=================================================================================
1629 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1632 if (mySelectSubMesh->isChecked()) {
1633 mySelectSubMesh->setChecked(false);
1635 myCurrentLineEdit = myGroupLine;
1636 setSelectionMode(grpGroupSelection);
1639 myGroupLine->setText( "" );
1640 myCurrentLineEdit = 0;
1642 setSelectionMode(myTypeId);
1644 myGroupBtn->setEnabled(on);
1645 myGroupLine->setEnabled(on);
1649 //=================================================================================
1650 // function : (onSelectGeomGroup)
1651 // purpose : Called when group type changed. on == "on geometry" or "on filter"
1652 //=================================================================================
1653 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1656 if (mySelectSubMesh->isChecked()) {
1657 mySelectSubMesh->setChecked(false);
1659 else if (mySelectGroup->isChecked()) {
1660 mySelectGroup->setChecked(false);
1662 if ( myGrpTypeId == 1 ) { // on geometry
1663 myCurrentLineEdit = myGeomGroupLine;
1667 myCurrentLineEdit = 0;
1669 setSelectionMode(grpAllSelection);
1672 myGeomGroupBtn->setChecked(false);
1673 myGeomObjects->length(0);
1674 myGeomGroupLine->setText( "" );
1675 myCurrentLineEdit = 0;
1677 setSelectionMode( myTypeId );
1681 //=================================================================================
1682 // function : setCurrentSelection()
1684 //=================================================================================
1685 void SMESHGUI_GroupDlg::setCurrentSelection()
1687 QPushButton* send = (QPushButton*)sender();
1688 myCurrentLineEdit = 0;
1689 if (send == myMeshGroupBtn) {
1690 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1691 mySelectionMgr->clearSelected();
1693 setSelectionMode(grpMeshSelection);
1695 setSelectionMode(grpGroupSelection);
1696 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1697 myCurrentLineEdit = myMeshGroupLine;
1698 onObjectSelectionChanged();
1700 else if (send == mySubMeshBtn) {
1701 myCurrentLineEdit = mySubMeshLine;
1702 onObjectSelectionChanged();
1704 else if (send == myGroupBtn) {
1705 myCurrentLineEdit = myGroupLine;
1706 onObjectSelectionChanged();
1711 //=================================================================================
1712 // function : setFilters()
1713 // purpose : SLOT. Called when "Filter" button pressed.
1714 //=================================================================================
1715 void SMESHGUI_GroupDlg::setFilters()
1717 if(myMesh->_is_nil()) {
1718 SUIT_MessageBox::critical(this,
1720 tr("NO_MESH_SELECTED"));
1724 SMESH::ElementType aType = SMESH::ALL;
1727 case grpNodeSelection: aType = SMESH::NODE; break;
1728 case grp0DSelection: aType = SMESH::ELEM0D; break;
1729 case grpBallSelection: aType = SMESH::BALL; break;
1730 case grpEdgeSelection: aType = SMESH::EDGE; break;
1731 case grpFaceSelection: aType = SMESH::FACE; break;
1732 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1736 if ( myFilterDlg == 0 )
1738 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1739 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1742 myFilterDlg->Init( aType );
1744 if ( !myGroupOnFilter->_is_nil() )
1746 myFilterDlg->SetFilter( myFilter, aType );
1747 myFilterDlg->Init( aType );
1750 bool isStandalone = ( sender() == myFilterBtn );
1751 myFilterDlg->SetEnabled( /*setInViewer=*/isStandalone,
1752 /*diffSources=*/isStandalone );
1753 myFilterDlg->SetMesh( myMesh );
1754 myFilterDlg->SetSelection();
1755 myFilterDlg->SetSourceWg( myElements, false );
1758 myFilterDlg->show();
1761 //=================================================================================
1762 // function : onFilterAccepted()
1763 // purpose : SLOT. Called when Filter dlg closed with OK button.
1764 // Uncheck "Select submesh" and "Select group" checkboxes
1765 //=================================================================================
1766 void SMESHGUI_GroupDlg::onFilterAccepted()
1768 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1770 mySelectionMode = myTypeId;
1771 mySelectSubMesh->setChecked( false );
1772 mySelectGroup->setChecked( false );
1774 // get a filter from myFilterDlg
1775 myFilter = myFilterDlg->GetFilter();
1776 if ( !myFilter->_is_nil() ) {
1777 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1778 if ( perdicate->_is_nil() )
1779 myFilter = SMESH::Filter::_nil();
1781 // set mesh to myFilter
1782 if ( !myFilter->_is_nil() ) {
1783 SMESH::SMESH_Mesh_var mesh = myMesh;
1784 if ( mesh->_is_nil() ) {
1785 if ( !myGroup->_is_nil() )
1786 mesh = myGroup->GetMesh();
1787 else if ( !myGroupOnGeom->_is_nil() )
1788 mesh = myGroupOnGeom->GetMesh();
1789 else if ( !myGroupOnFilter->_is_nil() )
1790 mesh = myGroupOnFilter->GetMesh();
1792 myFilter->SetMesh( mesh );
1798 //=================================================================================
1799 // function : onAdd()
1801 //=================================================================================
1802 void SMESHGUI_GroupDlg::onAdd()
1804 SALOME_ListIO aList;
1805 mySelectionMgr->selectedObjects( aList );
1807 int aNbSel = aList.Extent();
1809 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1812 int sizeBefore = myElements->count();
1814 SMESH::ElementType aType = SMESH::ALL;
1816 case grpNodeSelection:
1817 aType = SMESH::NODE;
1818 mySelector->SetSelectionMode(NodeSelection);
1820 case grpBallSelection:
1821 aType = SMESH::BALL;
1822 mySelector->SetSelectionMode(BallSelection);
1824 case grp0DSelection:
1825 aType = SMESH::ELEM0D;
1826 mySelector->SetSelectionMode(Elem0DSelection);
1828 case grpEdgeSelection:
1829 aType = SMESH::EDGE;
1830 mySelector->SetSelectionMode(EdgeSelection);
1832 case grpFaceSelection:
1833 aType = SMESH::FACE;
1834 mySelector->SetSelectionMode(FaceSelection);
1836 case grpVolumeSelection:
1837 aType = SMESH::VOLUME;
1838 mySelector->SetSelectionMode(VolumeSelection);
1841 mySelector->SetSelectionMode(ActorSelection);
1844 QListWidgetItem* anItem = 0;
1845 QList<QListWidgetItem*> listItemsToSel;
1847 if (myCurrentLineEdit == 0) {
1848 //if (aNbSel != 1) { myIsBusy = false; return; }
1849 QString aListStr = "";
1851 if (myTypeId == 0) {
1852 QListIterator<SMESH_Actor*> it( myActorsList );
1853 while ( it.hasNext() ) {
1855 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1860 QListIterator<SMESH_Actor*> it( myActorsList );
1861 while ( it.hasNext() ) {
1863 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1868 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1869 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1870 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1871 if (found.count() == 0) {
1872 anItem = new QListWidgetItem(*it);
1873 myElements->addItem(anItem);
1874 if (!anItem->isSelected())
1875 listItemsToSel.push_back(anItem);
1878 foreach(anItem, found)
1879 if (!anItem->isSelected())
1880 listItemsToSel.push_back(anItem);
1883 bool blocked = myElements->signalsBlocked();
1884 myElements->blockSignals(true);
1885 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1886 myElements->blockSignals(blocked);
1887 onListSelectionChanged();
1888 listItemsToSel.clear();
1890 } else if (myCurrentLineEdit == mySubMeshLine) {
1891 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1893 SALOME_ListIO aList;
1894 mySelectionMgr->selectedObjects( aList );
1896 SALOME_ListIteratorOfListIO anIt (aList);
1897 for ( ; anIt.More(); anIt.Next()) {
1898 SMESH::SMESH_subMesh_var aSubMesh =
1899 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1900 if (!aSubMesh->_is_nil()) {
1901 // check if mesh is the same
1902 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1904 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1905 int k = anElements->length();
1906 for (int i = 0; i < k; i++) {
1907 QString aText = QString::number(anElements[i]);
1908 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1909 if (found.count() == 0) {
1910 anItem = new QListWidgetItem(aText);
1911 myElements->addItem(anItem);
1912 if (!anItem->isSelected())
1913 listItemsToSel.push_back(anItem);
1916 foreach(anItem, found)
1917 if (!anItem->isSelected())
1918 listItemsToSel.push_back(anItem);
1921 bool blocked = myElements->signalsBlocked();
1922 myElements->blockSignals(true);
1923 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1924 myElements->blockSignals(blocked);
1925 onListSelectionChanged();
1926 listItemsToSel.clear();
1928 catch (const SALOME::SALOME_Exception& ex) {
1929 SalomeApp_Tools::QtCatchCorbaException(ex);
1934 mySelectSubMesh->setChecked(false);
1936 onListSelectionChanged();
1938 } else if (myCurrentLineEdit == myGroupLine) {
1939 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1940 SALOME_ListIO aList;
1941 mySelectionMgr->selectedObjects( aList );
1943 SALOME_ListIteratorOfListIO anIt (aList);
1944 for ( ; anIt.More(); anIt.Next()) {
1945 SMESH::SMESH_GroupBase_var aGroup =
1946 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1947 if (!aGroup->_is_nil()) {
1948 // check if mesh is the same
1949 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1950 SMESH::long_array_var anElements = aGroup->GetListOfID();
1951 int k = anElements->length();
1952 for (int i = 0; i < k; i++) {
1953 QString aText = QString::number(anElements[i]);
1954 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1955 if (found.count() == 0) {
1956 anItem = new QListWidgetItem(aText);
1957 myElements->addItem(anItem);
1958 if (!anItem->isSelected())
1959 listItemsToSel.push_back(anItem);
1962 foreach(anItem, found)
1963 if (!anItem->isSelected())
1964 listItemsToSel.push_back(anItem);
1967 bool blocked = myElements->signalsBlocked();
1968 myElements->blockSignals(true);
1969 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1970 myElements->blockSignals(blocked);
1971 onListSelectionChanged();
1972 listItemsToSel.clear();
1976 mySelectGroup->setChecked(false);
1978 onListSelectionChanged();
1980 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1981 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1982 GEOM::GEOM_IGroupOperations_wrap aGroupOp =
1983 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1985 SMESH::ElementType aGroupType = SMESH::ALL;
1986 switch(aGroupOp->GetType(myGeomObjects[0])) {
1987 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
1988 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
1989 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
1990 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
1991 default: myIsBusy = false; return;
1994 if (aGroupType == aType) {
1995 _PTR(SObject) aGroupSO =
1996 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1997 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1999 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2000 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
2001 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
2002 aBelongToGeom->SetGeom(myGeomObjects[0]);
2003 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
2004 aBelongToGeom->SetElementType(aType);
2005 aFilter->SetPredicate(aBelongToGeom);
2007 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
2009 int k = anElements->length();
2010 for (int i = 0; i < k; i++) {
2011 QString aText = QString::number(anElements[i]);
2012 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2013 if (found.count() == 0) {
2014 anItem = new QListWidgetItem(aText);
2015 myElements->addItem(anItem);
2016 if (!anItem->isSelected())
2017 listItemsToSel.push_back(anItem);
2020 foreach(anItem, found)
2021 if (!anItem->isSelected())
2022 listItemsToSel.push_back(anItem);
2025 bool blocked = myElements->signalsBlocked();
2026 myElements->blockSignals(true);
2027 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2028 myElements->blockSignals(blocked);
2029 onListSelectionChanged();
2030 listItemsToSel.clear();
2033 //VSR: mySelectGeomGroup->setChecked(false);
2035 onListSelectionChanged();
2038 if ( sizeBefore < myElements->count() )
2039 ++myNbChangesOfContents;
2040 // mySelectionMgr->clearSelected();
2044 //=================================================================================
2045 // function : onRemove()
2047 //=================================================================================
2048 void SMESHGUI_GroupDlg::onRemove()
2051 int sizeBefore = myElements->count();
2053 if (myCurrentLineEdit == 0) {
2054 QList<QListWidgetItem*> selItems = myElements->selectedItems();
2055 QListWidgetItem* item;
2056 foreach(item, selItems) delete item;
2058 SALOME_ListIO aList;
2059 mySelectionMgr->selectedObjects( aList );
2061 int aNbSel = aList.Extent();
2063 if (aNbSel == 0) { myIsBusy = false; return; }
2065 SMESH::ElementType aType = SMESH::ALL;
2067 case grpNodeSelection: aType = SMESH::NODE; break;
2068 case grp0DSelection: aType = SMESH::ELEM0D; break;
2069 case grpBallSelection: aType = SMESH::BALL; break;
2070 case grpEdgeSelection: aType = SMESH::EDGE; break;
2071 case grpFaceSelection: aType = SMESH::FACE; break;
2072 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2075 if (myCurrentLineEdit == mySubMeshLine) {
2076 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2077 SALOME_ListIO aList;
2078 mySelectionMgr->selectedObjects( aList );
2080 SALOME_ListIteratorOfListIO anIt (aList);
2081 for ( ; anIt.More(); anIt.Next()) {
2082 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2083 if (!aSubMesh->_is_nil()) {
2084 // check if mesh is the same
2085 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2086 if (aType == SMESH::NODE) {
2088 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2089 int k = anElements->length();
2090 for (int i = 0; i < k; i++) {
2091 QList<QListWidgetItem*> found =
2092 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2093 QListWidgetItem* anItem;
2094 foreach(anItem, found) delete anItem;
2097 catch (const SALOME::SALOME_Exception& ex) {
2098 SalomeApp_Tools::QtCatchCorbaException(ex);
2103 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2104 int k = anElements->length();
2105 for (int i = 0; i < k; i++) {
2106 QList<QListWidgetItem*> found =
2107 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2108 QListWidgetItem* anItem;
2109 foreach(anItem, found) delete anItem;
2112 catch (const SALOME::SALOME_Exception& ex) {
2113 SalomeApp_Tools::QtCatchCorbaException(ex);
2120 else if (myCurrentLineEdit == myGroupLine) {
2121 Standard_Boolean aRes;
2122 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2123 SALOME_ListIO aList;
2124 mySelectionMgr->selectedObjects( aList );
2126 SALOME_ListIteratorOfListIO anIt (aList);
2127 for ( ; anIt.More(); anIt.Next()) {
2128 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2129 if (aRes && !aGroup->_is_nil()) {
2130 // check if mesh is the same
2131 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2132 SMESH::long_array_var anElements = aGroup->GetListOfID();
2133 int k = anElements->length();
2134 for (int i = 0; i < k; i++) {
2135 QList<QListWidgetItem*> found =
2136 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2137 QListWidgetItem* anItem;
2138 foreach(anItem, found) delete anItem;
2146 if ( sizeBefore > myElements->count() )
2147 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2151 //=================================================================================
2152 // function : onSort()
2154 //=================================================================================
2155 void SMESHGUI_GroupDlg::onSort()
2157 // PAL5412: sorts items in ascending by "string" value
2158 // myElements->sort(true);
2159 // myElements->update();
2160 int i, k = myElements->count();
2163 QList<int> aSelected;
2164 std::vector<int> anArray(k);
2165 // QMemArray<int> anArray(k);
2167 for (i = 0; i < k; i++) {
2168 int id = myElements->item(i)->text().toInt();
2170 if (myElements->item(i)->isSelected())
2171 aSelected.append(id);
2173 // sort & update list
2174 std::sort(anArray.begin(), anArray.end());
2176 myElements->clear();
2177 QListWidgetItem* anItem;
2178 QList<QListWidgetItem*> listItemsToSel;
2179 for (i = 0; i < k; i++) {
2180 anItem = new QListWidgetItem(QString::number(anArray[i]));
2181 myElements->addItem(anItem);
2182 if (aSelected.contains(anArray[i]))
2183 listItemsToSel.push_back(anItem);
2185 bool blocked = myElements->signalsBlocked();
2186 myElements->blockSignals(true);
2187 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2188 myElements->blockSignals(blocked);
2189 listItemsToSel.clear();
2194 //=================================================================================
2195 // function : onVisibilityChanged()
2197 //=================================================================================
2198 void SMESHGUI_GroupDlg::onVisibilityChanged()
2200 SetAppropriateActor();
2203 //=================================================================================
2204 // function : SMESHGUI_GroupDlg::reject
2205 // purpose : SLOT called when "Close" button pressed. Close dialog
2206 //=================================================================================
2207 void SMESHGUI_GroupDlg::reject()
2209 if (SMESH::GetCurrentVtkView()) {
2210 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2211 SMESH::SetPointRepresentation(false);
2212 SMESH::SetPickable();
2213 restoreShowEntityMode();
2216 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2217 SUIT_DataOwnerPtrList aList;
2218 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2219 mySelectionMgr->setSelected( aList );
2222 mySelectionMgr->clearSelected();
2223 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2224 aViewWindow->SetSelectionMode(ActorSelection);
2225 mySelectionMgr->clearFilters();
2226 mySMESHGUI->ResetState();
2230 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
2233 //=================================================================================
2234 // function : onHelp()
2236 //=================================================================================
2237 void SMESHGUI_GroupDlg::onHelp()
2239 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2241 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2245 platform = "winapplication";
2247 platform = "application";
2249 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2250 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2251 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2253 arg(myHelpFileName));
2257 //=================================================================================
2258 // function : SMESHGUI_GroupDlg::onDeactivate
2259 // purpose : SLOT called when dialog must be deativated
2260 //=================================================================================
2261 void SMESHGUI_GroupDlg::onDeactivate()
2263 mySMESHGUI->ResetState();
2267 //=================================================================================
2268 // function : SMESHGUI_GroupDlg::enterEvent
2269 // purpose : Event filter
2270 //=================================================================================
2271 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2274 mySMESHGUI->EmitSignalDeactivateDialog();
2276 mySelectionMode = grpNoSelection;
2277 setSelectionMode(myTypeId);
2278 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2279 mySMESHGUI->SetActiveDialogBox(this);
2280 mySMESHGUI->SetState(800);
2284 //=================================================================================
2285 // function : keyPressEvent()
2287 //=================================================================================
2288 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2290 QDialog::keyPressEvent( e );
2291 if ( e->isAccepted() )
2294 if ( e->key() == Qt::Key_F1 )
2301 //================================================================================
2303 * \brief Enable showing of the popup when Geometry selection btn is clicked
2304 * \param enable - true to enable
2306 //================================================================================
2308 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2310 void SMESHGUI_GroupDlg::updateGeomPopup()
2312 bool enable = false;
2314 if ( !myMesh->_is_nil() )
2315 enable = myMesh->NbEdges() > 0;
2317 if ( myGeomGroupBtn )
2319 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2321 if ( !myGeomPopup ) {
2322 myGeomPopup = new QMenu(this);
2323 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2324 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2325 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2327 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2333 //=================================================================================
2334 // function : onGeomSelectionButton()
2336 //=================================================================================
2337 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2339 if ( myGeomPopup && isBtnOn )
2341 myCurrentLineEdit = myGeomGroupLine;
2342 QAction* a = myGeomPopup->exec( QCursor::pos() );
2343 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2344 setSelectionMode(grpGeomSelection);
2348 myCurrentLineEdit = 0;
2349 setSelectionMode(grpAllSelection);
2353 //=================================================================================
2354 // function : onGeomPopup()
2356 //=================================================================================
2357 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2359 int index = myActions[a];
2360 if ( index == GEOM_BY_MESH_INDEX )
2362 mySelectionMode = grpNoSelection;
2363 if ( !myShapeByMeshOp ) {
2364 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2365 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2366 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2367 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2368 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2370 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2371 if ( !myMesh->_is_nil() ) {
2373 hide(); // stop processing selection
2375 myShapeByMeshOp->setModule( mySMESHGUI );
2376 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2377 myShapeByMeshOp->SetMesh( myMesh );
2378 myShapeByMeshOp->start();
2383 //================================================================================
2385 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2387 //================================================================================
2389 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2391 if ( myShapeByMeshOp == op ) {
2392 mySMESHGUI->getApp()->updateObjectBrowser();
2394 // Select a found geometry object
2395 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2396 if ( !aGeomVar->_is_nil() )
2398 QString ID = aGeomVar->GetStudyEntry();
2399 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2400 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2401 SALOME_ListIO anIOList;
2402 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2403 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2404 anIOList.Append( anIO );
2405 mySelectionMgr->setSelectedObjects( anIOList, false );
2406 onObjectSelectionChanged();
2412 //================================================================================
2414 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2416 //================================================================================
2418 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2420 if ( myShapeByMeshOp == op )
2423 setSelectionMode(grpGeomSelection);
2427 //=================================================================================
2428 // function : setGroupColor()
2430 //=================================================================================
2431 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2433 QColor aQColor( (int)( theColor.R * 255.0 ),
2434 (int)( theColor.G * 255.0 ),
2435 (int)( theColor.B * 255.0 ) );
2436 setGroupQColor( aQColor );
2439 //=================================================================================
2440 // function : getGroupColor()
2442 //=================================================================================
2443 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2445 QColor aQColor = getGroupQColor();
2447 SALOMEDS::Color aColor;
2448 aColor.R = (float)aQColor.red() / 255.0;
2449 aColor.G = (float)aQColor.green() / 255.0;
2450 aColor.B = (float)aQColor.blue() / 255.0;
2455 //=================================================================================
2456 // function : setGroupQColor()
2458 //=================================================================================
2459 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2461 if( theColor.isValid() )
2462 myColorBtn->setColor( theColor );
2465 //=================================================================================
2466 // function : getGroupQColor()
2468 //=================================================================================
2469 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2471 return myColorBtn->color();
2474 //=================================================================================
2475 // function : setDefaultGroupColor()
2477 //=================================================================================
2478 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2480 if( myMesh->_is_nil() )
2483 bool isAutoColor = myMesh->GetAutoColor();
2485 QColor aQColor = myColorBtn->color();
2488 if ( !aQColor.isValid() ) {
2489 int r = 0, g = 0, b = 0;
2490 SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2491 aQColor.setRgb( r, g, b );
2496 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2497 SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
2498 #else // old algorithm for auto-colors
2499 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2501 QList<SALOMEDS::Color> aReservedColors;
2502 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2504 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2505 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2506 aReservedColors.append( aReservedColor );
2509 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2510 #endif // SIMPLE_AUTOCOLOR
2512 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2513 (int)( aColor.G * 255.0 ),
2514 (int)( aColor.B * 255.0 ) );
2518 setGroupQColor( aQColor );
2521 //=================================================================================
2522 // function : SetAppropriateActor()
2523 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2524 // NPAL19389: create a group with a selection in another group.
2525 // if mesh actor is not visible - find any first visible group or submesh
2526 //=================================================================================
2527 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2529 bool isActor = false;
2530 myActorsList.clear();
2532 if (myMesh->_is_nil()) return false;
2534 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2536 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2538 if (!myGroupOnGeom->_is_nil()) {
2539 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2540 if (anActor && anActor->hasIO())
2543 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2546 myActorsList.append(anActor);
2552 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2553 if (anActor && anActor->hasIO()) {
2555 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2558 myActorsList.append(anActor);
2562 if (!isActor && !myGroup->_is_nil()) {
2563 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2564 if (anActor && anActor->hasIO())
2565 myActorsList.append(anActor);
2568 // try any visible actor of group or submesh of current mesh
2571 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2573 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2574 int len = strlen(meshEntry);
2576 // iterate on all actors in current view window, search for
2577 // any visible actor, that belongs to group or submesh of current mesh
2578 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2579 vtkActorCollection *aCollection = aCopy.GetActors();
2580 int nbItems = aCollection->GetNumberOfItems();
2581 for (int i=0; i<nbItems && !isActor; i++)
2583 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2584 if (anActor && anActor->hasIO()) {
2585 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2586 if (aViewWindow->isVisible(anIO)) {
2587 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2588 myActorsList.append(anActor);
2596 if (myActorsList.count() > 0) {
2597 QListIterator<SMESH_Actor*> it( myActorsList );
2598 while ( it.hasNext() ) {
2599 SMESH_Actor* anActor = it.next();
2600 if ( IsActorVisible(anActor) )
2601 anActor->SetPickable(true);
2605 return ( isActor || (myActorsList.count() > 0) );
2608 //=======================================================================
2609 //function : setShowEntityMode
2610 //purpose : make shown only entity corresponding to my type
2611 //=======================================================================
2612 void SMESHGUI_GroupDlg::setShowEntityMode()
2614 if ( !myMesh->_is_nil() ) {
2615 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2616 if (!myStoredShownEntity)
2617 myStoredShownEntity = actor->GetEntityMode();
2618 switch ( myTypeId ) {
2619 case grpNodeSelection: restoreShowEntityMode(); break;
2620 case grp0DSelection: actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
2621 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2622 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2623 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2624 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2630 //=======================================================================
2631 //function : restoreShowEntityMode
2632 //purpose : restore ShowEntity mode of myActor
2633 //=======================================================================
2634 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2636 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2637 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2638 actor->SetEntityMode(myStoredShownEntity);
2641 myStoredShownEntity = 0;
2644 //=======================================================================
2645 //function : IsActorVisible
2646 //purpose : return visibility of the actor
2647 //=======================================================================
2648 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2650 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2651 if (theActor && aViewWindow)
2652 return aViewWindow->isVisible(theActor->getIO());
2656 //================================================================
2657 //function : setIsApplyAndClose
2658 //purpose : Set value of the flag indicating that the dialog is
2659 // accepted by Apply & Close button
2660 //================================================================
2661 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2663 myIsApplyAndClose = theFlag;
2666 //================================================================
2667 //function : isApplyAndClose
2668 //purpose : Get value of the flag indicating that the dialog is
2669 // accepted by Apply & Close button
2670 //================================================================
2671 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2673 return myIsApplyAndClose;