1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_GroupDlg.cxx
25 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
28 #include "SMESHGUI_GroupDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_GroupUtils.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
36 #include "SMESHGUI_FilterDlg.h"
37 #include "SMESHGUI_ShapeByMeshDlg.h"
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_Actor.h>
41 #include <SMESH_ActorUtils.h>
42 #include <SMESH_LogicalFilter.hxx>
44 // SALOME GEOM includes
46 #include <GEOM_SelectionFilter.h>
48 // SALOME GUI includes
49 #include <QtxColorButton.h>
51 #include <SUIT_Desktop.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SUIT_Session.h>
54 #include <SUIT_MessageBox.h>
56 #include <SalomeApp_Tools.h>
57 #include <SalomeApp_Application.h>
58 #include <SalomeApp_Study.h>
59 #include <LightApp_SelectionMgr.h>
61 #include <SALOME_ListIO.hxx>
62 #include <SALOME_ListIteratorOfListIO.hxx>
64 #include <SVTK_ViewWindow.h>
66 #include <VTKViewer_Algorithm.h>
68 // SALOME KERNEL includes
69 #include <SALOMEDSClient_Study.hxx>
72 #include <vtkRenderer.h>
73 #include <vtkActorCollection.h>
76 #include <TColStd_MapOfInteger.hxx>
79 #include <QButtonGroup>
83 #include <QPushButton>
84 #include <QToolButton>
85 #include <QRadioButton>
87 #include <QGridLayout>
88 #include <QHBoxLayout>
89 #include <QVBoxLayout>
90 #include <QListWidget>
91 #include <QStackedWidget>
103 enum grpSelectionMode {
105 grpNodeSelection = 0,
106 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();
781 SMESH::RemoveFilters();
783 if (myActorsList.count() > 0)
784 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
785 it.next()->SetPointRepresentation(false);
787 SMESH::SetPointRepresentation(false);
790 case grpNodeSelection:
791 if ( myGrpTypeId == 0 ) // standalone
793 if (myActorsList.count() > 0)
794 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
795 it.next()->SetPointRepresentation(true);
797 SMESH::SetPointRepresentation(true);
799 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
801 case grpEdgeSelection:
802 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
804 case grpFaceSelection:
805 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
807 case grpVolumeSelection:
808 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
810 case grpSubMeshSelection: {
812 SMESH_TypeFilter* f = 0;
814 case 0: f = new SMESH_TypeFilter(SUBMESH); break;
815 case 1: f = new SMESH_TypeFilter(SUBMESH_EDGE); break;
816 case 2: f = new SMESH_TypeFilter(SUBMESH_FACE); break;
817 case 3: f = new SMESH_TypeFilter(SUBMESH_SOLID); break;
818 default:f = new SMESH_TypeFilter(SUBMESH);
820 QList<SUIT_SelectionFilter*> filtList;
821 filtList.append( f );
822 filtList.append( new SMESH_TypeFilter(SUBMESH_COMPOUND));
823 mySubMeshFilter->setFilters( filtList );
825 mySelectionMgr->installFilter( mySubMeshFilter );
827 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
830 case grpGroupSelection: {
832 SMESH_TypeFilter* f = 0;
834 case 0: f = new SMESH_TypeFilter(GROUP_NODE); break;
835 case 1: f = new SMESH_TypeFilter(GROUP_EDGE); break;
836 case 2: f = new SMESH_TypeFilter(GROUP_FACE); break;
837 case 3: f = new SMESH_TypeFilter(GROUP_VOLUME); break;
838 default:f = new SMESH_TypeFilter(GROUP);
840 QList<SUIT_SelectionFilter*> filtList;
841 filtList.append( f );
842 myGroupFilter->setFilters( filtList );
844 mySelectionMgr->installFilter(myGroupFilter);
845 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
848 case grpMeshSelection:
849 mySelectionMgr->installFilter(myMeshFilter);
850 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
852 case grpGeomSelection:
853 mySelectionMgr->installFilter(myGeomFilter);
854 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
857 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
860 if ( aViewWindow ) aViewWindow->Repaint();
861 mySelectionMode = theMode;
865 //=================================================================================
866 // function : onApply()
868 //=================================================================================
869 bool SMESHGUI_GroupDlg::onApply()
871 if (mySMESHGUI->isActiveStudyLocked())
874 if (myName->text().trimmed().isEmpty())
877 SMESH::ElementType aType = SMESH::ALL;
879 case 0: aType = SMESH::NODE; break;
880 case 1: aType = SMESH::EDGE; break;
881 case 2: aType = SMESH::FACE; break;
882 case 3: aType = SMESH::VOLUME; break;
886 QStringList anEntryList;
888 SMESH::SMESH_GroupBase_var resultGroup;
891 if (myGrpTypeId == 0) // standalone
893 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
896 mySelectionMgr->clearSelected();
898 if (myGroup->_is_nil()) { // creation or conversion
899 // check if group on geometry is not null
900 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
901 if (myMesh->_is_nil())
903 if ( myGroupOnGeom->_is_nil() )
904 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
906 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
908 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
909 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
913 if (myGroup->_is_nil()) { // creation
914 if (myMesh->_is_nil())
917 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
919 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
922 if ( mySelectAll->isChecked() ) {
924 myGroup->AddFrom(myMesh.in());
929 if ( !myFilter->_is_nil() &&
930 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
932 myGroup->AddFrom( myFilter );
936 SMESH::long_array_var anIdList = new SMESH::long_array;
937 int i, k = myElements->count();
939 for (i = 0; i < k; i++) {
940 anIdList[i] = myElements->item(i)->text().toInt();
942 myGroup->Add(anIdList.inout());
949 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
952 if ( mySelectAll->isChecked() ) {
955 myGroup->AddFrom(myMesh.in());
960 int i, total = myElements->count();
961 for (i = 0; i < total; i++) {
962 int anId = myElements->item(i)->text().toInt();
963 int idx = myIdList.indexOf(anId);
965 aAddList.append(anId);
967 myIdList.removeAt(idx);
969 if (!aAddList.empty()) {
970 SMESH::long_array_var anIdList = new SMESH::long_array;
971 int added = aAddList.count();
972 anIdList->length(added);
973 for (i = 0; i < added; i++)
974 anIdList[i] = aAddList[i];
975 myGroup->Add(anIdList.inout());
977 if (!myIdList.empty()) {
978 SMESH::long_array_var anIdList = new SMESH::long_array;
979 int removed = myIdList.count();
980 anIdList->length(removed);
981 for (i = 0; i < removed; i++)
982 anIdList[i] = myIdList[i];
983 myGroup->Remove(anIdList.inout());
985 /* init for next operation */
987 for (i = 0; i < total; i++) {
988 myIdList.append(myElements->item(i)->text().toInt());
995 else if (myGrpTypeId == 1) // on geom object
997 if (CORBA::is_nil(myGroupOnGeom)) { // creation
998 if (myMesh->_is_nil() || !myGeomObjects->length())
1001 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1002 GEOM::GEOM_IGroupOperations_var aGroupOp =
1003 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1005 if (myGeomObjects->length() == 1) {
1006 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1007 myName->text().toLatin1().data(),
1011 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1012 if ( aSMESHGen->_is_nil() )
1015 // create a geometry group
1016 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1017 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1019 if (geomGen->_is_nil() || !aStudy)
1022 GEOM::GEOM_IGroupOperations_var op =
1023 geomGen->GetIGroupOperations(aStudy->StudyId());
1027 // check and add all selected GEOM objects: they must be
1028 // a sub-shapes of the main GEOM and must be of one type
1029 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1030 for ( int i =0; i < myGeomObjects->length(); i++) {
1031 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1033 aGroupType = aSubShapeType;
1034 else if (aSubShapeType != aGroupType) {
1035 aGroupType = TopAbs_SHAPE;
1040 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1041 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1042 op->UnionList(aGroupVar, myGeomObjects);
1045 // publish the GEOM group in study
1046 QString aNewGeomGroupName ( "Auto_group_for_" );
1047 aNewGeomGroupName += myName->text();
1048 SALOMEDS::SObject_var aNewGroupSO =
1049 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
1050 aNewGeomGroupName.toLatin1().data(), aMeshShape);
1053 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1054 myName->text().toLatin1().data(),
1057 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1063 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1068 if (myGrpTypeId == 2) // group on filter
1070 if ( myFilter->_is_nil() ) return false;
1072 if (CORBA::is_nil(myGroupOnFilter)) { // creation
1073 if (myMesh->_is_nil())
1076 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1077 myName->text().toLatin1().data(),
1080 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1085 myGroupOnFilter->SetFilter( myFilter );
1087 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1095 SALOMEDS::Color aColor = getGroupColor();
1096 resultGroup->SetColor(aColor);
1098 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1100 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1104 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1106 /* init for the next operation */
1107 myName->setText( "" );
1108 myElements->clear();
1109 myGroup = SMESH::SMESH_Group::_nil();
1110 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1111 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1112 myFilter = SMESH::Filter::_nil();
1116 resultGroup->SetName(myName->text().toLatin1().data());
1119 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
1120 anActor->setName(myName->text().toLatin1().data());
1121 switch ( myTypeId ) {
1122 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1123 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1129 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1130 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1135 SMESHGUI::Modified();
1136 mySMESHGUI->updateObjBrowser(true);
1137 SMESH::UpdateView(); // asv: fix of BUG PAL5515
1138 mySelectionMgr->clearSelected();
1140 if( LightApp_Application* anApp =
1141 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1142 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1147 //=================================================================================
1148 // function : onOK()
1150 //=================================================================================
1151 void SMESHGUI_GroupDlg::onOK()
1153 setIsApplyAndClose( true );
1156 setIsApplyAndClose( false );
1159 //=================================================================================
1160 // function : onListSelectionChanged()
1161 // purpose : Called when selection in element list is changed
1162 //=================================================================================
1163 void SMESHGUI_GroupDlg::onListSelectionChanged()
1165 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1166 if( myIsBusy || myActorsList.count() == 0 ) return;
1169 if (myCurrentLineEdit == 0) {
1170 mySelectionMgr->clearSelected();
1171 TColStd_MapOfInteger aIndexes;
1172 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1173 QListWidgetItem* anItem;
1174 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1175 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1176 SALOME_ListIO aList;
1177 aList.Append(myActorsList.first()->getIO());
1178 mySelectionMgr->setSelectedObjects(aList,false);
1183 //=================================================================================
1184 // function : onObjectSelectionChanged()
1185 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1186 //=================================================================================
1187 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1189 if ( myIsBusy || !isEnabled()) return;
1190 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1194 SALOME_ListIO aList;
1195 mySelectionMgr->selectedObjects( aList );
1197 int aNbSel = aList.Extent();
1198 myElements->clearSelection();
1200 if (myCurrentLineEdit)
1202 myCurrentLineEdit->setText( "" );
1203 QString aString = "";
1205 if (myCurrentLineEdit == myMeshGroupLine)
1207 mySelectSubMesh->setEnabled(false);
1208 mySelectGroup->setEnabled(false);
1209 myGroupLine->setText( "" );
1210 mySubMeshLine->setText( "" );
1212 myGeomGroupBtn->setEnabled(false);
1213 myGeomGroupLine->setEnabled(false);
1214 myGeomGroupLine->setText( "" );
1215 myGeomObjects = new GEOM::ListOfGO();
1216 myGeomObjects->length(0);
1218 if (myGeomGroupBtn->isChecked())
1219 myGeomGroupBtn->setChecked(false);
1221 myName->setText( "" );
1223 myElements->clear();
1226 myGroup = SMESH::SMESH_Group::_nil();
1227 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1228 restoreShowEntityMode();
1229 myMesh = SMESH::SMESH_Mesh::_nil();
1235 Handle(SALOME_InteractiveObject) IO = aList.First();
1238 restoreShowEntityMode();
1239 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1240 setShowEntityMode();
1242 if (myMesh->_is_nil())
1249 if ( myFilterDlg && !myMesh->_is_nil()){
1250 myFilterDlg->SetMesh( myMesh );
1252 myGroup = SMESH::SMESH_Group::_nil();
1254 // NPAL19389: create a group with a selection in another group
1255 // set actor of myMesh, if it is visible, else try
1256 // any visible actor of group or submesh of myMesh
1257 SetAppropriateActor();
1259 aString = aList.First()->getName();
1260 myMeshGroupLine->setText(aString);
1261 myMeshGroupLine->home( false );
1263 mySelectSubMesh->setEnabled(true);
1264 mySelectGroup->setEnabled(true);
1265 myGeomGroupBtn->setEnabled(true);
1266 myGeomGroupLine->setEnabled(true);
1270 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1271 if (aGroup->_is_nil())
1278 myGroup = SMESH::SMESH_Group::_nil();
1279 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1283 mySelectSubMesh->setEnabled(true);
1284 mySelectGroup->setEnabled(true);
1286 myCurrentLineEdit = 0;
1291 if (myGrpTypeId == 0)
1297 myElements->clear();
1298 setSelectionMode(myTypeId);
1306 else if (myCurrentLineEdit == myGeomGroupLine)
1308 myGeomObjects = new GEOM::ListOfGO();
1311 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1313 if (aNbSel == 0 || !aMeshSO)
1315 myGeomObjects->length(0);
1321 myGeomObjects->length(aNbSel);
1323 GEOM::GEOM_Object_var aGeomGroup;
1326 SALOME_ListIteratorOfListIO anIt (aList);
1327 for (; anIt.More(); anIt.Next())
1329 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1331 // Check if the object is a geometry group
1332 if (CORBA::is_nil(aGeomGroup))
1335 // Check if group constructed on the same shape as a mesh or on its child
1336 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1337 GEOM::GEOM_IGroupOperations_var anOp =
1338 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1340 // The main shape of the group
1341 GEOM::GEOM_Object_var aGroupMainShape;
1342 if (aGeomGroup->GetType() == 37)
1343 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1345 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1346 _PTR(SObject) aGroupMainShapeSO =
1347 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1348 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1350 _PTR(SObject) anObj, aRef;
1351 bool isRefOrSubShape = false;
1352 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1353 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1354 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1355 isRefOrSubShape = true;
1357 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1358 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1359 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1360 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1361 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1362 if (aRef->GetID() == aFather->GetID())
1363 isRefOrSubShape = true;
1365 aFather = aFather->GetFather();
1369 if (isRefOrSubShape)
1370 myGeomObjects[i++] = aGeomGroup;
1373 myGeomObjects->length(i);
1385 if (myCurrentLineEdit == mySubMeshLine)
1386 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1387 else if (myCurrentLineEdit == myGroupLine)
1388 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1389 else if (myCurrentLineEdit == myGeomGroupLine)
1390 aString = tr( "%1 Objects" ).arg(aNbSel);
1393 aString = aList.First()->getName();
1397 myCurrentLineEdit->setText(aString);
1398 myCurrentLineEdit->home(false);
1399 // 07.06.2008 skl for IPAL19574:
1400 // change name of group only if it is empty
1401 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1402 myOldName = myName->text();
1403 myName->blockSignals(true);
1404 myName->setText(aString);
1405 myName->blockSignals(false);
1410 else // !myCurrentLineEdit: local selection of nodes or elements
1412 if (aNbSel == 1 && myActorsList.count() > 0 )
1414 // NPAL19389: create a group with a selection in another group
1415 // Switch myActor to the newly selected one, if the last
1416 // is visible and belongs to group or submesh of myMesh
1417 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1418 Handle(SALOME_InteractiveObject) selIO = aList.First();
1419 if (curIO->hasEntry() && selIO->hasEntry()) {
1420 const char* selEntry = selIO->getEntry();
1421 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1422 // different objects: selected and myActor
1423 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1424 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1425 // newly selected actor is visible
1428 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1430 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1431 int len = strlen(meshEntry);
1433 if (strncmp(selEntry, meshEntry, len) == 0) {
1434 // selected object is myMesh or a part of it
1435 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1438 SMESH::SetPickable(myActor);
1447 QString aListStr = "";
1449 if (myTypeId == 0) {
1450 QListIterator<SMESH_Actor*> it( myActorsList );
1451 while ( it.hasNext() ) {
1453 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1457 QListIterator<SMESH_Actor*> it( myActorsList );
1458 while ( it.hasNext() ) {
1460 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1465 QListWidgetItem* anItem;
1466 QList<QListWidgetItem*> listItemsToSel;
1467 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1468 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1469 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1470 foreach(anItem, found)
1471 if (!anItem->isSelected())
1472 listItemsToSel.push_back(anItem);
1474 bool blocked = myElements->signalsBlocked();
1475 myElements->blockSignals(true);
1476 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1477 myElements->blockSignals(blocked);
1478 onListSelectionChanged();
1479 listItemsToSel.clear();
1484 if (myActorsList.count() == 0) {
1485 if (!myGroup->_is_nil()) {
1486 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1488 myActorsList.append( anActor );
1490 else if(!myGroupOnGeom->_is_nil()) {
1491 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1493 myActorsList.append( anActor );
1496 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1498 myActorsList.append( anActor );
1502 // somehow, if we display the mesh, while selecting from another actor,
1503 // the mesh becomes pickable, and there is no way to select any element
1504 if (myActorsList.count() > 0) {
1505 QListIterator<SMESH_Actor*> it( myActorsList );
1506 while ( it.hasNext() ) {
1507 SMESH_Actor* anActor = it.next();
1508 if ( IsActorVisible(anActor) )
1509 anActor->SetPickable(true);
1516 //=================================================================================
1517 // function : onSelectAll()
1518 // purpose : Called when "Select all" is checked
1519 //=================================================================================
1520 void SMESHGUI_GroupDlg::onSelectAll()
1522 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1524 myElementsLab->setEnabled( !noElemsModif );
1525 myElements->setEnabled ( !noElemsModif );
1526 myFilterBtn->setEnabled ( !mySelectAll->isChecked() );
1527 myAddBtn->setEnabled ( !noElemsModif );
1528 myRemoveBtn->setEnabled ( !noElemsModif );
1529 mySortBtn->setEnabled ( !noElemsModif );
1530 mySelectBox->setEnabled ( !noElemsModif );
1531 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1533 int selMode = mySelectionMode;
1534 mySelectionMode = grpNoSelection;
1535 setSelectionMode( selMode );
1539 //=================================================================================
1540 // function : onSelectSubMesh()
1541 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1542 //=================================================================================
1543 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1546 if (mySelectGroup->isChecked()) {
1547 mySelectGroup->setChecked(false);
1549 //VSR: else if (mySelectGeomGroup->isChecked()) {
1550 //VSR: mySelectGeomGroup->setChecked(false);
1552 myCurrentLineEdit = mySubMeshLine;
1553 setSelectionMode(grpSubMeshSelection);
1556 mySubMeshLine->setText( "" );
1557 myCurrentLineEdit = 0;
1559 setSelectionMode(myTypeId);
1561 mySubMeshBtn->setEnabled(on);
1562 mySubMeshLine->setEnabled(on);
1566 //=================================================================================
1567 // function : (onSelectGroup)
1568 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1569 //=================================================================================
1570 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1573 if (mySelectSubMesh->isChecked()) {
1574 mySelectSubMesh->setChecked(false);
1576 myCurrentLineEdit = myGroupLine;
1577 setSelectionMode(grpGroupSelection);
1580 myGroupLine->setText( "" );
1581 myCurrentLineEdit = 0;
1583 setSelectionMode(myTypeId);
1585 myGroupBtn->setEnabled(on);
1586 myGroupLine->setEnabled(on);
1590 //=================================================================================
1591 // function : (onSelectGeomGroup)
1592 // purpose : Called when group type changed. on == "on group" or "on filter"
1593 //=================================================================================
1594 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1597 if (mySelectSubMesh->isChecked()) {
1598 mySelectSubMesh->setChecked(false);
1600 else if (mySelectGroup->isChecked()) {
1601 mySelectGroup->setChecked(false);
1603 if ( myGrpTypeId == 1 ) { // on group
1604 myCurrentLineEdit = myGeomGroupLine;
1608 myCurrentLineEdit = 0;
1610 setSelectionMode(grpAllSelection);
1613 myGeomGroupBtn->setChecked(false);
1614 myGeomObjects->length(0);
1615 myGeomGroupLine->setText( "" );
1616 myCurrentLineEdit = 0;
1618 setSelectionMode( myTypeId );
1622 //=================================================================================
1623 // function : setCurrentSelection()
1625 //=================================================================================
1626 void SMESHGUI_GroupDlg::setCurrentSelection()
1628 QPushButton* send = (QPushButton*)sender();
1629 myCurrentLineEdit = 0;
1630 if (send == myMeshGroupBtn) {
1631 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1632 mySelectionMgr->clearSelected();
1634 setSelectionMode(grpMeshSelection);
1636 setSelectionMode(grpGroupSelection);
1637 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1638 myCurrentLineEdit = myMeshGroupLine;
1639 onObjectSelectionChanged();
1641 else if (send == mySubMeshBtn) {
1642 myCurrentLineEdit = mySubMeshLine;
1643 onObjectSelectionChanged();
1645 else if (send == myGroupBtn) {
1646 myCurrentLineEdit = myGroupLine;
1647 onObjectSelectionChanged();
1652 //=================================================================================
1653 // function : setFilters()
1654 // purpose : SLOT. Called when "Filter" button pressed.
1655 //=================================================================================
1656 void SMESHGUI_GroupDlg::setFilters()
1658 if(myMesh->_is_nil()) {
1659 SUIT_MessageBox::critical(this,
1661 tr("NO_MESH_SELECTED"));
1665 SMESH::ElementType aType = SMESH::ALL;
1668 case 0 : aType = SMESH::NODE; break;
1669 case 1 : aType = SMESH::EDGE; break;
1670 case 2 : aType = SMESH::FACE; break;
1671 case 3 : aType = SMESH::VOLUME; break;
1675 if ( myFilterDlg == 0 )
1677 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1678 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1681 myFilterDlg->Init( aType );
1683 if ( !myGroupOnFilter->_is_nil() )
1685 myFilterDlg->SetFilter( myFilter, aType );
1686 myFilterDlg->Init( aType );
1689 myFilterDlg->SetSelection();
1690 myFilterDlg->SetMesh( myMesh );
1691 myFilterDlg->SetSourceWg( myElements, false );
1693 myFilterDlg->show();
1696 //=================================================================================
1697 // function : onFilterAccepted()
1698 // purpose : SLOT. Called when Filter dlg closed with OK button.
1699 // Uncheck "Select submesh" and "Select group" checkboxes
1700 //=================================================================================
1701 void SMESHGUI_GroupDlg::onFilterAccepted()
1703 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1705 mySelectionMode = myTypeId;
1706 mySelectSubMesh->setChecked( false );
1707 mySelectGroup->setChecked( false );
1709 // get a filter from myFilterDlg
1710 myFilter = myFilterDlg->GetFilter();
1711 if ( !myFilter->_is_nil() ) {
1712 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1713 if ( perdicate->_is_nil() )
1714 myFilter = SMESH::Filter::_nil();
1716 // set mesh to myFilter
1717 if ( !myFilter->_is_nil() ) {
1718 SMESH::SMESH_Mesh_var mesh = myMesh;
1719 if ( mesh->_is_nil() ) {
1720 if ( !myGroup->_is_nil() )
1721 mesh = myGroup->GetMesh();
1722 else if ( !myGroupOnGeom->_is_nil() )
1723 mesh = myGroupOnGeom->GetMesh();
1724 else if ( !myGroupOnFilter->_is_nil() )
1725 mesh = myGroupOnFilter->GetMesh();
1727 myFilter->SetMesh( mesh );
1733 //=================================================================================
1734 // function : onAdd()
1736 //=================================================================================
1737 void SMESHGUI_GroupDlg::onAdd()
1739 SALOME_ListIO aList;
1740 mySelectionMgr->selectedObjects( aList );
1742 int aNbSel = aList.Extent();
1744 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1747 int sizeBefore = myElements->count();
1749 SMESH::ElementType aType = SMESH::ALL;
1752 aType = SMESH::NODE;
1753 mySelector->SetSelectionMode(NodeSelection);
1756 aType = SMESH::EDGE;
1757 mySelector->SetSelectionMode(EdgeSelection);
1760 aType = SMESH::FACE;
1761 mySelector->SetSelectionMode(FaceSelection);
1764 aType = SMESH::VOLUME;
1765 mySelector->SetSelectionMode(VolumeSelection);
1768 mySelector->SetSelectionMode(ActorSelection);
1771 QListWidgetItem* anItem = 0;
1772 QList<QListWidgetItem*> listItemsToSel;
1774 if (myCurrentLineEdit == 0) {
1775 //if (aNbSel != 1) { myIsBusy = false; return; }
1776 QString aListStr = "";
1778 if (myTypeId == 0) {
1779 QListIterator<SMESH_Actor*> it( myActorsList );
1780 while ( it.hasNext() ) {
1782 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1787 QListIterator<SMESH_Actor*> it( myActorsList );
1788 while ( it.hasNext() ) {
1790 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1795 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1796 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1797 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1798 if (found.count() == 0) {
1799 anItem = new QListWidgetItem(*it);
1800 myElements->addItem(anItem);
1801 if (!anItem->isSelected())
1802 listItemsToSel.push_back(anItem);
1805 foreach(anItem, found)
1806 if (!anItem->isSelected())
1807 listItemsToSel.push_back(anItem);
1810 bool blocked = myElements->signalsBlocked();
1811 myElements->blockSignals(true);
1812 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1813 myElements->blockSignals(blocked);
1814 onListSelectionChanged();
1815 listItemsToSel.clear();
1817 } else if (myCurrentLineEdit == mySubMeshLine) {
1818 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1820 SALOME_ListIO aList;
1821 mySelectionMgr->selectedObjects( aList );
1823 SALOME_ListIteratorOfListIO anIt (aList);
1824 for ( ; anIt.More(); anIt.Next()) {
1825 SMESH::SMESH_subMesh_var aSubMesh =
1826 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1827 if (!aSubMesh->_is_nil()) {
1828 // check if mesh is the same
1829 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1831 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1832 int k = anElements->length();
1833 for (int i = 0; i < k; i++) {
1834 QString aText = QString::number(anElements[i]);
1835 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1836 if (found.count() == 0) {
1837 anItem = new QListWidgetItem(aText);
1838 myElements->addItem(anItem);
1839 if (!anItem->isSelected())
1840 listItemsToSel.push_back(anItem);
1843 foreach(anItem, found)
1844 if (!anItem->isSelected())
1845 listItemsToSel.push_back(anItem);
1848 bool blocked = myElements->signalsBlocked();
1849 myElements->blockSignals(true);
1850 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1851 myElements->blockSignals(blocked);
1852 onListSelectionChanged();
1853 listItemsToSel.clear();
1855 catch (const SALOME::SALOME_Exception& ex) {
1856 SalomeApp_Tools::QtCatchCorbaException(ex);
1861 mySelectSubMesh->setChecked(false);
1863 onListSelectionChanged();
1865 } else if (myCurrentLineEdit == myGroupLine) {
1866 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1867 SALOME_ListIO aList;
1868 mySelectionMgr->selectedObjects( aList );
1870 SALOME_ListIteratorOfListIO anIt (aList);
1871 for ( ; anIt.More(); anIt.Next()) {
1872 SMESH::SMESH_GroupBase_var aGroup =
1873 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1874 if (!aGroup->_is_nil()) {
1875 // check if mesh is the same
1876 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1877 SMESH::long_array_var anElements = aGroup->GetListOfID();
1878 int k = anElements->length();
1879 for (int i = 0; i < k; i++) {
1880 QString aText = QString::number(anElements[i]);
1881 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1882 if (found.count() == 0) {
1883 anItem = new QListWidgetItem(aText);
1884 myElements->addItem(anItem);
1885 if (!anItem->isSelected())
1886 listItemsToSel.push_back(anItem);
1889 foreach(anItem, found)
1890 if (!anItem->isSelected())
1891 listItemsToSel.push_back(anItem);
1894 bool blocked = myElements->signalsBlocked();
1895 myElements->blockSignals(true);
1896 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1897 myElements->blockSignals(blocked);
1898 onListSelectionChanged();
1899 listItemsToSel.clear();
1903 mySelectGroup->setChecked(false);
1905 onListSelectionChanged();
1907 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1908 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1909 GEOM::GEOM_IGroupOperations_var aGroupOp =
1910 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1912 SMESH::ElementType aGroupType = SMESH::ALL;
1913 switch(aGroupOp->GetType(myGeomObjects[0])) {
1914 case 7: aGroupType = SMESH::NODE; break;
1915 case 6: aGroupType = SMESH::EDGE; break;
1916 case 4: aGroupType = SMESH::FACE; break;
1917 case 2: aGroupType = SMESH::VOLUME; break;
1918 default: myIsBusy = false; return;
1921 if (aGroupType == aType) {
1922 _PTR(SObject) aGroupSO =
1923 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1924 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1926 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1927 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1928 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
1929 aBelongToGeom->SetGeom(myGeomObjects[0]);
1930 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1931 aBelongToGeom->SetElementType(aType);
1932 aFilter->SetPredicate(aBelongToGeom);
1934 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1936 int k = anElements->length();
1937 for (int i = 0; i < k; i++) {
1938 QString aText = QString::number(anElements[i]);
1939 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1940 if (found.count() == 0) {
1941 anItem = new QListWidgetItem(aText);
1942 myElements->addItem(anItem);
1943 if (!anItem->isSelected())
1944 listItemsToSel.push_back(anItem);
1947 foreach(anItem, found)
1948 if (!anItem->isSelected())
1949 listItemsToSel.push_back(anItem);
1952 bool blocked = myElements->signalsBlocked();
1953 myElements->blockSignals(true);
1954 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1955 myElements->blockSignals(blocked);
1956 onListSelectionChanged();
1957 listItemsToSel.clear();
1960 //VSR: mySelectGeomGroup->setChecked(false);
1962 onListSelectionChanged();
1965 if ( sizeBefore < myElements->count() )
1966 ++myNbChangesOfContents;
1967 // mySelectionMgr->clearSelected();
1971 //=================================================================================
1972 // function : onRemove()
1974 //=================================================================================
1975 void SMESHGUI_GroupDlg::onRemove()
1978 int sizeBefore = myElements->count();
1980 if (myCurrentLineEdit == 0) {
1981 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1982 QListWidgetItem* item;
1983 foreach(item, selItems) delete item;
1985 SALOME_ListIO aList;
1986 mySelectionMgr->selectedObjects( aList );
1988 int aNbSel = aList.Extent();
1990 if (aNbSel == 0) { myIsBusy = false; return; }
1992 SMESH::ElementType aType = SMESH::ALL;
1994 case 0: aType = SMESH::NODE; break;
1995 case 1: aType = SMESH::EDGE; break;
1996 case 2: aType = SMESH::FACE; break;
1997 case 3: aType = SMESH::VOLUME; break;
2000 if (myCurrentLineEdit == mySubMeshLine) {
2001 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2002 SALOME_ListIO aList;
2003 mySelectionMgr->selectedObjects( aList );
2005 SALOME_ListIteratorOfListIO anIt (aList);
2006 for ( ; anIt.More(); anIt.Next()) {
2007 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2008 if (!aSubMesh->_is_nil()) {
2009 // check if mesh is the same
2010 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2011 if (aType == SMESH::NODE) {
2013 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2014 int k = anElements->length();
2015 for (int i = 0; i < k; i++) {
2016 QList<QListWidgetItem*> found =
2017 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2018 QListWidgetItem* anItem;
2019 foreach(anItem, found) delete anItem;
2022 catch (const SALOME::SALOME_Exception& ex) {
2023 SalomeApp_Tools::QtCatchCorbaException(ex);
2028 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2029 int k = anElements->length();
2030 for (int i = 0; i < k; i++) {
2031 QList<QListWidgetItem*> found =
2032 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2033 QListWidgetItem* anItem;
2034 foreach(anItem, found) delete anItem;
2037 catch (const SALOME::SALOME_Exception& ex) {
2038 SalomeApp_Tools::QtCatchCorbaException(ex);
2045 else if (myCurrentLineEdit == myGroupLine) {
2046 Standard_Boolean aRes;
2047 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2048 SALOME_ListIO aList;
2049 mySelectionMgr->selectedObjects( aList );
2051 SALOME_ListIteratorOfListIO anIt (aList);
2052 for ( ; anIt.More(); anIt.Next()) {
2053 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2054 if (aRes && !aGroup->_is_nil()) {
2055 // check if mesh is the same
2056 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2057 SMESH::long_array_var anElements = aGroup->GetListOfID();
2058 int k = anElements->length();
2059 for (int i = 0; i < k; i++) {
2060 QList<QListWidgetItem*> found =
2061 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2062 QListWidgetItem* anItem;
2063 foreach(anItem, found) delete anItem;
2071 if ( sizeBefore > myElements->count() )
2072 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2076 //=================================================================================
2077 // function : onSort()
2079 //=================================================================================
2080 void SMESHGUI_GroupDlg::onSort()
2082 // PAL5412: sorts items in ascending by "string" value
2083 // myElements->sort(true);
2084 // myElements->update();
2085 int i, k = myElements->count();
2088 QList<int> aSelected;
2089 std::vector<int> anArray(k);
2090 // QMemArray<int> anArray(k);
2092 for (i = 0; i < k; i++) {
2093 int id = myElements->item(i)->text().toInt();
2095 if (myElements->item(i)->isSelected())
2096 aSelected.append(id);
2098 // sort & update list
2099 std::sort(anArray.begin(), anArray.end());
2101 myElements->clear();
2102 QListWidgetItem* anItem;
2103 QList<QListWidgetItem*> listItemsToSel;
2104 for (i = 0; i < k; i++) {
2105 anItem = new QListWidgetItem(QString::number(anArray[i]));
2106 myElements->addItem(anItem);
2107 if (aSelected.contains(anArray[i]))
2108 listItemsToSel.push_back(anItem);
2110 bool blocked = myElements->signalsBlocked();
2111 myElements->blockSignals(true);
2112 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2113 myElements->blockSignals(blocked);
2114 listItemsToSel.clear();
2119 //=================================================================================
2120 // function : closeEvent()
2122 //=================================================================================
2123 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
2128 //=================================================================================
2129 // function : onVisibilityChanged()
2131 //=================================================================================
2132 void SMESHGUI_GroupDlg::onVisibilityChanged()
2134 SetAppropriateActor();
2137 //=================================================================================
2138 // function : SMESHGUI_GroupDlg::onClose
2139 // purpose : SLOT called when "Close" button pressed. Close dialog
2140 //=================================================================================
2141 void SMESHGUI_GroupDlg::onClose()
2143 if (SMESH::GetCurrentVtkView()) {
2144 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2145 SMESH::SetPointRepresentation(false);
2146 SMESH::SetPickable();
2147 restoreShowEntityMode();
2150 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2151 SUIT_DataOwnerPtrList aList;
2152 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2153 mySelectionMgr->setSelected( aList );
2156 mySelectionMgr->clearSelected();
2157 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2158 aViewWindow->SetSelectionMode(ActorSelection);
2159 mySelectionMgr->clearFilters();
2160 mySMESHGUI->ResetState();
2165 //=================================================================================
2166 // function : onHelp()
2168 //=================================================================================
2169 void SMESHGUI_GroupDlg::onHelp()
2171 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2173 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2177 platform = "winapplication";
2179 platform = "application";
2181 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2182 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2183 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2185 arg(myHelpFileName));
2189 //=================================================================================
2190 // function : SMESHGUI_GroupDlg::onDeactivate
2191 // purpose : SLOT called when dialog must be deativated
2192 //=================================================================================
2193 void SMESHGUI_GroupDlg::onDeactivate()
2195 mySMESHGUI->ResetState();
2199 //=================================================================================
2200 // function : SMESHGUI_GroupDlg::enterEvent
2201 // purpose : Event filter
2202 //=================================================================================
2203 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2206 mySMESHGUI->EmitSignalDeactivateDialog();
2208 mySelectionMode = grpNoSelection;
2209 setSelectionMode(myTypeId);
2210 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2211 mySMESHGUI->SetActiveDialogBox(this);
2212 mySMESHGUI->SetState(800);
2216 //=================================================================================
2217 // function : hideEvent
2218 // purpose : caused by ESC key
2219 //=================================================================================
2220 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
2222 if (!isMinimized() && !myIsBusy)
2226 //=================================================================================
2227 // function : keyPressEvent()
2229 //=================================================================================
2230 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2232 QDialog::keyPressEvent( e );
2233 if ( e->isAccepted() )
2236 if ( e->key() == Qt::Key_F1 )
2243 //================================================================================
2245 * \brief Enable showing of the popup when Geometry selection btn is clicked
2246 * \param enable - true to enable
2248 //================================================================================
2250 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2252 void SMESHGUI_GroupDlg::updateGeomPopup()
2254 bool enable = false;
2256 if ( !myMesh->_is_nil() )
2257 enable = myMesh->NbEdges() > 0;
2259 if ( myGeomGroupBtn )
2261 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2263 if ( !myGeomPopup ) {
2264 myGeomPopup = new QMenu(this);
2265 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2266 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2267 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2269 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2275 //=================================================================================
2276 // function : onGeomSelectionButton()
2278 //=================================================================================
2279 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2281 if ( myGeomPopup && isBtnOn )
2283 myCurrentLineEdit = myGeomGroupLine;
2284 QAction* a = myGeomPopup->exec( QCursor::pos() );
2285 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2286 setSelectionMode(grpGeomSelection);
2290 myCurrentLineEdit = 0;
2291 setSelectionMode(grpAllSelection);
2295 //=================================================================================
2296 // function : onGeomPopup()
2298 //=================================================================================
2299 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2301 int index = myActions[a];
2302 if ( index == GEOM_BY_MESH_INDEX )
2304 mySelectionMode = grpNoSelection;
2305 if ( !myShapeByMeshOp ) {
2306 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2307 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2308 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2309 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2310 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2312 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2313 if ( !myMesh->_is_nil() ) {
2315 hide(); // stop processing selection
2317 myShapeByMeshOp->setModule( mySMESHGUI );
2318 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2319 myShapeByMeshOp->SetMesh( myMesh );
2320 myShapeByMeshOp->start();
2325 //================================================================================
2327 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2329 //================================================================================
2331 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2333 if ( myShapeByMeshOp == op ) {
2334 mySMESHGUI->getApp()->updateObjectBrowser();
2336 // Select a found geometry object
2337 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2338 if ( !aGeomVar->_is_nil() )
2340 QString ID = aGeomVar->GetStudyEntry();
2341 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2342 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2343 SALOME_ListIO anIOList;
2344 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2345 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2346 anIOList.Append( anIO );
2347 mySelectionMgr->setSelectedObjects( anIOList, false );
2348 onObjectSelectionChanged();
2354 //================================================================================
2356 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2358 //================================================================================
2360 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2362 if ( myShapeByMeshOp == op )
2365 setSelectionMode(grpGeomSelection);
2369 //=================================================================================
2370 // function : setGroupColor()
2372 //=================================================================================
2373 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2375 QColor aQColor( (int)( theColor.R * 255.0 ),
2376 (int)( theColor.G * 255.0 ),
2377 (int)( theColor.B * 255.0 ) );
2378 setGroupQColor( aQColor );
2381 //=================================================================================
2382 // function : getGroupColor()
2384 //=================================================================================
2385 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2387 QColor aQColor = getGroupQColor();
2389 SALOMEDS::Color aColor;
2390 aColor.R = (float)aQColor.red() / 255.0;
2391 aColor.G = (float)aQColor.green() / 255.0;
2392 aColor.B = (float)aQColor.blue() / 255.0;
2397 //=================================================================================
2398 // function : setGroupQColor()
2400 //=================================================================================
2401 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2403 if( theColor.isValid() )
2404 myColorBtn->setColor( theColor );
2407 //=================================================================================
2408 // function : getGroupQColor()
2410 //=================================================================================
2411 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2413 return myColorBtn->color();
2416 //=================================================================================
2417 // function : setDefaultGroupColor()
2419 //=================================================================================
2420 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2422 if( myMesh->_is_nil() )
2425 bool isAutoColor = myMesh->GetAutoColor();
2430 int r = 0, g = 0, b = 0;
2431 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2432 aQColor.setRgb( r, g, b );
2436 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2438 QList<SALOMEDS::Color> aReservedColors;
2439 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2441 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2442 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2443 aReservedColors.append( aReservedColor );
2446 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2447 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2448 (int)( aColor.G * 255.0 ),
2449 (int)( aColor.B * 255.0 ) );
2453 setGroupQColor( aQColor );
2456 //=================================================================================
2457 // function : SetAppropriateActor()
2458 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2459 // NPAL19389: create a group with a selection in another group.
2460 // if mesh actor is not visible - find any first visible group or submesh
2461 //=================================================================================
2462 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2464 bool isActor = false;
2465 myActorsList.clear();
2467 if (myMesh->_is_nil()) return false;
2469 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2471 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2473 if (!myGroupOnGeom->_is_nil()) {
2474 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2475 if (anActor && anActor->hasIO())
2478 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2481 myActorsList.append(anActor);
2487 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2488 if (anActor && anActor->hasIO()) {
2490 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2493 myActorsList.append(anActor);
2497 if (!isActor && !myGroup->_is_nil()) {
2498 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2499 if (anActor && anActor->hasIO())
2500 myActorsList.append(anActor);
2503 // try any visible actor of group or submesh of current mesh
2506 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2508 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2509 int len = strlen(meshEntry);
2511 // iterate on all actors in current view window, search for
2512 // any visible actor, that belongs to group or submesh of current mesh
2513 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2514 vtkActorCollection *aCollection = aCopy.GetActors();
2515 int nbItems = aCollection->GetNumberOfItems();
2516 for (int i=0; i<nbItems && !isActor; i++)
2518 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2519 if (anActor && anActor->hasIO()) {
2520 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2521 if (aViewWindow->isVisible(anIO)) {
2522 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2523 myActorsList.append(anActor);
2531 if (myActorsList.count() > 0) {
2532 QListIterator<SMESH_Actor*> it( myActorsList );
2533 while ( it.hasNext() ) {
2534 SMESH_Actor* anActor = it.next();
2535 if ( IsActorVisible(anActor) )
2536 anActor->SetPickable(true);
2540 return ( isActor || (myActorsList.count() > 0) );
2543 //=======================================================================
2544 //function : setShowEntityMode
2545 //purpose : make shown only entity corresponding to my type
2546 //=======================================================================
2547 void SMESHGUI_GroupDlg::setShowEntityMode()
2549 if ( !myMesh->_is_nil() ) {
2550 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2551 if (!myStoredShownEntity)
2552 myStoredShownEntity = actor->GetEntityMode();
2553 switch ( myTypeId ) {
2554 case 0: restoreShowEntityMode(); break;
2555 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2556 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2557 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2563 //=======================================================================
2564 //function : restoreShowEntityMode
2565 //purpose : restore ShowEntity mode of myActor
2566 //=======================================================================
2567 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2569 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2570 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2571 actor->SetEntityMode(myStoredShownEntity);
2574 myStoredShownEntity = 0;
2577 //=======================================================================
2578 //function : IsActorVisible
2579 //purpose : return visibility of the actor
2580 //=======================================================================
2581 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2583 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2584 if (theActor && aViewWindow)
2585 return aViewWindow->isVisible(theActor->getIO());
2589 //================================================================
2590 //function : setIsApplyAndClose
2591 //purpose : Set value of the flag indicating that the dialog is
2592 // accepted by Apply & Close button
2593 //================================================================
2594 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2596 myIsApplyAndClose = theFlag;
2599 //================================================================
2600 //function : isApplyAndClose
2601 //purpose : Get value of the flag indicating that the dialog is
2602 // accepted by Apply & Close button
2603 //================================================================
2604 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2606 return myIsApplyAndClose;