1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_GroupDlg.cxx
25 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
28 #include "SMESHGUI_GroupDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_GroupUtils.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
36 #include "SMESHGUI_FilterDlg.h"
37 #include "SMESHGUI_ShapeByMeshDlg.h"
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_Actor.h>
41 #include <SMESH_ActorUtils.h>
42 #include <SMESH_LogicalFilter.hxx>
44 // SALOME GEOM includes
46 #include <GEOM_SelectionFilter.h>
48 // SALOME GUI includes
49 #include <QtxColorButton.h>
51 #include <SUIT_Desktop.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SUIT_Session.h>
54 #include <SUIT_MessageBox.h>
56 #include <SalomeApp_Tools.h>
57 #include <SalomeApp_Application.h>
58 #include <SalomeApp_Study.h>
59 #include <LightApp_SelectionMgr.h>
61 #include <SALOME_ListIO.hxx>
62 #include <SALOME_ListIteratorOfListIO.hxx>
64 #include <SVTK_ViewWindow.h>
66 #include <VTKViewer_Algorithm.h>
68 // SALOME KERNEL includes
69 #include <SALOMEDSClient_Study.hxx>
72 #include <vtkRenderer.h>
73 #include <vtkActorCollection.h>
76 #include <TColStd_MapOfInteger.hxx>
79 #include <QButtonGroup>
83 #include <QPushButton>
84 #include <QToolButton>
85 #include <QRadioButton>
87 #include <QGridLayout>
88 #include <QHBoxLayout>
89 #include <QVBoxLayout>
90 #include <QListWidget>
91 #include <QStackedWidget>
103 enum grpSelectionMode {
105 grpNodeSelection = 0,
106 grpBallSelection = 1,
107 grpEdgeSelection = 2,
108 grpFaceSelection = 3,
109 grpVolumeSelection = 4,
110 grpSubMeshSelection = 5,
111 grpGroupSelection = 6,
112 grpMeshSelection = 7,
113 grpGeomSelection = 8,
117 //=================================================================================
118 // function : SMESHGUI_GroupDlg()
120 //=================================================================================
121 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
122 SMESH::SMESH_Mesh_ptr theMesh )
123 : QDialog( SMESH::GetDesktop( theModule ) ),
124 mySMESHGUI( theModule ),
125 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
126 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
128 myNameChanged( false ),
129 myIsApplyAndClose( false ),
130 myNbChangesOfContents(0)
133 if ( !theMesh->_is_nil() )
137 mySelectSubMesh->setEnabled( false );
138 mySelectGroup->setEnabled( false );
139 myGeomGroupBtn->setEnabled( false );
140 myGeomGroupLine->setEnabled( false );
144 //=================================================================================
145 // function : SMESHGUI_GroupDlg()
147 //=================================================================================
148 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
149 SMESH::SMESH_GroupBase_ptr theGroup,
150 const bool theIsConvert )
151 : QDialog( SMESH::GetDesktop( theModule ) ),
152 mySMESHGUI( theModule ),
153 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
154 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
156 myNameChanged( false ),
157 myNbChangesOfContents(0) // just not to use uninitialized variable
160 if ( !theGroup->_is_nil() )
161 init( theGroup, theIsConvert );
164 mySelectSubMesh->setEnabled( false );
165 mySelectGroup->setEnabled( false );
167 myCurrentLineEdit = myMeshGroupLine;
168 setSelectionMode( grpGroupSelection );
172 //=================================================================================
173 // function : SMESHGUI_GroupDlg()
175 //=================================================================================
176 void SMESHGUI_GroupDlg::initDialog( bool create)
179 setAttribute( Qt::WA_DeleteOnClose, true );
183 myCurrentLineEdit = 0;
187 myGeomObjects = new GEOM::ListOfGO();
188 myGeomObjects->length( 0 );
190 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
192 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
193 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
195 setSizeGripEnabled( true);
197 QGridLayout* aMainLayout = new QGridLayout( this );
198 aMainLayout->setMargin( MARGIN );
199 aMainLayout->setSpacing( SPACING );
201 /***************************************************************/
202 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
203 myMeshGroupBtn = new QPushButton( this );
204 myMeshGroupBtn->setIcon( image0 );
205 myMeshGroupLine = new QLineEdit( this );
206 myMeshGroupLine->setReadOnly( true );
208 /***************************************************************/
209 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
210 myTypeGroup = new QButtonGroup( this );
211 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
212 aTypeBoxLayout->setMargin( MARGIN );
213 aTypeBoxLayout->setSpacing( SPACING );
216 types.append( tr( "MESH_NODE" ) );
217 types.append( tr( "SMESH_BALL_ELEM" ) );
218 types.append( tr( "SMESH_EDGE" ) );
219 types.append( tr( "SMESH_FACE" ) );
220 types.append( tr( "SMESH_VOLUME" ) );
222 for ( int i = 0; i < types.count(); i++ )
224 rb = new QRadioButton( types[i], aTypeBox );
225 myTypeGroup->addButton( rb, i );
226 aTypeBoxLayout->addWidget( rb );
228 aTypeBox->setEnabled( create );
231 /***************************************************************/
232 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
233 aName->setMinimumWidth( 50 );
234 myName = new QLineEdit( this );
236 /***************************************************************/
237 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
238 myGrpTypeGroup = new QButtonGroup( this );
239 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
240 aGrpTypeBoxLayout->setMargin( MARGIN );
241 aGrpTypeBoxLayout->setSpacing( SPACING );
243 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
244 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
245 QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox );
246 myGrpTypeGroup->addButton( rb1, 0 );
247 myGrpTypeGroup->addButton( rb2, 1 );
248 myGrpTypeGroup->addButton( rb3, 2 );
249 aGrpTypeBoxLayout->addWidget( rb1 );
250 aGrpTypeBoxLayout->addWidget( rb2 );
251 aGrpTypeBoxLayout->addWidget( rb3 );
252 aGrpTypeBox->setEnabled( create );
255 /***************************************************************/
256 myWGStack = new QStackedWidget( this );
257 QWidget* wg1 = new QWidget( myWGStack );
258 QWidget* wg2 = new QWidget( myWGStack );
259 QWidget* wg3 = new QWidget( myWGStack );
261 /***************************************************************/
262 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
263 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
264 aContentBoxLayout->setMargin( MARGIN );
265 aContentBoxLayout->setSpacing( SPACING );
267 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
268 myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
270 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
271 myElements = new QListWidget( aContentBox );
272 myElements->setSelectionMode( QListWidget::ExtendedSelection );
274 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
275 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
276 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
277 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
279 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
280 aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
281 aContentBoxLayout->addWidget( myFilterBtn, 1, 1 );
282 aContentBoxLayout->addWidget( myElementsLab, 2, 0 );
283 aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 );
284 aContentBoxLayout->addWidget( myAddBtn, 3, 1 );
285 aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 );
286 aContentBoxLayout->addWidget( mySortBtn, 8, 1 );
288 aContentBoxLayout->setColumnStretch( 0, 1 );
289 aContentBoxLayout->setRowStretch( 3, 1 );
290 aContentBoxLayout->setRowStretch( 6, 1 );
292 /***************************************************************/
293 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
294 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
295 mySelectBoxLayout->setMargin( MARGIN );
296 mySelectBoxLayout->setSpacing( SPACING );
298 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
299 mySubMeshBtn = new QPushButton( mySelectBox );
300 mySubMeshBtn->setIcon( image0 );
301 mySubMeshLine = new QLineEdit( mySelectBox );
302 mySubMeshLine->setReadOnly( true );
303 onSelectSubMesh( false );
305 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
306 myGroupBtn = new QPushButton( mySelectBox );
307 myGroupBtn->setIcon( image0 );
308 myGroupLine = new QLineEdit( mySelectBox );
309 myGroupLine->setReadOnly( true );
310 onSelectGroup( false );
312 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
313 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
314 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
315 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
316 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
317 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
319 /***************************************************************/
320 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
321 wg1Layout->setMargin( 0 );
322 wg1Layout->setSpacing( SPACING );
323 wg1Layout->addWidget( aContentBox );
324 wg1Layout->addWidget( mySelectBox );
325 wg1Layout->setStretchFactor( aContentBox, 10 );
327 /***************************************************************/
328 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
329 myGeomGroupBtn = new QToolButton( wg2 );
330 myGeomGroupBtn->setIcon( image0 );
331 myGeomGroupBtn->setCheckable( true );
332 myGeomGroupLine = new QLineEdit( wg2 );
333 myGeomGroupLine->setReadOnly( true ); //VSR ???
334 onSelectGeomGroup( false );
336 myGeomGroupBtn->setEnabled( create );
337 myGeomGroupLine->setEnabled( create );
339 /***************************************************************/
340 QGridLayout* wg2Layout = new QGridLayout( wg2 );
341 wg2Layout->setMargin( 0 );
342 wg2Layout->setSpacing( SPACING );
343 wg2Layout->addWidget( geomObject, 0, 0 );
344 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
345 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
346 wg2Layout->setRowStretch( 1, 5 );
348 /***************************************************************/
349 QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
350 QGridLayout* wg3Layout = new QGridLayout( wg3 );
351 wg3Layout->setMargin( 0 );
352 wg3Layout->setSpacing( SPACING );
353 wg3Layout->addWidget( aFilter2, 0, 0 );
354 wg3Layout->setRowStretch( 1, 5 );
356 /***************************************************************/
357 myWGStack->insertWidget( 0, wg1 );
358 myWGStack->insertWidget( 1, wg2 );
359 myWGStack->insertWidget( 2, wg3 );
361 /***************************************************************/
362 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
363 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
364 aColorBoxLayout->setMargin(MARGIN);
365 aColorBoxLayout->setSpacing(SPACING);
367 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
368 myColorBtn = new QtxColorButton(aColorBox);
369 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
370 myColorBtn->sizePolicy().verticalPolicy() );
372 aColorBoxLayout->addWidget(aColorLab);
373 aColorBoxLayout->addWidget(myColorBtn);
375 /***************************************************************/
377 QFrame* aButtons = new QFrame(this);
378 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
379 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
380 aBtnLayout->setMargin(MARGIN);
381 aBtnLayout->setSpacing(SPACING);
383 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
384 myOKBtn->setAutoDefault(true);
385 myOKBtn->setDefault(true);
386 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
387 myApplyBtn->setAutoDefault(true);
388 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
389 myCloseBtn->setAutoDefault(true);
390 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
391 myHelpBtn->setAutoDefault(true);
393 aBtnLayout->addWidget(myOKBtn);
394 aBtnLayout->addSpacing(10);
395 aBtnLayout->addWidget(myApplyBtn);
396 aBtnLayout->addSpacing(10);
397 aBtnLayout->addStretch();
398 aBtnLayout->addWidget(myCloseBtn);
399 aBtnLayout->addWidget(myHelpBtn);
401 /***************************************************************/
402 aMainLayout->addWidget(meshGroupLab, 0, 0);
403 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
404 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
405 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
406 aMainLayout->addWidget(aName, 2, 0);
407 aMainLayout->addWidget(myName, 2, 2);
408 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
409 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
410 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
411 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
413 /* signals and slots connections */
414 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
415 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
416 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
418 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
419 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
421 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
422 connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters()));
423 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
424 connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
425 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
426 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
427 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
429 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
430 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
431 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
432 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
433 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
435 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
437 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
438 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
439 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
440 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
443 mySMESHGUI->SetActiveDialogBox(this);
444 mySMESHGUI->SetState(800);
446 mySelectionMode = grpNoSelection;
447 myMeshFilter = new SMESH_TypeFilter(MESH);
448 mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
449 SMESH_LogicalFilter::LO_OR,
450 /*takeOwnership=*/true);
451 myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
452 SMESH_LogicalFilter::LO_OR,
453 /*takeOwnership=*/true);
454 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
455 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
457 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
458 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
459 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
460 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
462 rb1->setChecked(true); // VSR !!!
463 onGrpTypeChanged(0); // VSR!!!
465 if (myMesh->_is_nil() )
466 myTypeGroup->button(0)->setChecked(true);
468 onSelectAll(); //updateButtons();
471 //=================================================================================
472 // function : ~SMESHGUI_GroupDlg()
473 // purpose : Destroys the object and frees any allocated resources
474 //=================================================================================
475 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
477 // no need to delete child widgets, Qt does it all for us
478 if ( myFilterDlg != 0 ) {
479 myFilterDlg->setParent( 0 );
482 if ( myMeshFilter ) delete myMeshFilter;
483 if ( mySubMeshFilter ) delete mySubMeshFilter;
484 if ( myGroupFilter ) delete myGroupFilter;
485 if ( myGeomFilter ) delete myGeomFilter;
488 //=================================================================================
489 // function : GetDefaultName()
490 // purpose : Get the Group Name if Create new Group
491 //=================================================================================
492 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
496 // collect all object names of SMESH component
497 SalomeApp_Study* appStudy =
498 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
499 if ( !appStudy ) return aName;
500 _PTR(Study) aStudy = appStudy->studyDS();
502 std::set<std::string> aSet;
503 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
505 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
507 for (it->InitEx(true); it->More(); it->Next()) {
509 aSet.insert(obj->GetName());
513 // build a unique name
515 bool isUnique = false;
517 aName = theOperation + "_" + QString::number(++aNumber);
518 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
524 //=================================================================================
527 //=================================================================================
528 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
530 mySelectionMgr->installFilter(myMeshFilter);
532 /* init data from current selection */
533 restoreShowEntityMode();
534 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
536 myGroup = SMESH::SMESH_Group::_nil();
537 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
538 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
540 // NPAL19389: create a group with a selection in another group
541 // set actor of myMesh, if it is visible, else try
542 // any visible actor of group or submesh of myMesh
543 SetAppropriateActor();
545 setDefaultGroupColor();
548 mySelectionMgr->selectedObjects( aList );
549 if( !aList.IsEmpty() )
551 QString aName = aList.First()->getName();
552 myMeshGroupLine->setText(aName);
553 myMeshGroupLine->home( false );
556 myCurrentLineEdit = 0;
558 myTypeGroup->button(0)->setChecked(true);
562 //=================================================================================
565 //=================================================================================
566 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
567 const bool theIsConvert)
569 restoreShowEntityMode();
570 myMesh = theGroup->GetMesh();
573 myNameChanged = true;
574 myName->blockSignals(true);
575 myName->setText(theGroup->GetName());
576 myName->blockSignals(false);
579 SALOMEDS::Color aColor = theGroup->GetColor();
580 setGroupColor( aColor );
582 myMeshGroupLine->setText(theGroup->GetName());
585 switch(theGroup->GetType()) {
586 case SMESH::NODE: aType = 0; break;
587 case SMESH::BALL: aType = 1; break;
588 case SMESH::EDGE: aType = 2; break;
589 case SMESH::FACE: aType = 3; break;
590 case SMESH::VOLUME: aType = 4; break;
592 myTypeGroup->button(aType)->setChecked(true);
594 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
595 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
596 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
597 myFilter = SMESH::Filter::_nil();
599 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
602 // NPAL19389: create a group with a selection in another group
603 // set actor of myMesh, if it is visible, else set
604 // actor of theGroup, if it is visible, else try
605 // any visible actor of group or submesh of myMesh
606 // commented, because an attempt to set selection on not displayed cells leads to error
607 SetAppropriateActor();
609 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
611 anActor = SMESH::FindActorByObject(theGroup);
612 SMESH::SetPickable(anActor);*/
614 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
615 myGrpTypeGroup->button(grpType)->setChecked(true);
616 onGrpTypeChanged(grpType);
619 if ( grpType == 0 ) { // standalone group
620 myCurrentLineEdit = 0;
622 myAllowElemsModif->setChecked( true );
624 setSelectionMode(aType);
626 setShowEntityMode(); // depends on myTypeId
629 if (!theGroup->IsEmpty()) {
630 SMESH::long_array_var anElements = theGroup->GetListOfID();
631 int k = anElements->length();
632 for (int i = 0; i < k; i++) {
633 myIdList.append(anElements[i]);
634 myElements->addItem(QString::number(anElements[i]));
636 myElements->selectAll();
639 else if ( grpType == 1 ) // group on geom
641 QString aShapeName( "" );
642 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
643 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
644 if (!aGroupShape->_is_nil())
646 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
648 aShapeName = aGroupShapeSO->GetName().c_str();
650 myGeomGroupLine->setText( aShapeName );
652 else // group on filter
654 myFilter = myGroupOnFilter->GetFilter();
655 if ( !myFilter->_is_nil() ) {
656 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
657 if ( perdicate->_is_nil() )
658 myFilter = SMESH::Filter::_nil();
664 myNameChanged = true;
665 myName->blockSignals(true);
666 myName->setText(theGroup->GetName());
667 myName->blockSignals(false);
670 onSelectAll(); //updateButtons();
673 //=================================================================================
674 // function : updateButtons()
676 //=================================================================================
677 void SMESHGUI_GroupDlg::updateButtons()
679 bool enable = !myName->text().trimmed().isEmpty();
682 if (myGrpTypeId == 0) { // standalone
683 if ( !mySelectAll->isChecked() )
685 if ( myAllowElemsModif->isChecked() )
687 enable = ( myElements->count() > 0 );
689 else if ((enable = !myFilter->_is_nil() ))
691 SMESH::array_of_ElementType_var types = myFilter->GetTypes();
692 enable = types->length();
695 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
697 else if (myGrpTypeId == 1) // on geom
699 if (CORBA::is_nil(myGroupOnGeom)) // creation mode
700 enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
702 else if (myGrpTypeId == 2) // on filter
704 if (( enable = !myFilter->_is_nil() ))
705 if (CORBA::is_nil(myGroupOnFilter) ) // creation mode
706 enable = !myMesh->_is_nil();
710 myOKBtn->setEnabled(enable);
711 myApplyBtn->setEnabled(enable);
714 //=================================================================================
715 // function : onNameChanged()
717 //=================================================================================
718 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
720 myOldName = myName->text();
722 myNameChanged = !myName->text().trimmed().isEmpty();
725 //=================================================================================
726 // function : onTypeChanged()
727 // purpose : Group elements type radio button management
728 //=================================================================================
729 void SMESHGUI_GroupDlg::onTypeChanged (int id)
731 if (myTypeId != id) {
734 if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
735 setSelectionMode(id);
737 setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
739 onObjectSelectionChanged();
744 //=================================================================================
745 // function : onGrpTypeChanged()
746 // purpose : Group type radio button management
747 //=================================================================================
748 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
750 if (myGrpTypeId != id) {
752 myWGStack->setCurrentIndex( id );
753 myName->blockSignals(true);
754 myName->setText(myOldName);
755 myName->blockSignals(false);
756 onSelectGeomGroup(id != 0);
761 //=================================================================================
762 // function : onColorChanged()
763 // purpose : Color button management
764 //=================================================================================
765 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
770 //=================================================================================
771 // function : setSelectionMode()
772 // purpose : Radio button management
773 //=================================================================================
774 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
777 if (myMesh->_is_nil())
779 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
780 bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
781 if (mySelectionMode != theMode) {
782 // [PAL10408] mySelectionMgr->clearSelected();
783 mySelectionMgr->clearFilters();
784 SMESH::RemoveFilters();
786 if (myActorsList.count() > 0)
787 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
788 it.next()->SetPointRepresentation(false);
790 SMESH::SetPointRepresentation(false);
793 case grpNodeSelection:
794 if ( myGrpTypeId == 0 ) // standalone
796 if (myActorsList.count() > 0)
797 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
798 it.next()->SetPointRepresentation(true);
800 SMESH::SetPointRepresentation(true);
802 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
804 case grpEdgeSelection:
805 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
807 case grpBallSelection:
808 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
810 case grpFaceSelection:
811 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
813 case grpVolumeSelection:
814 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
816 case grpSubMeshSelection: {
818 SMESH_TypeFilter* f = 0;
820 case grpNodeSelection: f = new SMESH_TypeFilter(SUBMESH); break;
821 case grpEdgeSelection: f = new SMESH_TypeFilter(SUBMESH_EDGE); break;
822 case grpFaceSelection: f = new SMESH_TypeFilter(SUBMESH_FACE); break;
823 case grpVolumeSelection: f = new SMESH_TypeFilter(SUBMESH_SOLID); break;
824 default: f = new SMESH_TypeFilter(SUBMESH);
826 QList<SUIT_SelectionFilter*> filtList;
827 filtList.append( f );
828 filtList.append( new SMESH_TypeFilter(SUBMESH_COMPOUND));
829 mySubMeshFilter->setFilters( filtList );
831 mySelectionMgr->installFilter( mySubMeshFilter );
833 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
836 case grpGroupSelection: {
838 SMESH_TypeFilter* f = 0;
840 case grpNodeSelection: f = new SMESH_TypeFilter(GROUP_NODE); break;
841 case grpBallSelection: f = new SMESH_TypeFilter(GROUP_BALL); break;
842 case grpEdgeSelection: f = new SMESH_TypeFilter(GROUP_EDGE); break;
843 case grpFaceSelection: f = new SMESH_TypeFilter(GROUP_FACE); break;
844 case grpVolumeSelection: f = new SMESH_TypeFilter(GROUP_VOLUME); break;
845 default: f = new SMESH_TypeFilter(GROUP);
847 QList<SUIT_SelectionFilter*> filtList;
848 filtList.append( f );
849 myGroupFilter->setFilters( filtList );
851 mySelectionMgr->installFilter(myGroupFilter);
852 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
855 case grpMeshSelection:
856 mySelectionMgr->installFilter(myMeshFilter);
857 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
859 case grpGeomSelection:
860 mySelectionMgr->installFilter(myGeomFilter);
861 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
864 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
867 if ( aViewWindow ) aViewWindow->Repaint();
868 mySelectionMode = theMode;
872 //=================================================================================
873 // function : onApply()
875 //=================================================================================
876 bool SMESHGUI_GroupDlg::onApply()
878 if (mySMESHGUI->isActiveStudyLocked())
881 if (myName->text().trimmed().isEmpty())
884 SMESH::ElementType aType = SMESH::ALL;
886 case grpNodeSelection: aType = SMESH::NODE; break;
887 case grpBallSelection: aType = SMESH::BALL; break;
888 case grpEdgeSelection: aType = SMESH::EDGE; break;
889 case grpFaceSelection: aType = SMESH::FACE; break;
890 case grpVolumeSelection: aType = SMESH::VOLUME; break;
894 QStringList anEntryList;
896 SMESH::SMESH_GroupBase_var resultGroup;
899 if (myGrpTypeId == 0) // standalone
901 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
904 mySelectionMgr->clearSelected();
906 if (myGroup->_is_nil()) { // creation or conversion
907 // check if group on geometry is not null
908 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
909 if (myMesh->_is_nil())
911 if ( myGroupOnGeom->_is_nil() )
912 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
914 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
916 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
917 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
921 if (myGroup->_is_nil()) { // creation
922 if (myMesh->_is_nil())
925 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
927 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
930 if ( mySelectAll->isChecked() ) {
932 myGroup->AddFrom(myMesh.in());
937 if ( !myFilter->_is_nil() &&
938 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
940 myGroup->AddFrom( myFilter );
944 SMESH::long_array_var anIdList = new SMESH::long_array;
945 int i, k = myElements->count();
947 for (i = 0; i < k; i++) {
948 anIdList[i] = myElements->item(i)->text().toInt();
950 myGroup->Add(anIdList.inout());
957 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
960 if ( mySelectAll->isChecked() ) {
963 myGroup->AddFrom(myMesh.in());
968 int i, total = myElements->count();
969 for (i = 0; i < total; i++) {
970 int anId = myElements->item(i)->text().toInt();
971 int idx = myIdList.indexOf(anId);
973 aAddList.append(anId);
975 myIdList.removeAt(idx);
977 if (!aAddList.empty()) {
978 SMESH::long_array_var anIdList = new SMESH::long_array;
979 int added = aAddList.count();
980 anIdList->length(added);
981 for (i = 0; i < added; i++)
982 anIdList[i] = aAddList[i];
983 myGroup->Add(anIdList.inout());
985 if (!myIdList.empty()) {
986 SMESH::long_array_var anIdList = new SMESH::long_array;
987 int removed = myIdList.count();
988 anIdList->length(removed);
989 for (i = 0; i < removed; i++)
990 anIdList[i] = myIdList[i];
991 myGroup->Remove(anIdList.inout());
993 /* init for next operation */
995 for (i = 0; i < total; i++) {
996 myIdList.append(myElements->item(i)->text().toInt());
1003 else if (myGrpTypeId == 1) // on geom object
1005 if (CORBA::is_nil(myGroupOnGeom)) { // creation
1006 if (myMesh->_is_nil() || !myGeomObjects->length())
1009 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1010 GEOM::GEOM_IGroupOperations_var aGroupOp =
1011 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1013 if (myGeomObjects->length() == 1) {
1014 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1015 myName->text().toLatin1().data(),
1019 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1020 if ( aSMESHGen->_is_nil() )
1023 // create a geometry group
1024 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1025 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1027 if (geomGen->_is_nil() || !aStudy)
1030 GEOM::GEOM_IGroupOperations_var op =
1031 geomGen->GetIGroupOperations(aStudy->StudyId());
1035 // check and add all selected GEOM objects: they must be
1036 // a sub-shapes of the main GEOM and must be of one type
1037 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1038 for ( int i =0; i < myGeomObjects->length(); i++) {
1039 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1041 aGroupType = aSubShapeType;
1042 else if (aSubShapeType != aGroupType) {
1043 aGroupType = TopAbs_SHAPE;
1048 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1049 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1050 op->UnionList(aGroupVar, myGeomObjects);
1053 // publish the GEOM group in study
1054 QString aNewGeomGroupName ( "Auto_group_for_" );
1055 aNewGeomGroupName += myName->text();
1056 SALOMEDS::SObject_var aNewGroupSO =
1057 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
1058 aNewGeomGroupName.toLatin1().data(), aMeshShape);
1061 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1062 myName->text().toLatin1().data(),
1065 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1071 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1076 if (myGrpTypeId == 2) // group on filter
1078 if ( myFilter->_is_nil() ) return false;
1080 if (CORBA::is_nil(myGroupOnFilter)) { // creation
1081 if (myMesh->_is_nil())
1084 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1085 myName->text().toLatin1().data(),
1088 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1093 myGroupOnFilter->SetFilter( myFilter );
1095 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1103 SALOMEDS::Color aColor = getGroupColor();
1104 resultGroup->SetColor(aColor);
1106 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1108 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1112 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1114 /* init for the next operation */
1115 myName->setText( "" );
1116 myElements->clear();
1117 myGroup = SMESH::SMESH_Group::_nil();
1118 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1119 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1120 myFilter = SMESH::Filter::_nil();
1124 resultGroup->SetName(myName->text().toLatin1().data());
1127 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
1128 anActor->setName(myName->text().toLatin1().data());
1131 switch ( myTypeId ) {
1132 case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1133 case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1134 case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1135 case grpVolumeSelection:
1136 SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
1137 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1139 case grpFaceSelection:
1141 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1142 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1147 SMESHGUI::Modified();
1148 mySMESHGUI->updateObjBrowser(true);
1149 SMESH::UpdateView(); // asv: fix of BUG PAL5515
1150 mySelectionMgr->clearSelected();
1152 if( LightApp_Application* anApp =
1153 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1154 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1159 //=================================================================================
1160 // function : onOK()
1162 //=================================================================================
1163 void SMESHGUI_GroupDlg::onOK()
1165 setIsApplyAndClose( true );
1168 setIsApplyAndClose( false );
1171 //=================================================================================
1172 // function : onListSelectionChanged()
1173 // purpose : Called when selection in element list is changed
1174 //=================================================================================
1175 void SMESHGUI_GroupDlg::onListSelectionChanged()
1177 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1178 if( myIsBusy || myActorsList.count() == 0 ) return;
1181 if (myCurrentLineEdit == 0) {
1182 mySelectionMgr->clearSelected();
1183 TColStd_MapOfInteger aIndexes;
1184 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1185 QListWidgetItem* anItem;
1186 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1187 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1188 SALOME_ListIO aList;
1189 aList.Append(myActorsList.first()->getIO());
1190 mySelectionMgr->setSelectedObjects(aList,false);
1195 //=================================================================================
1196 // function : onObjectSelectionChanged()
1197 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1198 //=================================================================================
1199 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1201 if ( myIsBusy || !isEnabled()) return;
1202 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1206 SALOME_ListIO aList;
1207 mySelectionMgr->selectedObjects( aList );
1209 int aNbSel = aList.Extent();
1210 myElements->clearSelection();
1212 if (myCurrentLineEdit)
1214 myCurrentLineEdit->setText( "" );
1215 QString aString = "";
1217 if (myCurrentLineEdit == myMeshGroupLine)
1219 mySelectSubMesh->setEnabled(false);
1220 mySelectGroup->setEnabled(false);
1221 myGroupLine->setText( "" );
1222 mySubMeshLine->setText( "" );
1224 myGeomGroupBtn->setEnabled(false);
1225 myGeomGroupLine->setEnabled(false);
1226 myGeomGroupLine->setText( "" );
1227 myGeomObjects = new GEOM::ListOfGO();
1228 myGeomObjects->length(0);
1230 if (myGeomGroupBtn->isChecked())
1231 myGeomGroupBtn->setChecked(false);
1233 myName->setText( "" );
1235 myElements->clear();
1238 myGroup = SMESH::SMESH_Group::_nil();
1239 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1240 restoreShowEntityMode();
1241 myMesh = SMESH::SMESH_Mesh::_nil();
1247 Handle(SALOME_InteractiveObject) IO = aList.First();
1250 restoreShowEntityMode();
1251 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1252 setShowEntityMode();
1254 if (myMesh->_is_nil())
1261 if ( myFilterDlg && !myMesh->_is_nil()){
1262 myFilterDlg->SetMesh( myMesh );
1264 myGroup = SMESH::SMESH_Group::_nil();
1266 // NPAL19389: create a group with a selection in another group
1267 // set actor of myMesh, if it is visible, else try
1268 // any visible actor of group or submesh of myMesh
1269 SetAppropriateActor();
1271 aString = aList.First()->getName();
1272 myMeshGroupLine->setText(aString);
1273 myMeshGroupLine->home( false );
1275 mySelectSubMesh->setEnabled(true);
1276 mySelectGroup->setEnabled(true);
1277 myGeomGroupBtn->setEnabled(true);
1278 myGeomGroupLine->setEnabled(true);
1282 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1283 if (aGroup->_is_nil())
1290 myGroup = SMESH::SMESH_Group::_nil();
1291 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1295 mySelectSubMesh->setEnabled(true);
1296 mySelectGroup->setEnabled(true);
1298 myCurrentLineEdit = 0;
1303 if (myGrpTypeId == 0)
1309 myElements->clear();
1310 setSelectionMode(myTypeId);
1318 else if (myCurrentLineEdit == myGeomGroupLine)
1320 myGeomObjects = new GEOM::ListOfGO();
1323 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1325 if (aNbSel == 0 || !aMeshSO)
1327 myGeomObjects->length(0);
1333 myGeomObjects->length(aNbSel);
1335 GEOM::GEOM_Object_var aGeomGroup;
1338 SALOME_ListIteratorOfListIO anIt (aList);
1339 for (; anIt.More(); anIt.Next())
1341 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1343 // Check if the object is a geometry group
1344 if (CORBA::is_nil(aGeomGroup))
1347 // Check if group constructed on the same shape as a mesh or on its child
1348 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1349 GEOM::GEOM_IGroupOperations_var anOp =
1350 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1352 // The main shape of the group
1353 GEOM::GEOM_Object_var aGroupMainShape;
1354 if (aGeomGroup->GetType() == 37)
1355 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1357 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1358 _PTR(SObject) aGroupMainShapeSO =
1359 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1361 _PTR(SObject) anObj, aRef;
1362 bool isRefOrSubShape = false;
1363 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1364 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1365 isRefOrSubShape = true;
1367 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1368 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1369 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1370 if (aRef->GetID() == aFather->GetID())
1371 isRefOrSubShape = true;
1373 aFather = aFather->GetFather();
1377 if (isRefOrSubShape)
1378 myGeomObjects[i++] = aGeomGroup;
1381 myGeomObjects->length(i);
1393 if (myCurrentLineEdit == mySubMeshLine)
1394 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1395 else if (myCurrentLineEdit == myGroupLine)
1396 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1397 else if (myCurrentLineEdit == myGeomGroupLine)
1398 aString = tr( "%1 Objects" ).arg(aNbSel);
1401 aString = aList.First()->getName();
1405 myCurrentLineEdit->setText(aString);
1406 myCurrentLineEdit->home(false);
1407 // 07.06.2008 skl for IPAL19574:
1408 // change name of group only if it is empty
1409 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1410 myOldName = myName->text();
1411 myName->blockSignals(true);
1412 myName->setText(aString);
1413 myName->blockSignals(false);
1418 else // !myCurrentLineEdit: local selection of nodes or elements
1420 if (aNbSel == 1 && myActorsList.count() > 0 )
1422 // NPAL19389: create a group with a selection in another group
1423 // Switch myActor to the newly selected one, if the last
1424 // is visible and belongs to group or submesh of myMesh
1425 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1426 Handle(SALOME_InteractiveObject) selIO = aList.First();
1427 if (curIO->hasEntry() && selIO->hasEntry()) {
1428 const char* selEntry = selIO->getEntry();
1429 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1430 // different objects: selected and myActor
1431 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1432 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1433 // newly selected actor is visible
1436 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1438 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1439 int len = strlen(meshEntry);
1441 if (strncmp(selEntry, meshEntry, len) == 0) {
1442 // selected object is myMesh or a part of it
1443 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1446 SMESH::SetPickable(myActor);
1455 QString aListStr = "";
1457 if (myTypeId == 0) {
1458 QListIterator<SMESH_Actor*> it( myActorsList );
1459 while ( it.hasNext() ) {
1461 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1465 QListIterator<SMESH_Actor*> it( myActorsList );
1466 while ( it.hasNext() ) {
1468 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1473 QListWidgetItem* anItem;
1474 QList<QListWidgetItem*> listItemsToSel;
1475 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1476 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1477 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1478 foreach(anItem, found)
1479 if (!anItem->isSelected())
1480 listItemsToSel.push_back(anItem);
1482 bool blocked = myElements->signalsBlocked();
1483 myElements->blockSignals(true);
1484 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1485 myElements->blockSignals(blocked);
1486 onListSelectionChanged();
1487 listItemsToSel.clear();
1492 if (myActorsList.count() == 0) {
1493 if (!myGroup->_is_nil()) {
1494 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1496 myActorsList.append( anActor );
1498 else if(!myGroupOnGeom->_is_nil()) {
1499 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1501 myActorsList.append( anActor );
1504 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1506 myActorsList.append( anActor );
1510 // somehow, if we display the mesh, while selecting from another actor,
1511 // the mesh becomes pickable, and there is no way to select any element
1512 if (myActorsList.count() > 0) {
1513 QListIterator<SMESH_Actor*> it( myActorsList );
1514 while ( it.hasNext() ) {
1515 SMESH_Actor* anActor = it.next();
1516 if ( IsActorVisible(anActor) )
1517 anActor->SetPickable(true);
1524 //=================================================================================
1525 // function : onSelectAll()
1526 // purpose : Called when "Select all" is checked
1527 //=================================================================================
1528 void SMESHGUI_GroupDlg::onSelectAll()
1530 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1532 myElementsLab->setEnabled( !noElemsModif );
1533 myElements->setEnabled ( !noElemsModif );
1534 myFilterBtn->setEnabled ( !mySelectAll->isChecked() );
1535 myAddBtn->setEnabled ( !noElemsModif );
1536 myRemoveBtn->setEnabled ( !noElemsModif );
1537 mySortBtn->setEnabled ( !noElemsModif );
1538 mySelectBox->setEnabled ( !noElemsModif );
1539 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1541 int selMode = mySelectionMode;
1542 mySelectionMode = grpNoSelection;
1543 setSelectionMode( selMode );
1547 //=================================================================================
1548 // function : onSelectSubMesh()
1549 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1550 //=================================================================================
1551 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1554 if (mySelectGroup->isChecked()) {
1555 mySelectGroup->setChecked(false);
1557 //VSR: else if (mySelectGeomGroup->isChecked()) {
1558 //VSR: mySelectGeomGroup->setChecked(false);
1560 myCurrentLineEdit = mySubMeshLine;
1561 setSelectionMode(grpSubMeshSelection);
1564 mySubMeshLine->setText( "" );
1565 myCurrentLineEdit = 0;
1567 setSelectionMode(myTypeId);
1569 mySubMeshBtn->setEnabled(on);
1570 mySubMeshLine->setEnabled(on);
1574 //=================================================================================
1575 // function : (onSelectGroup)
1576 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1577 //=================================================================================
1578 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1581 if (mySelectSubMesh->isChecked()) {
1582 mySelectSubMesh->setChecked(false);
1584 myCurrentLineEdit = myGroupLine;
1585 setSelectionMode(grpGroupSelection);
1588 myGroupLine->setText( "" );
1589 myCurrentLineEdit = 0;
1591 setSelectionMode(myTypeId);
1593 myGroupBtn->setEnabled(on);
1594 myGroupLine->setEnabled(on);
1598 //=================================================================================
1599 // function : (onSelectGeomGroup)
1600 // purpose : Called when group type changed. on == "on group" or "on filter"
1601 //=================================================================================
1602 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1605 if (mySelectSubMesh->isChecked()) {
1606 mySelectSubMesh->setChecked(false);
1608 else if (mySelectGroup->isChecked()) {
1609 mySelectGroup->setChecked(false);
1611 if ( myGrpTypeId == 1 ) { // on group
1612 myCurrentLineEdit = myGeomGroupLine;
1616 myCurrentLineEdit = 0;
1618 setSelectionMode(grpAllSelection);
1621 myGeomGroupBtn->setChecked(false);
1622 myGeomObjects->length(0);
1623 myGeomGroupLine->setText( "" );
1624 myCurrentLineEdit = 0;
1626 setSelectionMode( myTypeId );
1630 //=================================================================================
1631 // function : setCurrentSelection()
1633 //=================================================================================
1634 void SMESHGUI_GroupDlg::setCurrentSelection()
1636 QPushButton* send = (QPushButton*)sender();
1637 myCurrentLineEdit = 0;
1638 if (send == myMeshGroupBtn) {
1639 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1640 mySelectionMgr->clearSelected();
1642 setSelectionMode(grpMeshSelection);
1644 setSelectionMode(grpGroupSelection);
1645 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1646 myCurrentLineEdit = myMeshGroupLine;
1647 onObjectSelectionChanged();
1649 else if (send == mySubMeshBtn) {
1650 myCurrentLineEdit = mySubMeshLine;
1651 onObjectSelectionChanged();
1653 else if (send == myGroupBtn) {
1654 myCurrentLineEdit = myGroupLine;
1655 onObjectSelectionChanged();
1660 //=================================================================================
1661 // function : setFilters()
1662 // purpose : SLOT. Called when "Filter" button pressed.
1663 //=================================================================================
1664 void SMESHGUI_GroupDlg::setFilters()
1666 if(myMesh->_is_nil()) {
1667 SUIT_MessageBox::critical(this,
1669 tr("NO_MESH_SELECTED"));
1673 SMESH::ElementType aType = SMESH::ALL;
1676 case grpNodeSelection: aType = SMESH::NODE; break;
1677 case grpBallSelection: aType = SMESH::BALL; break;
1678 case grpEdgeSelection: aType = SMESH::EDGE; break;
1679 case grpFaceSelection: aType = SMESH::FACE; break;
1680 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1684 if ( myFilterDlg == 0 )
1686 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1687 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1690 myFilterDlg->Init( aType );
1692 if ( !myGroupOnFilter->_is_nil() )
1694 myFilterDlg->SetFilter( myFilter, aType );
1695 myFilterDlg->Init( aType );
1698 myFilterDlg->SetSelection();
1699 myFilterDlg->SetMesh( myMesh );
1700 myFilterDlg->SetSourceWg( myElements, false );
1702 myFilterDlg->show();
1705 //=================================================================================
1706 // function : onFilterAccepted()
1707 // purpose : SLOT. Called when Filter dlg closed with OK button.
1708 // Uncheck "Select submesh" and "Select group" checkboxes
1709 //=================================================================================
1710 void SMESHGUI_GroupDlg::onFilterAccepted()
1712 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1714 mySelectionMode = myTypeId;
1715 mySelectSubMesh->setChecked( false );
1716 mySelectGroup->setChecked( false );
1718 // get a filter from myFilterDlg
1719 myFilter = myFilterDlg->GetFilter();
1720 if ( !myFilter->_is_nil() ) {
1721 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1722 if ( perdicate->_is_nil() )
1723 myFilter = SMESH::Filter::_nil();
1725 // set mesh to myFilter
1726 if ( !myFilter->_is_nil() ) {
1727 SMESH::SMESH_Mesh_var mesh = myMesh;
1728 if ( mesh->_is_nil() ) {
1729 if ( !myGroup->_is_nil() )
1730 mesh = myGroup->GetMesh();
1731 else if ( !myGroupOnGeom->_is_nil() )
1732 mesh = myGroupOnGeom->GetMesh();
1733 else if ( !myGroupOnFilter->_is_nil() )
1734 mesh = myGroupOnFilter->GetMesh();
1736 myFilter->SetMesh( mesh );
1742 //=================================================================================
1743 // function : onAdd()
1745 //=================================================================================
1746 void SMESHGUI_GroupDlg::onAdd()
1748 SALOME_ListIO aList;
1749 mySelectionMgr->selectedObjects( aList );
1751 int aNbSel = aList.Extent();
1753 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1756 int sizeBefore = myElements->count();
1758 SMESH::ElementType aType = SMESH::ALL;
1760 case grpNodeSelection:
1761 aType = SMESH::NODE;
1762 mySelector->SetSelectionMode(NodeSelection);
1764 case grpBallSelection:
1765 aType = SMESH::BALL;
1766 mySelector->SetSelectionMode(BallSelection);
1768 case grpEdgeSelection:
1769 aType = SMESH::EDGE;
1770 mySelector->SetSelectionMode(EdgeSelection);
1772 case grpFaceSelection:
1773 aType = SMESH::FACE;
1774 mySelector->SetSelectionMode(FaceSelection);
1776 case grpVolumeSelection:
1777 aType = SMESH::VOLUME;
1778 mySelector->SetSelectionMode(VolumeSelection);
1781 mySelector->SetSelectionMode(ActorSelection);
1784 QListWidgetItem* anItem = 0;
1785 QList<QListWidgetItem*> listItemsToSel;
1787 if (myCurrentLineEdit == 0) {
1788 //if (aNbSel != 1) { myIsBusy = false; return; }
1789 QString aListStr = "";
1791 if (myTypeId == 0) {
1792 QListIterator<SMESH_Actor*> it( myActorsList );
1793 while ( it.hasNext() ) {
1795 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1800 QListIterator<SMESH_Actor*> it( myActorsList );
1801 while ( it.hasNext() ) {
1803 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1808 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1809 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1810 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1811 if (found.count() == 0) {
1812 anItem = new QListWidgetItem(*it);
1813 myElements->addItem(anItem);
1814 if (!anItem->isSelected())
1815 listItemsToSel.push_back(anItem);
1818 foreach(anItem, found)
1819 if (!anItem->isSelected())
1820 listItemsToSel.push_back(anItem);
1823 bool blocked = myElements->signalsBlocked();
1824 myElements->blockSignals(true);
1825 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1826 myElements->blockSignals(blocked);
1827 onListSelectionChanged();
1828 listItemsToSel.clear();
1830 } else if (myCurrentLineEdit == mySubMeshLine) {
1831 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1833 SALOME_ListIO aList;
1834 mySelectionMgr->selectedObjects( aList );
1836 SALOME_ListIteratorOfListIO anIt (aList);
1837 for ( ; anIt.More(); anIt.Next()) {
1838 SMESH::SMESH_subMesh_var aSubMesh =
1839 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1840 if (!aSubMesh->_is_nil()) {
1841 // check if mesh is the same
1842 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1844 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1845 int k = anElements->length();
1846 for (int i = 0; i < k; i++) {
1847 QString aText = QString::number(anElements[i]);
1848 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1849 if (found.count() == 0) {
1850 anItem = new QListWidgetItem(aText);
1851 myElements->addItem(anItem);
1852 if (!anItem->isSelected())
1853 listItemsToSel.push_back(anItem);
1856 foreach(anItem, found)
1857 if (!anItem->isSelected())
1858 listItemsToSel.push_back(anItem);
1861 bool blocked = myElements->signalsBlocked();
1862 myElements->blockSignals(true);
1863 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1864 myElements->blockSignals(blocked);
1865 onListSelectionChanged();
1866 listItemsToSel.clear();
1868 catch (const SALOME::SALOME_Exception& ex) {
1869 SalomeApp_Tools::QtCatchCorbaException(ex);
1874 mySelectSubMesh->setChecked(false);
1876 onListSelectionChanged();
1878 } else if (myCurrentLineEdit == myGroupLine) {
1879 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1880 SALOME_ListIO aList;
1881 mySelectionMgr->selectedObjects( aList );
1883 SALOME_ListIteratorOfListIO anIt (aList);
1884 for ( ; anIt.More(); anIt.Next()) {
1885 SMESH::SMESH_GroupBase_var aGroup =
1886 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1887 if (!aGroup->_is_nil()) {
1888 // check if mesh is the same
1889 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1890 SMESH::long_array_var anElements = aGroup->GetListOfID();
1891 int k = anElements->length();
1892 for (int i = 0; i < k; i++) {
1893 QString aText = QString::number(anElements[i]);
1894 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1895 if (found.count() == 0) {
1896 anItem = new QListWidgetItem(aText);
1897 myElements->addItem(anItem);
1898 if (!anItem->isSelected())
1899 listItemsToSel.push_back(anItem);
1902 foreach(anItem, found)
1903 if (!anItem->isSelected())
1904 listItemsToSel.push_back(anItem);
1907 bool blocked = myElements->signalsBlocked();
1908 myElements->blockSignals(true);
1909 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1910 myElements->blockSignals(blocked);
1911 onListSelectionChanged();
1912 listItemsToSel.clear();
1916 mySelectGroup->setChecked(false);
1918 onListSelectionChanged();
1920 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1921 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1922 GEOM::GEOM_IGroupOperations_var aGroupOp =
1923 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1925 SMESH::ElementType aGroupType = SMESH::ALL;
1926 switch(aGroupOp->GetType(myGeomObjects[0])) {
1927 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
1928 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
1929 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
1930 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
1931 default: myIsBusy = false; return;
1934 if (aGroupType == aType) {
1935 _PTR(SObject) aGroupSO =
1936 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1937 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1939 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1940 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1941 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
1942 aBelongToGeom->SetGeom(myGeomObjects[0]);
1943 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1944 aBelongToGeom->SetElementType(aType);
1945 aFilter->SetPredicate(aBelongToGeom);
1947 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1949 int k = anElements->length();
1950 for (int i = 0; i < k; i++) {
1951 QString aText = QString::number(anElements[i]);
1952 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1953 if (found.count() == 0) {
1954 anItem = new QListWidgetItem(aText);
1955 myElements->addItem(anItem);
1956 if (!anItem->isSelected())
1957 listItemsToSel.push_back(anItem);
1960 foreach(anItem, found)
1961 if (!anItem->isSelected())
1962 listItemsToSel.push_back(anItem);
1965 bool blocked = myElements->signalsBlocked();
1966 myElements->blockSignals(true);
1967 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1968 myElements->blockSignals(blocked);
1969 onListSelectionChanged();
1970 listItemsToSel.clear();
1973 //VSR: mySelectGeomGroup->setChecked(false);
1975 onListSelectionChanged();
1978 if ( sizeBefore < myElements->count() )
1979 ++myNbChangesOfContents;
1980 // mySelectionMgr->clearSelected();
1984 //=================================================================================
1985 // function : onRemove()
1987 //=================================================================================
1988 void SMESHGUI_GroupDlg::onRemove()
1991 int sizeBefore = myElements->count();
1993 if (myCurrentLineEdit == 0) {
1994 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1995 QListWidgetItem* item;
1996 foreach(item, selItems) delete item;
1998 SALOME_ListIO aList;
1999 mySelectionMgr->selectedObjects( aList );
2001 int aNbSel = aList.Extent();
2003 if (aNbSel == 0) { myIsBusy = false; return; }
2005 SMESH::ElementType aType = SMESH::ALL;
2007 case grpNodeSelection: aType = SMESH::NODE; break;
2008 case grpBallSelection: aType = SMESH::BALL; break;
2009 case grpEdgeSelection: aType = SMESH::EDGE; break;
2010 case grpFaceSelection: aType = SMESH::FACE; break;
2011 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2014 if (myCurrentLineEdit == mySubMeshLine) {
2015 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2016 SALOME_ListIO aList;
2017 mySelectionMgr->selectedObjects( aList );
2019 SALOME_ListIteratorOfListIO anIt (aList);
2020 for ( ; anIt.More(); anIt.Next()) {
2021 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2022 if (!aSubMesh->_is_nil()) {
2023 // check if mesh is the same
2024 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2025 if (aType == SMESH::NODE) {
2027 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2028 int k = anElements->length();
2029 for (int i = 0; i < k; i++) {
2030 QList<QListWidgetItem*> found =
2031 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2032 QListWidgetItem* anItem;
2033 foreach(anItem, found) delete anItem;
2036 catch (const SALOME::SALOME_Exception& ex) {
2037 SalomeApp_Tools::QtCatchCorbaException(ex);
2042 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2043 int k = anElements->length();
2044 for (int i = 0; i < k; i++) {
2045 QList<QListWidgetItem*> found =
2046 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2047 QListWidgetItem* anItem;
2048 foreach(anItem, found) delete anItem;
2051 catch (const SALOME::SALOME_Exception& ex) {
2052 SalomeApp_Tools::QtCatchCorbaException(ex);
2059 else if (myCurrentLineEdit == myGroupLine) {
2060 Standard_Boolean aRes;
2061 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2062 SALOME_ListIO aList;
2063 mySelectionMgr->selectedObjects( aList );
2065 SALOME_ListIteratorOfListIO anIt (aList);
2066 for ( ; anIt.More(); anIt.Next()) {
2067 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2068 if (aRes && !aGroup->_is_nil()) {
2069 // check if mesh is the same
2070 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2071 SMESH::long_array_var anElements = aGroup->GetListOfID();
2072 int k = anElements->length();
2073 for (int i = 0; i < k; i++) {
2074 QList<QListWidgetItem*> found =
2075 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2076 QListWidgetItem* anItem;
2077 foreach(anItem, found) delete anItem;
2085 if ( sizeBefore > myElements->count() )
2086 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2090 //=================================================================================
2091 // function : onSort()
2093 //=================================================================================
2094 void SMESHGUI_GroupDlg::onSort()
2096 // PAL5412: sorts items in ascending by "string" value
2097 // myElements->sort(true);
2098 // myElements->update();
2099 int i, k = myElements->count();
2102 QList<int> aSelected;
2103 std::vector<int> anArray(k);
2104 // QMemArray<int> anArray(k);
2106 for (i = 0; i < k; i++) {
2107 int id = myElements->item(i)->text().toInt();
2109 if (myElements->item(i)->isSelected())
2110 aSelected.append(id);
2112 // sort & update list
2113 std::sort(anArray.begin(), anArray.end());
2115 myElements->clear();
2116 QListWidgetItem* anItem;
2117 QList<QListWidgetItem*> listItemsToSel;
2118 for (i = 0; i < k; i++) {
2119 anItem = new QListWidgetItem(QString::number(anArray[i]));
2120 myElements->addItem(anItem);
2121 if (aSelected.contains(anArray[i]))
2122 listItemsToSel.push_back(anItem);
2124 bool blocked = myElements->signalsBlocked();
2125 myElements->blockSignals(true);
2126 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2127 myElements->blockSignals(blocked);
2128 listItemsToSel.clear();
2133 //=================================================================================
2134 // function : closeEvent()
2136 //=================================================================================
2137 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
2142 //=================================================================================
2143 // function : onVisibilityChanged()
2145 //=================================================================================
2146 void SMESHGUI_GroupDlg::onVisibilityChanged()
2148 SetAppropriateActor();
2151 //=================================================================================
2152 // function : SMESHGUI_GroupDlg::onClose
2153 // purpose : SLOT called when "Close" button pressed. Close dialog
2154 //=================================================================================
2155 void SMESHGUI_GroupDlg::onClose()
2157 if (SMESH::GetCurrentVtkView()) {
2158 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2159 SMESH::SetPointRepresentation(false);
2160 SMESH::SetPickable();
2161 restoreShowEntityMode();
2164 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2165 SUIT_DataOwnerPtrList aList;
2166 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2167 mySelectionMgr->setSelected( aList );
2170 mySelectionMgr->clearSelected();
2171 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2172 aViewWindow->SetSelectionMode(ActorSelection);
2173 mySelectionMgr->clearFilters();
2174 mySMESHGUI->ResetState();
2179 //=================================================================================
2180 // function : onHelp()
2182 //=================================================================================
2183 void SMESHGUI_GroupDlg::onHelp()
2185 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2187 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2191 platform = "winapplication";
2193 platform = "application";
2195 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2196 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2197 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2199 arg(myHelpFileName));
2203 //=================================================================================
2204 // function : SMESHGUI_GroupDlg::onDeactivate
2205 // purpose : SLOT called when dialog must be deativated
2206 //=================================================================================
2207 void SMESHGUI_GroupDlg::onDeactivate()
2209 mySMESHGUI->ResetState();
2213 //=================================================================================
2214 // function : SMESHGUI_GroupDlg::enterEvent
2215 // purpose : Event filter
2216 //=================================================================================
2217 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2220 mySMESHGUI->EmitSignalDeactivateDialog();
2222 mySelectionMode = grpNoSelection;
2223 setSelectionMode(myTypeId);
2224 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2225 mySMESHGUI->SetActiveDialogBox(this);
2226 mySMESHGUI->SetState(800);
2230 //=================================================================================
2231 // function : hideEvent
2232 // purpose : caused by ESC key
2233 //=================================================================================
2234 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
2236 if (!isMinimized() && !myIsBusy)
2240 //=================================================================================
2241 // function : keyPressEvent()
2243 //=================================================================================
2244 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2246 QDialog::keyPressEvent( e );
2247 if ( e->isAccepted() )
2250 if ( e->key() == Qt::Key_F1 )
2257 //================================================================================
2259 * \brief Enable showing of the popup when Geometry selection btn is clicked
2260 * \param enable - true to enable
2262 //================================================================================
2264 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2266 void SMESHGUI_GroupDlg::updateGeomPopup()
2268 bool enable = false;
2270 if ( !myMesh->_is_nil() )
2271 enable = myMesh->NbEdges() > 0;
2273 if ( myGeomGroupBtn )
2275 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2277 if ( !myGeomPopup ) {
2278 myGeomPopup = new QMenu(this);
2279 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2280 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2281 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2283 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2289 //=================================================================================
2290 // function : onGeomSelectionButton()
2292 //=================================================================================
2293 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2295 if ( myGeomPopup && isBtnOn )
2297 myCurrentLineEdit = myGeomGroupLine;
2298 QAction* a = myGeomPopup->exec( QCursor::pos() );
2299 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2300 setSelectionMode(grpGeomSelection);
2304 myCurrentLineEdit = 0;
2305 setSelectionMode(grpAllSelection);
2309 //=================================================================================
2310 // function : onGeomPopup()
2312 //=================================================================================
2313 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2315 int index = myActions[a];
2316 if ( index == GEOM_BY_MESH_INDEX )
2318 mySelectionMode = grpNoSelection;
2319 if ( !myShapeByMeshOp ) {
2320 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2321 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2322 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2323 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2324 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2326 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2327 if ( !myMesh->_is_nil() ) {
2329 hide(); // stop processing selection
2331 myShapeByMeshOp->setModule( mySMESHGUI );
2332 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2333 myShapeByMeshOp->SetMesh( myMesh );
2334 myShapeByMeshOp->start();
2339 //================================================================================
2341 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2343 //================================================================================
2345 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2347 if ( myShapeByMeshOp == op ) {
2348 mySMESHGUI->getApp()->updateObjectBrowser();
2350 // Select a found geometry object
2351 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2352 if ( !aGeomVar->_is_nil() )
2354 QString ID = aGeomVar->GetStudyEntry();
2355 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2356 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2357 SALOME_ListIO anIOList;
2358 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2359 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2360 anIOList.Append( anIO );
2361 mySelectionMgr->setSelectedObjects( anIOList, false );
2362 onObjectSelectionChanged();
2368 //================================================================================
2370 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2372 //================================================================================
2374 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2376 if ( myShapeByMeshOp == op )
2379 setSelectionMode(grpGeomSelection);
2383 //=================================================================================
2384 // function : setGroupColor()
2386 //=================================================================================
2387 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2389 QColor aQColor( (int)( theColor.R * 255.0 ),
2390 (int)( theColor.G * 255.0 ),
2391 (int)( theColor.B * 255.0 ) );
2392 setGroupQColor( aQColor );
2395 //=================================================================================
2396 // function : getGroupColor()
2398 //=================================================================================
2399 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2401 QColor aQColor = getGroupQColor();
2403 SALOMEDS::Color aColor;
2404 aColor.R = (float)aQColor.red() / 255.0;
2405 aColor.G = (float)aQColor.green() / 255.0;
2406 aColor.B = (float)aQColor.blue() / 255.0;
2411 //=================================================================================
2412 // function : setGroupQColor()
2414 //=================================================================================
2415 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2417 if( theColor.isValid() )
2418 myColorBtn->setColor( theColor );
2421 //=================================================================================
2422 // function : getGroupQColor()
2424 //=================================================================================
2425 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2427 return myColorBtn->color();
2430 //=================================================================================
2431 // function : setDefaultGroupColor()
2433 //=================================================================================
2434 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2436 if( myMesh->_is_nil() )
2439 bool isAutoColor = myMesh->GetAutoColor();
2444 int r = 0, g = 0, b = 0;
2445 SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2446 aQColor.setRgb( r, g, b );
2450 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2452 QList<SALOMEDS::Color> aReservedColors;
2453 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2455 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2456 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2457 aReservedColors.append( aReservedColor );
2460 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2461 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2462 (int)( aColor.G * 255.0 ),
2463 (int)( aColor.B * 255.0 ) );
2467 setGroupQColor( aQColor );
2470 //=================================================================================
2471 // function : SetAppropriateActor()
2472 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2473 // NPAL19389: create a group with a selection in another group.
2474 // if mesh actor is not visible - find any first visible group or submesh
2475 //=================================================================================
2476 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2478 bool isActor = false;
2479 myActorsList.clear();
2481 if (myMesh->_is_nil()) return false;
2483 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2485 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2487 if (!myGroupOnGeom->_is_nil()) {
2488 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2489 if (anActor && anActor->hasIO())
2492 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2495 myActorsList.append(anActor);
2501 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2502 if (anActor && anActor->hasIO()) {
2504 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2507 myActorsList.append(anActor);
2511 if (!isActor && !myGroup->_is_nil()) {
2512 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2513 if (anActor && anActor->hasIO())
2514 myActorsList.append(anActor);
2517 // try any visible actor of group or submesh of current mesh
2520 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2522 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2523 int len = strlen(meshEntry);
2525 // iterate on all actors in current view window, search for
2526 // any visible actor, that belongs to group or submesh of current mesh
2527 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2528 vtkActorCollection *aCollection = aCopy.GetActors();
2529 int nbItems = aCollection->GetNumberOfItems();
2530 for (int i=0; i<nbItems && !isActor; i++)
2532 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2533 if (anActor && anActor->hasIO()) {
2534 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2535 if (aViewWindow->isVisible(anIO)) {
2536 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2537 myActorsList.append(anActor);
2545 if (myActorsList.count() > 0) {
2546 QListIterator<SMESH_Actor*> it( myActorsList );
2547 while ( it.hasNext() ) {
2548 SMESH_Actor* anActor = it.next();
2549 if ( IsActorVisible(anActor) )
2550 anActor->SetPickable(true);
2554 return ( isActor || (myActorsList.count() > 0) );
2557 //=======================================================================
2558 //function : setShowEntityMode
2559 //purpose : make shown only entity corresponding to my type
2560 //=======================================================================
2561 void SMESHGUI_GroupDlg::setShowEntityMode()
2563 if ( !myMesh->_is_nil() ) {
2564 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2565 if (!myStoredShownEntity)
2566 myStoredShownEntity = actor->GetEntityMode();
2567 switch ( myTypeId ) {
2568 case grpNodeSelection: restoreShowEntityMode(); break;
2569 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2570 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2571 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2572 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2578 //=======================================================================
2579 //function : restoreShowEntityMode
2580 //purpose : restore ShowEntity mode of myActor
2581 //=======================================================================
2582 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2584 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2585 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2586 actor->SetEntityMode(myStoredShownEntity);
2589 myStoredShownEntity = 0;
2592 //=======================================================================
2593 //function : IsActorVisible
2594 //purpose : return visibility of the actor
2595 //=======================================================================
2596 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2598 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2599 if (theActor && aViewWindow)
2600 return aViewWindow->isVisible(theActor->getIO());
2604 //================================================================
2605 //function : setIsApplyAndClose
2606 //purpose : Set value of the flag indicating that the dialog is
2607 // accepted by Apply & Close button
2608 //================================================================
2609 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2611 myIsApplyAndClose = theFlag;
2614 //================================================================
2615 //function : isApplyAndClose
2616 //purpose : Get value of the flag indicating that the dialog is
2617 // accepted by Apply & Close button
2618 //================================================================
2619 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2621 return myIsApplyAndClose;