1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_GroupDlg.cxx
25 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
28 #include "SMESHGUI_GroupDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_GroupUtils.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
36 #include "SMESHGUI_FilterDlg.h"
37 #include "SMESHGUI_ShapeByMeshDlg.h"
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_Actor.h>
41 //#include <SMESH_ActorUtils.h>
42 #include <SMESH_LogicalFilter.hxx>
44 // SALOME GEOM includes
46 #include <GEOM_SelectionFilter.h>
47 #include <GEOM_wrap.hxx>
49 // SALOME GUI includes
50 #include <QtxColorButton.h>
52 #include <SUIT_Desktop.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SUIT_Session.h>
55 #include <SUIT_MessageBox.h>
56 #include <SUIT_OverrideCursor.h>
58 #include <SalomeApp_Tools.h>
59 #include <SalomeApp_Application.h>
60 #include <SalomeApp_Study.h>
61 #include <LightApp_SelectionMgr.h>
63 #include <SALOME_ListIO.hxx>
65 #include <SVTK_ViewWindow.h>
67 #include <VTKViewer_Algorithm.h>
69 // SALOME KERNEL includes
70 #include <SALOMEDSClient_Study.hxx>
73 #include <vtkRenderer.h>
74 #include <vtkActorCollection.h>
77 #include <TColStd_MapOfInteger.hxx>
80 #include <QButtonGroup>
84 #include <QPushButton>
85 #include <QToolButton>
86 #include <QRadioButton>
88 #include <QGridLayout>
89 #include <QHBoxLayout>
90 #include <QVBoxLayout>
91 #include <QListWidget>
92 #include <QStackedWidget>
104 enum grpSelectionMode {
106 grpNodeSelection = 0,
108 grpBallSelection = 2,
109 grpEdgeSelection = 3,
110 grpFaceSelection = 4,
111 grpVolumeSelection = 5,
112 grpSubMeshSelection = 6,
113 grpGroupSelection = 7,
114 grpMeshSelection = 8,
115 grpGeomSelection = 9,
116 grpAllSelection = 10,
119 //=================================================================================
120 // function : SMESHGUI_GroupDlg()
122 //=================================================================================
123 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
124 SMESH::SMESH_Mesh_ptr theMesh )
125 : QDialog( SMESH::GetDesktop( theModule ) ),
126 mySMESHGUI( theModule ),
127 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
128 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
130 myNameChanged( false ),
131 myIsApplyAndClose( false ),
132 myNbChangesOfContents(0)
135 if ( !theMesh->_is_nil() )
139 mySelectSubMesh->setEnabled( false );
140 mySelectGroup->setEnabled( false );
141 myGeomGroupBtn->setEnabled( false );
142 myGeomGroupLine->setEnabled( false );
146 //=================================================================================
147 // function : SMESHGUI_GroupDlg()
149 //=================================================================================
150 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
151 SMESH::SMESH_GroupBase_ptr theGroup,
152 const bool theIsConvert )
153 : QDialog( SMESH::GetDesktop( theModule ) ),
154 mySMESHGUI( theModule ),
155 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), myStoredShownEntity(0),
156 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
158 myNameChanged( false ),
159 myNbChangesOfContents(0) // just not to use uninitialized variable
162 if ( !theGroup->_is_nil() )
163 init( theGroup, theIsConvert );
166 mySelectSubMesh->setEnabled( false );
167 mySelectGroup->setEnabled( false );
169 myCurrentLineEdit = myMeshGroupLine;
170 setSelectionMode( grpGroupSelection );
174 //=================================================================================
175 // function : SMESHGUI_GroupDlg()
177 //=================================================================================
178 void SMESHGUI_GroupDlg::initDialog( bool create)
181 setAttribute( Qt::WA_DeleteOnClose, true );
185 myCurrentLineEdit = 0;
189 myGeomObjects = new GEOM::ListOfGO();
190 myGeomObjects->length( 0 );
192 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
194 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
195 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
197 setSizeGripEnabled( true);
199 QGridLayout* aMainLayout = new QGridLayout( this );
200 aMainLayout->setMargin( MARGIN );
201 aMainLayout->setSpacing( SPACING );
203 /***************************************************************/
204 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
205 myMeshGroupBtn = new QPushButton( this );
206 myMeshGroupBtn->setIcon( image0 );
207 myMeshGroupLine = new QLineEdit( this );
208 myMeshGroupLine->setReadOnly( true );
210 /***************************************************************/
211 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
212 myTypeGroup = new QButtonGroup( this );
213 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
214 aTypeBoxLayout->setMargin( MARGIN );
215 aTypeBoxLayout->setSpacing( SPACING );
218 types.append( tr( "MESH_NODE" ) );
219 types.append( tr( "SMESH_ELEM0D" ) );
220 types.append( tr( "SMESH_BALL_ELEM" ) );
221 types.append( tr( "SMESH_EDGE" ) );
222 types.append( tr( "SMESH_FACE" ) );
223 types.append( tr( "SMESH_VOLUME" ) );
225 for ( int i = 0; i < types.count(); i++ )
227 rb = new QRadioButton( types[i], aTypeBox );
228 myTypeGroup->addButton( rb, i );
229 aTypeBoxLayout->addWidget( rb );
231 aTypeBox->setEnabled( create );
234 /***************************************************************/
235 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
236 aName->setMinimumWidth( 50 );
237 myName = new QLineEdit( this );
239 /***************************************************************/
240 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
241 myGrpTypeGroup = new QButtonGroup( this );
242 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
243 aGrpTypeBoxLayout->setMargin( MARGIN );
244 aGrpTypeBoxLayout->setSpacing( SPACING );
246 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
247 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
248 QRadioButton* rb3 = new QRadioButton( tr( "SMESH_GROUP_FILTER" ), aGrpTypeBox );
249 myGrpTypeGroup->addButton( rb1, 0 );
250 myGrpTypeGroup->addButton( rb2, 1 );
251 myGrpTypeGroup->addButton( rb3, 2 );
252 aGrpTypeBoxLayout->addWidget( rb1 );
253 aGrpTypeBoxLayout->addWidget( rb2 );
254 aGrpTypeBoxLayout->addWidget( rb3 );
255 aGrpTypeBox->setEnabled( create );
258 /***************************************************************/
259 myWGStack = new QStackedWidget( this );
260 QWidget* wg1 = new QWidget( myWGStack );
261 QWidget* wg2 = new QWidget( myWGStack );
262 QWidget* wg3 = new QWidget( myWGStack );
264 /***************************************************************/
265 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
266 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
267 aContentBoxLayout->setMargin( MARGIN );
268 aContentBoxLayout->setSpacing( SPACING );
270 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
271 myAllowElemsModif = new QCheckBox( tr( "ALLOW_ELEM_LIST_MODIF" ), aContentBox );
273 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
274 myElements = new QListWidget( aContentBox );
275 myElements->setSelectionMode( QListWidget::ExtendedSelection );
277 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
278 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
279 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
280 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
282 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
283 aContentBoxLayout->addWidget( myAllowElemsModif, 1, 0 );
284 aContentBoxLayout->addWidget( myFilterBtn, 1, 1 );
285 aContentBoxLayout->addWidget( myElementsLab, 2, 0 );
286 aContentBoxLayout->addWidget( myElements, 3, 0, 6, 1 );
287 aContentBoxLayout->addWidget( myAddBtn, 3, 1 );
288 aContentBoxLayout->addWidget( myRemoveBtn, 4, 1 );
289 aContentBoxLayout->addWidget( mySortBtn, 8, 1 );
291 aContentBoxLayout->setColumnStretch( 0, 1 );
292 aContentBoxLayout->setRowStretch( 3, 1 );
293 aContentBoxLayout->setRowStretch( 6, 1 );
295 /***************************************************************/
296 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
297 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
298 mySelectBoxLayout->setMargin( MARGIN );
299 mySelectBoxLayout->setSpacing( SPACING );
301 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
302 mySubMeshBtn = new QPushButton( mySelectBox );
303 mySubMeshBtn->setIcon( image0 );
304 mySubMeshLine = new QLineEdit( mySelectBox );
305 mySubMeshLine->setReadOnly( true );
306 onSelectSubMesh( false );
308 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
309 myGroupBtn = new QPushButton( mySelectBox );
310 myGroupBtn->setIcon( image0 );
311 myGroupLine = new QLineEdit( mySelectBox );
312 myGroupLine->setReadOnly( true );
313 onSelectGroup( false );
315 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
316 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
317 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
318 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
319 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
320 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
322 /***************************************************************/
323 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
324 wg1Layout->setMargin( 0 );
325 wg1Layout->setSpacing( SPACING );
326 wg1Layout->addWidget( aContentBox );
327 wg1Layout->addWidget( mySelectBox );
328 wg1Layout->setStretchFactor( aContentBox, 10 );
330 /***************************************************************/
331 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
332 myGeomGroupBtn = new QToolButton( wg2 );
333 myGeomGroupBtn->setIcon( image0 );
334 myGeomGroupBtn->setCheckable( true );
335 myGeomGroupLine = new QLineEdit( wg2 );
336 myGeomGroupLine->setReadOnly( true ); //VSR ???
337 onSelectGeomGroup( false );
339 myGeomGroupBtn->setEnabled( create );
340 myGeomGroupLine->setEnabled( create );
342 /***************************************************************/
343 QGridLayout* wg2Layout = new QGridLayout( wg2 );
344 wg2Layout->setMargin( 0 );
345 wg2Layout->setSpacing( SPACING );
346 wg2Layout->addWidget( geomObject, 0, 0 );
347 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
348 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
349 wg2Layout->setRowStretch( 1, 5 );
351 /***************************************************************/
352 QPushButton * aFilter2 = new QPushButton( tr( "SMESH_BUT_FILTER" ), wg3 );
353 QGridLayout* wg3Layout = new QGridLayout( wg3 );
354 wg3Layout->setMargin( 0 );
355 wg3Layout->setSpacing( SPACING );
356 wg3Layout->addWidget( aFilter2, 0, 0 );
357 wg3Layout->setRowStretch( 1, 5 );
359 /***************************************************************/
360 myWGStack->insertWidget( 0, wg1 );
361 myWGStack->insertWidget( 1, wg2 );
362 myWGStack->insertWidget( 2, wg3 );
364 /***************************************************************/
365 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
366 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
367 aColorBoxLayout->setMargin(MARGIN);
368 aColorBoxLayout->setSpacing(SPACING);
370 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
371 myColorBtn = new QtxColorButton(aColorBox);
372 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
373 myColorBtn->sizePolicy().verticalPolicy() );
375 aColorBoxLayout->addWidget(aColorLab);
376 aColorBoxLayout->addWidget(myColorBtn);
378 /***************************************************************/
380 QFrame* aButtons = new QFrame(this);
381 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
382 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
383 aBtnLayout->setMargin(MARGIN);
384 aBtnLayout->setSpacing(SPACING);
386 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
387 myOKBtn->setAutoDefault(true);
388 myOKBtn->setDefault(true);
389 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
390 myApplyBtn->setAutoDefault(true);
391 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
392 myCloseBtn->setAutoDefault(true);
393 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
394 myHelpBtn->setAutoDefault(true);
396 aBtnLayout->addWidget(myOKBtn);
397 aBtnLayout->addSpacing(10);
398 aBtnLayout->addWidget(myApplyBtn);
399 aBtnLayout->addSpacing(10);
400 aBtnLayout->addStretch();
401 aBtnLayout->addWidget(myCloseBtn);
402 aBtnLayout->addWidget(myHelpBtn);
404 /***************************************************************/
405 aMainLayout->addWidget(meshGroupLab, 0, 0);
406 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
407 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
408 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
409 aMainLayout->addWidget(aName, 2, 0);
410 aMainLayout->addWidget(myName, 2, 2);
411 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
412 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
413 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
414 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
416 /* signals and slots connections */
417 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
418 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
419 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
421 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
422 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
424 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
425 connect(aFilter2, SIGNAL(clicked()), this, SLOT(setFilters()));
426 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
427 connect(myAllowElemsModif,SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
428 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
429 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
430 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
432 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
433 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
434 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
435 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
436 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
438 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
440 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
441 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
442 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
443 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
446 mySMESHGUI->SetActiveDialogBox(this);
447 mySMESHGUI->SetState(800);
449 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
450 mySelectionMode = grpNoSelection;
452 myMeshFilter = new SMESH_TypeFilter(SMESH::MESH);
453 mySubMeshFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
454 SMESH_LogicalFilter::LO_OR,
455 /*takeOwnership=*/true);
456 myGroupFilter = new SMESH_LogicalFilter(QList<SUIT_SelectionFilter*>(),
457 SMESH_LogicalFilter::LO_OR,
458 /*takeOwnership=*/true);
459 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
461 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
462 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
463 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
464 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
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(std::string(SMESH::toUtf8(aName))) == 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( SMESH::toUtf8(aResName) );
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(SMESH::fromUtf8(theGroup->GetName()));
598 myName->blockSignals(false);
601 SALOMEDS::Color aColor = theGroup->GetColor();
602 setGroupColor( aColor );
604 myMeshGroupLine->setText(SMESH::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(SMESH::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 bool meshHasGeom = ( myMesh->_is_nil() || myMesh->HasShapeToMesh() );
734 if ( myGrpTypeId != 1 )
736 myGrpTypeGroup->button(1)->setEnabled( meshHasGeom );
740 myGeomGroupBtn->setEnabled( meshHasGeom );
741 myGeomGroupLine->setEnabled( meshHasGeom );
744 myOKBtn->setEnabled(enable);
745 myApplyBtn->setEnabled(enable);
748 //=================================================================================
749 // function : onNameChanged()
751 //=================================================================================
752 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
754 myOldName = myName->text();
756 myNameChanged = !myName->text().trimmed().isEmpty();
759 //=================================================================================
760 // function : onTypeChanged()
761 // purpose : Group elements type radio button management
762 //=================================================================================
763 void SMESHGUI_GroupDlg::onTypeChanged (int id)
765 if (myTypeId != id) {
768 if ( myGrpTypeId == 0 && myCurrentLineEdit == 0)
769 setSelectionMode(id);
771 setSelectionMode( mySelectionMode++ ); // update according to mySelectionMode
773 onObjectSelectionChanged();
778 //=================================================================================
779 // function : onGrpTypeChanged()
780 // purpose : Group type radio button management
781 //=================================================================================
782 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
784 if (myGrpTypeId != id) {
786 myWGStack->setCurrentIndex( id );
787 myName->blockSignals(true);
788 myName->setText(myOldName);
789 myName->blockSignals(false);
790 onSelectGeomGroup(id != 0);
795 //=================================================================================
796 // function : onColorChanged()
797 // purpose : Color button management
798 //=================================================================================
799 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
804 //=================================================================================
805 // function : setSelectionMode()
806 // purpose : Radio button management
807 //=================================================================================
808 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
811 if (myMesh->_is_nil())
813 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
814 bool isSelectAll = mySelectAll->isChecked() || !myAllowElemsModif->isChecked() || myGrpTypeId != 0;
815 if (mySelectionMode != theMode) {
816 // [PAL10408] mySelectionMgr->clearSelected();
817 mySelectionMgr->clearFilters();
818 SMESH::RemoveFilters();
820 if (myActorsList.count() > 0)
821 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
822 it.next()->SetPointRepresentation(false);
824 SMESH::SetPointRepresentation(false);
827 case grpNodeSelection:
828 if ( myGrpTypeId == 0 ) // standalone
830 if (myActorsList.count() > 0)
831 for (QListIterator<SMESH_Actor*> it( myActorsList ); it.hasNext(); )
832 it.next()->SetPointRepresentation(true);
834 SMESH::SetPointRepresentation(true);
836 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
838 case grpEdgeSelection:
839 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
841 case grpBallSelection:
842 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection);
845 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : Elem0DSelection);
847 case grpFaceSelection:
848 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
850 case grpVolumeSelection:
851 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
853 case grpSubMeshSelection: {
855 SMESH_TypeFilter* f = 0;
857 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH); break;
858 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_EDGE); break;
859 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_FACE); break;
860 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::SUBMESH_SOLID); break;
861 default: f = new SMESH_TypeFilter(SMESH::SUBMESH);
863 QList<SUIT_SelectionFilter*> filtList;
864 filtList.append( f );
865 filtList.append( new SMESH_TypeFilter(SMESH::SUBMESH_COMPOUND));
866 mySubMeshFilter->setFilters( filtList );
868 mySelectionMgr->installFilter( mySubMeshFilter );
870 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
873 case grpGroupSelection: {
875 SMESH_TypeFilter* f = 0;
877 case grpNodeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_NODE); break;
878 case grp0DSelection: f = new SMESH_TypeFilter(SMESH::GROUP_0D); break;
879 case grpBallSelection: f = new SMESH_TypeFilter(SMESH::GROUP_BALL); break;
880 case grpEdgeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_EDGE); break;
881 case grpFaceSelection: f = new SMESH_TypeFilter(SMESH::GROUP_FACE); break;
882 case grpVolumeSelection: f = new SMESH_TypeFilter(SMESH::GROUP_VOLUME); break;
883 default: f = new SMESH_TypeFilter(SMESH::GROUP);
885 QList<SUIT_SelectionFilter*> filtList;
886 filtList.append( f );
887 myGroupFilter->setFilters( filtList );
889 mySelectionMgr->installFilter(myGroupFilter);
890 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
893 case grpMeshSelection:
894 mySelectionMgr->installFilter(myMeshFilter);
895 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
897 case grpGeomSelection:
898 mySelectionMgr->installFilter(myGeomFilter);
899 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
902 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
905 if ( aViewWindow ) aViewWindow->Repaint();
906 mySelectionMode = theMode;
910 //=================================================================================
911 // function : onApply()
913 //=================================================================================
914 bool SMESHGUI_GroupDlg::onApply()
916 if (mySMESHGUI->isActiveStudyLocked())
919 if (myName->text().trimmed().isEmpty())
922 SMESH::ElementType aType = SMESH::ALL;
924 case grpNodeSelection: aType = SMESH::NODE; break;
925 case grp0DSelection: aType = SMESH::ELEM0D; break;
926 case grpBallSelection: aType = SMESH::BALL; break;
927 case grpEdgeSelection: aType = SMESH::EDGE; break;
928 case grpFaceSelection: aType = SMESH::FACE; break;
929 case grpVolumeSelection: aType = SMESH::VOLUME; break;
933 QStringList anEntryList;
935 SMESH::SMESH_GroupBase_var resultGroup;
936 bool isCreation, isConversion = false;
938 SUIT_OverrideCursor wc;
940 if (myGrpTypeId == 0) // standalone
942 if (!mySelectAll->isChecked() && !myElements->count() && myAllowElemsModif->isChecked())
945 mySelectionMgr->clearSelected();
947 if (myGroup->_is_nil()) { // creation or conversion
948 // check if group on geometry is not null
949 if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
950 if (myMesh->_is_nil())
952 if ( myGroupOnGeom->_is_nil() )
953 myGroup = myMesh->ConvertToStandalone( myGroupOnFilter );
955 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
957 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
958 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
963 if (myGroup->_is_nil()) { // creation
964 if (myMesh->_is_nil())
967 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
969 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
972 if ( mySelectAll->isChecked() ) {
974 myGroup->AddFrom(myMesh.in());
979 if ( !myFilter->_is_nil() &&
980 ( myNbChangesOfContents == 1 || !myAllowElemsModif->isChecked()))
982 myGroup->AddFrom( myFilter );
986 SMESH::long_array_var anIdList = new SMESH::long_array;
987 int i, k = myElements->count();
989 for (i = 0; i < k; i++) {
990 anIdList[i] = myElements->item(i)->text().toInt();
992 myGroup->Add(anIdList.inout());
999 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
1002 if ( mySelectAll->isChecked() ) {
1005 myGroup->AddFrom(myMesh.in());
1008 QList<int> aAddList;
1010 int i, total = myElements->count();
1011 for (i = 0; i < total; i++) {
1012 int anId = myElements->item(i)->text().toInt();
1013 int idx = myIdList.indexOf(anId);
1015 aAddList.append(anId);
1017 myIdList.removeAt(idx);
1019 if (!aAddList.empty()) {
1020 SMESH::long_array_var anIdList = new SMESH::long_array;
1021 int added = aAddList.count();
1022 anIdList->length(added);
1023 for (i = 0; i < added; i++)
1024 anIdList[i] = aAddList[i];
1025 myGroup->Add(anIdList.inout());
1027 if (!myIdList.empty()) {
1028 SMESH::long_array_var anIdList = new SMESH::long_array;
1029 int removed = myIdList.count();
1030 anIdList->length(removed);
1031 for (i = 0; i < removed; i++)
1032 anIdList[i] = myIdList[i];
1033 myGroup->Remove(anIdList.inout());
1035 /* init for next operation */
1037 for (i = 0; i < total; i++) {
1038 myIdList.append(myElements->item(i)->text().toInt());
1045 else if (myGrpTypeId == 1) // on geom object
1047 if (CORBA::is_nil(myGroupOnGeom)) { // creation
1048 if (myMesh->_is_nil() || !myGeomObjects->length())
1051 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1053 if (myGeomObjects->length() == 1) {
1054 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1055 SMESH::toUtf8(myName->text()),
1059 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
1060 if ( aSMESHGen->_is_nil() )
1063 // create a geometry group
1064 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1065 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1067 if (geomGen->_is_nil() || !aStudy)
1070 GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
1074 // check and add all selected GEOM objects: they must be
1075 // a sub-shapes of the main GEOM and must be of one type
1076 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
1077 for ( int i =0; i < myGeomObjects->length(); i++) {
1078 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
1080 aGroupType = aSubShapeType;
1081 else if (aSubShapeType != aGroupType) {
1082 aGroupType = TopAbs_SHAPE;
1087 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
1088 GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
1089 op->UnionList(aGroupVar, myGeomObjects);
1092 // publish the GEOM group in study
1093 QString aNewGeomGroupName ( "Auto_group_for_" );
1094 aNewGeomGroupName += myName->text();
1095 SALOMEDS::SObject_var aNewGroupSO =
1096 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
1097 SMESH::toUtf8(aNewGeomGroupName), aMeshShape);
1100 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
1101 SMESH::toUtf8(myName->text()),
1104 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1110 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
1115 if (myGrpTypeId == 2) // group on filter
1117 if ( myFilter->_is_nil() ) return false;
1119 if (CORBA::is_nil(myGroupOnFilter)) { // creation
1120 if (myMesh->_is_nil())
1123 myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
1124 SMESH::toUtf8(myName->text()),
1127 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1132 myGroupOnFilter->SetFilter( myFilter );
1134 resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
1142 SALOMEDS::Color aColor = getGroupColor();
1143 resultGroup->SetColor(aColor);
1145 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
1147 anEntryList.append( aMeshGroupSO->GetID().c_str() );
1149 resultGroup->SetName(SMESH::toUtf8(myName->text().trimmed()));
1153 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
1155 /* init for the next operation */
1157 myElements->clear();
1158 myGroup = SMESH::SMESH_Group::_nil();
1159 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1160 myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
1161 myFilter = SMESH::Filter::_nil();
1163 setDefaultGroupColor(); // reset color for case if 'auto-color' feature is enabled.
1169 if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
1171 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
1172 if ( isConversion ) { // need to reset TVisualObj and actor
1173 SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
1174 SMESH::Update( anIO,true);
1175 myActorsList.clear();
1176 anActor = SMESH::FindActorByEntry( anIO->getEntry() );
1177 if ( !anActor ) return false;
1178 myActorsList.append( anActor );
1180 anActor->setName(SMESH::toUtf8(myName->text()));
1183 switch ( myTypeId ) {
1184 case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
1185 case grp0DSelection: anActor->Set0DColor ( aColor.R, aColor.G, aColor.B ); break;
1186 case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
1187 case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
1188 case grpVolumeSelection:
1189 SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
1190 anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
1192 case grpFaceSelection:
1194 SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
1195 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
1198 // update a visible group accoding to a changed contents
1199 if ( !isConversion && anActor->GetVisibility() )
1200 SMESH::Update( anIO, true );
1204 SMESHGUI::Modified();
1205 mySMESHGUI->updateObjBrowser(true);
1206 mySelectionMgr->clearSelected();
1208 if( LightApp_Application* anApp =
1209 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1210 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1215 //=================================================================================
1216 // function : onOK()
1218 //=================================================================================
1219 void SMESHGUI_GroupDlg::onOK()
1221 setIsApplyAndClose( true );
1224 setIsApplyAndClose( false );
1226 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
1229 //=================================================================================
1230 // function : onListSelectionChanged()
1231 // purpose : Called when selection in element list is changed
1232 //=================================================================================
1233 void SMESHGUI_GroupDlg::onListSelectionChanged()
1235 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1236 if( myIsBusy || myActorsList.count() == 0 ) return;
1239 if (myCurrentLineEdit == 0) {
1240 mySelectionMgr->clearSelected();
1241 TColStd_MapOfInteger aIndexes;
1242 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1243 QListWidgetItem* anItem;
1244 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1245 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1246 SALOME_ListIO aList;
1247 aList.Append(myActorsList.first()->getIO());
1248 mySelectionMgr->setSelectedObjects(aList,false);
1253 //=================================================================================
1254 // function : onObjectSelectionChanged()
1255 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1256 //=================================================================================
1257 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1259 if ( myIsBusy || !isEnabled()) return;
1260 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1264 SALOME_ListIO aList;
1265 mySelectionMgr->selectedObjects( aList );
1267 int aNbSel = aList.Extent();
1268 myElements->clearSelection();
1270 if (myCurrentLineEdit)
1272 myCurrentLineEdit->setText( "" );
1273 QString aString = "";
1275 if (myCurrentLineEdit == myMeshGroupLine)
1277 mySelectSubMesh->setEnabled(false);
1278 mySelectGroup->setEnabled(false);
1279 myGroupLine->setText( "" );
1280 mySubMeshLine->setText( "" );
1282 myGeomGroupBtn->setEnabled(false);
1283 myGeomGroupLine->setEnabled(false);
1284 myGeomGroupLine->setText( "" );
1285 myGeomObjects = new GEOM::ListOfGO();
1286 myGeomObjects->length(0);
1288 if (myGeomGroupBtn->isChecked())
1289 myGeomGroupBtn->setChecked(false);
1291 myName->setText( "" );
1293 myElements->clear();
1296 myGroup = SMESH::SMESH_Group::_nil();
1297 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1298 restoreShowEntityMode();
1299 myMesh = SMESH::SMESH_Mesh::_nil();
1305 Handle(SALOME_InteractiveObject) IO = aList.First();
1308 restoreShowEntityMode();
1309 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1310 setShowEntityMode();
1312 if (myMesh->_is_nil())
1319 if ( myFilterDlg && !myMesh->_is_nil()){
1320 myFilterDlg->SetMesh( myMesh );
1322 myGroup = SMESH::SMESH_Group::_nil();
1324 // NPAL19389: create a group with a selection in another group
1325 // set actor of myMesh, if it is visible, else try
1326 // any visible actor of group or submesh of myMesh
1327 SetAppropriateActor();
1329 aString = aList.First()->getName();
1330 myMeshGroupLine->setText(aString);
1331 myMeshGroupLine->home( false );
1333 mySelectSubMesh->setEnabled(true);
1334 mySelectGroup->setEnabled(true);
1335 myGeomGroupBtn->setEnabled(true);
1336 myGeomGroupLine->setEnabled(true);
1340 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1341 if (aGroup->_is_nil())
1348 myGroup = SMESH::SMESH_Group::_nil();
1349 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1353 mySelectSubMesh->setEnabled(true);
1354 mySelectGroup->setEnabled(true);
1356 myCurrentLineEdit = 0;
1361 if (myGrpTypeId == 0)
1367 myElements->clear();
1368 setSelectionMode(myTypeId);
1376 else if (myCurrentLineEdit == myGeomGroupLine)
1378 myGeomObjects = new GEOM::ListOfGO();
1381 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1383 if (aNbSel == 0 || !aMeshSO)
1385 myGeomObjects->length(0);
1391 myGeomObjects->length(aNbSel);
1393 GEOM::GEOM_Object_var aGeomGroup;
1396 SALOME_ListIteratorOfListIO anIt (aList);
1397 for (; anIt.More(); anIt.Next())
1399 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1401 // Check if the object is a geometry group
1402 if (CORBA::is_nil(aGeomGroup))
1405 // Check if group constructed on the same shape as a mesh or on its child
1406 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1408 // The main shape of the group
1409 GEOM::GEOM_Object_var aGroupMainShape;
1410 if (aGeomGroup->GetType() == 37) {
1411 GEOM::GEOM_IGroupOperations_wrap anOp =
1412 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1413 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1414 // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
1417 aGroupMainShape = aGeomGroup;
1418 aGroupMainShape->Register();
1420 _PTR(SObject) aGroupMainShapeSO =
1421 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1423 _PTR(SObject) anObj, aRef;
1424 bool isRefOrSubShape = false;
1425 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1426 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1427 isRefOrSubShape = true;
1429 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1430 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1431 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1432 if (aRef->GetID() == aFather->GetID())
1433 isRefOrSubShape = true;
1435 aFather = aFather->GetFather();
1439 if (isRefOrSubShape)
1440 myGeomObjects[i++] = aGeomGroup;
1443 myGeomObjects->length(i);
1455 if (myCurrentLineEdit == mySubMeshLine)
1456 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1457 else if (myCurrentLineEdit == myGroupLine)
1458 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1459 else if (myCurrentLineEdit == myGeomGroupLine)
1460 aString = tr( "%1 Objects" ).arg(aNbSel);
1463 aString = aList.First()->getName();
1467 myCurrentLineEdit->setText(aString);
1468 myCurrentLineEdit->home(false);
1469 // 07.06.2008 skl for IPAL19574:
1470 // change name of group only if it is empty
1471 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1472 myOldName = myName->text();
1473 myName->blockSignals(true);
1474 myName->setText(aString);
1475 myName->blockSignals(false);
1480 else // !myCurrentLineEdit: local selection of nodes or elements
1482 if (aNbSel == 1 && myActorsList.count() > 0 )
1484 // NPAL19389: create a group with a selection in another group
1485 // Switch myActor to the newly selected one, if the last
1486 // is visible and belongs to group or submesh of myMesh
1487 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1488 Handle(SALOME_InteractiveObject) selIO = aList.First();
1489 if (curIO->hasEntry() && selIO->hasEntry()) {
1490 const char* selEntry = selIO->getEntry();
1491 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1492 // different objects: selected and myActor
1493 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1494 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1495 // newly selected actor is visible
1498 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1500 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1501 int len = strlen(meshEntry);
1503 if (strncmp(selEntry, meshEntry, len) == 0) {
1504 // selected object is myMesh or a part of it
1505 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1508 SMESH::SetPickable(myActor);
1517 QString aListStr = "";
1519 if (myTypeId == 0) {
1520 QListIterator<SMESH_Actor*> it( myActorsList );
1521 while ( it.hasNext() ) {
1523 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1527 QListIterator<SMESH_Actor*> it( myActorsList );
1528 while ( it.hasNext() ) {
1530 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1535 QListWidgetItem* anItem;
1536 QList<QListWidgetItem*> listItemsToSel;
1537 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1538 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1539 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1540 foreach(anItem, found)
1541 if (!anItem->isSelected())
1542 listItemsToSel.push_back(anItem);
1544 bool blocked = myElements->signalsBlocked();
1545 myElements->blockSignals(true);
1546 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1547 myElements->blockSignals(blocked);
1548 onListSelectionChanged();
1549 listItemsToSel.clear();
1554 if (myActorsList.count() == 0) {
1555 if (!myGroup->_is_nil()) {
1556 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1558 myActorsList.append( anActor );
1560 else if(!myGroupOnGeom->_is_nil()) {
1561 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1563 myActorsList.append( anActor );
1566 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1568 myActorsList.append( anActor );
1572 // somehow, if we display the mesh, while selecting from another actor,
1573 // the mesh becomes pickable, and there is no way to select any element
1574 if (myActorsList.count() > 0) {
1575 QListIterator<SMESH_Actor*> it( myActorsList );
1576 while ( it.hasNext() ) {
1577 SMESH_Actor* anActor = it.next();
1578 if ( IsActorVisible(anActor) )
1579 anActor->SetPickable(true);
1586 //=================================================================================
1587 // function : onSelectAll()
1588 // purpose : Called when "Select all" is checked
1589 //=================================================================================
1590 void SMESHGUI_GroupDlg::onSelectAll()
1592 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1594 myElementsLab->setEnabled( !noElemsModif );
1595 myElements->setEnabled ( !noElemsModif );
1596 myFilterBtn->setEnabled ( !noElemsModif );
1597 myAddBtn->setEnabled ( !noElemsModif );
1598 myRemoveBtn->setEnabled ( !noElemsModif );
1599 mySortBtn->setEnabled ( !noElemsModif );
1600 mySelectBox->setEnabled ( !noElemsModif );
1601 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1603 int selMode = mySelectionMode;
1604 mySelectionMode = grpNoSelection;
1605 setSelectionMode( selMode );
1609 //=================================================================================
1610 // function : onSelectSubMesh()
1611 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1612 //=================================================================================
1613 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1616 if (mySelectGroup->isChecked()) {
1617 mySelectGroup->setChecked(false);
1619 //VSR: else if (mySelectGeomGroup->isChecked()) {
1620 //VSR: mySelectGeomGroup->setChecked(false);
1622 myCurrentLineEdit = mySubMeshLine;
1623 setSelectionMode(grpSubMeshSelection);
1626 mySubMeshLine->setText( "" );
1627 myCurrentLineEdit = 0;
1629 setSelectionMode(myTypeId);
1631 mySubMeshBtn->setEnabled(on);
1632 mySubMeshLine->setEnabled(on);
1636 //=================================================================================
1637 // function : (onSelectGroup)
1638 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1639 //=================================================================================
1640 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1643 if (mySelectSubMesh->isChecked()) {
1644 mySelectSubMesh->setChecked(false);
1646 myCurrentLineEdit = myGroupLine;
1647 setSelectionMode(grpGroupSelection);
1650 myGroupLine->setText( "" );
1651 myCurrentLineEdit = 0;
1653 setSelectionMode(myTypeId);
1655 myGroupBtn->setEnabled(on);
1656 myGroupLine->setEnabled(on);
1660 //=================================================================================
1661 // function : (onSelectGeomGroup)
1662 // purpose : Called when group type changed. on == "on geometry" or "on filter"
1663 //=================================================================================
1664 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1667 if (mySelectSubMesh->isChecked()) {
1668 mySelectSubMesh->setChecked(false);
1670 else if (mySelectGroup->isChecked()) {
1671 mySelectGroup->setChecked(false);
1673 if ( myGrpTypeId == 1 ) { // on geometry
1674 myCurrentLineEdit = myGeomGroupLine;
1678 myCurrentLineEdit = 0;
1680 setSelectionMode(grpAllSelection);
1683 myGeomGroupBtn->setChecked(false);
1684 myGeomObjects->length(0);
1685 myGeomGroupLine->setText( "" );
1686 myCurrentLineEdit = 0;
1688 setSelectionMode( myTypeId );
1692 //=================================================================================
1693 // function : setCurrentSelection()
1695 //=================================================================================
1696 void SMESHGUI_GroupDlg::setCurrentSelection()
1698 QPushButton* send = (QPushButton*)sender();
1699 myCurrentLineEdit = 0;
1700 if (send == myMeshGroupBtn) {
1701 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1702 mySelectionMgr->clearSelected();
1704 setSelectionMode(grpMeshSelection);
1706 setSelectionMode(grpGroupSelection);
1707 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1708 myCurrentLineEdit = myMeshGroupLine;
1709 onObjectSelectionChanged();
1711 else if (send == mySubMeshBtn) {
1712 myCurrentLineEdit = mySubMeshLine;
1713 onObjectSelectionChanged();
1715 else if (send == myGroupBtn) {
1716 myCurrentLineEdit = myGroupLine;
1717 onObjectSelectionChanged();
1722 //=================================================================================
1723 // function : setFilters()
1724 // purpose : SLOT. Called when "Filter" button pressed.
1725 //=================================================================================
1726 void SMESHGUI_GroupDlg::setFilters()
1728 if(myMesh->_is_nil()) {
1729 SUIT_MessageBox::critical(this,
1731 tr("NO_MESH_SELECTED"));
1735 SMESH::ElementType aType = SMESH::ALL;
1738 case grpNodeSelection: aType = SMESH::NODE; break;
1739 case grp0DSelection: aType = SMESH::ELEM0D; break;
1740 case grpBallSelection: aType = SMESH::BALL; break;
1741 case grpEdgeSelection: aType = SMESH::EDGE; break;
1742 case grpFaceSelection: aType = SMESH::FACE; break;
1743 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1747 if ( myFilterDlg == 0 )
1749 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1750 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1753 myFilterDlg->Init( aType );
1755 if ( !myGroupOnFilter->_is_nil() )
1757 myFilterDlg->SetFilter( myFilter, aType );
1758 myFilterDlg->Init( aType );
1761 bool isStandalone = ( sender() == myFilterBtn );
1762 myFilterDlg->SetEnabled( /*setInViewer=*/isStandalone,
1763 /*diffSources=*/isStandalone );
1764 myFilterDlg->SetMesh( myMesh );
1765 myFilterDlg->SetSelection();
1766 myFilterDlg->SetSourceWg( myElements, false );
1769 myFilterDlg->show();
1772 //=================================================================================
1773 // function : onFilterAccepted()
1774 // purpose : SLOT. Called when Filter dlg closed with OK button.
1775 // Uncheck "Select submesh" and "Select group" checkboxes
1776 //=================================================================================
1777 void SMESHGUI_GroupDlg::onFilterAccepted()
1779 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1781 mySelectionMode = myTypeId;
1782 mySelectSubMesh->setChecked( false );
1783 mySelectGroup->setChecked( false );
1785 // get a filter from myFilterDlg
1786 myFilter = myFilterDlg->GetFilter();
1787 if ( !myFilter->_is_nil() ) {
1788 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1789 if ( perdicate->_is_nil() )
1790 myFilter = SMESH::Filter::_nil();
1792 // set mesh to myFilter
1793 if ( !myFilter->_is_nil() ) {
1794 SMESH::SMESH_Mesh_var mesh = myMesh;
1795 if ( mesh->_is_nil() ) {
1796 if ( !myGroup->_is_nil() )
1797 mesh = myGroup->GetMesh();
1798 else if ( !myGroupOnGeom->_is_nil() )
1799 mesh = myGroupOnGeom->GetMesh();
1800 else if ( !myGroupOnFilter->_is_nil() )
1801 mesh = myGroupOnFilter->GetMesh();
1803 myFilter->SetMesh( mesh );
1809 //=================================================================================
1810 // function : onAdd()
1812 //=================================================================================
1813 void SMESHGUI_GroupDlg::onAdd()
1815 SALOME_ListIO aList;
1816 mySelectionMgr->selectedObjects( aList );
1818 int aNbSel = aList.Extent();
1820 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1823 int sizeBefore = myElements->count();
1825 SMESH::ElementType aType = SMESH::ALL;
1827 case grpNodeSelection:
1828 aType = SMESH::NODE;
1829 mySelector->SetSelectionMode(NodeSelection);
1831 case grpBallSelection:
1832 aType = SMESH::BALL;
1833 mySelector->SetSelectionMode(BallSelection);
1835 case grp0DSelection:
1836 aType = SMESH::ELEM0D;
1837 mySelector->SetSelectionMode(Elem0DSelection);
1839 case grpEdgeSelection:
1840 aType = SMESH::EDGE;
1841 mySelector->SetSelectionMode(EdgeSelection);
1843 case grpFaceSelection:
1844 aType = SMESH::FACE;
1845 mySelector->SetSelectionMode(FaceSelection);
1847 case grpVolumeSelection:
1848 aType = SMESH::VOLUME;
1849 mySelector->SetSelectionMode(VolumeSelection);
1852 mySelector->SetSelectionMode(ActorSelection);
1855 QListWidgetItem* anItem = 0;
1856 QList<QListWidgetItem*> listItemsToSel;
1858 if (myCurrentLineEdit == 0) {
1859 //if (aNbSel != 1) { myIsBusy = false; return; }
1860 QString aListStr = "";
1862 if (myTypeId == 0) {
1863 QListIterator<SMESH_Actor*> it( myActorsList );
1864 while ( it.hasNext() ) {
1866 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1871 QListIterator<SMESH_Actor*> it( myActorsList );
1872 while ( it.hasNext() ) {
1874 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1879 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1880 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1881 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1882 if (found.count() == 0) {
1883 anItem = new QListWidgetItem(*it);
1884 myElements->addItem(anItem);
1885 if (!anItem->isSelected())
1886 listItemsToSel.push_back(anItem);
1889 foreach(anItem, found)
1890 if (!anItem->isSelected())
1891 listItemsToSel.push_back(anItem);
1894 bool blocked = myElements->signalsBlocked();
1895 myElements->blockSignals(true);
1896 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1897 myElements->blockSignals(blocked);
1898 onListSelectionChanged();
1899 listItemsToSel.clear();
1901 } else if (myCurrentLineEdit == mySubMeshLine) {
1902 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1904 SALOME_ListIO aList;
1905 mySelectionMgr->selectedObjects( aList );
1907 SALOME_ListIteratorOfListIO anIt (aList);
1908 for ( ; anIt.More(); anIt.Next()) {
1909 SMESH::SMESH_subMesh_var aSubMesh =
1910 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1911 if (!aSubMesh->_is_nil()) {
1912 // check if mesh is the same
1913 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1915 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1916 int k = anElements->length();
1917 for (int i = 0; i < k; i++) {
1918 QString aText = QString::number(anElements[i]);
1919 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1920 if (found.count() == 0) {
1921 anItem = new QListWidgetItem(aText);
1922 myElements->addItem(anItem);
1923 if (!anItem->isSelected())
1924 listItemsToSel.push_back(anItem);
1927 foreach(anItem, found)
1928 if (!anItem->isSelected())
1929 listItemsToSel.push_back(anItem);
1932 bool blocked = myElements->signalsBlocked();
1933 myElements->blockSignals(true);
1934 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1935 myElements->blockSignals(blocked);
1936 onListSelectionChanged();
1937 listItemsToSel.clear();
1939 catch (const SALOME::SALOME_Exception& ex) {
1940 SalomeApp_Tools::QtCatchCorbaException(ex);
1945 mySelectSubMesh->setChecked(false);
1947 onListSelectionChanged();
1949 } else if (myCurrentLineEdit == myGroupLine) {
1950 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1951 SALOME_ListIO aList;
1952 mySelectionMgr->selectedObjects( aList );
1954 SALOME_ListIteratorOfListIO anIt (aList);
1955 for ( ; anIt.More(); anIt.Next()) {
1956 SMESH::SMESH_GroupBase_var aGroup =
1957 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1958 if (!aGroup->_is_nil()) {
1959 // check if mesh is the same
1960 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1961 SMESH::long_array_var anElements = aGroup->GetListOfID();
1962 int k = anElements->length();
1963 for (int i = 0; i < k; i++) {
1964 QString aText = QString::number(anElements[i]);
1965 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1966 if (found.count() == 0) {
1967 anItem = new QListWidgetItem(aText);
1968 myElements->addItem(anItem);
1969 if (!anItem->isSelected())
1970 listItemsToSel.push_back(anItem);
1973 foreach(anItem, found)
1974 if (!anItem->isSelected())
1975 listItemsToSel.push_back(anItem);
1978 bool blocked = myElements->signalsBlocked();
1979 myElements->blockSignals(true);
1980 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1981 myElements->blockSignals(blocked);
1982 onListSelectionChanged();
1983 listItemsToSel.clear();
1987 mySelectGroup->setChecked(false);
1989 onListSelectionChanged();
1991 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1992 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1993 GEOM::GEOM_IGroupOperations_wrap aGroupOp =
1994 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1996 SMESH::ElementType aGroupType = SMESH::ALL;
1997 switch(aGroupOp->GetType(myGeomObjects[0])) {
1998 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
1999 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
2000 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
2001 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
2002 default: myIsBusy = false; return;
2005 if (aGroupType == aType) {
2006 _PTR(SObject) aGroupSO =
2007 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
2008 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
2010 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2011 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
2012 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
2013 aBelongToGeom->SetGeom(myGeomObjects[0]);
2014 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
2015 aBelongToGeom->SetElementType(aType);
2016 aFilter->SetPredicate(aBelongToGeom);
2018 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
2020 int k = anElements->length();
2021 for (int i = 0; i < k; i++) {
2022 QString aText = QString::number(anElements[i]);
2023 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2024 if (found.count() == 0) {
2025 anItem = new QListWidgetItem(aText);
2026 myElements->addItem(anItem);
2027 if (!anItem->isSelected())
2028 listItemsToSel.push_back(anItem);
2031 foreach(anItem, found)
2032 if (!anItem->isSelected())
2033 listItemsToSel.push_back(anItem);
2036 bool blocked = myElements->signalsBlocked();
2037 myElements->blockSignals(true);
2038 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2039 myElements->blockSignals(blocked);
2040 onListSelectionChanged();
2041 listItemsToSel.clear();
2044 //VSR: mySelectGeomGroup->setChecked(false);
2046 onListSelectionChanged();
2049 if ( sizeBefore < myElements->count() )
2050 ++myNbChangesOfContents;
2051 // mySelectionMgr->clearSelected();
2055 //=================================================================================
2056 // function : onRemove()
2058 //=================================================================================
2059 void SMESHGUI_GroupDlg::onRemove()
2062 int sizeBefore = myElements->count();
2064 if (myCurrentLineEdit == 0) {
2065 QList<QListWidgetItem*> selItems = myElements->selectedItems();
2066 QListWidgetItem* item;
2067 foreach(item, selItems) delete item;
2069 SALOME_ListIO aList;
2070 mySelectionMgr->selectedObjects( aList );
2072 int aNbSel = aList.Extent();
2074 if (aNbSel == 0) { myIsBusy = false; return; }
2076 SMESH::ElementType aType = SMESH::ALL;
2078 case grpNodeSelection: aType = SMESH::NODE; break;
2079 case grp0DSelection: aType = SMESH::ELEM0D; break;
2080 case grpBallSelection: aType = SMESH::BALL; break;
2081 case grpEdgeSelection: aType = SMESH::EDGE; break;
2082 case grpFaceSelection: aType = SMESH::FACE; break;
2083 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2086 if (myCurrentLineEdit == mySubMeshLine) {
2087 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2088 SALOME_ListIO aList;
2089 mySelectionMgr->selectedObjects( aList );
2091 SALOME_ListIteratorOfListIO anIt (aList);
2092 for ( ; anIt.More(); anIt.Next()) {
2093 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2094 if (!aSubMesh->_is_nil()) {
2095 // check if mesh is the same
2096 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2097 if (aType == SMESH::NODE) {
2099 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2100 int k = anElements->length();
2101 for (int i = 0; i < k; i++) {
2102 QList<QListWidgetItem*> found =
2103 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2104 QListWidgetItem* anItem;
2105 foreach(anItem, found) delete anItem;
2108 catch (const SALOME::SALOME_Exception& ex) {
2109 SalomeApp_Tools::QtCatchCorbaException(ex);
2114 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2115 int k = anElements->length();
2116 for (int i = 0; i < k; i++) {
2117 QList<QListWidgetItem*> found =
2118 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2119 QListWidgetItem* anItem;
2120 foreach(anItem, found) delete anItem;
2123 catch (const SALOME::SALOME_Exception& ex) {
2124 SalomeApp_Tools::QtCatchCorbaException(ex);
2131 else if (myCurrentLineEdit == myGroupLine) {
2132 Standard_Boolean aRes;
2133 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2134 SALOME_ListIO aList;
2135 mySelectionMgr->selectedObjects( aList );
2137 SALOME_ListIteratorOfListIO anIt (aList);
2138 for ( ; anIt.More(); anIt.Next()) {
2139 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2140 if (aRes && !aGroup->_is_nil()) {
2141 // check if mesh is the same
2142 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2143 SMESH::long_array_var anElements = aGroup->GetListOfID();
2144 int k = anElements->length();
2145 for (int i = 0; i < k; i++) {
2146 QList<QListWidgetItem*> found =
2147 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2148 QListWidgetItem* anItem;
2149 foreach(anItem, found) delete anItem;
2157 if ( sizeBefore > myElements->count() )
2158 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2162 //=================================================================================
2163 // function : onSort()
2165 //=================================================================================
2166 void SMESHGUI_GroupDlg::onSort()
2168 // PAL5412: sorts items in ascending by "string" value
2169 // myElements->sort(true);
2170 // myElements->update();
2171 int i, k = myElements->count();
2174 QList<int> aSelected;
2175 std::vector<int> anArray(k);
2176 // QMemArray<int> anArray(k);
2178 for (i = 0; i < k; i++) {
2179 int id = myElements->item(i)->text().toInt();
2181 if (myElements->item(i)->isSelected())
2182 aSelected.append(id);
2184 // sort & update list
2185 std::sort(anArray.begin(), anArray.end());
2187 myElements->clear();
2188 QListWidgetItem* anItem;
2189 QList<QListWidgetItem*> listItemsToSel;
2190 for (i = 0; i < k; i++) {
2191 anItem = new QListWidgetItem(QString::number(anArray[i]));
2192 myElements->addItem(anItem);
2193 if (aSelected.contains(anArray[i]))
2194 listItemsToSel.push_back(anItem);
2196 bool blocked = myElements->signalsBlocked();
2197 myElements->blockSignals(true);
2198 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2199 myElements->blockSignals(blocked);
2200 listItemsToSel.clear();
2205 //=================================================================================
2206 // function : onVisibilityChanged()
2208 //=================================================================================
2209 void SMESHGUI_GroupDlg::onVisibilityChanged()
2211 SetAppropriateActor();
2214 //=================================================================================
2215 // function : SMESHGUI_GroupDlg::reject
2216 // purpose : SLOT called when "Close" button pressed. Close dialog
2217 //=================================================================================
2218 void SMESHGUI_GroupDlg::reject()
2220 if (SMESH::GetCurrentVtkView()) {
2221 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2222 SMESH::SetPointRepresentation(false);
2223 SMESH::SetPickable();
2224 restoreShowEntityMode();
2227 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2228 SUIT_DataOwnerPtrList aList;
2229 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2230 mySelectionMgr->setSelected( aList );
2233 mySelectionMgr->clearSelected();
2234 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2235 aViewWindow->SetSelectionMode(ActorSelection);
2236 mySelectionMgr->clearFilters();
2237 mySMESHGUI->ResetState();
2241 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
2244 //=================================================================================
2245 // function : onHelp()
2247 //=================================================================================
2248 void SMESHGUI_GroupDlg::onHelp()
2250 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2252 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2256 platform = "winapplication";
2258 platform = "application";
2260 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2261 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2262 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2264 arg(myHelpFileName));
2268 //=================================================================================
2269 // function : SMESHGUI_GroupDlg::onDeactivate
2270 // purpose : SLOT called when dialog must be deativated
2271 //=================================================================================
2272 void SMESHGUI_GroupDlg::onDeactivate()
2274 mySMESHGUI->ResetState();
2278 //=================================================================================
2279 // function : SMESHGUI_GroupDlg::enterEvent
2280 // purpose : Event filter
2281 //=================================================================================
2282 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2285 mySMESHGUI->EmitSignalDeactivateDialog();
2287 mySelectionMode = grpNoSelection;
2288 setSelectionMode(myTypeId);
2289 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2290 mySMESHGUI->SetActiveDialogBox(this);
2291 mySMESHGUI->SetState(800);
2295 //=================================================================================
2296 // function : keyPressEvent()
2298 //=================================================================================
2299 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2301 QDialog::keyPressEvent( e );
2302 if ( e->isAccepted() )
2305 if ( e->key() == Qt::Key_F1 )
2312 //================================================================================
2314 * \brief Enable showing of the popup when Geometry selection btn is clicked
2315 * \param enable - true to enable
2317 //================================================================================
2319 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2321 void SMESHGUI_GroupDlg::updateGeomPopup()
2323 bool enable = false;
2325 if ( !myMesh->_is_nil() )
2326 enable = myMesh->NbEdges() > 0;
2328 if ( myGeomGroupBtn )
2330 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2332 if ( !myGeomPopup ) {
2333 myGeomPopup = new QMenu(this);
2334 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2335 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2336 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2338 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2344 //=================================================================================
2345 // function : onGeomSelectionButton()
2347 //=================================================================================
2348 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2350 if ( myGeomPopup && isBtnOn )
2352 myCurrentLineEdit = myGeomGroupLine;
2353 QAction* a = myGeomPopup->exec( QCursor::pos() );
2354 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2355 setSelectionMode(grpGeomSelection);
2359 myCurrentLineEdit = 0;
2360 setSelectionMode(grpAllSelection);
2364 //=================================================================================
2365 // function : onGeomPopup()
2367 //=================================================================================
2368 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2370 int index = myActions[a];
2371 if ( index == GEOM_BY_MESH_INDEX )
2373 mySelectionMode = grpNoSelection;
2374 if ( !myShapeByMeshOp ) {
2375 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2376 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2377 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2378 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2379 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2381 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2382 if ( !myMesh->_is_nil() ) {
2384 hide(); // stop processing selection
2386 myShapeByMeshOp->setModule( mySMESHGUI );
2387 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2388 myShapeByMeshOp->SetMesh( myMesh );
2389 myShapeByMeshOp->start();
2394 //================================================================================
2396 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2398 //================================================================================
2400 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2402 if ( myShapeByMeshOp == op ) {
2403 mySMESHGUI->getApp()->updateObjectBrowser();
2405 // Select a found geometry object
2406 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2407 if ( !aGeomVar->_is_nil() )
2409 QString ID = aGeomVar->GetStudyEntry();
2410 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2411 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2412 SALOME_ListIO anIOList;
2413 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2414 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2415 anIOList.Append( anIO );
2416 mySelectionMgr->setSelectedObjects( anIOList, false );
2417 onObjectSelectionChanged();
2423 //================================================================================
2425 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2427 //================================================================================
2429 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2431 if ( myShapeByMeshOp == op )
2434 setSelectionMode(grpGeomSelection);
2438 //=================================================================================
2439 // function : setGroupColor()
2441 //=================================================================================
2442 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2444 QColor aQColor( (int)( theColor.R * 255.0 ),
2445 (int)( theColor.G * 255.0 ),
2446 (int)( theColor.B * 255.0 ) );
2447 setGroupQColor( aQColor );
2450 //=================================================================================
2451 // function : getGroupColor()
2453 //=================================================================================
2454 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2456 QColor aQColor = getGroupQColor();
2458 SALOMEDS::Color aColor;
2459 aColor.R = (float)aQColor.red() / 255.0;
2460 aColor.G = (float)aQColor.green() / 255.0;
2461 aColor.B = (float)aQColor.blue() / 255.0;
2466 //=================================================================================
2467 // function : setGroupQColor()
2469 //=================================================================================
2470 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2472 if( theColor.isValid() )
2473 myColorBtn->setColor( theColor );
2476 //=================================================================================
2477 // function : getGroupQColor()
2479 //=================================================================================
2480 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2482 return myColorBtn->color();
2485 //=================================================================================
2486 // function : setDefaultGroupColor()
2488 //=================================================================================
2489 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2491 if( myMesh->_is_nil() )
2494 bool isAutoColor = myMesh->GetAutoColor();
2496 QColor aQColor = myColorBtn->color();
2499 if ( !aQColor.isValid() ) {
2500 int r = 0, g = 0, b = 0;
2501 SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2502 aQColor.setRgb( r, g, b );
2507 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2508 SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
2509 #else // old algorithm for auto-colors
2510 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2512 QList<SALOMEDS::Color> aReservedColors;
2513 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2515 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2516 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2517 aReservedColors.append( aReservedColor );
2520 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2521 #endif // SIMPLE_AUTOCOLOR
2523 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2524 (int)( aColor.G * 255.0 ),
2525 (int)( aColor.B * 255.0 ) );
2529 setGroupQColor( aQColor );
2532 //=================================================================================
2533 // function : SetAppropriateActor()
2534 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2535 // NPAL19389: create a group with a selection in another group.
2536 // if mesh actor is not visible - find any first visible group or submesh
2537 //=================================================================================
2538 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2540 bool isActor = false;
2541 myActorsList.clear();
2543 if (myMesh->_is_nil()) return false;
2545 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2547 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2549 if (!myGroupOnGeom->_is_nil()) {
2550 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2551 if (anActor && anActor->hasIO())
2554 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2557 myActorsList.append(anActor);
2563 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2564 if (anActor && anActor->hasIO()) {
2566 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2569 myActorsList.append(anActor);
2573 if (!isActor && !myGroup->_is_nil()) {
2574 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2575 if (anActor && anActor->hasIO())
2576 myActorsList.append(anActor);
2579 // try any visible actor of group or submesh of current mesh
2582 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2584 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2585 int len = strlen(meshEntry);
2587 // iterate on all actors in current view window, search for
2588 // any visible actor, that belongs to group or submesh of current mesh
2589 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2590 vtkActorCollection *aCollection = aCopy.GetActors();
2591 int nbItems = aCollection->GetNumberOfItems();
2592 for (int i=0; i<nbItems && !isActor; i++)
2594 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2595 if (anActor && anActor->hasIO()) {
2596 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2597 if (aViewWindow->isVisible(anIO)) {
2598 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2599 myActorsList.append(anActor);
2607 if (myActorsList.count() > 0) {
2608 QListIterator<SMESH_Actor*> it( myActorsList );
2609 while ( it.hasNext() ) {
2610 SMESH_Actor* anActor = it.next();
2611 if ( IsActorVisible(anActor) )
2612 anActor->SetPickable(true);
2616 return ( isActor || (myActorsList.count() > 0) );
2619 //=======================================================================
2620 //function : setShowEntityMode
2621 //purpose : make shown only entity corresponding to my type
2622 //=======================================================================
2623 void SMESHGUI_GroupDlg::setShowEntityMode()
2625 if ( !myMesh->_is_nil() ) {
2626 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2627 if (!myStoredShownEntity)
2628 myStoredShownEntity = actor->GetEntityMode();
2629 switch ( myTypeId ) {
2630 case grpNodeSelection: restoreShowEntityMode(); break;
2631 case grp0DSelection: actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
2632 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2633 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2634 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2635 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2641 //=======================================================================
2642 //function : restoreShowEntityMode
2643 //purpose : restore ShowEntity mode of myActor
2644 //=======================================================================
2645 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2647 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2648 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2649 actor->SetEntityMode(myStoredShownEntity);
2652 myStoredShownEntity = 0;
2655 //=======================================================================
2656 //function : IsActorVisible
2657 //purpose : return visibility of the actor
2658 //=======================================================================
2659 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2661 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2662 if (theActor && aViewWindow)
2663 return aViewWindow->isVisible(theActor->getIO());
2667 //================================================================
2668 //function : setIsApplyAndClose
2669 //purpose : Set value of the flag indicating that the dialog is
2670 // accepted by Apply & Close button
2671 //================================================================
2672 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2674 myIsApplyAndClose = theFlag;
2677 //================================================================
2678 //function : isApplyAndClose
2679 //purpose : Get value of the flag indicating that the dialog is
2680 // accepted by Apply & Close button
2681 //================================================================
2682 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2684 return myIsApplyAndClose;