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 aString = aList.First()->getName();
1333 myMeshGroupLine->setText(aString);
1334 myMeshGroupLine->home( false );
1336 mySelectSubMesh->setEnabled(true);
1337 mySelectGroup->setEnabled(true);
1338 myGeomGroupBtn->setEnabled(true);
1339 myGeomGroupLine->setEnabled(true);
1343 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1344 if (aGroup->_is_nil())
1351 myGroup = SMESH::SMESH_Group::_nil();
1352 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1356 mySelectSubMesh->setEnabled(true);
1357 mySelectGroup->setEnabled(true);
1359 myCurrentLineEdit = 0;
1364 if (myGrpTypeId == 0)
1370 myElements->clear();
1371 setSelectionMode(myTypeId);
1379 else if (myCurrentLineEdit == myGeomGroupLine)
1381 myGeomObjects = new GEOM::ListOfGO();
1384 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1386 if (aNbSel == 0 || !aMeshSO)
1388 myGeomObjects->length(0);
1394 myGeomObjects->length(aNbSel);
1396 GEOM::GEOM_Object_var aGeomGroup;
1399 SALOME_ListIteratorOfListIO anIt (aList);
1400 for (; anIt.More(); anIt.Next())
1402 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
1404 // Check if the object is a geometry group
1405 if (CORBA::is_nil(aGeomGroup))
1408 // Check if group constructed on the same shape as a mesh or on its child
1409 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1411 // The main shape of the group
1412 GEOM::GEOM_Object_var aGroupMainShape;
1413 if (aGeomGroup->GetType() == 37) {
1414 GEOM::GEOM_IGroupOperations_wrap anOp =
1415 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1416 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1417 // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
1420 aGroupMainShape = aGeomGroup;
1421 aGroupMainShape->Register();
1423 _PTR(SObject) aGroupMainShapeSO =
1424 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1426 _PTR(SObject) anObj, aRef;
1427 bool isRefOrSubShape = false;
1428 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1429 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1430 isRefOrSubShape = true;
1432 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1433 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1434 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1435 if (aRef->GetID() == aFather->GetID())
1436 isRefOrSubShape = true;
1438 aFather = aFather->GetFather();
1442 if (isRefOrSubShape)
1443 myGeomObjects[i++] = aGeomGroup;
1446 myGeomObjects->length(i);
1458 if (myCurrentLineEdit == mySubMeshLine)
1459 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1460 else if (myCurrentLineEdit == myGroupLine)
1461 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1462 else if (myCurrentLineEdit == myGeomGroupLine)
1463 aString = tr( "%1 Objects" ).arg(aNbSel);
1466 aString = aList.First()->getName();
1470 myCurrentLineEdit->setText(aString);
1471 myCurrentLineEdit->home(false);
1472 // 07.06.2008 skl for IPAL19574:
1473 // change name of group only if it is empty
1474 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1475 myOldName = myName->text();
1476 myName->blockSignals(true);
1477 myName->setText(aString);
1478 myName->blockSignals(false);
1483 else // !myCurrentLineEdit: local selection of nodes or elements
1485 if (aNbSel == 1 && myActorsList.count() > 0 )
1487 // NPAL19389: create a group with a selection in another group
1488 // Switch myActor to the newly selected one, if the last
1489 // is visible and belongs to group or submesh of myMesh
1490 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1491 Handle(SALOME_InteractiveObject) selIO = aList.First();
1492 if (curIO->hasEntry() && selIO->hasEntry()) {
1493 const char* selEntry = selIO->getEntry();
1494 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1495 // different objects: selected and myActor
1496 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1497 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1498 // newly selected actor is visible
1501 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1503 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1504 int len = strlen(meshEntry);
1506 if (strncmp(selEntry, meshEntry, len) == 0) {
1507 // selected object is myMesh or a part of it
1508 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1511 SMESH::SetPickable(myActor);
1520 QString aListStr = "";
1522 if (myTypeId == 0) {
1523 QListIterator<SMESH_Actor*> it( myActorsList );
1524 while ( it.hasNext() ) {
1526 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1530 QListIterator<SMESH_Actor*> it( myActorsList );
1531 while ( it.hasNext() ) {
1533 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1538 QListWidgetItem* anItem;
1539 QList<QListWidgetItem*> listItemsToSel;
1540 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1541 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1542 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1543 foreach(anItem, found)
1544 if (!anItem->isSelected())
1545 listItemsToSel.push_back(anItem);
1547 bool blocked = myElements->signalsBlocked();
1548 myElements->blockSignals(true);
1549 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1550 myElements->blockSignals(blocked);
1551 onListSelectionChanged();
1552 listItemsToSel.clear();
1557 if (myActorsList.count() == 0) {
1558 if (!myGroup->_is_nil()) {
1559 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1561 myActorsList.append( anActor );
1563 else if(!myGroupOnGeom->_is_nil()) {
1564 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1566 myActorsList.append( anActor );
1569 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1571 myActorsList.append( anActor );
1575 // somehow, if we display the mesh, while selecting from another actor,
1576 // the mesh becomes pickable, and there is no way to select any element
1577 if (myActorsList.count() > 0) {
1578 QListIterator<SMESH_Actor*> it( myActorsList );
1579 while ( it.hasNext() ) {
1580 SMESH_Actor* anActor = it.next();
1581 if ( IsActorVisible(anActor) )
1582 anActor->SetPickable(true);
1589 //=================================================================================
1590 // function : onSelectAll()
1591 // purpose : Called when "Select all" is checked
1592 //=================================================================================
1593 void SMESHGUI_GroupDlg::onSelectAll()
1595 bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
1597 myElementsLab->setEnabled( !noElemsModif );
1598 myElements->setEnabled ( !noElemsModif );
1599 myFilterBtn->setEnabled ( !noElemsModif );
1600 myAddBtn->setEnabled ( !noElemsModif );
1601 myRemoveBtn->setEnabled ( !noElemsModif );
1602 mySortBtn->setEnabled ( !noElemsModif );
1603 mySelectBox->setEnabled ( !noElemsModif );
1604 myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
1606 int selMode = mySelectionMode;
1607 mySelectionMode = grpNoSelection;
1608 setSelectionMode( selMode );
1612 //=================================================================================
1613 // function : onSelectSubMesh()
1614 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1615 //=================================================================================
1616 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1619 if (mySelectGroup->isChecked()) {
1620 mySelectGroup->setChecked(false);
1622 //VSR: else if (mySelectGeomGroup->isChecked()) {
1623 //VSR: mySelectGeomGroup->setChecked(false);
1625 myCurrentLineEdit = mySubMeshLine;
1626 setSelectionMode(grpSubMeshSelection);
1629 mySubMeshLine->setText( "" );
1630 myCurrentLineEdit = 0;
1632 setSelectionMode(myTypeId);
1634 mySubMeshBtn->setEnabled(on);
1635 mySubMeshLine->setEnabled(on);
1639 //=================================================================================
1640 // function : (onSelectGroup)
1641 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1642 //=================================================================================
1643 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1646 if (mySelectSubMesh->isChecked()) {
1647 mySelectSubMesh->setChecked(false);
1649 myCurrentLineEdit = myGroupLine;
1650 setSelectionMode(grpGroupSelection);
1653 myGroupLine->setText( "" );
1654 myCurrentLineEdit = 0;
1656 setSelectionMode(myTypeId);
1658 myGroupBtn->setEnabled(on);
1659 myGroupLine->setEnabled(on);
1663 //=================================================================================
1664 // function : (onSelectGeomGroup)
1665 // purpose : Called when group type changed. on == "on geometry" or "on filter"
1666 //=================================================================================
1667 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1670 if (mySelectSubMesh->isChecked()) {
1671 mySelectSubMesh->setChecked(false);
1673 else if (mySelectGroup->isChecked()) {
1674 mySelectGroup->setChecked(false);
1676 if ( myGrpTypeId == 1 ) { // on geometry
1677 myCurrentLineEdit = myGeomGroupLine;
1681 myCurrentLineEdit = 0;
1683 setSelectionMode(grpAllSelection);
1686 myGeomGroupBtn->setChecked(false);
1687 myGeomObjects->length(0);
1688 myGeomGroupLine->setText( "" );
1689 myCurrentLineEdit = 0;
1691 setSelectionMode( myTypeId );
1695 //=================================================================================
1696 // function : setCurrentSelection()
1698 //=================================================================================
1699 void SMESHGUI_GroupDlg::setCurrentSelection()
1701 QPushButton* send = (QPushButton*)sender();
1702 myCurrentLineEdit = 0;
1703 if (send == myMeshGroupBtn) {
1704 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1705 mySelectionMgr->clearSelected();
1707 setSelectionMode(grpMeshSelection);
1709 setSelectionMode(grpGroupSelection);
1710 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1711 myCurrentLineEdit = myMeshGroupLine;
1712 onObjectSelectionChanged();
1714 else if (send == mySubMeshBtn) {
1715 myCurrentLineEdit = mySubMeshLine;
1716 onObjectSelectionChanged();
1718 else if (send == myGroupBtn) {
1719 myCurrentLineEdit = myGroupLine;
1720 onObjectSelectionChanged();
1725 //=================================================================================
1726 // function : setFilters()
1727 // purpose : SLOT. Called when "Filter" button pressed.
1728 //=================================================================================
1729 void SMESHGUI_GroupDlg::setFilters()
1731 if(myMesh->_is_nil()) {
1732 SUIT_MessageBox::critical(this,
1734 tr("NO_MESH_SELECTED"));
1738 SMESH::ElementType aType = SMESH::ALL;
1741 case grpNodeSelection: aType = SMESH::NODE; break;
1742 case grp0DSelection: aType = SMESH::ELEM0D; break;
1743 case grpBallSelection: aType = SMESH::BALL; break;
1744 case grpEdgeSelection: aType = SMESH::EDGE; break;
1745 case grpFaceSelection: aType = SMESH::FACE; break;
1746 case grpVolumeSelection: aType = SMESH::VOLUME; break;
1750 if ( myFilterDlg == 0 )
1752 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1753 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1756 myFilterDlg->Init( aType );
1758 if ( !myGroupOnFilter->_is_nil() )
1760 myFilterDlg->SetFilter( myFilter, aType );
1761 myFilterDlg->Init( aType );
1764 bool isStandalone = ( sender() == myFilterBtn );
1765 myFilterDlg->SetEnabled( /*setInViewer=*/isStandalone,
1766 /*diffSources=*/isStandalone );
1767 myFilterDlg->SetMesh( myMesh );
1768 myFilterDlg->SetGroup( myGroupOnFilter );
1769 myFilterDlg->SetSelection();
1770 myFilterDlg->SetSourceWg( myElements, false );
1772 myFilterDlg->show();
1775 //=================================================================================
1776 // function : onFilterAccepted()
1777 // purpose : SLOT. Called when Filter dlg closed with OK button.
1778 // Uncheck "Select submesh" and "Select group" checkboxes
1779 //=================================================================================
1780 void SMESHGUI_GroupDlg::onFilterAccepted()
1782 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1784 mySelectionMode = myTypeId;
1785 mySelectSubMesh->setChecked( false );
1786 mySelectGroup->setChecked( false );
1788 // get a filter from myFilterDlg
1789 myFilter = myFilterDlg->GetFilter();
1790 if ( !myFilter->_is_nil() ) {
1791 SMESH::Predicate_var perdicate = myFilter->GetPredicate();
1792 if ( perdicate->_is_nil() )
1793 myFilter = SMESH::Filter::_nil();
1795 // set mesh to myFilter
1796 if ( !myFilter->_is_nil() ) {
1797 SMESH::SMESH_Mesh_var mesh = myMesh;
1798 if ( mesh->_is_nil() ) {
1799 if ( !myGroup->_is_nil() )
1800 mesh = myGroup->GetMesh();
1801 else if ( !myGroupOnGeom->_is_nil() )
1802 mesh = myGroupOnGeom->GetMesh();
1803 else if ( !myGroupOnFilter->_is_nil() )
1804 mesh = myGroupOnFilter->GetMesh();
1806 myFilter->SetMesh( mesh );
1812 //=================================================================================
1813 // function : onAdd()
1815 //=================================================================================
1816 void SMESHGUI_GroupDlg::onAdd()
1818 SALOME_ListIO aList;
1819 mySelectionMgr->selectedObjects( aList );
1821 int aNbSel = aList.Extent();
1823 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1826 int sizeBefore = myElements->count();
1828 SMESH::ElementType aType = SMESH::ALL;
1830 case grpNodeSelection:
1831 aType = SMESH::NODE;
1832 mySelector->SetSelectionMode(NodeSelection);
1834 case grpBallSelection:
1835 aType = SMESH::BALL;
1836 mySelector->SetSelectionMode(BallSelection);
1838 case grp0DSelection:
1839 aType = SMESH::ELEM0D;
1840 mySelector->SetSelectionMode(Elem0DSelection);
1842 case grpEdgeSelection:
1843 aType = SMESH::EDGE;
1844 mySelector->SetSelectionMode(EdgeSelection);
1846 case grpFaceSelection:
1847 aType = SMESH::FACE;
1848 mySelector->SetSelectionMode(FaceSelection);
1850 case grpVolumeSelection:
1851 aType = SMESH::VOLUME;
1852 mySelector->SetSelectionMode(VolumeSelection);
1855 mySelector->SetSelectionMode(ActorSelection);
1858 QListWidgetItem* anItem = 0;
1859 QList<QListWidgetItem*> listItemsToSel;
1861 if (myCurrentLineEdit == 0) {
1862 //if (aNbSel != 1) { myIsBusy = false; return; }
1863 QString aListStr = "";
1865 if (myTypeId == 0) {
1866 QListIterator<SMESH_Actor*> it( myActorsList );
1867 while ( it.hasNext() ) {
1869 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1874 QListIterator<SMESH_Actor*> it( myActorsList );
1875 while ( it.hasNext() ) {
1877 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1882 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1883 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1884 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1885 if (found.count() == 0) {
1886 anItem = new QListWidgetItem(*it);
1887 myElements->addItem(anItem);
1888 if (!anItem->isSelected())
1889 listItemsToSel.push_back(anItem);
1892 foreach(anItem, found)
1893 if (!anItem->isSelected())
1894 listItemsToSel.push_back(anItem);
1897 bool blocked = myElements->signalsBlocked();
1898 myElements->blockSignals(true);
1899 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1900 myElements->blockSignals(blocked);
1901 onListSelectionChanged();
1902 listItemsToSel.clear();
1904 } else if (myCurrentLineEdit == mySubMeshLine) {
1905 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1907 SALOME_ListIO aList;
1908 mySelectionMgr->selectedObjects( aList );
1910 SALOME_ListIteratorOfListIO anIt (aList);
1911 for ( ; anIt.More(); anIt.Next()) {
1912 SMESH::SMESH_subMesh_var aSubMesh =
1913 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1914 if (!aSubMesh->_is_nil()) {
1915 // check if mesh is the same
1916 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1918 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1919 int k = anElements->length();
1920 for (int i = 0; i < k; i++) {
1921 QString aText = QString::number(anElements[i]);
1922 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1923 if (found.count() == 0) {
1924 anItem = new QListWidgetItem(aText);
1925 myElements->addItem(anItem);
1926 if (!anItem->isSelected())
1927 listItemsToSel.push_back(anItem);
1930 foreach(anItem, found)
1931 if (!anItem->isSelected())
1932 listItemsToSel.push_back(anItem);
1935 bool blocked = myElements->signalsBlocked();
1936 myElements->blockSignals(true);
1937 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1938 myElements->blockSignals(blocked);
1939 onListSelectionChanged();
1940 listItemsToSel.clear();
1942 catch (const SALOME::SALOME_Exception& ex) {
1943 SalomeApp_Tools::QtCatchCorbaException(ex);
1948 mySelectSubMesh->setChecked(false);
1950 onListSelectionChanged();
1952 } else if (myCurrentLineEdit == myGroupLine) {
1953 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1954 SALOME_ListIO aList;
1955 mySelectionMgr->selectedObjects( aList );
1957 SALOME_ListIteratorOfListIO anIt (aList);
1958 for ( ; anIt.More(); anIt.Next()) {
1959 SMESH::SMESH_GroupBase_var aGroup =
1960 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1961 if (!aGroup->_is_nil()) {
1962 // check if mesh is the same
1963 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1964 SMESH::long_array_var anElements = aGroup->GetListOfID();
1965 int k = anElements->length();
1966 for (int i = 0; i < k; i++) {
1967 QString aText = QString::number(anElements[i]);
1968 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1969 if (found.count() == 0) {
1970 anItem = new QListWidgetItem(aText);
1971 myElements->addItem(anItem);
1972 if (!anItem->isSelected())
1973 listItemsToSel.push_back(anItem);
1976 foreach(anItem, found)
1977 if (!anItem->isSelected())
1978 listItemsToSel.push_back(anItem);
1981 bool blocked = myElements->signalsBlocked();
1982 myElements->blockSignals(true);
1983 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1984 myElements->blockSignals(blocked);
1985 onListSelectionChanged();
1986 listItemsToSel.clear();
1990 mySelectGroup->setChecked(false);
1992 onListSelectionChanged();
1994 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1995 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1996 GEOM::GEOM_IGroupOperations_wrap aGroupOp =
1997 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1999 SMESH::ElementType aGroupType = SMESH::ALL;
2000 switch(aGroupOp->GetType(myGeomObjects[0])) {
2001 case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
2002 case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
2003 case TopAbs_FACE: aGroupType = SMESH::FACE; break;
2004 case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
2005 default: myIsBusy = false; return;
2008 if (aGroupType == aType) {
2009 _PTR(SObject) aGroupSO =
2010 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
2011 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
2013 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2014 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
2015 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
2016 aBelongToGeom->SetGeom(myGeomObjects[0]);
2017 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
2018 aBelongToGeom->SetElementType(aType);
2019 aFilter->SetPredicate(aBelongToGeom);
2021 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
2023 int k = anElements->length();
2024 for (int i = 0; i < k; i++) {
2025 QString aText = QString::number(anElements[i]);
2026 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
2027 if (found.count() == 0) {
2028 anItem = new QListWidgetItem(aText);
2029 myElements->addItem(anItem);
2030 if (!anItem->isSelected())
2031 listItemsToSel.push_back(anItem);
2034 foreach(anItem, found)
2035 if (!anItem->isSelected())
2036 listItemsToSel.push_back(anItem);
2039 bool blocked = myElements->signalsBlocked();
2040 myElements->blockSignals(true);
2041 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2042 myElements->blockSignals(blocked);
2043 onListSelectionChanged();
2044 listItemsToSel.clear();
2047 //VSR: mySelectGeomGroup->setChecked(false);
2049 onListSelectionChanged();
2052 if ( sizeBefore < myElements->count() )
2053 ++myNbChangesOfContents;
2054 // mySelectionMgr->clearSelected();
2058 //=================================================================================
2059 // function : onRemove()
2061 //=================================================================================
2062 void SMESHGUI_GroupDlg::onRemove()
2065 int sizeBefore = myElements->count();
2067 if (myCurrentLineEdit == 0) {
2068 QList<QListWidgetItem*> selItems = myElements->selectedItems();
2069 QListWidgetItem* item;
2070 foreach(item, selItems) delete item;
2072 SALOME_ListIO aList;
2073 mySelectionMgr->selectedObjects( aList );
2075 int aNbSel = aList.Extent();
2077 if (aNbSel == 0) { myIsBusy = false; return; }
2079 SMESH::ElementType aType = SMESH::ALL;
2081 case grpNodeSelection: aType = SMESH::NODE; break;
2082 case grp0DSelection: aType = SMESH::ELEM0D; break;
2083 case grpBallSelection: aType = SMESH::BALL; break;
2084 case grpEdgeSelection: aType = SMESH::EDGE; break;
2085 case grpFaceSelection: aType = SMESH::FACE; break;
2086 case grpVolumeSelection: aType = SMESH::VOLUME; break;
2089 if (myCurrentLineEdit == mySubMeshLine) {
2090 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2091 SALOME_ListIO aList;
2092 mySelectionMgr->selectedObjects( aList );
2094 SALOME_ListIteratorOfListIO anIt (aList);
2095 for ( ; anIt.More(); anIt.Next()) {
2096 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
2097 if (!aSubMesh->_is_nil()) {
2098 // check if mesh is the same
2099 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
2100 if (aType == SMESH::NODE) {
2102 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
2103 int k = anElements->length();
2104 for (int i = 0; i < k; i++) {
2105 QList<QListWidgetItem*> found =
2106 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2107 QListWidgetItem* anItem;
2108 foreach(anItem, found) delete anItem;
2111 catch (const SALOME::SALOME_Exception& ex) {
2112 SalomeApp_Tools::QtCatchCorbaException(ex);
2117 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
2118 int k = anElements->length();
2119 for (int i = 0; i < k; i++) {
2120 QList<QListWidgetItem*> found =
2121 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2122 QListWidgetItem* anItem;
2123 foreach(anItem, found) delete anItem;
2126 catch (const SALOME::SALOME_Exception& ex) {
2127 SalomeApp_Tools::QtCatchCorbaException(ex);
2134 else if (myCurrentLineEdit == myGroupLine) {
2135 Standard_Boolean aRes;
2136 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
2137 SALOME_ListIO aList;
2138 mySelectionMgr->selectedObjects( aList );
2140 SALOME_ListIteratorOfListIO anIt (aList);
2141 for ( ; anIt.More(); anIt.Next()) {
2142 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
2143 if (aRes && !aGroup->_is_nil()) {
2144 // check if mesh is the same
2145 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
2146 SMESH::long_array_var anElements = aGroup->GetListOfID();
2147 int k = anElements->length();
2148 for (int i = 0; i < k; i++) {
2149 QList<QListWidgetItem*> found =
2150 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
2151 QListWidgetItem* anItem;
2152 foreach(anItem, found) delete anItem;
2160 if ( sizeBefore > myElements->count() )
2161 myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
2165 //=================================================================================
2166 // function : onSort()
2168 //=================================================================================
2169 void SMESHGUI_GroupDlg::onSort()
2171 // PAL5412: sorts items in ascending by "string" value
2172 // myElements->sort(true);
2173 // myElements->update();
2174 int i, k = myElements->count();
2177 QList<int> aSelected;
2178 std::vector<int> anArray(k);
2179 // QMemArray<int> anArray(k);
2181 for (i = 0; i < k; i++) {
2182 int id = myElements->item(i)->text().toInt();
2184 if (myElements->item(i)->isSelected())
2185 aSelected.append(id);
2187 // sort & update list
2188 std::sort(anArray.begin(), anArray.end());
2190 myElements->clear();
2191 QListWidgetItem* anItem;
2192 QList<QListWidgetItem*> listItemsToSel;
2193 for (i = 0; i < k; i++) {
2194 anItem = new QListWidgetItem(QString::number(anArray[i]));
2195 myElements->addItem(anItem);
2196 if (aSelected.contains(anArray[i]))
2197 listItemsToSel.push_back(anItem);
2199 bool blocked = myElements->signalsBlocked();
2200 myElements->blockSignals(true);
2201 foreach(anItem, listItemsToSel) anItem->setSelected(true);
2202 myElements->blockSignals(blocked);
2203 listItemsToSel.clear();
2208 //=================================================================================
2209 // function : onVisibilityChanged()
2211 //=================================================================================
2212 void SMESHGUI_GroupDlg::onVisibilityChanged()
2214 SetAppropriateActor();
2217 //=================================================================================
2218 // function : SMESHGUI_GroupDlg::reject
2219 // purpose : SLOT called when "Close" button pressed. Close dialog
2220 //=================================================================================
2221 void SMESHGUI_GroupDlg::reject()
2223 if (SMESH::GetCurrentVtkView()) {
2224 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
2225 SMESH::SetPointRepresentation(false);
2226 SMESH::SetPickable();
2227 restoreShowEntityMode();
2230 if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
2231 SUIT_DataOwnerPtrList aList;
2232 aList.append( new LightApp_DataOwner( myObjectToSelect ) );
2233 mySelectionMgr->setSelected( aList );
2236 mySelectionMgr->clearSelected();
2237 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2238 aViewWindow->SetSelectionMode(ActorSelection);
2239 mySelectionMgr->clearFilters();
2240 mySMESHGUI->ResetState();
2244 if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
2247 //=================================================================================
2248 // function : onHelp()
2250 //=================================================================================
2251 void SMESHGUI_GroupDlg::onHelp()
2253 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2255 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2259 platform = "winapplication";
2261 platform = "application";
2263 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2264 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2265 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2267 arg(myHelpFileName));
2271 //=================================================================================
2272 // function : SMESHGUI_GroupDlg::onDeactivate
2273 // purpose : SLOT called when dialog must be deativated
2274 //=================================================================================
2275 void SMESHGUI_GroupDlg::onDeactivate()
2277 mySMESHGUI->ResetState();
2281 //=================================================================================
2282 // function : SMESHGUI_GroupDlg::enterEvent
2283 // purpose : Event filter
2284 //=================================================================================
2285 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2288 mySMESHGUI->EmitSignalDeactivateDialog();
2290 mySelectionMode = grpNoSelection;
2291 setSelectionMode(myTypeId);
2292 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2293 mySMESHGUI->SetActiveDialogBox(this);
2294 mySMESHGUI->SetState(800);
2298 //=================================================================================
2299 // function : keyPressEvent()
2301 //=================================================================================
2302 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2304 QDialog::keyPressEvent( e );
2305 if ( e->isAccepted() )
2308 if ( e->key() == Qt::Key_F1 )
2315 //================================================================================
2317 * \brief Enable showing of the popup when Geometry selection btn is clicked
2318 * \param enable - true to enable
2320 //================================================================================
2322 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2324 void SMESHGUI_GroupDlg::updateGeomPopup()
2326 bool enable = false;
2328 if ( !myMesh->_is_nil() )
2329 enable = myMesh->NbEdges() > 0;
2331 if ( myGeomGroupBtn )
2333 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2335 if ( !myGeomPopup ) {
2336 myGeomPopup = new QMenu(this);
2337 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2338 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2339 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2341 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2347 //=================================================================================
2348 // function : onGeomSelectionButton()
2350 //=================================================================================
2351 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2353 if ( myGeomPopup && isBtnOn )
2355 myCurrentLineEdit = myGeomGroupLine;
2356 QAction* a = myGeomPopup->exec( QCursor::pos() );
2357 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2358 setSelectionMode(grpGeomSelection);
2362 myCurrentLineEdit = 0;
2363 setSelectionMode(grpAllSelection);
2367 //=================================================================================
2368 // function : onGeomPopup()
2370 //=================================================================================
2371 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2373 int index = myActions[a];
2374 if ( index == GEOM_BY_MESH_INDEX )
2376 mySelectionMode = grpNoSelection;
2377 if ( !myShapeByMeshOp ) {
2378 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2379 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2380 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2381 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2382 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2384 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2385 if ( !myMesh->_is_nil() ) {
2387 hide(); // stop processing selection
2389 myShapeByMeshOp->setModule( mySMESHGUI );
2390 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2391 myShapeByMeshOp->SetMesh( myMesh );
2392 myShapeByMeshOp->start();
2397 //================================================================================
2399 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2401 //================================================================================
2403 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2405 if ( myShapeByMeshOp == op ) {
2406 mySMESHGUI->getApp()->updateObjectBrowser();
2408 // Select a found geometry object
2409 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2410 if ( !aGeomVar->_is_nil() )
2412 QString ID = aGeomVar->GetStudyEntry();
2413 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2414 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2415 SALOME_ListIO anIOList;
2416 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2417 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2418 anIOList.Append( anIO );
2419 mySelectionMgr->setSelectedObjects( anIOList, false );
2420 onObjectSelectionChanged();
2426 //================================================================================
2428 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2430 //================================================================================
2432 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2434 if ( myShapeByMeshOp == op )
2437 setSelectionMode(grpGeomSelection);
2441 //=================================================================================
2442 // function : setGroupColor()
2444 //=================================================================================
2445 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2447 QColor aQColor( (int)( theColor.R * 255.0 ),
2448 (int)( theColor.G * 255.0 ),
2449 (int)( theColor.B * 255.0 ) );
2450 setGroupQColor( aQColor );
2453 //=================================================================================
2454 // function : getGroupColor()
2456 //=================================================================================
2457 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2459 QColor aQColor = getGroupQColor();
2461 SALOMEDS::Color aColor;
2462 aColor.R = (float)aQColor.red() / 255.0;
2463 aColor.G = (float)aQColor.green() / 255.0;
2464 aColor.B = (float)aQColor.blue() / 255.0;
2469 //=================================================================================
2470 // function : setGroupQColor()
2472 //=================================================================================
2473 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2475 if( theColor.isValid() )
2476 myColorBtn->setColor( theColor );
2479 //=================================================================================
2480 // function : getGroupQColor()
2482 //=================================================================================
2483 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2485 return myColorBtn->color();
2488 //=================================================================================
2489 // function : setDefaultGroupColor()
2491 //=================================================================================
2492 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2494 if( myMesh->_is_nil() )
2497 bool isAutoColor = myMesh->GetAutoColor();
2499 QColor aQColor = myColorBtn->color();
2502 if ( !aQColor.isValid() ) {
2503 int r = 0, g = 0, b = 0;
2504 SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
2505 aQColor.setRgb( r, g, b );
2510 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2511 SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
2512 #else // old algorithm for auto-colors
2513 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2515 QList<SALOMEDS::Color> aReservedColors;
2516 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2518 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2519 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2520 aReservedColors.append( aReservedColor );
2523 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2524 #endif // SIMPLE_AUTOCOLOR
2526 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2527 (int)( aColor.G * 255.0 ),
2528 (int)( aColor.B * 255.0 ) );
2532 setGroupQColor( aQColor );
2535 //=================================================================================
2536 // function : SetAppropriateActor()
2537 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2538 // NPAL19389: create a group with a selection in another group.
2539 // if mesh actor is not visible - find any first visible group or submesh
2540 //=================================================================================
2541 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2543 bool isActor = false;
2544 myActorsList.clear();
2546 if (myMesh->_is_nil()) return false;
2548 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2550 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2552 if (!myGroupOnGeom->_is_nil()) {
2553 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2554 if (anActor && anActor->hasIO())
2557 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2560 myActorsList.append(anActor);
2566 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2567 if (anActor && anActor->hasIO()) {
2569 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2572 myActorsList.append(anActor);
2576 if (!isActor && !myGroup->_is_nil()) {
2577 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2578 if (anActor && anActor->hasIO())
2579 myActorsList.append(anActor);
2582 // try any visible actor of group or submesh of current mesh
2585 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2587 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2588 int len = strlen(meshEntry);
2590 // iterate on all actors in current view window, search for
2591 // any visible actor, that belongs to group or submesh of current mesh
2592 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2593 vtkActorCollection *aCollection = aCopy.GetActors();
2594 int nbItems = aCollection->GetNumberOfItems();
2595 for (int i=0; i<nbItems && !isActor; i++)
2597 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2598 if (anActor && anActor->hasIO()) {
2599 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2600 if (aViewWindow->isVisible(anIO)) {
2601 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2602 myActorsList.append(anActor);
2610 if (myActorsList.count() > 0) {
2611 QListIterator<SMESH_Actor*> it( myActorsList );
2612 while ( it.hasNext() ) {
2613 SMESH_Actor* anActor = it.next();
2614 if ( IsActorVisible(anActor) )
2615 anActor->SetPickable(true);
2619 return ( isActor || (myActorsList.count() > 0) );
2622 //=======================================================================
2623 //function : setShowEntityMode
2624 //purpose : make shown only entity corresponding to my type
2625 //=======================================================================
2626 void SMESHGUI_GroupDlg::setShowEntityMode()
2628 if ( !myMesh->_is_nil() ) {
2629 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2630 if (!myStoredShownEntity)
2631 myStoredShownEntity = actor->GetEntityMode();
2632 switch ( myTypeId ) {
2633 case grpNodeSelection: restoreShowEntityMode(); break;
2634 case grp0DSelection: actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
2635 case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
2636 case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2637 case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2638 case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2644 //=======================================================================
2645 //function : restoreShowEntityMode
2646 //purpose : restore ShowEntity mode of myActor
2647 //=======================================================================
2648 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2650 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2651 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2652 actor->SetEntityMode(myStoredShownEntity);
2655 myStoredShownEntity = 0;
2658 //=======================================================================
2659 //function : IsActorVisible
2660 //purpose : return visibility of the actor
2661 //=======================================================================
2662 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2664 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2665 if (theActor && aViewWindow)
2666 return aViewWindow->isVisible(theActor->getIO());
2670 //================================================================
2671 //function : setIsApplyAndClose
2672 //purpose : Set value of the flag indicating that the dialog is
2673 // accepted by Apply & Close button
2674 //================================================================
2675 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2677 myIsApplyAndClose = theFlag;
2680 //================================================================
2681 //function : isApplyAndClose
2682 //purpose : Get value of the flag indicating that the dialog is
2683 // accepted by Apply & Close button
2684 //================================================================
2685 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2687 return myIsApplyAndClose;