1 // Copyright (C) 2007-2014 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>
64 #include <SALOME_ListIteratorOfListIO.hxx>
66 #include <SVTK_ViewWindow.h>
68 #include <VTKViewer_Algorithm.h>
70 // SALOME KERNEL includes
71 #include <SALOMEDSClient_Study.hxx>
74 #include <vtkRenderer.h>
75 #include <vtkActorCollection.h>
78 #include <TColStd_MapOfInteger.hxx>
81 #include <QButtonGroup>
85 #include <QPushButton>
86 #include <QToolButton>
87 #include <QRadioButton>
89 #include <QGridLayout>
90 #include <QHBoxLayout>
91 #include <QVBoxLayout>
92 #include <QListWidget>
93 #include <QStackedWidget>
105 enum grpSelectionMode {
107 grpNodeSelection = 0,
109 grpBallSelection = 2,
110 grpEdgeSelection = 3,
111 grpFaceSelection = 4,
112 grpVolumeSelection = 5,
113 grpSubMeshSelection = 6,
114 grpGroupSelection = 7,
115 grpMeshSelection = 8,
116 grpGeomSelection = 9,
117 grpAllSelection = 10,
120 //=================================================================================
121 // function : SMESHGUI_GroupDlg()
123 //=================================================================================
124 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
125 SMESH::SMESH_Mesh_ptr theMesh )
126 : QDialog( SMESH::GetDesktop( theModule ) ),
127 mySMESHGUI( theModule ),
128 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
129 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
131 myNameChanged( false ),
132 myIsApplyAndClose( false ),
133 myNbChangesOfContents(0)
136 if ( !theMesh->_is_nil() )
140 mySelectSubMesh->setEnabled( false );
141 mySelectGroup->setEnabled( false );
142 myGeomGroupBtn->setEnabled( false );
143 myGeomGroupLine->setEnabled( false );
147 //=================================================================================
148 // function : SMESHGUI_GroupDlg()
150 //=================================================================================
151 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
152 SMESH::SMESH_GroupBase_ptr theGroup,
153 const bool theIsConvert )
154 : QDialog( SMESH::GetDesktop( theModule ) ),
155 mySMESHGUI( theModule ),
156 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
157 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
159 myNameChanged( false ),
160 myNbChangesOfContents(0) // just not to use uninitialized variable
163 if ( !theGroup->_is_nil() )
164 init( theGroup, theIsConvert );
167 mySelectSubMesh->setEnabled( false );
168 mySelectGroup->setEnabled( false );
170 myCurrentLineEdit = myMeshGroupLine;
171 setSelectionMode( grpGroupSelection );
175 //=================================================================================
176 // function : SMESHGUI_GroupDlg()
178 //=================================================================================
179 void SMESHGUI_GroupDlg::initDialog( bool create)
182 setAttribute( Qt::WA_DeleteOnClose, true );
186 myCurrentLineEdit = 0;
190 myGeomObjects = new GEOM::ListOfGO();
191 myGeomObjects->length( 0 );
193 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
195 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
196 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
198 setSizeGripEnabled( true);
200 QGridLayout* aMainLayout = new QGridLayout( this );
201 aMainLayout->setMargin( MARGIN );
202 aMainLayout->setSpacing( SPACING );
204 /***************************************************************/
205 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
206 myMeshGroupBtn = new QPushButton( this );
207 myMeshGroupBtn->setIcon( image0 );
208 myMeshGroupLine = new QLineEdit( this );
209 myMeshGroupLine->setReadOnly( true );
211 /***************************************************************/
212 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
213 myTypeGroup = new QButtonGroup( this );
214 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
215 aTypeBoxLayout->setMargin( MARGIN );
216 aTypeBoxLayout->setSpacing( SPACING );
219 types.append( tr( "MESH_NODE" ) );
220 types.append( tr( "SMESH_ELEM0D" ) );
221 types.append( tr( "SMESH_BALL_ELEM" ) );
222 types.append( tr( "SMESH_EDGE" ) );
223 types.append( tr( "SMESH_FACE" ) );
224 types.append( tr( "SMESH_VOLUME" ) );
226 for ( int i = 0; i < types.count(); i++ )
228 rb = new QRadioButton( types[i], aTypeBox );
229 myTypeGroup->addButton( rb, i );
230 aTypeBoxLayout->addWidget( rb );
232 aTypeBox->setEnabled( create );
235 /***************************************************************/
236 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
237 aName->setMinimumWidth( 50 );
238 myName = new QLineEdit( this );
240 /***************************************************************/
241 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
242 myGrpTypeGroup = new QButtonGroup( this );
243 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
244 aGrpTypeBoxLayout->setMargin( MARGIN );
245 aGrpTypeBoxLayout->setSpacing( SPACING );
247 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
248 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
249 QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox );
250 myGrpTypeGroup->addButton( rb1, 0 );
251 myGrpTypeGroup->addButton( rb2, 1 );
252 myGrpTypeGroup->addButton( rb3, 2 );
253 aGrpTypeBoxLayout->addWidget( rb1 );
254 aGrpTypeBoxLayout->addWidget( rb2 );
255 aGrpTypeBoxLayout->addWidget( rb3 );
256 aGrpTypeBox->setEnabled( create );
259 /***************************************************************/
260 myWGStack = new QStackedWidget( this );
261 QWidget* wg1 = new QWidget( myWGStack );
262 QWidget* wg2 = new QWidget( myWGStack );
263 QWidget* wg3 = new QWidget( myWGStack );
265 /***************************************************************/
266 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
267 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
268 aContentBoxLayout->setMargin( MARGIN );
269 aContentBoxLayout->setSpacing( SPACING );
271 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
272 myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
274 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
275 myElements = new QListWidget( aContentBox );
276 myElements->setSelectionMode( QListWidget::ExtendedSelection );
278 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
279 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
280 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
281 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
283 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
284 aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
285 aContentBoxLayout->addWidget( myFilterBtn, 1, 1 );
286 aContentBoxLayout->addWidget( myElementsLab, 2, 0 );
287 aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 );
288 aContentBoxLayout->addWidget( myAddBtn, 3, 1 );
289 aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 );
290 aContentBoxLayout->addWidget( mySortBtn, 8, 1 );
292 aContentBoxLayout->setColumnStretch( 0, 1 );
293 aContentBoxLayout->setRowStretch( 3, 1 );
294 aContentBoxLayout->setRowStretch( 6, 1 );
296 /***************************************************************/
297 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
298 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
299 mySelectBoxLayout->setMargin( MARGIN );
300 mySelectBoxLayout->setSpacing( SPACING );
302 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
303 mySubMeshBtn = new QPushButton( mySelectBox );
304 mySubMeshBtn->setIcon( image0 );
305 mySubMeshLine = new QLineEdit( mySelectBox );
306 mySubMeshLine->setReadOnly( true );
307 onSelectSubMesh( false );
309 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
310 myGroupBtn = new QPushButton( mySelectBox );
311 myGroupBtn->setIcon( image0 );
312 myGroupLine = new QLineEdit( mySelectBox );
313 myGroupLine->setReadOnly( true );
314 onSelectGroup( false );
316 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
317 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
318 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
319 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
320 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
321 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
323 /***************************************************************/
324 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
325 wg1Layout->setMargin( 0 );
326 wg1Layout->setSpacing( SPACING );
327 wg1Layout->addWidget( aContentBox );
328 wg1Layout->addWidget( mySelectBox );
329 wg1Layout->setStretchFactor( aContentBox, 10 );
331 /***************************************************************/
332 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
333 myGeomGroupBtn = new QToolButton( wg2 );
334 myGeomGroupBtn->setIcon( image0 );
335 myGeomGroupBtn->setCheckable( true );
336 myGeomGroupLine = new QLineEdit( wg2 );
337 myGeomGroupLine->setReadOnly( true ); //VSR ???
338 onSelectGeomGroup( false );
340 myGeomGroupBtn->setEnabled( create );
341 myGeomGroupLine->setEnabled( create );
343 /***************************************************************/
344 QGridLayout* wg2Layout = new QGridLayout( wg2 );
345 wg2Layout->setMargin( 0 );
346 wg2Layout->setSpacing( SPACING );
347 wg2Layout->addWidget( geomObject, 0, 0 );
348 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
349 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
350 wg2Layout->setRowStretch( 1, 5 );
352 /***************************************************************/
353 QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
354 QGridLayout* wg3Layout = new QGridLayout( wg3 );
355 wg3Layout->setMargin( 0 );
356 wg3Layout->setSpacing( SPACING );
357 wg3Layout->addWidget( aFilter2, 0, 0 );
358 wg3Layout->setRowStretch( 1, 5 );
360 /***************************************************************/
361 myWGStack->insertWidget( 0, wg1 );
362 myWGStack->insertWidget( 1, wg2 );
363 myWGStack->insertWidget( 2, wg3 );
365 /***************************************************************/
366 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
367 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
368 aColorBoxLayout->setMargin(MARGIN);
369 aColorBoxLayout->setSpacing(SPACING);
371 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
372 myColorBtn = new QtxColorButton(aColorBox);
373 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
374 myColorBtn->sizePolicy().verticalPolicy() );
376 aColorBoxLayout->addWidget(aColorLab);
377 aColorBoxLayout->addWidget(myColorBtn);
379 /***************************************************************/
381 QFrame* aButtons = new QFrame(this);
382 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
383 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
384 aBtnLayout->setMargin(MARGIN);
385 aBtnLayout->setSpacing(SPACING);
387 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
388 myOKBtn->setAutoDefault(true);
389 myOKBtn->setDefault(true);
390 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
391 myApplyBtn->setAutoDefault(true);
392 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
393 myCloseBtn->setAutoDefault(true);
394 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
395 myHelpBtn->setAutoDefault(true);
397 aBtnLayout->addWidget(myOKBtn);
398 aBtnLayout->addSpacing(10);
399 aBtnLayout->addWidget(myApplyBtn);
400 aBtnLayout->addSpacing(10);
401 aBtnLayout->addStretch();
402 aBtnLayout->addWidget(myCloseBtn);
403 aBtnLayout->addWidget(myHelpBtn);
405 /***************************************************************/
406 aMainLayout->addWidget(meshGroupLab, 0, 0);
407 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
408 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
409 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
410 aMainLayout->addWidget(aName, 2, 0);
411 aMainLayout->addWidget(myName, 2, 2);
412 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
413 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
414 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
415 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
417 /* signals and slots connections */
418 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
419 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
420 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
422 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
423 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
425 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
426 connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters()));
427 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
428 connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
429 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
430 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
431 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
433 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
434 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
435 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
436 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
437 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
439 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
441 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
442 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
443 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
444 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
447 mySMESHGUI->SetActiveDialogBox(this);
448 mySMESHGUI->SetState(800);
450 mySelectionMode = grpNoSelection;
451 myMeshFilter = new SMESH_TypeFilter(SMESH::MESH);
452 mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
453 SMESH_LogicalFilter::LO_OR,
454 /*takeOwnership=*/true);
455 myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
456 SMESH_LogicalFilter::LO_OR,
457 /*takeOwnership=*/true);
458 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
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()));
466 rb1->setChecked(true); // VSR !!!
467 onGrpTypeChanged(0); // VSR!!!
469 if (myMesh->_is_nil() )
470 myTypeGroup->button(0)->setChecked(true);
472 onSelectAll(); //updateButtons();
475 //=================================================================================
476 // function : ~SMESHGUI_GroupDlg()
477 // purpose : Destroys the object and frees any allocated resources
478 //=================================================================================
479 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
481 // no need to delete child widgets, Qt does it all for us
482 if ( myFilterDlg != 0 ) {
483 myFilterDlg->setParent( 0 );
486 if ( myMeshFilter ) delete myMeshFilter;
487 if ( mySubMeshFilter ) delete mySubMeshFilter;
488 if ( myGroupFilter ) delete myGroupFilter;
489 if ( myGeomFilter ) delete myGeomFilter;
492 //=================================================================================
493 // function : GetDefaultName()
494 // purpose : Get the Group Name if Create new Group
495 //=================================================================================
496 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
500 // collect all object names of SMESH component
501 SalomeApp_Study* appStudy =
502 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
503 if ( !appStudy ) return aName;
504 _PTR(Study) aStudy = appStudy->studyDS();
506 std::set<std::string> aSet;
507 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
509 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
511 for (it->InitEx(true); it->More(); it->Next()) {
513 aSet.insert(obj->GetName());
517 // build a unique name
519 bool isUnique = false;
521 aName = theOperation + "_" + QString::number(++aNumber);
522 isUnique = (aSet.count(aName.toUtf8().data()) == 0);
528 void SMESHGUI_GroupDlg::setDefaultName() const
531 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
533 QString aPrefix ="Group_";
537 aResName = aPrefix + QString::number( i++ );
538 anObj = aStudy->FindObject( aResName.toUtf8().data() );
541 myName->setText(aResName);
544 //=================================================================================
547 //=================================================================================
548 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
550 mySelectionMgr->installFilter(myMeshFilter);
552 /* init data from current selection */
553 restoreShowEntityMode();
554 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
556 myGroup = SMESH::SMESH_Group::_nil();
557 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
558 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
560 // NPAL19389: create a group with a selection in another group
561 // set actor of myMesh, if it is visible, else try
562 // any visible actor of group or submesh of myMesh
563 SetAppropriateActor();
565 setDefaultGroupColor();
570 mySelectionMgr->selectedObjects( aList );
571 if( !aList.IsEmpty() )
573 QString aName = aList.First()->getName();
574 myMeshGroupLine->setText(aName);//??????
575 myMeshGroupLine->home( false );
578 myCurrentLineEdit = 0;
580 myTypeGroup->button(0)->setChecked(true);
584 //=================================================================================
587 //=================================================================================
588 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
589 const bool theIsConvert)
591 restoreShowEntityMode();
592 myMesh = theGroup->GetMesh();
595 myNameChanged = true;
596 myName->blockSignals(true);
597 myName->setText(QString::fromUtf8(theGroup->GetName()));
598 myName->blockSignals(false);
601 SALOMEDS::Color aColor = theGroup->GetColor();
602 setGroupColor( aColor );
604 myMeshGroupLine->setText(QString::fromUtf8(theGroup->GetName()));
607 switch(theGroup->GetType()) {
608 case SMESH::NODE: aType = grpNodeSelection; break;
609 case SMESH::ELEM0D: aType = grp0DSelection; break;
610 case SMESH::BALL: aType = grpBallSelection; break;
611 case SMESH::EDGE: aType = grpEdgeSelection; break;
612 case SMESH::FACE: aType = grpFaceSelection; break;
613 case SMESH::VOLUME: aType = grpVolumeSelection; break;
615 myTypeGroup->button(aType)->setChecked(true);
617 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
618 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
619 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
620 myFilter = SMESH::Filter::_nil();
622 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
625 // NPAL19389: create a group with a selection in another group
626 // set actor of myMesh, if it is visible, else set
627 // actor of theGroup, if it is visible, else try
628 // any visible actor of group or submesh of myMesh
629 // commented, because an attempt to set selection on not displayed cells leads to error
630 SetAppropriateActor();
632 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
634 anActor = SMESH::FindActorByObject(theGroup);
635 SMESH::SetPickable(anActor);*/
637 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
638 myGrpTypeGroup->button(grpType)->setChecked(true);
639 onGrpTypeChanged(grpType);
642 if ( grpType == 0 ) { // standalone group
643 myCurrentLineEdit = 0;
645 myAllowElemsModif->setChecked( true );
647 setSelectionMode(aType);
649 setShowEntityMode(); // depends on myTypeId
652 if (!theGroup->IsEmpty()) {
653 SMESH::long_array_var anElements = theGroup->GetListOfID();
654 int k = anElements->length();
655 for (int i = 0; i < k; i++) {
656 myIdList.append(anElements[i]);
657 myElements->addItem(QString::number(anElements[i]));
659 myElements->selectAll();
662 else if ( grpType == 1 ) // group on geom
664 QString aShapeName( "" );
665 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
666 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
667 if (!aGroupShape->_is_nil())
669 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
671 aShapeName = aGroupShapeSO->GetName().c_str();
673 myGeomGroupLine->setText( aShapeName );
675 else // group on filter
677 myFilter = myGroupOnFilter->GetFilter();
678 if ( !myFilter->_is_nil() ) {
679 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
680 if ( perdicate->_is_nil() )
681 myFilter = SMESH::Filter::_nil();
687 myNameChanged = true;
688 myName->blockSignals(true);
689 myName->setText(QString::fromUtf8(theGroup->GetName()));
690 myName->blockSignals(false);
693 onSelectAll(); //updateButtons();
696 //=================================================================================
697 // function : updateButtons()
699 //=================================================================================
700 void SMESHGUI_GroupDlg::updateButtons()
702 bool enable = !myName->text().trimmed().isEmpty();
705 if (myGrpTypeId == 0) { // standalone
706 if ( !mySelectAll->isChecked() )
708 if ( myAllowElemsModif->isChecked() )
710 enable = ( myElements->count() > 0 );
712 else if ((enable = !myFilter->_is_nil() ))
714 SMESH::array_of_ElementType_var types = myFilter->GetTypes();
715 enable = types->length();
718 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
720 else if (myGrpTypeId == 1) // on geom
722 if (CORBA::is_nil(myGroupOnGeom)) // creation mode
723 enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
725 else if (myGrpTypeId == 2) // on filter
727 if (( enable = !myFilter->_is_nil() ))
728 if (CORBA::is_nil(myGroupOnFilter) ) // creation mode
729 enable = !myMesh->_is_nil();
733 myOKBtn->setEnabled(enable);
734 myApplyBtn->setEnabled(enable);
737 //=================================================================================
738 // function : onNameChanged()
740 //=================================================================================
741 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
743 myOldName = myName->text();
745 myNameChanged = !myName->text().trimmed().isEmpty();
748 //=================================================================================
749 // function : onTypeChanged()
750 // purpose : Group elements type radio button management
751 //=================================================================================
752 void SMESHGUI_GroupDlg::onTypeChanged (int id)
754 if (myTypeId != id) {
757 if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
758 setSelectionMode(id);
760 setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
762 onObjectSelectionChanged();
767 //=================================================================================
768 // function : onGrpTypeChanged()
769 // purpose : Group type radio button management
770 //=================================================================================
771 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
773 if (myGrpTypeId != id) {
775 myWGStack->setCurrentIndex( id );
776 myName->blockSignals(true);
777 myName->setText(myOldName);
778 myName->blockSignals(false);
779 onSelectGeomGroup(id != 0);
784 //=================================================================================
785 // function : onColorChanged()
786 // purpose : Color button management
787 //=================================================================================
788 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
793 //=================================================================================
794 // function : setSelectionMode()
795 // purpose : Radio button management
796 //=================================================================================
797 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
800 if (myMesh->_is_nil())
802 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
803 bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
804 if (mySelectionMode != theMode) {
805 // [PAL10408] mySelectionMgr->clearSelected();
806 mySelectionMgr->clearFilters();
807 SMESH::RemoveFilters();
809 if (myActorsList.count() > 0)
810 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
811 it.next()->SetPointRepresentation(false);
813 SMESH::SetPointRepresentation(false);
816 case grpNodeSelection:
817 if ( myGrpTypeId == 0 ) // standalone
819 if (myActorsList.count() > 0)
820 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
821 it.next()->SetPointRepresentation(true);
823 SMESH::SetPointRepresentation(true);
825 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
827 case grpEdgeSelection:
828 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
830 case grpBallSelection:
831 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
834 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : Elem0DSelection);
836 case grpFaceSelection:
837 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
839 case grpVolumeSelection:
840 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
842 case grpSubMeshSelection: {
844 SMESH_TypeFilter* f = 0;
846 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH); break;
847 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_EDGE); break;
848 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_FACE); break;
849 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_SOLID); break;
850 default: f = new SMESH_TypeFilter(SMESH::SUBMESH);
852 QList<SUIT_SelectionFilter*> filtList;
853 filtList.append( f );
854 filtList.append( new SMESH_TypeFilter(SMESH::SUBMESH_COMPOUND));
855 mySubMeshFilter->setFilters( filtList );
857 mySelectionMgr->installFilter( mySubMeshFilter );
859 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
862 case grpGroupSelection: {
864 SMESH_TypeFilter* f = 0;
866 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_NODE); break;
867 case grp0DSelection: f = new SMESH_TypeFilter(SMESH::GROUP_0D); break;
868 case grpBallSelection: f = new SMESH_TypeFilter(SMESH::GROUP_BALL); break;
869 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_EDGE); break;
870 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::GROUP_FACE); break;
871 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_VOLUME); break;
872 default: f = new SMESH_TypeFilter(SMESH::GROUP);
874 QList<SUIT_SelectionFilter*> filtList;
875 filtList.append( f );
876 myGroupFilter->setFilters( filtList );
878 mySelectionMgr->installFilter(myGroupFilter);
879 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
882 case grpMeshSelection:
883 mySelectionMgr->installFilter(myMeshFilter);
884 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
886 case grpGeomSelection:
887 mySelectionMgr->installFilter(myGeomFilter);
888 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
891 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
894 if ( aViewWindow ) aViewWindow->Repaint();
895 mySelectionMode = theMode;
899 //=================================================================================
900 // function : onApply()
902 //=================================================================================
903 bool SMESHGUI_GroupDlg::onApply()
905 if (mySMESHGUI->isActiveStudyLocked())
908 if (myName->text().trimmed().isEmpty())
911 SMESH::ElementType aType = SMESH::ALL;
913 case grpNodeSelection: aType = SMESH::NODE; break;
914 case grp0DSelection: aType = SMESH::ELEM0D; break;
915 case grpBallSelection: aType = SMESH::BALL; break;
916 case grpEdgeSelection: aType = SMESH::EDGE; break;
917 case grpFaceSelection: aType = SMESH::FACE; break;
918 case grpVolumeSelection: aType = SMESH::VOLUME; break;
922 QStringList anEntryList;
924 SMESH::SMESH_GroupBase_var resultGroup;
925 bool isCreation, isConversion = false;
927 SUIT_OverrideCursor wc;
929 if (myGrpTypeId == 0) // standalone
931 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
934 mySelectionMgr->clearSelected();
936 if (myGroup->_is_nil()) { // creation or conversion
937 // check if group on geometry is not null
938 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
939 if (myMesh->_is_nil())
941 if ( myGroupOnGeom->_is_nil() )
942 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
944 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
946 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
947 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
952 if (myGroup->_is_nil()) { // creation
953 if (myMesh->_is_nil())
956 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
958 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
961 if ( mySelectAll->isChecked() ) {
963 myGroup->AddFrom(myMesh.in());
968 if ( !myFilter->_is_nil() &&
969 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
971 myGroup->AddFrom( myFilter );
975 SMESH::long_array_var anIdList = new SMESH::long_array;
976 int i, k = myElements->count();
978 for (i = 0; i < k; i++) {
979 anIdList[i] = myElements->item(i)->text().toInt();
981 myGroup->Add(anIdList.inout());
988 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
991 if ( mySelectAll->isChecked() ) {
994 myGroup->AddFrom(myMesh.in());
999 int i, total = myElements->count();
1000 for (i = 0; i < total; i++) {
1001 int anId = myElements->item(i)->text().toInt();
1002 int idx = myIdList.indexOf(anId);
1004 aAddList.append(anId);
1006 myIdList.removeAt(idx);
1008 if (!aAddList.empty()) {
1009 SMESH::long_array_var anIdList = new SMESH::long_array;
1010 int added = aAddList.count();
1011 anIdList->length(added);
1012 for (i = 0; i < added; i++)
1013 anIdList[i] = aAddList[i];
1014 myGroup->Add(anIdList.inout());
1016 if (!myIdList.empty()) {
1017 SMESH::long_array_var anIdList = new SMESH::long_array;
1018 int removed = myIdList.count();
1019 anIdList->length(removed);
1020 for (i = 0; i < removed; i++)
1021 anIdList[i] = myIdList[i];
1022 myGroup->Remove(anIdList.inout());
1024 /* init for next operation */
1026 for (i = 0; i < total; i++) {
1027 myIdList.append(myElements->item(i)->text().toInt());
1034 else if (myGrpTypeId == 1) // on geom object
1036 if (CORBA::is_nil(myGroupOnGeom)) { // creation
1037 if (myMesh->_is_nil() || !myGeomObjects->length())
1040 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1042 if (myGeomObjects->length() == 1) {
1043 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1044 myName->text().toUtf8().data(),
1048 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1049 if ( aSMESHGen->_is_nil() )
1052 // create a geometry group
1053 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1054 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1056 if (geomGen->_is_nil() || !aStudy)
1059 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
1063 // check and add all selected GEOM objects: they must be
1064 // a sub-shapes of the main GEOM and must be of one type
1065 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1066 for ( int i =0; i < myGeomObjects->length(); i++) {
1067 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1069 aGroupType = aSubShapeType;
1070 else if (aSubShapeType != aGroupType) {
1071 aGroupType = TopAbs_SHAPE;
1076 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1077 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1078 op->UnionList(aGroupVar, myGeomObjects);
1081 // publish the GEOM group in study
1082 QString aNewGeomGroupName ( "Auto_group_for_" );
1083 aNewGeomGroupName += myName->text();
1084 SALOMEDS::SObject_var aNewGroupSO =
1085 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
1086 aNewGeomGroupName.toUtf8().data(), aMeshShape);
1089 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1090 myName->text().toUtf8().data(),
1093 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1099 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1104 if (myGrpTypeId == 2) // group on filter
1106 if ( myFilter->_is_nil() ) return false;
1108 if (CORBA::is_nil(myGroupOnFilter)) { // creation
1109 if (myMesh->_is_nil())
1112 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1113 myName->text().toUtf8().data(),
1116 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1121 myGroupOnFilter->SetFilter( myFilter );
1123 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1131 SALOMEDS::Color aColor = getGroupColor();
1132 resultGroup->SetColor(aColor);
1134 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1136 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1140 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1142 /* init for the next operation */
1144 myElements->clear();
1145 myGroup = SMESH::SMESH_Group::_nil();
1146 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1147 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1148 myFilter = SMESH::Filter::_nil();
1150 setDefaultGroupColor(); // reset color for case if 'auto-color' feature is enabled.
1154 resultGroup->SetName(myName->text().toUtf8().data());
1158 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
1159 if ( isConversion ) { // need to reset TVisualObj and actor
1160 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1161 SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
1162 SMESH::Update( anIO,true);
1163 myActorsList.clear();
1164 anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1165 if ( !anActor ) return false;
1166 myActorsList.append( anActor );
1168 anActor->setName(myName->text().toUtf8().data());
1171 switch ( myTypeId ) {
1172 case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1173 case grp0DSelection: anActor->Set0DColor ( aColor.R, aColor.G, aColor.B ); break;
1174 case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1175 case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1176 case grpVolumeSelection:
1177 SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
1178 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1180 case grpFaceSelection:
1182 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1183 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1189 SMESHGUI::Modified();
1190 mySMESHGUI->updateObjBrowser(true);
1191 SMESH::UpdateView(); // asv: fix of BUG PAL5515
1192 mySelectionMgr->clearSelected();
1194 if( LightApp_Application* anApp =
1195 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1196 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1201 //=================================================================================
1202 // function : onOK()
1204 //=================================================================================
1205 void SMESHGUI_GroupDlg::onOK()
1207 setIsApplyAndClose( true );
1210 setIsApplyAndClose( false );
1212 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
1215 //=================================================================================
1216 // function : onListSelectionChanged()
1217 // purpose : Called when selection in element list is changed
1218 //=================================================================================
1219 void SMESHGUI_GroupDlg::onListSelectionChanged()
1221 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1222 if( myIsBusy || myActorsList.count() == 0 ) return;
1225 if (myCurrentLineEdit == 0) {
1226 mySelectionMgr->clearSelected();
1227 TColStd_MapOfInteger aIndexes;
1228 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1229 QListWidgetItem* anItem;
1230 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1231 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1232 SALOME_ListIO aList;
1233 aList.Append(myActorsList.first()->getIO());
1234 mySelectionMgr->setSelectedObjects(aList,false);
1239 //=================================================================================
1240 // function : onObjectSelectionChanged()
1241 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1242 //=================================================================================
1243 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1245 if ( myIsBusy || !isEnabled()) return;
1246 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1250 SALOME_ListIO aList;
1251 mySelectionMgr->selectedObjects( aList );
1253 int aNbSel = aList.Extent();
1254 myElements->clearSelection();
1256 if (myCurrentLineEdit)
1258 myCurrentLineEdit->setText( "" );
1259 QString aString = "";
1261 if (myCurrentLineEdit == myMeshGroupLine)
1263 mySelectSubMesh->setEnabled(false);
1264 mySelectGroup->setEnabled(false);
1265 myGroupLine->setText( "" );
1266 mySubMeshLine->setText( "" );
1268 myGeomGroupBtn->setEnabled(false);
1269 myGeomGroupLine->setEnabled(false);
1270 myGeomGroupLine->setText( "" );
1271 myGeomObjects = new GEOM::ListOfGO();
1272 myGeomObjects->length(0);
1274 if (myGeomGroupBtn->isChecked())
1275 myGeomGroupBtn->setChecked(false);
1277 myName->setText( "" );
1279 myElements->clear();
1282 myGroup = SMESH::SMESH_Group::_nil();
1283 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1284 restoreShowEntityMode();
1285 myMesh = SMESH::SMESH_Mesh::_nil();
1291 Handle(SALOME_InteractiveObject) IO = aList.First();
1294 restoreShowEntityMode();
1295 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1296 setShowEntityMode();
1298 if (myMesh->_is_nil())
1305 if ( myFilterDlg && !myMesh->_is_nil()){
1306 myFilterDlg->SetMesh( myMesh );
1308 myGroup = SMESH::SMESH_Group::_nil();
1310 // NPAL19389: create a group with a selection in another group
1311 // set actor of myMesh, if it is visible, else try
1312 // any visible actor of group or submesh of myMesh
1313 SetAppropriateActor();
1315 aString = aList.First()->getName();
1316 myMeshGroupLine->setText(aString);
1317 myMeshGroupLine->home( false );
1319 mySelectSubMesh->setEnabled(true);
1320 mySelectGroup->setEnabled(true);
1321 myGeomGroupBtn->setEnabled(true);
1322 myGeomGroupLine->setEnabled(true);
1326 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1327 if (aGroup->_is_nil())
1334 myGroup = SMESH::SMESH_Group::_nil();
1335 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1339 mySelectSubMesh->setEnabled(true);
1340 mySelectGroup->setEnabled(true);
1342 myCurrentLineEdit = 0;
1347 if (myGrpTypeId == 0)
1353 myElements->clear();
1354 setSelectionMode(myTypeId);
1362 else if (myCurrentLineEdit == myGeomGroupLine)
1364 myGeomObjects = new GEOM::ListOfGO();
1367 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1369 if (aNbSel == 0 || !aMeshSO)
1371 myGeomObjects->length(0);
1377 myGeomObjects->length(aNbSel);
1379 GEOM::GEOM_Object_var aGeomGroup;
1382 SALOME_ListIteratorOfListIO anIt (aList);
1383 for (; anIt.More(); anIt.Next())
1385 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1387 // Check if the object is a geometry group
1388 if (CORBA::is_nil(aGeomGroup))
1391 // Check if group constructed on the same shape as a mesh or on its child
1392 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1394 // The main shape of the group
1395 GEOM::GEOM_Object_var aGroupMainShape;
1396 if (aGeomGroup->GetType() == 37) {
1397 GEOM::GEOM_IGroupOperations_wrap anOp =
1398 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1399 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1400 // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
1403 aGroupMainShape = aGeomGroup;
1404 aGroupMainShape->Register();
1406 _PTR(SObject) aGroupMainShapeSO =
1407 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1409 _PTR(SObject) anObj, aRef;
1410 bool isRefOrSubShape = false;
1411 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1412 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1413 isRefOrSubShape = true;
1415 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1416 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1417 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1418 if (aRef->GetID() == aFather->GetID())
1419 isRefOrSubShape = true;
1421 aFather = aFather->GetFather();
1425 if (isRefOrSubShape)
1426 myGeomObjects[i++] = aGeomGroup;
1429 myGeomObjects->length(i);
1441 if (myCurrentLineEdit == mySubMeshLine)
1442 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1443 else if (myCurrentLineEdit == myGroupLine)
1444 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1445 else if (myCurrentLineEdit == myGeomGroupLine)
1446 aString = tr( "%1 Objects" ).arg(aNbSel);
1449 aString = aList.First()->getName();
1453 myCurrentLineEdit->setText(aString);
1454 myCurrentLineEdit->home(false);
1455 // 07.06.2008 skl for IPAL19574:
1456 // change name of group only if it is empty
1457 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1458 myOldName = myName->text();
1459 myName->blockSignals(true);
1460 myName->setText(aString);
1461 myName->blockSignals(false);
1466 else // !myCurrentLineEdit: local selection of nodes or elements
1468 if (aNbSel == 1 && myActorsList.count() > 0 )
1470 // NPAL19389: create a group with a selection in another group
1471 // Switch myActor to the newly selected one, if the last
1472 // is visible and belongs to group or submesh of myMesh
1473 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1474 Handle(SALOME_InteractiveObject) selIO = aList.First();
1475 if (curIO->hasEntry() && selIO->hasEntry()) {
1476 const char* selEntry = selIO->getEntry();
1477 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1478 // different objects: selected and myActor
1479 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1480 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1481 // newly selected actor is visible
1484 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1486 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1487 int len = strlen(meshEntry);
1489 if (strncmp(selEntry, meshEntry, len) == 0) {
1490 // selected object is myMesh or a part of it
1491 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1494 SMESH::SetPickable(myActor);
1503 QString aListStr = "";
1505 if (myTypeId == 0) {
1506 QListIterator<SMESH_Actor*> it( myActorsList );
1507 while ( it.hasNext() ) {
1509 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1513 QListIterator<SMESH_Actor*> it( myActorsList );
1514 while ( it.hasNext() ) {
1516 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1521 QListWidgetItem* anItem;
1522 QList<QListWidgetItem*> listItemsToSel;
1523 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1524 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1525 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1526 foreach(anItem, found)
1527 if (!anItem->isSelected())
1528 listItemsToSel.push_back(anItem);
1530 bool blocked = myElements->signalsBlocked();
1531 myElements->blockSignals(true);
1532 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1533 myElements->blockSignals(blocked);
1534 onListSelectionChanged();
1535 listItemsToSel.clear();
1540 if (myActorsList.count() == 0) {
1541 if (!myGroup->_is_nil()) {
1542 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1544 myActorsList.append( anActor );
1546 else if(!myGroupOnGeom->_is_nil()) {
1547 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1549 myActorsList.append( anActor );
1552 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1554 myActorsList.append( anActor );
1558 // somehow, if we display the mesh, while selecting from another actor,
1559 // the mesh becomes pickable, and there is no way to select any element
1560 if (myActorsList.count() > 0) {
1561 QListIterator<SMESH_Actor*> it( myActorsList );
1562 while ( it.hasNext() ) {
1563 SMESH_Actor* anActor = it.next();
1564 if ( IsActorVisible(anActor) )
1565 anActor->SetPickable(true);
1572 //=================================================================================
1573 // function : onSelectAll()
1574 // purpose : Called when "Select all" is checked
1575 //=================================================================================
1576 void SMESHGUI_GroupDlg::onSelectAll()
1578 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1580 myElementsLab->setEnabled( !noElemsModif );
1581 myElements->setEnabled ( !noElemsModif );
1582 myFilterBtn->setEnabled ( !noElemsModif );
1583 myAddBtn->setEnabled ( !noElemsModif );
1584 myRemoveBtn->setEnabled ( !noElemsModif );
1585 mySortBtn->setEnabled ( !noElemsModif );
1586 mySelectBox->setEnabled ( !noElemsModif );
1587 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1589 int selMode = mySelectionMode;
1590 mySelectionMode = grpNoSelection;
1591 setSelectionMode( selMode );
1595 //=================================================================================
1596 // function : onSelectSubMesh()
1597 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1598 //=================================================================================
1599 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1602 if (mySelectGroup->isChecked()) {
1603 mySelectGroup->setChecked(false);
1605 //VSR: else if (mySelectGeomGroup->isChecked()) {
1606 //VSR: mySelectGeomGroup->setChecked(false);
1608 myCurrentLineEdit = mySubMeshLine;
1609 setSelectionMode(grpSubMeshSelection);
1612 mySubMeshLine->setText( "" );
1613 myCurrentLineEdit = 0;
1615 setSelectionMode(myTypeId);
1617 mySubMeshBtn->setEnabled(on);
1618 mySubMeshLine->setEnabled(on);
1622 //=================================================================================
1623 // function : (onSelectGroup)
1624 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1625 //=================================================================================
1626 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1629 if (mySelectSubMesh->isChecked()) {
1630 mySelectSubMesh->setChecked(false);
1632 myCurrentLineEdit = myGroupLine;
1633 setSelectionMode(grpGroupSelection);
1636 myGroupLine->setText( "" );
1637 myCurrentLineEdit = 0;
1639 setSelectionMode(myTypeId);
1641 myGroupBtn->setEnabled(on);
1642 myGroupLine->setEnabled(on);
1646 //=================================================================================
1647 // function : (onSelectGeomGroup)
1648 // purpose : Called when group type changed. on == "on group" or "on filter"
1649 //=================================================================================
1650 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1653 if (mySelectSubMesh->isChecked()) {
1654 mySelectSubMesh->setChecked(false);
1656 else if (mySelectGroup->isChecked()) {
1657 mySelectGroup->setChecked(false);
1659 if ( myGrpTypeId == 1 ) { // on group
1660 myCurrentLineEdit = myGeomGroupLine;
1664 myCurrentLineEdit = 0;
1666 setSelectionMode(grpAllSelection);
1669 myGeomGroupBtn->setChecked(false);
1670 myGeomObjects->length(0);
1671 myGeomGroupLine->setText( "" );
1672 myCurrentLineEdit = 0;
1674 setSelectionMode( myTypeId );
1678 //=================================================================================
1679 // function : setCurrentSelection()
1681 //=================================================================================
1682 void SMESHGUI_GroupDlg::setCurrentSelection()
1684 QPushButton* send = (QPushButton*)sender();
1685 myCurrentLineEdit = 0;
1686 if (send == myMeshGroupBtn) {
1687 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1688 mySelectionMgr->clearSelected();
1690 setSelectionMode(grpMeshSelection);
1692 setSelectionMode(grpGroupSelection);
1693 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1694 myCurrentLineEdit = myMeshGroupLine;
1695 onObjectSelectionChanged();
1697 else if (send == mySubMeshBtn) {
1698 myCurrentLineEdit = mySubMeshLine;
1699 onObjectSelectionChanged();
1701 else if (send == myGroupBtn) {
1702 myCurrentLineEdit = myGroupLine;
1703 onObjectSelectionChanged();
1708 //=================================================================================
1709 // function : setFilters()
1710 // purpose : SLOT. Called when "Filter" button pressed.
1711 //=================================================================================
1712 void SMESHGUI_GroupDlg::setFilters()
1714 if(myMesh->_is_nil()) {
1715 SUIT_MessageBox::critical(this,
1717 tr("NO_MESH_SELECTED"));
1721 SMESH::ElementType aType = SMESH::ALL;
1724 case grpNodeSelection: aType = SMESH::NODE; break;
1725 case grp0DSelection: aType = SMESH::ELEM0D; break;
1726 case grpBallSelection: aType = SMESH::BALL; break;
1727 case grpEdgeSelection: aType = SMESH::EDGE; break;
1728 case grpFaceSelection: aType = SMESH::FACE; break;
1729 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1733 if ( myFilterDlg == 0 )
1735 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1736 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1739 myFilterDlg->Init( aType );
1741 if ( !myGroupOnFilter->_is_nil() )
1743 myFilterDlg->SetFilter( myFilter, aType );
1744 myFilterDlg->Init( aType );
1747 myFilterDlg->SetMesh( myMesh );
1748 myFilterDlg->SetSelection();
1749 myFilterDlg->SetSourceWg( myElements, false );
1751 myFilterDlg->show();
1754 //=================================================================================
1755 // function : onFilterAccepted()
1756 // purpose : SLOT. Called when Filter dlg closed with OK button.
1757 // Uncheck "Select submesh" and "Select group" checkboxes
1758 //=================================================================================
1759 void SMESHGUI_GroupDlg::onFilterAccepted()
1761 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1763 mySelectionMode = myTypeId;
1764 mySelectSubMesh->setChecked( false );
1765 mySelectGroup->setChecked( false );
1767 // get a filter from myFilterDlg
1768 myFilter = myFilterDlg->GetFilter();
1769 if ( !myFilter->_is_nil() ) {
1770 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1771 if ( perdicate->_is_nil() )
1772 myFilter = SMESH::Filter::_nil();
1774 // set mesh to myFilter
1775 if ( !myFilter->_is_nil() ) {
1776 SMESH::SMESH_Mesh_var mesh = myMesh;
1777 if ( mesh->_is_nil() ) {
1778 if ( !myGroup->_is_nil() )
1779 mesh = myGroup->GetMesh();
1780 else if ( !myGroupOnGeom->_is_nil() )
1781 mesh = myGroupOnGeom->GetMesh();
1782 else if ( !myGroupOnFilter->_is_nil() )
1783 mesh = myGroupOnFilter->GetMesh();
1785 myFilter->SetMesh( mesh );
1791 //=================================================================================
1792 // function : onAdd()
1794 //=================================================================================
1795 void SMESHGUI_GroupDlg::onAdd()
1797 SALOME_ListIO aList;
1798 mySelectionMgr->selectedObjects( aList );
1800 int aNbSel = aList.Extent();
1802 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1805 int sizeBefore = myElements->count();
1807 SMESH::ElementType aType = SMESH::ALL;
1809 case grpNodeSelection:
1810 aType = SMESH::NODE;
1811 mySelector->SetSelectionMode(NodeSelection);
1813 case grpBallSelection:
1814 aType = SMESH::BALL;
1815 mySelector->SetSelectionMode(BallSelection);
1817 case grp0DSelection:
1818 aType = SMESH::ELEM0D;
1819 mySelector->SetSelectionMode(Elem0DSelection);
1821 case grpEdgeSelection:
1822 aType = SMESH::EDGE;
1823 mySelector->SetSelectionMode(EdgeSelection);
1825 case grpFaceSelection:
1826 aType = SMESH::FACE;
1827 mySelector->SetSelectionMode(FaceSelection);
1829 case grpVolumeSelection:
1830 aType = SMESH::VOLUME;
1831 mySelector->SetSelectionMode(VolumeSelection);
1834 mySelector->SetSelectionMode(ActorSelection);
1837 QListWidgetItem* anItem = 0;
1838 QList<QListWidgetItem*> listItemsToSel;
1840 if (myCurrentLineEdit == 0) {
1841 //if (aNbSel != 1) { myIsBusy = false; return; }
1842 QString aListStr = "";
1844 if (myTypeId == 0) {
1845 QListIterator<SMESH_Actor*> it( myActorsList );
1846 while ( it.hasNext() ) {
1848 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1853 QListIterator<SMESH_Actor*> it( myActorsList );
1854 while ( it.hasNext() ) {
1856 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1861 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1862 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1863 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1864 if (found.count() == 0) {
1865 anItem = new QListWidgetItem(*it);
1866 myElements->addItem(anItem);
1867 if (!anItem->isSelected())
1868 listItemsToSel.push_back(anItem);
1871 foreach(anItem, found)
1872 if (!anItem->isSelected())
1873 listItemsToSel.push_back(anItem);
1876 bool blocked = myElements->signalsBlocked();
1877 myElements->blockSignals(true);
1878 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1879 myElements->blockSignals(blocked);
1880 onListSelectionChanged();
1881 listItemsToSel.clear();
1883 } else if (myCurrentLineEdit == mySubMeshLine) {
1884 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1886 SALOME_ListIO aList;
1887 mySelectionMgr->selectedObjects( aList );
1889 SALOME_ListIteratorOfListIO anIt (aList);
1890 for ( ; anIt.More(); anIt.Next()) {
1891 SMESH::SMESH_subMesh_var aSubMesh =
1892 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1893 if (!aSubMesh->_is_nil()) {
1894 // check if mesh is the same
1895 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1897 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1898 int k = anElements->length();
1899 for (int i = 0; i < k; i++) {
1900 QString aText = QString::number(anElements[i]);
1901 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1902 if (found.count() == 0) {
1903 anItem = new QListWidgetItem(aText);
1904 myElements->addItem(anItem);
1905 if (!anItem->isSelected())
1906 listItemsToSel.push_back(anItem);
1909 foreach(anItem, found)
1910 if (!anItem->isSelected())
1911 listItemsToSel.push_back(anItem);
1914 bool blocked = myElements->signalsBlocked();
1915 myElements->blockSignals(true);
1916 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1917 myElements->blockSignals(blocked);
1918 onListSelectionChanged();
1919 listItemsToSel.clear();
1921 catch (const SALOME::SALOME_Exception& ex) {
1922 SalomeApp_Tools::QtCatchCorbaException(ex);
1927 mySelectSubMesh->setChecked(false);
1929 onListSelectionChanged();
1931 } else if (myCurrentLineEdit == myGroupLine) {
1932 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1933 SALOME_ListIO aList;
1934 mySelectionMgr->selectedObjects( aList );
1936 SALOME_ListIteratorOfListIO anIt (aList);
1937 for ( ; anIt.More(); anIt.Next()) {
1938 SMESH::SMESH_GroupBase_var aGroup =
1939 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1940 if (!aGroup->_is_nil()) {
1941 // check if mesh is the same
1942 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1943 SMESH::long_array_var anElements = aGroup->GetListOfID();
1944 int k = anElements->length();
1945 for (int i = 0; i < k; i++) {
1946 QString aText = QString::number(anElements[i]);
1947 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1948 if (found.count() == 0) {
1949 anItem = new QListWidgetItem(aText);
1950 myElements->addItem(anItem);
1951 if (!anItem->isSelected())
1952 listItemsToSel.push_back(anItem);
1955 foreach(anItem, found)
1956 if (!anItem->isSelected())
1957 listItemsToSel.push_back(anItem);
1960 bool blocked = myElements->signalsBlocked();
1961 myElements->blockSignals(true);
1962 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1963 myElements->blockSignals(blocked);
1964 onListSelectionChanged();
1965 listItemsToSel.clear();
1969 mySelectGroup->setChecked(false);
1971 onListSelectionChanged();
1973 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1974 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1975 GEOM::GEOM_IGroupOperations_wrap aGroupOp =
1976 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1978 SMESH::ElementType aGroupType = SMESH::ALL;
1979 switch(aGroupOp->GetType(myGeomObjects[0])) {
1980 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
1981 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
1982 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
1983 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
1984 default: myIsBusy = false; return;
1987 if (aGroupType == aType) {
1988 _PTR(SObject) aGroupSO =
1989 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1990 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1992 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1993 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1994 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
1995 aBelongToGeom->SetGeom(myGeomObjects[0]);
1996 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1997 aBelongToGeom->SetElementType(aType);
1998 aFilter->SetPredicate(aBelongToGeom);
2000 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
2002 int k = anElements->length();
2003 for (int i = 0; i < k; i++) {
2004 QString aText = QString::number(anElements[i]);
2005 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2006 if (found.count() == 0) {
2007 anItem = new QListWidgetItem(aText);
2008 myElements->addItem(anItem);
2009 if (!anItem->isSelected())
2010 listItemsToSel.push_back(anItem);
2013 foreach(anItem, found)
2014 if (!anItem->isSelected())
2015 listItemsToSel.push_back(anItem);
2018 bool blocked = myElements->signalsBlocked();
2019 myElements->blockSignals(true);
2020 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2021 myElements->blockSignals(blocked);
2022 onListSelectionChanged();
2023 listItemsToSel.clear();
2026 //VSR: mySelectGeomGroup->setChecked(false);
2028 onListSelectionChanged();
2031 if ( sizeBefore < myElements->count() )
2032 ++myNbChangesOfContents;
2033 // mySelectionMgr->clearSelected();
2037 //=================================================================================
2038 // function : onRemove()
2040 //=================================================================================
2041 void SMESHGUI_GroupDlg::onRemove()
2044 int sizeBefore = myElements->count();
2046 if (myCurrentLineEdit == 0) {
2047 QList<QListWidgetItem*> selItems = myElements->selectedItems();
2048 QListWidgetItem* item;
2049 foreach(item, selItems) delete item;
2051 SALOME_ListIO aList;
2052 mySelectionMgr->selectedObjects( aList );
2054 int aNbSel = aList.Extent();
2056 if (aNbSel == 0) { myIsBusy = false; return; }
2058 SMESH::ElementType aType = SMESH::ALL;
2060 case grpNodeSelection: aType = SMESH::NODE; break;
2061 case grp0DSelection: aType = SMESH::ELEM0D; break;
2062 case grpBallSelection: aType = SMESH::BALL; break;
2063 case grpEdgeSelection: aType = SMESH::EDGE; break;
2064 case grpFaceSelection: aType = SMESH::FACE; break;
2065 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2068 if (myCurrentLineEdit == mySubMeshLine) {
2069 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2070 SALOME_ListIO aList;
2071 mySelectionMgr->selectedObjects( aList );
2073 SALOME_ListIteratorOfListIO anIt (aList);
2074 for ( ; anIt.More(); anIt.Next()) {
2075 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2076 if (!aSubMesh->_is_nil()) {
2077 // check if mesh is the same
2078 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2079 if (aType == SMESH::NODE) {
2081 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2082 int k = anElements->length();
2083 for (int i = 0; i < k; i++) {
2084 QList<QListWidgetItem*> found =
2085 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2086 QListWidgetItem* anItem;
2087 foreach(anItem, found) delete anItem;
2090 catch (const SALOME::SALOME_Exception& ex) {
2091 SalomeApp_Tools::QtCatchCorbaException(ex);
2096 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2097 int k = anElements->length();
2098 for (int i = 0; i < k; i++) {
2099 QList<QListWidgetItem*> found =
2100 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2101 QListWidgetItem* anItem;
2102 foreach(anItem, found) delete anItem;
2105 catch (const SALOME::SALOME_Exception& ex) {
2106 SalomeApp_Tools::QtCatchCorbaException(ex);
2113 else if (myCurrentLineEdit == myGroupLine) {
2114 Standard_Boolean aRes;
2115 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2116 SALOME_ListIO aList;
2117 mySelectionMgr->selectedObjects( aList );
2119 SALOME_ListIteratorOfListIO anIt (aList);
2120 for ( ; anIt.More(); anIt.Next()) {
2121 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2122 if (aRes && !aGroup->_is_nil()) {
2123 // check if mesh is the same
2124 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2125 SMESH::long_array_var anElements = aGroup->GetListOfID();
2126 int k = anElements->length();
2127 for (int i = 0; i < k; i++) {
2128 QList<QListWidgetItem*> found =
2129 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2130 QListWidgetItem* anItem;
2131 foreach(anItem, found) delete anItem;
2139 if ( sizeBefore > myElements->count() )
2140 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2144 //=================================================================================
2145 // function : onSort()
2147 //=================================================================================
2148 void SMESHGUI_GroupDlg::onSort()
2150 // PAL5412: sorts items in ascending by "string" value
2151 // myElements->sort(true);
2152 // myElements->update();
2153 int i, k = myElements->count();
2156 QList<int> aSelected;
2157 std::vector<int> anArray(k);
2158 // QMemArray<int> anArray(k);
2160 for (i = 0; i < k; i++) {
2161 int id = myElements->item(i)->text().toInt();
2163 if (myElements->item(i)->isSelected())
2164 aSelected.append(id);
2166 // sort & update list
2167 std::sort(anArray.begin(), anArray.end());
2169 myElements->clear();
2170 QListWidgetItem* anItem;
2171 QList<QListWidgetItem*> listItemsToSel;
2172 for (i = 0; i < k; i++) {
2173 anItem = new QListWidgetItem(QString::number(anArray[i]));
2174 myElements->addItem(anItem);
2175 if (aSelected.contains(anArray[i]))
2176 listItemsToSel.push_back(anItem);
2178 bool blocked = myElements->signalsBlocked();
2179 myElements->blockSignals(true);
2180 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2181 myElements->blockSignals(blocked);
2182 listItemsToSel.clear();
2187 //=================================================================================
2188 // function : onVisibilityChanged()
2190 //=================================================================================
2191 void SMESHGUI_GroupDlg::onVisibilityChanged()
2193 SetAppropriateActor();
2196 //=================================================================================
2197 // function : SMESHGUI_GroupDlg::reject
2198 // purpose : SLOT called when "Close" button pressed. Close dialog
2199 //=================================================================================
2200 void SMESHGUI_GroupDlg::reject()
2202 if (SMESH::GetCurrentVtkView()) {
2203 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2204 SMESH::SetPointRepresentation(false);
2205 SMESH::SetPickable();
2206 restoreShowEntityMode();
2209 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2210 SUIT_DataOwnerPtrList aList;
2211 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2212 mySelectionMgr->setSelected( aList );
2215 mySelectionMgr->clearSelected();
2216 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2217 aViewWindow->SetSelectionMode(ActorSelection);
2218 mySelectionMgr->clearFilters();
2219 mySMESHGUI->ResetState();
2223 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
2226 //=================================================================================
2227 // function : onHelp()
2229 //=================================================================================
2230 void SMESHGUI_GroupDlg::onHelp()
2232 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2234 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2238 platform = "winapplication";
2240 platform = "application";
2242 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2243 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2244 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2246 arg(myHelpFileName));
2250 //=================================================================================
2251 // function : SMESHGUI_GroupDlg::onDeactivate
2252 // purpose : SLOT called when dialog must be deativated
2253 //=================================================================================
2254 void SMESHGUI_GroupDlg::onDeactivate()
2256 mySMESHGUI->ResetState();
2260 //=================================================================================
2261 // function : SMESHGUI_GroupDlg::enterEvent
2262 // purpose : Event filter
2263 //=================================================================================
2264 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2267 mySMESHGUI->EmitSignalDeactivateDialog();
2269 mySelectionMode = grpNoSelection;
2270 setSelectionMode(myTypeId);
2271 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2272 mySMESHGUI->SetActiveDialogBox(this);
2273 mySMESHGUI->SetState(800);
2277 //=================================================================================
2278 // function : keyPressEvent()
2280 //=================================================================================
2281 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2283 QDialog::keyPressEvent( e );
2284 if ( e->isAccepted() )
2287 if ( e->key() == Qt::Key_F1 )
2294 //================================================================================
2296 * \brief Enable showing of the popup when Geometry selection btn is clicked
2297 * \param enable - true to enable
2299 //================================================================================
2301 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2303 void SMESHGUI_GroupDlg::updateGeomPopup()
2305 bool enable = false;
2307 if ( !myMesh->_is_nil() )
2308 enable = myMesh->NbEdges() > 0;
2310 if ( myGeomGroupBtn )
2312 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2314 if ( !myGeomPopup ) {
2315 myGeomPopup = new QMenu(this);
2316 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2317 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2318 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2320 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2326 //=================================================================================
2327 // function : onGeomSelectionButton()
2329 //=================================================================================
2330 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2332 if ( myGeomPopup && isBtnOn )
2334 myCurrentLineEdit = myGeomGroupLine;
2335 QAction* a = myGeomPopup->exec( QCursor::pos() );
2336 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2337 setSelectionMode(grpGeomSelection);
2341 myCurrentLineEdit = 0;
2342 setSelectionMode(grpAllSelection);
2346 //=================================================================================
2347 // function : onGeomPopup()
2349 //=================================================================================
2350 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2352 int index = myActions[a];
2353 if ( index == GEOM_BY_MESH_INDEX )
2355 mySelectionMode = grpNoSelection;
2356 if ( !myShapeByMeshOp ) {
2357 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2358 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2359 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2360 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2361 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2363 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2364 if ( !myMesh->_is_nil() ) {
2366 hide(); // stop processing selection
2368 myShapeByMeshOp->setModule( mySMESHGUI );
2369 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2370 myShapeByMeshOp->SetMesh( myMesh );
2371 myShapeByMeshOp->start();
2376 //================================================================================
2378 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2380 //================================================================================
2382 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2384 if ( myShapeByMeshOp == op ) {
2385 mySMESHGUI->getApp()->updateObjectBrowser();
2387 // Select a found geometry object
2388 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2389 if ( !aGeomVar->_is_nil() )
2391 QString ID = aGeomVar->GetStudyEntry();
2392 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2393 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2394 SALOME_ListIO anIOList;
2395 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2396 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2397 anIOList.Append( anIO );
2398 mySelectionMgr->setSelectedObjects( anIOList, false );
2399 onObjectSelectionChanged();
2405 //================================================================================
2407 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2409 //================================================================================
2411 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2413 if ( myShapeByMeshOp == op )
2416 setSelectionMode(grpGeomSelection);
2420 //=================================================================================
2421 // function : setGroupColor()
2423 //=================================================================================
2424 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2426 QColor aQColor( (int)( theColor.R * 255.0 ),
2427 (int)( theColor.G * 255.0 ),
2428 (int)( theColor.B * 255.0 ) );
2429 setGroupQColor( aQColor );
2432 //=================================================================================
2433 // function : getGroupColor()
2435 //=================================================================================
2436 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2438 QColor aQColor = getGroupQColor();
2440 SALOMEDS::Color aColor;
2441 aColor.R = (float)aQColor.red() / 255.0;
2442 aColor.G = (float)aQColor.green() / 255.0;
2443 aColor.B = (float)aQColor.blue() / 255.0;
2448 //=================================================================================
2449 // function : setGroupQColor()
2451 //=================================================================================
2452 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2454 if( theColor.isValid() )
2455 myColorBtn->setColor( theColor );
2458 //=================================================================================
2459 // function : getGroupQColor()
2461 //=================================================================================
2462 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2464 return myColorBtn->color();
2467 //=================================================================================
2468 // function : setDefaultGroupColor()
2470 //=================================================================================
2471 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2473 if( myMesh->_is_nil() )
2476 bool isAutoColor = myMesh->GetAutoColor();
2478 QColor aQColor = myColorBtn->color();
2481 if ( !aQColor.isValid() ) {
2482 int r = 0, g = 0, b = 0;
2483 SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2484 aQColor.setRgb( r, g, b );
2489 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2490 SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
2491 #else // old algorithm for auto-colors
2492 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2494 QList<SALOMEDS::Color> aReservedColors;
2495 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2497 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2498 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2499 aReservedColors.append( aReservedColor );
2502 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2503 #endif // SIMPLE_AUTOCOLOR
2505 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2506 (int)( aColor.G * 255.0 ),
2507 (int)( aColor.B * 255.0 ) );
2511 setGroupQColor( aQColor );
2514 //=================================================================================
2515 // function : SetAppropriateActor()
2516 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2517 // NPAL19389: create a group with a selection in another group.
2518 // if mesh actor is not visible - find any first visible group or submesh
2519 //=================================================================================
2520 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2522 bool isActor = false;
2523 myActorsList.clear();
2525 if (myMesh->_is_nil()) return false;
2527 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2529 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2531 if (!myGroupOnGeom->_is_nil()) {
2532 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2533 if (anActor && anActor->hasIO())
2536 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2539 myActorsList.append(anActor);
2545 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2546 if (anActor && anActor->hasIO()) {
2548 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2551 myActorsList.append(anActor);
2555 if (!isActor && !myGroup->_is_nil()) {
2556 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2557 if (anActor && anActor->hasIO())
2558 myActorsList.append(anActor);
2561 // try any visible actor of group or submesh of current mesh
2564 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2566 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2567 int len = strlen(meshEntry);
2569 // iterate on all actors in current view window, search for
2570 // any visible actor, that belongs to group or submesh of current mesh
2571 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2572 vtkActorCollection *aCollection = aCopy.GetActors();
2573 int nbItems = aCollection->GetNumberOfItems();
2574 for (int i=0; i<nbItems && !isActor; i++)
2576 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2577 if (anActor && anActor->hasIO()) {
2578 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2579 if (aViewWindow->isVisible(anIO)) {
2580 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2581 myActorsList.append(anActor);
2589 if (myActorsList.count() > 0) {
2590 QListIterator<SMESH_Actor*> it( myActorsList );
2591 while ( it.hasNext() ) {
2592 SMESH_Actor* anActor = it.next();
2593 if ( IsActorVisible(anActor) )
2594 anActor->SetPickable(true);
2598 return ( isActor || (myActorsList.count() > 0) );
2601 //=======================================================================
2602 //function : setShowEntityMode
2603 //purpose : make shown only entity corresponding to my type
2604 //=======================================================================
2605 void SMESHGUI_GroupDlg::setShowEntityMode()
2607 if ( !myMesh->_is_nil() ) {
2608 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2609 if (!myStoredShownEntity)
2610 myStoredShownEntity = actor->GetEntityMode();
2611 switch ( myTypeId ) {
2612 case grpNodeSelection: restoreShowEntityMode(); break;
2613 case grp0DSelection: actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
2614 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2615 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2616 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2617 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2623 //=======================================================================
2624 //function : restoreShowEntityMode
2625 //purpose : restore ShowEntity mode of myActor
2626 //=======================================================================
2627 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2629 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2630 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2631 actor->SetEntityMode(myStoredShownEntity);
2634 myStoredShownEntity = 0;
2637 //=======================================================================
2638 //function : IsActorVisible
2639 //purpose : return visibility of the actor
2640 //=======================================================================
2641 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2643 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2644 if (theActor && aViewWindow)
2645 return aViewWindow->isVisible(theActor->getIO());
2649 //================================================================
2650 //function : setIsApplyAndClose
2651 //purpose : Set value of the flag indicating that the dialog is
2652 // accepted by Apply & Close button
2653 //================================================================
2654 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2656 myIsApplyAndClose = theFlag;
2659 //================================================================
2660 //function : isApplyAndClose
2661 //purpose : Get value of the flag indicating that the dialog is
2662 // accepted by Apply & Close button
2663 //================================================================
2664 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2666 return myIsApplyAndClose;