1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_GroupDlg.cxx
25 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
28 #include "SMESHGUI_GroupDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_GroupUtils.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
36 #include "SMESHGUI_FilterDlg.h"
37 #include "SMESHGUI_ShapeByMeshDlg.h"
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_Actor.h>
41 #include <SMESH_ActorUtils.h>
43 // SALOME GEOM includes
45 #include <GEOM_SelectionFilter.h>
47 // SALOME GUI includes
48 #include <QtxColorButton.h>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_ResourceMgr.h>
52 #include <SUIT_Session.h>
53 #include <SUIT_MessageBox.h>
55 #include <SalomeApp_Tools.h>
56 #include <SalomeApp_Application.h>
57 #include <SalomeApp_Study.h>
58 #include <LightApp_SelectionMgr.h>
60 #include <SALOME_ListIO.hxx>
61 #include <SALOME_ListIteratorOfListIO.hxx>
63 #include <SVTK_ViewWindow.h>
65 #include <VTKViewer_Algorithm.h>
67 // SALOME KERNEL includes
68 #include <SALOMEDSClient_Study.hxx>
71 #include <vtkRenderer.h>
72 #include <vtkActorCollection.h>
75 #include <TColStd_MapOfInteger.hxx>
78 #include <QButtonGroup>
82 #include <QPushButton>
83 #include <QToolButton>
84 #include <QRadioButton>
86 #include <QGridLayout>
87 #include <QHBoxLayout>
88 #include <QVBoxLayout>
89 #include <QListWidget>
90 #include <QStackedWidget>
102 enum grpSelectionMode {
104 grpNodeSelection = 0,
105 grpEdgeSelection = 1,
106 grpFaceSelection = 2,
107 grpVolumeSelection = 3,
108 grpSubMeshSelection = 4,
109 grpGroupSelection = 5,
110 grpMeshSelection = 6,
111 grpGeomSelection = 7,
115 //=================================================================================
116 // function : SMESHGUI_GroupDlg()
118 //=================================================================================
119 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
120 SMESH::SMESH_Mesh_ptr theMesh )
121 : QDialog( SMESH::GetDesktop( theModule ) ),
122 mySMESHGUI( theModule ),
123 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
124 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
126 myNameChanged( false )
129 if ( !theMesh->_is_nil() )
133 mySelectSubMesh->setEnabled( false );
134 mySelectGroup->setEnabled( false );
135 myGeomGroupBtn->setEnabled( false );
136 myGeomGroupLine->setEnabled( false );
140 //=================================================================================
141 // function : SMESHGUI_GroupDlg()
143 //=================================================================================
144 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
145 SMESH::SMESH_GroupBase_ptr theGroup,
146 const bool theIsConvert )
147 : QDialog( SMESH::GetDesktop( theModule ) ),
148 mySMESHGUI( theModule ),
149 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
150 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
152 myNameChanged( false )
155 if ( !theGroup->_is_nil() )
156 init( theGroup, theIsConvert );
159 mySelectSubMesh->setEnabled( false );
160 mySelectGroup->setEnabled( false );
162 myCurrentLineEdit = myMeshGroupLine;
163 setSelectionMode( grpGroupSelection );
167 //=================================================================================
168 // function : SMESHGUI_GroupDlg()
170 //=================================================================================
171 void SMESHGUI_GroupDlg::initDialog( bool create)
174 setAttribute( Qt::WA_DeleteOnClose, true );
178 myCurrentLineEdit = 0;
182 myGeomObjects = new GEOM::ListOfGO();
183 myGeomObjects->length( 0 );
185 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
187 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
188 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
190 setSizeGripEnabled( true);
192 QGridLayout* aMainLayout = new QGridLayout( this );
193 aMainLayout->setMargin( MARGIN );
194 aMainLayout->setSpacing( SPACING );
196 /***************************************************************/
197 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
198 myMeshGroupBtn = new QPushButton( this );
199 myMeshGroupBtn->setIcon( image0 );
200 myMeshGroupLine = new QLineEdit( this );
201 myMeshGroupLine->setReadOnly( true );
203 /***************************************************************/
204 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
205 myTypeGroup = new QButtonGroup( this );
206 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
207 aTypeBoxLayout->setMargin( MARGIN );
208 aTypeBoxLayout->setSpacing( SPACING );
211 types.append( tr( "MESH_NODE" ) );
212 types.append( tr( "SMESH_EDGE" ) );
213 types.append( tr( "SMESH_FACE" ) );
214 types.append( tr( "SMESH_VOLUME" ) );
216 for ( int i = 0; i < types.count(); i++ )
218 rb = new QRadioButton( types[i], aTypeBox );
219 myTypeGroup->addButton( rb, i );
220 aTypeBoxLayout->addWidget( rb );
222 aTypeBox->setEnabled( create );
225 /***************************************************************/
226 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
227 aName->setMinimumWidth( 50 );
228 myName = new QLineEdit( this );
230 /***************************************************************/
231 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
232 myGrpTypeGroup = new QButtonGroup( this );
233 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
234 aGrpTypeBoxLayout->setMargin( MARGIN );
235 aGrpTypeBoxLayout->setSpacing( SPACING );
237 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
238 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
239 myGrpTypeGroup->addButton( rb1, 0 );
240 myGrpTypeGroup->addButton( rb2, 1 );
241 aGrpTypeBoxLayout->addWidget( rb1 );
242 aGrpTypeBoxLayout->addWidget( rb2 );
243 aGrpTypeBox->setEnabled( create );
246 /***************************************************************/
247 myWGStack = new QStackedWidget( this );
248 QWidget* wg1 = new QWidget( myWGStack );
249 QWidget* wg2 = new QWidget( myWGStack );
251 /***************************************************************/
252 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
253 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
254 aContentBoxLayout->setMargin( MARGIN );
255 aContentBoxLayout->setSpacing( SPACING );
257 mySelectAll = new QCheckBox( tr( "SELECT_ALL" ), aContentBox );
259 myElementsLab = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
260 myElements = new QListWidget( aContentBox );
261 myElements->setSelectionMode( QListWidget::ExtendedSelection );
263 myFilter = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
264 myAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
265 myRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
266 mySortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
268 aContentBoxLayout->addWidget( mySelectAll, 0, 0 );
269 aContentBoxLayout->addWidget( myElementsLab, 1, 0 );
270 aContentBoxLayout->addWidget( myElements, 2, 0, 6, 1 );
271 aContentBoxLayout->addWidget( myFilter, 2, 1 );
272 aContentBoxLayout->addWidget( myAddBtn, 4, 1 );
273 aContentBoxLayout->addWidget( myRemoveBtn, 5, 1 );
274 aContentBoxLayout->addWidget( mySortBtn, 7, 1 );
276 aContentBoxLayout->setColumnStretch( 0, 1 );
277 aContentBoxLayout->setRowStretch( 3, 1 );
278 aContentBoxLayout->setRowStretch( 6, 1 );
280 /***************************************************************/
281 mySelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
282 QGridLayout* mySelectBoxLayout = new QGridLayout( mySelectBox );
283 mySelectBoxLayout->setMargin( MARGIN );
284 mySelectBoxLayout->setSpacing( SPACING );
286 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), mySelectBox );
287 mySubMeshBtn = new QPushButton( mySelectBox );
288 mySubMeshBtn->setIcon( image0 );
289 mySubMeshLine = new QLineEdit( mySelectBox );
290 mySubMeshLine->setReadOnly( true );
291 onSelectSubMesh( false );
293 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), mySelectBox );
294 myGroupBtn = new QPushButton( mySelectBox );
295 myGroupBtn->setIcon( image0 );
296 myGroupLine = new QLineEdit( mySelectBox );
297 myGroupLine->setReadOnly( true );
298 onSelectGroup( false );
300 mySelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
301 mySelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
302 mySelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
303 mySelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
304 mySelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
305 mySelectBoxLayout->addWidget( myGroupLine, 1, 2 );
307 /***************************************************************/
308 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
309 wg1Layout->setMargin( 0 );
310 wg1Layout->setSpacing( SPACING );
311 wg1Layout->addWidget( aContentBox );
312 wg1Layout->addWidget( mySelectBox );
313 wg1Layout->setStretchFactor( aContentBox, 10 );
315 /***************************************************************/
316 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
317 myGeomGroupBtn = new QToolButton( wg2 );
318 myGeomGroupBtn->setIcon( image0 );
319 myGeomGroupBtn->setCheckable( true );
320 myGeomGroupLine = new QLineEdit( wg2 );
321 myGeomGroupLine->setReadOnly( true ); //VSR ???
322 onSelectGeomGroup( false );
324 myGeomGroupBtn->setEnabled( create );
325 myGeomGroupLine->setEnabled( create );
327 /***************************************************************/
328 QGridLayout* wg2Layout = new QGridLayout( wg2 );
329 wg2Layout->setMargin( 0 );
330 wg1Layout->setSpacing( SPACING );
331 wg2Layout->addWidget( geomObject, 0, 0 );
332 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
333 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
334 wg2Layout->setRowStretch( 1, 5 );
336 /***************************************************************/
337 myWGStack->insertWidget( 0, wg1 );
338 myWGStack->insertWidget( 1, wg2 );
340 /***************************************************************/
341 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
342 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
343 aColorBoxLayout->setMargin(MARGIN);
344 aColorBoxLayout->setSpacing(SPACING);
346 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
347 myColorBtn = new QtxColorButton(aColorBox);
348 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
349 myColorBtn->sizePolicy().verticalPolicy() );
351 aColorBoxLayout->addWidget(aColorLab);
352 aColorBoxLayout->addWidget(myColorBtn);
354 /***************************************************************/
356 QFrame* aButtons = new QFrame(this);
357 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
358 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
359 aBtnLayout->setMargin(MARGIN);
360 aBtnLayout->setSpacing(SPACING);
362 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
363 myOKBtn->setAutoDefault(true);
364 myOKBtn->setDefault(true);
365 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
366 myApplyBtn->setAutoDefault(true);
367 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
368 myCloseBtn->setAutoDefault(true);
369 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
370 myHelpBtn->setAutoDefault(true);
372 aBtnLayout->addWidget(myOKBtn);
373 aBtnLayout->addSpacing(10);
374 aBtnLayout->addWidget(myApplyBtn);
375 aBtnLayout->addSpacing(10);
376 aBtnLayout->addStretch();
377 aBtnLayout->addWidget(myCloseBtn);
378 aBtnLayout->addWidget(myHelpBtn);
380 /***************************************************************/
381 aMainLayout->addWidget(meshGroupLab, 0, 0);
382 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
383 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
384 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
385 aMainLayout->addWidget(aName, 2, 0);
386 aMainLayout->addWidget(myName, 2, 2);
387 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
388 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
389 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
390 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
392 /* signals and slots connections */
393 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
394 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
395 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
397 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
398 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
400 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
401 connect(mySelectAll, SIGNAL(toggled(bool)), this, SLOT(onSelectAll()));
402 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
403 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
404 connect(mySortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
406 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
407 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
408 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
409 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
410 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
412 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
414 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
415 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
416 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
417 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
420 mySMESHGUI->SetActiveDialogBox(this);
421 mySMESHGUI->SetState(800);
423 mySelectionMode = grpNoSelection;
424 myMeshFilter = new SMESH_TypeFilter(MESH);
425 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
426 myGroupFilter = new SMESH_TypeFilter(GROUP);
427 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
428 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
430 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
431 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
432 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
433 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
435 rb1->setChecked(true); // VSR !!!
436 onGrpTypeChanged(0); // VSR!!!
438 if (myMesh->_is_nil() )
439 myTypeGroup->button(0)->setChecked(true);
442 //myName->setText(GetDefaultName(tr( "SMESH_GROUP" )));
445 //=================================================================================
446 // function : ~SMESHGUI_GroupDlg()
447 // purpose : Destroys the object and frees any allocated resources
448 //=================================================================================
449 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
451 // no need to delete child widgets, Qt does it all for us
452 if ( myFilterDlg != 0 ) {
453 myFilterDlg->setParent( 0 );
458 //=================================================================================
459 // function : GetDefaultName()
460 // purpose : Get the Group Name if Create new Group
461 //=================================================================================
462 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
466 // collect all object names of SMESH component
467 SalomeApp_Study* appStudy =
468 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
469 if ( !appStudy ) return aName;
470 _PTR(Study) aStudy = appStudy->studyDS();
472 std::set<std::string> aSet;
473 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
475 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
477 for (it->InitEx(true); it->More(); it->Next()) {
479 aSet.insert(obj->GetName());
483 // build a unique name
485 bool isUnique = false;
487 aName = theOperation + "_" + QString::number(++aNumber);
488 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
494 //=================================================================================
497 //=================================================================================
498 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
500 mySelectionMgr->installFilter(myMeshFilter);
502 /* init data from current selection */
503 restoreShowEntityMode();
504 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
506 myGroup = SMESH::SMESH_Group::_nil();
507 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
509 // NPAL19389: create a group with a selection in another group
510 // set actor of myMesh, if it is visible, else try
511 // any visible actor of group or submesh of myMesh
512 SetAppropriateActor();
514 setDefaultGroupColor();
517 mySelectionMgr->selectedObjects( aList );
518 if( !aList.IsEmpty() )
520 QString aName = aList.First()->getName();
521 myMeshGroupLine->setText(aName);
522 myMeshGroupLine->home( false );
525 myCurrentLineEdit = 0;
527 myTypeGroup->button(0)->setChecked(true);
531 //=================================================================================
534 //=================================================================================
535 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
536 const bool theIsConvert)
538 restoreShowEntityMode();
539 myMesh = theGroup->GetMesh();
542 myNameChanged = true;
543 myName->blockSignals(true);
544 myName->setText(theGroup->GetName());
545 myName->blockSignals(false);
548 SALOMEDS::Color aColor = theGroup->GetColor();
549 setGroupColor( aColor );
551 myMeshGroupLine->setText(theGroup->GetName());
554 switch(theGroup->GetType()) {
555 case SMESH::NODE: aType= 0; break;
556 case SMESH::EDGE: aType = 1; break;
557 case SMESH::FACE: aType = 2; break;
558 case SMESH::VOLUME: aType = 3; break;
560 myTypeGroup->button(aType)->setChecked(true);
562 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
563 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
565 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil())
568 // NPAL19389: create a group with a selection in another group
569 // set actor of myMesh, if it is visible, else set
570 // actor of theGroup, if it is visible, else try
571 // any visible actor of group or submesh of myMesh
572 // commented, because an attempt to set selection on not displayed cells leads to error
573 SetAppropriateActor();
575 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
577 anActor = SMESH::FindActorByObject(theGroup);
578 SMESH::SetPickable(anActor);*/
580 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : 1));
581 myGrpTypeGroup->button(grpType)->setChecked(true);
582 onGrpTypeChanged(grpType);
585 if ( grpType == 0 ) {
586 myCurrentLineEdit = 0;
588 setSelectionMode(aType);
590 setShowEntityMode(); // depends on myTypeId
593 if (!theGroup->IsEmpty()) {
594 SMESH::long_array_var anElements = theGroup->GetListOfID();
595 int k = anElements->length();
596 for (int i = 0; i < k; i++) {
597 myIdList.append(anElements[i]);
598 myElements->addItem(QString::number(anElements[i]));
600 myElements->selectAll();
605 QString aShapeName( "" );
606 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
607 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
608 if (!aGroupShape->_is_nil())
610 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
612 aShapeName = aGroupShapeSO->GetName().c_str();
614 myGeomGroupLine->setText( aShapeName );
615 myNameChanged = true;
616 myName->blockSignals(true);
617 myName->setText(theGroup->GetName());
618 myName->blockSignals(false);
623 //=================================================================================
624 // function : updateButtons()
626 //=================================================================================
627 void SMESHGUI_GroupDlg::updateButtons()
629 bool enable = !myName->text().trimmed().isEmpty();
631 if (myGrpTypeId == 0) {
632 enable = enable && (mySelectAll->isChecked() || myElements->count() > 0);
633 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
635 else if (myGrpTypeId == 1) {
636 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
637 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
641 myOKBtn->setEnabled(enable);
642 myApplyBtn->setEnabled(enable);
645 //=================================================================================
646 // function : onNameChanged()
648 //=================================================================================
649 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
651 myOldName = myName->text();
653 myNameChanged = !myName->text().trimmed().isEmpty();
656 //=================================================================================
657 // function : onTypeChanged()
658 // purpose : Group elements type radio button management
659 //=================================================================================
660 void SMESHGUI_GroupDlg::onTypeChanged (int id)
662 if (myTypeId != id) {
664 if (myCurrentLineEdit == 0)
665 setSelectionMode(id);
671 //=================================================================================
672 // function : onGrpTypeChanged()
673 // purpose : Group type radio button management
674 //=================================================================================
675 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
677 if (myGrpTypeId != id) {
678 myWGStack->setCurrentIndex( id );
679 myName->blockSignals(true);
680 myName->setText(myOldName);
681 myName->blockSignals(false);
682 onSelectGeomGroup(id == 1);
687 //=================================================================================
688 // function : onColorChanged()
689 // purpose : Color button management
690 //=================================================================================
691 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
696 //=================================================================================
697 // function : setSelectionMode()
698 // purpose : Radio button management
699 //=================================================================================
700 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
703 if (myMesh->_is_nil())
705 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
706 bool isSelectAll = mySelectAll->isChecked();
707 if (mySelectionMode != theMode) {
708 // [PAL10408] mySelectionMgr->clearSelected();
709 mySelectionMgr->clearFilters();
710 if (myActorsList.count() > 0) {
711 QListIterator<SMESH_Actor*> it( myActorsList );
712 while ( it.hasNext() )
713 it.next()->SetPointRepresentation(false);
716 SMESH::SetPointRepresentation(false);
719 case grpNodeSelection:
720 if (myActorsList.count() > 0) {
721 QListIterator<SMESH_Actor*> it( myActorsList );
722 while ( it.hasNext() )
723 it.next()->SetPointRepresentation(true);
726 SMESH::SetPointRepresentation(true);
728 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : NodeSelection);
730 case grpEdgeSelection:
731 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection);
733 case grpFaceSelection:
734 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection);
736 case grpVolumeSelection:
737 if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : VolumeSelection);
739 case grpSubMeshSelection:
740 mySelectionMgr->installFilter(mySubMeshFilter);
741 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
743 case grpGroupSelection:
744 mySelectionMgr->installFilter(myGroupFilter);
745 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
747 case grpMeshSelection:
748 mySelectionMgr->installFilter(myMeshFilter);
749 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
751 case grpGeomSelection:
752 mySelectionMgr->installFilter(myGeomFilter);
753 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
756 if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
759 if ( aViewWindow ) aViewWindow->Repaint();
760 mySelectionMode = theMode;
764 //=================================================================================
765 // function : onApply()
767 //=================================================================================
768 bool SMESHGUI_GroupDlg::onApply()
770 if (mySMESHGUI->isActiveStudyLocked())
773 if (myName->text().trimmed().isEmpty())
776 if (myGrpTypeId == 0) { // on mesh elements
777 if (!mySelectAll->isChecked() && !myElements->count())
780 mySelectionMgr->clearSelected();
782 if (myGroup->_is_nil()) { // creation or conversion
783 // check if group on geometry is not null
784 if (!CORBA::is_nil(myGroupOnGeom)) {
785 if (myMesh->_is_nil())
787 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
788 // nullify pointer, because object become dead
789 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
793 if (myGroup->_is_nil()) { // creation
794 if (myMesh->_is_nil())
797 SMESH::ElementType aType = SMESH::ALL;
799 case 0: aType = SMESH::NODE; break;
800 case 1: aType = SMESH::EDGE; break;
801 case 2: aType = SMESH::FACE; break;
802 case 3: aType = SMESH::VOLUME; break;
805 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
807 if ( mySelectAll->isChecked() ) {
809 myGroup->AddFrom(myMesh.in());
813 SMESH::long_array_var anIdList = new SMESH::long_array;
814 int i, k = myElements->count();
816 for (i = 0; i < k; i++) {
817 anIdList[i] = myElements->item(i)->text().toInt();
820 myGroup->Add(anIdList.inout());
823 SALOMEDS::Color aColor = getGroupColor();
824 myGroup->SetColor(aColor);
826 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
828 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
829 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
831 /* init for next operation */
832 myName->setText( "" );
834 myGroup = SMESH::SMESH_Group::_nil();
837 myGroup->SetName(myName->text().toLatin1().data());
839 SALOMEDS::Color aColor = getGroupColor();
840 myGroup->SetColor(aColor);
842 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
843 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
844 anActor->setName(myName->text().toLatin1().data());
845 switch ( myTypeId ) {
846 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
847 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
849 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
853 if ( mySelectAll->isChecked() ) {
856 myGroup->AddFrom(myMesh.in());
861 int i, total = myElements->count();
862 for (i = 0; i < total; i++) {
863 int anId = myElements->item(i)->text().toInt();
864 int idx = myIdList.indexOf(anId);
866 aAddList.append(anId);
868 myIdList.removeAt(idx);
870 if (!aAddList.empty()) {
871 SMESH::long_array_var anIdList = new SMESH::long_array;
872 int added = aAddList.count();
873 anIdList->length(added);
874 for (i = 0; i < added; i++)
875 anIdList[i] = aAddList[i];
876 myGroup->Add(anIdList.inout());
878 if (!myIdList.empty()) {
879 SMESH::long_array_var anIdList = new SMESH::long_array;
880 int removed = myIdList.count();
881 anIdList->length(removed);
882 for (i = 0; i < removed; i++)
883 anIdList[i] = myIdList[i];
884 myGroup->Remove(anIdList.inout());
886 /* init for next operation */
888 for (i = 0; i < total; i++) {
889 myIdList.append(myElements->item(i)->text().toInt());
894 SMESHGUI::Modified();
895 mySMESHGUI->updateObjBrowser(true);
896 SMESH::UpdateView(); // asv: fix of BUG PAL5515
897 mySelectionMgr->clearSelected();
900 else if (myGrpTypeId == 1) { // on geom object
901 if (CORBA::is_nil(myGroupOnGeom)) { // creation
902 if (myMesh->_is_nil() || !myGeomObjects->length())
905 SMESH::ElementType aType = SMESH::ALL;
907 case 0: aType = SMESH::NODE; break;
908 case 1: aType = SMESH::EDGE; break;
909 case 2: aType = SMESH::FACE; break;
910 case 3: aType = SMESH::VOLUME; break;
913 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
914 GEOM::GEOM_IGroupOperations_var aGroupOp =
915 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
917 if (myGeomObjects->length() == 1) {
918 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
919 myName->text().toLatin1().data(),
923 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
924 if ( aSMESHGen->_is_nil() )
927 // create a geometry group
928 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
929 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
931 if (geomGen->_is_nil() || !aStudy)
934 GEOM::GEOM_IGroupOperations_var op =
935 geomGen->GetIGroupOperations(aStudy->StudyId());
939 // check and add all selected GEOM objects: they must be
940 // a sub-shapes of the main GEOM and must be of one type
941 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
942 for ( int i =0; i < myGeomObjects->length(); i++) {
943 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
945 aGroupType = aSubShapeType;
946 else if (aSubShapeType != aGroupType) {
947 aGroupType = TopAbs_SHAPE;
952 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
953 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
954 op->UnionList(aGroupVar, myGeomObjects);
957 // publish the GEOM group in study
958 QString aNewGeomGroupName ( "Auto_group_for_" );
959 aNewGeomGroupName += myName->text();
960 SALOMEDS::SObject_var aNewGroupSO =
961 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
962 aNewGeomGroupName.toLatin1().data(), aMeshShape);
965 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
966 myName->text().toLatin1().data(),
970 SALOMEDS::Color aColor = getGroupColor();
971 myGroupOnGeom->SetColor(aColor);
973 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
975 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
976 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
978 /* init for next operation */
979 myName->setText( "" );
980 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
983 myGroupOnGeom->SetName(myName->text().toLatin1().data());
985 SALOMEDS::Color aColor = getGroupColor();
986 myGroupOnGeom->SetColor(aColor);
988 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
989 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
990 anActor->setName(myName->text().toLatin1().data());
991 switch ( myTypeId ) {
992 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
993 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
995 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
1000 SMESHGUI::Modified();
1001 mySMESHGUI->updateObjBrowser(true);
1002 mySelectionMgr->clearSelected();
1009 //=================================================================================
1010 // function : onOK()
1012 //=================================================================================
1013 void SMESHGUI_GroupDlg::onOK()
1019 //=================================================================================
1020 // function : onListSelectionChanged()
1021 // purpose : Called when selection in element list is changed
1022 //=================================================================================
1023 void SMESHGUI_GroupDlg::onListSelectionChanged()
1025 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
1026 if( myIsBusy || myActorsList.count() == 0 ) return;
1029 if (myCurrentLineEdit == 0) {
1030 mySelectionMgr->clearSelected();
1031 TColStd_MapOfInteger aIndexes;
1032 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1033 QListWidgetItem* anItem;
1034 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
1035 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
1036 SALOME_ListIO aList;
1037 aList.Append(myActorsList.first()->getIO());
1038 mySelectionMgr->setSelectedObjects(aList,false);
1043 //=================================================================================
1044 // function : onObjectSelectionChanged()
1045 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1046 //=================================================================================
1047 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1049 if ( myIsBusy || !isEnabled()) return;
1050 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1054 SALOME_ListIO aList;
1055 mySelectionMgr->selectedObjects( aList );
1057 int aNbSel = aList.Extent();
1058 myElements->clearSelection();
1060 if (myCurrentLineEdit)
1062 myCurrentLineEdit->setText( "" );
1063 QString aString = "";
1065 if (myCurrentLineEdit == myMeshGroupLine)
1067 mySelectSubMesh->setEnabled(false);
1068 mySelectGroup->setEnabled(false);
1069 myGroupLine->setText( "" );
1070 mySubMeshLine->setText( "" );
1072 myGeomGroupBtn->setEnabled(false);
1073 myGeomGroupLine->setEnabled(false);
1074 myGeomGroupLine->setText( "" );
1075 myGeomObjects = new GEOM::ListOfGO();
1076 myGeomObjects->length(0);
1078 if (myGeomGroupBtn->isChecked())
1079 myGeomGroupBtn->setChecked(false);
1081 myName->setText( "" );
1083 myElements->clear();
1086 myGroup = SMESH::SMESH_Group::_nil();
1087 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1088 restoreShowEntityMode();
1089 myMesh = SMESH::SMESH_Mesh::_nil();
1095 Handle(SALOME_InteractiveObject) IO = aList.First();
1098 restoreShowEntityMode();
1099 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1100 setShowEntityMode();
1102 if (myMesh->_is_nil())
1109 if ( myFilterDlg && !myMesh->_is_nil()){
1110 myFilterDlg->SetMesh( myMesh );
1112 myGroup = SMESH::SMESH_Group::_nil();
1114 // NPAL19389: create a group with a selection in another group
1115 // set actor of myMesh, if it is visible, else try
1116 // any visible actor of group or submesh of myMesh
1117 SetAppropriateActor();
1119 aString = aList.First()->getName();
1120 myMeshGroupLine->setText(aString);
1121 myMeshGroupLine->home( false );
1123 mySelectSubMesh->setEnabled(true);
1124 mySelectGroup->setEnabled(true);
1125 myGeomGroupBtn->setEnabled(true);
1126 myGeomGroupLine->setEnabled(true);
1130 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1131 if (aGroup->_is_nil())
1138 myGroup = SMESH::SMESH_Group::_nil();
1139 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1143 mySelectSubMesh->setEnabled(true);
1144 mySelectGroup->setEnabled(true);
1146 myCurrentLineEdit = 0;
1151 if (myGrpTypeId == 0)
1157 myElements->clear();
1158 setSelectionMode(myTypeId);
1166 else if (myCurrentLineEdit == myGeomGroupLine)
1168 myGeomObjects = new GEOM::ListOfGO();
1171 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1173 if (aNbSel == 0 || !aMeshSO)
1175 myGeomObjects->length(0);
1181 myGeomObjects->length(aNbSel);
1183 GEOM::GEOM_Object_var aGeomGroup;
1184 Standard_Boolean testResult;
1187 SALOME_ListIteratorOfListIO anIt (aList);
1188 for (; anIt.More(); anIt.Next())
1190 testResult = Standard_False;
1191 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1193 // Check if the object is a geometry group
1194 if (!testResult || CORBA::is_nil(aGeomGroup))
1197 // Check if group constructed on the same shape as a mesh or on its child
1198 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1199 GEOM::GEOM_IGroupOperations_var anOp =
1200 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1202 // The main shape of the group
1203 GEOM::GEOM_Object_var aGroupMainShape;
1204 if (aGeomGroup->GetType() == 37)
1205 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1207 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1208 _PTR(SObject) aGroupMainShapeSO =
1209 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1210 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1212 _PTR(SObject) anObj, aRef;
1213 bool isRefOrSubShape = false;
1214 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1215 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1216 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1217 isRefOrSubShape = true;
1219 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1220 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1221 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1222 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1223 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1224 if (aRef->GetID() == aFather->GetID())
1225 isRefOrSubShape = true;
1227 aFather = aFather->GetFather();
1231 if (isRefOrSubShape)
1232 myGeomObjects[i++] = aGeomGroup;
1235 myGeomObjects->length(i);
1247 if (myCurrentLineEdit == mySubMeshLine)
1248 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1249 else if (myCurrentLineEdit == myGroupLine)
1250 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1251 else if (myCurrentLineEdit == myGeomGroupLine)
1252 aString = tr( "%1 Objects" ).arg(aNbSel);
1255 aString = aList.First()->getName();
1259 myCurrentLineEdit->setText(aString);
1260 myCurrentLineEdit->home(false);
1261 // 07.06.2008 skl for IPAL19574:
1262 // change name of group only if it is empty
1263 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1264 myOldName = myName->text();
1265 myName->blockSignals(true);
1266 myName->setText(aString);
1267 myName->blockSignals(false);
1272 else // !myCurrentLineEdit: local selection of nodes or elements
1274 if (aNbSel == 1 && myActorsList.count() > 0 )
1276 // NPAL19389: create a group with a selection in another group
1277 // Switch myActor to the newly selected one, if the last
1278 // is visible and belongs to group or submesh of myMesh
1279 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1280 Handle(SALOME_InteractiveObject) selIO = aList.First();
1281 if (curIO->hasEntry() && selIO->hasEntry()) {
1282 const char* selEntry = selIO->getEntry();
1283 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1284 // different objects: selected and myActor
1285 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1286 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1287 // newly selected actor is visible
1290 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1292 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1293 int len = strlen(meshEntry);
1295 if (strncmp(selEntry, meshEntry, len) == 0) {
1296 // selected object is myMesh or a part of it
1297 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1300 SMESH::SetPickable(myActor);
1309 QString aListStr = "";
1311 if (myTypeId == 0) {
1312 QListIterator<SMESH_Actor*> it( myActorsList );
1313 while ( it.hasNext() ) {
1315 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1319 QListIterator<SMESH_Actor*> it( myActorsList );
1320 while ( it.hasNext() ) {
1322 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1327 QListWidgetItem* anItem;
1328 QList<QListWidgetItem*> listItemsToSel;
1329 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1330 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1331 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1332 foreach(anItem, found)
1333 if (!anItem->isSelected())
1334 listItemsToSel.push_back(anItem);
1336 bool blocked = myElements->signalsBlocked();
1337 myElements->blockSignals(true);
1338 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1339 myElements->blockSignals(blocked);
1340 onListSelectionChanged();
1341 listItemsToSel.clear();
1346 if (myActorsList.count() == 0) {
1347 if (!myGroup->_is_nil()) {
1348 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1350 myActorsList.append( anActor );
1352 else if(!myGroupOnGeom->_is_nil()) {
1353 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1355 myActorsList.append( anActor );
1358 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1360 myActorsList.append( anActor );
1364 // somehow, if we display the mesh, while selecting from another actor,
1365 // the mesh becomes pickable, and there is no way to select any element
1366 if (myActorsList.count() > 0) {
1367 QListIterator<SMESH_Actor*> it( myActorsList );
1368 while ( it.hasNext() ) {
1369 SMESH_Actor* anActor = it.next();
1370 if ( IsActorVisible(anActor) )
1371 anActor->SetPickable(true);
1378 //=================================================================================
1379 // function : onSelectSubMesh()
1380 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1381 //=================================================================================
1382 void SMESHGUI_GroupDlg::onSelectAll()
1384 myElementsLab->setEnabled( !mySelectAll->isChecked() );
1385 myElements->setEnabled( !mySelectAll->isChecked() );
1386 myFilter->setEnabled( !mySelectAll->isChecked() );
1387 myAddBtn->setEnabled( !mySelectAll->isChecked() );
1388 myRemoveBtn->setEnabled( !mySelectAll->isChecked() );
1389 mySortBtn->setEnabled( !mySelectAll->isChecked() );
1390 mySelectBox->setEnabled( !mySelectAll->isChecked() );
1391 int selMode = mySelectionMode;
1392 mySelectionMode = grpNoSelection;
1393 setSelectionMode( selMode );
1396 //=================================================================================
1397 // function : onSelectSubMesh()
1398 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1399 //=================================================================================
1400 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1403 if (mySelectGroup->isChecked()) {
1404 mySelectGroup->setChecked(false);
1406 //VSR: else if (mySelectGeomGroup->isChecked()) {
1407 //VSR: mySelectGeomGroup->setChecked(false);
1409 myCurrentLineEdit = mySubMeshLine;
1410 setSelectionMode(grpSubMeshSelection);
1413 mySubMeshLine->setText( "" );
1414 myCurrentLineEdit = 0;
1416 setSelectionMode(myTypeId);
1418 mySubMeshBtn->setEnabled(on);
1419 mySubMeshLine->setEnabled(on);
1423 //=================================================================================
1424 // function : (onSelectGroup)
1425 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1426 //=================================================================================
1427 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1430 if (mySelectSubMesh->isChecked()) {
1431 mySelectSubMesh->setChecked(false);
1433 myCurrentLineEdit = myGroupLine;
1434 setSelectionMode(grpGroupSelection);
1437 myGroupLine->setText( "" );
1438 myCurrentLineEdit = 0;
1440 setSelectionMode(myTypeId);
1442 myGroupBtn->setEnabled(on);
1443 myGroupLine->setEnabled(on);
1447 //=================================================================================
1448 // function : (onSelectGeomGroup)
1449 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1450 //=================================================================================
1451 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1454 if (mySelectSubMesh->isChecked()) {
1455 mySelectSubMesh->setChecked(false);
1457 else if (mySelectGroup->isChecked()) {
1458 mySelectGroup->setChecked(false);
1460 myCurrentLineEdit = myGeomGroupLine;
1462 setSelectionMode(grpAllSelection);
1465 myGeomGroupBtn->setChecked(false);
1466 myGeomObjects->length(0);
1467 myGeomGroupLine->setText( "" );
1468 myCurrentLineEdit = 0;
1470 setSelectionMode(myTypeId);
1475 //=================================================================================
1476 // function : setCurrentSelection()
1478 //=================================================================================
1479 void SMESHGUI_GroupDlg::setCurrentSelection()
1481 QPushButton* send = (QPushButton*)sender();
1482 myCurrentLineEdit = 0;
1483 if (send == myMeshGroupBtn) {
1484 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1485 mySelectionMgr->clearSelected();
1487 setSelectionMode(grpMeshSelection);
1489 setSelectionMode(grpGroupSelection);
1490 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1491 myCurrentLineEdit = myMeshGroupLine;
1492 onObjectSelectionChanged();
1494 else if (send == mySubMeshBtn) {
1495 myCurrentLineEdit = mySubMeshLine;
1496 onObjectSelectionChanged();
1498 else if (send == myGroupBtn) {
1499 myCurrentLineEdit = myGroupLine;
1500 onObjectSelectionChanged();
1505 //=================================================================================
1506 // function : setFilters()
1507 // purpose : SLOT. Called when "Filter" button pressed.
1508 //=================================================================================
1509 void SMESHGUI_GroupDlg::setFilters()
1511 if(myMesh->_is_nil()) {
1512 SUIT_MessageBox::critical(this,
1514 tr("NO_MESH_SELECTED"));
1518 SMESH::ElementType aType = SMESH::ALL;
1521 case 0 : aType = SMESH::NODE; break;
1522 case 1 : aType = SMESH::EDGE; break;
1523 case 2 : aType = SMESH::FACE; break;
1524 case 3 : aType = SMESH::VOLUME; break;
1528 if ( myFilterDlg == 0 )
1530 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1531 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1534 myFilterDlg->Init( aType );
1536 myFilterDlg->SetSelection();
1537 myFilterDlg->SetMesh( myMesh );
1538 myFilterDlg->SetSourceWg( myElements, false );
1540 myFilterDlg->show();
1543 //=================================================================================
1544 // function : onFilterAccepted()
1545 // purpose : SLOT. Called when Filter dlg closed with OK button.
1546 // Uncheck "Select submesh" and "Select group" checkboxes
1547 //=================================================================================
1548 void SMESHGUI_GroupDlg::onFilterAccepted()
1550 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1552 mySelectionMode = myTypeId;
1553 mySelectSubMesh->setChecked( false );
1554 mySelectGroup->setChecked( false );
1558 //=================================================================================
1559 // function : onAdd()
1561 //=================================================================================
1562 void SMESHGUI_GroupDlg::onAdd()
1564 SALOME_ListIO aList;
1565 mySelectionMgr->selectedObjects( aList );
1567 int aNbSel = aList.Extent();
1569 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1573 SMESH::ElementType aType = SMESH::ALL;
1576 aType = SMESH::NODE;
1577 mySelector->SetSelectionMode(NodeSelection);
1580 aType = SMESH::EDGE;
1581 mySelector->SetSelectionMode(EdgeSelection);
1584 aType = SMESH::FACE;
1585 mySelector->SetSelectionMode(FaceSelection);
1588 aType = SMESH::VOLUME;
1589 mySelector->SetSelectionMode(VolumeSelection);
1592 mySelector->SetSelectionMode(ActorSelection);
1595 QListWidgetItem* anItem = 0;
1596 QList<QListWidgetItem*> listItemsToSel;
1598 if (myCurrentLineEdit == 0) {
1599 //if (aNbSel != 1) { myIsBusy = false; return; }
1600 QString aListStr = "";
1602 if (myTypeId == 0) {
1603 QListIterator<SMESH_Actor*> it( myActorsList );
1604 while ( it.hasNext() ) {
1606 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1611 QListIterator<SMESH_Actor*> it( myActorsList );
1612 while ( it.hasNext() ) {
1614 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1619 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1620 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1621 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1622 if (found.count() == 0) {
1623 anItem = new QListWidgetItem(*it);
1624 myElements->addItem(anItem);
1625 if (!anItem->isSelected())
1626 listItemsToSel.push_back(anItem);
1629 foreach(anItem, found)
1630 if (!anItem->isSelected())
1631 listItemsToSel.push_back(anItem);
1634 bool blocked = myElements->signalsBlocked();
1635 myElements->blockSignals(true);
1636 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1637 myElements->blockSignals(blocked);
1638 onListSelectionChanged();
1639 listItemsToSel.clear();
1641 } else if (myCurrentLineEdit == mySubMeshLine) {
1642 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1644 SALOME_ListIO aList;
1645 mySelectionMgr->selectedObjects( aList );
1647 SALOME_ListIteratorOfListIO anIt (aList);
1648 for ( ; anIt.More(); anIt.Next()) {
1649 SMESH::SMESH_subMesh_var aSubMesh =
1650 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1651 if (!aSubMesh->_is_nil()) {
1652 // check if mesh is the same
1653 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1655 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1656 int k = anElements->length();
1657 for (int i = 0; i < k; i++) {
1658 QString aText = QString::number(anElements[i]);
1659 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1660 if (found.count() == 0) {
1661 anItem = new QListWidgetItem(aText);
1662 myElements->addItem(anItem);
1663 if (!anItem->isSelected())
1664 listItemsToSel.push_back(anItem);
1667 foreach(anItem, found)
1668 if (!anItem->isSelected())
1669 listItemsToSel.push_back(anItem);
1672 bool blocked = myElements->signalsBlocked();
1673 myElements->blockSignals(true);
1674 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1675 myElements->blockSignals(blocked);
1676 onListSelectionChanged();
1677 listItemsToSel.clear();
1679 catch (const SALOME::SALOME_Exception& ex) {
1680 SalomeApp_Tools::QtCatchCorbaException(ex);
1685 mySelectSubMesh->setChecked(false);
1687 onListSelectionChanged();
1689 } else if (myCurrentLineEdit == myGroupLine) {
1690 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1691 SALOME_ListIO aList;
1692 mySelectionMgr->selectedObjects( aList );
1694 SALOME_ListIteratorOfListIO anIt (aList);
1695 for ( ; anIt.More(); anIt.Next()) {
1696 SMESH::SMESH_GroupBase_var aGroup =
1697 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1698 if (!aGroup->_is_nil()) {
1699 // check if mesh is the same
1700 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1701 SMESH::long_array_var anElements = aGroup->GetListOfID();
1702 int k = anElements->length();
1703 for (int i = 0; i < k; i++) {
1704 QString aText = QString::number(anElements[i]);
1705 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1706 if (found.count() == 0) {
1707 anItem = new QListWidgetItem(aText);
1708 myElements->addItem(anItem);
1709 if (!anItem->isSelected())
1710 listItemsToSel.push_back(anItem);
1713 foreach(anItem, found)
1714 if (!anItem->isSelected())
1715 listItemsToSel.push_back(anItem);
1718 bool blocked = myElements->signalsBlocked();
1719 myElements->blockSignals(true);
1720 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1721 myElements->blockSignals(blocked);
1722 onListSelectionChanged();
1723 listItemsToSel.clear();
1727 mySelectGroup->setChecked(false);
1729 onListSelectionChanged();
1731 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1732 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1733 GEOM::GEOM_IGroupOperations_var aGroupOp =
1734 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1736 SMESH::ElementType aGroupType = SMESH::ALL;
1737 switch(aGroupOp->GetType(myGeomObjects[0])) {
1738 case 7: aGroupType = SMESH::NODE; break;
1739 case 6: aGroupType = SMESH::EDGE; break;
1740 case 4: aGroupType = SMESH::FACE; break;
1741 case 2: aGroupType = SMESH::VOLUME; break;
1742 default: myIsBusy = false; return;
1745 if (aGroupType == aType) {
1746 _PTR(SObject) aGroupSO =
1747 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1748 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1750 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1751 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1752 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1753 aBelongToGeom->SetGeom(myGeomObjects[0]);
1754 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1755 aBelongToGeom->SetElementType(aType);
1756 aFilter->SetPredicate(aBelongToGeom);
1758 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1760 int k = anElements->length();
1761 for (int i = 0; i < k; i++) {
1762 QString aText = QString::number(anElements[i]);
1763 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1764 if (found.count() == 0) {
1765 anItem = new QListWidgetItem(aText);
1766 myElements->addItem(anItem);
1767 if (!anItem->isSelected())
1768 listItemsToSel.push_back(anItem);
1771 foreach(anItem, found)
1772 if (!anItem->isSelected())
1773 listItemsToSel.push_back(anItem);
1776 bool blocked = myElements->signalsBlocked();
1777 myElements->blockSignals(true);
1778 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1779 myElements->blockSignals(blocked);
1780 onListSelectionChanged();
1781 listItemsToSel.clear();
1784 //VSR: mySelectGeomGroup->setChecked(false);
1786 onListSelectionChanged();
1789 // mySelectionMgr->clearSelected();
1793 //=================================================================================
1794 // function : onRemove()
1796 //=================================================================================
1797 void SMESHGUI_GroupDlg::onRemove()
1800 if (myCurrentLineEdit == 0) {
1801 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1802 QListWidgetItem* item;
1803 foreach(item, selItems) delete item;
1805 SALOME_ListIO aList;
1806 mySelectionMgr->selectedObjects( aList );
1808 int aNbSel = aList.Extent();
1810 if (aNbSel == 0) { myIsBusy = false; return; }
1812 SMESH::ElementType aType = SMESH::ALL;
1814 case 0: aType = SMESH::NODE; break;
1815 case 1: aType = SMESH::EDGE; break;
1816 case 2: aType = SMESH::FACE; break;
1817 case 3: aType = SMESH::VOLUME; break;
1820 if (myCurrentLineEdit == mySubMeshLine) {
1821 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1822 SALOME_ListIO aList;
1823 mySelectionMgr->selectedObjects( aList );
1825 SALOME_ListIteratorOfListIO anIt (aList);
1826 for ( ; anIt.More(); anIt.Next()) {
1827 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1828 if (!aSubMesh->_is_nil()) {
1829 // check if mesh is the same
1830 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1831 if (aType == SMESH::NODE) {
1833 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1834 int k = anElements->length();
1835 for (int i = 0; i < k; i++) {
1836 QList<QListWidgetItem*> found =
1837 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1838 QListWidgetItem* anItem;
1839 foreach(anItem, found) delete anItem;
1842 catch (const SALOME::SALOME_Exception& ex) {
1843 SalomeApp_Tools::QtCatchCorbaException(ex);
1848 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1849 int k = anElements->length();
1850 for (int i = 0; i < k; i++) {
1851 QList<QListWidgetItem*> found =
1852 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1853 QListWidgetItem* anItem;
1854 foreach(anItem, found) delete anItem;
1857 catch (const SALOME::SALOME_Exception& ex) {
1858 SalomeApp_Tools::QtCatchCorbaException(ex);
1865 else if (myCurrentLineEdit == myGroupLine) {
1866 Standard_Boolean aRes;
1867 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1868 SALOME_ListIO aList;
1869 mySelectionMgr->selectedObjects( aList );
1871 SALOME_ListIteratorOfListIO anIt (aList);
1872 for ( ; anIt.More(); anIt.Next()) {
1873 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1874 if (aRes && !aGroup->_is_nil()) {
1875 // check if mesh is the same
1876 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1877 SMESH::long_array_var anElements = aGroup->GetListOfID();
1878 int k = anElements->length();
1879 for (int i = 0; i < k; i++) {
1880 QList<QListWidgetItem*> found =
1881 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1882 QListWidgetItem* anItem;
1883 foreach(anItem, found) delete anItem;
1894 //=================================================================================
1895 // function : onSort()
1897 //=================================================================================
1898 void SMESHGUI_GroupDlg::onSort()
1900 // PAL5412: sorts items in ascending by "string" value
1901 // myElements->sort(true);
1902 // myElements->update();
1903 int i, k = myElements->count();
1906 QList<int> aSelected;
1907 std::vector<int> anArray(k);
1908 // QMemArray<int> anArray(k);
1910 for (i = 0; i < k; i++) {
1911 int id = myElements->item(i)->text().toInt();
1913 if (myElements->item(i)->isSelected())
1914 aSelected.append(id);
1916 // sort & update list
1917 std::sort(anArray.begin(), anArray.end());
1919 myElements->clear();
1920 QListWidgetItem* anItem;
1921 QList<QListWidgetItem*> listItemsToSel;
1922 for (i = 0; i < k; i++) {
1923 anItem = new QListWidgetItem(QString::number(anArray[i]));
1924 myElements->addItem(anItem);
1925 if (aSelected.contains(anArray[i]))
1926 listItemsToSel.push_back(anItem);
1928 bool blocked = myElements->signalsBlocked();
1929 myElements->blockSignals(true);
1930 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1931 myElements->blockSignals(blocked);
1932 listItemsToSel.clear();
1937 //=================================================================================
1938 // function : closeEvent()
1940 //=================================================================================
1941 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1946 //=================================================================================
1947 // function : onVisibilityChanged()
1949 //=================================================================================
1950 void SMESHGUI_GroupDlg::onVisibilityChanged()
1952 SetAppropriateActor();
1955 //=================================================================================
1956 // function : SMESHGUI_GroupDlg::onClose
1957 // purpose : SLOT called when "Close" button pressed. Close dialog
1958 //=================================================================================
1959 void SMESHGUI_GroupDlg::onClose()
1961 if (SMESH::GetCurrentVtkView()) {
1962 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1963 SMESH::SetPointRepresentation(false);
1964 SMESH::SetPickable();
1965 restoreShowEntityMode();
1968 mySelectionMgr->clearSelected();
1969 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1970 aViewWindow->SetSelectionMode(ActorSelection);
1971 mySelectionMgr->clearFilters();
1972 mySMESHGUI->ResetState();
1977 //=================================================================================
1978 // function : onHelp()
1980 //=================================================================================
1981 void SMESHGUI_GroupDlg::onHelp()
1983 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1985 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1989 platform = "winapplication";
1991 platform = "application";
1993 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1994 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1995 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1997 arg(myHelpFileName));
2001 //=================================================================================
2002 // function : SMESHGUI_GroupDlg::onDeactivate
2003 // purpose : SLOT called when dialog must be deativated
2004 //=================================================================================
2005 void SMESHGUI_GroupDlg::onDeactivate()
2007 mySMESHGUI->ResetState();
2011 //=================================================================================
2012 // function : SMESHGUI_GroupDlg::enterEvent
2013 // purpose : Event filter
2014 //=================================================================================
2015 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2018 mySMESHGUI->EmitSignalDeactivateDialog();
2020 mySelectionMode = grpNoSelection;
2021 setSelectionMode(myTypeId);
2022 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2023 mySMESHGUI->SetActiveDialogBox(this);
2024 mySMESHGUI->SetState(800);
2028 //=================================================================================
2029 // function : hideEvent
2030 // purpose : caused by ESC key
2031 //=================================================================================
2032 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
2034 if (!isMinimized() && !myIsBusy)
2038 //=================================================================================
2039 // function : keyPressEvent()
2041 //=================================================================================
2042 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2044 QDialog::keyPressEvent( e );
2045 if ( e->isAccepted() )
2048 if ( e->key() == Qt::Key_F1 )
2055 //================================================================================
2057 * \brief Enable showing of the popup when Geometry selection btn is clicked
2058 * \param enable - true to enable
2060 //================================================================================
2062 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2064 void SMESHGUI_GroupDlg::updateGeomPopup()
2066 bool enable = false;
2068 if ( !myMesh->_is_nil() )
2069 enable = myMesh->NbEdges() > 0;
2071 if ( myGeomGroupBtn )
2073 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2075 if ( !myGeomPopup ) {
2076 myGeomPopup = new QMenu(this);
2077 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2078 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2079 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2081 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2087 //=================================================================================
2088 // function : onGeomSelectionButton()
2090 //=================================================================================
2091 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2093 if ( myGeomPopup && isBtnOn )
2095 myCurrentLineEdit = myGeomGroupLine;
2096 QAction* a = myGeomPopup->exec( QCursor::pos() );
2097 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2098 setSelectionMode(grpGeomSelection);
2102 myCurrentLineEdit = 0;
2103 setSelectionMode(grpAllSelection);
2107 //=================================================================================
2108 // function : onGeomPopup()
2110 //=================================================================================
2111 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2113 int index = myActions[a];
2114 if ( index == GEOM_BY_MESH_INDEX )
2116 mySelectionMode = grpNoSelection;
2117 if ( !myShapeByMeshOp ) {
2118 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2119 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2120 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2121 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2122 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2124 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2125 if ( !myMesh->_is_nil() ) {
2127 hide(); // stop processing selection
2129 myShapeByMeshOp->setModule( mySMESHGUI );
2130 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2131 myShapeByMeshOp->SetMesh( myMesh );
2132 myShapeByMeshOp->start();
2137 //================================================================================
2139 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2141 //================================================================================
2143 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2145 if ( myShapeByMeshOp == op ) {
2146 mySMESHGUI->getApp()->updateObjectBrowser();
2148 // Select a found geometry object
2149 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2150 if ( !aGeomVar->_is_nil() )
2152 QString ID = aGeomVar->GetStudyEntry();
2153 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2154 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2155 SALOME_ListIO anIOList;
2156 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2157 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2158 anIOList.Append( anIO );
2159 mySelectionMgr->setSelectedObjects( anIOList, false );
2160 onObjectSelectionChanged();
2166 //================================================================================
2168 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2170 //================================================================================
2172 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2174 if ( myShapeByMeshOp == op )
2177 setSelectionMode(grpGeomSelection);
2181 //=================================================================================
2182 // function : setGroupColor()
2184 //=================================================================================
2185 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2187 QColor aQColor( (int)( theColor.R * 255.0 ),
2188 (int)( theColor.G * 255.0 ),
2189 (int)( theColor.B * 255.0 ) );
2190 setGroupQColor( aQColor );
2193 //=================================================================================
2194 // function : getGroupColor()
2196 //=================================================================================
2197 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2199 QColor aQColor = getGroupQColor();
2201 SALOMEDS::Color aColor;
2202 aColor.R = (float)aQColor.red() / 255.0;
2203 aColor.G = (float)aQColor.green() / 255.0;
2204 aColor.B = (float)aQColor.blue() / 255.0;
2209 //=================================================================================
2210 // function : setGroupQColor()
2212 //=================================================================================
2213 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2215 if( theColor.isValid() )
2216 myColorBtn->setColor( theColor );
2219 //=================================================================================
2220 // function : getGroupQColor()
2222 //=================================================================================
2223 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2225 return myColorBtn->color();
2228 //=================================================================================
2229 // function : setDefaultGroupColor()
2231 //=================================================================================
2232 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2234 if( myMesh->_is_nil() )
2237 bool isAutoColor = myMesh->GetAutoColor();
2242 int r = 0, g = 0, b = 0;
2243 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2244 aQColor.setRgb( r, g, b );
2248 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2250 QList<SALOMEDS::Color> aReservedColors;
2251 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2253 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2254 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2255 aReservedColors.append( aReservedColor );
2258 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2259 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2260 (int)( aColor.G * 255.0 ),
2261 (int)( aColor.B * 255.0 ) );
2265 setGroupQColor( aQColor );
2268 //=================================================================================
2269 // function : SetAppropriateActor()
2270 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2271 // NPAL19389: create a group with a selection in another group.
2272 // if mesh actor is not visible - find any first visible group or submesh
2273 //=================================================================================
2274 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2276 bool isActor = false;
2277 myActorsList.clear();
2279 if (myMesh->_is_nil()) return false;
2281 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2283 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2285 if (!myGroupOnGeom->_is_nil()) {
2286 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2287 if (anActor && anActor->hasIO())
2290 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2293 myActorsList.append(anActor);
2299 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2300 if (anActor && anActor->hasIO()) {
2302 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2305 myActorsList.append(anActor);
2309 if (!isActor && !myGroup->_is_nil()) {
2310 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2311 if (anActor && anActor->hasIO())
2312 myActorsList.append(anActor);
2315 // try any visible actor of group or submesh of current mesh
2318 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2320 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2321 int len = strlen(meshEntry);
2323 // iterate on all actors in current view window, search for
2324 // any visible actor, that belongs to group or submesh of current mesh
2325 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2326 vtkActorCollection *aCollection = aCopy.GetActors();
2327 int nbItems = aCollection->GetNumberOfItems();
2328 for (int i=0; i<nbItems && !isActor; i++)
2330 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2331 if (anActor && anActor->hasIO()) {
2332 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2333 if (aViewWindow->isVisible(anIO)) {
2334 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2335 myActorsList.append(anActor);
2343 if (myActorsList.count() > 0) {
2344 QListIterator<SMESH_Actor*> it( myActorsList );
2345 while ( it.hasNext() ) {
2346 SMESH_Actor* anActor = it.next();
2347 if ( IsActorVisible(anActor) )
2348 anActor->SetPickable(true);
2352 return ( isActor || (myActorsList.count() > 0) );
2355 //=======================================================================
2356 //function : setShowEntityMode
2357 //purpose : make shown only entity corresponding to my type
2358 //=======================================================================
2359 void SMESHGUI_GroupDlg::setShowEntityMode()
2361 if ( !myMesh->_is_nil() ) {
2362 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2363 if (!myStoredShownEntity)
2364 myStoredShownEntity = actor->GetEntityMode();
2365 switch ( myTypeId ) {
2366 case 0: restoreShowEntityMode(); break;
2367 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2368 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2369 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2375 //=======================================================================
2376 //function : restoreShowEntityMode
2377 //purpose : restore ShowEntity mode of myActor
2378 //=======================================================================
2379 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2381 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2382 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2383 actor->SetEntityMode(myStoredShownEntity);
2386 myStoredShownEntity = 0;
2389 //=======================================================================
2390 //function : IsActorVisible
2391 //purpose : return visibility of the actor
2392 //=======================================================================
2393 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2395 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2396 if (theActor && aViewWindow)
2397 return aViewWindow->isVisible(theActor->getIO());