1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_GroupDlg.cxx
25 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
28 #include "SMESHGUI_GroupDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_GroupUtils.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
36 #include "SMESHGUI_FilterDlg.h"
37 #include "SMESHGUI_ShapeByMeshDlg.h"
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_Actor.h>
41 #include <SMESH_ActorUtils.h>
42 #include <SMESH_LogicalFilter.hxx>
44 // SALOME GEOM includes
46 #include <GEOM_SelectionFilter.h>
48 // SALOME GUI includes
49 #include <QtxColorButton.h>
51 #include <SUIT_Desktop.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SUIT_Session.h>
54 #include <SUIT_MessageBox.h>
56 #include <SalomeApp_Tools.h>
57 #include <SalomeApp_Application.h>
58 #include <SalomeApp_Study.h>
59 #include <LightApp_SelectionMgr.h>
61 #include <SALOME_ListIO.hxx>
62 #include <SALOME_ListIteratorOfListIO.hxx>
64 #include <SVTK_ViewWindow.h>
66 #include <VTKViewer_Algorithm.h>
68 // SALOME KERNEL includes
69 #include <SALOMEDSClient_Study.hxx>
72 #include <vtkRenderer.h>
73 #include <vtkActorCollection.h>
76 #include <TColStd_MapOfInteger.hxx>
79 #include <QButtonGroup>
83 #include <QPushButton>
84 #include <QToolButton>
85 #include <QRadioButton>
87 #include <QGridLayout>
88 #include <QHBoxLayout>
89 #include <QVBoxLayout>
90 #include <QListWidget>
91 #include <QStackedWidget>
103 enum grpSelectionMode {
105 grpNodeSelection = 0,
106 grpBallSelection = 1,
107 grpEdgeSelection = 2,
108 grpFaceSelection = 3,
109 grpVolumeSelection = 4,
110 grpSubMeshSelection = 5,
111 grpGroupSelection = 6,
112 grpMeshSelection = 7,
113 grpGeomSelection = 8,
117 //=================================================================================
118 // function : SMESHGUI_GroupDlg()
120 //=================================================================================
121 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
122 SMESH::SMESH_Mesh_ptr theMesh )
123 : QDialog( SMESH::GetDesktop( theModule ) ),
124 mySMESHGUI( theModule ),
125 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
126 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
128 myNameChanged( false ),
129 myIsApplyAndClose( false ),
130 myNbChangesOfContents(0)
133 if ( !theMesh->_is_nil() )
137 mySelectSubMesh->setEnabled( false );
138 mySelectGroup->setEnabled( false );
139 myGeomGroupBtn->setEnabled( false );
140 myGeomGroupLine->setEnabled( false );
144 //=================================================================================
145 // function : SMESHGUI_GroupDlg()
147 //=================================================================================
148 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
149 SMESH::SMESH_GroupBase_ptr theGroup,
150 const bool theIsConvert )
151 : QDialog( SMESH::GetDesktop( theModule ) ),
152 mySMESHGUI( theModule ),
153 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
154 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
156 myNameChanged( false ),
157 myNbChangesOfContents(0) // just not to use uninitialized variable
160 if ( !theGroup->_is_nil() )
161 init( theGroup, theIsConvert );
164 mySelectSubMesh->setEnabled( false );
165 mySelectGroup->setEnabled( false );
167 myCurrentLineEdit = myMeshGroupLine;
168 setSelectionMode( grpGroupSelection );
172 //=================================================================================
173 // function : SMESHGUI_GroupDlg()
175 //=================================================================================
176 void SMESHGUI_GroupDlg::initDialog( bool create)
179 setAttribute( Qt::WA_DeleteOnClose, true );
183 myCurrentLineEdit = 0;
187 myGeomObjects = new GEOM::ListOfGO();
188 myGeomObjects->length( 0 );
190 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
192 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
193 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
195 setSizeGripEnabled( true);
197 QGridLayout* aMainLayout = new QGridLayout( this );
198 aMainLayout->setMargin( MARGIN );
199 aMainLayout->setSpacing( SPACING );
201 /***************************************************************/
202 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
203 myMeshGroupBtn = new QPushButton( this );
204 myMeshGroupBtn->setIcon( image0 );
205 myMeshGroupLine = new QLineEdit( this );
206 myMeshGroupLine->setReadOnly( true );
208 /***************************************************************/
209 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
210 myTypeGroup = new QButtonGroup( this );
211 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
212 aTypeBoxLayout->setMargin( MARGIN );
213 aTypeBoxLayout->setSpacing( SPACING );
216 types.append( tr( "MESH_NODE" ) );
217 types.append( tr( "SMESH_BALL_ELEM" ) );
218 types.append( tr( "SMESH_EDGE" ) );
219 types.append( tr( "SMESH_FACE" ) );
220 types.append( tr( "SMESH_VOLUME" ) );
222 for ( int i = 0; i < types.count(); i++ )
224 rb = new QRadioButton( types[i], aTypeBox );
225 myTypeGroup->addButton( rb, i );
226 aTypeBoxLayout->addWidget( rb );
228 aTypeBox->setEnabled( create );
231 /***************************************************************/
232 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
233 aName->setMinimumWidth( 50 );
234 myName = new QLineEdit( this );
236 /***************************************************************/
237 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
238 myGrpTypeGroup = new QButtonGroup( this );
239 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
240 aGrpTypeBoxLayout->setMargin( MARGIN );
241 aGrpTypeBoxLayout->setSpacing( SPACING );
243 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
244 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
245 QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox );
246 myGrpTypeGroup->addButton( rb1, 0 );
247 myGrpTypeGroup->addButton( rb2, 1 );
248 myGrpTypeGroup->addButton( rb3, 2 );
249 aGrpTypeBoxLayout->addWidget( rb1 );
250 aGrpTypeBoxLayout->addWidget( rb2 );
251 aGrpTypeBoxLayout->addWidget( rb3 );
252 aGrpTypeBox->setEnabled( create );
255 /***************************************************************/
256 myWGStack = new QStackedWidget( this );
257 QWidget* wg1 = new QWidget( myWGStack );
258 QWidget* wg2 = new QWidget( myWGStack );
259 QWidget* wg3 = new QWidget( myWGStack );
261 /***************************************************************/
262 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
263 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
264 aContentBoxLayout->setMargin( MARGIN );
265 aContentBoxLayout->setSpacing( SPACING );
267 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
268 myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
270 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
271 myElements = new QListWidget( aContentBox );
272 myElements->setSelectionMode( QListWidget::ExtendedSelection );
274 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
275 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
276 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
277 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
279 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
280 aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
281 aContentBoxLayout->addWidget( myFilterBtn, 1, 1 );
282 aContentBoxLayout->addWidget( myElementsLab, 2, 0 );
283 aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 );
284 aContentBoxLayout->addWidget( myAddBtn, 3, 1 );
285 aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 );
286 aContentBoxLayout->addWidget( mySortBtn, 8, 1 );
288 aContentBoxLayout->setColumnStretch( 0, 1 );
289 aContentBoxLayout->setRowStretch( 3, 1 );
290 aContentBoxLayout->setRowStretch( 6, 1 );
292 /***************************************************************/
293 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
294 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
295 mySelectBoxLayout->setMargin( MARGIN );
296 mySelectBoxLayout->setSpacing( SPACING );
298 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
299 mySubMeshBtn = new QPushButton( mySelectBox );
300 mySubMeshBtn->setIcon( image0 );
301 mySubMeshLine = new QLineEdit( mySelectBox );
302 mySubMeshLine->setReadOnly( true );
303 onSelectSubMesh( false );
305 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
306 myGroupBtn = new QPushButton( mySelectBox );
307 myGroupBtn->setIcon( image0 );
308 myGroupLine = new QLineEdit( mySelectBox );
309 myGroupLine->setReadOnly( true );
310 onSelectGroup( false );
312 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
313 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
314 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
315 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
316 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
317 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
319 /***************************************************************/
320 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
321 wg1Layout->setMargin( 0 );
322 wg1Layout->setSpacing( SPACING );
323 wg1Layout->addWidget( aContentBox );
324 wg1Layout->addWidget( mySelectBox );
325 wg1Layout->setStretchFactor( aContentBox, 10 );
327 /***************************************************************/
328 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
329 myGeomGroupBtn = new QToolButton( wg2 );
330 myGeomGroupBtn->setIcon( image0 );
331 myGeomGroupBtn->setCheckable( true );
332 myGeomGroupLine = new QLineEdit( wg2 );
333 myGeomGroupLine->setReadOnly( true ); //VSR ???
334 onSelectGeomGroup( false );
336 myGeomGroupBtn->setEnabled( create );
337 myGeomGroupLine->setEnabled( create );
339 /***************************************************************/
340 QGridLayout* wg2Layout = new QGridLayout( wg2 );
341 wg2Layout->setMargin( 0 );
342 wg2Layout->setSpacing( SPACING );
343 wg2Layout->addWidget( geomObject, 0, 0 );
344 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
345 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
346 wg2Layout->setRowStretch( 1, 5 );
348 /***************************************************************/
349 QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
350 QGridLayout* wg3Layout = new QGridLayout( wg3 );
351 wg3Layout->setMargin( 0 );
352 wg3Layout->setSpacing( SPACING );
353 wg3Layout->addWidget( aFilter2, 0, 0 );
354 wg3Layout->setRowStretch( 1, 5 );
356 /***************************************************************/
357 myWGStack->insertWidget( 0, wg1 );
358 myWGStack->insertWidget( 1, wg2 );
359 myWGStack->insertWidget( 2, wg3 );
361 /***************************************************************/
362 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
363 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
364 aColorBoxLayout->setMargin(MARGIN);
365 aColorBoxLayout->setSpacing(SPACING);
367 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
368 myColorBtn = new QtxColorButton(aColorBox);
369 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
370 myColorBtn->sizePolicy().verticalPolicy() );
372 aColorBoxLayout->addWidget(aColorLab);
373 aColorBoxLayout->addWidget(myColorBtn);
375 /***************************************************************/
377 QFrame* aButtons = new QFrame(this);
378 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
379 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
380 aBtnLayout->setMargin(MARGIN);
381 aBtnLayout->setSpacing(SPACING);
383 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
384 myOKBtn->setAutoDefault(true);
385 myOKBtn->setDefault(true);
386 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
387 myApplyBtn->setAutoDefault(true);
388 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
389 myCloseBtn->setAutoDefault(true);
390 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
391 myHelpBtn->setAutoDefault(true);
393 aBtnLayout->addWidget(myOKBtn);
394 aBtnLayout->addSpacing(10);
395 aBtnLayout->addWidget(myApplyBtn);
396 aBtnLayout->addSpacing(10);
397 aBtnLayout->addStretch();
398 aBtnLayout->addWidget(myCloseBtn);
399 aBtnLayout->addWidget(myHelpBtn);
401 /***************************************************************/
402 aMainLayout->addWidget(meshGroupLab, 0, 0);
403 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
404 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
405 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
406 aMainLayout->addWidget(aName, 2, 0);
407 aMainLayout->addWidget(myName, 2, 2);
408 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
409 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
410 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
411 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
413 /* signals and slots connections */
414 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
415 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
416 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
418 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
419 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
421 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
422 connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters()));
423 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
424 connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
425 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
426 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
427 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
429 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
430 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
431 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
432 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
433 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
435 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
437 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
438 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
439 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
440 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
443 mySMESHGUI->SetActiveDialogBox(this);
444 mySMESHGUI->SetState(800);
446 mySelectionMode = grpNoSelection;
447 myMeshFilter = new SMESH_TypeFilter(MESH);
448 mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
449 SMESH_LogicalFilter::LO_OR,
450 /*takeOwnership=*/true);
451 myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
452 SMESH_LogicalFilter::LO_OR,
453 /*takeOwnership=*/true);
454 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
455 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
457 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
458 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
459 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
460 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
462 rb1->setChecked(true); // VSR !!!
463 onGrpTypeChanged(0); // VSR!!!
465 if (myMesh->_is_nil() )
466 myTypeGroup->button(0)->setChecked(true);
468 onSelectAll(); //updateButtons();
471 //=================================================================================
472 // function : ~SMESHGUI_GroupDlg()
473 // purpose : Destroys the object and frees any allocated resources
474 //=================================================================================
475 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
477 // no need to delete child widgets, Qt does it all for us
478 if ( myFilterDlg != 0 ) {
479 myFilterDlg->setParent( 0 );
482 if ( myMeshFilter ) delete myMeshFilter;
483 if ( mySubMeshFilter ) delete mySubMeshFilter;
484 if ( myGroupFilter ) delete myGroupFilter;
485 if ( myGeomFilter ) delete myGeomFilter;
488 //=================================================================================
489 // function : GetDefaultName()
490 // purpose : Get the Group Name if Create new Group
491 //=================================================================================
492 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
496 // collect all object names of SMESH component
497 SalomeApp_Study* appStudy =
498 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
499 if ( !appStudy ) return aName;
500 _PTR(Study) aStudy = appStudy->studyDS();
502 std::set<std::string> aSet;
503 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
505 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
507 for (it->InitEx(true); it->More(); it->Next()) {
509 aSet.insert(obj->GetName());
513 // build a unique name
515 bool isUnique = false;
517 aName = theOperation + "_" + QString::number(++aNumber);
518 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
524 //=================================================================================
527 //=================================================================================
528 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
530 mySelectionMgr->installFilter(myMeshFilter);
532 /* init data from current selection */
533 restoreShowEntityMode();
534 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
536 myGroup = SMESH::SMESH_Group::_nil();
537 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
538 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
540 // NPAL19389: create a group with a selection in another group
541 // set actor of myMesh, if it is visible, else try
542 // any visible actor of group or submesh of myMesh
543 SetAppropriateActor();
545 setDefaultGroupColor();
548 mySelectionMgr->selectedObjects( aList );
549 if( !aList.IsEmpty() )
551 QString aName = aList.First()->getName();
552 myMeshGroupLine->setText(aName);
553 myMeshGroupLine->home( false );
556 myCurrentLineEdit = 0;
558 myTypeGroup->button(0)->setChecked(true);
562 //=================================================================================
565 //=================================================================================
566 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
567 const bool theIsConvert)
569 restoreShowEntityMode();
570 myMesh = theGroup->GetMesh();
573 myNameChanged = true;
574 myName->blockSignals(true);
575 myName->setText(theGroup->GetName());
576 myName->blockSignals(false);
579 SALOMEDS::Color aColor = theGroup->GetColor();
580 setGroupColor( aColor );
582 myMeshGroupLine->setText(theGroup->GetName());
585 switch(theGroup->GetType()) {
586 case SMESH::NODE: aType = 0; break;
587 case SMESH::BALL: aType = 1; break;
588 case SMESH::EDGE: aType = 2; break;
589 case SMESH::FACE: aType = 3; break;
590 case SMESH::VOLUME: aType = 4; break;
592 myTypeGroup->button(aType)->setChecked(true);
594 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
595 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
596 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
597 myFilter = SMESH::Filter::_nil();
599 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
602 // NPAL19389: create a group with a selection in another group
603 // set actor of myMesh, if it is visible, else set
604 // actor of theGroup, if it is visible, else try
605 // any visible actor of group or submesh of myMesh
606 // commented, because an attempt to set selection on not displayed cells leads to error
607 SetAppropriateActor();
609 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
611 anActor = SMESH::FindActorByObject(theGroup);
612 SMESH::SetPickable(anActor);*/
614 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
615 myGrpTypeGroup->button(grpType)->setChecked(true);
616 onGrpTypeChanged(grpType);
619 if ( grpType == 0 ) { // standalone group
620 myCurrentLineEdit = 0;
622 myAllowElemsModif->setChecked( true );
624 setSelectionMode(aType);
626 setShowEntityMode(); // depends on myTypeId
629 if (!theGroup->IsEmpty()) {
630 SMESH::long_array_var anElements = theGroup->GetListOfID();
631 int k = anElements->length();
632 for (int i = 0; i < k; i++) {
633 myIdList.append(anElements[i]);
634 myElements->addItem(QString::number(anElements[i]));
636 myElements->selectAll();
639 else if ( grpType == 1 ) // group on geom
641 QString aShapeName( "" );
642 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
643 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
644 if (!aGroupShape->_is_nil())
646 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
648 aShapeName = aGroupShapeSO->GetName().c_str();
650 myGeomGroupLine->setText( aShapeName );
652 else // group on filter
654 myFilter = myGroupOnFilter->GetFilter();
655 if ( !myFilter->_is_nil() ) {
656 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
657 if ( perdicate->_is_nil() )
658 myFilter = SMESH::Filter::_nil();
664 myNameChanged = true;
665 myName->blockSignals(true);
666 myName->setText(theGroup->GetName());
667 myName->blockSignals(false);
670 onSelectAll(); //updateButtons();
673 //=================================================================================
674 // function : updateButtons()
676 //=================================================================================
677 void SMESHGUI_GroupDlg::updateButtons()
679 bool enable = !myName->text().trimmed().isEmpty();
682 if (myGrpTypeId == 0) { // standalone
683 if ( !mySelectAll->isChecked() )
685 if ( myAllowElemsModif->isChecked() )
687 enable = ( myElements->count() > 0 );
689 else if ((enable = !myFilter->_is_nil() ))
691 SMESH::array_of_ElementType_var types = myFilter->GetTypes();
692 enable = types->length();
695 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
697 else if (myGrpTypeId == 1) // on geom
699 if (CORBA::is_nil(myGroupOnGeom)) // creation mode
700 enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
702 else if (myGrpTypeId == 2) // on filter
704 if (( enable = !myFilter->_is_nil() ))
705 if (CORBA::is_nil(myGroupOnFilter) ) // creation mode
706 enable = !myMesh->_is_nil();
710 myOKBtn->setEnabled(enable);
711 myApplyBtn->setEnabled(enable);
714 //=================================================================================
715 // function : onNameChanged()
717 //=================================================================================
718 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
720 myOldName = myName->text();
722 myNameChanged = !myName->text().trimmed().isEmpty();
725 //=================================================================================
726 // function : onTypeChanged()
727 // purpose : Group elements type radio button management
728 //=================================================================================
729 void SMESHGUI_GroupDlg::onTypeChanged (int id)
731 if (myTypeId != id) {
734 if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
735 setSelectionMode(id);
737 setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
739 onObjectSelectionChanged();
744 //=================================================================================
745 // function : onGrpTypeChanged()
746 // purpose : Group type radio button management
747 //=================================================================================
748 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
750 if (myGrpTypeId != id) {
752 myWGStack->setCurrentIndex( id );
753 myName->blockSignals(true);
754 myName->setText(myOldName);
755 myName->blockSignals(false);
756 onSelectGeomGroup(id != 0);
761 //=================================================================================
762 // function : onColorChanged()
763 // purpose : Color button management
764 //=================================================================================
765 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
770 //=================================================================================
771 // function : setSelectionMode()
772 // purpose : Radio button management
773 //=================================================================================
774 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
777 if (myMesh->_is_nil())
779 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
780 bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
781 if (mySelectionMode != theMode) {
782 // [PAL10408] mySelectionMgr->clearSelected();
783 mySelectionMgr->clearFilters();
784 SMESH::RemoveFilters();
786 if (myActorsList.count() > 0)
787 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
788 it.next()->SetPointRepresentation(false);
790 SMESH::SetPointRepresentation(false);
793 case grpNodeSelection:
794 if ( myGrpTypeId == 0 ) // standalone
796 if (myActorsList.count() > 0)
797 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
798 it.next()->SetPointRepresentation(true);
800 SMESH::SetPointRepresentation(true);
802 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
804 case grpEdgeSelection:
805 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
807 case grpBallSelection:
808 //if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
810 case grpFaceSelection:
811 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
813 case grpVolumeSelection:
814 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
816 case grpSubMeshSelection: {
818 SMESH_TypeFilter* f = 0;
820 case grpNodeSelection: f = new SMESH_TypeFilter(SUBMESH); break;
821 case grpEdgeSelection: f = new SMESH_TypeFilter(SUBMESH_EDGE); break;
822 case grpFaceSelection: f = new SMESH_TypeFilter(SUBMESH_FACE); break;
823 case grpVolumeSelection: f = new SMESH_TypeFilter(SUBMESH_SOLID); break;
824 default: f = new SMESH_TypeFilter(SUBMESH);
826 QList<SUIT_SelectionFilter*> filtList;
827 filtList.append( f );
828 filtList.append( new SMESH_TypeFilter(SUBMESH_COMPOUND));
829 mySubMeshFilter->setFilters( filtList );
831 mySelectionMgr->installFilter( mySubMeshFilter );
833 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
836 case grpGroupSelection: {
838 SMESH_TypeFilter* f = 0;
840 case grpNodeSelection: f = new SMESH_TypeFilter(GROUP_NODE); break;
841 case grpBallSelection: f = new SMESH_TypeFilter(GROUP_BALL); break;
842 case grpEdgeSelection: f = new SMESH_TypeFilter(GROUP_EDGE); break;
843 case grpFaceSelection: f = new SMESH_TypeFilter(GROUP_FACE); break;
844 case grpVolumeSelection: f = new SMESH_TypeFilter(GROUP_VOLUME); break;
845 default: f = new SMESH_TypeFilter(GROUP);
847 QList<SUIT_SelectionFilter*> filtList;
848 filtList.append( f );
849 myGroupFilter->setFilters( filtList );
851 mySelectionMgr->installFilter(myGroupFilter);
852 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
855 case grpMeshSelection:
856 mySelectionMgr->installFilter(myMeshFilter);
857 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
859 case grpGeomSelection:
860 mySelectionMgr->installFilter(myGeomFilter);
861 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
864 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
867 if ( aViewWindow ) aViewWindow->Repaint();
868 mySelectionMode = theMode;
872 //=================================================================================
873 // function : onApply()
875 //=================================================================================
876 bool SMESHGUI_GroupDlg::onApply()
878 if (mySMESHGUI->isActiveStudyLocked())
881 if (myName->text().trimmed().isEmpty())
884 SMESH::ElementType aType = SMESH::ALL;
886 case grpNodeSelection: aType = SMESH::NODE; break;
887 case grpBallSelection: aType = SMESH::BALL; break;
888 case grpEdgeSelection: aType = SMESH::EDGE; break;
889 case grpFaceSelection: aType = SMESH::FACE; break;
890 case grpVolumeSelection: aType = SMESH::VOLUME; break;
894 QStringList anEntryList;
896 SMESH::SMESH_GroupBase_var resultGroup;
899 if (myGrpTypeId == 0) // standalone
901 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
904 mySelectionMgr->clearSelected();
906 if (myGroup->_is_nil()) { // creation or conversion
907 // check if group on geometry is not null
908 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
909 if (myMesh->_is_nil())
911 if ( myGroupOnGeom->_is_nil() )
912 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
914 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
916 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
917 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
921 if (myGroup->_is_nil()) { // creation
922 if (myMesh->_is_nil())
925 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
927 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
930 if ( mySelectAll->isChecked() ) {
932 myGroup->AddFrom(myMesh.in());
937 if ( !myFilter->_is_nil() &&
938 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
940 myGroup->AddFrom( myFilter );
944 SMESH::long_array_var anIdList = new SMESH::long_array;
945 int i, k = myElements->count();
947 for (i = 0; i < k; i++) {
948 anIdList[i] = myElements->item(i)->text().toInt();
950 myGroup->Add(anIdList.inout());
957 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
960 if ( mySelectAll->isChecked() ) {
963 myGroup->AddFrom(myMesh.in());
968 int i, total = myElements->count();
969 for (i = 0; i < total; i++) {
970 int anId = myElements->item(i)->text().toInt();
971 int idx = myIdList.indexOf(anId);
973 aAddList.append(anId);
975 myIdList.removeAt(idx);
977 if (!aAddList.empty()) {
978 SMESH::long_array_var anIdList = new SMESH::long_array;
979 int added = aAddList.count();
980 anIdList->length(added);
981 for (i = 0; i < added; i++)
982 anIdList[i] = aAddList[i];
983 myGroup->Add(anIdList.inout());
985 if (!myIdList.empty()) {
986 SMESH::long_array_var anIdList = new SMESH::long_array;
987 int removed = myIdList.count();
988 anIdList->length(removed);
989 for (i = 0; i < removed; i++)
990 anIdList[i] = myIdList[i];
991 myGroup->Remove(anIdList.inout());
993 /* init for next operation */
995 for (i = 0; i < total; i++) {
996 myIdList.append(myElements->item(i)->text().toInt());
1003 else if (myGrpTypeId == 1) // on geom object
1005 if (CORBA::is_nil(myGroupOnGeom)) { // creation
1006 if (myMesh->_is_nil() || !myGeomObjects->length())
1009 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1010 GEOM::GEOM_IGroupOperations_var aGroupOp =
1011 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1013 if (myGeomObjects->length() == 1) {
1014 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1015 myName->text().toLatin1().data(),
1019 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1020 if ( aSMESHGen->_is_nil() )
1023 // create a geometry group
1024 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1025 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1027 if (geomGen->_is_nil() || !aStudy)
1030 GEOM::GEOM_IGroupOperations_var op =
1031 geomGen->GetIGroupOperations(aStudy->StudyId());
1035 // check and add all selected GEOM objects: they must be
1036 // a sub-shapes of the main GEOM and must be of one type
1037 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1038 for ( int i =0; i < myGeomObjects->length(); i++) {
1039 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1041 aGroupType = aSubShapeType;
1042 else if (aSubShapeType != aGroupType) {
1043 aGroupType = TopAbs_SHAPE;
1048 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1049 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1050 op->UnionList(aGroupVar, myGeomObjects);
1053 // publish the GEOM group in study
1054 QString aNewGeomGroupName ( "Auto_group_for_" );
1055 aNewGeomGroupName += myName->text();
1056 SALOMEDS::SObject_var aNewGroupSO =
1057 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
1058 aNewGeomGroupName.toLatin1().data(), aMeshShape);
1061 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1062 myName->text().toLatin1().data(),
1065 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1071 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1076 if (myGrpTypeId == 2) // group on filter
1078 if ( myFilter->_is_nil() ) return false;
1080 if (CORBA::is_nil(myGroupOnFilter)) { // creation
1081 if (myMesh->_is_nil())
1084 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1085 myName->text().toLatin1().data(),
1088 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1093 myGroupOnFilter->SetFilter( myFilter );
1095 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1103 SALOMEDS::Color aColor = getGroupColor();
1104 resultGroup->SetColor(aColor);
1106 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1108 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1112 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1114 /* init for the next operation */
1115 myName->setText( "" );
1116 myElements->clear();
1117 myGroup = SMESH::SMESH_Group::_nil();
1118 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1119 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1120 myFilter = SMESH::Filter::_nil();
1124 resultGroup->SetName(myName->text().toLatin1().data());
1127 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
1128 anActor->setName(myName->text().toLatin1().data());
1129 switch ( myTypeId ) {
1130 case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1131 case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1132 case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1133 case grpFaceSelection:
1134 case grpVolumeSelection:
1138 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1139 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1143 SMESHGUI::Modified();
1144 mySMESHGUI->updateObjBrowser(true);
1145 SMESH::UpdateView(); // asv: fix of BUG PAL5515
1146 mySelectionMgr->clearSelected();
1148 if( LightApp_Application* anApp =
1149 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1150 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1155 //=================================================================================
1156 // function : onOK()
1158 //=================================================================================
1159 void SMESHGUI_GroupDlg::onOK()
1161 setIsApplyAndClose( true );
1164 setIsApplyAndClose( false );
1167 //=================================================================================
1168 // function : onListSelectionChanged()
1169 // purpose : Called when selection in element list is changed
1170 //=================================================================================
1171 void SMESHGUI_GroupDlg::onListSelectionChanged()
1173 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1174 if( myIsBusy || myActorsList.count() == 0 ) return;
1177 if (myCurrentLineEdit == 0) {
1178 mySelectionMgr->clearSelected();
1179 TColStd_MapOfInteger aIndexes;
1180 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1181 QListWidgetItem* anItem;
1182 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1183 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1184 SALOME_ListIO aList;
1185 aList.Append(myActorsList.first()->getIO());
1186 mySelectionMgr->setSelectedObjects(aList,false);
1191 //=================================================================================
1192 // function : onObjectSelectionChanged()
1193 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1194 //=================================================================================
1195 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1197 if ( myIsBusy || !isEnabled()) return;
1198 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1202 SALOME_ListIO aList;
1203 mySelectionMgr->selectedObjects( aList );
1205 int aNbSel = aList.Extent();
1206 myElements->clearSelection();
1208 if (myCurrentLineEdit)
1210 myCurrentLineEdit->setText( "" );
1211 QString aString = "";
1213 if (myCurrentLineEdit == myMeshGroupLine)
1215 mySelectSubMesh->setEnabled(false);
1216 mySelectGroup->setEnabled(false);
1217 myGroupLine->setText( "" );
1218 mySubMeshLine->setText( "" );
1220 myGeomGroupBtn->setEnabled(false);
1221 myGeomGroupLine->setEnabled(false);
1222 myGeomGroupLine->setText( "" );
1223 myGeomObjects = new GEOM::ListOfGO();
1224 myGeomObjects->length(0);
1226 if (myGeomGroupBtn->isChecked())
1227 myGeomGroupBtn->setChecked(false);
1229 myName->setText( "" );
1231 myElements->clear();
1234 myGroup = SMESH::SMESH_Group::_nil();
1235 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1236 restoreShowEntityMode();
1237 myMesh = SMESH::SMESH_Mesh::_nil();
1243 Handle(SALOME_InteractiveObject) IO = aList.First();
1246 restoreShowEntityMode();
1247 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1248 setShowEntityMode();
1250 if (myMesh->_is_nil())
1257 if ( myFilterDlg && !myMesh->_is_nil()){
1258 myFilterDlg->SetMesh( myMesh );
1260 myGroup = SMESH::SMESH_Group::_nil();
1262 // NPAL19389: create a group with a selection in another group
1263 // set actor of myMesh, if it is visible, else try
1264 // any visible actor of group or submesh of myMesh
1265 SetAppropriateActor();
1267 aString = aList.First()->getName();
1268 myMeshGroupLine->setText(aString);
1269 myMeshGroupLine->home( false );
1271 mySelectSubMesh->setEnabled(true);
1272 mySelectGroup->setEnabled(true);
1273 myGeomGroupBtn->setEnabled(true);
1274 myGeomGroupLine->setEnabled(true);
1278 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1279 if (aGroup->_is_nil())
1286 myGroup = SMESH::SMESH_Group::_nil();
1287 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1291 mySelectSubMesh->setEnabled(true);
1292 mySelectGroup->setEnabled(true);
1294 myCurrentLineEdit = 0;
1299 if (myGrpTypeId == 0)
1305 myElements->clear();
1306 setSelectionMode(myTypeId);
1314 else if (myCurrentLineEdit == myGeomGroupLine)
1316 myGeomObjects = new GEOM::ListOfGO();
1319 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1321 if (aNbSel == 0 || !aMeshSO)
1323 myGeomObjects->length(0);
1329 myGeomObjects->length(aNbSel);
1331 GEOM::GEOM_Object_var aGeomGroup;
1334 SALOME_ListIteratorOfListIO anIt (aList);
1335 for (; anIt.More(); anIt.Next())
1337 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1339 // Check if the object is a geometry group
1340 if (CORBA::is_nil(aGeomGroup))
1343 // Check if group constructed on the same shape as a mesh or on its child
1344 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1345 GEOM::GEOM_IGroupOperations_var anOp =
1346 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1348 // The main shape of the group
1349 GEOM::GEOM_Object_var aGroupMainShape;
1350 if (aGeomGroup->GetType() == 37)
1351 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1353 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1354 _PTR(SObject) aGroupMainShapeSO =
1355 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1357 _PTR(SObject) anObj, aRef;
1358 bool isRefOrSubShape = false;
1359 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1360 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1361 isRefOrSubShape = true;
1363 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1364 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1365 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1366 if (aRef->GetID() == aFather->GetID())
1367 isRefOrSubShape = true;
1369 aFather = aFather->GetFather();
1373 if (isRefOrSubShape)
1374 myGeomObjects[i++] = aGeomGroup;
1377 myGeomObjects->length(i);
1389 if (myCurrentLineEdit == mySubMeshLine)
1390 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1391 else if (myCurrentLineEdit == myGroupLine)
1392 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1393 else if (myCurrentLineEdit == myGeomGroupLine)
1394 aString = tr( "%1 Objects" ).arg(aNbSel);
1397 aString = aList.First()->getName();
1401 myCurrentLineEdit->setText(aString);
1402 myCurrentLineEdit->home(false);
1403 // 07.06.2008 skl for IPAL19574:
1404 // change name of group only if it is empty
1405 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1406 myOldName = myName->text();
1407 myName->blockSignals(true);
1408 myName->setText(aString);
1409 myName->blockSignals(false);
1414 else // !myCurrentLineEdit: local selection of nodes or elements
1416 if (aNbSel == 1 && myActorsList.count() > 0 )
1418 // NPAL19389: create a group with a selection in another group
1419 // Switch myActor to the newly selected one, if the last
1420 // is visible and belongs to group or submesh of myMesh
1421 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1422 Handle(SALOME_InteractiveObject) selIO = aList.First();
1423 if (curIO->hasEntry() && selIO->hasEntry()) {
1424 const char* selEntry = selIO->getEntry();
1425 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1426 // different objects: selected and myActor
1427 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1428 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1429 // newly selected actor is visible
1432 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1434 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1435 int len = strlen(meshEntry);
1437 if (strncmp(selEntry, meshEntry, len) == 0) {
1438 // selected object is myMesh or a part of it
1439 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1442 SMESH::SetPickable(myActor);
1451 QString aListStr = "";
1453 if (myTypeId == 0) {
1454 QListIterator<SMESH_Actor*> it( myActorsList );
1455 while ( it.hasNext() ) {
1457 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1461 QListIterator<SMESH_Actor*> it( myActorsList );
1462 while ( it.hasNext() ) {
1464 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1469 QListWidgetItem* anItem;
1470 QList<QListWidgetItem*> listItemsToSel;
1471 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1472 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1473 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1474 foreach(anItem, found)
1475 if (!anItem->isSelected())
1476 listItemsToSel.push_back(anItem);
1478 bool blocked = myElements->signalsBlocked();
1479 myElements->blockSignals(true);
1480 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1481 myElements->blockSignals(blocked);
1482 onListSelectionChanged();
1483 listItemsToSel.clear();
1488 if (myActorsList.count() == 0) {
1489 if (!myGroup->_is_nil()) {
1490 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1492 myActorsList.append( anActor );
1494 else if(!myGroupOnGeom->_is_nil()) {
1495 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1497 myActorsList.append( anActor );
1500 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1502 myActorsList.append( anActor );
1506 // somehow, if we display the mesh, while selecting from another actor,
1507 // the mesh becomes pickable, and there is no way to select any element
1508 if (myActorsList.count() > 0) {
1509 QListIterator<SMESH_Actor*> it( myActorsList );
1510 while ( it.hasNext() ) {
1511 SMESH_Actor* anActor = it.next();
1512 if ( IsActorVisible(anActor) )
1513 anActor->SetPickable(true);
1520 //=================================================================================
1521 // function : onSelectAll()
1522 // purpose : Called when "Select all" is checked
1523 //=================================================================================
1524 void SMESHGUI_GroupDlg::onSelectAll()
1526 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1528 myElementsLab->setEnabled( !noElemsModif );
1529 myElements->setEnabled ( !noElemsModif );
1530 myFilterBtn->setEnabled ( !mySelectAll->isChecked() );
1531 myAddBtn->setEnabled ( !noElemsModif );
1532 myRemoveBtn->setEnabled ( !noElemsModif );
1533 mySortBtn->setEnabled ( !noElemsModif );
1534 mySelectBox->setEnabled ( !noElemsModif );
1535 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1537 int selMode = mySelectionMode;
1538 mySelectionMode = grpNoSelection;
1539 setSelectionMode( selMode );
1543 //=================================================================================
1544 // function : onSelectSubMesh()
1545 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1546 //=================================================================================
1547 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1550 if (mySelectGroup->isChecked()) {
1551 mySelectGroup->setChecked(false);
1553 //VSR: else if (mySelectGeomGroup->isChecked()) {
1554 //VSR: mySelectGeomGroup->setChecked(false);
1556 myCurrentLineEdit = mySubMeshLine;
1557 setSelectionMode(grpSubMeshSelection);
1560 mySubMeshLine->setText( "" );
1561 myCurrentLineEdit = 0;
1563 setSelectionMode(myTypeId);
1565 mySubMeshBtn->setEnabled(on);
1566 mySubMeshLine->setEnabled(on);
1570 //=================================================================================
1571 // function : (onSelectGroup)
1572 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1573 //=================================================================================
1574 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1577 if (mySelectSubMesh->isChecked()) {
1578 mySelectSubMesh->setChecked(false);
1580 myCurrentLineEdit = myGroupLine;
1581 setSelectionMode(grpGroupSelection);
1584 myGroupLine->setText( "" );
1585 myCurrentLineEdit = 0;
1587 setSelectionMode(myTypeId);
1589 myGroupBtn->setEnabled(on);
1590 myGroupLine->setEnabled(on);
1594 //=================================================================================
1595 // function : (onSelectGeomGroup)
1596 // purpose : Called when group type changed. on == "on group" or "on filter"
1597 //=================================================================================
1598 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1601 if (mySelectSubMesh->isChecked()) {
1602 mySelectSubMesh->setChecked(false);
1604 else if (mySelectGroup->isChecked()) {
1605 mySelectGroup->setChecked(false);
1607 if ( myGrpTypeId == 1 ) { // on group
1608 myCurrentLineEdit = myGeomGroupLine;
1612 myCurrentLineEdit = 0;
1614 setSelectionMode(grpAllSelection);
1617 myGeomGroupBtn->setChecked(false);
1618 myGeomObjects->length(0);
1619 myGeomGroupLine->setText( "" );
1620 myCurrentLineEdit = 0;
1622 setSelectionMode( myTypeId );
1626 //=================================================================================
1627 // function : setCurrentSelection()
1629 //=================================================================================
1630 void SMESHGUI_GroupDlg::setCurrentSelection()
1632 QPushButton* send = (QPushButton*)sender();
1633 myCurrentLineEdit = 0;
1634 if (send == myMeshGroupBtn) {
1635 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1636 mySelectionMgr->clearSelected();
1638 setSelectionMode(grpMeshSelection);
1640 setSelectionMode(grpGroupSelection);
1641 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1642 myCurrentLineEdit = myMeshGroupLine;
1643 onObjectSelectionChanged();
1645 else if (send == mySubMeshBtn) {
1646 myCurrentLineEdit = mySubMeshLine;
1647 onObjectSelectionChanged();
1649 else if (send == myGroupBtn) {
1650 myCurrentLineEdit = myGroupLine;
1651 onObjectSelectionChanged();
1656 //=================================================================================
1657 // function : setFilters()
1658 // purpose : SLOT. Called when "Filter" button pressed.
1659 //=================================================================================
1660 void SMESHGUI_GroupDlg::setFilters()
1662 if(myMesh->_is_nil()) {
1663 SUIT_MessageBox::critical(this,
1665 tr("NO_MESH_SELECTED"));
1669 SMESH::ElementType aType = SMESH::ALL;
1672 case grpNodeSelection: aType = SMESH::NODE; break;
1673 case grpBallSelection: aType = SMESH::BALL; break;
1674 case grpEdgeSelection: aType = SMESH::EDGE; break;
1675 case grpFaceSelection: aType = SMESH::FACE; break;
1676 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1680 if ( myFilterDlg == 0 )
1682 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1683 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1686 myFilterDlg->Init( aType );
1688 if ( !myGroupOnFilter->_is_nil() )
1690 myFilterDlg->SetFilter( myFilter, aType );
1691 myFilterDlg->Init( aType );
1694 myFilterDlg->SetSelection();
1695 myFilterDlg->SetMesh( myMesh );
1696 myFilterDlg->SetSourceWg( myElements, false );
1698 myFilterDlg->show();
1701 //=================================================================================
1702 // function : onFilterAccepted()
1703 // purpose : SLOT. Called when Filter dlg closed with OK button.
1704 // Uncheck "Select submesh" and "Select group" checkboxes
1705 //=================================================================================
1706 void SMESHGUI_GroupDlg::onFilterAccepted()
1708 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1710 mySelectionMode = myTypeId;
1711 mySelectSubMesh->setChecked( false );
1712 mySelectGroup->setChecked( false );
1714 // get a filter from myFilterDlg
1715 myFilter = myFilterDlg->GetFilter();
1716 if ( !myFilter->_is_nil() ) {
1717 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1718 if ( perdicate->_is_nil() )
1719 myFilter = SMESH::Filter::_nil();
1721 // set mesh to myFilter
1722 if ( !myFilter->_is_nil() ) {
1723 SMESH::SMESH_Mesh_var mesh = myMesh;
1724 if ( mesh->_is_nil() ) {
1725 if ( !myGroup->_is_nil() )
1726 mesh = myGroup->GetMesh();
1727 else if ( !myGroupOnGeom->_is_nil() )
1728 mesh = myGroupOnGeom->GetMesh();
1729 else if ( !myGroupOnFilter->_is_nil() )
1730 mesh = myGroupOnFilter->GetMesh();
1732 myFilter->SetMesh( mesh );
1738 //=================================================================================
1739 // function : onAdd()
1741 //=================================================================================
1742 void SMESHGUI_GroupDlg::onAdd()
1744 SALOME_ListIO aList;
1745 mySelectionMgr->selectedObjects( aList );
1747 int aNbSel = aList.Extent();
1749 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1752 int sizeBefore = myElements->count();
1754 SMESH::ElementType aType = SMESH::ALL;
1756 case grpNodeSelection:
1757 aType = SMESH::NODE;
1758 mySelector->SetSelectionMode(NodeSelection);
1760 case grpBallSelection:
1761 aType = SMESH::BALL;
1762 //mySelector->SetSelectionMode(BallSelection);
1764 case grpEdgeSelection:
1765 aType = SMESH::EDGE;
1766 mySelector->SetSelectionMode(EdgeSelection);
1768 case grpFaceSelection:
1769 aType = SMESH::FACE;
1770 mySelector->SetSelectionMode(FaceSelection);
1772 case grpVolumeSelection:
1773 aType = SMESH::VOLUME;
1774 mySelector->SetSelectionMode(VolumeSelection);
1777 mySelector->SetSelectionMode(ActorSelection);
1780 QListWidgetItem* anItem = 0;
1781 QList<QListWidgetItem*> listItemsToSel;
1783 if (myCurrentLineEdit == 0) {
1784 //if (aNbSel != 1) { myIsBusy = false; return; }
1785 QString aListStr = "";
1787 if (myTypeId == 0) {
1788 QListIterator<SMESH_Actor*> it( myActorsList );
1789 while ( it.hasNext() ) {
1791 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1796 QListIterator<SMESH_Actor*> it( myActorsList );
1797 while ( it.hasNext() ) {
1799 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1804 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1805 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1806 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1807 if (found.count() == 0) {
1808 anItem = new QListWidgetItem(*it);
1809 myElements->addItem(anItem);
1810 if (!anItem->isSelected())
1811 listItemsToSel.push_back(anItem);
1814 foreach(anItem, found)
1815 if (!anItem->isSelected())
1816 listItemsToSel.push_back(anItem);
1819 bool blocked = myElements->signalsBlocked();
1820 myElements->blockSignals(true);
1821 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1822 myElements->blockSignals(blocked);
1823 onListSelectionChanged();
1824 listItemsToSel.clear();
1826 } else if (myCurrentLineEdit == mySubMeshLine) {
1827 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1829 SALOME_ListIO aList;
1830 mySelectionMgr->selectedObjects( aList );
1832 SALOME_ListIteratorOfListIO anIt (aList);
1833 for ( ; anIt.More(); anIt.Next()) {
1834 SMESH::SMESH_subMesh_var aSubMesh =
1835 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1836 if (!aSubMesh->_is_nil()) {
1837 // check if mesh is the same
1838 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1840 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1841 int k = anElements->length();
1842 for (int i = 0; i < k; i++) {
1843 QString aText = QString::number(anElements[i]);
1844 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1845 if (found.count() == 0) {
1846 anItem = new QListWidgetItem(aText);
1847 myElements->addItem(anItem);
1848 if (!anItem->isSelected())
1849 listItemsToSel.push_back(anItem);
1852 foreach(anItem, found)
1853 if (!anItem->isSelected())
1854 listItemsToSel.push_back(anItem);
1857 bool blocked = myElements->signalsBlocked();
1858 myElements->blockSignals(true);
1859 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1860 myElements->blockSignals(blocked);
1861 onListSelectionChanged();
1862 listItemsToSel.clear();
1864 catch (const SALOME::SALOME_Exception& ex) {
1865 SalomeApp_Tools::QtCatchCorbaException(ex);
1870 mySelectSubMesh->setChecked(false);
1872 onListSelectionChanged();
1874 } else if (myCurrentLineEdit == myGroupLine) {
1875 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1876 SALOME_ListIO aList;
1877 mySelectionMgr->selectedObjects( aList );
1879 SALOME_ListIteratorOfListIO anIt (aList);
1880 for ( ; anIt.More(); anIt.Next()) {
1881 SMESH::SMESH_GroupBase_var aGroup =
1882 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1883 if (!aGroup->_is_nil()) {
1884 // check if mesh is the same
1885 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1886 SMESH::long_array_var anElements = aGroup->GetListOfID();
1887 int k = anElements->length();
1888 for (int i = 0; i < k; i++) {
1889 QString aText = QString::number(anElements[i]);
1890 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1891 if (found.count() == 0) {
1892 anItem = new QListWidgetItem(aText);
1893 myElements->addItem(anItem);
1894 if (!anItem->isSelected())
1895 listItemsToSel.push_back(anItem);
1898 foreach(anItem, found)
1899 if (!anItem->isSelected())
1900 listItemsToSel.push_back(anItem);
1903 bool blocked = myElements->signalsBlocked();
1904 myElements->blockSignals(true);
1905 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1906 myElements->blockSignals(blocked);
1907 onListSelectionChanged();
1908 listItemsToSel.clear();
1912 mySelectGroup->setChecked(false);
1914 onListSelectionChanged();
1916 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1917 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1918 GEOM::GEOM_IGroupOperations_var aGroupOp =
1919 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1921 SMESH::ElementType aGroupType = SMESH::ALL;
1922 switch(aGroupOp->GetType(myGeomObjects[0])) {
1923 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
1924 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
1925 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
1926 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
1927 default: myIsBusy = false; return;
1930 if (aGroupType == aType) {
1931 _PTR(SObject) aGroupSO =
1932 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1933 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1935 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1936 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1937 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
1938 aBelongToGeom->SetGeom(myGeomObjects[0]);
1939 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1940 aBelongToGeom->SetElementType(aType);
1941 aFilter->SetPredicate(aBelongToGeom);
1943 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1945 int k = anElements->length();
1946 for (int i = 0; i < k; i++) {
1947 QString aText = QString::number(anElements[i]);
1948 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1949 if (found.count() == 0) {
1950 anItem = new QListWidgetItem(aText);
1951 myElements->addItem(anItem);
1952 if (!anItem->isSelected())
1953 listItemsToSel.push_back(anItem);
1956 foreach(anItem, found)
1957 if (!anItem->isSelected())
1958 listItemsToSel.push_back(anItem);
1961 bool blocked = myElements->signalsBlocked();
1962 myElements->blockSignals(true);
1963 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1964 myElements->blockSignals(blocked);
1965 onListSelectionChanged();
1966 listItemsToSel.clear();
1969 //VSR: mySelectGeomGroup->setChecked(false);
1971 onListSelectionChanged();
1974 if ( sizeBefore < myElements->count() )
1975 ++myNbChangesOfContents;
1976 // mySelectionMgr->clearSelected();
1980 //=================================================================================
1981 // function : onRemove()
1983 //=================================================================================
1984 void SMESHGUI_GroupDlg::onRemove()
1987 int sizeBefore = myElements->count();
1989 if (myCurrentLineEdit == 0) {
1990 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1991 QListWidgetItem* item;
1992 foreach(item, selItems) delete item;
1994 SALOME_ListIO aList;
1995 mySelectionMgr->selectedObjects( aList );
1997 int aNbSel = aList.Extent();
1999 if (aNbSel == 0) { myIsBusy = false; return; }
2001 SMESH::ElementType aType = SMESH::ALL;
2003 case grpNodeSelection: aType = SMESH::NODE; break;
2004 case grpBallSelection: aType = SMESH::BALL; break;
2005 case grpEdgeSelection: aType = SMESH::EDGE; break;
2006 case grpFaceSelection: aType = SMESH::FACE; break;
2007 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2010 if (myCurrentLineEdit == mySubMeshLine) {
2011 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2012 SALOME_ListIO aList;
2013 mySelectionMgr->selectedObjects( aList );
2015 SALOME_ListIteratorOfListIO anIt (aList);
2016 for ( ; anIt.More(); anIt.Next()) {
2017 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2018 if (!aSubMesh->_is_nil()) {
2019 // check if mesh is the same
2020 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2021 if (aType == SMESH::NODE) {
2023 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2024 int k = anElements->length();
2025 for (int i = 0; i < k; i++) {
2026 QList<QListWidgetItem*> found =
2027 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2028 QListWidgetItem* anItem;
2029 foreach(anItem, found) delete anItem;
2032 catch (const SALOME::SALOME_Exception& ex) {
2033 SalomeApp_Tools::QtCatchCorbaException(ex);
2038 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2039 int k = anElements->length();
2040 for (int i = 0; i < k; i++) {
2041 QList<QListWidgetItem*> found =
2042 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2043 QListWidgetItem* anItem;
2044 foreach(anItem, found) delete anItem;
2047 catch (const SALOME::SALOME_Exception& ex) {
2048 SalomeApp_Tools::QtCatchCorbaException(ex);
2055 else if (myCurrentLineEdit == myGroupLine) {
2056 Standard_Boolean aRes;
2057 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2058 SALOME_ListIO aList;
2059 mySelectionMgr->selectedObjects( aList );
2061 SALOME_ListIteratorOfListIO anIt (aList);
2062 for ( ; anIt.More(); anIt.Next()) {
2063 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2064 if (aRes && !aGroup->_is_nil()) {
2065 // check if mesh is the same
2066 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2067 SMESH::long_array_var anElements = aGroup->GetListOfID();
2068 int k = anElements->length();
2069 for (int i = 0; i < k; i++) {
2070 QList<QListWidgetItem*> found =
2071 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2072 QListWidgetItem* anItem;
2073 foreach(anItem, found) delete anItem;
2081 if ( sizeBefore > myElements->count() )
2082 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2086 //=================================================================================
2087 // function : onSort()
2089 //=================================================================================
2090 void SMESHGUI_GroupDlg::onSort()
2092 // PAL5412: sorts items in ascending by "string" value
2093 // myElements->sort(true);
2094 // myElements->update();
2095 int i, k = myElements->count();
2098 QList<int> aSelected;
2099 std::vector<int> anArray(k);
2100 // QMemArray<int> anArray(k);
2102 for (i = 0; i < k; i++) {
2103 int id = myElements->item(i)->text().toInt();
2105 if (myElements->item(i)->isSelected())
2106 aSelected.append(id);
2108 // sort & update list
2109 std::sort(anArray.begin(), anArray.end());
2111 myElements->clear();
2112 QListWidgetItem* anItem;
2113 QList<QListWidgetItem*> listItemsToSel;
2114 for (i = 0; i < k; i++) {
2115 anItem = new QListWidgetItem(QString::number(anArray[i]));
2116 myElements->addItem(anItem);
2117 if (aSelected.contains(anArray[i]))
2118 listItemsToSel.push_back(anItem);
2120 bool blocked = myElements->signalsBlocked();
2121 myElements->blockSignals(true);
2122 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2123 myElements->blockSignals(blocked);
2124 listItemsToSel.clear();
2129 //=================================================================================
2130 // function : closeEvent()
2132 //=================================================================================
2133 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
2138 //=================================================================================
2139 // function : onVisibilityChanged()
2141 //=================================================================================
2142 void SMESHGUI_GroupDlg::onVisibilityChanged()
2144 SetAppropriateActor();
2147 //=================================================================================
2148 // function : SMESHGUI_GroupDlg::onClose
2149 // purpose : SLOT called when "Close" button pressed. Close dialog
2150 //=================================================================================
2151 void SMESHGUI_GroupDlg::onClose()
2153 if (SMESH::GetCurrentVtkView()) {
2154 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2155 SMESH::SetPointRepresentation(false);
2156 SMESH::SetPickable();
2157 restoreShowEntityMode();
2160 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2161 SUIT_DataOwnerPtrList aList;
2162 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2163 mySelectionMgr->setSelected( aList );
2166 mySelectionMgr->clearSelected();
2167 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2168 aViewWindow->SetSelectionMode(ActorSelection);
2169 mySelectionMgr->clearFilters();
2170 mySMESHGUI->ResetState();
2175 //=================================================================================
2176 // function : onHelp()
2178 //=================================================================================
2179 void SMESHGUI_GroupDlg::onHelp()
2181 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2183 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2187 platform = "winapplication";
2189 platform = "application";
2191 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2192 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2193 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2195 arg(myHelpFileName));
2199 //=================================================================================
2200 // function : SMESHGUI_GroupDlg::onDeactivate
2201 // purpose : SLOT called when dialog must be deativated
2202 //=================================================================================
2203 void SMESHGUI_GroupDlg::onDeactivate()
2205 mySMESHGUI->ResetState();
2209 //=================================================================================
2210 // function : SMESHGUI_GroupDlg::enterEvent
2211 // purpose : Event filter
2212 //=================================================================================
2213 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2216 mySMESHGUI->EmitSignalDeactivateDialog();
2218 mySelectionMode = grpNoSelection;
2219 setSelectionMode(myTypeId);
2220 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2221 mySMESHGUI->SetActiveDialogBox(this);
2222 mySMESHGUI->SetState(800);
2226 //=================================================================================
2227 // function : hideEvent
2228 // purpose : caused by ESC key
2229 //=================================================================================
2230 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
2232 if (!isMinimized() && !myIsBusy)
2236 //=================================================================================
2237 // function : keyPressEvent()
2239 //=================================================================================
2240 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2242 QDialog::keyPressEvent( e );
2243 if ( e->isAccepted() )
2246 if ( e->key() == Qt::Key_F1 )
2253 //================================================================================
2255 * \brief Enable showing of the popup when Geometry selection btn is clicked
2256 * \param enable - true to enable
2258 //================================================================================
2260 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2262 void SMESHGUI_GroupDlg::updateGeomPopup()
2264 bool enable = false;
2266 if ( !myMesh->_is_nil() )
2267 enable = myMesh->NbEdges() > 0;
2269 if ( myGeomGroupBtn )
2271 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2273 if ( !myGeomPopup ) {
2274 myGeomPopup = new QMenu(this);
2275 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2276 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2277 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2279 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2285 //=================================================================================
2286 // function : onGeomSelectionButton()
2288 //=================================================================================
2289 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2291 if ( myGeomPopup && isBtnOn )
2293 myCurrentLineEdit = myGeomGroupLine;
2294 QAction* a = myGeomPopup->exec( QCursor::pos() );
2295 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2296 setSelectionMode(grpGeomSelection);
2300 myCurrentLineEdit = 0;
2301 setSelectionMode(grpAllSelection);
2305 //=================================================================================
2306 // function : onGeomPopup()
2308 //=================================================================================
2309 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2311 int index = myActions[a];
2312 if ( index == GEOM_BY_MESH_INDEX )
2314 mySelectionMode = grpNoSelection;
2315 if ( !myShapeByMeshOp ) {
2316 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2317 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2318 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2319 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2320 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2322 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2323 if ( !myMesh->_is_nil() ) {
2325 hide(); // stop processing selection
2327 myShapeByMeshOp->setModule( mySMESHGUI );
2328 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2329 myShapeByMeshOp->SetMesh( myMesh );
2330 myShapeByMeshOp->start();
2335 //================================================================================
2337 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2339 //================================================================================
2341 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2343 if ( myShapeByMeshOp == op ) {
2344 mySMESHGUI->getApp()->updateObjectBrowser();
2346 // Select a found geometry object
2347 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2348 if ( !aGeomVar->_is_nil() )
2350 QString ID = aGeomVar->GetStudyEntry();
2351 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2352 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2353 SALOME_ListIO anIOList;
2354 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2355 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2356 anIOList.Append( anIO );
2357 mySelectionMgr->setSelectedObjects( anIOList, false );
2358 onObjectSelectionChanged();
2364 //================================================================================
2366 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2368 //================================================================================
2370 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2372 if ( myShapeByMeshOp == op )
2375 setSelectionMode(grpGeomSelection);
2379 //=================================================================================
2380 // function : setGroupColor()
2382 //=================================================================================
2383 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2385 QColor aQColor( (int)( theColor.R * 255.0 ),
2386 (int)( theColor.G * 255.0 ),
2387 (int)( theColor.B * 255.0 ) );
2388 setGroupQColor( aQColor );
2391 //=================================================================================
2392 // function : getGroupColor()
2394 //=================================================================================
2395 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2397 QColor aQColor = getGroupQColor();
2399 SALOMEDS::Color aColor;
2400 aColor.R = (float)aQColor.red() / 255.0;
2401 aColor.G = (float)aQColor.green() / 255.0;
2402 aColor.B = (float)aQColor.blue() / 255.0;
2407 //=================================================================================
2408 // function : setGroupQColor()
2410 //=================================================================================
2411 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2413 if( theColor.isValid() )
2414 myColorBtn->setColor( theColor );
2417 //=================================================================================
2418 // function : getGroupQColor()
2420 //=================================================================================
2421 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2423 return myColorBtn->color();
2426 //=================================================================================
2427 // function : setDefaultGroupColor()
2429 //=================================================================================
2430 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2432 if( myMesh->_is_nil() )
2435 bool isAutoColor = myMesh->GetAutoColor();
2440 int r = 0, g = 0, b = 0;
2441 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2442 aQColor.setRgb( r, g, b );
2446 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2448 QList<SALOMEDS::Color> aReservedColors;
2449 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2451 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2452 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2453 aReservedColors.append( aReservedColor );
2456 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2457 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2458 (int)( aColor.G * 255.0 ),
2459 (int)( aColor.B * 255.0 ) );
2463 setGroupQColor( aQColor );
2466 //=================================================================================
2467 // function : SetAppropriateActor()
2468 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2469 // NPAL19389: create a group with a selection in another group.
2470 // if mesh actor is not visible - find any first visible group or submesh
2471 //=================================================================================
2472 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2474 bool isActor = false;
2475 myActorsList.clear();
2477 if (myMesh->_is_nil()) return false;
2479 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2481 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2483 if (!myGroupOnGeom->_is_nil()) {
2484 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2485 if (anActor && anActor->hasIO())
2488 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2491 myActorsList.append(anActor);
2497 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2498 if (anActor && anActor->hasIO()) {
2500 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2503 myActorsList.append(anActor);
2507 if (!isActor && !myGroup->_is_nil()) {
2508 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2509 if (anActor && anActor->hasIO())
2510 myActorsList.append(anActor);
2513 // try any visible actor of group or submesh of current mesh
2516 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2518 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2519 int len = strlen(meshEntry);
2521 // iterate on all actors in current view window, search for
2522 // any visible actor, that belongs to group or submesh of current mesh
2523 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2524 vtkActorCollection *aCollection = aCopy.GetActors();
2525 int nbItems = aCollection->GetNumberOfItems();
2526 for (int i=0; i<nbItems && !isActor; i++)
2528 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2529 if (anActor && anActor->hasIO()) {
2530 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2531 if (aViewWindow->isVisible(anIO)) {
2532 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2533 myActorsList.append(anActor);
2541 if (myActorsList.count() > 0) {
2542 QListIterator<SMESH_Actor*> it( myActorsList );
2543 while ( it.hasNext() ) {
2544 SMESH_Actor* anActor = it.next();
2545 if ( IsActorVisible(anActor) )
2546 anActor->SetPickable(true);
2550 return ( isActor || (myActorsList.count() > 0) );
2553 //=======================================================================
2554 //function : setShowEntityMode
2555 //purpose : make shown only entity corresponding to my type
2556 //=======================================================================
2557 void SMESHGUI_GroupDlg::setShowEntityMode()
2559 if ( !myMesh->_is_nil() ) {
2560 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2561 if (!myStoredShownEntity)
2562 myStoredShownEntity = actor->GetEntityMode();
2563 switch ( myTypeId ) {
2564 case grpNodeSelection: restoreShowEntityMode(); break;
2565 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2566 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2567 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2568 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2574 //=======================================================================
2575 //function : restoreShowEntityMode
2576 //purpose : restore ShowEntity mode of myActor
2577 //=======================================================================
2578 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2580 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2581 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2582 actor->SetEntityMode(myStoredShownEntity);
2585 myStoredShownEntity = 0;
2588 //=======================================================================
2589 //function : IsActorVisible
2590 //purpose : return visibility of the actor
2591 //=======================================================================
2592 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2594 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2595 if (theActor && aViewWindow)
2596 return aViewWindow->isVisible(theActor->getIO());
2600 //================================================================
2601 //function : setIsApplyAndClose
2602 //purpose : Set value of the flag indicating that the dialog is
2603 // accepted by Apply & Close button
2604 //================================================================
2605 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2607 myIsApplyAndClose = theFlag;
2610 //================================================================
2611 //function : isApplyAndClose
2612 //purpose : Get value of the flag indicating that the dialog is
2613 // accepted by Apply & Close button
2614 //================================================================
2615 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2617 return myIsApplyAndClose;