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;
1124 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
1128 SMESHGUI::Modified();
1129 mySMESHGUI->updateObjBrowser(true);
1130 SMESH::UpdateView(); // asv: fix of BUG PAL5515
1131 mySelectionMgr->clearSelected();
1133 if( LightApp_Application* anApp =
1134 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1135 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1140 //=================================================================================
1141 // function : onOK()
1143 //=================================================================================
1144 void SMESHGUI_GroupDlg::onOK()
1146 setIsApplyAndClose( true );
1149 setIsApplyAndClose( false );
1152 //=================================================================================
1153 // function : onListSelectionChanged()
1154 // purpose : Called when selection in element list is changed
1155 //=================================================================================
1156 void SMESHGUI_GroupDlg::onListSelectionChanged()
1158 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1159 if( myIsBusy || myActorsList.count() == 0 ) return;
1162 if (myCurrentLineEdit == 0) {
1163 mySelectionMgr->clearSelected();
1164 TColStd_MapOfInteger aIndexes;
1165 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1166 QListWidgetItem* anItem;
1167 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1168 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1169 SALOME_ListIO aList;
1170 aList.Append(myActorsList.first()->getIO());
1171 mySelectionMgr->setSelectedObjects(aList,false);
1176 //=================================================================================
1177 // function : onObjectSelectionChanged()
1178 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1179 //=================================================================================
1180 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1182 if ( myIsBusy || !isEnabled()) return;
1183 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1187 SALOME_ListIO aList;
1188 mySelectionMgr->selectedObjects( aList );
1190 int aNbSel = aList.Extent();
1191 myElements->clearSelection();
1193 if (myCurrentLineEdit)
1195 myCurrentLineEdit->setText( "" );
1196 QString aString = "";
1198 if (myCurrentLineEdit == myMeshGroupLine)
1200 mySelectSubMesh->setEnabled(false);
1201 mySelectGroup->setEnabled(false);
1202 myGroupLine->setText( "" );
1203 mySubMeshLine->setText( "" );
1205 myGeomGroupBtn->setEnabled(false);
1206 myGeomGroupLine->setEnabled(false);
1207 myGeomGroupLine->setText( "" );
1208 myGeomObjects = new GEOM::ListOfGO();
1209 myGeomObjects->length(0);
1211 if (myGeomGroupBtn->isChecked())
1212 myGeomGroupBtn->setChecked(false);
1214 myName->setText( "" );
1216 myElements->clear();
1219 myGroup = SMESH::SMESH_Group::_nil();
1220 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1221 restoreShowEntityMode();
1222 myMesh = SMESH::SMESH_Mesh::_nil();
1228 Handle(SALOME_InteractiveObject) IO = aList.First();
1231 restoreShowEntityMode();
1232 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1233 setShowEntityMode();
1235 if (myMesh->_is_nil())
1242 if ( myFilterDlg && !myMesh->_is_nil()){
1243 myFilterDlg->SetMesh( myMesh );
1245 myGroup = SMESH::SMESH_Group::_nil();
1247 // NPAL19389: create a group with a selection in another group
1248 // set actor of myMesh, if it is visible, else try
1249 // any visible actor of group or submesh of myMesh
1250 SetAppropriateActor();
1252 aString = aList.First()->getName();
1253 myMeshGroupLine->setText(aString);
1254 myMeshGroupLine->home( false );
1256 mySelectSubMesh->setEnabled(true);
1257 mySelectGroup->setEnabled(true);
1258 myGeomGroupBtn->setEnabled(true);
1259 myGeomGroupLine->setEnabled(true);
1263 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1264 if (aGroup->_is_nil())
1271 myGroup = SMESH::SMESH_Group::_nil();
1272 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1276 mySelectSubMesh->setEnabled(true);
1277 mySelectGroup->setEnabled(true);
1279 myCurrentLineEdit = 0;
1284 if (myGrpTypeId == 0)
1290 myElements->clear();
1291 setSelectionMode(myTypeId);
1299 else if (myCurrentLineEdit == myGeomGroupLine)
1301 myGeomObjects = new GEOM::ListOfGO();
1304 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1306 if (aNbSel == 0 || !aMeshSO)
1308 myGeomObjects->length(0);
1314 myGeomObjects->length(aNbSel);
1316 GEOM::GEOM_Object_var aGeomGroup;
1319 SALOME_ListIteratorOfListIO anIt (aList);
1320 for (; anIt.More(); anIt.Next())
1322 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1324 // Check if the object is a geometry group
1325 if (CORBA::is_nil(aGeomGroup))
1328 // Check if group constructed on the same shape as a mesh or on its child
1329 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1330 GEOM::GEOM_IGroupOperations_var anOp =
1331 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1333 // The main shape of the group
1334 GEOM::GEOM_Object_var aGroupMainShape;
1335 if (aGeomGroup->GetType() == 37)
1336 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1338 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1339 _PTR(SObject) aGroupMainShapeSO =
1340 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1341 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1343 _PTR(SObject) anObj, aRef;
1344 bool isRefOrSubShape = false;
1345 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1346 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1347 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1348 isRefOrSubShape = true;
1350 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1351 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1352 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1353 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1354 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1355 if (aRef->GetID() == aFather->GetID())
1356 isRefOrSubShape = true;
1358 aFather = aFather->GetFather();
1362 if (isRefOrSubShape)
1363 myGeomObjects[i++] = aGeomGroup;
1366 myGeomObjects->length(i);
1378 if (myCurrentLineEdit == mySubMeshLine)
1379 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1380 else if (myCurrentLineEdit == myGroupLine)
1381 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1382 else if (myCurrentLineEdit == myGeomGroupLine)
1383 aString = tr( "%1 Objects" ).arg(aNbSel);
1386 aString = aList.First()->getName();
1390 myCurrentLineEdit->setText(aString);
1391 myCurrentLineEdit->home(false);
1392 // 07.06.2008 skl for IPAL19574:
1393 // change name of group only if it is empty
1394 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1395 myOldName = myName->text();
1396 myName->blockSignals(true);
1397 myName->setText(aString);
1398 myName->blockSignals(false);
1403 else // !myCurrentLineEdit: local selection of nodes or elements
1405 if (aNbSel == 1 && myActorsList.count() > 0 )
1407 // NPAL19389: create a group with a selection in another group
1408 // Switch myActor to the newly selected one, if the last
1409 // is visible and belongs to group or submesh of myMesh
1410 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1411 Handle(SALOME_InteractiveObject) selIO = aList.First();
1412 if (curIO->hasEntry() && selIO->hasEntry()) {
1413 const char* selEntry = selIO->getEntry();
1414 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1415 // different objects: selected and myActor
1416 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1417 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1418 // newly selected actor is visible
1421 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1423 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1424 int len = strlen(meshEntry);
1426 if (strncmp(selEntry, meshEntry, len) == 0) {
1427 // selected object is myMesh or a part of it
1428 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1431 SMESH::SetPickable(myActor);
1440 QString aListStr = "";
1442 if (myTypeId == 0) {
1443 QListIterator<SMESH_Actor*> it( myActorsList );
1444 while ( it.hasNext() ) {
1446 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1450 QListIterator<SMESH_Actor*> it( myActorsList );
1451 while ( it.hasNext() ) {
1453 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1458 QListWidgetItem* anItem;
1459 QList<QListWidgetItem*> listItemsToSel;
1460 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1461 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1462 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1463 foreach(anItem, found)
1464 if (!anItem->isSelected())
1465 listItemsToSel.push_back(anItem);
1467 bool blocked = myElements->signalsBlocked();
1468 myElements->blockSignals(true);
1469 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1470 myElements->blockSignals(blocked);
1471 onListSelectionChanged();
1472 listItemsToSel.clear();
1477 if (myActorsList.count() == 0) {
1478 if (!myGroup->_is_nil()) {
1479 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1481 myActorsList.append( anActor );
1483 else if(!myGroupOnGeom->_is_nil()) {
1484 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1486 myActorsList.append( anActor );
1489 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1491 myActorsList.append( anActor );
1495 // somehow, if we display the mesh, while selecting from another actor,
1496 // the mesh becomes pickable, and there is no way to select any element
1497 if (myActorsList.count() > 0) {
1498 QListIterator<SMESH_Actor*> it( myActorsList );
1499 while ( it.hasNext() ) {
1500 SMESH_Actor* anActor = it.next();
1501 if ( IsActorVisible(anActor) )
1502 anActor->SetPickable(true);
1509 //=================================================================================
1510 // function : onSelectAll()
1511 // purpose : Called when "Select all" is checked
1512 //=================================================================================
1513 void SMESHGUI_GroupDlg::onSelectAll()
1515 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1517 myElementsLab->setEnabled( !noElemsModif );
1518 myElements->setEnabled ( !noElemsModif );
1519 myFilterBtn->setEnabled ( !mySelectAll->isChecked() );
1520 myAddBtn->setEnabled ( !noElemsModif );
1521 myRemoveBtn->setEnabled ( !noElemsModif );
1522 mySortBtn->setEnabled ( !noElemsModif );
1523 mySelectBox->setEnabled ( !noElemsModif );
1524 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1526 int selMode = mySelectionMode;
1527 mySelectionMode = grpNoSelection;
1528 setSelectionMode( selMode );
1532 //=================================================================================
1533 // function : onSelectSubMesh()
1534 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1535 //=================================================================================
1536 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1539 if (mySelectGroup->isChecked()) {
1540 mySelectGroup->setChecked(false);
1542 //VSR: else if (mySelectGeomGroup->isChecked()) {
1543 //VSR: mySelectGeomGroup->setChecked(false);
1545 myCurrentLineEdit = mySubMeshLine;
1546 setSelectionMode(grpSubMeshSelection);
1549 mySubMeshLine->setText( "" );
1550 myCurrentLineEdit = 0;
1552 setSelectionMode(myTypeId);
1554 mySubMeshBtn->setEnabled(on);
1555 mySubMeshLine->setEnabled(on);
1559 //=================================================================================
1560 // function : (onSelectGroup)
1561 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1562 //=================================================================================
1563 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1566 if (mySelectSubMesh->isChecked()) {
1567 mySelectSubMesh->setChecked(false);
1569 myCurrentLineEdit = myGroupLine;
1570 setSelectionMode(grpGroupSelection);
1573 myGroupLine->setText( "" );
1574 myCurrentLineEdit = 0;
1576 setSelectionMode(myTypeId);
1578 myGroupBtn->setEnabled(on);
1579 myGroupLine->setEnabled(on);
1583 //=================================================================================
1584 // function : (onSelectGeomGroup)
1585 // purpose : Called when group type changed. on == "on group" or "on filter"
1586 //=================================================================================
1587 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1590 if (mySelectSubMesh->isChecked()) {
1591 mySelectSubMesh->setChecked(false);
1593 else if (mySelectGroup->isChecked()) {
1594 mySelectGroup->setChecked(false);
1596 if ( myGrpTypeId == 1 ) { // on group
1597 myCurrentLineEdit = myGeomGroupLine;
1601 myCurrentLineEdit = 0;
1603 setSelectionMode(grpAllSelection);
1606 myGeomGroupBtn->setChecked(false);
1607 myGeomObjects->length(0);
1608 myGeomGroupLine->setText( "" );
1609 myCurrentLineEdit = 0;
1611 setSelectionMode( myTypeId );
1616 //=================================================================================
1617 // function : setCurrentSelection()
1619 //=================================================================================
1620 void SMESHGUI_GroupDlg::setCurrentSelection()
1622 QPushButton* send = (QPushButton*)sender();
1623 myCurrentLineEdit = 0;
1624 if (send == myMeshGroupBtn) {
1625 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1626 mySelectionMgr->clearSelected();
1628 setSelectionMode(grpMeshSelection);
1630 setSelectionMode(grpGroupSelection);
1631 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1632 myCurrentLineEdit = myMeshGroupLine;
1633 onObjectSelectionChanged();
1635 else if (send == mySubMeshBtn) {
1636 myCurrentLineEdit = mySubMeshLine;
1637 onObjectSelectionChanged();
1639 else if (send == myGroupBtn) {
1640 myCurrentLineEdit = myGroupLine;
1641 onObjectSelectionChanged();
1646 //=================================================================================
1647 // function : setFilters()
1648 // purpose : SLOT. Called when "Filter" button pressed.
1649 //=================================================================================
1650 void SMESHGUI_GroupDlg::setFilters()
1652 if(myMesh->_is_nil()) {
1653 SUIT_MessageBox::critical(this,
1655 tr("NO_MESH_SELECTED"));
1659 SMESH::ElementType aType = SMESH::ALL;
1662 case 0 : aType = SMESH::NODE; break;
1663 case 1 : aType = SMESH::EDGE; break;
1664 case 2 : aType = SMESH::FACE; break;
1665 case 3 : aType = SMESH::VOLUME; break;
1669 if ( myFilterDlg == 0 )
1671 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1672 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1675 myFilterDlg->Init( aType );
1677 if ( !myGroupOnFilter->_is_nil() )
1679 myFilterDlg->SetFilter( myFilter, aType );
1680 myFilterDlg->Init( aType );
1683 myFilterDlg->SetSelection();
1684 myFilterDlg->SetMesh( myMesh );
1685 myFilterDlg->SetSourceWg( myElements, false );
1687 myFilterDlg->show();
1690 //=================================================================================
1691 // function : onFilterAccepted()
1692 // purpose : SLOT. Called when Filter dlg closed with OK button.
1693 // Uncheck "Select submesh" and "Select group" checkboxes
1694 //=================================================================================
1695 void SMESHGUI_GroupDlg::onFilterAccepted()
1697 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1699 mySelectionMode = myTypeId;
1700 mySelectSubMesh->setChecked( false );
1701 mySelectGroup->setChecked( false );
1703 // get a filter from myFilterDlg
1704 myFilter = myFilterDlg->GetFilter();
1705 if ( !myFilter->_is_nil() ) {
1706 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1707 if ( perdicate->_is_nil() )
1708 myFilter = SMESH::Filter::_nil();
1710 // set mesh to myFilter
1711 if ( !myFilter->_is_nil() ) {
1712 SMESH::SMESH_Mesh_var mesh = myMesh;
1713 if ( mesh->_is_nil() ) {
1714 if ( !myGroup->_is_nil() )
1715 mesh = myGroup->GetMesh();
1716 else if ( !myGroupOnGeom->_is_nil() )
1717 mesh = myGroupOnGeom->GetMesh();
1718 else if ( !myGroupOnFilter->_is_nil() )
1719 mesh = myGroupOnFilter->GetMesh();
1721 myFilter->SetMesh( mesh );
1727 //=================================================================================
1728 // function : onAdd()
1730 //=================================================================================
1731 void SMESHGUI_GroupDlg::onAdd()
1733 SALOME_ListIO aList;
1734 mySelectionMgr->selectedObjects( aList );
1736 int aNbSel = aList.Extent();
1738 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1741 int sizeBefore = myElements->count();
1743 SMESH::ElementType aType = SMESH::ALL;
1746 aType = SMESH::NODE;
1747 mySelector->SetSelectionMode(NodeSelection);
1750 aType = SMESH::EDGE;
1751 mySelector->SetSelectionMode(EdgeSelection);
1754 aType = SMESH::FACE;
1755 mySelector->SetSelectionMode(FaceSelection);
1758 aType = SMESH::VOLUME;
1759 mySelector->SetSelectionMode(VolumeSelection);
1762 mySelector->SetSelectionMode(ActorSelection);
1765 QListWidgetItem* anItem = 0;
1766 QList<QListWidgetItem*> listItemsToSel;
1768 if (myCurrentLineEdit == 0) {
1769 //if (aNbSel != 1) { myIsBusy = false; return; }
1770 QString aListStr = "";
1772 if (myTypeId == 0) {
1773 QListIterator<SMESH_Actor*> it( myActorsList );
1774 while ( it.hasNext() ) {
1776 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1781 QListIterator<SMESH_Actor*> it( myActorsList );
1782 while ( it.hasNext() ) {
1784 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1789 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1790 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1791 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1792 if (found.count() == 0) {
1793 anItem = new QListWidgetItem(*it);
1794 myElements->addItem(anItem);
1795 if (!anItem->isSelected())
1796 listItemsToSel.push_back(anItem);
1799 foreach(anItem, found)
1800 if (!anItem->isSelected())
1801 listItemsToSel.push_back(anItem);
1804 bool blocked = myElements->signalsBlocked();
1805 myElements->blockSignals(true);
1806 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1807 myElements->blockSignals(blocked);
1808 onListSelectionChanged();
1809 listItemsToSel.clear();
1811 } else if (myCurrentLineEdit == mySubMeshLine) {
1812 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1814 SALOME_ListIO aList;
1815 mySelectionMgr->selectedObjects( aList );
1817 SALOME_ListIteratorOfListIO anIt (aList);
1818 for ( ; anIt.More(); anIt.Next()) {
1819 SMESH::SMESH_subMesh_var aSubMesh =
1820 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1821 if (!aSubMesh->_is_nil()) {
1822 // check if mesh is the same
1823 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1825 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1826 int k = anElements->length();
1827 for (int i = 0; i < k; i++) {
1828 QString aText = QString::number(anElements[i]);
1829 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1830 if (found.count() == 0) {
1831 anItem = new QListWidgetItem(aText);
1832 myElements->addItem(anItem);
1833 if (!anItem->isSelected())
1834 listItemsToSel.push_back(anItem);
1837 foreach(anItem, found)
1838 if (!anItem->isSelected())
1839 listItemsToSel.push_back(anItem);
1842 bool blocked = myElements->signalsBlocked();
1843 myElements->blockSignals(true);
1844 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1845 myElements->blockSignals(blocked);
1846 onListSelectionChanged();
1847 listItemsToSel.clear();
1849 catch (const SALOME::SALOME_Exception& ex) {
1850 SalomeApp_Tools::QtCatchCorbaException(ex);
1855 mySelectSubMesh->setChecked(false);
1857 onListSelectionChanged();
1859 } else if (myCurrentLineEdit == myGroupLine) {
1860 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1861 SALOME_ListIO aList;
1862 mySelectionMgr->selectedObjects( aList );
1864 SALOME_ListIteratorOfListIO anIt (aList);
1865 for ( ; anIt.More(); anIt.Next()) {
1866 SMESH::SMESH_GroupBase_var aGroup =
1867 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1868 if (!aGroup->_is_nil()) {
1869 // check if mesh is the same
1870 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1871 SMESH::long_array_var anElements = aGroup->GetListOfID();
1872 int k = anElements->length();
1873 for (int i = 0; i < k; i++) {
1874 QString aText = QString::number(anElements[i]);
1875 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1876 if (found.count() == 0) {
1877 anItem = new QListWidgetItem(aText);
1878 myElements->addItem(anItem);
1879 if (!anItem->isSelected())
1880 listItemsToSel.push_back(anItem);
1883 foreach(anItem, found)
1884 if (!anItem->isSelected())
1885 listItemsToSel.push_back(anItem);
1888 bool blocked = myElements->signalsBlocked();
1889 myElements->blockSignals(true);
1890 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1891 myElements->blockSignals(blocked);
1892 onListSelectionChanged();
1893 listItemsToSel.clear();
1897 mySelectGroup->setChecked(false);
1899 onListSelectionChanged();
1901 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1902 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1903 GEOM::GEOM_IGroupOperations_var aGroupOp =
1904 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1906 SMESH::ElementType aGroupType = SMESH::ALL;
1907 switch(aGroupOp->GetType(myGeomObjects[0])) {
1908 case 7: aGroupType = SMESH::NODE; break;
1909 case 6: aGroupType = SMESH::EDGE; break;
1910 case 4: aGroupType = SMESH::FACE; break;
1911 case 2: aGroupType = SMESH::VOLUME; break;
1912 default: myIsBusy = false; return;
1915 if (aGroupType == aType) {
1916 _PTR(SObject) aGroupSO =
1917 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1918 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1920 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1921 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1922 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
1923 aBelongToGeom->SetGeom(myGeomObjects[0]);
1924 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1925 aBelongToGeom->SetElementType(aType);
1926 aFilter->SetPredicate(aBelongToGeom);
1928 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1930 int k = anElements->length();
1931 for (int i = 0; i < k; i++) {
1932 QString aText = QString::number(anElements[i]);
1933 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1934 if (found.count() == 0) {
1935 anItem = new QListWidgetItem(aText);
1936 myElements->addItem(anItem);
1937 if (!anItem->isSelected())
1938 listItemsToSel.push_back(anItem);
1941 foreach(anItem, found)
1942 if (!anItem->isSelected())
1943 listItemsToSel.push_back(anItem);
1946 bool blocked = myElements->signalsBlocked();
1947 myElements->blockSignals(true);
1948 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1949 myElements->blockSignals(blocked);
1950 onListSelectionChanged();
1951 listItemsToSel.clear();
1954 //VSR: mySelectGeomGroup->setChecked(false);
1956 onListSelectionChanged();
1959 if ( sizeBefore < myElements->count() )
1960 ++myNbChangesOfContents;
1961 // mySelectionMgr->clearSelected();
1965 //=================================================================================
1966 // function : onRemove()
1968 //=================================================================================
1969 void SMESHGUI_GroupDlg::onRemove()
1972 int sizeBefore = myElements->count();
1974 if (myCurrentLineEdit == 0) {
1975 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1976 QListWidgetItem* item;
1977 foreach(item, selItems) delete item;
1979 SALOME_ListIO aList;
1980 mySelectionMgr->selectedObjects( aList );
1982 int aNbSel = aList.Extent();
1984 if (aNbSel == 0) { myIsBusy = false; return; }
1986 SMESH::ElementType aType = SMESH::ALL;
1988 case 0: aType = SMESH::NODE; break;
1989 case 1: aType = SMESH::EDGE; break;
1990 case 2: aType = SMESH::FACE; break;
1991 case 3: aType = SMESH::VOLUME; break;
1994 if (myCurrentLineEdit == mySubMeshLine) {
1995 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1996 SALOME_ListIO aList;
1997 mySelectionMgr->selectedObjects( aList );
1999 SALOME_ListIteratorOfListIO anIt (aList);
2000 for ( ; anIt.More(); anIt.Next()) {
2001 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2002 if (!aSubMesh->_is_nil()) {
2003 // check if mesh is the same
2004 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2005 if (aType == SMESH::NODE) {
2007 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2008 int k = anElements->length();
2009 for (int i = 0; i < k; i++) {
2010 QList<QListWidgetItem*> found =
2011 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2012 QListWidgetItem* anItem;
2013 foreach(anItem, found) delete anItem;
2016 catch (const SALOME::SALOME_Exception& ex) {
2017 SalomeApp_Tools::QtCatchCorbaException(ex);
2022 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2023 int k = anElements->length();
2024 for (int i = 0; i < k; i++) {
2025 QList<QListWidgetItem*> found =
2026 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2027 QListWidgetItem* anItem;
2028 foreach(anItem, found) delete anItem;
2031 catch (const SALOME::SALOME_Exception& ex) {
2032 SalomeApp_Tools::QtCatchCorbaException(ex);
2039 else if (myCurrentLineEdit == myGroupLine) {
2040 Standard_Boolean aRes;
2041 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2042 SALOME_ListIO aList;
2043 mySelectionMgr->selectedObjects( aList );
2045 SALOME_ListIteratorOfListIO anIt (aList);
2046 for ( ; anIt.More(); anIt.Next()) {
2047 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2048 if (aRes && !aGroup->_is_nil()) {
2049 // check if mesh is the same
2050 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2051 SMESH::long_array_var anElements = aGroup->GetListOfID();
2052 int k = anElements->length();
2053 for (int i = 0; i < k; i++) {
2054 QList<QListWidgetItem*> found =
2055 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2056 QListWidgetItem* anItem;
2057 foreach(anItem, found) delete anItem;
2065 if ( sizeBefore > myElements->count() )
2066 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2070 //=================================================================================
2071 // function : onSort()
2073 //=================================================================================
2074 void SMESHGUI_GroupDlg::onSort()
2076 // PAL5412: sorts items in ascending by "string" value
2077 // myElements->sort(true);
2078 // myElements->update();
2079 int i, k = myElements->count();
2082 QList<int> aSelected;
2083 std::vector<int> anArray(k);
2084 // QMemArray<int> anArray(k);
2086 for (i = 0; i < k; i++) {
2087 int id = myElements->item(i)->text().toInt();
2089 if (myElements->item(i)->isSelected())
2090 aSelected.append(id);
2092 // sort & update list
2093 std::sort(anArray.begin(), anArray.end());
2095 myElements->clear();
2096 QListWidgetItem* anItem;
2097 QList<QListWidgetItem*> listItemsToSel;
2098 for (i = 0; i < k; i++) {
2099 anItem = new QListWidgetItem(QString::number(anArray[i]));
2100 myElements->addItem(anItem);
2101 if (aSelected.contains(anArray[i]))
2102 listItemsToSel.push_back(anItem);
2104 bool blocked = myElements->signalsBlocked();
2105 myElements->blockSignals(true);
2106 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2107 myElements->blockSignals(blocked);
2108 listItemsToSel.clear();
2113 //=================================================================================
2114 // function : closeEvent()
2116 //=================================================================================
2117 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
2122 //=================================================================================
2123 // function : onVisibilityChanged()
2125 //=================================================================================
2126 void SMESHGUI_GroupDlg::onVisibilityChanged()
2128 SetAppropriateActor();
2131 //=================================================================================
2132 // function : SMESHGUI_GroupDlg::onClose
2133 // purpose : SLOT called when "Close" button pressed. Close dialog
2134 //=================================================================================
2135 void SMESHGUI_GroupDlg::onClose()
2137 if (SMESH::GetCurrentVtkView()) {
2138 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2139 SMESH::SetPointRepresentation(false);
2140 SMESH::SetPickable();
2141 restoreShowEntityMode();
2144 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2145 SUIT_DataOwnerPtrList aList;
2146 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2147 mySelectionMgr->setSelected( aList );
2150 mySelectionMgr->clearSelected();
2151 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2152 aViewWindow->SetSelectionMode(ActorSelection);
2153 mySelectionMgr->clearFilters();
2154 mySMESHGUI->ResetState();
2159 //=================================================================================
2160 // function : onHelp()
2162 //=================================================================================
2163 void SMESHGUI_GroupDlg::onHelp()
2165 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2167 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2171 platform = "winapplication";
2173 platform = "application";
2175 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2176 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2177 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2179 arg(myHelpFileName));
2183 //=================================================================================
2184 // function : SMESHGUI_GroupDlg::onDeactivate
2185 // purpose : SLOT called when dialog must be deativated
2186 //=================================================================================
2187 void SMESHGUI_GroupDlg::onDeactivate()
2189 mySMESHGUI->ResetState();
2193 //=================================================================================
2194 // function : SMESHGUI_GroupDlg::enterEvent
2195 // purpose : Event filter
2196 //=================================================================================
2197 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2200 mySMESHGUI->EmitSignalDeactivateDialog();
2202 mySelectionMode = grpNoSelection;
2203 setSelectionMode(myTypeId);
2204 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2205 mySMESHGUI->SetActiveDialogBox(this);
2206 mySMESHGUI->SetState(800);
2210 //=================================================================================
2211 // function : hideEvent
2212 // purpose : caused by ESC key
2213 //=================================================================================
2214 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
2216 if (!isMinimized() && !myIsBusy)
2220 //=================================================================================
2221 // function : keyPressEvent()
2223 //=================================================================================
2224 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2226 QDialog::keyPressEvent( e );
2227 if ( e->isAccepted() )
2230 if ( e->key() == Qt::Key_F1 )
2237 //================================================================================
2239 * \brief Enable showing of the popup when Geometry selection btn is clicked
2240 * \param enable - true to enable
2242 //================================================================================
2244 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2246 void SMESHGUI_GroupDlg::updateGeomPopup()
2248 bool enable = false;
2250 if ( !myMesh->_is_nil() )
2251 enable = myMesh->NbEdges() > 0;
2253 if ( myGeomGroupBtn )
2255 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2257 if ( !myGeomPopup ) {
2258 myGeomPopup = new QMenu(this);
2259 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2260 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2261 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2263 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2269 //=================================================================================
2270 // function : onGeomSelectionButton()
2272 //=================================================================================
2273 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2275 if ( myGeomPopup && isBtnOn )
2277 myCurrentLineEdit = myGeomGroupLine;
2278 QAction* a = myGeomPopup->exec( QCursor::pos() );
2279 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2280 setSelectionMode(grpGeomSelection);
2284 myCurrentLineEdit = 0;
2285 setSelectionMode(grpAllSelection);
2289 //=================================================================================
2290 // function : onGeomPopup()
2292 //=================================================================================
2293 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2295 int index = myActions[a];
2296 if ( index == GEOM_BY_MESH_INDEX )
2298 mySelectionMode = grpNoSelection;
2299 if ( !myShapeByMeshOp ) {
2300 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2301 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2302 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2303 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2304 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2306 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2307 if ( !myMesh->_is_nil() ) {
2309 hide(); // stop processing selection
2311 myShapeByMeshOp->setModule( mySMESHGUI );
2312 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2313 myShapeByMeshOp->SetMesh( myMesh );
2314 myShapeByMeshOp->start();
2319 //================================================================================
2321 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2323 //================================================================================
2325 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2327 if ( myShapeByMeshOp == op ) {
2328 mySMESHGUI->getApp()->updateObjectBrowser();
2330 // Select a found geometry object
2331 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2332 if ( !aGeomVar->_is_nil() )
2334 QString ID = aGeomVar->GetStudyEntry();
2335 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2336 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2337 SALOME_ListIO anIOList;
2338 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2339 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2340 anIOList.Append( anIO );
2341 mySelectionMgr->setSelectedObjects( anIOList, false );
2342 onObjectSelectionChanged();
2348 //================================================================================
2350 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2352 //================================================================================
2354 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2356 if ( myShapeByMeshOp == op )
2359 setSelectionMode(grpGeomSelection);
2363 //=================================================================================
2364 // function : setGroupColor()
2366 //=================================================================================
2367 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2369 QColor aQColor( (int)( theColor.R * 255.0 ),
2370 (int)( theColor.G * 255.0 ),
2371 (int)( theColor.B * 255.0 ) );
2372 setGroupQColor( aQColor );
2375 //=================================================================================
2376 // function : getGroupColor()
2378 //=================================================================================
2379 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2381 QColor aQColor = getGroupQColor();
2383 SALOMEDS::Color aColor;
2384 aColor.R = (float)aQColor.red() / 255.0;
2385 aColor.G = (float)aQColor.green() / 255.0;
2386 aColor.B = (float)aQColor.blue() / 255.0;
2391 //=================================================================================
2392 // function : setGroupQColor()
2394 //=================================================================================
2395 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2397 if( theColor.isValid() )
2398 myColorBtn->setColor( theColor );
2401 //=================================================================================
2402 // function : getGroupQColor()
2404 //=================================================================================
2405 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2407 return myColorBtn->color();
2410 //=================================================================================
2411 // function : setDefaultGroupColor()
2413 //=================================================================================
2414 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2416 if( myMesh->_is_nil() )
2419 bool isAutoColor = myMesh->GetAutoColor();
2424 int r = 0, g = 0, b = 0;
2425 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2426 aQColor.setRgb( r, g, b );
2430 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2432 QList<SALOMEDS::Color> aReservedColors;
2433 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2435 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2436 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2437 aReservedColors.append( aReservedColor );
2440 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2441 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2442 (int)( aColor.G * 255.0 ),
2443 (int)( aColor.B * 255.0 ) );
2447 setGroupQColor( aQColor );
2450 //=================================================================================
2451 // function : SetAppropriateActor()
2452 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2453 // NPAL19389: create a group with a selection in another group.
2454 // if mesh actor is not visible - find any first visible group or submesh
2455 //=================================================================================
2456 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2458 bool isActor = false;
2459 myActorsList.clear();
2461 if (myMesh->_is_nil()) return false;
2463 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2465 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2467 if (!myGroupOnGeom->_is_nil()) {
2468 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2469 if (anActor && anActor->hasIO())
2472 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2475 myActorsList.append(anActor);
2481 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2482 if (anActor && anActor->hasIO()) {
2484 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2487 myActorsList.append(anActor);
2491 if (!isActor && !myGroup->_is_nil()) {
2492 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2493 if (anActor && anActor->hasIO())
2494 myActorsList.append(anActor);
2497 // try any visible actor of group or submesh of current mesh
2500 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2502 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2503 int len = strlen(meshEntry);
2505 // iterate on all actors in current view window, search for
2506 // any visible actor, that belongs to group or submesh of current mesh
2507 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2508 vtkActorCollection *aCollection = aCopy.GetActors();
2509 int nbItems = aCollection->GetNumberOfItems();
2510 for (int i=0; i<nbItems && !isActor; i++)
2512 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2513 if (anActor && anActor->hasIO()) {
2514 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2515 if (aViewWindow->isVisible(anIO)) {
2516 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2517 myActorsList.append(anActor);
2525 if (myActorsList.count() > 0) {
2526 QListIterator<SMESH_Actor*> it( myActorsList );
2527 while ( it.hasNext() ) {
2528 SMESH_Actor* anActor = it.next();
2529 if ( IsActorVisible(anActor) )
2530 anActor->SetPickable(true);
2534 return ( isActor || (myActorsList.count() > 0) );
2537 //=======================================================================
2538 //function : setShowEntityMode
2539 //purpose : make shown only entity corresponding to my type
2540 //=======================================================================
2541 void SMESHGUI_GroupDlg::setShowEntityMode()
2543 if ( !myMesh->_is_nil() ) {
2544 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2545 if (!myStoredShownEntity)
2546 myStoredShownEntity = actor->GetEntityMode();
2547 switch ( myTypeId ) {
2548 case 0: restoreShowEntityMode(); break;
2549 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2550 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2551 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2557 //=======================================================================
2558 //function : restoreShowEntityMode
2559 //purpose : restore ShowEntity mode of myActor
2560 //=======================================================================
2561 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2563 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2564 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2565 actor->SetEntityMode(myStoredShownEntity);
2568 myStoredShownEntity = 0;
2571 //=======================================================================
2572 //function : IsActorVisible
2573 //purpose : return visibility of the actor
2574 //=======================================================================
2575 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2577 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2578 if (theActor && aViewWindow)
2579 return aViewWindow->isVisible(theActor->getIO());
2583 //================================================================
2584 //function : setIsApplyAndClose
2585 //purpose : Set value of the flag indicating that the dialog is
2586 // accepted by Apply & Close button
2587 //================================================================
2588 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2590 myIsApplyAndClose = theFlag;
2593 //================================================================
2594 //function : isApplyAndClose
2595 //purpose : Get value of the flag indicating that the dialog is
2596 // accepted by Apply & Close button
2597 //================================================================
2598 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2600 return myIsApplyAndClose;