1 // Copyright (C) 2007-2008 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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_GroupDlg.cxx
24 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
27 #include "SMESHGUI_GroupDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_GroupUtils.h"
33 #include "SMESHGUI_FilterUtils.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
35 #include "SMESHGUI_FilterDlg.h"
36 #include "SMESHGUI_ShapeByMeshDlg.h"
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_Actor.h>
40 #include <SMESH_ActorUtils.h>
42 // SALOME GEOM includes
44 #include <GEOM_SelectionFilter.h>
46 // SALOME GUI includes
47 #include <QtxColorButton.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_ResourceMgr.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_MessageBox.h>
54 #include <SalomeApp_Tools.h>
55 #include <SalomeApp_Application.h>
56 #include <SalomeApp_Study.h>
57 #include <LightApp_SelectionMgr.h>
59 #include <SALOME_ListIO.hxx>
60 #include <SALOME_ListIteratorOfListIO.hxx>
62 #include <SVTK_ViewWindow.h>
64 #include <VTKViewer_Algorithm.h>
66 // SALOME KERNEL includes
67 #include <SALOMEDSClient_Study.hxx>
70 #include <vtkRenderer.h>
71 #include <vtkActorCollection.h>
74 #include <TColStd_MapOfInteger.hxx>
77 #include <QButtonGroup>
81 #include <QPushButton>
82 #include <QToolButton>
83 #include <QRadioButton>
85 #include <QGridLayout>
86 #include <QHBoxLayout>
87 #include <QVBoxLayout>
88 #include <QListWidget>
89 #include <QStackedWidget>
101 //=================================================================================
102 // function : SMESHGUI_GroupDlg()
104 //=================================================================================
105 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
106 SMESH::SMESH_Mesh_ptr theMesh )
107 : QDialog( SMESH::GetDesktop( theModule ) ),
108 mySMESHGUI( theModule ),
109 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
110 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
112 myNameChanged( false )
115 if ( !theMesh->_is_nil() )
119 mySelectSubMesh->setEnabled( false );
120 mySelectGroup->setEnabled( false );
121 myGeomGroupBtn->setEnabled( false );
122 myGeomGroupLine->setEnabled( false );
126 //=================================================================================
127 // function : SMESHGUI_GroupDlg()
129 //=================================================================================
130 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
131 SMESH::SMESH_GroupBase_ptr theGroup,
132 const bool theIsConvert )
133 : QDialog( SMESH::GetDesktop( theModule ) ),
134 mySMESHGUI( theModule ),
135 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
136 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
138 myNameChanged( false )
141 if ( !theGroup->_is_nil() )
142 init( theGroup, theIsConvert );
145 mySelectSubMesh->setEnabled( false );
146 mySelectGroup->setEnabled( false );
148 myCurrentLineEdit = myMeshGroupLine;
149 setSelectionMode( 5 );
153 //=================================================================================
154 // function : SMESHGUI_GroupDlg()
156 //=================================================================================
157 void SMESHGUI_GroupDlg::initDialog( bool create)
160 setAttribute( Qt::WA_DeleteOnClose, true );
164 myCurrentLineEdit = 0;
168 myGeomObjects = new GEOM::ListOfGO();
169 myGeomObjects->length( 0 );
171 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
173 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
174 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
176 setSizeGripEnabled( true);
178 QGridLayout* aMainLayout = new QGridLayout( this );
179 aMainLayout->setMargin( MARGIN );
180 aMainLayout->setSpacing( SPACING );
182 /***************************************************************/
183 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
184 myMeshGroupBtn = new QPushButton( this );
185 myMeshGroupBtn->setIcon( image0 );
186 myMeshGroupLine = new QLineEdit( this );
187 myMeshGroupLine->setReadOnly( true );
189 /***************************************************************/
190 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
191 myTypeGroup = new QButtonGroup( this );
192 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
193 aTypeBoxLayout->setMargin( MARGIN );
194 aTypeBoxLayout->setSpacing( SPACING );
197 types.append( tr( "MESH_NODE" ) );
198 types.append( tr( "SMESH_EDGE" ) );
199 types.append( tr( "SMESH_FACE" ) );
200 types.append( tr( "SMESH_VOLUME" ) );
202 for ( int i = 0; i < types.count(); i++ )
204 rb = new QRadioButton( types[i], aTypeBox );
205 myTypeGroup->addButton( rb, i );
206 aTypeBoxLayout->addWidget( rb );
208 aTypeBox->setEnabled( create );
211 /***************************************************************/
212 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
213 aName->setMinimumWidth( 50 );
214 myName = new QLineEdit( this );
216 /***************************************************************/
217 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
218 myGrpTypeGroup = new QButtonGroup( this );
219 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
220 aGrpTypeBoxLayout->setMargin( MARGIN );
221 aGrpTypeBoxLayout->setSpacing( SPACING );
223 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
224 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
225 myGrpTypeGroup->addButton( rb1, 0 );
226 myGrpTypeGroup->addButton( rb2, 1 );
227 aGrpTypeBoxLayout->addWidget( rb1 );
228 aGrpTypeBoxLayout->addWidget( rb2 );
229 aGrpTypeBox->setEnabled( create );
232 /***************************************************************/
233 myWGStack = new QStackedWidget( this );
234 QWidget* wg1 = new QWidget( myWGStack );
235 QWidget* wg2 = new QWidget( myWGStack );
237 /***************************************************************/
238 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
239 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
240 aContentBoxLayout->setMargin( MARGIN );
241 aContentBoxLayout->setSpacing( SPACING );
243 QLabel* aLabel = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
244 myElements = new QListWidget( aContentBox );
245 myElements->setSelectionMode( QListWidget::ExtendedSelection );
247 myFilter = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
248 QPushButton* aAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
249 QPushButton* aRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
250 QPushButton* aSortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
252 aContentBoxLayout->addWidget( aLabel, 0, 0 );
253 aContentBoxLayout->addWidget( myElements, 1, 0, 6, 1 );
254 aContentBoxLayout->addWidget( myFilter, 1, 1 );
255 aContentBoxLayout->addWidget( aAddBtn, 3, 1 );
256 aContentBoxLayout->addWidget( aRemoveBtn, 4, 1 );
257 aContentBoxLayout->addWidget( aSortBtn, 6, 1 );
259 aContentBoxLayout->setColumnStretch( 0, 1 );
260 aContentBoxLayout->setRowStretch( 2, 1 );
261 aContentBoxLayout->setRowStretch( 5, 1 );
263 /***************************************************************/
264 QGroupBox* aSelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
265 QGridLayout* aSelectBoxLayout = new QGridLayout( aSelectBox );
266 aSelectBoxLayout->setMargin( MARGIN );
267 aSelectBoxLayout->setSpacing( SPACING );
269 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), aSelectBox );
270 mySubMeshBtn = new QPushButton( aSelectBox );
271 mySubMeshBtn->setIcon( image0 );
272 mySubMeshLine = new QLineEdit( aSelectBox );
273 mySubMeshLine->setReadOnly( true );
274 onSelectSubMesh( false );
276 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), aSelectBox );
277 myGroupBtn = new QPushButton( aSelectBox );
278 myGroupBtn->setIcon( image0 );
279 myGroupLine = new QLineEdit( aSelectBox );
280 myGroupLine->setReadOnly( true );
281 onSelectGroup( false );
283 aSelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
284 aSelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
285 aSelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
286 aSelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
287 aSelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
288 aSelectBoxLayout->addWidget( myGroupLine, 1, 2 );
290 /***************************************************************/
291 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
292 wg1Layout->setMargin( 0 );
293 wg1Layout->setSpacing( SPACING );
294 wg1Layout->addWidget( aContentBox );
295 wg1Layout->addWidget( aSelectBox );
296 wg1Layout->setStretchFactor( aContentBox, 10 );
298 /***************************************************************/
299 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
300 myGeomGroupBtn = new QToolButton( wg2 );
301 myGeomGroupBtn->setIcon( image0 );
302 myGeomGroupBtn->setCheckable( true );
303 myGeomGroupLine = new QLineEdit( wg2 );
304 myGeomGroupLine->setReadOnly( true ); //VSR ???
305 onSelectGeomGroup( false );
307 myGeomGroupBtn->setEnabled( create );
308 myGeomGroupLine->setEnabled( create );
310 /***************************************************************/
311 QGridLayout* wg2Layout = new QGridLayout( wg2 );
312 wg2Layout->setMargin( 0 );
313 wg1Layout->setSpacing( SPACING );
314 wg2Layout->addWidget( geomObject, 0, 0 );
315 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
316 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
317 wg2Layout->setRowStretch( 1, 5 );
319 /***************************************************************/
320 myWGStack->insertWidget( 0, wg1 );
321 myWGStack->insertWidget( 1, wg2 );
323 /***************************************************************/
324 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
325 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
326 aColorBoxLayout->setMargin(MARGIN);
327 aColorBoxLayout->setSpacing(SPACING);
329 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
330 myColorBtn = new QtxColorButton(aColorBox);
331 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
332 myColorBtn->sizePolicy().verticalPolicy() );
334 aColorBoxLayout->addWidget(aColorLab);
335 aColorBoxLayout->addWidget(myColorBtn);
337 /***************************************************************/
339 QFrame* aButtons = new QFrame(this);
340 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
341 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
342 aBtnLayout->setMargin(MARGIN);
343 aBtnLayout->setSpacing(SPACING);
345 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
346 myOKBtn->setAutoDefault(true);
347 myOKBtn->setDefault(true);
348 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
349 myApplyBtn->setAutoDefault(true);
350 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
351 myCloseBtn->setAutoDefault(true);
352 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
353 myHelpBtn->setAutoDefault(true);
355 aBtnLayout->addWidget(myOKBtn);
356 aBtnLayout->addSpacing(10);
357 aBtnLayout->addWidget(myApplyBtn);
358 aBtnLayout->addSpacing(10);
359 aBtnLayout->addStretch();
360 aBtnLayout->addWidget(myCloseBtn);
361 aBtnLayout->addWidget(myHelpBtn);
363 /***************************************************************/
364 aMainLayout->addWidget(meshGroupLab, 0, 0);
365 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
366 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
367 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
368 aMainLayout->addWidget(aName, 2, 0);
369 aMainLayout->addWidget(myName, 2, 2);
370 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
371 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
372 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
373 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
375 /* signals and slots connections */
376 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
377 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
378 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
380 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
381 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
383 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
384 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
385 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
386 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
388 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
389 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
390 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
391 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
392 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
394 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
396 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
397 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
398 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
399 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
402 mySMESHGUI->SetActiveDialogBox(this);
403 mySMESHGUI->SetState(800);
405 mySelectionMode = -1;
406 myMeshFilter = new SMESH_TypeFilter(MESH);
407 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
408 myGroupFilter = new SMESH_TypeFilter(GROUP);
409 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
410 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
412 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
413 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
414 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
415 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
417 rb1->setChecked(true); // VSR !!!
418 onGrpTypeChanged(0); // VSR!!!
420 if (myMesh->_is_nil() )
421 myTypeGroup->button(0)->setChecked(true);
424 //myName->setText(GetDefaultName(tr( "SMESH_GROUP" )));
427 //=================================================================================
428 // function : ~SMESHGUI_GroupDlg()
429 // purpose : Destroys the object and frees any allocated resources
430 //=================================================================================
431 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
433 // no need to delete child widgets, Qt does it all for us
434 if ( myFilterDlg != 0 ) {
435 myFilterDlg->setParent( 0 );
440 //=================================================================================
441 // function : GetDefaultName()
442 // purpose : Get the Group Name if Create new Group
443 //=================================================================================
444 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
448 // collect all object names of SMESH component
449 SalomeApp_Study* appStudy =
450 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
451 if ( !appStudy ) return aName;
452 _PTR(Study) aStudy = appStudy->studyDS();
454 std::set<std::string> aSet;
455 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
457 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
459 for (it->InitEx(true); it->More(); it->Next()) {
461 aSet.insert(obj->GetName());
465 // build a unique name
467 bool isUnique = false;
469 aName = theOperation + "_" + QString::number(++aNumber);
470 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
476 //=================================================================================
479 //=================================================================================
480 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
482 mySelectionMgr->installFilter(myMeshFilter);
484 /* init data from current selection */
485 restoreShowEntityMode();
486 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
488 myGroup = SMESH::SMESH_Group::_nil();
489 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
491 // NPAL19389: create a group with a selection in another group
492 // set actor of myMesh, if it is visible, else try
493 // any visible actor of group or submesh of myMesh
494 SetAppropriateActor();
496 setDefaultGroupColor();
499 mySelectionMgr->selectedObjects( aList );
500 if( !aList.IsEmpty() )
502 QString aName = aList.First()->getName();
503 myMeshGroupLine->setText(aName);
504 myMeshGroupLine->home( false );
507 myCurrentLineEdit = 0;
509 myTypeGroup->button(0)->setChecked(true);
513 //=================================================================================
516 //=================================================================================
517 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
518 const bool theIsConvert)
520 restoreShowEntityMode();
521 myMesh = theGroup->GetMesh();
524 myNameChanged = true;
525 myName->blockSignals(true);
526 myName->setText(theGroup->GetName());
527 myName->blockSignals(false);
530 SALOMEDS::Color aColor = theGroup->GetColor();
531 setGroupColor( aColor );
533 myMeshGroupLine->setText(theGroup->GetName());
536 switch(theGroup->GetType()) {
537 case SMESH::NODE: aType= 0; break;
538 case SMESH::EDGE: aType = 1; break;
539 case SMESH::FACE: aType = 2; break;
540 case SMESH::VOLUME: aType = 3; break;
542 myTypeGroup->button(aType)->setChecked(true);
544 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
545 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
547 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil())
550 // NPAL19389: create a group with a selection in another group
551 // set actor of myMesh, if it is visible, else set
552 // actor of theGroup, if it is visible, else try
553 // any visible actor of group or submesh of myMesh
554 // commented, because an attempt to set selection on not displayed cells leads to error
555 SetAppropriateActor();
557 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
559 anActor = SMESH::FindActorByObject(theGroup);
560 SMESH::SetPickable(anActor);*/
562 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : 1));
563 myGrpTypeGroup->button(grpType)->setChecked(true);
564 onGrpTypeChanged(grpType);
567 if ( grpType == 0 ) {
568 myCurrentLineEdit = 0;
570 setSelectionMode(aType);
572 setShowEntityMode(); // depends on myTypeId
575 if (!theGroup->IsEmpty()) {
576 SMESH::long_array_var anElements = theGroup->GetListOfID();
577 int k = anElements->length();
578 for (int i = 0; i < k; i++) {
579 myIdList.append(anElements[i]);
580 myElements->addItem(QString::number(anElements[i]));
582 myElements->selectAll();
587 QString aShapeName( "" );
588 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
589 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
590 if (!aGroupShape->_is_nil())
592 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
593 aShapeName = aGroupShapeSO->GetName().c_str();
595 myGeomGroupLine->setText( aShapeName );
596 myNameChanged = true;
597 myName->blockSignals(true);
598 myName->setText(theGroup->GetName());
599 myName->blockSignals(false);
604 //=================================================================================
605 // function : updateButtons()
607 //=================================================================================
608 void SMESHGUI_GroupDlg::updateButtons()
610 bool enable = !myName->text().trimmed().isEmpty();
612 if (myGrpTypeId == 0) {
613 enable = enable && myElements->count() > 0;
614 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
616 else if (myGrpTypeId == 1) {
617 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
618 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
622 myOKBtn->setEnabled(enable);
623 myApplyBtn->setEnabled(enable);
626 //=================================================================================
627 // function : onNameChanged()
629 //=================================================================================
630 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
632 myOldName = myName->text();
634 myNameChanged = !myName->text().trimmed().isEmpty();
637 //=================================================================================
638 // function : onTypeChanged()
639 // purpose : Group elements type radio button management
640 //=================================================================================
641 void SMESHGUI_GroupDlg::onTypeChanged (int id)
643 if (myTypeId != id) {
645 if (myCurrentLineEdit == 0)
646 setSelectionMode(id);
652 //=================================================================================
653 // function : onGrpTypeChanged()
654 // purpose : Group type radio button management
655 //=================================================================================
656 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
658 if (myGrpTypeId != id) {
659 myWGStack->setCurrentIndex( id );
660 myName->blockSignals(true);
661 myName->setText(myOldName);
662 myName->blockSignals(false);
663 onSelectGeomGroup(id == 1);
668 //=================================================================================
669 // function : onColorChanged()
670 // purpose : Color button management
671 //=================================================================================
672 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
677 //=================================================================================
678 // function : setSelectionMode()
679 // purpose : Radio button management
680 //=================================================================================
681 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
684 if (myMesh->_is_nil())
686 if (mySelectionMode != theMode) {
687 // [PAL10408] mySelectionMgr->clearSelected();
688 mySelectionMgr->clearFilters();
689 if (myActorsList.count() > 0) {
690 QListIterator<SMESH_Actor*> it( myActorsList );
691 while ( it.hasNext() )
692 it.next()->SetPointRepresentation(false);
695 SMESH::SetPointRepresentation(false);
699 if (myActorsList.count() > 0) {
700 QListIterator<SMESH_Actor*> it( myActorsList );
701 while ( it.hasNext() )
702 it.next()->SetPointRepresentation(true);
705 SMESH::SetPointRepresentation(true);
706 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
707 aViewWindow->SetSelectionMode(NodeSelection);
710 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
711 aViewWindow->SetSelectionMode(EdgeSelection);
714 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
715 aViewWindow->SetSelectionMode(FaceSelection);
718 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
719 aViewWindow->SetSelectionMode(VolumeSelection);
723 mySelectionMgr->installFilter(mySubMeshFilter);
724 else if (theMode == 5)
725 mySelectionMgr->installFilter(myGroupFilter);
726 else if (theMode == 6)
727 mySelectionMgr->installFilter(myMeshFilter);
728 else if (theMode == 7)
729 mySelectionMgr->installFilter(myGeomFilter);
731 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
732 aViewWindow->SetSelectionMode(ActorSelection);
734 mySelectionMode = theMode;
738 //=================================================================================
739 // function : onApply()
741 //=================================================================================
742 bool SMESHGUI_GroupDlg::onApply()
744 if (mySMESHGUI->isActiveStudyLocked())
747 if (myName->text().trimmed().isEmpty())
750 if (myGrpTypeId == 0) { // on mesh elements
751 if (!myElements->count())
754 mySelectionMgr->clearSelected();
756 if (myGroup->_is_nil()) { // creation or conversion
757 // check if group on geometry is not null
758 if (!CORBA::is_nil(myGroupOnGeom)) {
759 if (myMesh->_is_nil())
761 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
762 // nullify pointer, because object become dead
763 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
767 if (myGroup->_is_nil()) { // creation
768 if (myMesh->_is_nil())
771 SMESH::ElementType aType = SMESH::ALL;
773 case 0: aType = SMESH::NODE; break;
774 case 1: aType = SMESH::EDGE; break;
775 case 2: aType = SMESH::FACE; break;
776 case 3: aType = SMESH::VOLUME; break;
779 SMESH::long_array_var anIdList = new SMESH::long_array;
780 int i, k = myElements->count();
782 for (i = 0; i < k; i++) {
783 anIdList[i] = myElements->item(i)->text().toInt();
786 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
787 myGroup->Add(anIdList.inout());
789 SALOMEDS::Color aColor = getGroupColor();
790 myGroup->SetColor(aColor);
792 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
794 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
795 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
797 /* init for next operation */
798 myName->setText( "" );
800 myGroup = SMESH::SMESH_Group::_nil();
803 myGroup->SetName(myName->text().toLatin1().data());
805 SALOMEDS::Color aColor = getGroupColor();
806 myGroup->SetColor(aColor);
808 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
809 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
810 anActor->setName(myName->text().toLatin1().data());
811 switch ( myTypeId ) {
812 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
813 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
815 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
821 int i, total = myElements->count();
822 for (i = 0; i < total; i++) {
823 int anId = myElements->item(i)->text().toInt();
824 int idx = myIdList.indexOf(anId);
826 aAddList.append(anId);
828 myIdList.removeAt(idx);
830 if (!aAddList.empty()) {
831 SMESH::long_array_var anIdList = new SMESH::long_array;
832 int added = aAddList.count();
833 anIdList->length(added);
834 for (i = 0; i < added; i++)
835 anIdList[i] = aAddList[i];
836 myGroup->Add(anIdList.inout());
838 if (!myIdList.empty()) {
839 SMESH::long_array_var anIdList = new SMESH::long_array;
840 int removed = myIdList.count();
841 anIdList->length(removed);
842 for (i = 0; i < removed; i++)
843 anIdList[i] = myIdList[i];
844 myGroup->Remove(anIdList.inout());
846 /* init for next operation */
848 for (i = 0; i < total; i++) {
849 myIdList.append(myElements->item(i)->text().toInt());
853 mySMESHGUI->updateObjBrowser(true);
854 SMESH::UpdateView(); // asv: fix of BUG PAL5515
855 mySelectionMgr->clearSelected();
858 else if (myGrpTypeId == 1) { // on geom object
859 if (CORBA::is_nil(myGroupOnGeom)) { // creation
860 if (myMesh->_is_nil() || !myGeomObjects->length())
863 SMESH::ElementType aType = SMESH::ALL;
865 case 0: aType = SMESH::NODE; break;
866 case 1: aType = SMESH::EDGE; break;
867 case 2: aType = SMESH::FACE; break;
868 case 3: aType = SMESH::VOLUME; break;
871 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
872 GEOM::GEOM_IGroupOperations_var aGroupOp =
873 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
875 if (myGeomObjects->length() == 1) {
876 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
877 myName->text().toLatin1().data(),
881 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
882 if ( aSMESHGen->_is_nil() )
885 // create a geometry group
886 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
887 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
889 if (geomGen->_is_nil() || !aStudy)
892 GEOM::GEOM_IGroupOperations_var op =
893 geomGen->GetIGroupOperations(aStudy->StudyId());
897 // check and add all selected GEOM objects: they must be
898 // a sub-shapes of the main GEOM and must be of one type
899 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
900 for ( int i =0; i < myGeomObjects->length(); i++) {
901 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
903 aGroupType = aSubShapeType;
904 else if (aSubShapeType != aGroupType) {
905 aGroupType = TopAbs_SHAPE;
910 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
911 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
912 op->UnionList(aGroupVar, myGeomObjects);
915 // publish the GEOM group in study
916 QString aNewGeomGroupName ( "Auto_group_for_" );
917 aNewGeomGroupName += myName->text();
918 SALOMEDS::SObject_var aNewGroupSO =
919 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
920 aNewGeomGroupName.toLatin1().data(), aMeshShape);
923 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
924 myName->text().toLatin1().data(),
928 SALOMEDS::Color aColor = getGroupColor();
929 myGroupOnGeom->SetColor(aColor);
931 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
933 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
934 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
936 /* init for next operation */
937 myName->setText( "" );
938 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
941 myGroupOnGeom->SetName(myName->text().toLatin1().data());
943 SALOMEDS::Color aColor = getGroupColor();
944 myGroupOnGeom->SetColor(aColor);
946 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
947 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
948 anActor->setName(myName->text().toLatin1().data());
949 switch ( myTypeId ) {
950 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
951 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
953 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
958 mySMESHGUI->updateObjBrowser(true);
959 mySelectionMgr->clearSelected();
966 //=================================================================================
969 //=================================================================================
970 void SMESHGUI_GroupDlg::onOK()
976 //=================================================================================
977 // function : onListSelectionChanged()
978 // purpose : Called when selection in element list is changed
979 //=================================================================================
980 void SMESHGUI_GroupDlg::onListSelectionChanged()
982 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
983 if( myIsBusy || myActorsList.count() == 0 ) return;
986 if (myCurrentLineEdit == 0) {
987 mySelectionMgr->clearSelected();
988 TColStd_MapOfInteger aIndexes;
989 QList<QListWidgetItem*> selItems = myElements->selectedItems();
990 QListWidgetItem* anItem;
991 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
992 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
994 aList.Append(myActorsList.first()->getIO());
995 mySelectionMgr->setSelectedObjects(aList,false);
1000 //=================================================================================
1001 // function : onObjectSelectionChanged()
1002 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1003 //=================================================================================
1004 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1006 if ( myIsBusy || !isEnabled()) return;
1007 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1011 SALOME_ListIO aList;
1012 mySelectionMgr->selectedObjects( aList );
1014 int aNbSel = aList.Extent();
1015 myElements->clearSelection();
1017 if (myCurrentLineEdit)
1019 myCurrentLineEdit->setText( "" );
1020 QString aString = "";
1022 if (myCurrentLineEdit == myMeshGroupLine)
1024 mySelectSubMesh->setEnabled(false);
1025 mySelectGroup->setEnabled(false);
1026 myGroupLine->setText( "" );
1027 mySubMeshLine->setText( "" );
1029 myGeomGroupBtn->setEnabled(false);
1030 myGeomGroupLine->setEnabled(false);
1031 myGeomGroupLine->setText( "" );
1032 myGeomObjects = new GEOM::ListOfGO();
1033 myGeomObjects->length(0);
1035 if (myGeomGroupBtn->isChecked())
1036 myGeomGroupBtn->setChecked(false);
1038 myName->setText( "" );
1040 myElements->clear();
1043 myGroup = SMESH::SMESH_Group::_nil();
1044 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1045 restoreShowEntityMode();
1046 myMesh = SMESH::SMESH_Mesh::_nil();
1052 Handle(SALOME_InteractiveObject) IO = aList.First();
1055 restoreShowEntityMode();
1056 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1057 setShowEntityMode();
1059 if (myMesh->_is_nil())
1065 myGroup = SMESH::SMESH_Group::_nil();
1067 // NPAL19389: create a group with a selection in another group
1068 // set actor of myMesh, if it is visible, else try
1069 // any visible actor of group or submesh of myMesh
1070 SetAppropriateActor();
1072 aString = aList.First()->getName();
1073 myMeshGroupLine->setText(aString);
1074 myMeshGroupLine->home( false );
1076 mySelectSubMesh->setEnabled(true);
1077 mySelectGroup->setEnabled(true);
1078 myGeomGroupBtn->setEnabled(true);
1079 myGeomGroupLine->setEnabled(true);
1083 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1084 if (aGroup->_is_nil())
1090 myCurrentLineEdit = 0;
1092 myGroup = SMESH::SMESH_Group::_nil();
1093 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1097 mySelectSubMesh->setEnabled(true);
1098 mySelectGroup->setEnabled(true);
1100 myCurrentLineEdit = 0;
1105 if (myGrpTypeId == 0)
1111 myElements->clear();
1112 setSelectionMode(myTypeId);
1120 else if (myCurrentLineEdit == myGeomGroupLine)
1122 myGeomObjects = new GEOM::ListOfGO();
1125 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1127 if (aNbSel == 0 || !aMeshSO)
1129 myGeomObjects->length(0);
1135 myGeomObjects->length(aNbSel);
1137 GEOM::GEOM_Object_var aGeomGroup;
1138 Standard_Boolean testResult;
1141 SALOME_ListIteratorOfListIO anIt (aList);
1142 for (; anIt.More(); anIt.Next())
1144 testResult = Standard_False;
1145 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1147 // Check if the object is a geometry group
1148 if (!testResult || CORBA::is_nil(aGeomGroup))
1151 // Check if group constructed on the same shape as a mesh or on its child
1152 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1153 GEOM::GEOM_IGroupOperations_var anOp =
1154 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1156 // The main shape of the group
1157 GEOM::GEOM_Object_var aGroupMainShape;
1158 if (aGeomGroup->GetType() == 37)
1159 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1161 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1162 _PTR(SObject) aGroupMainShapeSO =
1163 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1164 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1166 _PTR(SObject) anObj, aRef;
1167 bool isRefOrSubShape = false;
1168 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1169 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1170 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1171 isRefOrSubShape = true;
1173 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1174 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1175 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1176 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1177 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1178 if (aRef->GetID() == aFather->GetID())
1179 isRefOrSubShape = true;
1181 aFather = aFather->GetFather();
1185 if (isRefOrSubShape)
1186 myGeomObjects[i++] = aGeomGroup;
1189 myGeomObjects->length(i);
1201 if (myCurrentLineEdit == mySubMeshLine)
1202 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1203 else if (myCurrentLineEdit == myGroupLine)
1204 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1205 else if (myCurrentLineEdit == myGeomGroupLine)
1206 aString = tr( "%1 Objects" ).arg(aNbSel);
1209 aString = aList.First()->getName();
1213 myCurrentLineEdit->setText(aString);
1214 myCurrentLineEdit->home(false);
1215 // 07.06.2008 skl for IPAL19574:
1216 // change name of group only if it is empty
1217 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1218 myOldName = myName->text();
1219 myName->blockSignals(true);
1220 myName->setText(aString);
1221 myName->blockSignals(false);
1226 else // !myCurrentLineEdit: local selection of nodes or elements
1228 if (aNbSel == 1 && myActorsList.count() > 0 )
1230 // NPAL19389: create a group with a selection in another group
1231 // Switch myActor to the newly selected one, if the last
1232 // is visible and belongs to group or submesh of myMesh
1233 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1234 Handle(SALOME_InteractiveObject) selIO = aList.First();
1235 if (curIO->hasEntry() && selIO->hasEntry()) {
1236 const char* selEntry = selIO->getEntry();
1237 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1238 // different objects: selected and myActor
1239 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1240 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1241 // newly selected actor is visible
1244 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1246 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1247 int len = strlen(meshEntry);
1249 if (strncmp(selEntry, meshEntry, len) == 0) {
1250 // selected object is myMesh or a part of it
1251 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1254 SMESH::SetPickable(myActor);
1263 QString aListStr = "";
1265 if (myTypeId == 0) {
1266 QListIterator<SMESH_Actor*> it( myActorsList );
1267 while ( it.hasNext() ) {
1269 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1273 QListIterator<SMESH_Actor*> it( myActorsList );
1274 while ( it.hasNext() ) {
1276 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1281 QListWidgetItem* anItem;
1282 QList<QListWidgetItem*> listItemsToSel;
1283 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1284 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1285 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1286 foreach(anItem, found)
1287 if (!anItem->isSelected())
1288 listItemsToSel.push_back(anItem);
1290 bool blocked = myElements->signalsBlocked();
1291 myElements->blockSignals(true);
1292 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1293 myElements->blockSignals(blocked);
1294 onListSelectionChanged();
1295 listItemsToSel.clear();
1300 if (myActorsList.count() == 0) {
1301 if (!myGroup->_is_nil()) {
1302 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1304 myActorsList.append( anActor );
1306 else if(!myGroupOnGeom->_is_nil()) {
1307 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1309 myActorsList.append( anActor );
1312 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1314 myActorsList.append( anActor );
1318 // somehow, if we display the mesh, while selecting from another actor,
1319 // the mesh becomes pickable, and there is no way to select any element
1320 if (myActorsList.count() > 0) {
1321 QListIterator<SMESH_Actor*> it( myActorsList );
1322 while ( it.hasNext() ) {
1323 SMESH_Actor* anActor = it.next();
1324 if ( IsActorVisible(anActor) )
1325 anActor->SetPickable(true);
1332 //=================================================================================
1333 // function : onSelectSubMesh()
1334 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1335 //=================================================================================
1336 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1339 if (mySelectGroup->isChecked()) {
1340 mySelectGroup->setChecked(false);
1342 //VSR: else if (mySelectGeomGroup->isChecked()) {
1343 //VSR: mySelectGeomGroup->setChecked(false);
1345 myCurrentLineEdit = mySubMeshLine;
1346 setSelectionMode(4);
1349 mySubMeshLine->setText( "" );
1350 myCurrentLineEdit = 0;
1352 setSelectionMode(myTypeId);
1354 mySubMeshBtn->setEnabled(on);
1355 mySubMeshLine->setEnabled(on);
1359 //=================================================================================
1360 // function : (onSelectGroup)
1361 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1362 //=================================================================================
1363 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1366 if (mySelectSubMesh->isChecked()) {
1367 mySelectSubMesh->setChecked(false);
1369 myCurrentLineEdit = myGroupLine;
1370 setSelectionMode(5);
1373 myGroupLine->setText( "" );
1374 myCurrentLineEdit = 0;
1376 setSelectionMode(myTypeId);
1378 myGroupBtn->setEnabled(on);
1379 myGroupLine->setEnabled(on);
1383 //=================================================================================
1384 // function : (onSelectGeomGroup)
1385 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1386 //=================================================================================
1387 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1390 if (mySelectSubMesh->isChecked()) {
1391 mySelectSubMesh->setChecked(false);
1393 else if (mySelectGroup->isChecked()) {
1394 mySelectGroup->setChecked(false);
1396 myCurrentLineEdit = myGeomGroupLine;
1398 setSelectionMode(8);
1401 myGeomGroupBtn->setChecked(false);
1402 myGeomObjects->length(0);
1403 myGeomGroupLine->setText( "" );
1404 myCurrentLineEdit = 0;
1406 setSelectionMode(myTypeId);
1411 //=================================================================================
1412 // function : setCurrentSelection()
1414 //=================================================================================
1415 void SMESHGUI_GroupDlg::setCurrentSelection()
1417 QPushButton* send = (QPushButton*)sender();
1418 myCurrentLineEdit = 0;
1419 if (send == myMeshGroupBtn) {
1420 myCurrentLineEdit = myMeshGroupLine;
1422 setSelectionMode(6);
1424 setSelectionMode(5);
1425 onObjectSelectionChanged();
1427 else if (send == mySubMeshBtn) {
1428 myCurrentLineEdit = mySubMeshLine;
1429 onObjectSelectionChanged();
1431 else if (send == myGroupBtn) {
1432 myCurrentLineEdit = myGroupLine;
1433 onObjectSelectionChanged();
1438 //=================================================================================
1439 // function : setFilters()
1440 // purpose : SLOT. Called when "Filter" button pressed.
1441 //=================================================================================
1442 void SMESHGUI_GroupDlg::setFilters()
1444 if(myMesh->_is_nil()) {
1445 SUIT_MessageBox::critical(this,
1447 tr("NO_MESH_SELECTED"));
1451 SMESH::ElementType aType = SMESH::ALL;
1454 case 0 : aType = SMESH::NODE; break;
1455 case 1 : aType = SMESH::EDGE; break;
1456 case 2 : aType = SMESH::FACE; break;
1457 case 3 : aType = SMESH::VOLUME; break;
1461 if ( myFilterDlg == 0 )
1463 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1464 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1467 myFilterDlg->Init( aType );
1469 myFilterDlg->SetSelection();
1470 myFilterDlg->SetMesh( myMesh );
1471 myFilterDlg->SetSourceWg( myElements, false );
1473 myFilterDlg->show();
1476 //=================================================================================
1477 // function : onFilterAccepted()
1478 // purpose : SLOT. Called when Filter dlg closed with OK button.
1479 // Uncheck "Select submesh" and "Select group" checkboxes
1480 //=================================================================================
1481 void SMESHGUI_GroupDlg::onFilterAccepted()
1483 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1485 mySelectionMode = myTypeId;
1486 mySelectSubMesh->setChecked( false );
1487 mySelectGroup->setChecked( false );
1491 //=================================================================================
1492 // function : onAdd()
1494 //=================================================================================
1495 void SMESHGUI_GroupDlg::onAdd()
1497 SALOME_ListIO aList;
1498 mySelectionMgr->selectedObjects( aList );
1500 int aNbSel = aList.Extent();
1502 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1506 SMESH::ElementType aType = SMESH::ALL;
1509 aType = SMESH::NODE;
1510 mySelector->SetSelectionMode(NodeSelection);
1513 aType = SMESH::EDGE;
1514 mySelector->SetSelectionMode(EdgeSelection);
1517 aType = SMESH::FACE;
1518 mySelector->SetSelectionMode(FaceSelection);
1521 aType = SMESH::VOLUME;
1522 mySelector->SetSelectionMode(VolumeSelection);
1525 mySelector->SetSelectionMode(ActorSelection);
1528 QListWidgetItem* anItem = 0;
1529 QList<QListWidgetItem*> listItemsToSel;
1531 if (myCurrentLineEdit == 0) {
1532 //if (aNbSel != 1) { myIsBusy = false; return; }
1533 QString aListStr = "";
1535 if (myTypeId == 0) {
1536 QListIterator<SMESH_Actor*> it( myActorsList );
1537 while ( it.hasNext() ) {
1539 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1544 QListIterator<SMESH_Actor*> it( myActorsList );
1545 while ( it.hasNext() ) {
1547 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1552 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1553 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1554 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1555 if (found.count() == 0) {
1556 anItem = new QListWidgetItem(*it);
1557 myElements->addItem(anItem);
1558 if (!anItem->isSelected())
1559 listItemsToSel.push_back(anItem);
1562 foreach(anItem, found)
1563 if (!anItem->isSelected())
1564 listItemsToSel.push_back(anItem);
1567 bool blocked = myElements->signalsBlocked();
1568 myElements->blockSignals(true);
1569 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1570 myElements->blockSignals(blocked);
1571 onListSelectionChanged();
1572 listItemsToSel.clear();
1574 } else if (myCurrentLineEdit == mySubMeshLine) {
1575 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1577 SALOME_ListIO aList;
1578 mySelectionMgr->selectedObjects( aList );
1580 SALOME_ListIteratorOfListIO anIt (aList);
1581 for ( ; anIt.More(); anIt.Next()) {
1582 SMESH::SMESH_subMesh_var aSubMesh =
1583 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1584 if (!aSubMesh->_is_nil()) {
1585 // check if mesh is the same
1586 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1588 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1589 int k = anElements->length();
1590 for (int i = 0; i < k; i++) {
1591 QString aText = QString::number(anElements[i]);
1592 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1593 if (found.count() == 0) {
1594 anItem = new QListWidgetItem(aText);
1595 myElements->addItem(anItem);
1596 if (!anItem->isSelected())
1597 listItemsToSel.push_back(anItem);
1600 foreach(anItem, found)
1601 if (!anItem->isSelected())
1602 listItemsToSel.push_back(anItem);
1605 bool blocked = myElements->signalsBlocked();
1606 myElements->blockSignals(true);
1607 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1608 myElements->blockSignals(blocked);
1609 onListSelectionChanged();
1610 listItemsToSel.clear();
1612 catch (const SALOME::SALOME_Exception& ex) {
1613 SalomeApp_Tools::QtCatchCorbaException(ex);
1618 mySelectSubMesh->setChecked(false);
1620 onListSelectionChanged();
1622 } else if (myCurrentLineEdit == myGroupLine) {
1623 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1624 SALOME_ListIO aList;
1625 mySelectionMgr->selectedObjects( aList );
1627 SALOME_ListIteratorOfListIO anIt (aList);
1628 for ( ; anIt.More(); anIt.Next()) {
1629 SMESH::SMESH_GroupBase_var aGroup =
1630 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1631 if (!aGroup->_is_nil()) {
1632 // check if mesh is the same
1633 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1634 SMESH::long_array_var anElements = aGroup->GetListOfID();
1635 int k = anElements->length();
1636 for (int i = 0; i < k; i++) {
1637 QString aText = QString::number(anElements[i]);
1638 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1639 if (found.count() == 0) {
1640 anItem = new QListWidgetItem(aText);
1641 myElements->addItem(anItem);
1642 if (!anItem->isSelected())
1643 listItemsToSel.push_back(anItem);
1646 foreach(anItem, found)
1647 if (!anItem->isSelected())
1648 listItemsToSel.push_back(anItem);
1651 bool blocked = myElements->signalsBlocked();
1652 myElements->blockSignals(true);
1653 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1654 myElements->blockSignals(blocked);
1655 onListSelectionChanged();
1656 listItemsToSel.clear();
1660 mySelectGroup->setChecked(false);
1662 onListSelectionChanged();
1664 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1665 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1666 GEOM::GEOM_IGroupOperations_var aGroupOp =
1667 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1669 SMESH::ElementType aGroupType = SMESH::ALL;
1670 switch(aGroupOp->GetType(myGeomObjects[0])) {
1671 case 7: aGroupType = SMESH::NODE; break;
1672 case 6: aGroupType = SMESH::EDGE; break;
1673 case 4: aGroupType = SMESH::FACE; break;
1674 case 2: aGroupType = SMESH::VOLUME; break;
1675 default: myIsBusy = false; return;
1678 if (aGroupType == aType) {
1679 _PTR(SObject) aGroupSO =
1680 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1681 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1683 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1684 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1685 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1686 aBelongToGeom->SetGeom(myGeomObjects[0]);
1687 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1688 aBelongToGeom->SetElementType(aType);
1689 aFilter->SetPredicate(aBelongToGeom);
1691 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1693 int k = anElements->length();
1694 for (int i = 0; i < k; i++) {
1695 QString aText = QString::number(anElements[i]);
1696 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1697 if (found.count() == 0) {
1698 anItem = new QListWidgetItem(aText);
1699 myElements->addItem(anItem);
1700 if (!anItem->isSelected())
1701 listItemsToSel.push_back(anItem);
1704 foreach(anItem, found)
1705 if (!anItem->isSelected())
1706 listItemsToSel.push_back(anItem);
1709 bool blocked = myElements->signalsBlocked();
1710 myElements->blockSignals(true);
1711 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1712 myElements->blockSignals(blocked);
1713 onListSelectionChanged();
1714 listItemsToSel.clear();
1717 //VSR: mySelectGeomGroup->setChecked(false);
1719 onListSelectionChanged();
1722 // mySelectionMgr->clearSelected();
1726 //=================================================================================
1727 // function : onRemove()
1729 //=================================================================================
1730 void SMESHGUI_GroupDlg::onRemove()
1733 if (myCurrentLineEdit == 0) {
1734 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1735 QListWidgetItem* item;
1736 foreach(item, selItems) delete item;
1738 SALOME_ListIO aList;
1739 mySelectionMgr->selectedObjects( aList );
1741 int aNbSel = aList.Extent();
1743 if (aNbSel == 0) { myIsBusy = false; return; }
1745 SMESH::ElementType aType = SMESH::ALL;
1747 case 0: aType = SMESH::NODE; break;
1748 case 1: aType = SMESH::EDGE; break;
1749 case 2: aType = SMESH::FACE; break;
1750 case 3: aType = SMESH::VOLUME; break;
1753 if (myCurrentLineEdit == mySubMeshLine) {
1754 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1755 SALOME_ListIO aList;
1756 mySelectionMgr->selectedObjects( aList );
1758 SALOME_ListIteratorOfListIO anIt (aList);
1759 for ( ; anIt.More(); anIt.Next()) {
1760 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1761 if (!aSubMesh->_is_nil()) {
1762 // check if mesh is the same
1763 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1764 if (aType == SMESH::NODE) {
1766 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1767 int k = anElements->length();
1768 for (int i = 0; i < k; i++) {
1769 QList<QListWidgetItem*> found =
1770 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1771 QListWidgetItem* anItem;
1772 foreach(anItem, found) delete anItem;
1775 catch (const SALOME::SALOME_Exception& ex) {
1776 SalomeApp_Tools::QtCatchCorbaException(ex);
1781 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1782 int k = anElements->length();
1783 for (int i = 0; i < k; i++) {
1784 QList<QListWidgetItem*> found =
1785 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1786 QListWidgetItem* anItem;
1787 foreach(anItem, found) delete anItem;
1790 catch (const SALOME::SALOME_Exception& ex) {
1791 SalomeApp_Tools::QtCatchCorbaException(ex);
1798 else if (myCurrentLineEdit == myGroupLine) {
1799 Standard_Boolean aRes;
1800 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1801 SALOME_ListIO aList;
1802 mySelectionMgr->selectedObjects( aList );
1804 SALOME_ListIteratorOfListIO anIt (aList);
1805 for ( ; anIt.More(); anIt.Next()) {
1806 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1807 if (aRes && !aGroup->_is_nil()) {
1808 // check if mesh is the same
1809 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1810 SMESH::long_array_var anElements = aGroup->GetListOfID();
1811 int k = anElements->length();
1812 for (int i = 0; i < k; i++) {
1813 QList<QListWidgetItem*> found =
1814 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1815 QListWidgetItem* anItem;
1816 foreach(anItem, found) delete anItem;
1827 //=================================================================================
1828 // function : onSort()
1830 //=================================================================================
1831 void SMESHGUI_GroupDlg::onSort()
1833 // PAL5412: sorts items in ascending by "string" value
1834 // myElements->sort(true);
1835 // myElements->update();
1836 int i, k = myElements->count();
1839 QList<int> aSelected;
1840 std::vector<int> anArray(k);
1841 // QMemArray<int> anArray(k);
1843 for (i = 0; i < k; i++) {
1844 int id = myElements->item(i)->text().toInt();
1846 if (myElements->item(i)->isSelected())
1847 aSelected.append(id);
1849 // sort & update list
1850 std::sort(anArray.begin(), anArray.end());
1852 myElements->clear();
1853 QListWidgetItem* anItem;
1854 QList<QListWidgetItem*> listItemsToSel;
1855 for (i = 0; i < k; i++) {
1856 anItem = new QListWidgetItem(QString::number(anArray[i]));
1857 myElements->addItem(anItem);
1858 if (aSelected.contains(anArray[i]))
1859 listItemsToSel.push_back(anItem);
1861 bool blocked = myElements->signalsBlocked();
1862 myElements->blockSignals(true);
1863 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1864 myElements->blockSignals(blocked);
1865 listItemsToSel.clear();
1870 //=================================================================================
1871 // function : closeEvent()
1873 //=================================================================================
1874 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1879 //=================================================================================
1880 // function : onVisibilityChanged()
1882 //=================================================================================
1883 void SMESHGUI_GroupDlg::onVisibilityChanged()
1885 SetAppropriateActor();
1888 //=================================================================================
1889 // function : SMESHGUI_GroupDlg::onClose
1890 // purpose : SLOT called when "Close" button pressed. Close dialog
1891 //=================================================================================
1892 void SMESHGUI_GroupDlg::onClose()
1894 if (SMESH::GetCurrentVtkView()) {
1895 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1896 SMESH::SetPointRepresentation(false);
1897 SMESH::SetPickable();
1898 restoreShowEntityMode();
1901 mySelectionMgr->clearSelected();
1902 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1903 aViewWindow->SetSelectionMode(ActorSelection);
1904 mySelectionMgr->clearFilters();
1905 mySMESHGUI->ResetState();
1910 //=================================================================================
1911 // function : onHelp()
1913 //=================================================================================
1914 void SMESHGUI_GroupDlg::onHelp()
1916 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1918 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1922 platform = "winapplication";
1924 platform = "application";
1926 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1927 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1928 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1930 arg(myHelpFileName));
1934 //=================================================================================
1935 // function : SMESHGUI_GroupDlg::onDeactivate
1936 // purpose : SLOT called when dialog must be deativated
1937 //=================================================================================
1938 void SMESHGUI_GroupDlg::onDeactivate()
1940 mySMESHGUI->ResetState();
1944 //=================================================================================
1945 // function : SMESHGUI_GroupDlg::enterEvent
1946 // purpose : Event filter
1947 //=================================================================================
1948 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1951 mySMESHGUI->EmitSignalDeactivateDialog();
1953 mySelectionMode = -1;
1954 setSelectionMode(myTypeId);
1955 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1956 mySMESHGUI->SetActiveDialogBox(this);
1957 mySMESHGUI->SetState(800);
1961 //=================================================================================
1962 // function : hideEvent
1963 // purpose : caused by ESC key
1964 //=================================================================================
1965 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1967 if (!isMinimized() && !myIsBusy)
1971 //=================================================================================
1972 // function : keyPressEvent()
1974 //=================================================================================
1975 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1977 QDialog::keyPressEvent( e );
1978 if ( e->isAccepted() )
1981 if ( e->key() == Qt::Key_F1 )
1988 //================================================================================
1990 * \brief Enable showing of the popup when Geometry selection btn is clicked
1991 * \param enable - true to enable
1993 //================================================================================
1995 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1997 void SMESHGUI_GroupDlg::updateGeomPopup()
1999 bool enable = false;
2001 if ( !myMesh->_is_nil() )
2002 enable = myMesh->NbEdges() > 0;
2004 if ( myGeomGroupBtn )
2006 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2008 if ( !myGeomPopup ) {
2009 myGeomPopup = new QMenu(this);
2010 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2011 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2012 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2014 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2020 //=================================================================================
2021 // function : onGeomSelectionButton()
2023 //=================================================================================
2024 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2026 if ( myGeomPopup && isBtnOn )
2028 myCurrentLineEdit = myGeomGroupLine;
2029 QAction* a = myGeomPopup->exec( QCursor::pos() );
2030 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2031 setSelectionMode(7);
2035 myCurrentLineEdit = 0;
2036 setSelectionMode(8);
2040 //=================================================================================
2041 // function : onGeomPopup()
2043 //=================================================================================
2044 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2046 int index = myActions[a];
2047 if ( index == GEOM_BY_MESH_INDEX )
2049 mySelectionMode = -1;
2050 if ( !myShapeByMeshOp ) {
2051 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2052 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2053 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2054 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2055 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2057 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2058 if ( !myMesh->_is_nil() ) {
2060 hide(); // stop processing selection
2062 myShapeByMeshOp->setModule( mySMESHGUI );
2063 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2064 myShapeByMeshOp->SetMesh( myMesh );
2065 myShapeByMeshOp->start();
2070 //================================================================================
2072 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2074 //================================================================================
2076 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2078 if ( myShapeByMeshOp == op ) {
2079 mySMESHGUI->getApp()->updateObjectBrowser();
2081 // Select a found geometry object
2082 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2083 if ( !aGeomVar->_is_nil() )
2085 QString ID = aGeomVar->GetStudyEntry();
2086 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2087 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2088 SALOME_ListIO anIOList;
2089 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2090 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2091 anIOList.Append( anIO );
2092 mySelectionMgr->setSelectedObjects( anIOList, false );
2093 onObjectSelectionChanged();
2099 //================================================================================
2101 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2103 //================================================================================
2105 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2107 if ( myShapeByMeshOp == op )
2110 setSelectionMode(7);
2114 //=================================================================================
2115 // function : setGroupColor()
2117 //=================================================================================
2118 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2120 QColor aQColor( (int)( theColor.R * 255.0 ),
2121 (int)( theColor.G * 255.0 ),
2122 (int)( theColor.B * 255.0 ) );
2123 setGroupQColor( aQColor );
2126 //=================================================================================
2127 // function : getGroupColor()
2129 //=================================================================================
2130 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2132 QColor aQColor = getGroupQColor();
2134 SALOMEDS::Color aColor;
2135 aColor.R = (float)aQColor.red() / 255.0;
2136 aColor.G = (float)aQColor.green() / 255.0;
2137 aColor.B = (float)aQColor.blue() / 255.0;
2142 //=================================================================================
2143 // function : setGroupQColor()
2145 //=================================================================================
2146 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2148 if( theColor.isValid() )
2149 myColorBtn->setColor( theColor );
2152 //=================================================================================
2153 // function : getGroupQColor()
2155 //=================================================================================
2156 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2158 return myColorBtn->color();
2161 //=================================================================================
2162 // function : setDefaultGroupColor()
2164 //=================================================================================
2165 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2167 if( myMesh->_is_nil() )
2170 bool isAutoColor = myMesh->GetAutoColor();
2175 int r = 0, g = 0, b = 0;
2176 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2177 aQColor.setRgb( r, g, b );
2181 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2183 QList<SALOMEDS::Color> aReservedColors;
2184 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2186 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2187 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2188 aReservedColors.append( aReservedColor );
2191 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2192 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2193 (int)( aColor.G * 255.0 ),
2194 (int)( aColor.B * 255.0 ) );
2198 setGroupQColor( aQColor );
2201 //=================================================================================
2202 // function : SetAppropriateActor()
2203 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2204 // NPAL19389: create a group with a selection in another group.
2205 // if mesh actor is not visible - find any first visible group or submesh
2206 //=================================================================================
2207 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2209 bool isActor = false;
2210 myActorsList.clear();
2212 if (myMesh->_is_nil()) return false;
2214 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2216 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2218 if (!myGroupOnGeom->_is_nil()) {
2219 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2220 if (anActor && anActor->hasIO())
2223 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2226 myActorsList.append(anActor);
2232 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2233 if (anActor && anActor->hasIO())
2236 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2239 myActorsList.append(anActor);
2242 // try any visible actor of group or submesh of current mesh
2245 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2247 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2248 int len = strlen(meshEntry);
2250 // iterate on all actors in current view window, search for
2251 // any visible actor, that belongs to group or submesh of current mesh
2252 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2253 vtkActorCollection *aCollection = aCopy.GetActors();
2254 int nbItems = aCollection->GetNumberOfItems();
2255 for (int i=0; i<nbItems && !isActor; i++)
2257 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2258 if (anActor && anActor->hasIO()) {
2259 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2260 if (aViewWindow->isVisible(anIO)) {
2261 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0)
2262 myActorsList.append(anActor);
2270 if (myActorsList.count() > 0) {
2271 QListIterator<SMESH_Actor*> it( myActorsList );
2272 while ( it.hasNext() ) {
2273 SMESH_Actor* anActor = it.next();
2274 if ( IsActorVisible(anActor) )
2275 anActor->SetPickable(true);
2279 return ( isActor || (myActorsList.count() > 0) );
2282 //=======================================================================
2283 //function : setShowEntityMode
2284 //purpose : make shown only entity corresponding to my type
2285 //=======================================================================
2286 void SMESHGUI_GroupDlg::setShowEntityMode()
2288 if ( !myMesh->_is_nil() ) {
2289 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2290 if (!myStoredShownEntity)
2291 myStoredShownEntity = actor->GetEntityMode();
2292 switch ( myTypeId ) {
2293 case 0: restoreShowEntityMode(); break;
2294 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2295 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2296 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2302 //=======================================================================
2303 //function : restoreShowEntityMode
2304 //purpose : restore ShowEntity mode of myActor
2305 //=======================================================================
2306 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2308 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2309 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2310 actor->SetEntityMode(myStoredShownEntity);
2313 myStoredShownEntity = 0;
2316 //=======================================================================
2317 //function : IsActorVisible
2318 //purpose : return visibility of the actor
2319 //=======================================================================
2320 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2322 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2323 if (theActor && aViewWindow)
2324 return aViewWindow->isVisible(theActor->getIO());