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>
64 #include <SALOME_ListIteratorOfListIO.hxx>
66 #include <SVTK_ViewWindow.h>
68 #include <VTKViewer_Algorithm.h>
70 // SALOME KERNEL includes
71 #include <SALOMEDSClient_Study.hxx>
74 #include <vtkRenderer.h>
75 #include <vtkActorCollection.h>
78 #include <TColStd_MapOfInteger.hxx>
81 #include <QButtonGroup>
85 #include <QPushButton>
86 #include <QToolButton>
87 #include <QRadioButton>
89 #include <QGridLayout>
90 #include <QHBoxLayout>
91 #include <QVBoxLayout>
92 #include <QListWidget>
93 #include <QStackedWidget>
105 enum grpSelectionMode {
107 grpNodeSelection = 0,
109 grpBallSelection = 2,
110 grpEdgeSelection = 3,
111 grpFaceSelection = 4,
112 grpVolumeSelection = 5,
113 grpSubMeshSelection = 6,
114 grpGroupSelection = 7,
115 grpMeshSelection = 8,
116 grpGeomSelection = 9,
117 grpAllSelection = 10,
120 //=================================================================================
121 // function : SMESHGUI_GroupDlg()
123 //=================================================================================
124 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
125 SMESH::SMESH_Mesh_ptr theMesh )
126 : QDialog( SMESH::GetDesktop( theModule ) ),
127 mySMESHGUI( theModule ),
128 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
129 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
131 myNameChanged( false ),
132 myIsApplyAndClose( false ),
133 myNbChangesOfContents(0)
136 if ( !theMesh->_is_nil() )
140 mySelectSubMesh->setEnabled( false );
141 mySelectGroup->setEnabled( false );
142 myGeomGroupBtn->setEnabled( false );
143 myGeomGroupLine->setEnabled( false );
147 //=================================================================================
148 // function : SMESHGUI_GroupDlg()
150 //=================================================================================
151 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
152 SMESH::SMESH_GroupBase_ptr theGroup,
153 const bool theIsConvert )
154 : QDialog( SMESH::GetDesktop( theModule ) ),
155 mySMESHGUI( theModule ),
156 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
157 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
159 myNameChanged( false ),
160 myNbChangesOfContents(0) // just not to use uninitialized variable
163 if ( !theGroup->_is_nil() )
164 init( theGroup, theIsConvert );
167 mySelectSubMesh->setEnabled( false );
168 mySelectGroup->setEnabled( false );
170 myCurrentLineEdit = myMeshGroupLine;
171 setSelectionMode( grpGroupSelection );
175 //=================================================================================
176 // function : SMESHGUI_GroupDlg()
178 //=================================================================================
179 void SMESHGUI_GroupDlg::initDialog( bool create)
182 setAttribute( Qt::WA_DeleteOnClose, true );
186 myCurrentLineEdit = 0;
190 myGeomObjects = new GEOM::ListOfGO();
191 myGeomObjects->length( 0 );
193 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
195 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
196 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
198 setSizeGripEnabled( true);
200 QGridLayout* aMainLayout = new QGridLayout( this );
201 aMainLayout->setMargin( MARGIN );
202 aMainLayout->setSpacing( SPACING );
204 /***************************************************************/
205 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
206 myMeshGroupBtn = new QPushButton( this );
207 myMeshGroupBtn->setIcon( image0 );
208 myMeshGroupLine = new QLineEdit( this );
209 myMeshGroupLine->setReadOnly( true );
211 /***************************************************************/
212 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
213 myTypeGroup = new QButtonGroup( this );
214 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
215 aTypeBoxLayout->setMargin( MARGIN );
216 aTypeBoxLayout->setSpacing( SPACING );
219 types.append( tr( "MESH_NODE" ) );
220 types.append( tr( "SMESH_ELEM0D" ) );
221 types.append( tr( "SMESH_BALL_ELEM" ) );
222 types.append( tr( "SMESH_EDGE" ) );
223 types.append( tr( "SMESH_FACE" ) );
224 types.append( tr( "SMESH_VOLUME" ) );
226 for ( int i = 0; i < types.count(); i++ )
228 rb = new QRadioButton( types[i], aTypeBox );
229 myTypeGroup->addButton( rb, i );
230 aTypeBoxLayout->addWidget( rb );
232 aTypeBox->setEnabled( create );
235 /***************************************************************/
236 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
237 aName->setMinimumWidth( 50 );
238 myName = new QLineEdit( this );
240 /***************************************************************/
241 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
242 myGrpTypeGroup = new QButtonGroup( this );
243 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
244 aGrpTypeBoxLayout->setMargin( MARGIN );
245 aGrpTypeBoxLayout->setSpacing( SPACING );
247 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
248 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
249 QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox );
250 myGrpTypeGroup->addButton( rb1, 0 );
251 myGrpTypeGroup->addButton( rb2, 1 );
252 myGrpTypeGroup->addButton( rb3, 2 );
253 aGrpTypeBoxLayout->addWidget( rb1 );
254 aGrpTypeBoxLayout->addWidget( rb2 );
255 aGrpTypeBoxLayout->addWidget( rb3 );
256 aGrpTypeBox->setEnabled( create );
259 /***************************************************************/
260 myWGStack = new QStackedWidget( this );
261 QWidget* wg1 = new QWidget( myWGStack );
262 QWidget* wg2 = new QWidget( myWGStack );
263 QWidget* wg3 = new QWidget( myWGStack );
265 /***************************************************************/
266 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
267 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
268 aContentBoxLayout->setMargin( MARGIN );
269 aContentBoxLayout->setSpacing( SPACING );
271 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
272 myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
274 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
275 myElements = new QListWidget( aContentBox );
276 myElements->setSelectionMode( QListWidget::ExtendedSelection );
278 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
279 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
280 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
281 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
283 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
284 aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
285 aContentBoxLayout->addWidget( myFilterBtn, 1, 1 );
286 aContentBoxLayout->addWidget( myElementsLab, 2, 0 );
287 aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 );
288 aContentBoxLayout->addWidget( myAddBtn, 3, 1 );
289 aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 );
290 aContentBoxLayout->addWidget( mySortBtn, 8, 1 );
292 aContentBoxLayout->setColumnStretch( 0, 1 );
293 aContentBoxLayout->setRowStretch( 3, 1 );
294 aContentBoxLayout->setRowStretch( 6, 1 );
296 /***************************************************************/
297 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
298 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
299 mySelectBoxLayout->setMargin( MARGIN );
300 mySelectBoxLayout->setSpacing( SPACING );
302 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
303 mySubMeshBtn = new QPushButton( mySelectBox );
304 mySubMeshBtn->setIcon( image0 );
305 mySubMeshLine = new QLineEdit( mySelectBox );
306 mySubMeshLine->setReadOnly( true );
307 onSelectSubMesh( false );
309 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
310 myGroupBtn = new QPushButton( mySelectBox );
311 myGroupBtn->setIcon( image0 );
312 myGroupLine = new QLineEdit( mySelectBox );
313 myGroupLine->setReadOnly( true );
314 onSelectGroup( false );
316 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
317 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
318 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
319 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
320 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
321 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
323 /***************************************************************/
324 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
325 wg1Layout->setMargin( 0 );
326 wg1Layout->setSpacing( SPACING );
327 wg1Layout->addWidget( aContentBox );
328 wg1Layout->addWidget( mySelectBox );
329 wg1Layout->setStretchFactor( aContentBox, 10 );
331 /***************************************************************/
332 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
333 myGeomGroupBtn = new QToolButton( wg2 );
334 myGeomGroupBtn->setIcon( image0 );
335 myGeomGroupBtn->setCheckable( true );
336 myGeomGroupLine = new QLineEdit( wg2 );
337 myGeomGroupLine->setReadOnly( true ); //VSR ???
338 onSelectGeomGroup( false );
340 myGeomGroupBtn->setEnabled( create );
341 myGeomGroupLine->setEnabled( create );
343 /***************************************************************/
344 QGridLayout* wg2Layout = new QGridLayout( wg2 );
345 wg2Layout->setMargin( 0 );
346 wg2Layout->setSpacing( SPACING );
347 wg2Layout->addWidget( geomObject, 0, 0 );
348 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
349 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
350 wg2Layout->setRowStretch( 1, 5 );
352 /***************************************************************/
353 QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
354 QGridLayout* wg3Layout = new QGridLayout( wg3 );
355 wg3Layout->setMargin( 0 );
356 wg3Layout->setSpacing( SPACING );
357 wg3Layout->addWidget( aFilter2, 0, 0 );
358 wg3Layout->setRowStretch( 1, 5 );
360 /***************************************************************/
361 myWGStack->insertWidget( 0, wg1 );
362 myWGStack->insertWidget( 1, wg2 );
363 myWGStack->insertWidget( 2, wg3 );
365 /***************************************************************/
366 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
367 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
368 aColorBoxLayout->setMargin(MARGIN);
369 aColorBoxLayout->setSpacing(SPACING);
371 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
372 myColorBtn = new QtxColorButton(aColorBox);
373 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
374 myColorBtn->sizePolicy().verticalPolicy() );
376 aColorBoxLayout->addWidget(aColorLab);
377 aColorBoxLayout->addWidget(myColorBtn);
379 /***************************************************************/
381 QFrame* aButtons = new QFrame(this);
382 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
383 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
384 aBtnLayout->setMargin(MARGIN);
385 aBtnLayout->setSpacing(SPACING);
387 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
388 myOKBtn->setAutoDefault(true);
389 myOKBtn->setDefault(true);
390 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
391 myApplyBtn->setAutoDefault(true);
392 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
393 myCloseBtn->setAutoDefault(true);
394 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
395 myHelpBtn->setAutoDefault(true);
397 aBtnLayout->addWidget(myOKBtn);
398 aBtnLayout->addSpacing(10);
399 aBtnLayout->addWidget(myApplyBtn);
400 aBtnLayout->addSpacing(10);
401 aBtnLayout->addStretch();
402 aBtnLayout->addWidget(myCloseBtn);
403 aBtnLayout->addWidget(myHelpBtn);
405 /***************************************************************/
406 aMainLayout->addWidget(meshGroupLab, 0, 0);
407 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
408 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
409 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
410 aMainLayout->addWidget(aName, 2, 0);
411 aMainLayout->addWidget(myName, 2, 2);
412 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
413 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
414 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
415 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
417 /* signals and slots connections */
418 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
419 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
420 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
422 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
423 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
425 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
426 connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters()));
427 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
428 connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
429 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
430 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
431 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
433 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
434 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
435 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
436 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
437 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
439 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
441 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
442 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
443 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
444 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
447 mySMESHGUI->SetActiveDialogBox(this);
448 mySMESHGUI->SetState(800);
450 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
451 mySelectionMode = grpNoSelection;
453 myMeshFilter = new SMESH_TypeFilter(SMESH::MESH);
454 mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
455 SMESH_LogicalFilter::LO_OR,
456 /*takeOwnership=*/true);
457 myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
458 SMESH_LogicalFilter::LO_OR,
459 /*takeOwnership=*/true);
460 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
462 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
463 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
464 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
465 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
467 rb1->setChecked(true); // VSR !!!
468 onGrpTypeChanged(0); // VSR!!!
470 if (myMesh->_is_nil() )
471 myTypeGroup->button(0)->setChecked(true);
473 onSelectAll(); //updateButtons();
476 //=================================================================================
477 // function : ~SMESHGUI_GroupDlg()
478 // purpose : Destroys the object and frees any allocated resources
479 //=================================================================================
480 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
482 // no need to delete child widgets, Qt does it all for us
483 if ( myFilterDlg != 0 ) {
484 myFilterDlg->setParent( 0 );
487 if ( myMeshFilter ) delete myMeshFilter;
488 if ( mySubMeshFilter ) delete mySubMeshFilter;
489 if ( myGroupFilter ) delete myGroupFilter;
490 if ( myGeomFilter ) delete myGeomFilter;
493 //=================================================================================
494 // function : GetDefaultName()
495 // purpose : Get the Group Name if Create new Group
496 //=================================================================================
497 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
501 // collect all object names of SMESH component
502 SalomeApp_Study* appStudy =
503 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
504 if ( !appStudy ) return aName;
505 _PTR(Study) aStudy = appStudy->studyDS();
507 std::set<std::string> aSet;
508 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
510 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
512 for (it->InitEx(true); it->More(); it->Next()) {
514 aSet.insert(obj->GetName());
518 // build a unique name
520 bool isUnique = false;
522 aName = theOperation + "_" + QString::number(++aNumber);
523 isUnique = (aSet.count(aName.toUtf8().data()) == 0);
529 void SMESHGUI_GroupDlg::setDefaultName() const
532 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
534 QString aPrefix ="Group_";
538 aResName = aPrefix + QString::number( i++ );
539 anObj = aStudy->FindObject( aResName.toUtf8().data() );
542 myName->setText(aResName);
545 //=================================================================================
548 //=================================================================================
549 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
551 mySelectionMgr->installFilter(myMeshFilter);
553 /* init data from current selection */
554 restoreShowEntityMode();
555 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
557 myGroup = SMESH::SMESH_Group::_nil();
558 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
559 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
561 // NPAL19389: create a group with a selection in another group
562 // set actor of myMesh, if it is visible, else try
563 // any visible actor of group or submesh of myMesh
564 SetAppropriateActor();
566 setDefaultGroupColor();
571 mySelectionMgr->selectedObjects( aList );
572 if( !aList.IsEmpty() )
574 QString aName = aList.First()->getName();
575 myMeshGroupLine->setText(aName);//??????
576 myMeshGroupLine->home( false );
579 myCurrentLineEdit = 0;
581 myTypeGroup->button(0)->setChecked(true);
585 //=================================================================================
588 //=================================================================================
589 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
590 const bool theIsConvert)
592 restoreShowEntityMode();
593 myMesh = theGroup->GetMesh();
596 myNameChanged = true;
597 myName->blockSignals(true);
598 myName->setText(QString::fromUtf8(theGroup->GetName()));
599 myName->blockSignals(false);
602 SALOMEDS::Color aColor = theGroup->GetColor();
603 setGroupColor( aColor );
605 myMeshGroupLine->setText(QString::fromUtf8(theGroup->GetName()));
608 switch(theGroup->GetType()) {
609 case SMESH::NODE: aType = grpNodeSelection; break;
610 case SMESH::ELEM0D: aType = grp0DSelection; break;
611 case SMESH::BALL: aType = grpBallSelection; break;
612 case SMESH::EDGE: aType = grpEdgeSelection; break;
613 case SMESH::FACE: aType = grpFaceSelection; break;
614 case SMESH::VOLUME: aType = grpVolumeSelection; break;
616 myTypeGroup->button(aType)->setChecked(true);
618 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
619 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
620 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
621 myFilter = SMESH::Filter::_nil();
623 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
626 // NPAL19389: create a group with a selection in another group
627 // set actor of myMesh, if it is visible, else set
628 // actor of theGroup, if it is visible, else try
629 // any visible actor of group or submesh of myMesh
630 // commented, because an attempt to set selection on not displayed cells leads to error
631 SetAppropriateActor();
633 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
635 anActor = SMESH::FindActorByObject(theGroup);
636 SMESH::SetPickable(anActor);*/
638 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
639 myGrpTypeGroup->button(grpType)->setChecked(true);
640 onGrpTypeChanged(grpType);
643 if ( grpType == 0 ) { // standalone group
644 myCurrentLineEdit = 0;
646 myAllowElemsModif->setChecked( true );
648 setSelectionMode(aType);
650 setShowEntityMode(); // depends on myTypeId
653 if (!theGroup->IsEmpty()) {
654 SMESH::long_array_var anElements = theGroup->GetListOfID();
655 int k = anElements->length();
656 for (int i = 0; i < k; i++) {
657 myIdList.append(anElements[i]);
658 myElements->addItem(QString::number(anElements[i]));
660 myElements->selectAll();
663 else if ( grpType == 1 ) // group on geom
665 QString aShapeName( "" );
666 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
667 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
668 if (!aGroupShape->_is_nil())
670 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
672 aShapeName = aGroupShapeSO->GetName().c_str();
674 myGeomGroupLine->setText( aShapeName );
676 else // group on filter
678 myFilter = myGroupOnFilter->GetFilter();
679 if ( !myFilter->_is_nil() ) {
680 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
681 if ( perdicate->_is_nil() )
682 myFilter = SMESH::Filter::_nil();
688 myNameChanged = true;
689 myName->blockSignals(true);
690 myName->setText(QString::fromUtf8(theGroup->GetName()));
691 myName->blockSignals(false);
694 onSelectAll(); //updateButtons();
697 //=================================================================================
698 // function : updateButtons()
700 //=================================================================================
701 void SMESHGUI_GroupDlg::updateButtons()
703 bool enable = !myName->text().trimmed().isEmpty();
706 if (myGrpTypeId == 0) { // standalone
707 if ( !mySelectAll->isChecked() )
709 if ( myAllowElemsModif->isChecked() )
711 enable = ( myElements->count() > 0 );
713 else if ((enable = !myFilter->_is_nil() ))
715 SMESH::array_of_ElementType_var types = myFilter->GetTypes();
716 enable = types->length();
719 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
721 else if (myGrpTypeId == 1) // on geom
723 if (CORBA::is_nil(myGroupOnGeom)) // creation mode
724 enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
726 else if (myGrpTypeId == 2) // on filter
728 if (( enable = !myFilter->_is_nil() ))
729 if (CORBA::is_nil(myGroupOnFilter) ) // creation mode
730 enable = !myMesh->_is_nil();
734 myOKBtn->setEnabled(enable);
735 myApplyBtn->setEnabled(enable);
738 //=================================================================================
739 // function : onNameChanged()
741 //=================================================================================
742 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
744 myOldName = myName->text();
746 myNameChanged = !myName->text().trimmed().isEmpty();
749 //=================================================================================
750 // function : onTypeChanged()
751 // purpose : Group elements type radio button management
752 //=================================================================================
753 void SMESHGUI_GroupDlg::onTypeChanged (int id)
755 if (myTypeId != id) {
758 if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
759 setSelectionMode(id);
761 setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
763 onObjectSelectionChanged();
768 //=================================================================================
769 // function : onGrpTypeChanged()
770 // purpose : Group type radio button management
771 //=================================================================================
772 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
774 if (myGrpTypeId != id) {
776 myWGStack->setCurrentIndex( id );
777 myName->blockSignals(true);
778 myName->setText(myOldName);
779 myName->blockSignals(false);
780 onSelectGeomGroup(id != 0);
785 //=================================================================================
786 // function : onColorChanged()
787 // purpose : Color button management
788 //=================================================================================
789 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
794 //=================================================================================
795 // function : setSelectionMode()
796 // purpose : Radio button management
797 //=================================================================================
798 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
801 if (myMesh->_is_nil())
803 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
804 bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
805 if (mySelectionMode != theMode) {
806 // [PAL10408] mySelectionMgr->clearSelected();
807 mySelectionMgr->clearFilters();
808 SMESH::RemoveFilters();
810 if (myActorsList.count() > 0)
811 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
812 it.next()->SetPointRepresentation(false);
814 SMESH::SetPointRepresentation(false);
817 case grpNodeSelection:
818 if ( myGrpTypeId == 0 ) // standalone
820 if (myActorsList.count() > 0)
821 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
822 it.next()->SetPointRepresentation(true);
824 SMESH::SetPointRepresentation(true);
826 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
828 case grpEdgeSelection:
829 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
831 case grpBallSelection:
832 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
835 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : Elem0DSelection);
837 case grpFaceSelection:
838 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
840 case grpVolumeSelection:
841 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
843 case grpSubMeshSelection: {
845 SMESH_TypeFilter* f = 0;
847 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH); break;
848 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_EDGE); break;
849 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_FACE); break;
850 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_SOLID); break;
851 default: f = new SMESH_TypeFilter(SMESH::SUBMESH);
853 QList<SUIT_SelectionFilter*> filtList;
854 filtList.append( f );
855 filtList.append( new SMESH_TypeFilter(SMESH::SUBMESH_COMPOUND));
856 mySubMeshFilter->setFilters( filtList );
858 mySelectionMgr->installFilter( mySubMeshFilter );
860 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
863 case grpGroupSelection: {
865 SMESH_TypeFilter* f = 0;
867 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_NODE); break;
868 case grp0DSelection: f = new SMESH_TypeFilter(SMESH::GROUP_0D); break;
869 case grpBallSelection: f = new SMESH_TypeFilter(SMESH::GROUP_BALL); break;
870 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_EDGE); break;
871 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::GROUP_FACE); break;
872 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_VOLUME); break;
873 default: f = new SMESH_TypeFilter(SMESH::GROUP);
875 QList<SUIT_SelectionFilter*> filtList;
876 filtList.append( f );
877 myGroupFilter->setFilters( filtList );
879 mySelectionMgr->installFilter(myGroupFilter);
880 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
883 case grpMeshSelection:
884 mySelectionMgr->installFilter(myMeshFilter);
885 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
887 case grpGeomSelection:
888 mySelectionMgr->installFilter(myGeomFilter);
889 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
892 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
895 if ( aViewWindow ) aViewWindow->Repaint();
896 mySelectionMode = theMode;
900 //=================================================================================
901 // function : onApply()
903 //=================================================================================
904 bool SMESHGUI_GroupDlg::onApply()
906 if (mySMESHGUI->isActiveStudyLocked())
909 if (myName->text().trimmed().isEmpty())
912 SMESH::ElementType aType = SMESH::ALL;
914 case grpNodeSelection: aType = SMESH::NODE; break;
915 case grp0DSelection: aType = SMESH::ELEM0D; break;
916 case grpBallSelection: aType = SMESH::BALL; break;
917 case grpEdgeSelection: aType = SMESH::EDGE; break;
918 case grpFaceSelection: aType = SMESH::FACE; break;
919 case grpVolumeSelection: aType = SMESH::VOLUME; break;
923 QStringList anEntryList;
925 SMESH::SMESH_GroupBase_var resultGroup;
926 bool isCreation, isConversion = false;
928 SUIT_OverrideCursor wc;
930 if (myGrpTypeId == 0) // standalone
932 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
935 mySelectionMgr->clearSelected();
937 if (myGroup->_is_nil()) { // creation or conversion
938 // check if group on geometry is not null
939 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
940 if (myMesh->_is_nil())
942 if ( myGroupOnGeom->_is_nil() )
943 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
945 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
947 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
948 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
953 if (myGroup->_is_nil()) { // creation
954 if (myMesh->_is_nil())
957 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
959 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
962 if ( mySelectAll->isChecked() ) {
964 myGroup->AddFrom(myMesh.in());
969 if ( !myFilter->_is_nil() &&
970 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
972 myGroup->AddFrom( myFilter );
976 SMESH::long_array_var anIdList = new SMESH::long_array;
977 int i, k = myElements->count();
979 for (i = 0; i < k; i++) {
980 anIdList[i] = myElements->item(i)->text().toInt();
982 myGroup->Add(anIdList.inout());
989 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
992 if ( mySelectAll->isChecked() ) {
995 myGroup->AddFrom(myMesh.in());
1000 int i, total = myElements->count();
1001 for (i = 0; i < total; i++) {
1002 int anId = myElements->item(i)->text().toInt();
1003 int idx = myIdList.indexOf(anId);
1005 aAddList.append(anId);
1007 myIdList.removeAt(idx);
1009 if (!aAddList.empty()) {
1010 SMESH::long_array_var anIdList = new SMESH::long_array;
1011 int added = aAddList.count();
1012 anIdList->length(added);
1013 for (i = 0; i < added; i++)
1014 anIdList[i] = aAddList[i];
1015 myGroup->Add(anIdList.inout());
1017 if (!myIdList.empty()) {
1018 SMESH::long_array_var anIdList = new SMESH::long_array;
1019 int removed = myIdList.count();
1020 anIdList->length(removed);
1021 for (i = 0; i < removed; i++)
1022 anIdList[i] = myIdList[i];
1023 myGroup->Remove(anIdList.inout());
1025 /* init for next operation */
1027 for (i = 0; i < total; i++) {
1028 myIdList.append(myElements->item(i)->text().toInt());
1035 else if (myGrpTypeId == 1) // on geom object
1037 if (CORBA::is_nil(myGroupOnGeom)) { // creation
1038 if (myMesh->_is_nil() || !myGeomObjects->length())
1041 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1043 if (myGeomObjects->length() == 1) {
1044 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1045 myName->text().toUtf8().data(),
1049 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1050 if ( aSMESHGen->_is_nil() )
1053 // create a geometry group
1054 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1055 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1057 if (geomGen->_is_nil() || !aStudy)
1060 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
1064 // check and add all selected GEOM objects: they must be
1065 // a sub-shapes of the main GEOM and must be of one type
1066 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1067 for ( int i =0; i < myGeomObjects->length(); i++) {
1068 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1070 aGroupType = aSubShapeType;
1071 else if (aSubShapeType != aGroupType) {
1072 aGroupType = TopAbs_SHAPE;
1077 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1078 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1079 op->UnionList(aGroupVar, myGeomObjects);
1082 // publish the GEOM group in study
1083 QString aNewGeomGroupName ( "Auto_group_for_" );
1084 aNewGeomGroupName += myName->text();
1085 SALOMEDS::SObject_var aNewGroupSO =
1086 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
1087 aNewGeomGroupName.toUtf8().data(), aMeshShape);
1090 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1091 myName->text().toUtf8().data(),
1094 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1100 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1105 if (myGrpTypeId == 2) // group on filter
1107 if ( myFilter->_is_nil() ) return false;
1109 if (CORBA::is_nil(myGroupOnFilter)) { // creation
1110 if (myMesh->_is_nil())
1113 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1114 myName->text().toUtf8().data(),
1117 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1122 myGroupOnFilter->SetFilter( myFilter );
1124 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1132 SALOMEDS::Color aColor = getGroupColor();
1133 resultGroup->SetColor(aColor);
1135 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1137 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1141 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1143 /* init for the next operation */
1145 myElements->clear();
1146 myGroup = SMESH::SMESH_Group::_nil();
1147 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1148 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1149 myFilter = SMESH::Filter::_nil();
1151 setDefaultGroupColor(); // reset color for case if 'auto-color' feature is enabled.
1155 resultGroup->SetName(myName->text().toUtf8().data());
1159 if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
1161 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1162 if ( isConversion ) { // need to reset TVisualObj and actor
1163 SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
1164 SMESH::Update( anIO,true);
1165 myActorsList.clear();
1166 anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1167 if ( !anActor ) return false;
1168 myActorsList.append( anActor );
1170 anActor->setName(myName->text().toUtf8().data());
1173 switch ( myTypeId ) {
1174 case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1175 case grp0DSelection: anActor->Set0DColor ( aColor.R, aColor.G, aColor.B ); break;
1176 case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1177 case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1178 case grpVolumeSelection:
1179 SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
1180 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1182 case grpFaceSelection:
1184 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1185 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1188 // update a visible group accoding to a changed contents
1189 if ( !isConversion && anActor->GetVisibility() )
1190 SMESH::Update( anIO, true );
1194 SMESHGUI::Modified();
1195 mySMESHGUI->updateObjBrowser(true);
1196 mySelectionMgr->clearSelected();
1198 if( LightApp_Application* anApp =
1199 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1200 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1205 //=================================================================================
1206 // function : onOK()
1208 //=================================================================================
1209 void SMESHGUI_GroupDlg::onOK()
1211 setIsApplyAndClose( true );
1214 setIsApplyAndClose( false );
1216 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
1219 //=================================================================================
1220 // function : onListSelectionChanged()
1221 // purpose : Called when selection in element list is changed
1222 //=================================================================================
1223 void SMESHGUI_GroupDlg::onListSelectionChanged()
1225 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1226 if( myIsBusy || myActorsList.count() == 0 ) return;
1229 if (myCurrentLineEdit == 0) {
1230 mySelectionMgr->clearSelected();
1231 TColStd_MapOfInteger aIndexes;
1232 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1233 QListWidgetItem* anItem;
1234 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1235 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1236 SALOME_ListIO aList;
1237 aList.Append(myActorsList.first()->getIO());
1238 mySelectionMgr->setSelectedObjects(aList,false);
1243 //=================================================================================
1244 // function : onObjectSelectionChanged()
1245 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1246 //=================================================================================
1247 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1249 if ( myIsBusy || !isEnabled()) return;
1250 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1254 SALOME_ListIO aList;
1255 mySelectionMgr->selectedObjects( aList );
1257 int aNbSel = aList.Extent();
1258 myElements->clearSelection();
1260 if (myCurrentLineEdit)
1262 myCurrentLineEdit->setText( "" );
1263 QString aString = "";
1265 if (myCurrentLineEdit == myMeshGroupLine)
1267 mySelectSubMesh->setEnabled(false);
1268 mySelectGroup->setEnabled(false);
1269 myGroupLine->setText( "" );
1270 mySubMeshLine->setText( "" );
1272 myGeomGroupBtn->setEnabled(false);
1273 myGeomGroupLine->setEnabled(false);
1274 myGeomGroupLine->setText( "" );
1275 myGeomObjects = new GEOM::ListOfGO();
1276 myGeomObjects->length(0);
1278 if (myGeomGroupBtn->isChecked())
1279 myGeomGroupBtn->setChecked(false);
1281 myName->setText( "" );
1283 myElements->clear();
1286 myGroup = SMESH::SMESH_Group::_nil();
1287 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1288 restoreShowEntityMode();
1289 myMesh = SMESH::SMESH_Mesh::_nil();
1295 Handle(SALOME_InteractiveObject) IO = aList.First();
1298 restoreShowEntityMode();
1299 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1300 setShowEntityMode();
1302 if (myMesh->_is_nil())
1309 if ( myFilterDlg && !myMesh->_is_nil()){
1310 myFilterDlg->SetMesh( myMesh );
1312 myGroup = SMESH::SMESH_Group::_nil();
1314 // NPAL19389: create a group with a selection in another group
1315 // set actor of myMesh, if it is visible, else try
1316 // any visible actor of group or submesh of myMesh
1317 SetAppropriateActor();
1319 aString = aList.First()->getName();
1320 myMeshGroupLine->setText(aString);
1321 myMeshGroupLine->home( false );
1323 mySelectSubMesh->setEnabled(true);
1324 mySelectGroup->setEnabled(true);
1325 myGeomGroupBtn->setEnabled(true);
1326 myGeomGroupLine->setEnabled(true);
1330 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1331 if (aGroup->_is_nil())
1338 myGroup = SMESH::SMESH_Group::_nil();
1339 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1343 mySelectSubMesh->setEnabled(true);
1344 mySelectGroup->setEnabled(true);
1346 myCurrentLineEdit = 0;
1351 if (myGrpTypeId == 0)
1357 myElements->clear();
1358 setSelectionMode(myTypeId);
1366 else if (myCurrentLineEdit == myGeomGroupLine)
1368 myGeomObjects = new GEOM::ListOfGO();
1371 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1373 if (aNbSel == 0 || !aMeshSO)
1375 myGeomObjects->length(0);
1381 myGeomObjects->length(aNbSel);
1383 GEOM::GEOM_Object_var aGeomGroup;
1386 SALOME_ListIteratorOfListIO anIt (aList);
1387 for (; anIt.More(); anIt.Next())
1389 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1391 // Check if the object is a geometry group
1392 if (CORBA::is_nil(aGeomGroup))
1395 // Check if group constructed on the same shape as a mesh or on its child
1396 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1398 // The main shape of the group
1399 GEOM::GEOM_Object_var aGroupMainShape;
1400 if (aGeomGroup->GetType() == 37) {
1401 GEOM::GEOM_IGroupOperations_wrap anOp =
1402 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1403 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1404 // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
1407 aGroupMainShape = aGeomGroup;
1408 aGroupMainShape->Register();
1410 _PTR(SObject) aGroupMainShapeSO =
1411 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1413 _PTR(SObject) anObj, aRef;
1414 bool isRefOrSubShape = false;
1415 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1416 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1417 isRefOrSubShape = true;
1419 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1420 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1421 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1422 if (aRef->GetID() == aFather->GetID())
1423 isRefOrSubShape = true;
1425 aFather = aFather->GetFather();
1429 if (isRefOrSubShape)
1430 myGeomObjects[i++] = aGeomGroup;
1433 myGeomObjects->length(i);
1445 if (myCurrentLineEdit == mySubMeshLine)
1446 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1447 else if (myCurrentLineEdit == myGroupLine)
1448 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1449 else if (myCurrentLineEdit == myGeomGroupLine)
1450 aString = tr( "%1 Objects" ).arg(aNbSel);
1453 aString = aList.First()->getName();
1457 myCurrentLineEdit->setText(aString);
1458 myCurrentLineEdit->home(false);
1459 // 07.06.2008 skl for IPAL19574:
1460 // change name of group only if it is empty
1461 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1462 myOldName = myName->text();
1463 myName->blockSignals(true);
1464 myName->setText(aString);
1465 myName->blockSignals(false);
1470 else // !myCurrentLineEdit: local selection of nodes or elements
1472 if (aNbSel == 1 && myActorsList.count() > 0 )
1474 // NPAL19389: create a group with a selection in another group
1475 // Switch myActor to the newly selected one, if the last
1476 // is visible and belongs to group or submesh of myMesh
1477 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1478 Handle(SALOME_InteractiveObject) selIO = aList.First();
1479 if (curIO->hasEntry() && selIO->hasEntry()) {
1480 const char* selEntry = selIO->getEntry();
1481 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1482 // different objects: selected and myActor
1483 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1484 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1485 // newly selected actor is visible
1488 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1490 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1491 int len = strlen(meshEntry);
1493 if (strncmp(selEntry, meshEntry, len) == 0) {
1494 // selected object is myMesh or a part of it
1495 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1498 SMESH::SetPickable(myActor);
1507 QString aListStr = "";
1509 if (myTypeId == 0) {
1510 QListIterator<SMESH_Actor*> it( myActorsList );
1511 while ( it.hasNext() ) {
1513 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1517 QListIterator<SMESH_Actor*> it( myActorsList );
1518 while ( it.hasNext() ) {
1520 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1525 QListWidgetItem* anItem;
1526 QList<QListWidgetItem*> listItemsToSel;
1527 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1528 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1529 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1530 foreach(anItem, found)
1531 if (!anItem->isSelected())
1532 listItemsToSel.push_back(anItem);
1534 bool blocked = myElements->signalsBlocked();
1535 myElements->blockSignals(true);
1536 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1537 myElements->blockSignals(blocked);
1538 onListSelectionChanged();
1539 listItemsToSel.clear();
1544 if (myActorsList.count() == 0) {
1545 if (!myGroup->_is_nil()) {
1546 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1548 myActorsList.append( anActor );
1550 else if(!myGroupOnGeom->_is_nil()) {
1551 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1553 myActorsList.append( anActor );
1556 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1558 myActorsList.append( anActor );
1562 // somehow, if we display the mesh, while selecting from another actor,
1563 // the mesh becomes pickable, and there is no way to select any element
1564 if (myActorsList.count() > 0) {
1565 QListIterator<SMESH_Actor*> it( myActorsList );
1566 while ( it.hasNext() ) {
1567 SMESH_Actor* anActor = it.next();
1568 if ( IsActorVisible(anActor) )
1569 anActor->SetPickable(true);
1576 //=================================================================================
1577 // function : onSelectAll()
1578 // purpose : Called when "Select all" is checked
1579 //=================================================================================
1580 void SMESHGUI_GroupDlg::onSelectAll()
1582 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1584 myElementsLab->setEnabled( !noElemsModif );
1585 myElements->setEnabled ( !noElemsModif );
1586 myFilterBtn->setEnabled ( !noElemsModif );
1587 myAddBtn->setEnabled ( !noElemsModif );
1588 myRemoveBtn->setEnabled ( !noElemsModif );
1589 mySortBtn->setEnabled ( !noElemsModif );
1590 mySelectBox->setEnabled ( !noElemsModif );
1591 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1593 int selMode = mySelectionMode;
1594 mySelectionMode = grpNoSelection;
1595 setSelectionMode( selMode );
1599 //=================================================================================
1600 // function : onSelectSubMesh()
1601 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1602 //=================================================================================
1603 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1606 if (mySelectGroup->isChecked()) {
1607 mySelectGroup->setChecked(false);
1609 //VSR: else if (mySelectGeomGroup->isChecked()) {
1610 //VSR: mySelectGeomGroup->setChecked(false);
1612 myCurrentLineEdit = mySubMeshLine;
1613 setSelectionMode(grpSubMeshSelection);
1616 mySubMeshLine->setText( "" );
1617 myCurrentLineEdit = 0;
1619 setSelectionMode(myTypeId);
1621 mySubMeshBtn->setEnabled(on);
1622 mySubMeshLine->setEnabled(on);
1626 //=================================================================================
1627 // function : (onSelectGroup)
1628 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1629 //=================================================================================
1630 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1633 if (mySelectSubMesh->isChecked()) {
1634 mySelectSubMesh->setChecked(false);
1636 myCurrentLineEdit = myGroupLine;
1637 setSelectionMode(grpGroupSelection);
1640 myGroupLine->setText( "" );
1641 myCurrentLineEdit = 0;
1643 setSelectionMode(myTypeId);
1645 myGroupBtn->setEnabled(on);
1646 myGroupLine->setEnabled(on);
1650 //=================================================================================
1651 // function : (onSelectGeomGroup)
1652 // purpose : Called when group type changed. on == "on geometry" or "on filter"
1653 //=================================================================================
1654 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1657 if (mySelectSubMesh->isChecked()) {
1658 mySelectSubMesh->setChecked(false);
1660 else if (mySelectGroup->isChecked()) {
1661 mySelectGroup->setChecked(false);
1663 if ( myGrpTypeId == 1 ) { // on geometry
1664 myCurrentLineEdit = myGeomGroupLine;
1668 myCurrentLineEdit = 0;
1670 setSelectionMode(grpAllSelection);
1673 myGeomGroupBtn->setChecked(false);
1674 myGeomObjects->length(0);
1675 myGeomGroupLine->setText( "" );
1676 myCurrentLineEdit = 0;
1678 setSelectionMode( myTypeId );
1682 //=================================================================================
1683 // function : setCurrentSelection()
1685 //=================================================================================
1686 void SMESHGUI_GroupDlg::setCurrentSelection()
1688 QPushButton* send = (QPushButton*)sender();
1689 myCurrentLineEdit = 0;
1690 if (send == myMeshGroupBtn) {
1691 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1692 mySelectionMgr->clearSelected();
1694 setSelectionMode(grpMeshSelection);
1696 setSelectionMode(grpGroupSelection);
1697 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1698 myCurrentLineEdit = myMeshGroupLine;
1699 onObjectSelectionChanged();
1701 else if (send == mySubMeshBtn) {
1702 myCurrentLineEdit = mySubMeshLine;
1703 onObjectSelectionChanged();
1705 else if (send == myGroupBtn) {
1706 myCurrentLineEdit = myGroupLine;
1707 onObjectSelectionChanged();
1712 //=================================================================================
1713 // function : setFilters()
1714 // purpose : SLOT. Called when "Filter" button pressed.
1715 //=================================================================================
1716 void SMESHGUI_GroupDlg::setFilters()
1718 if(myMesh->_is_nil()) {
1719 SUIT_MessageBox::critical(this,
1721 tr("NO_MESH_SELECTED"));
1725 SMESH::ElementType aType = SMESH::ALL;
1728 case grpNodeSelection: aType = SMESH::NODE; break;
1729 case grp0DSelection: aType = SMESH::ELEM0D; break;
1730 case grpBallSelection: aType = SMESH::BALL; break;
1731 case grpEdgeSelection: aType = SMESH::EDGE; break;
1732 case grpFaceSelection: aType = SMESH::FACE; break;
1733 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1737 if ( myFilterDlg == 0 )
1739 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1740 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1743 myFilterDlg->Init( aType );
1745 if ( !myGroupOnFilter->_is_nil() )
1747 myFilterDlg->SetFilter( myFilter, aType );
1748 myFilterDlg->Init( aType );
1751 bool isStandalone = ( sender() == myFilterBtn );
1752 myFilterDlg->SetEnabled( /*setInViewer=*/isStandalone,
1753 /*diffSources=*/isStandalone );
1754 myFilterDlg->SetMesh( myMesh );
1755 myFilterDlg->SetSelection();
1756 myFilterDlg->SetSourceWg( myElements, false );
1759 myFilterDlg->show();
1762 //=================================================================================
1763 // function : onFilterAccepted()
1764 // purpose : SLOT. Called when Filter dlg closed with OK button.
1765 // Uncheck "Select submesh" and "Select group" checkboxes
1766 //=================================================================================
1767 void SMESHGUI_GroupDlg::onFilterAccepted()
1769 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1771 mySelectionMode = myTypeId;
1772 mySelectSubMesh->setChecked( false );
1773 mySelectGroup->setChecked( false );
1775 // get a filter from myFilterDlg
1776 myFilter = myFilterDlg->GetFilter();
1777 if ( !myFilter->_is_nil() ) {
1778 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1779 if ( perdicate->_is_nil() )
1780 myFilter = SMESH::Filter::_nil();
1782 // set mesh to myFilter
1783 if ( !myFilter->_is_nil() ) {
1784 SMESH::SMESH_Mesh_var mesh = myMesh;
1785 if ( mesh->_is_nil() ) {
1786 if ( !myGroup->_is_nil() )
1787 mesh = myGroup->GetMesh();
1788 else if ( !myGroupOnGeom->_is_nil() )
1789 mesh = myGroupOnGeom->GetMesh();
1790 else if ( !myGroupOnFilter->_is_nil() )
1791 mesh = myGroupOnFilter->GetMesh();
1793 myFilter->SetMesh( mesh );
1799 //=================================================================================
1800 // function : onAdd()
1802 //=================================================================================
1803 void SMESHGUI_GroupDlg::onAdd()
1805 SALOME_ListIO aList;
1806 mySelectionMgr->selectedObjects( aList );
1808 int aNbSel = aList.Extent();
1810 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1813 int sizeBefore = myElements->count();
1815 SMESH::ElementType aType = SMESH::ALL;
1817 case grpNodeSelection:
1818 aType = SMESH::NODE;
1819 mySelector->SetSelectionMode(NodeSelection);
1821 case grpBallSelection:
1822 aType = SMESH::BALL;
1823 mySelector->SetSelectionMode(BallSelection);
1825 case grp0DSelection:
1826 aType = SMESH::ELEM0D;
1827 mySelector->SetSelectionMode(Elem0DSelection);
1829 case grpEdgeSelection:
1830 aType = SMESH::EDGE;
1831 mySelector->SetSelectionMode(EdgeSelection);
1833 case grpFaceSelection:
1834 aType = SMESH::FACE;
1835 mySelector->SetSelectionMode(FaceSelection);
1837 case grpVolumeSelection:
1838 aType = SMESH::VOLUME;
1839 mySelector->SetSelectionMode(VolumeSelection);
1842 mySelector->SetSelectionMode(ActorSelection);
1845 QListWidgetItem* anItem = 0;
1846 QList<QListWidgetItem*> listItemsToSel;
1848 if (myCurrentLineEdit == 0) {
1849 //if (aNbSel != 1) { myIsBusy = false; return; }
1850 QString aListStr = "";
1852 if (myTypeId == 0) {
1853 QListIterator<SMESH_Actor*> it( myActorsList );
1854 while ( it.hasNext() ) {
1856 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1861 QListIterator<SMESH_Actor*> it( myActorsList );
1862 while ( it.hasNext() ) {
1864 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1869 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1870 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1871 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1872 if (found.count() == 0) {
1873 anItem = new QListWidgetItem(*it);
1874 myElements->addItem(anItem);
1875 if (!anItem->isSelected())
1876 listItemsToSel.push_back(anItem);
1879 foreach(anItem, found)
1880 if (!anItem->isSelected())
1881 listItemsToSel.push_back(anItem);
1884 bool blocked = myElements->signalsBlocked();
1885 myElements->blockSignals(true);
1886 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1887 myElements->blockSignals(blocked);
1888 onListSelectionChanged();
1889 listItemsToSel.clear();
1891 } else if (myCurrentLineEdit == mySubMeshLine) {
1892 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1894 SALOME_ListIO aList;
1895 mySelectionMgr->selectedObjects( aList );
1897 SALOME_ListIteratorOfListIO anIt (aList);
1898 for ( ; anIt.More(); anIt.Next()) {
1899 SMESH::SMESH_subMesh_var aSubMesh =
1900 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1901 if (!aSubMesh->_is_nil()) {
1902 // check if mesh is the same
1903 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1905 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1906 int k = anElements->length();
1907 for (int i = 0; i < k; i++) {
1908 QString aText = QString::number(anElements[i]);
1909 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1910 if (found.count() == 0) {
1911 anItem = new QListWidgetItem(aText);
1912 myElements->addItem(anItem);
1913 if (!anItem->isSelected())
1914 listItemsToSel.push_back(anItem);
1917 foreach(anItem, found)
1918 if (!anItem->isSelected())
1919 listItemsToSel.push_back(anItem);
1922 bool blocked = myElements->signalsBlocked();
1923 myElements->blockSignals(true);
1924 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1925 myElements->blockSignals(blocked);
1926 onListSelectionChanged();
1927 listItemsToSel.clear();
1929 catch (const SALOME::SALOME_Exception& ex) {
1930 SalomeApp_Tools::QtCatchCorbaException(ex);
1935 mySelectSubMesh->setChecked(false);
1937 onListSelectionChanged();
1939 } else if (myCurrentLineEdit == myGroupLine) {
1940 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1941 SALOME_ListIO aList;
1942 mySelectionMgr->selectedObjects( aList );
1944 SALOME_ListIteratorOfListIO anIt (aList);
1945 for ( ; anIt.More(); anIt.Next()) {
1946 SMESH::SMESH_GroupBase_var aGroup =
1947 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1948 if (!aGroup->_is_nil()) {
1949 // check if mesh is the same
1950 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1951 SMESH::long_array_var anElements = aGroup->GetListOfID();
1952 int k = anElements->length();
1953 for (int i = 0; i < k; i++) {
1954 QString aText = QString::number(anElements[i]);
1955 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1956 if (found.count() == 0) {
1957 anItem = new QListWidgetItem(aText);
1958 myElements->addItem(anItem);
1959 if (!anItem->isSelected())
1960 listItemsToSel.push_back(anItem);
1963 foreach(anItem, found)
1964 if (!anItem->isSelected())
1965 listItemsToSel.push_back(anItem);
1968 bool blocked = myElements->signalsBlocked();
1969 myElements->blockSignals(true);
1970 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1971 myElements->blockSignals(blocked);
1972 onListSelectionChanged();
1973 listItemsToSel.clear();
1977 mySelectGroup->setChecked(false);
1979 onListSelectionChanged();
1981 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1982 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1983 GEOM::GEOM_IGroupOperations_wrap aGroupOp =
1984 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1986 SMESH::ElementType aGroupType = SMESH::ALL;
1987 switch(aGroupOp->GetType(myGeomObjects[0])) {
1988 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
1989 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
1990 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
1991 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
1992 default: myIsBusy = false; return;
1995 if (aGroupType == aType) {
1996 _PTR(SObject) aGroupSO =
1997 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1998 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
2000 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2001 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
2002 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
2003 aBelongToGeom->SetGeom(myGeomObjects[0]);
2004 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
2005 aBelongToGeom->SetElementType(aType);
2006 aFilter->SetPredicate(aBelongToGeom);
2008 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
2010 int k = anElements->length();
2011 for (int i = 0; i < k; i++) {
2012 QString aText = QString::number(anElements[i]);
2013 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2014 if (found.count() == 0) {
2015 anItem = new QListWidgetItem(aText);
2016 myElements->addItem(anItem);
2017 if (!anItem->isSelected())
2018 listItemsToSel.push_back(anItem);
2021 foreach(anItem, found)
2022 if (!anItem->isSelected())
2023 listItemsToSel.push_back(anItem);
2026 bool blocked = myElements->signalsBlocked();
2027 myElements->blockSignals(true);
2028 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2029 myElements->blockSignals(blocked);
2030 onListSelectionChanged();
2031 listItemsToSel.clear();
2034 //VSR: mySelectGeomGroup->setChecked(false);
2036 onListSelectionChanged();
2039 if ( sizeBefore < myElements->count() )
2040 ++myNbChangesOfContents;
2041 // mySelectionMgr->clearSelected();
2045 //=================================================================================
2046 // function : onRemove()
2048 //=================================================================================
2049 void SMESHGUI_GroupDlg::onRemove()
2052 int sizeBefore = myElements->count();
2054 if (myCurrentLineEdit == 0) {
2055 QList<QListWidgetItem*> selItems = myElements->selectedItems();
2056 QListWidgetItem* item;
2057 foreach(item, selItems) delete item;
2059 SALOME_ListIO aList;
2060 mySelectionMgr->selectedObjects( aList );
2062 int aNbSel = aList.Extent();
2064 if (aNbSel == 0) { myIsBusy = false; return; }
2066 SMESH::ElementType aType = SMESH::ALL;
2068 case grpNodeSelection: aType = SMESH::NODE; break;
2069 case grp0DSelection: aType = SMESH::ELEM0D; break;
2070 case grpBallSelection: aType = SMESH::BALL; break;
2071 case grpEdgeSelection: aType = SMESH::EDGE; break;
2072 case grpFaceSelection: aType = SMESH::FACE; break;
2073 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2076 if (myCurrentLineEdit == mySubMeshLine) {
2077 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2078 SALOME_ListIO aList;
2079 mySelectionMgr->selectedObjects( aList );
2081 SALOME_ListIteratorOfListIO anIt (aList);
2082 for ( ; anIt.More(); anIt.Next()) {
2083 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2084 if (!aSubMesh->_is_nil()) {
2085 // check if mesh is the same
2086 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2087 if (aType == SMESH::NODE) {
2089 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2090 int k = anElements->length();
2091 for (int i = 0; i < k; i++) {
2092 QList<QListWidgetItem*> found =
2093 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2094 QListWidgetItem* anItem;
2095 foreach(anItem, found) delete anItem;
2098 catch (const SALOME::SALOME_Exception& ex) {
2099 SalomeApp_Tools::QtCatchCorbaException(ex);
2104 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
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;
2113 catch (const SALOME::SALOME_Exception& ex) {
2114 SalomeApp_Tools::QtCatchCorbaException(ex);
2121 else if (myCurrentLineEdit == myGroupLine) {
2122 Standard_Boolean aRes;
2123 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2124 SALOME_ListIO aList;
2125 mySelectionMgr->selectedObjects( aList );
2127 SALOME_ListIteratorOfListIO anIt (aList);
2128 for ( ; anIt.More(); anIt.Next()) {
2129 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2130 if (aRes && !aGroup->_is_nil()) {
2131 // check if mesh is the same
2132 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2133 SMESH::long_array_var anElements = aGroup->GetListOfID();
2134 int k = anElements->length();
2135 for (int i = 0; i < k; i++) {
2136 QList<QListWidgetItem*> found =
2137 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2138 QListWidgetItem* anItem;
2139 foreach(anItem, found) delete anItem;
2147 if ( sizeBefore > myElements->count() )
2148 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2152 //=================================================================================
2153 // function : onSort()
2155 //=================================================================================
2156 void SMESHGUI_GroupDlg::onSort()
2158 // PAL5412: sorts items in ascending by "string" value
2159 // myElements->sort(true);
2160 // myElements->update();
2161 int i, k = myElements->count();
2164 QList<int> aSelected;
2165 std::vector<int> anArray(k);
2166 // QMemArray<int> anArray(k);
2168 for (i = 0; i < k; i++) {
2169 int id = myElements->item(i)->text().toInt();
2171 if (myElements->item(i)->isSelected())
2172 aSelected.append(id);
2174 // sort & update list
2175 std::sort(anArray.begin(), anArray.end());
2177 myElements->clear();
2178 QListWidgetItem* anItem;
2179 QList<QListWidgetItem*> listItemsToSel;
2180 for (i = 0; i < k; i++) {
2181 anItem = new QListWidgetItem(QString::number(anArray[i]));
2182 myElements->addItem(anItem);
2183 if (aSelected.contains(anArray[i]))
2184 listItemsToSel.push_back(anItem);
2186 bool blocked = myElements->signalsBlocked();
2187 myElements->blockSignals(true);
2188 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2189 myElements->blockSignals(blocked);
2190 listItemsToSel.clear();
2195 //=================================================================================
2196 // function : onVisibilityChanged()
2198 //=================================================================================
2199 void SMESHGUI_GroupDlg::onVisibilityChanged()
2201 SetAppropriateActor();
2204 //=================================================================================
2205 // function : SMESHGUI_GroupDlg::reject
2206 // purpose : SLOT called when "Close" button pressed. Close dialog
2207 //=================================================================================
2208 void SMESHGUI_GroupDlg::reject()
2210 if (SMESH::GetCurrentVtkView()) {
2211 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2212 SMESH::SetPointRepresentation(false);
2213 SMESH::SetPickable();
2214 restoreShowEntityMode();
2217 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2218 SUIT_DataOwnerPtrList aList;
2219 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2220 mySelectionMgr->setSelected( aList );
2223 mySelectionMgr->clearSelected();
2224 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2225 aViewWindow->SetSelectionMode(ActorSelection);
2226 mySelectionMgr->clearFilters();
2227 mySMESHGUI->ResetState();
2231 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
2234 //=================================================================================
2235 // function : onHelp()
2237 //=================================================================================
2238 void SMESHGUI_GroupDlg::onHelp()
2240 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2242 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2246 platform = "winapplication";
2248 platform = "application";
2250 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2251 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2252 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2254 arg(myHelpFileName));
2258 //=================================================================================
2259 // function : SMESHGUI_GroupDlg::onDeactivate
2260 // purpose : SLOT called when dialog must be deativated
2261 //=================================================================================
2262 void SMESHGUI_GroupDlg::onDeactivate()
2264 mySMESHGUI->ResetState();
2268 //=================================================================================
2269 // function : SMESHGUI_GroupDlg::enterEvent
2270 // purpose : Event filter
2271 //=================================================================================
2272 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2275 mySMESHGUI->EmitSignalDeactivateDialog();
2277 mySelectionMode = grpNoSelection;
2278 setSelectionMode(myTypeId);
2279 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2280 mySMESHGUI->SetActiveDialogBox(this);
2281 mySMESHGUI->SetState(800);
2285 //=================================================================================
2286 // function : keyPressEvent()
2288 //=================================================================================
2289 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2291 QDialog::keyPressEvent( e );
2292 if ( e->isAccepted() )
2295 if ( e->key() == Qt::Key_F1 )
2302 //================================================================================
2304 * \brief Enable showing of the popup when Geometry selection btn is clicked
2305 * \param enable - true to enable
2307 //================================================================================
2309 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2311 void SMESHGUI_GroupDlg::updateGeomPopup()
2313 bool enable = false;
2315 if ( !myMesh->_is_nil() )
2316 enable = myMesh->NbEdges() > 0;
2318 if ( myGeomGroupBtn )
2320 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2322 if ( !myGeomPopup ) {
2323 myGeomPopup = new QMenu(this);
2324 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2325 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2326 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2328 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2334 //=================================================================================
2335 // function : onGeomSelectionButton()
2337 //=================================================================================
2338 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2340 if ( myGeomPopup && isBtnOn )
2342 myCurrentLineEdit = myGeomGroupLine;
2343 QAction* a = myGeomPopup->exec( QCursor::pos() );
2344 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2345 setSelectionMode(grpGeomSelection);
2349 myCurrentLineEdit = 0;
2350 setSelectionMode(grpAllSelection);
2354 //=================================================================================
2355 // function : onGeomPopup()
2357 //=================================================================================
2358 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2360 int index = myActions[a];
2361 if ( index == GEOM_BY_MESH_INDEX )
2363 mySelectionMode = grpNoSelection;
2364 if ( !myShapeByMeshOp ) {
2365 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2366 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2367 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2368 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2369 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2371 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2372 if ( !myMesh->_is_nil() ) {
2374 hide(); // stop processing selection
2376 myShapeByMeshOp->setModule( mySMESHGUI );
2377 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2378 myShapeByMeshOp->SetMesh( myMesh );
2379 myShapeByMeshOp->start();
2384 //================================================================================
2386 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2388 //================================================================================
2390 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2392 if ( myShapeByMeshOp == op ) {
2393 mySMESHGUI->getApp()->updateObjectBrowser();
2395 // Select a found geometry object
2396 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2397 if ( !aGeomVar->_is_nil() )
2399 QString ID = aGeomVar->GetStudyEntry();
2400 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2401 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2402 SALOME_ListIO anIOList;
2403 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2404 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2405 anIOList.Append( anIO );
2406 mySelectionMgr->setSelectedObjects( anIOList, false );
2407 onObjectSelectionChanged();
2413 //================================================================================
2415 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2417 //================================================================================
2419 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2421 if ( myShapeByMeshOp == op )
2424 setSelectionMode(grpGeomSelection);
2428 //=================================================================================
2429 // function : setGroupColor()
2431 //=================================================================================
2432 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2434 QColor aQColor( (int)( theColor.R * 255.0 ),
2435 (int)( theColor.G * 255.0 ),
2436 (int)( theColor.B * 255.0 ) );
2437 setGroupQColor( aQColor );
2440 //=================================================================================
2441 // function : getGroupColor()
2443 //=================================================================================
2444 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2446 QColor aQColor = getGroupQColor();
2448 SALOMEDS::Color aColor;
2449 aColor.R = (float)aQColor.red() / 255.0;
2450 aColor.G = (float)aQColor.green() / 255.0;
2451 aColor.B = (float)aQColor.blue() / 255.0;
2456 //=================================================================================
2457 // function : setGroupQColor()
2459 //=================================================================================
2460 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2462 if( theColor.isValid() )
2463 myColorBtn->setColor( theColor );
2466 //=================================================================================
2467 // function : getGroupQColor()
2469 //=================================================================================
2470 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2472 return myColorBtn->color();
2475 //=================================================================================
2476 // function : setDefaultGroupColor()
2478 //=================================================================================
2479 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2481 if( myMesh->_is_nil() )
2484 bool isAutoColor = myMesh->GetAutoColor();
2486 QColor aQColor = myColorBtn->color();
2489 if ( !aQColor.isValid() ) {
2490 int r = 0, g = 0, b = 0;
2491 SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2492 aQColor.setRgb( r, g, b );
2497 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2498 SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
2499 #else // old algorithm for auto-colors
2500 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2502 QList<SALOMEDS::Color> aReservedColors;
2503 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2505 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2506 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2507 aReservedColors.append( aReservedColor );
2510 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2511 #endif // SIMPLE_AUTOCOLOR
2513 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2514 (int)( aColor.G * 255.0 ),
2515 (int)( aColor.B * 255.0 ) );
2519 setGroupQColor( aQColor );
2522 //=================================================================================
2523 // function : SetAppropriateActor()
2524 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2525 // NPAL19389: create a group with a selection in another group.
2526 // if mesh actor is not visible - find any first visible group or submesh
2527 //=================================================================================
2528 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2530 bool isActor = false;
2531 myActorsList.clear();
2533 if (myMesh->_is_nil()) return false;
2535 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2537 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2539 if (!myGroupOnGeom->_is_nil()) {
2540 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2541 if (anActor && anActor->hasIO())
2544 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2547 myActorsList.append(anActor);
2553 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2554 if (anActor && anActor->hasIO()) {
2556 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2559 myActorsList.append(anActor);
2563 if (!isActor && !myGroup->_is_nil()) {
2564 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2565 if (anActor && anActor->hasIO())
2566 myActorsList.append(anActor);
2569 // try any visible actor of group or submesh of current mesh
2572 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2574 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2575 int len = strlen(meshEntry);
2577 // iterate on all actors in current view window, search for
2578 // any visible actor, that belongs to group or submesh of current mesh
2579 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2580 vtkActorCollection *aCollection = aCopy.GetActors();
2581 int nbItems = aCollection->GetNumberOfItems();
2582 for (int i=0; i<nbItems && !isActor; i++)
2584 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2585 if (anActor && anActor->hasIO()) {
2586 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2587 if (aViewWindow->isVisible(anIO)) {
2588 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2589 myActorsList.append(anActor);
2597 if (myActorsList.count() > 0) {
2598 QListIterator<SMESH_Actor*> it( myActorsList );
2599 while ( it.hasNext() ) {
2600 SMESH_Actor* anActor = it.next();
2601 if ( IsActorVisible(anActor) )
2602 anActor->SetPickable(true);
2606 return ( isActor || (myActorsList.count() > 0) );
2609 //=======================================================================
2610 //function : setShowEntityMode
2611 //purpose : make shown only entity corresponding to my type
2612 //=======================================================================
2613 void SMESHGUI_GroupDlg::setShowEntityMode()
2615 if ( !myMesh->_is_nil() ) {
2616 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2617 if (!myStoredShownEntity)
2618 myStoredShownEntity = actor->GetEntityMode();
2619 switch ( myTypeId ) {
2620 case grpNodeSelection: restoreShowEntityMode(); break;
2621 case grp0DSelection: actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
2622 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2623 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2624 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2625 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2631 //=======================================================================
2632 //function : restoreShowEntityMode
2633 //purpose : restore ShowEntity mode of myActor
2634 //=======================================================================
2635 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2637 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2638 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2639 actor->SetEntityMode(myStoredShownEntity);
2642 myStoredShownEntity = 0;
2645 //=======================================================================
2646 //function : IsActorVisible
2647 //purpose : return visibility of the actor
2648 //=======================================================================
2649 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2651 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2652 if (theActor && aViewWindow)
2653 return aViewWindow->isVisible(theActor->getIO());
2657 //================================================================
2658 //function : setIsApplyAndClose
2659 //purpose : Set value of the flag indicating that the dialog is
2660 // accepted by Apply & Close button
2661 //================================================================
2662 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2664 myIsApplyAndClose = theFlag;
2667 //================================================================
2668 //function : isApplyAndClose
2669 //purpose : Get value of the flag indicating that the dialog is
2670 // accepted by Apply & Close button
2671 //================================================================
2672 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2674 return myIsApplyAndClose;