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>
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>
57 #include <SalomeApp_Tools.h>
58 #include <SalomeApp_Application.h>
59 #include <SalomeApp_Study.h>
60 #include <LightApp_SelectionMgr.h>
62 #include <SALOME_ListIO.hxx>
63 #include <SALOME_ListIteratorOfListIO.hxx>
65 #include <SVTK_ViewWindow.h>
67 #include <VTKViewer_Algorithm.h>
69 // SALOME KERNEL includes
70 #include <SALOMEDSClient_Study.hxx>
73 #include <vtkRenderer.h>
74 #include <vtkActorCollection.h>
77 #include <TColStd_MapOfInteger.hxx>
80 #include <QButtonGroup>
84 #include <QPushButton>
85 #include <QToolButton>
86 #include <QRadioButton>
88 #include <QGridLayout>
89 #include <QHBoxLayout>
90 #include <QVBoxLayout>
91 #include <QListWidget>
92 #include <QStackedWidget>
104 enum grpSelectionMode {
106 grpNodeSelection = 0,
108 grpBallSelection = 2,
109 grpEdgeSelection = 3,
110 grpFaceSelection = 4,
111 grpVolumeSelection = 5,
112 grpSubMeshSelection = 6,
113 grpGroupSelection = 7,
114 grpMeshSelection = 8,
115 grpGeomSelection = 9,
116 grpAllSelection = 10,
119 //=================================================================================
120 // function : SMESHGUI_GroupDlg()
122 //=================================================================================
123 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
124 SMESH::SMESH_Mesh_ptr theMesh )
125 : QDialog( SMESH::GetDesktop( theModule ) ),
126 mySMESHGUI( theModule ),
127 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
128 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
130 myNameChanged( false ),
131 myIsApplyAndClose( false ),
132 myNbChangesOfContents(0)
135 if ( !theMesh->_is_nil() )
139 mySelectSubMesh->setEnabled( false );
140 mySelectGroup->setEnabled( false );
141 myGeomGroupBtn->setEnabled( false );
142 myGeomGroupLine->setEnabled( false );
146 //=================================================================================
147 // function : SMESHGUI_GroupDlg()
149 //=================================================================================
150 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
151 SMESH::SMESH_GroupBase_ptr theGroup,
152 const bool theIsConvert )
153 : QDialog( SMESH::GetDesktop( theModule ) ),
154 mySMESHGUI( theModule ),
155 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
156 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
158 myNameChanged( false ),
159 myNbChangesOfContents(0) // just not to use uninitialized variable
162 if ( !theGroup->_is_nil() )
163 init( theGroup, theIsConvert );
166 mySelectSubMesh->setEnabled( false );
167 mySelectGroup->setEnabled( false );
169 myCurrentLineEdit = myMeshGroupLine;
170 setSelectionMode( grpGroupSelection );
174 //=================================================================================
175 // function : SMESHGUI_GroupDlg()
177 //=================================================================================
178 void SMESHGUI_GroupDlg::initDialog( bool create)
181 setAttribute( Qt::WA_DeleteOnClose, true );
185 myCurrentLineEdit = 0;
189 myGeomObjects = new GEOM::ListOfGO();
190 myGeomObjects->length( 0 );
192 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
194 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
195 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
197 setSizeGripEnabled( true);
199 QGridLayout* aMainLayout = new QGridLayout( this );
200 aMainLayout->setMargin( MARGIN );
201 aMainLayout->setSpacing( SPACING );
203 /***************************************************************/
204 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
205 myMeshGroupBtn = new QPushButton( this );
206 myMeshGroupBtn->setIcon( image0 );
207 myMeshGroupLine = new QLineEdit( this );
208 myMeshGroupLine->setReadOnly( true );
210 /***************************************************************/
211 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
212 myTypeGroup = new QButtonGroup( this );
213 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
214 aTypeBoxLayout->setMargin( MARGIN );
215 aTypeBoxLayout->setSpacing( SPACING );
218 types.append( tr( "MESH_NODE" ) );
219 types.append( tr( "SMESH_ELEM0D" ) );
220 types.append( tr( "SMESH_BALL_ELEM" ) );
221 types.append( tr( "SMESH_EDGE" ) );
222 types.append( tr( "SMESH_FACE" ) );
223 types.append( tr( "SMESH_VOLUME" ) );
225 for ( int i = 0; i < types.count(); i++ )
227 rb = new QRadioButton( types[i], aTypeBox );
228 myTypeGroup->addButton( rb, i );
229 aTypeBoxLayout->addWidget( rb );
231 aTypeBox->setEnabled( create );
234 /***************************************************************/
235 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
236 aName->setMinimumWidth( 50 );
237 myName = new QLineEdit( this );
239 /***************************************************************/
240 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
241 myGrpTypeGroup = new QButtonGroup( this );
242 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
243 aGrpTypeBoxLayout->setMargin( MARGIN );
244 aGrpTypeBoxLayout->setSpacing( SPACING );
246 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
247 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
248 QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox );
249 myGrpTypeGroup->addButton( rb1, 0 );
250 myGrpTypeGroup->addButton( rb2, 1 );
251 myGrpTypeGroup->addButton( rb3, 2 );
252 aGrpTypeBoxLayout->addWidget( rb1 );
253 aGrpTypeBoxLayout->addWidget( rb2 );
254 aGrpTypeBoxLayout->addWidget( rb3 );
255 aGrpTypeBox->setEnabled( create );
258 /***************************************************************/
259 myWGStack = new QStackedWidget( this );
260 QWidget* wg1 = new QWidget( myWGStack );
261 QWidget* wg2 = new QWidget( myWGStack );
262 QWidget* wg3 = new QWidget( myWGStack );
264 /***************************************************************/
265 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
266 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
267 aContentBoxLayout->setMargin( MARGIN );
268 aContentBoxLayout->setSpacing( SPACING );
270 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
271 myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
273 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
274 myElements = new QListWidget( aContentBox );
275 myElements->setSelectionMode( QListWidget::ExtendedSelection );
277 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
278 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
279 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
280 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
282 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
283 aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
284 aContentBoxLayout->addWidget( myFilterBtn, 1, 1 );
285 aContentBoxLayout->addWidget( myElementsLab, 2, 0 );
286 aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 );
287 aContentBoxLayout->addWidget( myAddBtn, 3, 1 );
288 aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 );
289 aContentBoxLayout->addWidget( mySortBtn, 8, 1 );
291 aContentBoxLayout->setColumnStretch( 0, 1 );
292 aContentBoxLayout->setRowStretch( 3, 1 );
293 aContentBoxLayout->setRowStretch( 6, 1 );
295 /***************************************************************/
296 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
297 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
298 mySelectBoxLayout->setMargin( MARGIN );
299 mySelectBoxLayout->setSpacing( SPACING );
301 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
302 mySubMeshBtn = new QPushButton( mySelectBox );
303 mySubMeshBtn->setIcon( image0 );
304 mySubMeshLine = new QLineEdit( mySelectBox );
305 mySubMeshLine->setReadOnly( true );
306 onSelectSubMesh( false );
308 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
309 myGroupBtn = new QPushButton( mySelectBox );
310 myGroupBtn->setIcon( image0 );
311 myGroupLine = new QLineEdit( mySelectBox );
312 myGroupLine->setReadOnly( true );
313 onSelectGroup( false );
315 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
316 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
317 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
318 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
319 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
320 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
322 /***************************************************************/
323 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
324 wg1Layout->setMargin( 0 );
325 wg1Layout->setSpacing( SPACING );
326 wg1Layout->addWidget( aContentBox );
327 wg1Layout->addWidget( mySelectBox );
328 wg1Layout->setStretchFactor( aContentBox, 10 );
330 /***************************************************************/
331 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
332 myGeomGroupBtn = new QToolButton( wg2 );
333 myGeomGroupBtn->setIcon( image0 );
334 myGeomGroupBtn->setCheckable( true );
335 myGeomGroupLine = new QLineEdit( wg2 );
336 myGeomGroupLine->setReadOnly( true ); //VSR ???
337 onSelectGeomGroup( false );
339 myGeomGroupBtn->setEnabled( create );
340 myGeomGroupLine->setEnabled( create );
342 /***************************************************************/
343 QGridLayout* wg2Layout = new QGridLayout( wg2 );
344 wg2Layout->setMargin( 0 );
345 wg2Layout->setSpacing( SPACING );
346 wg2Layout->addWidget( geomObject, 0, 0 );
347 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
348 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
349 wg2Layout->setRowStretch( 1, 5 );
351 /***************************************************************/
352 QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
353 QGridLayout* wg3Layout = new QGridLayout( wg3 );
354 wg3Layout->setMargin( 0 );
355 wg3Layout->setSpacing( SPACING );
356 wg3Layout->addWidget( aFilter2, 0, 0 );
357 wg3Layout->setRowStretch( 1, 5 );
359 /***************************************************************/
360 myWGStack->insertWidget( 0, wg1 );
361 myWGStack->insertWidget( 1, wg2 );
362 myWGStack->insertWidget( 2, wg3 );
364 /***************************************************************/
365 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
366 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
367 aColorBoxLayout->setMargin(MARGIN);
368 aColorBoxLayout->setSpacing(SPACING);
370 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
371 myColorBtn = new QtxColorButton(aColorBox);
372 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
373 myColorBtn->sizePolicy().verticalPolicy() );
375 aColorBoxLayout->addWidget(aColorLab);
376 aColorBoxLayout->addWidget(myColorBtn);
378 /***************************************************************/
380 QFrame* aButtons = new QFrame(this);
381 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
382 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
383 aBtnLayout->setMargin(MARGIN);
384 aBtnLayout->setSpacing(SPACING);
386 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
387 myOKBtn->setAutoDefault(true);
388 myOKBtn->setDefault(true);
389 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
390 myApplyBtn->setAutoDefault(true);
391 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
392 myCloseBtn->setAutoDefault(true);
393 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
394 myHelpBtn->setAutoDefault(true);
396 aBtnLayout->addWidget(myOKBtn);
397 aBtnLayout->addSpacing(10);
398 aBtnLayout->addWidget(myApplyBtn);
399 aBtnLayout->addSpacing(10);
400 aBtnLayout->addStretch();
401 aBtnLayout->addWidget(myCloseBtn);
402 aBtnLayout->addWidget(myHelpBtn);
404 /***************************************************************/
405 aMainLayout->addWidget(meshGroupLab, 0, 0);
406 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
407 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
408 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
409 aMainLayout->addWidget(aName, 2, 0);
410 aMainLayout->addWidget(myName, 2, 2);
411 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
412 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
413 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
414 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
416 /* signals and slots connections */
417 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
418 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
419 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
421 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
422 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
424 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
425 connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters()));
426 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
427 connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
428 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
429 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
430 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
432 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
433 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
434 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
435 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
436 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
438 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
440 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
441 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
442 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
443 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
446 mySMESHGUI->SetActiveDialogBox(this);
447 mySMESHGUI->SetState(800);
449 mySelectionMode = grpNoSelection;
450 myMeshFilter = new SMESH_TypeFilter(SMESH::MESH);
451 mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
452 SMESH_LogicalFilter::LO_OR,
453 /*takeOwnership=*/true);
454 myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
455 SMESH_LogicalFilter::LO_OR,
456 /*takeOwnership=*/true);
457 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
458 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
460 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
461 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
462 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
463 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
465 rb1->setChecked(true); // VSR !!!
466 onGrpTypeChanged(0); // VSR!!!
468 if (myMesh->_is_nil() )
469 myTypeGroup->button(0)->setChecked(true);
471 onSelectAll(); //updateButtons();
474 //=================================================================================
475 // function : ~SMESHGUI_GroupDlg()
476 // purpose : Destroys the object and frees any allocated resources
477 //=================================================================================
478 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
480 // no need to delete child widgets, Qt does it all for us
481 if ( myFilterDlg != 0 ) {
482 myFilterDlg->setParent( 0 );
485 if ( myMeshFilter ) delete myMeshFilter;
486 if ( mySubMeshFilter ) delete mySubMeshFilter;
487 if ( myGroupFilter ) delete myGroupFilter;
488 if ( myGeomFilter ) delete myGeomFilter;
491 //=================================================================================
492 // function : GetDefaultName()
493 // purpose : Get the Group Name if Create new Group
494 //=================================================================================
495 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
499 // collect all object names of SMESH component
500 SalomeApp_Study* appStudy =
501 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
502 if ( !appStudy ) return aName;
503 _PTR(Study) aStudy = appStudy->studyDS();
505 std::set<std::string> aSet;
506 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
508 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
510 for (it->InitEx(true); it->More(); it->Next()) {
512 aSet.insert(obj->GetName());
516 // build a unique name
518 bool isUnique = false;
520 aName = theOperation + "_" + QString::number(++aNumber);
521 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
527 void SMESHGUI_GroupDlg::setDefaultName() const
530 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
532 QString aPrefix ="Group_";
536 aResName = aPrefix + QString::number( i++ );
537 anObj = aStudy->FindObject( aResName.toLatin1().data() );
540 myName->setText(aResName);
543 //=================================================================================
546 //=================================================================================
547 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
549 mySelectionMgr->installFilter(myMeshFilter);
551 /* init data from current selection */
552 restoreShowEntityMode();
553 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
555 myGroup = SMESH::SMESH_Group::_nil();
556 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
557 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
559 // NPAL19389: create a group with a selection in another group
560 // set actor of myMesh, if it is visible, else try
561 // any visible actor of group or submesh of myMesh
562 SetAppropriateActor();
564 setDefaultGroupColor();
569 mySelectionMgr->selectedObjects( aList );
570 if( !aList.IsEmpty() )
572 QString aName = aList.First()->getName();
573 myMeshGroupLine->setText(aName);
574 myMeshGroupLine->home( false );
577 myCurrentLineEdit = 0;
579 myTypeGroup->button(0)->setChecked(true);
583 //=================================================================================
586 //=================================================================================
587 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
588 const bool theIsConvert)
590 restoreShowEntityMode();
591 myMesh = theGroup->GetMesh();
594 myNameChanged = true;
595 myName->blockSignals(true);
596 myName->setText(theGroup->GetName());
597 myName->blockSignals(false);
600 SALOMEDS::Color aColor = theGroup->GetColor();
601 setGroupColor( aColor );
603 myMeshGroupLine->setText(theGroup->GetName());
606 switch(theGroup->GetType()) {
607 case SMESH::NODE: aType = grpNodeSelection; break;
608 case SMESH::ELEM0D: aType = grp0DSelection; break;
609 case SMESH::BALL: aType = grpBallSelection; break;
610 case SMESH::EDGE: aType = grpEdgeSelection; break;
611 case SMESH::FACE: aType = grpFaceSelection; break;
612 case SMESH::VOLUME: aType = grpVolumeSelection; break;
614 myTypeGroup->button(aType)->setChecked(true);
616 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
617 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
618 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_narrow( theGroup );
619 myFilter = SMESH::Filter::_nil();
621 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil() && myGroupOnFilter->_is_nil() )
624 // NPAL19389: create a group with a selection in another group
625 // set actor of myMesh, if it is visible, else set
626 // actor of theGroup, if it is visible, else try
627 // any visible actor of group or submesh of myMesh
628 // commented, because an attempt to set selection on not displayed cells leads to error
629 SetAppropriateActor();
631 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
633 anActor = SMESH::FindActorByObject(theGroup);
634 SMESH::SetPickable(anActor);*/
636 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : myGroupOnGeom->_is_nil() ? 2 : 1));
637 myGrpTypeGroup->button(grpType)->setChecked(true);
638 onGrpTypeChanged(grpType);
641 if ( grpType == 0 ) { // standalone group
642 myCurrentLineEdit = 0;
644 myAllowElemsModif->setChecked( true );
646 setSelectionMode(aType);
648 setShowEntityMode(); // depends on myTypeId
651 if (!theGroup->IsEmpty()) {
652 SMESH::long_array_var anElements = theGroup->GetListOfID();
653 int k = anElements->length();
654 for (int i = 0; i < k; i++) {
655 myIdList.append(anElements[i]);
656 myElements->addItem(QString::number(anElements[i]));
658 myElements->selectAll();
661 else if ( grpType == 1 ) // group on geom
663 QString aShapeName( "" );
664 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
665 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
666 if (!aGroupShape->_is_nil())
668 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
670 aShapeName = aGroupShapeSO->GetName().c_str();
672 myGeomGroupLine->setText( aShapeName );
674 else // group on filter
676 myFilter = myGroupOnFilter->GetFilter();
677 if ( !myFilter->_is_nil() ) {
678 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
679 if ( perdicate->_is_nil() )
680 myFilter = SMESH::Filter::_nil();
686 myNameChanged = true;
687 myName->blockSignals(true);
688 myName->setText(theGroup->GetName());
689 myName->blockSignals(false);
692 onSelectAll(); //updateButtons();
695 //=================================================================================
696 // function : updateButtons()
698 //=================================================================================
699 void SMESHGUI_GroupDlg::updateButtons()
701 bool enable = !myName->text().trimmed().isEmpty();
704 if (myGrpTypeId == 0) { // standalone
705 if ( !mySelectAll->isChecked() )
707 if ( myAllowElemsModif->isChecked() )
709 enable = ( myElements->count() > 0 );
711 else if ((enable = !myFilter->_is_nil() ))
713 SMESH::array_of_ElementType_var types = myFilter->GetTypes();
714 enable = types->length();
717 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
719 else if (myGrpTypeId == 1) // on geom
721 if (CORBA::is_nil(myGroupOnGeom)) // creation mode
722 enable = ( myGeomObjects->length() > 0 && !myMesh->_is_nil() );
724 else if (myGrpTypeId == 2) // on filter
726 if (( enable = !myFilter->_is_nil() ))
727 if (CORBA::is_nil(myGroupOnFilter) ) // creation mode
728 enable = !myMesh->_is_nil();
732 myOKBtn->setEnabled(enable);
733 myApplyBtn->setEnabled(enable);
736 //=================================================================================
737 // function : onNameChanged()
739 //=================================================================================
740 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
742 myOldName = myName->text();
744 myNameChanged = !myName->text().trimmed().isEmpty();
747 //=================================================================================
748 // function : onTypeChanged()
749 // purpose : Group elements type radio button management
750 //=================================================================================
751 void SMESHGUI_GroupDlg::onTypeChanged (int id)
753 if (myTypeId != id) {
756 if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
757 setSelectionMode(id);
759 setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
761 onObjectSelectionChanged();
766 //=================================================================================
767 // function : onGrpTypeChanged()
768 // purpose : Group type radio button management
769 //=================================================================================
770 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
772 if (myGrpTypeId != id) {
774 myWGStack->setCurrentIndex( id );
775 myName->blockSignals(true);
776 myName->setText(myOldName);
777 myName->blockSignals(false);
778 onSelectGeomGroup(id != 0);
783 //=================================================================================
784 // function : onColorChanged()
785 // purpose : Color button management
786 //=================================================================================
787 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
792 //=================================================================================
793 // function : setSelectionMode()
794 // purpose : Radio button management
795 //=================================================================================
796 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
799 if (myMesh->_is_nil())
801 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
802 bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
803 if (mySelectionMode != theMode) {
804 // [PAL10408] mySelectionMgr->clearSelected();
805 mySelectionMgr->clearFilters();
806 SMESH::RemoveFilters();
808 if (myActorsList.count() > 0)
809 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
810 it.next()->SetPointRepresentation(false);
812 SMESH::SetPointRepresentation(false);
815 case grpNodeSelection:
816 if ( myGrpTypeId == 0 ) // standalone
818 if (myActorsList.count() > 0)
819 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
820 it.next()->SetPointRepresentation(true);
822 SMESH::SetPointRepresentation(true);
824 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
826 case grpEdgeSelection:
827 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
829 case grpBallSelection:
830 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
833 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : Elem0DSelection);
835 case grpFaceSelection:
836 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
838 case grpVolumeSelection:
839 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
841 case grpSubMeshSelection: {
843 SMESH_TypeFilter* f = 0;
845 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH); break;
846 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_EDGE); break;
847 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_FACE); break;
848 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_SOLID); break;
849 default: f = new SMESH_TypeFilter(SMESH::SUBMESH);
851 QList<SUIT_SelectionFilter*> filtList;
852 filtList.append( f );
853 filtList.append( new SMESH_TypeFilter(SMESH::SUBMESH_COMPOUND));
854 mySubMeshFilter->setFilters( filtList );
856 mySelectionMgr->installFilter( mySubMeshFilter );
858 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
861 case grpGroupSelection: {
863 SMESH_TypeFilter* f = 0;
865 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_NODE); break;
866 case grp0DSelection: f = new SMESH_TypeFilter(SMESH::GROUP_0D); break;
867 case grpBallSelection: f = new SMESH_TypeFilter(SMESH::GROUP_BALL); break;
868 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_EDGE); break;
869 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::GROUP_FACE); break;
870 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_VOLUME); break;
871 default: f = new SMESH_TypeFilter(SMESH::GROUP);
873 QList<SUIT_SelectionFilter*> filtList;
874 filtList.append( f );
875 myGroupFilter->setFilters( filtList );
877 mySelectionMgr->installFilter(myGroupFilter);
878 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
881 case grpMeshSelection:
882 mySelectionMgr->installFilter(myMeshFilter);
883 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
885 case grpGeomSelection:
886 mySelectionMgr->installFilter(myGeomFilter);
887 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
890 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
893 if ( aViewWindow ) aViewWindow->Repaint();
894 mySelectionMode = theMode;
898 //=================================================================================
899 // function : onApply()
901 //=================================================================================
902 bool SMESHGUI_GroupDlg::onApply()
904 if (mySMESHGUI->isActiveStudyLocked())
907 if (myName->text().trimmed().isEmpty())
910 SMESH::ElementType aType = SMESH::ALL;
912 case grpNodeSelection: aType = SMESH::NODE; break;
913 case grp0DSelection: aType = SMESH::ELEM0D; break;
914 case grpBallSelection: aType = SMESH::BALL; break;
915 case grpEdgeSelection: aType = SMESH::EDGE; break;
916 case grpFaceSelection: aType = SMESH::FACE; break;
917 case grpVolumeSelection: aType = SMESH::VOLUME; break;
921 QStringList anEntryList;
923 SMESH::SMESH_GroupBase_var resultGroup;
926 if (myGrpTypeId == 0) // standalone
928 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
931 mySelectionMgr->clearSelected();
933 if (myGroup->_is_nil()) { // creation or conversion
934 // check if group on geometry is not null
935 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
936 if (myMesh->_is_nil())
938 if ( myGroupOnGeom->_is_nil() )
939 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
941 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
943 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
944 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
948 if (myGroup->_is_nil()) { // creation
949 if (myMesh->_is_nil())
952 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
954 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
957 if ( mySelectAll->isChecked() ) {
959 myGroup->AddFrom(myMesh.in());
964 if ( !myFilter->_is_nil() &&
965 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
967 myGroup->AddFrom( myFilter );
971 SMESH::long_array_var anIdList = new SMESH::long_array;
972 int i, k = myElements->count();
974 for (i = 0; i < k; i++) {
975 anIdList[i] = myElements->item(i)->text().toInt();
977 myGroup->Add(anIdList.inout());
984 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
987 if ( mySelectAll->isChecked() ) {
990 myGroup->AddFrom(myMesh.in());
995 int i, total = myElements->count();
996 for (i = 0; i < total; i++) {
997 int anId = myElements->item(i)->text().toInt();
998 int idx = myIdList.indexOf(anId);
1000 aAddList.append(anId);
1002 myIdList.removeAt(idx);
1004 if (!aAddList.empty()) {
1005 SMESH::long_array_var anIdList = new SMESH::long_array;
1006 int added = aAddList.count();
1007 anIdList->length(added);
1008 for (i = 0; i < added; i++)
1009 anIdList[i] = aAddList[i];
1010 myGroup->Add(anIdList.inout());
1012 if (!myIdList.empty()) {
1013 SMESH::long_array_var anIdList = new SMESH::long_array;
1014 int removed = myIdList.count();
1015 anIdList->length(removed);
1016 for (i = 0; i < removed; i++)
1017 anIdList[i] = myIdList[i];
1018 myGroup->Remove(anIdList.inout());
1020 /* init for next operation */
1022 for (i = 0; i < total; i++) {
1023 myIdList.append(myElements->item(i)->text().toInt());
1030 else if (myGrpTypeId == 1) // on geom object
1032 if (CORBA::is_nil(myGroupOnGeom)) { // creation
1033 if (myMesh->_is_nil() || !myGeomObjects->length())
1036 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1038 if (myGeomObjects->length() == 1) {
1039 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1040 myName->text().toLatin1().data(),
1044 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1045 if ( aSMESHGen->_is_nil() )
1048 // create a geometry group
1049 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1050 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1052 if (geomGen->_is_nil() || !aStudy)
1055 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
1059 // check and add all selected GEOM objects: they must be
1060 // a sub-shapes of the main GEOM and must be of one type
1061 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1062 for ( int i =0; i < myGeomObjects->length(); i++) {
1063 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1065 aGroupType = aSubShapeType;
1066 else if (aSubShapeType != aGroupType) {
1067 aGroupType = TopAbs_SHAPE;
1072 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1073 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1074 op->UnionList(aGroupVar, myGeomObjects);
1077 // publish the GEOM group in study
1078 QString aNewGeomGroupName ( "Auto_group_for_" );
1079 aNewGeomGroupName += myName->text();
1080 SALOMEDS::SObject_var aNewGroupSO =
1081 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
1082 aNewGeomGroupName.toLatin1().data(), aMeshShape);
1085 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1086 myName->text().toLatin1().data(),
1089 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1095 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1100 if (myGrpTypeId == 2) // group on filter
1102 if ( myFilter->_is_nil() ) return false;
1104 if (CORBA::is_nil(myGroupOnFilter)) { // creation
1105 if (myMesh->_is_nil())
1108 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1109 myName->text().toLatin1().data(),
1112 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1117 myGroupOnFilter->SetFilter( myFilter );
1119 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1127 SALOMEDS::Color aColor = getGroupColor();
1128 resultGroup->SetColor(aColor);
1130 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1132 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1136 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1138 /* init for the next operation */
1140 myElements->clear();
1141 myGroup = SMESH::SMESH_Group::_nil();
1142 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1143 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1144 myFilter = SMESH::Filter::_nil();
1148 resultGroup->SetName(myName->text().toLatin1().data());
1151 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
1152 anActor->setName(myName->text().toLatin1().data());
1155 switch ( myTypeId ) {
1156 case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1157 case grp0DSelection: anActor->Set0DColor ( aColor.R, aColor.G, aColor.B ); break;
1158 case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1159 case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1160 case grpVolumeSelection:
1161 SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
1162 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1164 case grpFaceSelection:
1166 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1167 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1172 SMESHGUI::Modified();
1173 mySMESHGUI->updateObjBrowser(true);
1174 SMESH::UpdateView(); // asv: fix of BUG PAL5515
1175 mySelectionMgr->clearSelected();
1177 if( LightApp_Application* anApp =
1178 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1179 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1184 //=================================================================================
1185 // function : onOK()
1187 //=================================================================================
1188 void SMESHGUI_GroupDlg::onOK()
1190 setIsApplyAndClose( true );
1193 setIsApplyAndClose( false );
1196 //=================================================================================
1197 // function : onListSelectionChanged()
1198 // purpose : Called when selection in element list is changed
1199 //=================================================================================
1200 void SMESHGUI_GroupDlg::onListSelectionChanged()
1202 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1203 if( myIsBusy || myActorsList.count() == 0 ) return;
1206 if (myCurrentLineEdit == 0) {
1207 mySelectionMgr->clearSelected();
1208 TColStd_MapOfInteger aIndexes;
1209 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1210 QListWidgetItem* anItem;
1211 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1212 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1213 SALOME_ListIO aList;
1214 aList.Append(myActorsList.first()->getIO());
1215 mySelectionMgr->setSelectedObjects(aList,false);
1220 //=================================================================================
1221 // function : onObjectSelectionChanged()
1222 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1223 //=================================================================================
1224 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1226 if ( myIsBusy || !isEnabled()) return;
1227 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1231 SALOME_ListIO aList;
1232 mySelectionMgr->selectedObjects( aList );
1234 int aNbSel = aList.Extent();
1235 myElements->clearSelection();
1237 if (myCurrentLineEdit)
1239 myCurrentLineEdit->setText( "" );
1240 QString aString = "";
1242 if (myCurrentLineEdit == myMeshGroupLine)
1244 mySelectSubMesh->setEnabled(false);
1245 mySelectGroup->setEnabled(false);
1246 myGroupLine->setText( "" );
1247 mySubMeshLine->setText( "" );
1249 myGeomGroupBtn->setEnabled(false);
1250 myGeomGroupLine->setEnabled(false);
1251 myGeomGroupLine->setText( "" );
1252 myGeomObjects = new GEOM::ListOfGO();
1253 myGeomObjects->length(0);
1255 if (myGeomGroupBtn->isChecked())
1256 myGeomGroupBtn->setChecked(false);
1258 myName->setText( "" );
1260 myElements->clear();
1263 myGroup = SMESH::SMESH_Group::_nil();
1264 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1265 restoreShowEntityMode();
1266 myMesh = SMESH::SMESH_Mesh::_nil();
1272 Handle(SALOME_InteractiveObject) IO = aList.First();
1275 restoreShowEntityMode();
1276 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1277 setShowEntityMode();
1279 if (myMesh->_is_nil())
1286 if ( myFilterDlg && !myMesh->_is_nil()){
1287 myFilterDlg->SetMesh( myMesh );
1289 myGroup = SMESH::SMESH_Group::_nil();
1291 // NPAL19389: create a group with a selection in another group
1292 // set actor of myMesh, if it is visible, else try
1293 // any visible actor of group or submesh of myMesh
1294 SetAppropriateActor();
1296 aString = aList.First()->getName();
1297 myMeshGroupLine->setText(aString);
1298 myMeshGroupLine->home( false );
1300 mySelectSubMesh->setEnabled(true);
1301 mySelectGroup->setEnabled(true);
1302 myGeomGroupBtn->setEnabled(true);
1303 myGeomGroupLine->setEnabled(true);
1307 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1308 if (aGroup->_is_nil())
1315 myGroup = SMESH::SMESH_Group::_nil();
1316 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1320 mySelectSubMesh->setEnabled(true);
1321 mySelectGroup->setEnabled(true);
1323 myCurrentLineEdit = 0;
1328 if (myGrpTypeId == 0)
1334 myElements->clear();
1335 setSelectionMode(myTypeId);
1343 else if (myCurrentLineEdit == myGeomGroupLine)
1345 myGeomObjects = new GEOM::ListOfGO();
1348 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1350 if (aNbSel == 0 || !aMeshSO)
1352 myGeomObjects->length(0);
1358 myGeomObjects->length(aNbSel);
1360 GEOM::GEOM_Object_var aGeomGroup;
1363 SALOME_ListIteratorOfListIO anIt (aList);
1364 for (; anIt.More(); anIt.Next())
1366 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1368 // Check if the object is a geometry group
1369 if (CORBA::is_nil(aGeomGroup))
1372 // Check if group constructed on the same shape as a mesh or on its child
1373 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1375 // The main shape of the group
1376 GEOM::GEOM_Object_var aGroupMainShape;
1377 if (aGeomGroup->GetType() == 37) {
1378 GEOM::GEOM_IGroupOperations_wrap anOp =
1379 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1380 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1381 // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
1384 aGroupMainShape = aGeomGroup;
1385 aGroupMainShape->Register();
1387 _PTR(SObject) aGroupMainShapeSO =
1388 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1390 _PTR(SObject) anObj, aRef;
1391 bool isRefOrSubShape = false;
1392 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1393 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1394 isRefOrSubShape = true;
1396 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1397 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1398 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1399 if (aRef->GetID() == aFather->GetID())
1400 isRefOrSubShape = true;
1402 aFather = aFather->GetFather();
1406 if (isRefOrSubShape)
1407 myGeomObjects[i++] = aGeomGroup;
1410 myGeomObjects->length(i);
1422 if (myCurrentLineEdit == mySubMeshLine)
1423 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1424 else if (myCurrentLineEdit == myGroupLine)
1425 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1426 else if (myCurrentLineEdit == myGeomGroupLine)
1427 aString = tr( "%1 Objects" ).arg(aNbSel);
1430 aString = aList.First()->getName();
1434 myCurrentLineEdit->setText(aString);
1435 myCurrentLineEdit->home(false);
1436 // 07.06.2008 skl for IPAL19574:
1437 // change name of group only if it is empty
1438 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1439 myOldName = myName->text();
1440 myName->blockSignals(true);
1441 myName->setText(aString);
1442 myName->blockSignals(false);
1447 else // !myCurrentLineEdit: local selection of nodes or elements
1449 if (aNbSel == 1 && myActorsList.count() > 0 )
1451 // NPAL19389: create a group with a selection in another group
1452 // Switch myActor to the newly selected one, if the last
1453 // is visible and belongs to group or submesh of myMesh
1454 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1455 Handle(SALOME_InteractiveObject) selIO = aList.First();
1456 if (curIO->hasEntry() && selIO->hasEntry()) {
1457 const char* selEntry = selIO->getEntry();
1458 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1459 // different objects: selected and myActor
1460 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1461 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1462 // newly selected actor is visible
1465 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1467 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1468 int len = strlen(meshEntry);
1470 if (strncmp(selEntry, meshEntry, len) == 0) {
1471 // selected object is myMesh or a part of it
1472 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1475 SMESH::SetPickable(myActor);
1484 QString aListStr = "";
1486 if (myTypeId == 0) {
1487 QListIterator<SMESH_Actor*> it( myActorsList );
1488 while ( it.hasNext() ) {
1490 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1494 QListIterator<SMESH_Actor*> it( myActorsList );
1495 while ( it.hasNext() ) {
1497 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1502 QListWidgetItem* anItem;
1503 QList<QListWidgetItem*> listItemsToSel;
1504 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1505 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1506 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1507 foreach(anItem, found)
1508 if (!anItem->isSelected())
1509 listItemsToSel.push_back(anItem);
1511 bool blocked = myElements->signalsBlocked();
1512 myElements->blockSignals(true);
1513 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1514 myElements->blockSignals(blocked);
1515 onListSelectionChanged();
1516 listItemsToSel.clear();
1521 if (myActorsList.count() == 0) {
1522 if (!myGroup->_is_nil()) {
1523 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1525 myActorsList.append( anActor );
1527 else if(!myGroupOnGeom->_is_nil()) {
1528 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1530 myActorsList.append( anActor );
1533 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1535 myActorsList.append( anActor );
1539 // somehow, if we display the mesh, while selecting from another actor,
1540 // the mesh becomes pickable, and there is no way to select any element
1541 if (myActorsList.count() > 0) {
1542 QListIterator<SMESH_Actor*> it( myActorsList );
1543 while ( it.hasNext() ) {
1544 SMESH_Actor* anActor = it.next();
1545 if ( IsActorVisible(anActor) )
1546 anActor->SetPickable(true);
1553 //=================================================================================
1554 // function : onSelectAll()
1555 // purpose : Called when "Select all" is checked
1556 //=================================================================================
1557 void SMESHGUI_GroupDlg::onSelectAll()
1559 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1561 myElementsLab->setEnabled( !noElemsModif );
1562 myElements->setEnabled ( !noElemsModif );
1563 myFilterBtn->setEnabled ( !mySelectAll->isChecked() );
1564 myAddBtn->setEnabled ( !noElemsModif );
1565 myRemoveBtn->setEnabled ( !noElemsModif );
1566 mySortBtn->setEnabled ( !noElemsModif );
1567 mySelectBox->setEnabled ( !noElemsModif );
1568 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1570 int selMode = mySelectionMode;
1571 mySelectionMode = grpNoSelection;
1572 setSelectionMode( selMode );
1576 //=================================================================================
1577 // function : onSelectSubMesh()
1578 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1579 //=================================================================================
1580 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1583 if (mySelectGroup->isChecked()) {
1584 mySelectGroup->setChecked(false);
1586 //VSR: else if (mySelectGeomGroup->isChecked()) {
1587 //VSR: mySelectGeomGroup->setChecked(false);
1589 myCurrentLineEdit = mySubMeshLine;
1590 setSelectionMode(grpSubMeshSelection);
1593 mySubMeshLine->setText( "" );
1594 myCurrentLineEdit = 0;
1596 setSelectionMode(myTypeId);
1598 mySubMeshBtn->setEnabled(on);
1599 mySubMeshLine->setEnabled(on);
1603 //=================================================================================
1604 // function : (onSelectGroup)
1605 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1606 //=================================================================================
1607 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1610 if (mySelectSubMesh->isChecked()) {
1611 mySelectSubMesh->setChecked(false);
1613 myCurrentLineEdit = myGroupLine;
1614 setSelectionMode(grpGroupSelection);
1617 myGroupLine->setText( "" );
1618 myCurrentLineEdit = 0;
1620 setSelectionMode(myTypeId);
1622 myGroupBtn->setEnabled(on);
1623 myGroupLine->setEnabled(on);
1627 //=================================================================================
1628 // function : (onSelectGeomGroup)
1629 // purpose : Called when group type changed. on == "on group" or "on filter"
1630 //=================================================================================
1631 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1634 if (mySelectSubMesh->isChecked()) {
1635 mySelectSubMesh->setChecked(false);
1637 else if (mySelectGroup->isChecked()) {
1638 mySelectGroup->setChecked(false);
1640 if ( myGrpTypeId == 1 ) { // on group
1641 myCurrentLineEdit = myGeomGroupLine;
1645 myCurrentLineEdit = 0;
1647 setSelectionMode(grpAllSelection);
1650 myGeomGroupBtn->setChecked(false);
1651 myGeomObjects->length(0);
1652 myGeomGroupLine->setText( "" );
1653 myCurrentLineEdit = 0;
1655 setSelectionMode( myTypeId );
1659 //=================================================================================
1660 // function : setCurrentSelection()
1662 //=================================================================================
1663 void SMESHGUI_GroupDlg::setCurrentSelection()
1665 QPushButton* send = (QPushButton*)sender();
1666 myCurrentLineEdit = 0;
1667 if (send == myMeshGroupBtn) {
1668 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1669 mySelectionMgr->clearSelected();
1671 setSelectionMode(grpMeshSelection);
1673 setSelectionMode(grpGroupSelection);
1674 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1675 myCurrentLineEdit = myMeshGroupLine;
1676 onObjectSelectionChanged();
1678 else if (send == mySubMeshBtn) {
1679 myCurrentLineEdit = mySubMeshLine;
1680 onObjectSelectionChanged();
1682 else if (send == myGroupBtn) {
1683 myCurrentLineEdit = myGroupLine;
1684 onObjectSelectionChanged();
1689 //=================================================================================
1690 // function : setFilters()
1691 // purpose : SLOT. Called when "Filter" button pressed.
1692 //=================================================================================
1693 void SMESHGUI_GroupDlg::setFilters()
1695 if(myMesh->_is_nil()) {
1696 SUIT_MessageBox::critical(this,
1698 tr("NO_MESH_SELECTED"));
1702 SMESH::ElementType aType = SMESH::ALL;
1705 case grpNodeSelection: aType = SMESH::NODE; break;
1706 case grp0DSelection: aType = SMESH::ELEM0D; break;
1707 case grpBallSelection: aType = SMESH::BALL; break;
1708 case grpEdgeSelection: aType = SMESH::EDGE; break;
1709 case grpFaceSelection: aType = SMESH::FACE; break;
1710 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1714 if ( myFilterDlg == 0 )
1716 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1717 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1720 myFilterDlg->Init( aType );
1722 if ( !myGroupOnFilter->_is_nil() )
1724 myFilterDlg->SetFilter( myFilter, aType );
1725 myFilterDlg->Init( aType );
1728 myFilterDlg->SetSelection();
1729 myFilterDlg->SetMesh( myMesh );
1730 myFilterDlg->SetSourceWg( myElements, false );
1732 myFilterDlg->show();
1735 //=================================================================================
1736 // function : onFilterAccepted()
1737 // purpose : SLOT. Called when Filter dlg closed with OK button.
1738 // Uncheck "Select submesh" and "Select group" checkboxes
1739 //=================================================================================
1740 void SMESHGUI_GroupDlg::onFilterAccepted()
1742 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1744 mySelectionMode = myTypeId;
1745 mySelectSubMesh->setChecked( false );
1746 mySelectGroup->setChecked( false );
1748 // get a filter from myFilterDlg
1749 myFilter = myFilterDlg->GetFilter();
1750 if ( !myFilter->_is_nil() ) {
1751 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1752 if ( perdicate->_is_nil() )
1753 myFilter = SMESH::Filter::_nil();
1755 // set mesh to myFilter
1756 if ( !myFilter->_is_nil() ) {
1757 SMESH::SMESH_Mesh_var mesh = myMesh;
1758 if ( mesh->_is_nil() ) {
1759 if ( !myGroup->_is_nil() )
1760 mesh = myGroup->GetMesh();
1761 else if ( !myGroupOnGeom->_is_nil() )
1762 mesh = myGroupOnGeom->GetMesh();
1763 else if ( !myGroupOnFilter->_is_nil() )
1764 mesh = myGroupOnFilter->GetMesh();
1766 myFilter->SetMesh( mesh );
1772 //=================================================================================
1773 // function : onAdd()
1775 //=================================================================================
1776 void SMESHGUI_GroupDlg::onAdd()
1778 SALOME_ListIO aList;
1779 mySelectionMgr->selectedObjects( aList );
1781 int aNbSel = aList.Extent();
1783 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1786 int sizeBefore = myElements->count();
1788 SMESH::ElementType aType = SMESH::ALL;
1790 case grpNodeSelection:
1791 aType = SMESH::NODE;
1792 mySelector->SetSelectionMode(NodeSelection);
1794 case grpBallSelection:
1795 aType = SMESH::BALL;
1796 mySelector->SetSelectionMode(BallSelection);
1798 case grp0DSelection:
1799 aType = SMESH::ELEM0D;
1800 mySelector->SetSelectionMode(Elem0DSelection);
1802 case grpEdgeSelection:
1803 aType = SMESH::EDGE;
1804 mySelector->SetSelectionMode(EdgeSelection);
1806 case grpFaceSelection:
1807 aType = SMESH::FACE;
1808 mySelector->SetSelectionMode(FaceSelection);
1810 case grpVolumeSelection:
1811 aType = SMESH::VOLUME;
1812 mySelector->SetSelectionMode(VolumeSelection);
1815 mySelector->SetSelectionMode(ActorSelection);
1818 QListWidgetItem* anItem = 0;
1819 QList<QListWidgetItem*> listItemsToSel;
1821 if (myCurrentLineEdit == 0) {
1822 //if (aNbSel != 1) { myIsBusy = false; return; }
1823 QString aListStr = "";
1825 if (myTypeId == 0) {
1826 QListIterator<SMESH_Actor*> it( myActorsList );
1827 while ( it.hasNext() ) {
1829 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1834 QListIterator<SMESH_Actor*> it( myActorsList );
1835 while ( it.hasNext() ) {
1837 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1842 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1843 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1844 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1845 if (found.count() == 0) {
1846 anItem = new QListWidgetItem(*it);
1847 myElements->addItem(anItem);
1848 if (!anItem->isSelected())
1849 listItemsToSel.push_back(anItem);
1852 foreach(anItem, found)
1853 if (!anItem->isSelected())
1854 listItemsToSel.push_back(anItem);
1857 bool blocked = myElements->signalsBlocked();
1858 myElements->blockSignals(true);
1859 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1860 myElements->blockSignals(blocked);
1861 onListSelectionChanged();
1862 listItemsToSel.clear();
1864 } else if (myCurrentLineEdit == mySubMeshLine) {
1865 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1867 SALOME_ListIO aList;
1868 mySelectionMgr->selectedObjects( aList );
1870 SALOME_ListIteratorOfListIO anIt (aList);
1871 for ( ; anIt.More(); anIt.Next()) {
1872 SMESH::SMESH_subMesh_var aSubMesh =
1873 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1874 if (!aSubMesh->_is_nil()) {
1875 // check if mesh is the same
1876 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1878 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1879 int k = anElements->length();
1880 for (int i = 0; i < k; i++) {
1881 QString aText = QString::number(anElements[i]);
1882 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1883 if (found.count() == 0) {
1884 anItem = new QListWidgetItem(aText);
1885 myElements->addItem(anItem);
1886 if (!anItem->isSelected())
1887 listItemsToSel.push_back(anItem);
1890 foreach(anItem, found)
1891 if (!anItem->isSelected())
1892 listItemsToSel.push_back(anItem);
1895 bool blocked = myElements->signalsBlocked();
1896 myElements->blockSignals(true);
1897 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1898 myElements->blockSignals(blocked);
1899 onListSelectionChanged();
1900 listItemsToSel.clear();
1902 catch (const SALOME::SALOME_Exception& ex) {
1903 SalomeApp_Tools::QtCatchCorbaException(ex);
1908 mySelectSubMesh->setChecked(false);
1910 onListSelectionChanged();
1912 } else if (myCurrentLineEdit == myGroupLine) {
1913 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1914 SALOME_ListIO aList;
1915 mySelectionMgr->selectedObjects( aList );
1917 SALOME_ListIteratorOfListIO anIt (aList);
1918 for ( ; anIt.More(); anIt.Next()) {
1919 SMESH::SMESH_GroupBase_var aGroup =
1920 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1921 if (!aGroup->_is_nil()) {
1922 // check if mesh is the same
1923 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1924 SMESH::long_array_var anElements = aGroup->GetListOfID();
1925 int k = anElements->length();
1926 for (int i = 0; i < k; i++) {
1927 QString aText = QString::number(anElements[i]);
1928 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1929 if (found.count() == 0) {
1930 anItem = new QListWidgetItem(aText);
1931 myElements->addItem(anItem);
1932 if (!anItem->isSelected())
1933 listItemsToSel.push_back(anItem);
1936 foreach(anItem, found)
1937 if (!anItem->isSelected())
1938 listItemsToSel.push_back(anItem);
1941 bool blocked = myElements->signalsBlocked();
1942 myElements->blockSignals(true);
1943 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1944 myElements->blockSignals(blocked);
1945 onListSelectionChanged();
1946 listItemsToSel.clear();
1950 mySelectGroup->setChecked(false);
1952 onListSelectionChanged();
1954 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1955 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1956 GEOM::GEOM_IGroupOperations_wrap aGroupOp =
1957 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1959 SMESH::ElementType aGroupType = SMESH::ALL;
1960 switch(aGroupOp->GetType(myGeomObjects[0])) {
1961 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
1962 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
1963 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
1964 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
1965 default: myIsBusy = false; return;
1968 if (aGroupType == aType) {
1969 _PTR(SObject) aGroupSO =
1970 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1971 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1973 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1974 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1975 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
1976 aBelongToGeom->SetGeom(myGeomObjects[0]);
1977 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1978 aBelongToGeom->SetElementType(aType);
1979 aFilter->SetPredicate(aBelongToGeom);
1981 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1983 int k = anElements->length();
1984 for (int i = 0; i < k; i++) {
1985 QString aText = QString::number(anElements[i]);
1986 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1987 if (found.count() == 0) {
1988 anItem = new QListWidgetItem(aText);
1989 myElements->addItem(anItem);
1990 if (!anItem->isSelected())
1991 listItemsToSel.push_back(anItem);
1994 foreach(anItem, found)
1995 if (!anItem->isSelected())
1996 listItemsToSel.push_back(anItem);
1999 bool blocked = myElements->signalsBlocked();
2000 myElements->blockSignals(true);
2001 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2002 myElements->blockSignals(blocked);
2003 onListSelectionChanged();
2004 listItemsToSel.clear();
2007 //VSR: mySelectGeomGroup->setChecked(false);
2009 onListSelectionChanged();
2012 if ( sizeBefore < myElements->count() )
2013 ++myNbChangesOfContents;
2014 // mySelectionMgr->clearSelected();
2018 //=================================================================================
2019 // function : onRemove()
2021 //=================================================================================
2022 void SMESHGUI_GroupDlg::onRemove()
2025 int sizeBefore = myElements->count();
2027 if (myCurrentLineEdit == 0) {
2028 QList<QListWidgetItem*> selItems = myElements->selectedItems();
2029 QListWidgetItem* item;
2030 foreach(item, selItems) delete item;
2032 SALOME_ListIO aList;
2033 mySelectionMgr->selectedObjects( aList );
2035 int aNbSel = aList.Extent();
2037 if (aNbSel == 0) { myIsBusy = false; return; }
2039 SMESH::ElementType aType = SMESH::ALL;
2041 case grpNodeSelection: aType = SMESH::NODE; break;
2042 case grp0DSelection: aType = SMESH::ELEM0D; break;
2043 case grpBallSelection: aType = SMESH::BALL; break;
2044 case grpEdgeSelection: aType = SMESH::EDGE; break;
2045 case grpFaceSelection: aType = SMESH::FACE; break;
2046 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2049 if (myCurrentLineEdit == mySubMeshLine) {
2050 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2051 SALOME_ListIO aList;
2052 mySelectionMgr->selectedObjects( aList );
2054 SALOME_ListIteratorOfListIO anIt (aList);
2055 for ( ; anIt.More(); anIt.Next()) {
2056 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2057 if (!aSubMesh->_is_nil()) {
2058 // check if mesh is the same
2059 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2060 if (aType == SMESH::NODE) {
2062 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2063 int k = anElements->length();
2064 for (int i = 0; i < k; i++) {
2065 QList<QListWidgetItem*> found =
2066 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2067 QListWidgetItem* anItem;
2068 foreach(anItem, found) delete anItem;
2071 catch (const SALOME::SALOME_Exception& ex) {
2072 SalomeApp_Tools::QtCatchCorbaException(ex);
2077 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2078 int k = anElements->length();
2079 for (int i = 0; i < k; i++) {
2080 QList<QListWidgetItem*> found =
2081 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2082 QListWidgetItem* anItem;
2083 foreach(anItem, found) delete anItem;
2086 catch (const SALOME::SALOME_Exception& ex) {
2087 SalomeApp_Tools::QtCatchCorbaException(ex);
2094 else if (myCurrentLineEdit == myGroupLine) {
2095 Standard_Boolean aRes;
2096 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2097 SALOME_ListIO aList;
2098 mySelectionMgr->selectedObjects( aList );
2100 SALOME_ListIteratorOfListIO anIt (aList);
2101 for ( ; anIt.More(); anIt.Next()) {
2102 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2103 if (aRes && !aGroup->_is_nil()) {
2104 // check if mesh is the same
2105 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2106 SMESH::long_array_var anElements = aGroup->GetListOfID();
2107 int k = anElements->length();
2108 for (int i = 0; i < k; i++) {
2109 QList<QListWidgetItem*> found =
2110 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2111 QListWidgetItem* anItem;
2112 foreach(anItem, found) delete anItem;
2120 if ( sizeBefore > myElements->count() )
2121 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2125 //=================================================================================
2126 // function : onSort()
2128 //=================================================================================
2129 void SMESHGUI_GroupDlg::onSort()
2131 // PAL5412: sorts items in ascending by "string" value
2132 // myElements->sort(true);
2133 // myElements->update();
2134 int i, k = myElements->count();
2137 QList<int> aSelected;
2138 std::vector<int> anArray(k);
2139 // QMemArray<int> anArray(k);
2141 for (i = 0; i < k; i++) {
2142 int id = myElements->item(i)->text().toInt();
2144 if (myElements->item(i)->isSelected())
2145 aSelected.append(id);
2147 // sort & update list
2148 std::sort(anArray.begin(), anArray.end());
2150 myElements->clear();
2151 QListWidgetItem* anItem;
2152 QList<QListWidgetItem*> listItemsToSel;
2153 for (i = 0; i < k; i++) {
2154 anItem = new QListWidgetItem(QString::number(anArray[i]));
2155 myElements->addItem(anItem);
2156 if (aSelected.contains(anArray[i]))
2157 listItemsToSel.push_back(anItem);
2159 bool blocked = myElements->signalsBlocked();
2160 myElements->blockSignals(true);
2161 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2162 myElements->blockSignals(blocked);
2163 listItemsToSel.clear();
2168 //=================================================================================
2169 // function : onVisibilityChanged()
2171 //=================================================================================
2172 void SMESHGUI_GroupDlg::onVisibilityChanged()
2174 SetAppropriateActor();
2177 //=================================================================================
2178 // function : SMESHGUI_GroupDlg::reject
2179 // purpose : SLOT called when "Close" button pressed. Close dialog
2180 //=================================================================================
2181 void SMESHGUI_GroupDlg::reject()
2183 if (SMESH::GetCurrentVtkView()) {
2184 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2185 SMESH::SetPointRepresentation(false);
2186 SMESH::SetPickable();
2187 restoreShowEntityMode();
2190 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2191 SUIT_DataOwnerPtrList aList;
2192 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2193 mySelectionMgr->setSelected( aList );
2196 mySelectionMgr->clearSelected();
2197 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2198 aViewWindow->SetSelectionMode(ActorSelection);
2199 mySelectionMgr->clearFilters();
2200 mySMESHGUI->ResetState();
2205 //=================================================================================
2206 // function : onHelp()
2208 //=================================================================================
2209 void SMESHGUI_GroupDlg::onHelp()
2211 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2213 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2217 platform = "winapplication";
2219 platform = "application";
2221 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2222 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2223 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2225 arg(myHelpFileName));
2229 //=================================================================================
2230 // function : SMESHGUI_GroupDlg::onDeactivate
2231 // purpose : SLOT called when dialog must be deativated
2232 //=================================================================================
2233 void SMESHGUI_GroupDlg::onDeactivate()
2235 mySMESHGUI->ResetState();
2239 //=================================================================================
2240 // function : SMESHGUI_GroupDlg::enterEvent
2241 // purpose : Event filter
2242 //=================================================================================
2243 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2246 mySMESHGUI->EmitSignalDeactivateDialog();
2248 mySelectionMode = grpNoSelection;
2249 setSelectionMode(myTypeId);
2250 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2251 mySMESHGUI->SetActiveDialogBox(this);
2252 mySMESHGUI->SetState(800);
2256 //=================================================================================
2257 // function : keyPressEvent()
2259 //=================================================================================
2260 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2262 QDialog::keyPressEvent( e );
2263 if ( e->isAccepted() )
2266 if ( e->key() == Qt::Key_F1 )
2273 //================================================================================
2275 * \brief Enable showing of the popup when Geometry selection btn is clicked
2276 * \param enable - true to enable
2278 //================================================================================
2280 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2282 void SMESHGUI_GroupDlg::updateGeomPopup()
2284 bool enable = false;
2286 if ( !myMesh->_is_nil() )
2287 enable = myMesh->NbEdges() > 0;
2289 if ( myGeomGroupBtn )
2291 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2293 if ( !myGeomPopup ) {
2294 myGeomPopup = new QMenu(this);
2295 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2296 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2297 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2299 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2305 //=================================================================================
2306 // function : onGeomSelectionButton()
2308 //=================================================================================
2309 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2311 if ( myGeomPopup && isBtnOn )
2313 myCurrentLineEdit = myGeomGroupLine;
2314 QAction* a = myGeomPopup->exec( QCursor::pos() );
2315 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2316 setSelectionMode(grpGeomSelection);
2320 myCurrentLineEdit = 0;
2321 setSelectionMode(grpAllSelection);
2325 //=================================================================================
2326 // function : onGeomPopup()
2328 //=================================================================================
2329 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2331 int index = myActions[a];
2332 if ( index == GEOM_BY_MESH_INDEX )
2334 mySelectionMode = grpNoSelection;
2335 if ( !myShapeByMeshOp ) {
2336 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2337 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2338 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2339 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2340 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2342 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2343 if ( !myMesh->_is_nil() ) {
2345 hide(); // stop processing selection
2347 myShapeByMeshOp->setModule( mySMESHGUI );
2348 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2349 myShapeByMeshOp->SetMesh( myMesh );
2350 myShapeByMeshOp->start();
2355 //================================================================================
2357 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2359 //================================================================================
2361 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2363 if ( myShapeByMeshOp == op ) {
2364 mySMESHGUI->getApp()->updateObjectBrowser();
2366 // Select a found geometry object
2367 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2368 if ( !aGeomVar->_is_nil() )
2370 QString ID = aGeomVar->GetStudyEntry();
2371 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2372 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2373 SALOME_ListIO anIOList;
2374 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2375 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2376 anIOList.Append( anIO );
2377 mySelectionMgr->setSelectedObjects( anIOList, false );
2378 onObjectSelectionChanged();
2384 //================================================================================
2386 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2388 //================================================================================
2390 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2392 if ( myShapeByMeshOp == op )
2395 setSelectionMode(grpGeomSelection);
2399 //=================================================================================
2400 // function : setGroupColor()
2402 //=================================================================================
2403 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2405 QColor aQColor( (int)( theColor.R * 255.0 ),
2406 (int)( theColor.G * 255.0 ),
2407 (int)( theColor.B * 255.0 ) );
2408 setGroupQColor( aQColor );
2411 //=================================================================================
2412 // function : getGroupColor()
2414 //=================================================================================
2415 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2417 QColor aQColor = getGroupQColor();
2419 SALOMEDS::Color aColor;
2420 aColor.R = (float)aQColor.red() / 255.0;
2421 aColor.G = (float)aQColor.green() / 255.0;
2422 aColor.B = (float)aQColor.blue() / 255.0;
2427 //=================================================================================
2428 // function : setGroupQColor()
2430 //=================================================================================
2431 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2433 if( theColor.isValid() )
2434 myColorBtn->setColor( theColor );
2437 //=================================================================================
2438 // function : getGroupQColor()
2440 //=================================================================================
2441 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2443 return myColorBtn->color();
2446 //=================================================================================
2447 // function : setDefaultGroupColor()
2449 //=================================================================================
2450 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2452 if( myMesh->_is_nil() )
2455 bool isAutoColor = myMesh->GetAutoColor();
2460 int r = 0, g = 0, b = 0;
2461 SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2462 aQColor.setRgb( r, g, b );
2466 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2468 QList<SALOMEDS::Color> aReservedColors;
2469 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2471 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2472 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2473 aReservedColors.append( aReservedColor );
2476 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2477 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2478 (int)( aColor.G * 255.0 ),
2479 (int)( aColor.B * 255.0 ) );
2483 setGroupQColor( aQColor );
2486 //=================================================================================
2487 // function : SetAppropriateActor()
2488 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2489 // NPAL19389: create a group with a selection in another group.
2490 // if mesh actor is not visible - find any first visible group or submesh
2491 //=================================================================================
2492 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2494 bool isActor = false;
2495 myActorsList.clear();
2497 if (myMesh->_is_nil()) return false;
2499 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2501 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2503 if (!myGroupOnGeom->_is_nil()) {
2504 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2505 if (anActor && anActor->hasIO())
2508 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2511 myActorsList.append(anActor);
2517 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2518 if (anActor && anActor->hasIO()) {
2520 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2523 myActorsList.append(anActor);
2527 if (!isActor && !myGroup->_is_nil()) {
2528 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2529 if (anActor && anActor->hasIO())
2530 myActorsList.append(anActor);
2533 // try any visible actor of group or submesh of current mesh
2536 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2538 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2539 int len = strlen(meshEntry);
2541 // iterate on all actors in current view window, search for
2542 // any visible actor, that belongs to group or submesh of current mesh
2543 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2544 vtkActorCollection *aCollection = aCopy.GetActors();
2545 int nbItems = aCollection->GetNumberOfItems();
2546 for (int i=0; i<nbItems && !isActor; i++)
2548 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2549 if (anActor && anActor->hasIO()) {
2550 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2551 if (aViewWindow->isVisible(anIO)) {
2552 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2553 myActorsList.append(anActor);
2561 if (myActorsList.count() > 0) {
2562 QListIterator<SMESH_Actor*> it( myActorsList );
2563 while ( it.hasNext() ) {
2564 SMESH_Actor* anActor = it.next();
2565 if ( IsActorVisible(anActor) )
2566 anActor->SetPickable(true);
2570 return ( isActor || (myActorsList.count() > 0) );
2573 //=======================================================================
2574 //function : setShowEntityMode
2575 //purpose : make shown only entity corresponding to my type
2576 //=======================================================================
2577 void SMESHGUI_GroupDlg::setShowEntityMode()
2579 if ( !myMesh->_is_nil() ) {
2580 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2581 if (!myStoredShownEntity)
2582 myStoredShownEntity = actor->GetEntityMode();
2583 switch ( myTypeId ) {
2584 case grpNodeSelection: restoreShowEntityMode(); break;
2585 case grp0DSelection: actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
2586 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2587 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2588 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2589 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2595 //=======================================================================
2596 //function : restoreShowEntityMode
2597 //purpose : restore ShowEntity mode of myActor
2598 //=======================================================================
2599 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2601 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2602 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2603 actor->SetEntityMode(myStoredShownEntity);
2606 myStoredShownEntity = 0;
2609 //=======================================================================
2610 //function : IsActorVisible
2611 //purpose : return visibility of the actor
2612 //=======================================================================
2613 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2615 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2616 if (theActor && aViewWindow)
2617 return aViewWindow->isVisible(theActor->getIO());
2621 //================================================================
2622 //function : setIsApplyAndClose
2623 //purpose : Set value of the flag indicating that the dialog is
2624 // accepted by Apply & Close button
2625 //================================================================
2626 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2628 myIsApplyAndClose = theFlag;
2631 //================================================================
2632 //function : isApplyAndClose
2633 //purpose : Get value of the flag indicating that the dialog is
2634 // accepted by Apply & Close button
2635 //================================================================
2636 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2638 return myIsApplyAndClose;