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() )
1201 SMESH::Update( anIO, true );
1202 SMESH::RepaintCurrentView();
1207 SMESHGUI::Modified();
1208 mySMESHGUI->updateObjBrowser(true);
1209 mySelectionMgr->clearSelected();
1211 if( LightApp_Application* anApp =
1212 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
1213 myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
1218 //=================================================================================
1219 // function : onOK()
1221 //=================================================================================
1222 void SMESHGUI_GroupDlg::onOK()
1224 setIsApplyAndClose( true );
1227 setIsApplyAndClose( false );
1229 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
1232 //=================================================================================
1233 // function : onListSelectionChanged()
1234 // purpose : Called when selection in element list is changed
1235 //=================================================================================
1236 void SMESHGUI_GroupDlg::onListSelectionChanged()
1238 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1239 if( myIsBusy || myActorsList.count() == 0 ) return;
1242 if (myCurrentLineEdit == 0) {
1243 mySelectionMgr->clearSelected();
1244 TColStd_MapOfInteger aIndexes;
1245 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1246 QListWidgetItem* anItem;
1247 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1248 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1249 SALOME_ListIO aList;
1250 aList.Append(myActorsList.first()->getIO());
1251 mySelectionMgr->setSelectedObjects(aList,false);
1256 //=================================================================================
1257 // function : onObjectSelectionChanged()
1258 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1259 //=================================================================================
1260 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1262 if ( myIsBusy || !isEnabled()) return;
1263 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1267 SALOME_ListIO aList;
1268 mySelectionMgr->selectedObjects( aList );
1270 int aNbSel = aList.Extent();
1271 myElements->clearSelection();
1273 if (myCurrentLineEdit)
1275 myCurrentLineEdit->setText( "" );
1276 QString aString = "";
1278 if (myCurrentLineEdit == myMeshGroupLine)
1280 mySelectSubMesh->setEnabled(false);
1281 mySelectGroup->setEnabled(false);
1282 myGroupLine->setText( "" );
1283 mySubMeshLine->setText( "" );
1285 myGeomGroupBtn->setEnabled(false);
1286 myGeomGroupLine->setEnabled(false);
1287 myGeomGroupLine->setText( "" );
1288 myGeomObjects = new GEOM::ListOfGO();
1289 myGeomObjects->length(0);
1291 if (myGeomGroupBtn->isChecked())
1292 myGeomGroupBtn->setChecked(false);
1294 myName->setText( "" );
1296 myElements->clear();
1299 myGroup = SMESH::SMESH_Group::_nil();
1300 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1301 restoreShowEntityMode();
1302 myMesh = SMESH::SMESH_Mesh::_nil();
1308 Handle(SALOME_InteractiveObject) IO = aList.First();
1311 restoreShowEntityMode();
1312 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1313 setShowEntityMode();
1315 if (myMesh->_is_nil())
1322 if ( myFilterDlg && !myMesh->_is_nil()){
1323 myFilterDlg->SetMesh( myMesh );
1325 myGroup = SMESH::SMESH_Group::_nil();
1327 // NPAL19389: create a group with a selection in another group
1328 // set actor of myMesh, if it is visible, else try
1329 // any visible actor of group or submesh of myMesh
1330 SetAppropriateActor();
1332 setDefaultGroupColor();
1333 if (myName->text().isEmpty())
1336 aString = aList.First()->getName();
1337 myMeshGroupLine->setText(aString);
1338 myMeshGroupLine->home( false );
1340 mySelectSubMesh->setEnabled(true);
1341 mySelectGroup->setEnabled(true);
1342 myGeomGroupBtn->setEnabled(true);
1343 myGeomGroupLine->setEnabled(true);
1347 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1348 if (aGroup->_is_nil())
1355 myGroup = SMESH::SMESH_Group::_nil();
1356 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1360 mySelectSubMesh->setEnabled(true);
1361 mySelectGroup->setEnabled(true);
1363 myCurrentLineEdit = 0;
1368 if (myGrpTypeId == 0)
1374 myElements->clear();
1375 setSelectionMode(myTypeId);
1383 else if (myCurrentLineEdit == myGeomGroupLine)
1385 myGeomObjects = new GEOM::ListOfGO();
1388 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1390 if (aNbSel == 0 || !aMeshSO)
1392 myGeomObjects->length(0);
1398 myGeomObjects->length(aNbSel);
1400 GEOM::GEOM_Object_var aGeomGroup;
1403 SALOME_ListIteratorOfListIO anIt (aList);
1404 for (; anIt.More(); anIt.Next())
1406 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1408 // Check if the object is a geometry group
1409 if (CORBA::is_nil(aGeomGroup))
1412 // Check if group constructed on the same shape as a mesh or on its child
1413 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1415 // The main shape of the group
1416 GEOM::GEOM_Object_var aGroupMainShape;
1417 if (aGeomGroup->GetType() == 37) {
1418 GEOM::GEOM_IGroupOperations_wrap anOp =
1419 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1420 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1421 // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
1424 aGroupMainShape = aGeomGroup;
1425 aGroupMainShape->Register();
1427 _PTR(SObject) aGroupMainShapeSO =
1428 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1430 _PTR(SObject) anObj, aRef;
1431 bool isRefOrSubShape = false;
1432 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1433 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1434 isRefOrSubShape = true;
1436 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1437 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1438 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1439 if (aRef->GetID() == aFather->GetID())
1440 isRefOrSubShape = true;
1442 aFather = aFather->GetFather();
1446 if (isRefOrSubShape)
1447 myGeomObjects[i++] = aGeomGroup;
1450 myGeomObjects->length(i);
1462 if (myCurrentLineEdit == mySubMeshLine)
1463 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1464 else if (myCurrentLineEdit == myGroupLine)
1465 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1466 else if (myCurrentLineEdit == myGeomGroupLine)
1467 aString = tr( "%1 Objects" ).arg(aNbSel);
1470 aString = aList.First()->getName();
1474 myCurrentLineEdit->setText(aString);
1475 myCurrentLineEdit->home(false);
1476 // 07.06.2008 skl for IPAL19574:
1477 // change name of group only if it is empty
1478 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1479 myOldName = myName->text();
1480 myName->blockSignals(true);
1481 myName->setText(aString);
1482 myName->blockSignals(false);
1487 else // !myCurrentLineEdit: local selection of nodes or elements
1489 if (aNbSel == 1 && myActorsList.count() > 0 )
1491 // NPAL19389: create a group with a selection in another group
1492 // Switch myActor to the newly selected one, if the last
1493 // is visible and belongs to group or submesh of myMesh
1494 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1495 Handle(SALOME_InteractiveObject) selIO = aList.First();
1496 if (curIO->hasEntry() && selIO->hasEntry()) {
1497 const char* selEntry = selIO->getEntry();
1498 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1499 // different objects: selected and myActor
1500 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1501 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1502 // newly selected actor is visible
1505 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1507 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1508 int len = strlen(meshEntry);
1510 if (strncmp(selEntry, meshEntry, len) == 0) {
1511 // selected object is myMesh or a part of it
1512 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1515 SMESH::SetPickable(myActor);
1524 QString aListStr = "";
1526 if (myTypeId == 0) {
1527 QListIterator<SMESH_Actor*> it( myActorsList );
1528 while ( it.hasNext() ) {
1530 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1534 QListIterator<SMESH_Actor*> it( myActorsList );
1535 while ( it.hasNext() ) {
1537 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1542 QListWidgetItem* anItem;
1543 QList<QListWidgetItem*> listItemsToSel;
1544 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1545 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1546 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1547 foreach(anItem, found)
1548 if (!anItem->isSelected())
1549 listItemsToSel.push_back(anItem);
1551 bool blocked = myElements->signalsBlocked();
1552 myElements->blockSignals(true);
1553 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1554 myElements->blockSignals(blocked);
1555 onListSelectionChanged();
1556 listItemsToSel.clear();
1561 if (myActorsList.count() == 0) {
1562 if (!myGroup->_is_nil()) {
1563 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1565 myActorsList.append( anActor );
1567 else if(!myGroupOnGeom->_is_nil()) {
1568 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1570 myActorsList.append( anActor );
1573 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1575 myActorsList.append( anActor );
1579 // somehow, if we display the mesh, while selecting from another actor,
1580 // the mesh becomes pickable, and there is no way to select any element
1581 if (myActorsList.count() > 0) {
1582 QListIterator<SMESH_Actor*> it( myActorsList );
1583 while ( it.hasNext() ) {
1584 SMESH_Actor* anActor = it.next();
1585 if ( IsActorVisible(anActor) )
1586 anActor->SetPickable(true);
1593 //=================================================================================
1594 // function : onSelectAll()
1595 // purpose : Called when "Select all" is checked
1596 //=================================================================================
1597 void SMESHGUI_GroupDlg::onSelectAll()
1599 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1601 myElementsLab->setEnabled( !noElemsModif );
1602 myElements->setEnabled ( !noElemsModif );
1603 myFilterBtn->setEnabled ( !noElemsModif );
1604 myAddBtn->setEnabled ( !noElemsModif );
1605 myRemoveBtn->setEnabled ( !noElemsModif );
1606 mySortBtn->setEnabled ( !noElemsModif );
1607 mySelectBox->setEnabled ( !noElemsModif );
1608 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1610 int selMode = mySelectionMode;
1611 mySelectionMode = grpNoSelection;
1612 setSelectionMode( selMode );
1616 //=================================================================================
1617 // function : onSelectSubMesh()
1618 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1619 //=================================================================================
1620 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1623 if (mySelectGroup->isChecked()) {
1624 mySelectGroup->setChecked(false);
1626 //VSR: else if (mySelectGeomGroup->isChecked()) {
1627 //VSR: mySelectGeomGroup->setChecked(false);
1629 myCurrentLineEdit = mySubMeshLine;
1630 setSelectionMode(grpSubMeshSelection);
1633 mySubMeshLine->setText( "" );
1634 myCurrentLineEdit = 0;
1636 setSelectionMode(myTypeId);
1638 mySubMeshBtn->setEnabled(on);
1639 mySubMeshLine->setEnabled(on);
1643 //=================================================================================
1644 // function : (onSelectGroup)
1645 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1646 //=================================================================================
1647 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1650 if (mySelectSubMesh->isChecked()) {
1651 mySelectSubMesh->setChecked(false);
1653 myCurrentLineEdit = myGroupLine;
1654 setSelectionMode(grpGroupSelection);
1657 myGroupLine->setText( "" );
1658 myCurrentLineEdit = 0;
1660 setSelectionMode(myTypeId);
1662 myGroupBtn->setEnabled(on);
1663 myGroupLine->setEnabled(on);
1667 //=================================================================================
1668 // function : (onSelectGeomGroup)
1669 // purpose : Called when group type changed. on == "on geometry" or "on filter"
1670 //=================================================================================
1671 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1674 if (mySelectSubMesh->isChecked()) {
1675 mySelectSubMesh->setChecked(false);
1677 else if (mySelectGroup->isChecked()) {
1678 mySelectGroup->setChecked(false);
1680 if ( myGrpTypeId == 1 ) { // on geometry
1681 myCurrentLineEdit = myGeomGroupLine;
1685 myCurrentLineEdit = 0;
1687 setSelectionMode(grpAllSelection);
1690 myGeomGroupBtn->setChecked(false);
1691 myGeomObjects->length(0);
1692 myGeomGroupLine->setText( "" );
1693 myCurrentLineEdit = 0;
1695 setSelectionMode( myTypeId );
1699 //=================================================================================
1700 // function : setCurrentSelection()
1702 //=================================================================================
1703 void SMESHGUI_GroupDlg::setCurrentSelection()
1705 QPushButton* send = (QPushButton*)sender();
1706 myCurrentLineEdit = 0;
1707 if (send == myMeshGroupBtn) {
1708 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1709 mySelectionMgr->clearSelected();
1711 setSelectionMode(grpMeshSelection);
1713 setSelectionMode(grpGroupSelection);
1714 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1715 myCurrentLineEdit = myMeshGroupLine;
1716 onObjectSelectionChanged();
1718 else if (send == mySubMeshBtn) {
1719 myCurrentLineEdit = mySubMeshLine;
1720 onObjectSelectionChanged();
1722 else if (send == myGroupBtn) {
1723 myCurrentLineEdit = myGroupLine;
1724 onObjectSelectionChanged();
1729 //=================================================================================
1730 // function : setFilters()
1731 // purpose : SLOT. Called when "Filter" button pressed.
1732 //=================================================================================
1733 void SMESHGUI_GroupDlg::setFilters()
1735 if(myMesh->_is_nil()) {
1736 SUIT_MessageBox::critical(this,
1738 tr("NO_MESH_SELECTED"));
1742 SMESH::ElementType aType = SMESH::ALL;
1745 case grpNodeSelection: aType = SMESH::NODE; break;
1746 case grp0DSelection: aType = SMESH::ELEM0D; break;
1747 case grpBallSelection: aType = SMESH::BALL; break;
1748 case grpEdgeSelection: aType = SMESH::EDGE; break;
1749 case grpFaceSelection: aType = SMESH::FACE; break;
1750 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1754 if ( myFilterDlg == 0 )
1756 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1757 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1760 myFilterDlg->Init( aType );
1762 if ( !myGroupOnFilter->_is_nil() )
1764 myFilterDlg->SetFilter( myFilter, aType );
1765 myFilterDlg->Init( aType );
1768 bool isStandalone = ( sender() == myFilterBtn );
1769 myFilterDlg->SetEnabled( /*setInViewer=*/isStandalone,
1770 /*diffSources=*/isStandalone );
1771 myFilterDlg->SetMesh( myMesh );
1772 myFilterDlg->SetGroup( myGroupOnFilter );
1773 myFilterDlg->SetSelection();
1774 myFilterDlg->SetSourceWg( myElements, false );
1776 myFilterDlg->show();
1779 //=================================================================================
1780 // function : onFilterAccepted()
1781 // purpose : SLOT. Called when Filter dlg closed with OK button.
1782 // Uncheck "Select submesh" and "Select group" checkboxes
1783 //=================================================================================
1784 void SMESHGUI_GroupDlg::onFilterAccepted()
1786 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1788 mySelectionMode = myTypeId;
1789 mySelectSubMesh->setChecked( false );
1790 mySelectGroup->setChecked( false );
1792 // get a filter from myFilterDlg
1793 myFilter = myFilterDlg->GetFilter();
1794 if ( !myFilter->_is_nil() ) {
1795 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1796 if ( perdicate->_is_nil() )
1797 myFilter = SMESH::Filter::_nil();
1799 // set mesh to myFilter
1800 if ( !myFilter->_is_nil() ) {
1801 SMESH::SMESH_Mesh_var mesh = myMesh;
1802 if ( mesh->_is_nil() ) {
1803 if ( !myGroup->_is_nil() )
1804 mesh = myGroup->GetMesh();
1805 else if ( !myGroupOnGeom->_is_nil() )
1806 mesh = myGroupOnGeom->GetMesh();
1807 else if ( !myGroupOnFilter->_is_nil() )
1808 mesh = myGroupOnFilter->GetMesh();
1810 myFilter->SetMesh( mesh );
1816 //=================================================================================
1817 // function : onAdd()
1819 //=================================================================================
1820 void SMESHGUI_GroupDlg::onAdd()
1822 SALOME_ListIO aList;
1823 mySelectionMgr->selectedObjects( aList );
1825 int aNbSel = aList.Extent();
1827 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1830 int sizeBefore = myElements->count();
1832 SMESH::ElementType aType = SMESH::ALL;
1834 case grpNodeSelection:
1835 aType = SMESH::NODE;
1836 mySelector->SetSelectionMode(NodeSelection);
1838 case grpBallSelection:
1839 aType = SMESH::BALL;
1840 mySelector->SetSelectionMode(BallSelection);
1842 case grp0DSelection:
1843 aType = SMESH::ELEM0D;
1844 mySelector->SetSelectionMode(Elem0DSelection);
1846 case grpEdgeSelection:
1847 aType = SMESH::EDGE;
1848 mySelector->SetSelectionMode(EdgeSelection);
1850 case grpFaceSelection:
1851 aType = SMESH::FACE;
1852 mySelector->SetSelectionMode(FaceSelection);
1854 case grpVolumeSelection:
1855 aType = SMESH::VOLUME;
1856 mySelector->SetSelectionMode(VolumeSelection);
1859 mySelector->SetSelectionMode(ActorSelection);
1862 QListWidgetItem* anItem = 0;
1863 QList<QListWidgetItem*> listItemsToSel;
1865 if (myCurrentLineEdit == 0) {
1866 //if (aNbSel != 1) { myIsBusy = false; return; }
1867 QString aListStr = "";
1869 if (myTypeId == 0) {
1870 QListIterator<SMESH_Actor*> it( myActorsList );
1871 while ( it.hasNext() ) {
1873 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1878 QListIterator<SMESH_Actor*> it( myActorsList );
1879 while ( it.hasNext() ) {
1881 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1886 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1887 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1888 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1889 if (found.count() == 0) {
1890 anItem = new QListWidgetItem(*it);
1891 myElements->addItem(anItem);
1892 if (!anItem->isSelected())
1893 listItemsToSel.push_back(anItem);
1896 foreach(anItem, found)
1897 if (!anItem->isSelected())
1898 listItemsToSel.push_back(anItem);
1901 bool blocked = myElements->signalsBlocked();
1902 myElements->blockSignals(true);
1903 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1904 myElements->blockSignals(blocked);
1905 onListSelectionChanged();
1906 listItemsToSel.clear();
1908 } else if (myCurrentLineEdit == mySubMeshLine) {
1909 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1911 SALOME_ListIO aList;
1912 mySelectionMgr->selectedObjects( aList );
1914 SALOME_ListIteratorOfListIO anIt (aList);
1915 for ( ; anIt.More(); anIt.Next()) {
1916 SMESH::SMESH_subMesh_var aSubMesh =
1917 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1918 if (!aSubMesh->_is_nil()) {
1919 // check if mesh is the same
1920 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1922 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1923 int k = anElements->length();
1924 for (int i = 0; i < k; i++) {
1925 QString aText = QString::number(anElements[i]);
1926 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1927 if (found.count() == 0) {
1928 anItem = new QListWidgetItem(aText);
1929 myElements->addItem(anItem);
1930 if (!anItem->isSelected())
1931 listItemsToSel.push_back(anItem);
1934 foreach(anItem, found)
1935 if (!anItem->isSelected())
1936 listItemsToSel.push_back(anItem);
1939 bool blocked = myElements->signalsBlocked();
1940 myElements->blockSignals(true);
1941 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1942 myElements->blockSignals(blocked);
1943 onListSelectionChanged();
1944 listItemsToSel.clear();
1946 catch (const SALOME::SALOME_Exception& ex) {
1947 SalomeApp_Tools::QtCatchCorbaException(ex);
1952 mySelectSubMesh->setChecked(false);
1954 onListSelectionChanged();
1956 } else if (myCurrentLineEdit == myGroupLine) {
1957 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1958 SALOME_ListIO aList;
1959 mySelectionMgr->selectedObjects( aList );
1961 SALOME_ListIteratorOfListIO anIt (aList);
1962 for ( ; anIt.More(); anIt.Next()) {
1963 SMESH::SMESH_GroupBase_var aGroup =
1964 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1965 if (!aGroup->_is_nil()) {
1966 // check if mesh is the same
1967 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1968 SMESH::long_array_var anElements = aGroup->GetListOfID();
1969 int k = anElements->length();
1970 for (int i = 0; i < k; i++) {
1971 QString aText = QString::number(anElements[i]);
1972 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1973 if (found.count() == 0) {
1974 anItem = new QListWidgetItem(aText);
1975 myElements->addItem(anItem);
1976 if (!anItem->isSelected())
1977 listItemsToSel.push_back(anItem);
1980 foreach(anItem, found)
1981 if (!anItem->isSelected())
1982 listItemsToSel.push_back(anItem);
1985 bool blocked = myElements->signalsBlocked();
1986 myElements->blockSignals(true);
1987 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1988 myElements->blockSignals(blocked);
1989 onListSelectionChanged();
1990 listItemsToSel.clear();
1994 mySelectGroup->setChecked(false);
1996 onListSelectionChanged();
1998 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1999 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2000 GEOM::GEOM_IGroupOperations_wrap aGroupOp =
2001 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
2003 SMESH::ElementType aGroupType = SMESH::ALL;
2004 switch(aGroupOp->GetType(myGeomObjects[0])) {
2005 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
2006 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
2007 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
2008 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
2009 default: myIsBusy = false; return;
2012 if (aGroupType == aType) {
2013 _PTR(SObject) aGroupSO =
2014 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
2015 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
2017 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2018 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
2019 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
2020 aBelongToGeom->SetGeom(myGeomObjects[0]);
2021 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
2022 aBelongToGeom->SetElementType(aType);
2023 aFilter->SetPredicate(aBelongToGeom);
2025 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
2027 int k = anElements->length();
2028 for (int i = 0; i < k; i++) {
2029 QString aText = QString::number(anElements[i]);
2030 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2031 if (found.count() == 0) {
2032 anItem = new QListWidgetItem(aText);
2033 myElements->addItem(anItem);
2034 if (!anItem->isSelected())
2035 listItemsToSel.push_back(anItem);
2038 foreach(anItem, found)
2039 if (!anItem->isSelected())
2040 listItemsToSel.push_back(anItem);
2043 bool blocked = myElements->signalsBlocked();
2044 myElements->blockSignals(true);
2045 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2046 myElements->blockSignals(blocked);
2047 onListSelectionChanged();
2048 listItemsToSel.clear();
2051 //VSR: mySelectGeomGroup->setChecked(false);
2053 onListSelectionChanged();
2056 if ( sizeBefore < myElements->count() )
2057 ++myNbChangesOfContents;
2058 // mySelectionMgr->clearSelected();
2062 //=================================================================================
2063 // function : onRemove()
2065 //=================================================================================
2066 void SMESHGUI_GroupDlg::onRemove()
2069 int sizeBefore = myElements->count();
2071 if (myCurrentLineEdit == 0) {
2072 QList<QListWidgetItem*> selItems = myElements->selectedItems();
2073 QListWidgetItem* item;
2074 foreach(item, selItems) delete item;
2076 SALOME_ListIO aList;
2077 mySelectionMgr->selectedObjects( aList );
2079 int aNbSel = aList.Extent();
2081 if (aNbSel == 0) { myIsBusy = false; return; }
2083 SMESH::ElementType aType = SMESH::ALL;
2085 case grpNodeSelection: aType = SMESH::NODE; break;
2086 case grp0DSelection: aType = SMESH::ELEM0D; break;
2087 case grpBallSelection: aType = SMESH::BALL; break;
2088 case grpEdgeSelection: aType = SMESH::EDGE; break;
2089 case grpFaceSelection: aType = SMESH::FACE; break;
2090 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2093 if (myCurrentLineEdit == mySubMeshLine) {
2094 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2095 SALOME_ListIO aList;
2096 mySelectionMgr->selectedObjects( aList );
2098 SALOME_ListIteratorOfListIO anIt (aList);
2099 for ( ; anIt.More(); anIt.Next()) {
2100 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2101 if (!aSubMesh->_is_nil()) {
2102 // check if mesh is the same
2103 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2104 if (aType == SMESH::NODE) {
2106 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
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;
2115 catch (const SALOME::SALOME_Exception& ex) {
2116 SalomeApp_Tools::QtCatchCorbaException(ex);
2121 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2122 int k = anElements->length();
2123 for (int i = 0; i < k; i++) {
2124 QList<QListWidgetItem*> found =
2125 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2126 QListWidgetItem* anItem;
2127 foreach(anItem, found) delete anItem;
2130 catch (const SALOME::SALOME_Exception& ex) {
2131 SalomeApp_Tools::QtCatchCorbaException(ex);
2138 else if (myCurrentLineEdit == myGroupLine) {
2139 Standard_Boolean aRes;
2140 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2141 SALOME_ListIO aList;
2142 mySelectionMgr->selectedObjects( aList );
2144 SALOME_ListIteratorOfListIO anIt (aList);
2145 for ( ; anIt.More(); anIt.Next()) {
2146 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2147 if (aRes && !aGroup->_is_nil()) {
2148 // check if mesh is the same
2149 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2150 SMESH::long_array_var anElements = aGroup->GetListOfID();
2151 int k = anElements->length();
2152 for (int i = 0; i < k; i++) {
2153 QList<QListWidgetItem*> found =
2154 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2155 QListWidgetItem* anItem;
2156 foreach(anItem, found) delete anItem;
2164 if ( sizeBefore > myElements->count() )
2165 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2169 //=================================================================================
2170 // function : onSort()
2172 //=================================================================================
2173 void SMESHGUI_GroupDlg::onSort()
2175 // PAL5412: sorts items in ascending by "string" value
2176 // myElements->sort(true);
2177 // myElements->update();
2178 int i, k = myElements->count();
2181 QList<int> aSelected;
2182 std::vector<int> anArray(k);
2183 // QMemArray<int> anArray(k);
2185 for (i = 0; i < k; i++) {
2186 int id = myElements->item(i)->text().toInt();
2188 if (myElements->item(i)->isSelected())
2189 aSelected.append(id);
2191 // sort & update list
2192 std::sort(anArray.begin(), anArray.end());
2194 myElements->clear();
2195 QListWidgetItem* anItem;
2196 QList<QListWidgetItem*> listItemsToSel;
2197 for (i = 0; i < k; i++) {
2198 anItem = new QListWidgetItem(QString::number(anArray[i]));
2199 myElements->addItem(anItem);
2200 if (aSelected.contains(anArray[i]))
2201 listItemsToSel.push_back(anItem);
2203 bool blocked = myElements->signalsBlocked();
2204 myElements->blockSignals(true);
2205 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2206 myElements->blockSignals(blocked);
2207 listItemsToSel.clear();
2212 //=================================================================================
2213 // function : onVisibilityChanged()
2215 //=================================================================================
2216 void SMESHGUI_GroupDlg::onVisibilityChanged()
2218 SetAppropriateActor();
2221 //=================================================================================
2222 // function : SMESHGUI_GroupDlg::reject
2223 // purpose : SLOT called when "Close" button pressed. Close dialog
2224 //=================================================================================
2225 void SMESHGUI_GroupDlg::reject()
2227 if (SMESH::GetCurrentVtkView()) {
2228 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2229 SMESH::SetPointRepresentation(false);
2230 SMESH::SetPickable();
2231 restoreShowEntityMode();
2234 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2235 SUIT_DataOwnerPtrList aList;
2236 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2237 mySelectionMgr->setSelected( aList );
2240 mySelectionMgr->clearSelected();
2241 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2242 aViewWindow->SetSelectionMode(ActorSelection);
2243 mySelectionMgr->clearFilters();
2244 mySMESHGUI->ResetState();
2248 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
2251 //=================================================================================
2252 // function : onHelp()
2254 //=================================================================================
2255 void SMESHGUI_GroupDlg::onHelp()
2257 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2259 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2263 platform = "winapplication";
2265 platform = "application";
2267 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2268 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2269 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2271 arg(myHelpFileName));
2275 //=================================================================================
2276 // function : SMESHGUI_GroupDlg::onDeactivate
2277 // purpose : SLOT called when dialog must be deativated
2278 //=================================================================================
2279 void SMESHGUI_GroupDlg::onDeactivate()
2281 mySMESHGUI->ResetState();
2285 //=================================================================================
2286 // function : SMESHGUI_GroupDlg::enterEvent
2287 // purpose : Event filter
2288 //=================================================================================
2289 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2292 mySMESHGUI->EmitSignalDeactivateDialog();
2294 mySelectionMode = grpNoSelection;
2295 setSelectionMode(myTypeId);
2296 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2297 mySMESHGUI->SetActiveDialogBox(this);
2298 mySMESHGUI->SetState(800);
2302 //=================================================================================
2303 // function : keyPressEvent()
2305 //=================================================================================
2306 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2308 QDialog::keyPressEvent( e );
2309 if ( e->isAccepted() )
2312 if ( e->key() == Qt::Key_F1 )
2319 //================================================================================
2321 * \brief Enable showing of the popup when Geometry selection btn is clicked
2322 * \param enable - true to enable
2324 //================================================================================
2326 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2328 void SMESHGUI_GroupDlg::updateGeomPopup()
2330 bool enable = false;
2332 if ( !myMesh->_is_nil() )
2333 enable = myMesh->NbEdges() > 0;
2335 if ( myGeomGroupBtn )
2337 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2339 if ( !myGeomPopup ) {
2340 myGeomPopup = new QMenu(this);
2341 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2342 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2343 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2345 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2351 //=================================================================================
2352 // function : onGeomSelectionButton()
2354 //=================================================================================
2355 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2357 if ( myGeomPopup && isBtnOn )
2359 myCurrentLineEdit = myGeomGroupLine;
2360 QAction* a = myGeomPopup->exec( QCursor::pos() );
2361 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2362 setSelectionMode(grpGeomSelection);
2366 myCurrentLineEdit = 0;
2367 setSelectionMode(grpAllSelection);
2371 //=================================================================================
2372 // function : onGeomPopup()
2374 //=================================================================================
2375 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2377 int index = myActions[a];
2378 if ( index == GEOM_BY_MESH_INDEX )
2380 mySelectionMode = grpNoSelection;
2381 if ( !myShapeByMeshOp ) {
2382 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2383 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2384 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2385 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2386 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2388 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2389 if ( !myMesh->_is_nil() ) {
2391 hide(); // stop processing selection
2393 myShapeByMeshOp->setModule( mySMESHGUI );
2394 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2395 myShapeByMeshOp->SetMesh( myMesh );
2396 myShapeByMeshOp->start();
2401 //================================================================================
2403 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2405 //================================================================================
2407 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2409 if ( myShapeByMeshOp == op ) {
2410 mySMESHGUI->getApp()->updateObjectBrowser();
2412 // Select a found geometry object
2413 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2414 if ( !aGeomVar->_is_nil() )
2416 QString ID = aGeomVar->GetStudyEntry();
2417 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2418 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2419 SALOME_ListIO anIOList;
2420 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2421 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2422 anIOList.Append( anIO );
2423 mySelectionMgr->setSelectedObjects( anIOList, false );
2424 onObjectSelectionChanged();
2430 //================================================================================
2432 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2434 //================================================================================
2436 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2438 if ( myShapeByMeshOp == op )
2441 setSelectionMode(grpGeomSelection);
2445 //=================================================================================
2446 // function : setGroupColor()
2448 //=================================================================================
2449 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2451 QColor aQColor( (int)( theColor.R * 255.0 ),
2452 (int)( theColor.G * 255.0 ),
2453 (int)( theColor.B * 255.0 ) );
2454 setGroupQColor( aQColor );
2457 //=================================================================================
2458 // function : getGroupColor()
2460 //=================================================================================
2461 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2463 QColor aQColor = getGroupQColor();
2465 SALOMEDS::Color aColor;
2466 aColor.R = (float)aQColor.red() / 255.0;
2467 aColor.G = (float)aQColor.green() / 255.0;
2468 aColor.B = (float)aQColor.blue() / 255.0;
2473 //=================================================================================
2474 // function : setGroupQColor()
2476 //=================================================================================
2477 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2479 if( theColor.isValid() )
2480 myColorBtn->setColor( theColor );
2483 //=================================================================================
2484 // function : getGroupQColor()
2486 //=================================================================================
2487 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2489 return myColorBtn->color();
2492 //=================================================================================
2493 // function : setDefaultGroupColor()
2495 //=================================================================================
2496 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2498 if( myMesh->_is_nil() )
2501 bool isAutoColor = myMesh->GetAutoColor();
2503 QColor aQColor = myColorBtn->color();
2506 if ( !aQColor.isValid() ) {
2507 int r = 0, g = 0, b = 0;
2508 SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2509 aQColor.setRgb( r, g, b );
2514 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2515 SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
2516 #else // old algorithm for auto-colors
2517 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2519 QList<SALOMEDS::Color> aReservedColors;
2520 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2522 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2523 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2524 aReservedColors.append( aReservedColor );
2527 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2528 #endif // SIMPLE_AUTOCOLOR
2530 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2531 (int)( aColor.G * 255.0 ),
2532 (int)( aColor.B * 255.0 ) );
2536 setGroupQColor( aQColor );
2539 //=================================================================================
2540 // function : SetAppropriateActor()
2541 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2542 // NPAL19389: create a group with a selection in another group.
2543 // if mesh actor is not visible - find any first visible group or submesh
2544 //=================================================================================
2545 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2547 bool isActor = false;
2548 myActorsList.clear();
2550 if (myMesh->_is_nil()) return false;
2552 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2554 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2556 if (!myGroupOnGeom->_is_nil()) {
2557 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2558 if (anActor && anActor->hasIO())
2561 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2564 myActorsList.append(anActor);
2570 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2571 if (anActor && anActor->hasIO()) {
2573 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2576 myActorsList.append(anActor);
2580 if (!isActor && !myGroup->_is_nil()) {
2581 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2582 if (anActor && anActor->hasIO())
2583 myActorsList.append(anActor);
2586 // try any visible actor of group or submesh of current mesh
2589 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2591 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2592 int len = strlen(meshEntry);
2594 // iterate on all actors in current view window, search for
2595 // any visible actor, that belongs to group or submesh of current mesh
2596 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2597 vtkActorCollection *aCollection = aCopy.GetActors();
2598 int nbItems = aCollection->GetNumberOfItems();
2599 for (int i=0; i<nbItems && !isActor; i++)
2601 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2602 if (anActor && anActor->hasIO()) {
2603 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2604 if (aViewWindow->isVisible(anIO)) {
2605 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2606 myActorsList.append(anActor);
2614 if (myActorsList.count() > 0) {
2615 QListIterator<SMESH_Actor*> it( myActorsList );
2616 while ( it.hasNext() ) {
2617 SMESH_Actor* anActor = it.next();
2618 if ( IsActorVisible(anActor) )
2619 anActor->SetPickable(true);
2623 return ( isActor || (myActorsList.count() > 0) );
2626 //=======================================================================
2627 //function : setShowEntityMode
2628 //purpose : make shown only entity corresponding to my type
2629 //=======================================================================
2630 void SMESHGUI_GroupDlg::setShowEntityMode()
2632 if ( !myMesh->_is_nil() ) {
2633 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2634 if (!myStoredShownEntity)
2635 myStoredShownEntity = actor->GetEntityMode();
2636 switch ( myTypeId ) {
2637 case grpNodeSelection: restoreShowEntityMode(); break;
2638 case grp0DSelection: actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
2639 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2640 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2641 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2642 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2648 //=======================================================================
2649 //function : restoreShowEntityMode
2650 //purpose : restore ShowEntity mode of myActor
2651 //=======================================================================
2652 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2654 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2655 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2656 actor->SetEntityMode(myStoredShownEntity);
2659 myStoredShownEntity = 0;
2662 //=======================================================================
2663 //function : IsActorVisible
2664 //purpose : return visibility of the actor
2665 //=======================================================================
2666 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2668 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2669 if (theActor && aViewWindow)
2670 return aViewWindow->isVisible(theActor->getIO());
2674 //================================================================
2675 //function : setIsApplyAndClose
2676 //purpose : Set value of the flag indicating that the dialog is
2677 // accepted by Apply & Close button
2678 //================================================================
2679 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2681 myIsApplyAndClose = theFlag;
2684 //================================================================
2685 //function : isApplyAndClose
2686 //purpose : Get value of the flag indicating that the dialog is
2687 // accepted by Apply & Close button
2688 //================================================================
2689 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2691 return myIsApplyAndClose;