1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_GroupDlg.cxx
25 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
28 #include "SMESHGUI_GroupDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_GroupUtils.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
36 #include "SMESHGUI_FilterDlg.h"
37 #include "SMESHGUI_ShapeByMeshDlg.h"
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_Actor.h>
41 //#include <SMESH_ActorUtils.h>
42 #include <SMESH_LogicalFilter.hxx>
44 // SALOME GEOM includes
46 #include <GEOM_SelectionFilter.h>
47 #include <GEOM_wrap.hxx>
49 // SALOME GUI includes
50 #include <QtxColorButton.h>
52 #include <SUIT_Desktop.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SUIT_Session.h>
55 #include <SUIT_MessageBox.h>
56 #include <SUIT_OverrideCursor.h>
58 #include <SalomeApp_Tools.h>
59 #include <SalomeApp_Application.h>
60 #include <SalomeApp_Study.h>
61 #include <LightApp_SelectionMgr.h>
63 #include <SALOME_ListIO.hxx>
65 #include <SVTK_ViewWindow.h>
67 #include <VTKViewer_Algorithm.h>
69 // SALOME KERNEL includes
70 #include <SALOMEDSClient_Study.hxx>
73 #include <vtkRenderer.h>
74 #include <vtkActorCollection.h>
77 #include <TColStd_MapOfInteger.hxx>
80 #include <QButtonGroup>
84 #include <QPushButton>
85 #include <QToolButton>
86 #include <QRadioButton>
88 #include <QGridLayout>
89 #include <QHBoxLayout>
90 #include <QVBoxLayout>
91 #include <QListWidget>
92 #include <QStackedWidget>
104 enum grpSelectionMode {
106 grpNodeSelection = 0,
108 grpBallSelection = 2,
109 grpEdgeSelection = 3,
110 grpFaceSelection = 4,
111 grpVolumeSelection = 5,
112 grpSubMeshSelection = 6,
113 grpGroupSelection = 7,
114 grpMeshSelection = 8,
115 grpGeomSelection = 9,
116 grpAllSelection = 10,
119 //=================================================================================
120 // function : SMESHGUI_GroupDlg()
122 //=================================================================================
123 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
124 SMESH::SMESH_Mesh_ptr theMesh )
125 : QDialog( SMESH::GetDesktop( theModule ) ),
126 mySMESHGUI( theModule ),
127 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
128 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
130 myNameChanged( false ),
131 myIsApplyAndClose( false ),
132 myNbChangesOfContents(0)
135 if ( !theMesh->_is_nil() )
139 mySelectSubMesh->setEnabled( false );
140 mySelectGroup->setEnabled( false );
141 myGeomGroupBtn->setEnabled( false );
142 myGeomGroupLine->setEnabled( false );
146 //=================================================================================
147 // function : SMESHGUI_GroupDlg()
149 //=================================================================================
150 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
151 SMESH::SMESH_GroupBase_ptr theGroup,
152 const bool theIsConvert )
153 : QDialog( SMESH::GetDesktop( theModule ) ),
154 mySMESHGUI( theModule ),
155 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
156 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
158 myNameChanged( false ),
159 myNbChangesOfContents(0) // just not to use uninitialized variable
162 if ( !theGroup->_is_nil() )
163 init( theGroup, theIsConvert );
166 mySelectSubMesh->setEnabled( false );
167 mySelectGroup->setEnabled( false );
169 myCurrentLineEdit = myMeshGroupLine;
170 setSelectionMode( grpGroupSelection );
174 //=================================================================================
175 // function : SMESHGUI_GroupDlg()
177 //=================================================================================
178 void SMESHGUI_GroupDlg::initDialog( bool create)
181 setAttribute( Qt::WA_DeleteOnClose, true );
185 myCurrentLineEdit = 0;
189 myGeomObjects = new GEOM::ListOfGO();
190 myGeomObjects->length( 0 );
192 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
194 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
195 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
197 setSizeGripEnabled( true);
199 QGridLayout* aMainLayout = new QGridLayout( this );
200 aMainLayout->setMargin( MARGIN );
201 aMainLayout->setSpacing( SPACING );
203 /***************************************************************/
204 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
205 myMeshGroupBtn = new QPushButton( this );
206 myMeshGroupBtn->setIcon( image0 );
207 myMeshGroupLine = new QLineEdit( this );
208 myMeshGroupLine->setReadOnly( true );
210 /***************************************************************/
211 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
212 myTypeGroup = new QButtonGroup( this );
213 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
214 aTypeBoxLayout->setMargin( MARGIN );
215 aTypeBoxLayout->setSpacing( SPACING );
218 types.append( tr( "MESH_NODE" ) );
219 types.append( tr( "SMESH_ELEM0D" ) );
220 types.append( tr( "SMESH_BALL_ELEM" ) );
221 types.append( tr( "SMESH_EDGE" ) );
222 types.append( tr( "SMESH_FACE" ) );
223 types.append( tr( "SMESH_VOLUME" ) );
225 for ( int i = 0; i < types.count(); i++ )
227 rb = new QRadioButton( types[i], aTypeBox );
228 myTypeGroup->addButton( rb, i );
229 aTypeBoxLayout->addWidget( rb );
231 aTypeBox->setEnabled( create );
234 /***************************************************************/
235 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
236 aName->setMinimumWidth( 50 );
237 myName = new QLineEdit( this );
239 /***************************************************************/
240 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
241 myGrpTypeGroup = new QButtonGroup( this );
242 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
243 aGrpTypeBoxLayout->setMargin( MARGIN );
244 aGrpTypeBoxLayout->setSpacing( SPACING );
246 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
247 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
248 QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox );
249 myGrpTypeGroup->addButton( rb1, 0 );
250 myGrpTypeGroup->addButton( rb2, 1 );
251 myGrpTypeGroup->addButton( rb3, 2 );
252 aGrpTypeBoxLayout->addWidget( rb1 );
253 aGrpTypeBoxLayout->addWidget( rb2 );
254 aGrpTypeBoxLayout->addWidget( rb3 );
255 aGrpTypeBox->setEnabled( create );
258 /***************************************************************/
259 myWGStack = new QStackedWidget( this );
260 QWidget* wg1 = new QWidget( myWGStack );
261 QWidget* wg2 = new QWidget( myWGStack );
262 QWidget* wg3 = new QWidget( myWGStack );
264 /***************************************************************/
265 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
266 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
267 aContentBoxLayout->setMargin( MARGIN );
268 aContentBoxLayout->setSpacing( SPACING );
270 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
271 myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
273 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
274 myElements = new QListWidget( aContentBox );
275 myElements->setSelectionMode( QListWidget::ExtendedSelection );
277 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
278 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
279 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
280 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
282 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
283 aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
284 aContentBoxLayout->addWidget( myFilterBtn, 1, 1 );
285 aContentBoxLayout->addWidget( myElementsLab, 2, 0 );
286 aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 );
287 aContentBoxLayout->addWidget( myAddBtn, 3, 1 );
288 aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 );
289 aContentBoxLayout->addWidget( mySortBtn, 8, 1 );
291 aContentBoxLayout->setColumnStretch( 0, 1 );
292 aContentBoxLayout->setRowStretch( 3, 1 );
293 aContentBoxLayout->setRowStretch( 6, 1 );
295 /***************************************************************/
296 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
297 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
298 mySelectBoxLayout->setMargin( MARGIN );
299 mySelectBoxLayout->setSpacing( SPACING );
301 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
302 mySubMeshBtn = new QPushButton( mySelectBox );
303 mySubMeshBtn->setIcon( image0 );
304 mySubMeshLine = new QLineEdit( mySelectBox );
305 mySubMeshLine->setReadOnly( true );
306 onSelectSubMesh( false );
308 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
309 myGroupBtn = new QPushButton( mySelectBox );
310 myGroupBtn->setIcon( image0 );
311 myGroupLine = new QLineEdit( mySelectBox );
312 myGroupLine->setReadOnly( true );
313 onSelectGroup( false );
315 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
316 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
317 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
318 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
319 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
320 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
322 /***************************************************************/
323 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
324 wg1Layout->setMargin( 0 );
325 wg1Layout->setSpacing( SPACING );
326 wg1Layout->addWidget( aContentBox );
327 wg1Layout->addWidget( mySelectBox );
328 wg1Layout->setStretchFactor( aContentBox, 10 );
330 /***************************************************************/
331 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
332 myGeomGroupBtn = new QToolButton( wg2 );
333 myGeomGroupBtn->setIcon( image0 );
334 myGeomGroupBtn->setCheckable( true );
335 myGeomGroupLine = new QLineEdit( wg2 );
336 myGeomGroupLine->setReadOnly( true ); //VSR ???
337 onSelectGeomGroup( false );
339 myGeomGroupBtn->setEnabled( create );
340 myGeomGroupLine->setEnabled( create );
342 /***************************************************************/
343 QGridLayout* wg2Layout = new QGridLayout( wg2 );
344 wg2Layout->setMargin( 0 );
345 wg2Layout->setSpacing( SPACING );
346 wg2Layout->addWidget( geomObject, 0, 0 );
347 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
348 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
349 wg2Layout->setRowStretch( 1, 5 );
351 /***************************************************************/
352 QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
353 QGridLayout* wg3Layout = new QGridLayout( wg3 );
354 wg3Layout->setMargin( 0 );
355 wg3Layout->setSpacing( SPACING );
356 wg3Layout->addWidget( aFilter2, 0, 0 );
357 wg3Layout->setRowStretch( 1, 5 );
359 /***************************************************************/
360 myWGStack->insertWidget( 0, wg1 );
361 myWGStack->insertWidget( 1, wg2 );
362 myWGStack->insertWidget( 2, wg3 );
364 /***************************************************************/
365 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
366 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
367 aColorBoxLayout->setMargin(MARGIN);
368 aColorBoxLayout->setSpacing(SPACING);
370 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
371 myColorBtn = new QtxColorButton(aColorBox);
372 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
373 myColorBtn->sizePolicy().verticalPolicy() );
375 aColorBoxLayout->addWidget(aColorLab);
376 aColorBoxLayout->addWidget(myColorBtn);
378 /***************************************************************/
380 QFrame* aButtons = new QFrame(this);
381 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
382 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
383 aBtnLayout->setMargin(MARGIN);
384 aBtnLayout->setSpacing(SPACING);
386 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
387 myOKBtn->setAutoDefault(true);
388 myOKBtn->setDefault(true);
389 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
390 myApplyBtn->setAutoDefault(true);
391 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
392 myCloseBtn->setAutoDefault(true);
393 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
394 myHelpBtn->setAutoDefault(true);
396 aBtnLayout->addWidget(myOKBtn);
397 aBtnLayout->addSpacing(10);
398 aBtnLayout->addWidget(myApplyBtn);
399 aBtnLayout->addSpacing(10);
400 aBtnLayout->addStretch();
401 aBtnLayout->addWidget(myCloseBtn);
402 aBtnLayout->addWidget(myHelpBtn);
404 /***************************************************************/
405 aMainLayout->addWidget(meshGroupLab, 0, 0);
406 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
407 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
408 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
409 aMainLayout->addWidget(aName, 2, 0);
410 aMainLayout->addWidget(myName, 2, 2);
411 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
412 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
413 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
414 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
416 /* signals and slots connections */
417 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
418 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
419 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
421 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
422 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
424 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
425 connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters()));
426 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
427 connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
428 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
429 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
430 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
432 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
433 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
434 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
435 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
436 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
438 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
440 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
441 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
442 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
443 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
446 mySMESHGUI->SetActiveDialogBox(this);
447 mySMESHGUI->SetState(800);
449 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
450 mySelectionMode = grpNoSelection;
452 myMeshFilter = new SMESH_TypeFilter(SMESH::MESH);
453 mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
454 SMESH_LogicalFilter::LO_OR,
455 /*takeOwnership=*/true);
456 myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
457 SMESH_LogicalFilter::LO_OR,
458 /*takeOwnership=*/true);
459 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
461 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
462 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
463 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
464 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
465 connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), this, SLOT(onOpenView()));
466 connect(mySMESHGUI, SIGNAL(SignalCloseView()), this, SLOT(onCloseView()));
467 rb1->setChecked(true); // VSR !!!
468 onGrpTypeChanged(0); // VSR!!!
470 if (myMesh->_is_nil() )
471 myTypeGroup->button(0)->setChecked(true);
473 onSelectAll(); //updateButtons();
476 //=================================================================================
477 // function : ~SMESHGUI_GroupDlg()
478 // purpose : Destroys the object and frees any allocated resources
479 //=================================================================================
480 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
482 // no need to delete child widgets, Qt does it all for us
483 if ( myFilterDlg != 0 ) {
484 myFilterDlg->setParent( 0 );
487 if ( myMeshFilter ) delete myMeshFilter;
488 if ( mySubMeshFilter ) delete mySubMeshFilter;
489 if ( myGroupFilter ) delete myGroupFilter;
490 if ( myGeomFilter ) delete myGeomFilter;
493 //=================================================================================
494 // function : GetDefaultName()
495 // purpose : Get the Group Name if Create new Group
496 //=================================================================================
497 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
501 // collect all object names of SMESH component
502 SalomeApp_Study* appStudy =
503 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
504 if ( !appStudy ) return aName;
505 _PTR(Study) aStudy = appStudy->studyDS();
507 std::set<std::string> aSet;
508 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
510 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
512 for (it->InitEx(true); it->More(); it->Next()) {
514 aSet.insert(obj->GetName());
518 // build a unique name
520 bool isUnique = false;
522 aName = theOperation + "_" + QString::number(++aNumber);
523 isUnique = (aSet.count(std::string(SMESH::toUtf8(aName))) == 0);
529 void SMESHGUI_GroupDlg::setDefaultName() const
532 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
534 QString aPrefix ="Group_";
538 aResName = aPrefix + QString::number( i++ );
539 anObj = aStudy->FindObject( SMESH::toUtf8(aResName) );
542 myName->setText(aResName);
545 //=================================================================================
548 //=================================================================================
549 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
551 mySelectionMgr->installFilter(myMeshFilter);
553 /* init data from current selection */
554 restoreShowEntityMode();
555 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
557 myGroup = SMESH::SMESH_Group::_nil();
558 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
559 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
561 // NPAL19389: create a group with a selection in another group
562 // set actor of myMesh, if it is visible, else try
563 // any visible actor of group or submesh of myMesh
564 SetAppropriateActor();
566 setDefaultGroupColor();
571 mySelectionMgr->selectedObjects( aList );
572 if( !aList.IsEmpty() )
574 QString aName = aList.First()->getName();
575 myMeshGroupLine->setText(aName);//??????
576 myMeshGroupLine->home( false );
579 myCurrentLineEdit = 0;
581 myTypeGroup->button(0)->setChecked(true);
585 //=================================================================================
588 //=================================================================================
589 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
590 const bool theIsConvert)
592 restoreShowEntityMode();
593 myMesh = theGroup->GetMesh();
596 myNameChanged = true;
597 myName->blockSignals(true);
598 myName->setText(SMESH::fromUtf8(theGroup->GetName()));
599 myName->blockSignals(false);
602 SALOMEDS::Color aColor = theGroup->GetColor();
603 setGroupColor( aColor );
605 myMeshGroupLine->setText(SMESH::fromUtf8(theGroup->GetName()));
608 switch(theGroup->GetType()) {
609 case SMESH::NODE: aType = grpNodeSelection; break;
610 case SMESH::ELEM0D: aType = grp0DSelection; break;
611 case SMESH::BALL: aType = grpBallSelection; break;
612 case SMESH::EDGE: aType = grpEdgeSelection; break;
613 case SMESH::FACE: aType = grpFaceSelection; break;
614 case SMESH::VOLUME: aType = grpVolumeSelection; break;
616 myTypeGroup->button(aType)->setChecked(true);
618 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
619 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
620 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
621 myFilter = SMESH::Filter::_nil();
623 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
626 // NPAL19389: create a group with a selection in another group
627 // set actor of myMesh, if it is visible, else set
628 // actor of theGroup, if it is visible, else try
629 // any visible actor of group or submesh of myMesh
630 // commented, because an attempt to set selection on not displayed cells leads to error
631 SetAppropriateActor();
633 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
635 anActor = SMESH::FindActorByObject(theGroup);
636 SMESH::SetPickable(anActor);*/
638 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
639 myGrpTypeGroup->button(grpType)->setChecked(true);
640 onGrpTypeChanged(grpType);
643 if ( grpType == 0 ) { // standalone group
644 myCurrentLineEdit = 0;
646 myAllowElemsModif->setChecked( true );
648 setSelectionMode(aType);
650 setShowEntityMode(); // depends on myTypeId
653 if (!theGroup->IsEmpty()) {
654 SMESH::long_array_var anElements = theGroup->GetListOfID();
655 int k = anElements->length();
656 for (int i = 0; i < k; i++) {
657 myIdList.append(anElements[i]);
658 myElements->addItem(QString::number(anElements[i]));
660 myElements->selectAll();
663 else if ( grpType == 1 ) // group on geom
665 QString aShapeName( "" );
666 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
667 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
668 if (!aGroupShape->_is_nil())
670 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
672 aShapeName = aGroupShapeSO->GetName().c_str();
674 myGeomGroupLine->setText( aShapeName );
676 else // group on filter
678 myFilter = myGroupOnFilter->GetFilter();
679 if ( !myFilter->_is_nil() ) {
680 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
681 if ( perdicate->_is_nil() )
682 myFilter = SMESH::Filter::_nil();
688 myNameChanged = true;
689 myName->blockSignals(true);
690 myName->setText(SMESH::fromUtf8(theGroup->GetName()));
691 myName->blockSignals(false);
694 onSelectAll(); //updateButtons();
697 //=================================================================================
698 // function : updateButtons()
700 //=================================================================================
701 void SMESHGUI_GroupDlg::updateButtons()
703 bool enable = !myName->text().trimmed().isEmpty();
706 if (myGrpTypeId == 0) { // standalone
707 if ( !mySelectAll->isChecked() )
709 if ( myAllowElemsModif->isChecked() )
711 enable = ( myElements->count() > 0 );
713 else if ((enable = !myFilter->_is_nil() ))
715 SMESH::array_of_ElementType_var types = myFilter->GetTypes();
716 enable = types->length();
719 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
721 else if (myGrpTypeId == 1) // on geom
723 if (CORBA::is_nil(myGroupOnGeom)) // creation mode
724 enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
726 else if (myGrpTypeId == 2) // on filter
728 if (( enable = !myFilter->_is_nil() ))
729 if (CORBA::is_nil(myGroupOnFilter) ) // creation mode
730 enable = !myMesh->_is_nil();
734 bool meshHasGeom = ( myMesh->_is_nil() || myMesh->HasShapeToMesh() );
735 if ( myGrpTypeId != 1 )
737 myGrpTypeGroup->button(1)->setEnabled( meshHasGeom );
741 myGeomGroupBtn->setEnabled( meshHasGeom );
742 myGeomGroupLine->setEnabled( meshHasGeom );
745 myOKBtn->setEnabled(enable);
746 myApplyBtn->setEnabled(enable);
749 //=================================================================================
750 // function : onNameChanged()
752 //=================================================================================
753 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
755 myOldName = myName->text();
757 myNameChanged = !myName->text().trimmed().isEmpty();
760 //=================================================================================
761 // function : onTypeChanged()
762 // purpose : Group elements type radio button management
763 //=================================================================================
764 void SMESHGUI_GroupDlg::onTypeChanged (int id)
766 if (myTypeId != id) {
769 if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
770 setSelectionMode(id);
772 setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
774 onObjectSelectionChanged();
779 //=================================================================================
780 // function : onGrpTypeChanged()
781 // purpose : Group type radio button management
782 //=================================================================================
783 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
785 if (myGrpTypeId != id) {
787 myWGStack->setCurrentIndex( id );
788 myName->blockSignals(true);
789 myName->setText(myOldName);
790 myName->blockSignals(false);
791 onSelectGeomGroup(id != 0);
796 //=================================================================================
797 // function : onColorChanged()
798 // purpose : Color button management
799 //=================================================================================
800 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
805 //=================================================================================
806 // function : setSelectionMode()
807 // purpose : Radio button management
808 //=================================================================================
809 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
812 if (myMesh->_is_nil())
814 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
815 bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
816 if (mySelectionMode != theMode) {
817 // [PAL10408] mySelectionMgr->clearSelected();
818 mySelectionMgr->clearFilters();
819 SMESH::RemoveFilters();
821 if (myActorsList.count() > 0)
822 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
823 it.next()->SetPointRepresentation(false);
825 SMESH::SetPointRepresentation(false);
828 case grpNodeSelection:
829 if ( myGrpTypeId == 0 ) // standalone
831 if (myActorsList.count() > 0)
832 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
833 it.next()->SetPointRepresentation(true);
835 SMESH::SetPointRepresentation(true);
837 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
839 case grpEdgeSelection:
840 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
842 case grpBallSelection:
843 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
846 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : Elem0DSelection);
848 case grpFaceSelection:
849 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
851 case grpVolumeSelection:
852 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
854 case grpSubMeshSelection: {
856 SMESH_TypeFilter* f = 0;
858 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH); break;
859 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_EDGE); break;
860 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_FACE); break;
861 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_SOLID); break;
862 default: f = new SMESH_TypeFilter(SMESH::SUBMESH);
864 QList<SUIT_SelectionFilter*> filtList;
865 filtList.append( f );
866 filtList.append( new SMESH_TypeFilter(SMESH::SUBMESH_COMPOUND));
867 mySubMeshFilter->setFilters( filtList );
869 mySelectionMgr->installFilter( mySubMeshFilter );
871 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
874 case grpGroupSelection: {
876 SMESH_TypeFilter* f = 0;
878 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_NODE); break;
879 case grp0DSelection: f = new SMESH_TypeFilter(SMESH::GROUP_0D); break;
880 case grpBallSelection: f = new SMESH_TypeFilter(SMESH::GROUP_BALL); break;
881 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_EDGE); break;
882 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::GROUP_FACE); break;
883 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_VOLUME); break;
884 default: f = new SMESH_TypeFilter(SMESH::GROUP);
886 QList<SUIT_SelectionFilter*> filtList;
887 filtList.append( f );
888 myGroupFilter->setFilters( filtList );
890 mySelectionMgr->installFilter(myGroupFilter);
891 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
894 case grpMeshSelection:
895 mySelectionMgr->installFilter(myMeshFilter);
896 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
898 case grpGeomSelection:
899 mySelectionMgr->installFilter(myGeomFilter);
900 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
903 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
906 if ( aViewWindow ) aViewWindow->Repaint();
907 mySelectionMode = theMode;
911 //=================================================================================
912 // function : onApply()
914 //=================================================================================
915 bool SMESHGUI_GroupDlg::onApply()
917 if (mySMESHGUI->isActiveStudyLocked())
920 if (myName->text().trimmed().isEmpty())
923 SMESH::ElementType aType = SMESH::ALL;
925 case grpNodeSelection: aType = SMESH::NODE; break;
926 case grp0DSelection: aType = SMESH::ELEM0D; break;
927 case grpBallSelection: aType = SMESH::BALL; break;
928 case grpEdgeSelection: aType = SMESH::EDGE; break;
929 case grpFaceSelection: aType = SMESH::FACE; break;
930 case grpVolumeSelection: aType = SMESH::VOLUME; break;
934 QStringList anEntryList;
936 SMESH::SMESH_GroupBase_var resultGroup;
937 bool isCreation, isConversion = false;
939 SUIT_OverrideCursor wc;
941 if (myGrpTypeId == 0) // standalone
943 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
946 mySelectionMgr->clearSelected();
948 if (myGroup->_is_nil()) { // creation or conversion
949 // check if group on geometry is not null
950 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
951 if (myMesh->_is_nil())
953 if ( myGroupOnGeom->_is_nil() )
954 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
956 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
958 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
959 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
964 if (myGroup->_is_nil()) { // creation
965 if (myMesh->_is_nil())
968 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
970 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
973 if ( mySelectAll->isChecked() ) {
975 myGroup->AddFrom(myMesh.in());
980 if ( !myFilter->_is_nil() &&
981 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
983 myGroup->AddFrom( myFilter );
987 SMESH::long_array_var anIdList = new SMESH::long_array;
988 int i, k = myElements->count();
990 for (i = 0; i < k; i++) {
991 anIdList[i] = myElements->item(i)->text().toInt();
993 myGroup->Add(anIdList.inout());
1000 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
1003 if ( mySelectAll->isChecked() ) {
1006 myGroup->AddFrom(myMesh.in());
1009 QList<int> aAddList;
1011 int i, total = myElements->count();
1012 for (i = 0; i < total; i++) {
1013 int anId = myElements->item(i)->text().toInt();
1014 int idx = myIdList.indexOf(anId);
1016 aAddList.append(anId);
1018 myIdList.removeAt(idx);
1020 if (!aAddList.empty()) {
1021 SMESH::long_array_var anIdList = new SMESH::long_array;
1022 int added = aAddList.count();
1023 anIdList->length(added);
1024 for (i = 0; i < added; i++)
1025 anIdList[i] = aAddList[i];
1026 myGroup->Add(anIdList.inout());
1028 if (!myIdList.empty()) {
1029 SMESH::long_array_var anIdList = new SMESH::long_array;
1030 int removed = myIdList.count();
1031 anIdList->length(removed);
1032 for (i = 0; i < removed; i++)
1033 anIdList[i] = myIdList[i];
1034 myGroup->Remove(anIdList.inout());
1036 /* init for next operation */
1038 for (i = 0; i < total; i++) {
1039 myIdList.append(myElements->item(i)->text().toInt());
1046 else if (myGrpTypeId == 1) // on geom object
1048 if (CORBA::is_nil(myGroupOnGeom)) { // creation
1049 if (myMesh->_is_nil() || !myGeomObjects->length())
1052 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1054 if (myGeomObjects->length() == 1) {
1055 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1056 SMESH::toUtf8(myName->text()),
1060 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1061 if ( aSMESHGen->_is_nil() )
1064 // create a geometry group
1065 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1066 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1068 if (geomGen->_is_nil() || !aStudy)
1071 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
1075 // check and add all selected GEOM objects: they must be
1076 // a sub-shapes of the main GEOM and must be of one type
1077 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1078 for ( int i =0; i < myGeomObjects->length(); i++) {
1079 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1081 aGroupType = aSubShapeType;
1082 else if (aSubShapeType != aGroupType) {
1083 aGroupType = TopAbs_SHAPE;
1088 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1089 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1090 op->UnionList(aGroupVar, myGeomObjects);
1093 // publish the GEOM group in study
1094 QString aNewGeomGroupName ( "Auto_group_for_" );
1095 aNewGeomGroupName += myName->text();
1096 SALOMEDS::SObject_var aNewGroupSO =
1097 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
1098 SMESH::toUtf8(aNewGeomGroupName), aMeshShape);
1101 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1102 SMESH::toUtf8(myName->text()),
1105 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1111 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1116 if (myGrpTypeId == 2) // group on filter
1118 if ( myFilter->_is_nil() ) return false;
1120 if (CORBA::is_nil(myGroupOnFilter)) { // creation
1121 if (myMesh->_is_nil())
1124 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1125 SMESH::toUtf8(myName->text()),
1128 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1133 myGroupOnFilter->SetFilter( myFilter );
1135 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1143 SALOMEDS::Color aColor = getGroupColor();
1144 resultGroup->SetColor(aColor);
1146 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1148 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1150 resultGroup->SetName(SMESH::toUtf8(myName->text().trimmed()));
1154 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1156 /* init for the next operation */
1158 myElements->clear();
1159 myGroup = SMESH::SMESH_Group::_nil();
1160 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1161 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1162 myFilter = SMESH::Filter::_nil();
1164 setDefaultGroupColor(); // reset color for case if 'auto-color' feature is enabled.
1170 if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
1172 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1173 if ( isConversion ) { // need to reset TVisualObj and actor
1174 SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
1175 SMESH::Update( anIO,true);
1176 myActorsList.clear();
1177 anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1178 if ( !anActor ) return false;
1179 myActorsList.append( anActor );
1181 anActor->setName(SMESH::toUtf8(myName->text()));
1184 switch ( myTypeId ) {
1185 case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1186 case grp0DSelection: anActor->Set0DColor ( aColor.R, aColor.G, aColor.B ); break;
1187 case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1188 case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1189 case grpVolumeSelection:
1190 SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
1191 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1193 case grpFaceSelection:
1195 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1196 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1199 // update a visible group accoding to a changed contents
1200 if ( !isConversion && anActor->GetVisibility() )
1202 SMESH::Update( anIO, true );
1203 SMESH::RepaintCurrentView();
1208 SMESHGUI::Modified();
1209 mySMESHGUI->updateObjBrowser(true);
1210 mySelectionMgr->clearSelected();
1212 if( LightApp_Application* anApp =
1213 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1214 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1219 //=================================================================================
1220 // function : onOK()
1222 //=================================================================================
1223 void SMESHGUI_GroupDlg::onOK()
1225 setIsApplyAndClose( true );
1228 setIsApplyAndClose( false );
1230 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
1233 //=================================================================================
1234 // function : onListSelectionChanged()
1235 // purpose : Called when selection in element list is changed
1236 //=================================================================================
1237 void SMESHGUI_GroupDlg::onListSelectionChanged()
1239 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1240 if( myIsBusy || myActorsList.count() == 0 ) return;
1243 if (myCurrentLineEdit == 0) {
1244 mySelectionMgr->clearSelected();
1245 TColStd_MapOfInteger aIndexes;
1246 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1247 QListWidgetItem* anItem;
1248 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1249 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1250 SALOME_ListIO aList;
1251 aList.Append(myActorsList.first()->getIO());
1252 mySelectionMgr->setSelectedObjects(aList,false);
1257 //=================================================================================
1258 // function : onObjectSelectionChanged()
1259 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1260 //=================================================================================
1261 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1263 if ( myIsBusy || !isEnabled()) return;
1264 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1268 SALOME_ListIO aList;
1269 mySelectionMgr->selectedObjects( aList );
1271 int aNbSel = aList.Extent();
1272 myElements->clearSelection();
1274 if (myCurrentLineEdit)
1276 myCurrentLineEdit->setText( "" );
1277 QString aString = "";
1279 if (myCurrentLineEdit == myMeshGroupLine)
1281 mySelectSubMesh->setEnabled(false);
1282 mySelectGroup->setEnabled(false);
1283 myGroupLine->setText( "" );
1284 mySubMeshLine->setText( "" );
1286 myGeomGroupBtn->setEnabled(false);
1287 myGeomGroupLine->setEnabled(false);
1288 myGeomGroupLine->setText( "" );
1289 myGeomObjects = new GEOM::ListOfGO();
1290 myGeomObjects->length(0);
1292 if (myGeomGroupBtn->isChecked())
1293 myGeomGroupBtn->setChecked(false);
1295 myName->setText( "" );
1297 myElements->clear();
1300 myGroup = SMESH::SMESH_Group::_nil();
1301 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1302 restoreShowEntityMode();
1303 myMesh = SMESH::SMESH_Mesh::_nil();
1309 Handle(SALOME_InteractiveObject) IO = aList.First();
1312 restoreShowEntityMode();
1313 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1314 setShowEntityMode();
1316 if (myMesh->_is_nil())
1323 if ( myFilterDlg && !myMesh->_is_nil()){
1324 myFilterDlg->SetMesh( myMesh );
1326 myGroup = SMESH::SMESH_Group::_nil();
1328 // NPAL19389: create a group with a selection in another group
1329 // set actor of myMesh, if it is visible, else try
1330 // any visible actor of group or submesh of myMesh
1331 SetAppropriateActor();
1333 setDefaultGroupColor();
1334 if (myName->text().isEmpty())
1337 aString = aList.First()->getName();
1338 myMeshGroupLine->setText(aString);
1339 myMeshGroupLine->home( false );
1341 mySelectSubMesh->setEnabled(true);
1342 mySelectGroup->setEnabled(true);
1343 myGeomGroupBtn->setEnabled(true);
1344 myGeomGroupLine->setEnabled(true);
1348 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1349 if (aGroup->_is_nil())
1356 myGroup = SMESH::SMESH_Group::_nil();
1357 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1361 mySelectSubMesh->setEnabled(true);
1362 mySelectGroup->setEnabled(true);
1364 myCurrentLineEdit = 0;
1369 if (myGrpTypeId == 0)
1375 myElements->clear();
1376 setSelectionMode(myTypeId);
1384 else if (myCurrentLineEdit == myGeomGroupLine)
1386 myGeomObjects = new GEOM::ListOfGO();
1389 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1391 if (aNbSel == 0 || !aMeshSO)
1393 myGeomObjects->length(0);
1399 myGeomObjects->length(aNbSel);
1401 GEOM::GEOM_Object_var aGeomGroup;
1404 SALOME_ListIteratorOfListIO anIt (aList);
1405 for (; anIt.More(); anIt.Next())
1407 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1409 // Check if the object is a geometry group
1410 if (CORBA::is_nil(aGeomGroup))
1413 // Check if group constructed on the same shape as a mesh or on its child
1414 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1416 // The main shape of the group
1417 GEOM::GEOM_Object_var aGroupMainShape;
1418 if (aGeomGroup->GetType() == 37) {
1419 GEOM::GEOM_IGroupOperations_wrap anOp =
1420 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1421 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1422 // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
1425 aGroupMainShape = aGeomGroup;
1426 aGroupMainShape->Register();
1428 _PTR(SObject) aGroupMainShapeSO =
1429 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1431 _PTR(SObject) anObj, aRef;
1432 bool isRefOrSubShape = false;
1433 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1434 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1435 isRefOrSubShape = true;
1437 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1438 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1439 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1440 if (aRef->GetID() == aFather->GetID())
1441 isRefOrSubShape = true;
1443 aFather = aFather->GetFather();
1447 if (isRefOrSubShape)
1448 myGeomObjects[i++] = aGeomGroup;
1451 myGeomObjects->length(i);
1463 if (myCurrentLineEdit == mySubMeshLine)
1464 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1465 else if (myCurrentLineEdit == myGroupLine)
1466 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1467 else if (myCurrentLineEdit == myGeomGroupLine)
1468 aString = tr( "%1 Objects" ).arg(aNbSel);
1471 aString = aList.First()->getName();
1475 myCurrentLineEdit->setText(aString);
1476 myCurrentLineEdit->home(false);
1477 // 07.06.2008 skl for IPAL19574:
1478 // change name of group only if it is empty
1479 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1480 myOldName = myName->text();
1481 myName->blockSignals(true);
1482 myName->setText(aString);
1483 myName->blockSignals(false);
1488 else // !myCurrentLineEdit: local selection of nodes or elements
1490 if (aNbSel == 1 && myActorsList.count() > 0 )
1492 // NPAL19389: create a group with a selection in another group
1493 // Switch myActor to the newly selected one, if the last
1494 // is visible and belongs to group or submesh of myMesh
1495 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1496 Handle(SALOME_InteractiveObject) selIO = aList.First();
1497 if (curIO->hasEntry() && selIO->hasEntry()) {
1498 const char* selEntry = selIO->getEntry();
1499 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1500 // different objects: selected and myActor
1501 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1502 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1503 // newly selected actor is visible
1506 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1508 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1509 int len = strlen(meshEntry);
1511 if (strncmp(selEntry, meshEntry, len) == 0) {
1512 // selected object is myMesh or a part of it
1513 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1516 SMESH::SetPickable(myActor);
1525 QString aListStr = "";
1527 if (myTypeId == 0) {
1528 QListIterator<SMESH_Actor*> it( myActorsList );
1529 while ( it.hasNext() ) {
1531 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1535 QListIterator<SMESH_Actor*> it( myActorsList );
1536 while ( it.hasNext() ) {
1538 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1543 QListWidgetItem* anItem;
1544 QList<QListWidgetItem*> listItemsToSel;
1545 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1546 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1547 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1548 foreach(anItem, found)
1549 if (!anItem->isSelected())
1550 listItemsToSel.push_back(anItem);
1552 bool blocked = myElements->signalsBlocked();
1553 myElements->blockSignals(true);
1554 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1555 myElements->blockSignals(blocked);
1556 onListSelectionChanged();
1557 listItemsToSel.clear();
1562 if (myActorsList.count() == 0) {
1563 if (!myGroup->_is_nil()) {
1564 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1566 myActorsList.append( anActor );
1568 else if(!myGroupOnGeom->_is_nil()) {
1569 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1571 myActorsList.append( anActor );
1574 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1576 myActorsList.append( anActor );
1580 // somehow, if we display the mesh, while selecting from another actor,
1581 // the mesh becomes pickable, and there is no way to select any element
1582 if (myActorsList.count() > 0) {
1583 QListIterator<SMESH_Actor*> it( myActorsList );
1584 while ( it.hasNext() ) {
1585 SMESH_Actor* anActor = it.next();
1586 if ( IsActorVisible(anActor) )
1587 anActor->SetPickable(true);
1594 //=================================================================================
1595 // function : onSelectAll()
1596 // purpose : Called when "Select all" is checked
1597 //=================================================================================
1598 void SMESHGUI_GroupDlg::onSelectAll()
1600 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1602 myElementsLab->setEnabled( !noElemsModif );
1603 myElements->setEnabled ( !noElemsModif );
1604 myFilterBtn->setEnabled ( !noElemsModif );
1605 myAddBtn->setEnabled ( !noElemsModif );
1606 myRemoveBtn->setEnabled ( !noElemsModif );
1607 mySortBtn->setEnabled ( !noElemsModif );
1608 mySelectBox->setEnabled ( !noElemsModif );
1609 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1611 int selMode = mySelectionMode;
1612 mySelectionMode = grpNoSelection;
1613 setSelectionMode( selMode );
1617 //=================================================================================
1618 // function : onSelectSubMesh()
1619 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1620 //=================================================================================
1621 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1624 if (mySelectGroup->isChecked()) {
1625 mySelectGroup->setChecked(false);
1627 //VSR: else if (mySelectGeomGroup->isChecked()) {
1628 //VSR: mySelectGeomGroup->setChecked(false);
1630 myCurrentLineEdit = mySubMeshLine;
1631 setSelectionMode(grpSubMeshSelection);
1634 mySubMeshLine->setText( "" );
1635 myCurrentLineEdit = 0;
1637 setSelectionMode(myTypeId);
1639 mySubMeshBtn->setEnabled(on);
1640 mySubMeshLine->setEnabled(on);
1644 //=================================================================================
1645 // function : (onSelectGroup)
1646 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1647 //=================================================================================
1648 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1651 if (mySelectSubMesh->isChecked()) {
1652 mySelectSubMesh->setChecked(false);
1654 myCurrentLineEdit = myGroupLine;
1655 setSelectionMode(grpGroupSelection);
1658 myGroupLine->setText( "" );
1659 myCurrentLineEdit = 0;
1661 setSelectionMode(myTypeId);
1663 myGroupBtn->setEnabled(on);
1664 myGroupLine->setEnabled(on);
1668 //=================================================================================
1669 // function : (onSelectGeomGroup)
1670 // purpose : Called when group type changed. on == "on geometry" or "on filter"
1671 //=================================================================================
1672 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1675 if (mySelectSubMesh->isChecked()) {
1676 mySelectSubMesh->setChecked(false);
1678 else if (mySelectGroup->isChecked()) {
1679 mySelectGroup->setChecked(false);
1681 if ( myGrpTypeId == 1 ) { // on geometry
1682 myCurrentLineEdit = myGeomGroupLine;
1686 myCurrentLineEdit = 0;
1688 setSelectionMode(grpAllSelection);
1691 myGeomGroupBtn->setChecked(false);
1692 myGeomObjects->length(0);
1693 myGeomGroupLine->setText( "" );
1694 myCurrentLineEdit = 0;
1696 setSelectionMode( myTypeId );
1700 //=================================================================================
1701 // function : setCurrentSelection()
1703 //=================================================================================
1704 void SMESHGUI_GroupDlg::setCurrentSelection()
1706 QPushButton* send = (QPushButton*)sender();
1707 myCurrentLineEdit = 0;
1708 if (send == myMeshGroupBtn) {
1709 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1710 mySelectionMgr->clearSelected();
1712 setSelectionMode(grpMeshSelection);
1714 setSelectionMode(grpGroupSelection);
1715 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1716 myCurrentLineEdit = myMeshGroupLine;
1717 onObjectSelectionChanged();
1719 else if (send == mySubMeshBtn) {
1720 myCurrentLineEdit = mySubMeshLine;
1721 onObjectSelectionChanged();
1723 else if (send == myGroupBtn) {
1724 myCurrentLineEdit = myGroupLine;
1725 onObjectSelectionChanged();
1730 //=================================================================================
1731 // function : setFilters()
1732 // purpose : SLOT. Called when "Filter" button pressed.
1733 //=================================================================================
1734 void SMESHGUI_GroupDlg::setFilters()
1736 if(myMesh->_is_nil()) {
1737 SUIT_MessageBox::critical(this,
1739 tr("NO_MESH_SELECTED"));
1743 SMESH::ElementType aType = SMESH::ALL;
1746 case grpNodeSelection: aType = SMESH::NODE; break;
1747 case grp0DSelection: aType = SMESH::ELEM0D; break;
1748 case grpBallSelection: aType = SMESH::BALL; break;
1749 case grpEdgeSelection: aType = SMESH::EDGE; break;
1750 case grpFaceSelection: aType = SMESH::FACE; break;
1751 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1755 if ( myFilterDlg == 0 )
1757 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1758 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1761 myFilterDlg->Init( aType );
1763 if ( !myGroupOnFilter->_is_nil() )
1765 myFilterDlg->SetFilter( myFilter, aType );
1766 myFilterDlg->Init( aType );
1769 bool isStandalone = ( sender() == myFilterBtn );
1770 myFilterDlg->SetEnabled( /*setInViewer=*/isStandalone,
1771 /*diffSources=*/isStandalone );
1772 myFilterDlg->SetMesh( myMesh );
1773 myFilterDlg->SetGroup( myGroupOnFilter );
1774 myFilterDlg->SetSelection();
1775 myFilterDlg->SetSourceWg( myElements, false );
1777 myFilterDlg->show();
1780 //=================================================================================
1781 // function : onFilterAccepted()
1782 // purpose : SLOT. Called when Filter dlg closed with OK button.
1783 // Uncheck "Select submesh" and "Select group" checkboxes
1784 //=================================================================================
1785 void SMESHGUI_GroupDlg::onFilterAccepted()
1787 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1789 mySelectionMode = myTypeId;
1790 mySelectSubMesh->setChecked( false );
1791 mySelectGroup->setChecked( false );
1793 // get a filter from myFilterDlg
1794 myFilter = myFilterDlg->GetFilter();
1795 if ( !myFilter->_is_nil() ) {
1796 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1797 if ( perdicate->_is_nil() )
1798 myFilter = SMESH::Filter::_nil();
1800 // set mesh to myFilter
1801 if ( !myFilter->_is_nil() ) {
1802 SMESH::SMESH_Mesh_var mesh = myMesh;
1803 if ( mesh->_is_nil() ) {
1804 if ( !myGroup->_is_nil() )
1805 mesh = myGroup->GetMesh();
1806 else if ( !myGroupOnGeom->_is_nil() )
1807 mesh = myGroupOnGeom->GetMesh();
1808 else if ( !myGroupOnFilter->_is_nil() )
1809 mesh = myGroupOnFilter->GetMesh();
1811 myFilter->SetMesh( mesh );
1817 //=================================================================================
1818 // function : onAdd()
1820 //=================================================================================
1821 void SMESHGUI_GroupDlg::onAdd()
1823 SALOME_ListIO aList;
1824 mySelectionMgr->selectedObjects( aList );
1826 int aNbSel = aList.Extent();
1828 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1831 int sizeBefore = myElements->count();
1833 SMESH::ElementType aType = SMESH::ALL;
1835 case grpNodeSelection:
1836 aType = SMESH::NODE;
1837 mySelector->SetSelectionMode(NodeSelection);
1839 case grpBallSelection:
1840 aType = SMESH::BALL;
1841 mySelector->SetSelectionMode(BallSelection);
1843 case grp0DSelection:
1844 aType = SMESH::ELEM0D;
1845 mySelector->SetSelectionMode(Elem0DSelection);
1847 case grpEdgeSelection:
1848 aType = SMESH::EDGE;
1849 mySelector->SetSelectionMode(EdgeSelection);
1851 case grpFaceSelection:
1852 aType = SMESH::FACE;
1853 mySelector->SetSelectionMode(FaceSelection);
1855 case grpVolumeSelection:
1856 aType = SMESH::VOLUME;
1857 mySelector->SetSelectionMode(VolumeSelection);
1860 mySelector->SetSelectionMode(ActorSelection);
1863 QListWidgetItem* anItem = 0;
1864 QList<QListWidgetItem*> listItemsToSel;
1866 if (myCurrentLineEdit == 0) {
1867 //if (aNbSel != 1) { myIsBusy = false; return; }
1868 QString aListStr = "";
1870 if (myTypeId == 0) {
1871 QListIterator<SMESH_Actor*> it( myActorsList );
1872 while ( it.hasNext() ) {
1874 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1879 QListIterator<SMESH_Actor*> it( myActorsList );
1880 while ( it.hasNext() ) {
1882 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1887 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1888 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1889 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1890 if (found.count() == 0) {
1891 anItem = new QListWidgetItem(*it);
1892 myElements->addItem(anItem);
1893 if (!anItem->isSelected())
1894 listItemsToSel.push_back(anItem);
1897 foreach(anItem, found)
1898 if (!anItem->isSelected())
1899 listItemsToSel.push_back(anItem);
1902 bool blocked = myElements->signalsBlocked();
1903 myElements->blockSignals(true);
1904 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1905 myElements->blockSignals(blocked);
1906 onListSelectionChanged();
1907 listItemsToSel.clear();
1909 } else if (myCurrentLineEdit == mySubMeshLine) {
1910 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1912 SALOME_ListIO aList;
1913 mySelectionMgr->selectedObjects( aList );
1915 SALOME_ListIteratorOfListIO anIt (aList);
1916 for ( ; anIt.More(); anIt.Next()) {
1917 SMESH::SMESH_subMesh_var aSubMesh =
1918 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1919 if (!aSubMesh->_is_nil()) {
1920 // check if mesh is the same
1921 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1923 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1924 int k = anElements->length();
1925 for (int i = 0; i < k; i++) {
1926 QString aText = QString::number(anElements[i]);
1927 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1928 if (found.count() == 0) {
1929 anItem = new QListWidgetItem(aText);
1930 myElements->addItem(anItem);
1931 if (!anItem->isSelected())
1932 listItemsToSel.push_back(anItem);
1935 foreach(anItem, found)
1936 if (!anItem->isSelected())
1937 listItemsToSel.push_back(anItem);
1940 bool blocked = myElements->signalsBlocked();
1941 myElements->blockSignals(true);
1942 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1943 myElements->blockSignals(blocked);
1944 onListSelectionChanged();
1945 listItemsToSel.clear();
1947 catch (const SALOME::SALOME_Exception& ex) {
1948 SalomeApp_Tools::QtCatchCorbaException(ex);
1953 mySelectSubMesh->setChecked(false);
1955 onListSelectionChanged();
1957 } else if (myCurrentLineEdit == myGroupLine) {
1958 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1959 SALOME_ListIO aList;
1960 mySelectionMgr->selectedObjects( aList );
1962 SALOME_ListIteratorOfListIO anIt (aList);
1963 for ( ; anIt.More(); anIt.Next()) {
1964 SMESH::SMESH_GroupBase_var aGroup =
1965 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1966 if (!aGroup->_is_nil()) {
1967 // check if mesh is the same
1968 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1969 SMESH::long_array_var anElements = aGroup->GetListOfID();
1970 int k = anElements->length();
1971 for (int i = 0; i < k; i++) {
1972 QString aText = QString::number(anElements[i]);
1973 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1974 if (found.count() == 0) {
1975 anItem = new QListWidgetItem(aText);
1976 myElements->addItem(anItem);
1977 if (!anItem->isSelected())
1978 listItemsToSel.push_back(anItem);
1981 foreach(anItem, found)
1982 if (!anItem->isSelected())
1983 listItemsToSel.push_back(anItem);
1986 bool blocked = myElements->signalsBlocked();
1987 myElements->blockSignals(true);
1988 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1989 myElements->blockSignals(blocked);
1990 onListSelectionChanged();
1991 listItemsToSel.clear();
1995 mySelectGroup->setChecked(false);
1997 onListSelectionChanged();
1999 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
2000 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2001 GEOM::GEOM_IGroupOperations_wrap aGroupOp =
2002 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
2004 SMESH::ElementType aGroupType = SMESH::ALL;
2005 switch(aGroupOp->GetType(myGeomObjects[0])) {
2006 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
2007 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
2008 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
2009 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
2010 default: myIsBusy = false; return;
2013 if (aGroupType == aType) {
2014 _PTR(SObject) aGroupSO =
2015 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
2016 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
2018 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2019 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
2020 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
2021 aBelongToGeom->SetGeom(myGeomObjects[0]);
2022 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
2023 aBelongToGeom->SetElementType(aType);
2024 aFilter->SetPredicate(aBelongToGeom);
2026 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
2028 int k = anElements->length();
2029 for (int i = 0; i < k; i++) {
2030 QString aText = QString::number(anElements[i]);
2031 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2032 if (found.count() == 0) {
2033 anItem = new QListWidgetItem(aText);
2034 myElements->addItem(anItem);
2035 if (!anItem->isSelected())
2036 listItemsToSel.push_back(anItem);
2039 foreach(anItem, found)
2040 if (!anItem->isSelected())
2041 listItemsToSel.push_back(anItem);
2044 bool blocked = myElements->signalsBlocked();
2045 myElements->blockSignals(true);
2046 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2047 myElements->blockSignals(blocked);
2048 onListSelectionChanged();
2049 listItemsToSel.clear();
2052 //VSR: mySelectGeomGroup->setChecked(false);
2054 onListSelectionChanged();
2057 if ( sizeBefore < myElements->count() )
2058 ++myNbChangesOfContents;
2059 // mySelectionMgr->clearSelected();
2063 //=================================================================================
2064 // function : onRemove()
2066 //=================================================================================
2067 void SMESHGUI_GroupDlg::onRemove()
2070 int sizeBefore = myElements->count();
2072 if (myCurrentLineEdit == 0) {
2073 QList<QListWidgetItem*> selItems = myElements->selectedItems();
2074 QListWidgetItem* item;
2075 foreach(item, selItems) delete item;
2077 SALOME_ListIO aList;
2078 mySelectionMgr->selectedObjects( aList );
2080 int aNbSel = aList.Extent();
2082 if (aNbSel == 0) { myIsBusy = false; return; }
2084 SMESH::ElementType aType = SMESH::ALL;
2086 case grpNodeSelection: aType = SMESH::NODE; break;
2087 case grp0DSelection: aType = SMESH::ELEM0D; break;
2088 case grpBallSelection: aType = SMESH::BALL; break;
2089 case grpEdgeSelection: aType = SMESH::EDGE; break;
2090 case grpFaceSelection: aType = SMESH::FACE; break;
2091 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2094 if (myCurrentLineEdit == mySubMeshLine) {
2095 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2096 SALOME_ListIO aList;
2097 mySelectionMgr->selectedObjects( aList );
2099 SALOME_ListIteratorOfListIO anIt (aList);
2100 for ( ; anIt.More(); anIt.Next()) {
2101 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2102 if (!aSubMesh->_is_nil()) {
2103 // check if mesh is the same
2104 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2105 if (aType == SMESH::NODE) {
2107 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2108 int k = anElements->length();
2109 for (int i = 0; i < k; i++) {
2110 QList<QListWidgetItem*> found =
2111 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2112 QListWidgetItem* anItem;
2113 foreach(anItem, found) delete anItem;
2116 catch (const SALOME::SALOME_Exception& ex) {
2117 SalomeApp_Tools::QtCatchCorbaException(ex);
2122 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2123 int k = anElements->length();
2124 for (int i = 0; i < k; i++) {
2125 QList<QListWidgetItem*> found =
2126 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2127 QListWidgetItem* anItem;
2128 foreach(anItem, found) delete anItem;
2131 catch (const SALOME::SALOME_Exception& ex) {
2132 SalomeApp_Tools::QtCatchCorbaException(ex);
2139 else if (myCurrentLineEdit == myGroupLine) {
2140 Standard_Boolean aRes;
2141 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2142 SALOME_ListIO aList;
2143 mySelectionMgr->selectedObjects( aList );
2145 SALOME_ListIteratorOfListIO anIt (aList);
2146 for ( ; anIt.More(); anIt.Next()) {
2147 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2148 if (aRes && !aGroup->_is_nil()) {
2149 // check if mesh is the same
2150 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2151 SMESH::long_array_var anElements = aGroup->GetListOfID();
2152 int k = anElements->length();
2153 for (int i = 0; i < k; i++) {
2154 QList<QListWidgetItem*> found =
2155 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2156 QListWidgetItem* anItem;
2157 foreach(anItem, found) delete anItem;
2165 if ( sizeBefore > myElements->count() )
2166 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2170 //=================================================================================
2171 // function : onSort()
2173 //=================================================================================
2174 void SMESHGUI_GroupDlg::onSort()
2176 // PAL5412: sorts items in ascending by "string" value
2177 // myElements->sort(true);
2178 // myElements->update();
2179 int i, k = myElements->count();
2182 QList<int> aSelected;
2183 std::vector<int> anArray(k);
2184 // QMemArray<int> anArray(k);
2186 for (i = 0; i < k; i++) {
2187 int id = myElements->item(i)->text().toInt();
2189 if (myElements->item(i)->isSelected())
2190 aSelected.append(id);
2192 // sort & update list
2193 std::sort(anArray.begin(), anArray.end());
2195 myElements->clear();
2196 QListWidgetItem* anItem;
2197 QList<QListWidgetItem*> listItemsToSel;
2198 for (i = 0; i < k; i++) {
2199 anItem = new QListWidgetItem(QString::number(anArray[i]));
2200 myElements->addItem(anItem);
2201 if (aSelected.contains(anArray[i]))
2202 listItemsToSel.push_back(anItem);
2204 bool blocked = myElements->signalsBlocked();
2205 myElements->blockSignals(true);
2206 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2207 myElements->blockSignals(blocked);
2208 listItemsToSel.clear();
2213 //=================================================================================
2214 // function : onVisibilityChanged()
2216 //=================================================================================
2217 void SMESHGUI_GroupDlg::onVisibilityChanged()
2219 SetAppropriateActor();
2222 //=================================================================================
2223 // function : SMESHGUI_GroupDlg::reject
2224 // purpose : SLOT called when "Close" button pressed. Close dialog
2225 //=================================================================================
2226 void SMESHGUI_GroupDlg::reject()
2228 if (SMESH::GetCurrentVtkView()) {
2229 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2230 SMESH::SetPointRepresentation(false);
2231 SMESH::SetPickable();
2232 restoreShowEntityMode();
2235 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2236 SUIT_DataOwnerPtrList aList;
2237 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2238 mySelectionMgr->setSelected( aList );
2241 mySelectionMgr->clearSelected();
2242 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2243 aViewWindow->SetSelectionMode(ActorSelection);
2244 mySelectionMgr->clearFilters();
2245 mySMESHGUI->ResetState();
2249 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
2252 //=================================================================================
2253 // function : onOpenView()
2255 //=================================================================================
2256 void SMESHGUI_GroupDlg::onOpenView()
2259 SMESH::SetPointRepresentation(false);
2262 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
2263 mySMESHGUI->EmitSignalDeactivateDialog();
2268 //=================================================================================
2269 // function : onCloseView()
2271 //=================================================================================
2272 void SMESHGUI_GroupDlg::onCloseView()
2278 //=================================================================================
2279 // function : onHelp()
2281 //=================================================================================
2282 void SMESHGUI_GroupDlg::onHelp()
2284 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2286 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2290 platform = "winapplication";
2292 platform = "application";
2294 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2295 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2296 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2298 arg(myHelpFileName));
2302 //=================================================================================
2303 // function : SMESHGUI_GroupDlg::onDeactivate
2304 // purpose : SLOT called when dialog must be deativated
2305 //=================================================================================
2306 void SMESHGUI_GroupDlg::onDeactivate()
2308 mySMESHGUI->ResetState();
2312 //=================================================================================
2313 // function : SMESHGUI_GroupDlg::enterEvent
2314 // purpose : Event filter
2315 //=================================================================================
2316 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2319 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
2320 if ( aViewWindow && !mySelector) {
2321 mySelector = aViewWindow->GetSelector();
2323 mySMESHGUI->EmitSignalDeactivateDialog();
2325 mySelectionMode = grpNoSelection;
2326 setSelectionMode(myTypeId);
2327 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2328 mySMESHGUI->SetActiveDialogBox(this);
2329 mySMESHGUI->SetState(800);
2333 //=================================================================================
2334 // function : keyPressEvent()
2336 //=================================================================================
2337 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2339 QDialog::keyPressEvent( e );
2340 if ( e->isAccepted() )
2343 if ( e->key() == Qt::Key_F1 )
2350 //================================================================================
2352 * \brief Enable showing of the popup when Geometry selection btn is clicked
2353 * \param enable - true to enable
2355 //================================================================================
2357 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2359 void SMESHGUI_GroupDlg::updateGeomPopup()
2361 bool enable = false;
2363 if ( !myMesh->_is_nil() )
2364 enable = myMesh->NbEdges() > 0;
2366 if ( myGeomGroupBtn )
2368 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2370 if ( !myGeomPopup ) {
2371 myGeomPopup = new QMenu(this);
2372 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2373 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2374 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2376 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2382 //=================================================================================
2383 // function : onGeomSelectionButton()
2385 //=================================================================================
2386 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2388 if ( myGeomPopup && isBtnOn )
2390 myCurrentLineEdit = myGeomGroupLine;
2391 QAction* a = myGeomPopup->exec( QCursor::pos() );
2392 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2393 setSelectionMode(grpGeomSelection);
2397 myCurrentLineEdit = 0;
2398 setSelectionMode(grpAllSelection);
2402 //=================================================================================
2403 // function : onGeomPopup()
2405 //=================================================================================
2406 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2408 int index = myActions[a];
2409 if ( index == GEOM_BY_MESH_INDEX )
2411 mySelectionMode = grpNoSelection;
2412 if ( !myShapeByMeshOp ) {
2413 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2414 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2415 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2416 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2417 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2419 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2420 if ( !myMesh->_is_nil() ) {
2422 hide(); // stop processing selection
2424 myShapeByMeshOp->setModule( mySMESHGUI );
2425 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2426 myShapeByMeshOp->SetMesh( myMesh );
2427 myShapeByMeshOp->start();
2432 //================================================================================
2434 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2436 //================================================================================
2438 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2440 if ( myShapeByMeshOp == op ) {
2441 mySMESHGUI->getApp()->updateObjectBrowser();
2443 // Select a found geometry object
2444 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2445 if ( !aGeomVar->_is_nil() )
2447 QString ID = aGeomVar->GetStudyEntry();
2448 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2449 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2450 SALOME_ListIO anIOList;
2451 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2452 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2453 anIOList.Append( anIO );
2454 mySelectionMgr->setSelectedObjects( anIOList, false );
2455 onObjectSelectionChanged();
2461 //================================================================================
2463 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2465 //================================================================================
2467 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2469 if ( myShapeByMeshOp == op )
2472 setSelectionMode(grpGeomSelection);
2476 //=================================================================================
2477 // function : setGroupColor()
2479 //=================================================================================
2480 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2482 QColor aQColor( (int)( theColor.R * 255.0 ),
2483 (int)( theColor.G * 255.0 ),
2484 (int)( theColor.B * 255.0 ) );
2485 setGroupQColor( aQColor );
2488 //=================================================================================
2489 // function : getGroupColor()
2491 //=================================================================================
2492 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2494 QColor aQColor = getGroupQColor();
2496 SALOMEDS::Color aColor;
2497 aColor.R = (float)aQColor.red() / 255.0;
2498 aColor.G = (float)aQColor.green() / 255.0;
2499 aColor.B = (float)aQColor.blue() / 255.0;
2504 //=================================================================================
2505 // function : setGroupQColor()
2507 //=================================================================================
2508 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2510 if( theColor.isValid() )
2511 myColorBtn->setColor( theColor );
2514 //=================================================================================
2515 // function : getGroupQColor()
2517 //=================================================================================
2518 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2520 return myColorBtn->color();
2523 //=================================================================================
2524 // function : setDefaultGroupColor()
2526 //=================================================================================
2527 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2529 if( myMesh->_is_nil() )
2532 bool isAutoColor = myMesh->GetAutoColor();
2534 QColor aQColor = myColorBtn->color();
2537 if ( !aQColor.isValid() ) {
2538 int r = 0, g = 0, b = 0;
2539 SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2540 aQColor.setRgb( r, g, b );
2545 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2546 SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
2547 #else // old algorithm for auto-colors
2548 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2550 QList<SALOMEDS::Color> aReservedColors;
2551 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2553 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2554 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2555 aReservedColors.append( aReservedColor );
2558 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2559 #endif // SIMPLE_AUTOCOLOR
2561 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2562 (int)( aColor.G * 255.0 ),
2563 (int)( aColor.B * 255.0 ) );
2567 setGroupQColor( aQColor );
2570 //=================================================================================
2571 // function : SetAppropriateActor()
2572 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2573 // NPAL19389: create a group with a selection in another group.
2574 // if mesh actor is not visible - find any first visible group or submesh
2575 //=================================================================================
2576 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2578 bool isActor = false;
2579 myActorsList.clear();
2581 if (myMesh->_is_nil()) return false;
2583 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2585 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2587 if (!myGroupOnGeom->_is_nil()) {
2588 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2589 if (anActor && anActor->hasIO())
2592 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2595 myActorsList.append(anActor);
2601 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2602 if (anActor && anActor->hasIO()) {
2604 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2607 myActorsList.append(anActor);
2611 if (!isActor && !myGroup->_is_nil()) {
2612 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2613 if (anActor && anActor->hasIO())
2614 myActorsList.append(anActor);
2617 // try any visible actor of group or submesh of current mesh
2620 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2622 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2623 int len = strlen(meshEntry);
2625 // iterate on all actors in current view window, search for
2626 // any visible actor, that belongs to group or submesh of current mesh
2627 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2628 vtkActorCollection *aCollection = aCopy.GetActors();
2629 int nbItems = aCollection->GetNumberOfItems();
2630 for (int i=0; i<nbItems && !isActor; i++)
2632 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2633 if (anActor && anActor->hasIO()) {
2634 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2635 if (aViewWindow->isVisible(anIO)) {
2636 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2637 myActorsList.append(anActor);
2645 if (myActorsList.count() > 0) {
2646 QListIterator<SMESH_Actor*> it( myActorsList );
2647 while ( it.hasNext() ) {
2648 SMESH_Actor* anActor = it.next();
2649 if ( IsActorVisible(anActor) )
2650 anActor->SetPickable(true);
2654 return ( isActor || (myActorsList.count() > 0) );
2657 //=======================================================================
2658 //function : setShowEntityMode
2659 //purpose : make shown only entity corresponding to my type
2660 //=======================================================================
2661 void SMESHGUI_GroupDlg::setShowEntityMode()
2663 if ( !myMesh->_is_nil() ) {
2664 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2665 if (!myStoredShownEntity)
2666 myStoredShownEntity = actor->GetEntityMode();
2667 switch ( myTypeId ) {
2668 case grpNodeSelection: restoreShowEntityMode(); break;
2669 case grp0DSelection: actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
2670 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2671 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2672 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2673 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2679 //=======================================================================
2680 //function : restoreShowEntityMode
2681 //purpose : restore ShowEntity mode of myActor
2682 //=======================================================================
2683 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2685 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2686 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2687 actor->SetEntityMode(myStoredShownEntity);
2690 myStoredShownEntity = 0;
2693 //=======================================================================
2694 //function : IsActorVisible
2695 //purpose : return visibility of the actor
2696 //=======================================================================
2697 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2699 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2700 if (theActor && aViewWindow)
2701 return aViewWindow->isVisible(theActor->getIO());
2705 //================================================================
2706 //function : setIsApplyAndClose
2707 //purpose : Set value of the flag indicating that the dialog is
2708 // accepted by Apply & Close button
2709 //================================================================
2710 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2712 myIsApplyAndClose = theFlag;
2715 //================================================================
2716 //function : isApplyAndClose
2717 //purpose : Get value of the flag indicating that the dialog is
2718 // accepted by Apply & Close button
2719 //================================================================
2720 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2722 return myIsApplyAndClose;