1 // Copyright (C) 2007-2011 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 grpEdgeSelection = 1,
107 grpFaceSelection = 2,
108 grpVolumeSelection = 3,
109 grpSubMeshSelection = 4,
110 grpGroupSelection = 5,
111 grpMeshSelection = 6,
112 grpGeomSelection = 7,
116 //=================================================================================
117 // function : SMESHGUI_GroupDlg()
119 //=================================================================================
120 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
121 SMESH::SMESH_Mesh_ptr theMesh )
122 : QDialog( SMESH::GetDesktop( theModule ) ),
123 mySMESHGUI( theModule ),
124 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
125 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
127 myNameChanged( false ),
128 myIsApplyAndClose( false ),
129 myNbChangesOfContents(0)
132 if ( !theMesh->_is_nil() )
136 mySelectSubMesh->setEnabled( false );
137 mySelectGroup->setEnabled( false );
138 myGeomGroupBtn->setEnabled( false );
139 myGeomGroupLine->setEnabled( false );
143 //=================================================================================
144 // function : SMESHGUI_GroupDlg()
146 //=================================================================================
147 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
148 SMESH::SMESH_GroupBase_ptr theGroup,
149 const bool theIsConvert )
150 : QDialog( SMESH::GetDesktop( theModule ) ),
151 mySMESHGUI( theModule ),
152 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
153 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
155 myNameChanged( false ),
156 myNbChangesOfContents(0) // just not to use uninitialized variable
159 if ( !theGroup->_is_nil() )
160 init( theGroup, theIsConvert );
163 mySelectSubMesh->setEnabled( false );
164 mySelectGroup->setEnabled( false );
166 myCurrentLineEdit = myMeshGroupLine;
167 setSelectionMode( grpGroupSelection );
171 //=================================================================================
172 // function : SMESHGUI_GroupDlg()
174 //=================================================================================
175 void SMESHGUI_GroupDlg::initDialog( bool create)
178 setAttribute( Qt::WA_DeleteOnClose, true );
182 myCurrentLineEdit = 0;
186 myGeomObjects = new GEOM::ListOfGO();
187 myGeomObjects->length( 0 );
189 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
191 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
192 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
194 setSizeGripEnabled( true);
196 QGridLayout* aMainLayout = new QGridLayout( this );
197 aMainLayout->setMargin( MARGIN );
198 aMainLayout->setSpacing( SPACING );
200 /***************************************************************/
201 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
202 myMeshGroupBtn = new QPushButton( this );
203 myMeshGroupBtn->setIcon( image0 );
204 myMeshGroupLine = new QLineEdit( this );
205 myMeshGroupLine->setReadOnly( true );
207 /***************************************************************/
208 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
209 myTypeGroup = new QButtonGroup( this );
210 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
211 aTypeBoxLayout->setMargin( MARGIN );
212 aTypeBoxLayout->setSpacing( SPACING );
215 types.append( tr( "MESH_NODE" ) );
216 types.append( tr( "SMESH_EDGE" ) );
217 types.append( tr( "SMESH_FACE" ) );
218 types.append( tr( "SMESH_VOLUME" ) );
220 for ( int i = 0; i < types.count(); i++ )
222 rb = new QRadioButton( types[i], aTypeBox );
223 myTypeGroup->addButton( rb, i );
224 aTypeBoxLayout->addWidget( rb );
226 aTypeBox->setEnabled( create );
229 /***************************************************************/
230 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
231 aName->setMinimumWidth( 50 );
232 myName = new QLineEdit( this );
234 /***************************************************************/
235 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
236 myGrpTypeGroup = new QButtonGroup( this );
237 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
238 aGrpTypeBoxLayout->setMargin( MARGIN );
239 aGrpTypeBoxLayout->setSpacing( SPACING );
241 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
242 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
243 QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox );
244 myGrpTypeGroup->addButton( rb1, 0 );
245 myGrpTypeGroup->addButton( rb2, 1 );
246 myGrpTypeGroup->addButton( rb3, 2 );
247 aGrpTypeBoxLayout->addWidget( rb1 );
248 aGrpTypeBoxLayout->addWidget( rb2 );
249 aGrpTypeBoxLayout->addWidget( rb3 );
250 aGrpTypeBox->setEnabled( create );
253 /***************************************************************/
254 myWGStack = new QStackedWidget( this );
255 QWidget* wg1 = new QWidget( myWGStack );
256 QWidget* wg2 = new QWidget( myWGStack );
257 QWidget* wg3 = new QWidget( myWGStack );
259 /***************************************************************/
260 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
261 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
262 aContentBoxLayout->setMargin( MARGIN );
263 aContentBoxLayout->setSpacing( SPACING );
265 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
266 myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
268 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
269 myElements = new QListWidget( aContentBox );
270 myElements->setSelectionMode( QListWidget::ExtendedSelection );
272 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
273 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
274 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
275 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
277 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
278 aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
279 aContentBoxLayout->addWidget( myFilterBtn, 1, 1 );
280 aContentBoxLayout->addWidget( myElementsLab, 2, 0 );
281 aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 );
282 aContentBoxLayout->addWidget( myAddBtn, 3, 1 );
283 aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 );
284 aContentBoxLayout->addWidget( mySortBtn, 8, 1 );
286 aContentBoxLayout->setColumnStretch( 0, 1 );
287 aContentBoxLayout->setRowStretch( 3, 1 );
288 aContentBoxLayout->setRowStretch( 6, 1 );
290 /***************************************************************/
291 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
292 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
293 mySelectBoxLayout->setMargin( MARGIN );
294 mySelectBoxLayout->setSpacing( SPACING );
296 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
297 mySubMeshBtn = new QPushButton( mySelectBox );
298 mySubMeshBtn->setIcon( image0 );
299 mySubMeshLine = new QLineEdit( mySelectBox );
300 mySubMeshLine->setReadOnly( true );
301 onSelectSubMesh( false );
303 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
304 myGroupBtn = new QPushButton( mySelectBox );
305 myGroupBtn->setIcon( image0 );
306 myGroupLine = new QLineEdit( mySelectBox );
307 myGroupLine->setReadOnly( true );
308 onSelectGroup( false );
310 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
311 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
312 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
313 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
314 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
315 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
317 /***************************************************************/
318 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
319 wg1Layout->setMargin( 0 );
320 wg1Layout->setSpacing( SPACING );
321 wg1Layout->addWidget( aContentBox );
322 wg1Layout->addWidget( mySelectBox );
323 wg1Layout->setStretchFactor( aContentBox, 10 );
325 /***************************************************************/
326 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
327 myGeomGroupBtn = new QToolButton( wg2 );
328 myGeomGroupBtn->setIcon( image0 );
329 myGeomGroupBtn->setCheckable( true );
330 myGeomGroupLine = new QLineEdit( wg2 );
331 myGeomGroupLine->setReadOnly( true ); //VSR ???
332 onSelectGeomGroup( false );
334 myGeomGroupBtn->setEnabled( create );
335 myGeomGroupLine->setEnabled( create );
337 /***************************************************************/
338 QGridLayout* wg2Layout = new QGridLayout( wg2 );
339 wg2Layout->setMargin( 0 );
340 wg2Layout->setSpacing( SPACING );
341 wg2Layout->addWidget( geomObject, 0, 0 );
342 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
343 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
344 wg2Layout->setRowStretch( 1, 5 );
346 /***************************************************************/
347 QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
348 QGridLayout* wg3Layout = new QGridLayout( wg3 );
349 wg3Layout->setMargin( 0 );
350 wg3Layout->setSpacing( SPACING );
351 wg3Layout->addWidget( aFilter2, 0, 0 );
352 wg3Layout->setRowStretch( 1, 5 );
354 /***************************************************************/
355 myWGStack->insertWidget( 0, wg1 );
356 myWGStack->insertWidget( 1, wg2 );
357 myWGStack->insertWidget( 2, wg3 );
359 /***************************************************************/
360 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
361 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
362 aColorBoxLayout->setMargin(MARGIN);
363 aColorBoxLayout->setSpacing(SPACING);
365 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
366 myColorBtn = new QtxColorButton(aColorBox);
367 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
368 myColorBtn->sizePolicy().verticalPolicy() );
370 aColorBoxLayout->addWidget(aColorLab);
371 aColorBoxLayout->addWidget(myColorBtn);
373 /***************************************************************/
375 QFrame* aButtons = new QFrame(this);
376 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
377 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
378 aBtnLayout->setMargin(MARGIN);
379 aBtnLayout->setSpacing(SPACING);
381 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
382 myOKBtn->setAutoDefault(true);
383 myOKBtn->setDefault(true);
384 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
385 myApplyBtn->setAutoDefault(true);
386 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
387 myCloseBtn->setAutoDefault(true);
388 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
389 myHelpBtn->setAutoDefault(true);
391 aBtnLayout->addWidget(myOKBtn);
392 aBtnLayout->addSpacing(10);
393 aBtnLayout->addWidget(myApplyBtn);
394 aBtnLayout->addSpacing(10);
395 aBtnLayout->addStretch();
396 aBtnLayout->addWidget(myCloseBtn);
397 aBtnLayout->addWidget(myHelpBtn);
399 /***************************************************************/
400 aMainLayout->addWidget(meshGroupLab, 0, 0);
401 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
402 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
403 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
404 aMainLayout->addWidget(aName, 2, 0);
405 aMainLayout->addWidget(myName, 2, 2);
406 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
407 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
408 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
409 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
411 /* signals and slots connections */
412 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
413 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
414 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
416 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
417 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
419 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
420 connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters()));
421 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
422 connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
423 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
424 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
425 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
427 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
428 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
429 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
430 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
431 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
433 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
435 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
436 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
437 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
438 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
441 mySMESHGUI->SetActiveDialogBox(this);
442 mySMESHGUI->SetState(800);
444 mySelectionMode = grpNoSelection;
445 myMeshFilter = new SMESH_TypeFilter(MESH);
446 mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
447 SMESH_LogicalFilter::LO_OR,
448 /*takeOwnership=*/true);
449 myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
450 SMESH_LogicalFilter::LO_OR,
451 /*takeOwnership=*/true);
452 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
453 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
455 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
456 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
457 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
458 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
460 rb1->setChecked(true); // VSR !!!
461 onGrpTypeChanged(0); // VSR!!!
463 if (myMesh->_is_nil() )
464 myTypeGroup->button(0)->setChecked(true);
466 onSelectAll(); //updateButtons();
469 //=================================================================================
470 // function : ~SMESHGUI_GroupDlg()
471 // purpose : Destroys the object and frees any allocated resources
472 //=================================================================================
473 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
475 // no need to delete child widgets, Qt does it all for us
476 if ( myFilterDlg != 0 ) {
477 myFilterDlg->setParent( 0 );
480 if ( myMeshFilter ) delete myMeshFilter;
481 if ( mySubMeshFilter ) delete mySubMeshFilter;
482 if ( myGroupFilter ) delete myGroupFilter;
483 if ( myGeomFilter ) delete myGeomFilter;
486 //=================================================================================
487 // function : GetDefaultName()
488 // purpose : Get the Group Name if Create new Group
489 //=================================================================================
490 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
494 // collect all object names of SMESH component
495 SalomeApp_Study* appStudy =
496 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
497 if ( !appStudy ) return aName;
498 _PTR(Study) aStudy = appStudy->studyDS();
500 std::set<std::string> aSet;
501 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
503 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
505 for (it->InitEx(true); it->More(); it->Next()) {
507 aSet.insert(obj->GetName());
511 // build a unique name
513 bool isUnique = false;
515 aName = theOperation + "_" + QString::number(++aNumber);
516 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
522 //=================================================================================
525 //=================================================================================
526 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
528 mySelectionMgr->installFilter(myMeshFilter);
530 /* init data from current selection */
531 restoreShowEntityMode();
532 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
534 myGroup = SMESH::SMESH_Group::_nil();
535 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
536 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
538 // NPAL19389: create a group with a selection in another group
539 // set actor of myMesh, if it is visible, else try
540 // any visible actor of group or submesh of myMesh
541 SetAppropriateActor();
543 setDefaultGroupColor();
546 mySelectionMgr->selectedObjects( aList );
547 if( !aList.IsEmpty() )
549 QString aName = aList.First()->getName();
550 myMeshGroupLine->setText(aName);
551 myMeshGroupLine->home( false );
554 myCurrentLineEdit = 0;
556 myTypeGroup->button(0)->setChecked(true);
560 //=================================================================================
563 //=================================================================================
564 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
565 const bool theIsConvert)
567 restoreShowEntityMode();
568 myMesh = theGroup->GetMesh();
571 myNameChanged = true;
572 myName->blockSignals(true);
573 myName->setText(theGroup->GetName());
574 myName->blockSignals(false);
577 SALOMEDS::Color aColor = theGroup->GetColor();
578 setGroupColor( aColor );
580 myMeshGroupLine->setText(theGroup->GetName());
583 switch(theGroup->GetType()) {
584 case SMESH::NODE: aType= 0; break;
585 case SMESH::EDGE: aType = 1; break;
586 case SMESH::FACE: aType = 2; break;
587 case SMESH::VOLUME: aType = 3; break;
589 myTypeGroup->button(aType)->setChecked(true);
591 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
592 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
593 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
594 myFilter = SMESH::Filter::_nil();
596 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
599 // NPAL19389: create a group with a selection in another group
600 // set actor of myMesh, if it is visible, else set
601 // actor of theGroup, if it is visible, else try
602 // any visible actor of group or submesh of myMesh
603 // commented, because an attempt to set selection on not displayed cells leads to error
604 SetAppropriateActor();
606 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
608 anActor = SMESH::FindActorByObject(theGroup);
609 SMESH::SetPickable(anActor);*/
611 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
612 myGrpTypeGroup->button(grpType)->setChecked(true);
613 onGrpTypeChanged(grpType);
616 if ( grpType == 0 ) { // standalone group
617 myCurrentLineEdit = 0;
619 myAllowElemsModif->setChecked( true );
621 setSelectionMode(aType);
623 setShowEntityMode(); // depends on myTypeId
626 if (!theGroup->IsEmpty()) {
627 SMESH::long_array_var anElements = theGroup->GetListOfID();
628 int k = anElements->length();
629 for (int i = 0; i < k; i++) {
630 myIdList.append(anElements[i]);
631 myElements->addItem(QString::number(anElements[i]));
633 myElements->selectAll();
636 else if ( grpType == 1 ) // group on geom
638 QString aShapeName( "" );
639 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
640 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
641 if (!aGroupShape->_is_nil())
643 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
645 aShapeName = aGroupShapeSO->GetName().c_str();
647 myGeomGroupLine->setText( aShapeName );
649 else // group on filter
651 myFilter = myGroupOnFilter->GetFilter();
652 if ( !myFilter->_is_nil() ) {
653 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
654 if ( perdicate->_is_nil() )
655 myFilter = SMESH::Filter::_nil();
661 myNameChanged = true;
662 myName->blockSignals(true);
663 myName->setText(theGroup->GetName());
664 myName->blockSignals(false);
667 onSelectAll(); //updateButtons();
670 //=================================================================================
671 // function : updateButtons()
673 //=================================================================================
674 void SMESHGUI_GroupDlg::updateButtons()
676 bool enable = !myName->text().trimmed().isEmpty();
679 if (myGrpTypeId == 0) { // standalone
680 if ( !mySelectAll->isChecked() )
682 if ( myAllowElemsModif->isChecked() )
684 enable = ( myElements->count() > 0 );
686 else if ((enable = !myFilter->_is_nil() ))
688 SMESH::array_of_ElementType_var types = myFilter->GetTypes();
689 enable = types->length();
692 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
694 else if (myGrpTypeId == 1) // on geom
696 if (CORBA::is_nil(myGroupOnGeom)) // creation mode
697 enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
699 else if (myGrpTypeId == 2) // on filter
701 if (( enable = !myFilter->_is_nil() ))
702 if (CORBA::is_nil(myGroupOnFilter) ) // creation mode
703 enable = !myMesh->_is_nil();
707 myOKBtn->setEnabled(enable);
708 myApplyBtn->setEnabled(enable);
711 //=================================================================================
712 // function : onNameChanged()
714 //=================================================================================
715 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
717 myOldName = myName->text();
719 myNameChanged = !myName->text().trimmed().isEmpty();
722 //=================================================================================
723 // function : onTypeChanged()
724 // purpose : Group elements type radio button management
725 //=================================================================================
726 void SMESHGUI_GroupDlg::onTypeChanged (int id)
728 if (myTypeId != id) {
731 if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
732 setSelectionMode(id);
734 setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
736 onObjectSelectionChanged();
741 //=================================================================================
742 // function : onGrpTypeChanged()
743 // purpose : Group type radio button management
744 //=================================================================================
745 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
747 if (myGrpTypeId != id) {
749 myWGStack->setCurrentIndex( id );
750 myName->blockSignals(true);
751 myName->setText(myOldName);
752 myName->blockSignals(false);
753 onSelectGeomGroup(id != 0);
758 //=================================================================================
759 // function : onColorChanged()
760 // purpose : Color button management
761 //=================================================================================
762 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
767 //=================================================================================
768 // function : setSelectionMode()
769 // purpose : Radio button management
770 //=================================================================================
771 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
774 if (myMesh->_is_nil())
776 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
777 bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
778 if (mySelectionMode != theMode) {
779 // [PAL10408] mySelectionMgr->clearSelected();
780 mySelectionMgr->clearFilters();
782 if (myActorsList.count() > 0)
783 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
784 it.next()->SetPointRepresentation(false);
786 SMESH::SetPointRepresentation(false);
789 case grpNodeSelection:
790 if ( myGrpTypeId == 0 ) // standalone
792 if (myActorsList.count() > 0)
793 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
794 it.next()->SetPointRepresentation(true);
796 SMESH::SetPointRepresentation(true);
798 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
800 case grpEdgeSelection:
801 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
803 case grpFaceSelection:
804 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
806 case grpVolumeSelection:
807 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
809 case grpSubMeshSelection: {
811 SMESH_TypeFilter* f = 0;
813 case 0: f = new SMESH_TypeFilter(SUBMESH); break;
814 case 1: f = new SMESH_TypeFilter(SUBMESH_EDGE); break;
815 case 2: f = new SMESH_TypeFilter(SUBMESH_FACE); break;
816 case 3: f = new SMESH_TypeFilter(SUBMESH_SOLID); break;
817 default:f = new SMESH_TypeFilter(SUBMESH);
819 QList<SUIT_SelectionFilter*> filtList;
820 filtList.append( f );
821 filtList.append( new SMESH_TypeFilter(SUBMESH_COMPOUND));
822 mySubMeshFilter->setFilters( filtList );
824 mySelectionMgr->installFilter( mySubMeshFilter );
826 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
829 case grpGroupSelection: {
831 SMESH_TypeFilter* f = 0;
833 case 0: f = new SMESH_TypeFilter(GROUP_NODE); break;
834 case 1: f = new SMESH_TypeFilter(GROUP_EDGE); break;
835 case 2: f = new SMESH_TypeFilter(GROUP_FACE); break;
836 case 3: f = new SMESH_TypeFilter(GROUP_VOLUME); break;
837 default:f = new SMESH_TypeFilter(GROUP);
839 QList<SUIT_SelectionFilter*> filtList;
840 filtList.append( f );
841 myGroupFilter->setFilters( filtList );
843 mySelectionMgr->installFilter(myGroupFilter);
844 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
847 case grpMeshSelection:
848 mySelectionMgr->installFilter(myMeshFilter);
849 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
851 case grpGeomSelection:
852 mySelectionMgr->installFilter(myGeomFilter);
853 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
856 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
859 if ( aViewWindow ) aViewWindow->Repaint();
860 mySelectionMode = theMode;
864 //=================================================================================
865 // function : onApply()
867 //=================================================================================
868 bool SMESHGUI_GroupDlg::onApply()
870 if (mySMESHGUI->isActiveStudyLocked())
873 if (myName->text().trimmed().isEmpty())
876 SMESH::ElementType aType = SMESH::ALL;
878 case 0: aType = SMESH::NODE; break;
879 case 1: aType = SMESH::EDGE; break;
880 case 2: aType = SMESH::FACE; break;
881 case 3: aType = SMESH::VOLUME; break;
885 QStringList anEntryList;
887 SMESH::SMESH_GroupBase_var resultGroup;
890 if (myGrpTypeId == 0) // standalone
892 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
895 mySelectionMgr->clearSelected();
897 if (myGroup->_is_nil()) { // creation or conversion
898 // check if group on geometry is not null
899 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
900 if (myMesh->_is_nil())
902 if ( myGroupOnGeom->_is_nil() )
903 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
905 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
907 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
908 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
912 if (myGroup->_is_nil()) { // creation
913 if (myMesh->_is_nil())
916 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
918 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
921 if ( mySelectAll->isChecked() ) {
923 myGroup->AddFrom(myMesh.in());
928 if ( !myFilter->_is_nil() &&
929 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
931 myGroup->AddFrom( myFilter );
935 SMESH::long_array_var anIdList = new SMESH::long_array;
936 int i, k = myElements->count();
938 for (i = 0; i < k; i++) {
939 anIdList[i] = myElements->item(i)->text().toInt();
941 myGroup->Add(anIdList.inout());
948 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
951 if ( mySelectAll->isChecked() ) {
954 myGroup->AddFrom(myMesh.in());
959 int i, total = myElements->count();
960 for (i = 0; i < total; i++) {
961 int anId = myElements->item(i)->text().toInt();
962 int idx = myIdList.indexOf(anId);
964 aAddList.append(anId);
966 myIdList.removeAt(idx);
968 if (!aAddList.empty()) {
969 SMESH::long_array_var anIdList = new SMESH::long_array;
970 int added = aAddList.count();
971 anIdList->length(added);
972 for (i = 0; i < added; i++)
973 anIdList[i] = aAddList[i];
974 myGroup->Add(anIdList.inout());
976 if (!myIdList.empty()) {
977 SMESH::long_array_var anIdList = new SMESH::long_array;
978 int removed = myIdList.count();
979 anIdList->length(removed);
980 for (i = 0; i < removed; i++)
981 anIdList[i] = myIdList[i];
982 myGroup->Remove(anIdList.inout());
984 /* init for next operation */
986 for (i = 0; i < total; i++) {
987 myIdList.append(myElements->item(i)->text().toInt());
994 else if (myGrpTypeId == 1) // on geom object
996 if (CORBA::is_nil(myGroupOnGeom)) { // creation
997 if (myMesh->_is_nil() || !myGeomObjects->length())
1000 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1001 GEOM::GEOM_IGroupOperations_var aGroupOp =
1002 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1004 if (myGeomObjects->length() == 1) {
1005 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1006 myName->text().toLatin1().data(),
1010 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1011 if ( aSMESHGen->_is_nil() )
1014 // create a geometry group
1015 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1016 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1018 if (geomGen->_is_nil() || !aStudy)
1021 GEOM::GEOM_IGroupOperations_var op =
1022 geomGen->GetIGroupOperations(aStudy->StudyId());
1026 // check and add all selected GEOM objects: they must be
1027 // a sub-shapes of the main GEOM and must be of one type
1028 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1029 for ( int i =0; i < myGeomObjects->length(); i++) {
1030 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1032 aGroupType = aSubShapeType;
1033 else if (aSubShapeType != aGroupType) {
1034 aGroupType = TopAbs_SHAPE;
1039 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1040 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1041 op->UnionList(aGroupVar, myGeomObjects);
1044 // publish the GEOM group in study
1045 QString aNewGeomGroupName ( "Auto_group_for_" );
1046 aNewGeomGroupName += myName->text();
1047 SALOMEDS::SObject_var aNewGroupSO =
1048 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
1049 aNewGeomGroupName.toLatin1().data(), aMeshShape);
1052 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1053 myName->text().toLatin1().data(),
1056 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1062 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1067 if (myGrpTypeId == 2) // group on filter
1069 if ( myFilter->_is_nil() ) return false;
1071 if (CORBA::is_nil(myGroupOnFilter)) { // creation
1072 if (myMesh->_is_nil())
1075 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1076 myName->text().toLatin1().data(),
1079 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1084 myGroupOnFilter->SetFilter( myFilter );
1086 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1094 SALOMEDS::Color aColor = getGroupColor();
1095 resultGroup->SetColor(aColor);
1097 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1099 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1103 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1105 /* init for the next operation */
1106 myName->setText( "" );
1107 myElements->clear();
1108 myGroup = SMESH::SMESH_Group::_nil();
1109 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1110 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1111 myFilter = SMESH::Filter::_nil();
1115 resultGroup->SetName(myName->text().toLatin1().data());
1118 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
1119 anActor->setName(myName->text().toLatin1().data());
1120 switch ( myTypeId ) {
1121 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1122 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1128 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1129 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1134 SMESHGUI::Modified();
1135 mySMESHGUI->updateObjBrowser(true);
1136 SMESH::UpdateView(); // asv: fix of BUG PAL5515
1137 mySelectionMgr->clearSelected();
1139 if( LightApp_Application* anApp =
1140 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1141 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1146 //=================================================================================
1147 // function : onOK()
1149 //=================================================================================
1150 void SMESHGUI_GroupDlg::onOK()
1152 setIsApplyAndClose( true );
1155 setIsApplyAndClose( false );
1158 //=================================================================================
1159 // function : onListSelectionChanged()
1160 // purpose : Called when selection in element list is changed
1161 //=================================================================================
1162 void SMESHGUI_GroupDlg::onListSelectionChanged()
1164 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1165 if( myIsBusy || myActorsList.count() == 0 ) return;
1168 if (myCurrentLineEdit == 0) {
1169 mySelectionMgr->clearSelected();
1170 TColStd_MapOfInteger aIndexes;
1171 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1172 QListWidgetItem* anItem;
1173 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1174 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1175 SALOME_ListIO aList;
1176 aList.Append(myActorsList.first()->getIO());
1177 mySelectionMgr->setSelectedObjects(aList,false);
1182 //=================================================================================
1183 // function : onObjectSelectionChanged()
1184 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1185 //=================================================================================
1186 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1188 if ( myIsBusy || !isEnabled()) return;
1189 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1193 SALOME_ListIO aList;
1194 mySelectionMgr->selectedObjects( aList );
1196 int aNbSel = aList.Extent();
1197 myElements->clearSelection();
1199 if (myCurrentLineEdit)
1201 myCurrentLineEdit->setText( "" );
1202 QString aString = "";
1204 if (myCurrentLineEdit == myMeshGroupLine)
1206 mySelectSubMesh->setEnabled(false);
1207 mySelectGroup->setEnabled(false);
1208 myGroupLine->setText( "" );
1209 mySubMeshLine->setText( "" );
1211 myGeomGroupBtn->setEnabled(false);
1212 myGeomGroupLine->setEnabled(false);
1213 myGeomGroupLine->setText( "" );
1214 myGeomObjects = new GEOM::ListOfGO();
1215 myGeomObjects->length(0);
1217 if (myGeomGroupBtn->isChecked())
1218 myGeomGroupBtn->setChecked(false);
1220 myName->setText( "" );
1222 myElements->clear();
1225 myGroup = SMESH::SMESH_Group::_nil();
1226 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1227 restoreShowEntityMode();
1228 myMesh = SMESH::SMESH_Mesh::_nil();
1234 Handle(SALOME_InteractiveObject) IO = aList.First();
1237 restoreShowEntityMode();
1238 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1239 setShowEntityMode();
1241 if (myMesh->_is_nil())
1248 if ( myFilterDlg && !myMesh->_is_nil()){
1249 myFilterDlg->SetMesh( myMesh );
1251 myGroup = SMESH::SMESH_Group::_nil();
1253 // NPAL19389: create a group with a selection in another group
1254 // set actor of myMesh, if it is visible, else try
1255 // any visible actor of group or submesh of myMesh
1256 SetAppropriateActor();
1258 aString = aList.First()->getName();
1259 myMeshGroupLine->setText(aString);
1260 myMeshGroupLine->home( false );
1262 mySelectSubMesh->setEnabled(true);
1263 mySelectGroup->setEnabled(true);
1264 myGeomGroupBtn->setEnabled(true);
1265 myGeomGroupLine->setEnabled(true);
1269 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1270 if (aGroup->_is_nil())
1277 myGroup = SMESH::SMESH_Group::_nil();
1278 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1282 mySelectSubMesh->setEnabled(true);
1283 mySelectGroup->setEnabled(true);
1285 myCurrentLineEdit = 0;
1290 if (myGrpTypeId == 0)
1296 myElements->clear();
1297 setSelectionMode(myTypeId);
1305 else if (myCurrentLineEdit == myGeomGroupLine)
1307 myGeomObjects = new GEOM::ListOfGO();
1310 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1312 if (aNbSel == 0 || !aMeshSO)
1314 myGeomObjects->length(0);
1320 myGeomObjects->length(aNbSel);
1322 GEOM::GEOM_Object_var aGeomGroup;
1325 SALOME_ListIteratorOfListIO anIt (aList);
1326 for (; anIt.More(); anIt.Next())
1328 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1330 // Check if the object is a geometry group
1331 if (CORBA::is_nil(aGeomGroup))
1334 // Check if group constructed on the same shape as a mesh or on its child
1335 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1336 GEOM::GEOM_IGroupOperations_var anOp =
1337 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1339 // The main shape of the group
1340 GEOM::GEOM_Object_var aGroupMainShape;
1341 if (aGeomGroup->GetType() == 37)
1342 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1344 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1345 _PTR(SObject) aGroupMainShapeSO =
1346 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1347 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1349 _PTR(SObject) anObj, aRef;
1350 bool isRefOrSubShape = false;
1351 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1352 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1353 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1354 isRefOrSubShape = true;
1356 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1357 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1358 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1359 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1360 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1361 if (aRef->GetID() == aFather->GetID())
1362 isRefOrSubShape = true;
1364 aFather = aFather->GetFather();
1368 if (isRefOrSubShape)
1369 myGeomObjects[i++] = aGeomGroup;
1372 myGeomObjects->length(i);
1384 if (myCurrentLineEdit == mySubMeshLine)
1385 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1386 else if (myCurrentLineEdit == myGroupLine)
1387 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1388 else if (myCurrentLineEdit == myGeomGroupLine)
1389 aString = tr( "%1 Objects" ).arg(aNbSel);
1392 aString = aList.First()->getName();
1396 myCurrentLineEdit->setText(aString);
1397 myCurrentLineEdit->home(false);
1398 // 07.06.2008 skl for IPAL19574:
1399 // change name of group only if it is empty
1400 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1401 myOldName = myName->text();
1402 myName->blockSignals(true);
1403 myName->setText(aString);
1404 myName->blockSignals(false);
1409 else // !myCurrentLineEdit: local selection of nodes or elements
1411 if (aNbSel == 1 && myActorsList.count() > 0 )
1413 // NPAL19389: create a group with a selection in another group
1414 // Switch myActor to the newly selected one, if the last
1415 // is visible and belongs to group or submesh of myMesh
1416 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1417 Handle(SALOME_InteractiveObject) selIO = aList.First();
1418 if (curIO->hasEntry() && selIO->hasEntry()) {
1419 const char* selEntry = selIO->getEntry();
1420 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1421 // different objects: selected and myActor
1422 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1423 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1424 // newly selected actor is visible
1427 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1429 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1430 int len = strlen(meshEntry);
1432 if (strncmp(selEntry, meshEntry, len) == 0) {
1433 // selected object is myMesh or a part of it
1434 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1437 SMESH::SetPickable(myActor);
1446 QString aListStr = "";
1448 if (myTypeId == 0) {
1449 QListIterator<SMESH_Actor*> it( myActorsList );
1450 while ( it.hasNext() ) {
1452 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1456 QListIterator<SMESH_Actor*> it( myActorsList );
1457 while ( it.hasNext() ) {
1459 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1464 QListWidgetItem* anItem;
1465 QList<QListWidgetItem*> listItemsToSel;
1466 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1467 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1468 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1469 foreach(anItem, found)
1470 if (!anItem->isSelected())
1471 listItemsToSel.push_back(anItem);
1473 bool blocked = myElements->signalsBlocked();
1474 myElements->blockSignals(true);
1475 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1476 myElements->blockSignals(blocked);
1477 onListSelectionChanged();
1478 listItemsToSel.clear();
1483 if (myActorsList.count() == 0) {
1484 if (!myGroup->_is_nil()) {
1485 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1487 myActorsList.append( anActor );
1489 else if(!myGroupOnGeom->_is_nil()) {
1490 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1492 myActorsList.append( anActor );
1495 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1497 myActorsList.append( anActor );
1501 // somehow, if we display the mesh, while selecting from another actor,
1502 // the mesh becomes pickable, and there is no way to select any element
1503 if (myActorsList.count() > 0) {
1504 QListIterator<SMESH_Actor*> it( myActorsList );
1505 while ( it.hasNext() ) {
1506 SMESH_Actor* anActor = it.next();
1507 if ( IsActorVisible(anActor) )
1508 anActor->SetPickable(true);
1515 //=================================================================================
1516 // function : onSelectAll()
1517 // purpose : Called when "Select all" is checked
1518 //=================================================================================
1519 void SMESHGUI_GroupDlg::onSelectAll()
1521 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1523 myElementsLab->setEnabled( !noElemsModif );
1524 myElements->setEnabled ( !noElemsModif );
1525 myFilterBtn->setEnabled ( !mySelectAll->isChecked() );
1526 myAddBtn->setEnabled ( !noElemsModif );
1527 myRemoveBtn->setEnabled ( !noElemsModif );
1528 mySortBtn->setEnabled ( !noElemsModif );
1529 mySelectBox->setEnabled ( !noElemsModif );
1530 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1532 int selMode = mySelectionMode;
1533 mySelectionMode = grpNoSelection;
1534 setSelectionMode( selMode );
1538 //=================================================================================
1539 // function : onSelectSubMesh()
1540 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1541 //=================================================================================
1542 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1545 if (mySelectGroup->isChecked()) {
1546 mySelectGroup->setChecked(false);
1548 //VSR: else if (mySelectGeomGroup->isChecked()) {
1549 //VSR: mySelectGeomGroup->setChecked(false);
1551 myCurrentLineEdit = mySubMeshLine;
1552 setSelectionMode(grpSubMeshSelection);
1555 mySubMeshLine->setText( "" );
1556 myCurrentLineEdit = 0;
1558 setSelectionMode(myTypeId);
1560 mySubMeshBtn->setEnabled(on);
1561 mySubMeshLine->setEnabled(on);
1565 //=================================================================================
1566 // function : (onSelectGroup)
1567 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1568 //=================================================================================
1569 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1572 if (mySelectSubMesh->isChecked()) {
1573 mySelectSubMesh->setChecked(false);
1575 myCurrentLineEdit = myGroupLine;
1576 setSelectionMode(grpGroupSelection);
1579 myGroupLine->setText( "" );
1580 myCurrentLineEdit = 0;
1582 setSelectionMode(myTypeId);
1584 myGroupBtn->setEnabled(on);
1585 myGroupLine->setEnabled(on);
1589 //=================================================================================
1590 // function : (onSelectGeomGroup)
1591 // purpose : Called when group type changed. on == "on group" or "on filter"
1592 //=================================================================================
1593 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1596 if (mySelectSubMesh->isChecked()) {
1597 mySelectSubMesh->setChecked(false);
1599 else if (mySelectGroup->isChecked()) {
1600 mySelectGroup->setChecked(false);
1602 if ( myGrpTypeId == 1 ) { // on group
1603 myCurrentLineEdit = myGeomGroupLine;
1607 myCurrentLineEdit = 0;
1609 setSelectionMode(grpAllSelection);
1612 myGeomGroupBtn->setChecked(false);
1613 myGeomObjects->length(0);
1614 myGeomGroupLine->setText( "" );
1615 myCurrentLineEdit = 0;
1617 setSelectionMode( myTypeId );
1621 //=================================================================================
1622 // function : setCurrentSelection()
1624 //=================================================================================
1625 void SMESHGUI_GroupDlg::setCurrentSelection()
1627 QPushButton* send = (QPushButton*)sender();
1628 myCurrentLineEdit = 0;
1629 if (send == myMeshGroupBtn) {
1630 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1631 mySelectionMgr->clearSelected();
1633 setSelectionMode(grpMeshSelection);
1635 setSelectionMode(grpGroupSelection);
1636 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1637 myCurrentLineEdit = myMeshGroupLine;
1638 onObjectSelectionChanged();
1640 else if (send == mySubMeshBtn) {
1641 myCurrentLineEdit = mySubMeshLine;
1642 onObjectSelectionChanged();
1644 else if (send == myGroupBtn) {
1645 myCurrentLineEdit = myGroupLine;
1646 onObjectSelectionChanged();
1651 //=================================================================================
1652 // function : setFilters()
1653 // purpose : SLOT. Called when "Filter" button pressed.
1654 //=================================================================================
1655 void SMESHGUI_GroupDlg::setFilters()
1657 if(myMesh->_is_nil()) {
1658 SUIT_MessageBox::critical(this,
1660 tr("NO_MESH_SELECTED"));
1664 SMESH::ElementType aType = SMESH::ALL;
1667 case 0 : aType = SMESH::NODE; break;
1668 case 1 : aType = SMESH::EDGE; break;
1669 case 2 : aType = SMESH::FACE; break;
1670 case 3 : aType = SMESH::VOLUME; break;
1674 if ( myFilterDlg == 0 )
1676 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1677 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1680 myFilterDlg->Init( aType );
1682 if ( !myGroupOnFilter->_is_nil() )
1684 myFilterDlg->SetFilter( myFilter, aType );
1685 myFilterDlg->Init( aType );
1688 myFilterDlg->SetSelection();
1689 myFilterDlg->SetMesh( myMesh );
1690 myFilterDlg->SetSourceWg( myElements, false );
1692 myFilterDlg->show();
1695 //=================================================================================
1696 // function : onFilterAccepted()
1697 // purpose : SLOT. Called when Filter dlg closed with OK button.
1698 // Uncheck "Select submesh" and "Select group" checkboxes
1699 //=================================================================================
1700 void SMESHGUI_GroupDlg::onFilterAccepted()
1702 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1704 mySelectionMode = myTypeId;
1705 mySelectSubMesh->setChecked( false );
1706 mySelectGroup->setChecked( false );
1708 // get a filter from myFilterDlg
1709 myFilter = myFilterDlg->GetFilter();
1710 if ( !myFilter->_is_nil() ) {
1711 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1712 if ( perdicate->_is_nil() )
1713 myFilter = SMESH::Filter::_nil();
1715 // set mesh to myFilter
1716 if ( !myFilter->_is_nil() ) {
1717 SMESH::SMESH_Mesh_var mesh = myMesh;
1718 if ( mesh->_is_nil() ) {
1719 if ( !myGroup->_is_nil() )
1720 mesh = myGroup->GetMesh();
1721 else if ( !myGroupOnGeom->_is_nil() )
1722 mesh = myGroupOnGeom->GetMesh();
1723 else if ( !myGroupOnFilter->_is_nil() )
1724 mesh = myGroupOnFilter->GetMesh();
1726 myFilter->SetMesh( mesh );
1732 //=================================================================================
1733 // function : onAdd()
1735 //=================================================================================
1736 void SMESHGUI_GroupDlg::onAdd()
1738 SALOME_ListIO aList;
1739 mySelectionMgr->selectedObjects( aList );
1741 int aNbSel = aList.Extent();
1743 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1746 int sizeBefore = myElements->count();
1748 SMESH::ElementType aType = SMESH::ALL;
1751 aType = SMESH::NODE;
1752 mySelector->SetSelectionMode(NodeSelection);
1755 aType = SMESH::EDGE;
1756 mySelector->SetSelectionMode(EdgeSelection);
1759 aType = SMESH::FACE;
1760 mySelector->SetSelectionMode(FaceSelection);
1763 aType = SMESH::VOLUME;
1764 mySelector->SetSelectionMode(VolumeSelection);
1767 mySelector->SetSelectionMode(ActorSelection);
1770 QListWidgetItem* anItem = 0;
1771 QList<QListWidgetItem*> listItemsToSel;
1773 if (myCurrentLineEdit == 0) {
1774 //if (aNbSel != 1) { myIsBusy = false; return; }
1775 QString aListStr = "";
1777 if (myTypeId == 0) {
1778 QListIterator<SMESH_Actor*> it( myActorsList );
1779 while ( it.hasNext() ) {
1781 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1786 QListIterator<SMESH_Actor*> it( myActorsList );
1787 while ( it.hasNext() ) {
1789 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1794 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1795 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1796 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1797 if (found.count() == 0) {
1798 anItem = new QListWidgetItem(*it);
1799 myElements->addItem(anItem);
1800 if (!anItem->isSelected())
1801 listItemsToSel.push_back(anItem);
1804 foreach(anItem, found)
1805 if (!anItem->isSelected())
1806 listItemsToSel.push_back(anItem);
1809 bool blocked = myElements->signalsBlocked();
1810 myElements->blockSignals(true);
1811 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1812 myElements->blockSignals(blocked);
1813 onListSelectionChanged();
1814 listItemsToSel.clear();
1816 } else if (myCurrentLineEdit == mySubMeshLine) {
1817 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1819 SALOME_ListIO aList;
1820 mySelectionMgr->selectedObjects( aList );
1822 SALOME_ListIteratorOfListIO anIt (aList);
1823 for ( ; anIt.More(); anIt.Next()) {
1824 SMESH::SMESH_subMesh_var aSubMesh =
1825 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1826 if (!aSubMesh->_is_nil()) {
1827 // check if mesh is the same
1828 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1830 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1831 int k = anElements->length();
1832 for (int i = 0; i < k; i++) {
1833 QString aText = QString::number(anElements[i]);
1834 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1835 if (found.count() == 0) {
1836 anItem = new QListWidgetItem(aText);
1837 myElements->addItem(anItem);
1838 if (!anItem->isSelected())
1839 listItemsToSel.push_back(anItem);
1842 foreach(anItem, found)
1843 if (!anItem->isSelected())
1844 listItemsToSel.push_back(anItem);
1847 bool blocked = myElements->signalsBlocked();
1848 myElements->blockSignals(true);
1849 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1850 myElements->blockSignals(blocked);
1851 onListSelectionChanged();
1852 listItemsToSel.clear();
1854 catch (const SALOME::SALOME_Exception& ex) {
1855 SalomeApp_Tools::QtCatchCorbaException(ex);
1860 mySelectSubMesh->setChecked(false);
1862 onListSelectionChanged();
1864 } else if (myCurrentLineEdit == myGroupLine) {
1865 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1866 SALOME_ListIO aList;
1867 mySelectionMgr->selectedObjects( aList );
1869 SALOME_ListIteratorOfListIO anIt (aList);
1870 for ( ; anIt.More(); anIt.Next()) {
1871 SMESH::SMESH_GroupBase_var aGroup =
1872 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1873 if (!aGroup->_is_nil()) {
1874 // check if mesh is the same
1875 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1876 SMESH::long_array_var anElements = aGroup->GetListOfID();
1877 int k = anElements->length();
1878 for (int i = 0; i < k; i++) {
1879 QString aText = QString::number(anElements[i]);
1880 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1881 if (found.count() == 0) {
1882 anItem = new QListWidgetItem(aText);
1883 myElements->addItem(anItem);
1884 if (!anItem->isSelected())
1885 listItemsToSel.push_back(anItem);
1888 foreach(anItem, found)
1889 if (!anItem->isSelected())
1890 listItemsToSel.push_back(anItem);
1893 bool blocked = myElements->signalsBlocked();
1894 myElements->blockSignals(true);
1895 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1896 myElements->blockSignals(blocked);
1897 onListSelectionChanged();
1898 listItemsToSel.clear();
1902 mySelectGroup->setChecked(false);
1904 onListSelectionChanged();
1906 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1907 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1908 GEOM::GEOM_IGroupOperations_var aGroupOp =
1909 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1911 SMESH::ElementType aGroupType = SMESH::ALL;
1912 switch(aGroupOp->GetType(myGeomObjects[0])) {
1913 case 7: aGroupType = SMESH::NODE; break;
1914 case 6: aGroupType = SMESH::EDGE; break;
1915 case 4: aGroupType = SMESH::FACE; break;
1916 case 2: aGroupType = SMESH::VOLUME; break;
1917 default: myIsBusy = false; return;
1920 if (aGroupType == aType) {
1921 _PTR(SObject) aGroupSO =
1922 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1923 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1925 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1926 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1927 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
1928 aBelongToGeom->SetGeom(myGeomObjects[0]);
1929 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1930 aBelongToGeom->SetElementType(aType);
1931 aFilter->SetPredicate(aBelongToGeom);
1933 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1935 int k = anElements->length();
1936 for (int i = 0; i < k; i++) {
1937 QString aText = QString::number(anElements[i]);
1938 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1939 if (found.count() == 0) {
1940 anItem = new QListWidgetItem(aText);
1941 myElements->addItem(anItem);
1942 if (!anItem->isSelected())
1943 listItemsToSel.push_back(anItem);
1946 foreach(anItem, found)
1947 if (!anItem->isSelected())
1948 listItemsToSel.push_back(anItem);
1951 bool blocked = myElements->signalsBlocked();
1952 myElements->blockSignals(true);
1953 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1954 myElements->blockSignals(blocked);
1955 onListSelectionChanged();
1956 listItemsToSel.clear();
1959 //VSR: mySelectGeomGroup->setChecked(false);
1961 onListSelectionChanged();
1964 if ( sizeBefore < myElements->count() )
1965 ++myNbChangesOfContents;
1966 // mySelectionMgr->clearSelected();
1970 //=================================================================================
1971 // function : onRemove()
1973 //=================================================================================
1974 void SMESHGUI_GroupDlg::onRemove()
1977 int sizeBefore = myElements->count();
1979 if (myCurrentLineEdit == 0) {
1980 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1981 QListWidgetItem* item;
1982 foreach(item, selItems) delete item;
1984 SALOME_ListIO aList;
1985 mySelectionMgr->selectedObjects( aList );
1987 int aNbSel = aList.Extent();
1989 if (aNbSel == 0) { myIsBusy = false; return; }
1991 SMESH::ElementType aType = SMESH::ALL;
1993 case 0: aType = SMESH::NODE; break;
1994 case 1: aType = SMESH::EDGE; break;
1995 case 2: aType = SMESH::FACE; break;
1996 case 3: aType = SMESH::VOLUME; break;
1999 if (myCurrentLineEdit == mySubMeshLine) {
2000 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2001 SALOME_ListIO aList;
2002 mySelectionMgr->selectedObjects( aList );
2004 SALOME_ListIteratorOfListIO anIt (aList);
2005 for ( ; anIt.More(); anIt.Next()) {
2006 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2007 if (!aSubMesh->_is_nil()) {
2008 // check if mesh is the same
2009 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2010 if (aType == SMESH::NODE) {
2012 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2013 int k = anElements->length();
2014 for (int i = 0; i < k; i++) {
2015 QList<QListWidgetItem*> found =
2016 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2017 QListWidgetItem* anItem;
2018 foreach(anItem, found) delete anItem;
2021 catch (const SALOME::SALOME_Exception& ex) {
2022 SalomeApp_Tools::QtCatchCorbaException(ex);
2027 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2028 int k = anElements->length();
2029 for (int i = 0; i < k; i++) {
2030 QList<QListWidgetItem*> found =
2031 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2032 QListWidgetItem* anItem;
2033 foreach(anItem, found) delete anItem;
2036 catch (const SALOME::SALOME_Exception& ex) {
2037 SalomeApp_Tools::QtCatchCorbaException(ex);
2044 else if (myCurrentLineEdit == myGroupLine) {
2045 Standard_Boolean aRes;
2046 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2047 SALOME_ListIO aList;
2048 mySelectionMgr->selectedObjects( aList );
2050 SALOME_ListIteratorOfListIO anIt (aList);
2051 for ( ; anIt.More(); anIt.Next()) {
2052 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2053 if (aRes && !aGroup->_is_nil()) {
2054 // check if mesh is the same
2055 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2056 SMESH::long_array_var anElements = aGroup->GetListOfID();
2057 int k = anElements->length();
2058 for (int i = 0; i < k; i++) {
2059 QList<QListWidgetItem*> found =
2060 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2061 QListWidgetItem* anItem;
2062 foreach(anItem, found) delete anItem;
2070 if ( sizeBefore > myElements->count() )
2071 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2075 //=================================================================================
2076 // function : onSort()
2078 //=================================================================================
2079 void SMESHGUI_GroupDlg::onSort()
2081 // PAL5412: sorts items in ascending by "string" value
2082 // myElements->sort(true);
2083 // myElements->update();
2084 int i, k = myElements->count();
2087 QList<int> aSelected;
2088 std::vector<int> anArray(k);
2089 // QMemArray<int> anArray(k);
2091 for (i = 0; i < k; i++) {
2092 int id = myElements->item(i)->text().toInt();
2094 if (myElements->item(i)->isSelected())
2095 aSelected.append(id);
2097 // sort & update list
2098 std::sort(anArray.begin(), anArray.end());
2100 myElements->clear();
2101 QListWidgetItem* anItem;
2102 QList<QListWidgetItem*> listItemsToSel;
2103 for (i = 0; i < k; i++) {
2104 anItem = new QListWidgetItem(QString::number(anArray[i]));
2105 myElements->addItem(anItem);
2106 if (aSelected.contains(anArray[i]))
2107 listItemsToSel.push_back(anItem);
2109 bool blocked = myElements->signalsBlocked();
2110 myElements->blockSignals(true);
2111 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2112 myElements->blockSignals(blocked);
2113 listItemsToSel.clear();
2118 //=================================================================================
2119 // function : closeEvent()
2121 //=================================================================================
2122 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
2127 //=================================================================================
2128 // function : onVisibilityChanged()
2130 //=================================================================================
2131 void SMESHGUI_GroupDlg::onVisibilityChanged()
2133 SetAppropriateActor();
2136 //=================================================================================
2137 // function : SMESHGUI_GroupDlg::onClose
2138 // purpose : SLOT called when "Close" button pressed. Close dialog
2139 //=================================================================================
2140 void SMESHGUI_GroupDlg::onClose()
2142 if (SMESH::GetCurrentVtkView()) {
2143 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2144 SMESH::SetPointRepresentation(false);
2145 SMESH::SetPickable();
2146 restoreShowEntityMode();
2149 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2150 SUIT_DataOwnerPtrList aList;
2151 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2152 mySelectionMgr->setSelected( aList );
2155 mySelectionMgr->clearSelected();
2156 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2157 aViewWindow->SetSelectionMode(ActorSelection);
2158 mySelectionMgr->clearFilters();
2159 mySMESHGUI->ResetState();
2164 //=================================================================================
2165 // function : onHelp()
2167 //=================================================================================
2168 void SMESHGUI_GroupDlg::onHelp()
2170 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2172 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2176 platform = "winapplication";
2178 platform = "application";
2180 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2181 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2182 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2184 arg(myHelpFileName));
2188 //=================================================================================
2189 // function : SMESHGUI_GroupDlg::onDeactivate
2190 // purpose : SLOT called when dialog must be deativated
2191 //=================================================================================
2192 void SMESHGUI_GroupDlg::onDeactivate()
2194 mySMESHGUI->ResetState();
2198 //=================================================================================
2199 // function : SMESHGUI_GroupDlg::enterEvent
2200 // purpose : Event filter
2201 //=================================================================================
2202 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2205 mySMESHGUI->EmitSignalDeactivateDialog();
2207 mySelectionMode = grpNoSelection;
2208 setSelectionMode(myTypeId);
2209 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2210 mySMESHGUI->SetActiveDialogBox(this);
2211 mySMESHGUI->SetState(800);
2215 //=================================================================================
2216 // function : hideEvent
2217 // purpose : caused by ESC key
2218 //=================================================================================
2219 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
2221 if (!isMinimized() && !myIsBusy)
2225 //=================================================================================
2226 // function : keyPressEvent()
2228 //=================================================================================
2229 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2231 QDialog::keyPressEvent( e );
2232 if ( e->isAccepted() )
2235 if ( e->key() == Qt::Key_F1 )
2242 //================================================================================
2244 * \brief Enable showing of the popup when Geometry selection btn is clicked
2245 * \param enable - true to enable
2247 //================================================================================
2249 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2251 void SMESHGUI_GroupDlg::updateGeomPopup()
2253 bool enable = false;
2255 if ( !myMesh->_is_nil() )
2256 enable = myMesh->NbEdges() > 0;
2258 if ( myGeomGroupBtn )
2260 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2262 if ( !myGeomPopup ) {
2263 myGeomPopup = new QMenu(this);
2264 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2265 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2266 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2268 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2274 //=================================================================================
2275 // function : onGeomSelectionButton()
2277 //=================================================================================
2278 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2280 if ( myGeomPopup && isBtnOn )
2282 myCurrentLineEdit = myGeomGroupLine;
2283 QAction* a = myGeomPopup->exec( QCursor::pos() );
2284 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2285 setSelectionMode(grpGeomSelection);
2289 myCurrentLineEdit = 0;
2290 setSelectionMode(grpAllSelection);
2294 //=================================================================================
2295 // function : onGeomPopup()
2297 //=================================================================================
2298 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2300 int index = myActions[a];
2301 if ( index == GEOM_BY_MESH_INDEX )
2303 mySelectionMode = grpNoSelection;
2304 if ( !myShapeByMeshOp ) {
2305 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2306 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2307 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2308 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2309 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2311 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2312 if ( !myMesh->_is_nil() ) {
2314 hide(); // stop processing selection
2316 myShapeByMeshOp->setModule( mySMESHGUI );
2317 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2318 myShapeByMeshOp->SetMesh( myMesh );
2319 myShapeByMeshOp->start();
2324 //================================================================================
2326 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2328 //================================================================================
2330 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2332 if ( myShapeByMeshOp == op ) {
2333 mySMESHGUI->getApp()->updateObjectBrowser();
2335 // Select a found geometry object
2336 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2337 if ( !aGeomVar->_is_nil() )
2339 QString ID = aGeomVar->GetStudyEntry();
2340 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2341 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2342 SALOME_ListIO anIOList;
2343 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2344 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2345 anIOList.Append( anIO );
2346 mySelectionMgr->setSelectedObjects( anIOList, false );
2347 onObjectSelectionChanged();
2353 //================================================================================
2355 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2357 //================================================================================
2359 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2361 if ( myShapeByMeshOp == op )
2364 setSelectionMode(grpGeomSelection);
2368 //=================================================================================
2369 // function : setGroupColor()
2371 //=================================================================================
2372 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2374 QColor aQColor( (int)( theColor.R * 255.0 ),
2375 (int)( theColor.G * 255.0 ),
2376 (int)( theColor.B * 255.0 ) );
2377 setGroupQColor( aQColor );
2380 //=================================================================================
2381 // function : getGroupColor()
2383 //=================================================================================
2384 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2386 QColor aQColor = getGroupQColor();
2388 SALOMEDS::Color aColor;
2389 aColor.R = (float)aQColor.red() / 255.0;
2390 aColor.G = (float)aQColor.green() / 255.0;
2391 aColor.B = (float)aQColor.blue() / 255.0;
2396 //=================================================================================
2397 // function : setGroupQColor()
2399 //=================================================================================
2400 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2402 if( theColor.isValid() )
2403 myColorBtn->setColor( theColor );
2406 //=================================================================================
2407 // function : getGroupQColor()
2409 //=================================================================================
2410 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2412 return myColorBtn->color();
2415 //=================================================================================
2416 // function : setDefaultGroupColor()
2418 //=================================================================================
2419 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2421 if( myMesh->_is_nil() )
2424 bool isAutoColor = myMesh->GetAutoColor();
2429 int r = 0, g = 0, b = 0;
2430 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2431 aQColor.setRgb( r, g, b );
2435 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2437 QList<SALOMEDS::Color> aReservedColors;
2438 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2440 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2441 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2442 aReservedColors.append( aReservedColor );
2445 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2446 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2447 (int)( aColor.G * 255.0 ),
2448 (int)( aColor.B * 255.0 ) );
2452 setGroupQColor( aQColor );
2455 //=================================================================================
2456 // function : SetAppropriateActor()
2457 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2458 // NPAL19389: create a group with a selection in another group.
2459 // if mesh actor is not visible - find any first visible group or submesh
2460 //=================================================================================
2461 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2463 bool isActor = false;
2464 myActorsList.clear();
2466 if (myMesh->_is_nil()) return false;
2468 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2470 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2472 if (!myGroupOnGeom->_is_nil()) {
2473 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2474 if (anActor && anActor->hasIO())
2477 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2480 myActorsList.append(anActor);
2486 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2487 if (anActor && anActor->hasIO()) {
2489 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2492 myActorsList.append(anActor);
2496 if (!isActor && !myGroup->_is_nil()) {
2497 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2498 if (anActor && anActor->hasIO())
2499 myActorsList.append(anActor);
2502 // try any visible actor of group or submesh of current mesh
2505 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2507 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2508 int len = strlen(meshEntry);
2510 // iterate on all actors in current view window, search for
2511 // any visible actor, that belongs to group or submesh of current mesh
2512 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2513 vtkActorCollection *aCollection = aCopy.GetActors();
2514 int nbItems = aCollection->GetNumberOfItems();
2515 for (int i=0; i<nbItems && !isActor; i++)
2517 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2518 if (anActor && anActor->hasIO()) {
2519 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2520 if (aViewWindow->isVisible(anIO)) {
2521 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2522 myActorsList.append(anActor);
2530 if (myActorsList.count() > 0) {
2531 QListIterator<SMESH_Actor*> it( myActorsList );
2532 while ( it.hasNext() ) {
2533 SMESH_Actor* anActor = it.next();
2534 if ( IsActorVisible(anActor) )
2535 anActor->SetPickable(true);
2539 return ( isActor || (myActorsList.count() > 0) );
2542 //=======================================================================
2543 //function : setShowEntityMode
2544 //purpose : make shown only entity corresponding to my type
2545 //=======================================================================
2546 void SMESHGUI_GroupDlg::setShowEntityMode()
2548 if ( !myMesh->_is_nil() ) {
2549 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2550 if (!myStoredShownEntity)
2551 myStoredShownEntity = actor->GetEntityMode();
2552 switch ( myTypeId ) {
2553 case 0: restoreShowEntityMode(); break;
2554 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2555 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2556 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2562 //=======================================================================
2563 //function : restoreShowEntityMode
2564 //purpose : restore ShowEntity mode of myActor
2565 //=======================================================================
2566 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2568 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2569 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2570 actor->SetEntityMode(myStoredShownEntity);
2573 myStoredShownEntity = 0;
2576 //=======================================================================
2577 //function : IsActorVisible
2578 //purpose : return visibility of the actor
2579 //=======================================================================
2580 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2582 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2583 if (theActor && aViewWindow)
2584 return aViewWindow->isVisible(theActor->getIO());
2588 //================================================================
2589 //function : setIsApplyAndClose
2590 //purpose : Set value of the flag indicating that the dialog is
2591 // accepted by Apply & Close button
2592 //================================================================
2593 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2595 myIsApplyAndClose = theFlag;
2598 //================================================================
2599 //function : isApplyAndClose
2600 //purpose : Get value of the flag indicating that the dialog is
2601 // accepted by Apply & Close button
2602 //================================================================
2603 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2605 return myIsApplyAndClose;