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 // SALOME KERNEL includes
65 #include <SALOMEDSClient_Study.hxx>
68 #include <vtkRenderer.h>
69 #include <vtkActorCollection.h>
72 #include <TColStd_MapOfInteger.hxx>
75 #include <QButtonGroup>
79 #include <QPushButton>
80 #include <QToolButton>
81 #include <QRadioButton>
83 #include <QGridLayout>
84 #include <QHBoxLayout>
85 #include <QVBoxLayout>
86 #include <QListWidget>
87 #include <QStackedWidget>
99 //=================================================================================
100 // function : SMESHGUI_GroupDlg()
102 //=================================================================================
103 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
104 SMESH::SMESH_Mesh_ptr theMesh )
105 : QDialog( SMESH::GetDesktop( theModule ) ),
106 mySMESHGUI( theModule ),
107 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
108 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
110 myNameChanged( false ),
114 if ( !theMesh->_is_nil() )
118 mySelectSubMesh->setEnabled( false );
119 mySelectGroup->setEnabled( false );
120 myGeomGroupBtn->setEnabled( false );
121 myGeomGroupLine->setEnabled( false );
125 //=================================================================================
126 // function : SMESHGUI_GroupDlg()
128 //=================================================================================
129 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
130 SMESH::SMESH_GroupBase_ptr theGroup )
131 : QDialog( SMESH::GetDesktop( theModule ) ),
132 mySMESHGUI( theModule ),
133 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
134 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
136 myNameChanged( false )
139 if ( !theGroup->_is_nil() )
143 mySelectSubMesh->setEnabled( false );
144 mySelectGroup->setEnabled( false );
146 myCurrentLineEdit = myMeshGroupLine;
147 setSelectionMode( 5 );
151 //=================================================================================
152 // function : SMESHGUI_GroupDlg()
154 //=================================================================================
155 void SMESHGUI_GroupDlg::initDialog( bool create)
158 setAttribute( Qt::WA_DeleteOnClose, true );
162 myCurrentLineEdit = 0;
166 myGeomObjects = new GEOM::ListOfGO();
167 myGeomObjects->length( 0 );
169 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
171 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
172 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
174 setSizeGripEnabled( true);
176 QGridLayout* aMainLayout = new QGridLayout( this );
177 aMainLayout->setMargin( MARGIN );
178 aMainLayout->setSpacing( SPACING );
180 /***************************************************************/
181 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
182 myMeshGroupBtn = new QPushButton( this );
183 myMeshGroupBtn->setIcon( image0 );
184 myMeshGroupLine = new QLineEdit( this );
185 myMeshGroupLine->setReadOnly( true );
187 /***************************************************************/
188 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
189 myTypeGroup = new QButtonGroup( this );
190 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
191 aTypeBoxLayout->setMargin( MARGIN );
192 aTypeBoxLayout->setSpacing( SPACING );
195 types.append( tr( "MESH_NODE" ) );
196 types.append( tr( "SMESH_EDGE" ) );
197 types.append( tr( "SMESH_FACE" ) );
198 types.append( tr( "SMESH_VOLUME" ) );
200 for ( int i = 0; i < types.count(); i++ )
202 rb = new QRadioButton( types[i], aTypeBox );
203 myTypeGroup->addButton( rb, i );
204 aTypeBoxLayout->addWidget( rb );
206 aTypeBox->setEnabled( create );
209 /***************************************************************/
210 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
211 aName->setMinimumWidth( 50 );
212 myName = new QLineEdit( this );
214 /***************************************************************/
215 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
216 myGrpTypeGroup = new QButtonGroup( this );
217 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
218 aGrpTypeBoxLayout->setMargin( MARGIN );
219 aGrpTypeBoxLayout->setSpacing( SPACING );
221 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
222 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
223 myGrpTypeGroup->addButton( rb1, 0 );
224 myGrpTypeGroup->addButton( rb2, 1 );
225 aGrpTypeBoxLayout->addWidget( rb1 );
226 aGrpTypeBoxLayout->addWidget( rb2 );
227 aGrpTypeBox->setEnabled( create );
230 /***************************************************************/
231 myWGStack = new QStackedWidget( this );
232 QWidget* wg1 = new QWidget( myWGStack );
233 QWidget* wg2 = new QWidget( myWGStack );
235 /***************************************************************/
236 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
237 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
238 aContentBoxLayout->setMargin( MARGIN );
239 aContentBoxLayout->setSpacing( SPACING );
241 QLabel* aLabel = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
242 myElements = new QListWidget( aContentBox );
243 myElements->setSelectionMode( QListWidget::ExtendedSelection );
245 myFilter = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
246 QPushButton* aAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
247 QPushButton* aRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
248 QPushButton* aSortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
250 aContentBoxLayout->addWidget( aLabel, 0, 0 );
251 aContentBoxLayout->addWidget( myElements, 1, 0, 6, 1 );
252 aContentBoxLayout->addWidget( myFilter, 1, 1 );
253 aContentBoxLayout->addWidget( aAddBtn, 3, 1 );
254 aContentBoxLayout->addWidget( aRemoveBtn, 4, 1 );
255 aContentBoxLayout->addWidget( aSortBtn, 6, 1 );
257 aContentBoxLayout->setColumnStretch( 0, 1 );
258 aContentBoxLayout->setRowStretch( 2, 1 );
259 aContentBoxLayout->setRowStretch( 5, 1 );
261 /***************************************************************/
262 QGroupBox* aSelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
263 QGridLayout* aSelectBoxLayout = new QGridLayout( aSelectBox );
264 aSelectBoxLayout->setMargin( MARGIN );
265 aSelectBoxLayout->setSpacing( SPACING );
267 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), aSelectBox );
268 mySubMeshBtn = new QPushButton( aSelectBox );
269 mySubMeshBtn->setIcon( image0 );
270 mySubMeshLine = new QLineEdit( aSelectBox );
271 mySubMeshLine->setReadOnly( true );
272 onSelectSubMesh( false );
274 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), aSelectBox );
275 myGroupBtn = new QPushButton( aSelectBox );
276 myGroupBtn->setIcon( image0 );
277 myGroupLine = new QLineEdit( aSelectBox );
278 myGroupLine->setReadOnly( true );
279 onSelectGroup( false );
281 aSelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
282 aSelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
283 aSelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
284 aSelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
285 aSelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
286 aSelectBoxLayout->addWidget( myGroupLine, 1, 2 );
288 /***************************************************************/
289 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
290 wg1Layout->setMargin( 0 );
291 wg1Layout->setSpacing( SPACING );
292 wg1Layout->addWidget( aContentBox );
293 wg1Layout->addWidget( aSelectBox );
294 wg1Layout->setStretchFactor( aContentBox, 10 );
296 /***************************************************************/
297 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
298 myGeomGroupBtn = new QToolButton( wg2 );
299 myGeomGroupBtn->setIcon( image0 );
300 myGeomGroupBtn->setCheckable( true );
301 myGeomGroupLine = new QLineEdit( wg2 );
302 myGeomGroupLine->setReadOnly( true ); //VSR ???
303 onSelectGeomGroup( false );
305 myGeomGroupBtn->setEnabled( create );
306 myGeomGroupLine->setEnabled( create );
308 /***************************************************************/
309 QGridLayout* wg2Layout = new QGridLayout( wg2 );
310 wg2Layout->setMargin( 0 );
311 wg1Layout->setSpacing( SPACING );
312 wg2Layout->addWidget( geomObject, 0, 0 );
313 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
314 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
315 wg2Layout->setRowStretch( 1, 5 );
317 /***************************************************************/
318 myWGStack->insertWidget( 0, wg1 );
319 myWGStack->insertWidget( 1, wg2 );
321 /***************************************************************/
322 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
323 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
324 aColorBoxLayout->setMargin(MARGIN);
325 aColorBoxLayout->setSpacing(SPACING);
327 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
328 myColorBtn = new QtxColorButton(aColorBox);
329 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
330 myColorBtn->sizePolicy().verticalPolicy() );
332 aColorBoxLayout->addWidget(aColorLab);
333 aColorBoxLayout->addWidget(myColorBtn);
335 /***************************************************************/
337 QFrame* aButtons = new QFrame(this);
338 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
339 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
340 aBtnLayout->setMargin(MARGIN);
341 aBtnLayout->setSpacing(SPACING);
343 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
344 myOKBtn->setAutoDefault(true);
345 myOKBtn->setDefault(true);
346 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
347 myApplyBtn->setAutoDefault(true);
348 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
349 myCloseBtn->setAutoDefault(true);
350 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
351 myHelpBtn->setAutoDefault(true);
353 aBtnLayout->addWidget(myOKBtn);
354 aBtnLayout->addSpacing(10);
355 aBtnLayout->addWidget(myApplyBtn);
356 aBtnLayout->addSpacing(10);
357 aBtnLayout->addStretch();
358 aBtnLayout->addWidget(myCloseBtn);
359 aBtnLayout->addWidget(myHelpBtn);
361 /***************************************************************/
362 aMainLayout->addWidget(meshGroupLab, 0, 0);
363 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
364 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
365 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
366 aMainLayout->addWidget(aName, 2, 0);
367 aMainLayout->addWidget(myName, 2, 2);
368 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
369 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
370 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
371 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
373 /* signals and slots connections */
374 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
375 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
376 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
378 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
379 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
381 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
382 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
383 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
384 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
386 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
387 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
388 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
389 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
390 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
392 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
394 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
395 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
396 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
397 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
400 mySMESHGUI->SetActiveDialogBox(this);
401 mySMESHGUI->SetState(800);
403 mySelectionMode = -1;
404 myMeshFilter = new SMESH_TypeFilter(MESH);
405 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
406 myGroupFilter = new SMESH_TypeFilter(GROUP);
407 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
408 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
410 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
411 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
412 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
414 rb1->setChecked(true); // VSR !!!
415 onGrpTypeChanged(0); // VSR!!!
417 if (myMesh->_is_nil() )
418 myTypeGroup->button(0)->setChecked(true);
421 //myName->setText(GetDefaultName(tr( "SMESH_GROUP" )));
424 //=================================================================================
425 // function : ~SMESHGUI_GroupDlg()
426 // purpose : Destroys the object and frees any allocated resources
427 //=================================================================================
428 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
430 // no need to delete child widgets, Qt does it all for us
431 if ( myFilterDlg != 0 ) {
432 myFilterDlg->setParent( 0 );
437 //=================================================================================
438 // function : GetDefaultName()
439 // purpose : Get the Group Name if Create new Group
440 //=================================================================================
441 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
445 // collect all object names of SMESH component
446 SalomeApp_Study* appStudy =
447 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
448 if ( !appStudy ) return aName;
449 _PTR(Study) aStudy = appStudy->studyDS();
451 std::set<std::string> aSet;
452 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
454 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
456 for (it->InitEx(true); it->More(); it->Next()) {
458 aSet.insert(obj->GetName());
462 // build a unique name
464 bool isUnique = false;
466 aName = theOperation + "_" + QString::number(++aNumber);
467 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
473 //=================================================================================
476 //=================================================================================
477 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
479 mySelectionMgr->installFilter(myMeshFilter);
481 /* init data from current selection */
482 restoreShowEntityMode();
483 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
485 myGroup = SMESH::SMESH_Group::_nil();
486 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
488 // NPAL19389: create a group with a selection in another group
489 // set actor of myMesh, if it is visible, else try
490 // any visible actor of group or submesh of myMesh
491 SetAppropriateActor();
493 setDefaultGroupColor();
496 mySelectionMgr->selectedObjects( aList );
497 if( !aList.IsEmpty() )
499 QString aName = aList.First()->getName();
500 myMeshGroupLine->setText(aName);
501 myMeshGroupLine->home( false );
504 myCurrentLineEdit = 0;
506 myTypeGroup->button(0)->setChecked(true);
510 //=================================================================================
513 //=================================================================================
514 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
516 restoreShowEntityMode();
517 myMesh = theGroup->GetMesh();
520 myNameChanged = true;
521 myName->blockSignals(true);
522 myName->setText(theGroup->GetName());
523 myName->blockSignals(false);
526 SALOMEDS::Color aColor = theGroup->GetColor();
527 setGroupColor( aColor );
529 myMeshGroupLine->setText(theGroup->GetName());
532 switch(theGroup->GetType()) {
533 case SMESH::NODE: aType= 0; break;
534 case SMESH::EDGE: aType = 1; break;
535 case SMESH::FACE: aType = 2; break;
536 case SMESH::VOLUME: aType = 3; break;
538 myTypeGroup->button(aType)->setChecked(true);
540 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
542 if (!myGroup->_is_nil())
544 // NPAL19389: create a group with a selection in another group
545 // set actor of myMesh, if it is visible, else set
546 // actor of myGroup, if it is visible, else try
547 // any visible actor of group or submesh of myMesh
548 // commented, because an attempt to set selection on not displayed cells leads to error
549 //SetAppropriateActor();
550 myActor = SMESH::FindActorByObject(myMesh);
552 myActor = SMESH::FindActorByObject(myGroup);
553 SMESH::SetPickable(myActor);
555 myGrpTypeGroup->button(0)->setChecked(true);
558 myCurrentLineEdit = 0;
560 setSelectionMode(aType);
563 setShowEntityMode(); // depends on myTypeId
566 if (!myGroup->IsEmpty()) {
567 SMESH::long_array_var anElements = myGroup->GetListOfID();
568 int k = anElements->length();
569 for (int i = 0; i < k; i++) {
570 myIdList.append(anElements[i]);
571 myElements->addItem(QString::number(anElements[i]));
573 myElements->selectAll();
578 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
580 if ( !myGroupOnGeom->_is_nil() )
582 // NPAL19389: create a group with a selection in another group
583 // set actor of myMesh, if it is visible, else set
584 // actor of myGroupOnGeom, if it is visible, else try
585 // any visible actor of group or submesh of myMesh
586 // commented, because an attempt to set selection on not displayed cells leads to error
587 //SetAppropriateActor();
588 myActor = SMESH::FindActorByObject(myMesh);
590 myActor = SMESH::FindActorByObject(myGroupOnGeom);
591 SMESH::SetPickable(myActor);
593 myGrpTypeGroup->button(1)->setChecked(true);
596 QString aShapeName( "" );
597 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
598 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
599 if (!aGroupShape->_is_nil())
601 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
602 aShapeName = aGroupShapeSO->GetName().c_str();
604 myGeomGroupLine->setText( aShapeName );
605 myNameChanged = true;
606 myName->blockSignals(true);
607 myName->setText( "Group On " + aShapeName);
608 myName->blockSignals(false);
613 //=================================================================================
614 // function : updateButtons()
616 //=================================================================================
617 void SMESHGUI_GroupDlg::updateButtons()
619 bool enable = !myName->text().trimmed().isEmpty();
621 if (myGrpTypeId == 0) {
622 enable = enable && myElements->count() > 0;
623 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
625 else if (myGrpTypeId == 1) {
626 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
627 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
631 myOKBtn->setEnabled(enable);
632 myApplyBtn->setEnabled(enable);
635 //=================================================================================
636 // function : onNameChanged()
638 //=================================================================================
639 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
641 myOldName = myName->text();
643 myNameChanged = !myName->text().trimmed().isEmpty();
646 //=================================================================================
647 // function : onTypeChanged()
648 // purpose : Group elements type radio button management
649 //=================================================================================
650 void SMESHGUI_GroupDlg::onTypeChanged (int id)
652 if (myTypeId != id) {
654 if (myCurrentLineEdit == 0)
655 setSelectionMode(id);
661 //=================================================================================
662 // function : onGrpTypeChanged()
663 // purpose : Group type radio button management
664 //=================================================================================
665 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
667 if (myGrpTypeId != id) {
668 myWGStack->setCurrentIndex( id );
669 myName->blockSignals(true);
670 myName->setText(myOldName);
671 myName->blockSignals(false);
672 onSelectGeomGroup(id == 1);
677 //=================================================================================
678 // function : onColorChanged()
679 // purpose : Color button management
680 //=================================================================================
681 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
686 //=================================================================================
687 // function : setSelectionMode()
688 // purpose : Radio button management
689 //=================================================================================
690 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
693 if (myMesh->_is_nil())
695 if (mySelectionMode != theMode) {
696 // [PAL10408] mySelectionMgr->clearSelected();
697 mySelectionMgr->clearFilters();
699 myActor->SetPointRepresentation(false);
701 SMESH::SetPointRepresentation(false);
706 myActor->SetPointRepresentation(true);
708 SMESH::SetPointRepresentation(true);
709 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
710 aViewWindow->SetSelectionMode(NodeSelection);
713 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
714 aViewWindow->SetSelectionMode(EdgeSelection);
717 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
718 aViewWindow->SetSelectionMode(FaceSelection);
721 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
722 aViewWindow->SetSelectionMode(VolumeSelection);
726 mySelectionMgr->installFilter(mySubMeshFilter);
727 else if (theMode == 5)
728 mySelectionMgr->installFilter(myGroupFilter);
729 else if (theMode == 6)
730 mySelectionMgr->installFilter(myMeshFilter);
731 else if (theMode == 7)
732 mySelectionMgr->installFilter(myGeomFilter);
734 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
735 aViewWindow->SetSelectionMode(ActorSelection);
737 mySelectionMode = theMode;
741 //=================================================================================
742 // function : onApply()
744 //=================================================================================
745 bool SMESHGUI_GroupDlg::onApply()
747 if (mySMESHGUI->isActiveStudyLocked())
750 if (myName->text().trimmed().isEmpty())
753 if (myGrpTypeId == 0) { // on mesh elements
754 if (!myElements->count())
757 mySelectionMgr->clearSelected();
759 if (myGroup->_is_nil()) { // creation
760 if (myMesh->_is_nil())
763 SMESH::ElementType aType = SMESH::ALL;
765 case 0: aType = SMESH::NODE; break;
766 case 1: aType = SMESH::EDGE; break;
767 case 2: aType = SMESH::FACE; break;
768 case 3: aType = SMESH::VOLUME; break;
771 SMESH::long_array_var anIdList = new SMESH::long_array;
772 int i, k = myElements->count();
774 for (i = 0; i < k; i++) {
775 anIdList[i] = myElements->item(i)->text().toInt();
778 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
779 myGroup->Add(anIdList.inout());
781 SALOMEDS::Color aColor = getGroupColor();
782 myGroup->SetColor(aColor);
784 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
786 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
787 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
789 /* init for next operation */
790 myName->setText( "" );
792 myGroup = SMESH::SMESH_Group::_nil();
795 myGroup->SetName(myName->text().toLatin1().data());
797 SALOMEDS::Color aColor = getGroupColor();
798 myGroup->SetColor(aColor);
800 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
801 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
802 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
806 int i, total = myElements->count();
807 for (i = 0; i < total; i++) {
808 int anId = myElements->item(i)->text().toInt();
809 int idx = myIdList.indexOf(anId);
811 aAddList.append(anId);
813 myIdList.removeAt(idx);
815 if (!aAddList.empty()) {
816 SMESH::long_array_var anIdList = new SMESH::long_array;
817 int added = aAddList.count();
818 anIdList->length(added);
819 for (i = 0; i < added; i++)
820 anIdList[i] = aAddList[i];
821 myGroup->Add(anIdList.inout());
823 if (!myIdList.empty()) {
824 SMESH::long_array_var anIdList = new SMESH::long_array;
825 int removed = myIdList.count();
826 anIdList->length(removed);
827 for (i = 0; i < removed; i++)
828 anIdList[i] = myIdList[i];
829 myGroup->Remove(anIdList.inout());
831 /* init for next operation */
833 for (i = 0; i < total; i++) {
834 myIdList.append(myElements->item(i)->text().toInt());
838 mySMESHGUI->updateObjBrowser(true);
839 SMESH::UpdateView(); // asv: fix of BUG PAL5515
840 mySelectionMgr->clearSelected();
843 else if (myGrpTypeId == 1) { // on geom object
844 if (CORBA::is_nil(myGroupOnGeom)) { // creation
845 if (myMesh->_is_nil() || !myGeomObjects->length())
848 SMESH::ElementType aType = SMESH::ALL;
850 case 0: aType = SMESH::NODE; break;
851 case 1: aType = SMESH::EDGE; break;
852 case 2: aType = SMESH::FACE; break;
853 case 3: aType = SMESH::VOLUME; break;
856 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
857 GEOM::GEOM_IGroupOperations_var aGroupOp =
858 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
860 if (myGeomObjects->length() == 1) {
861 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
862 myName->text().toLatin1().data(),
866 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
867 if ( aSMESHGen->_is_nil() )
870 // create a geometry group
871 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
872 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
874 if (geomGen->_is_nil() || !aStudy)
877 GEOM::GEOM_IGroupOperations_var op =
878 geomGen->GetIGroupOperations(aStudy->StudyId());
882 // check and add all selected GEOM objects: they must be
883 // a sub-shapes of the main GEOM and must be of one type
884 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
885 for ( int i =0; i < myGeomObjects->length(); i++) {
886 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
888 aGroupType = aSubShapeType;
889 else if (aSubShapeType != aGroupType) {
890 aGroupType = TopAbs_SHAPE;
895 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
896 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
897 op->UnionList(aGroupVar, myGeomObjects);
900 // publish the GEOM group in study
901 QString aNewGeomGroupName ( "Auto_group_for_" );
902 aNewGeomGroupName += myName->text();
903 SALOMEDS::SObject_var aNewGroupSO =
904 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
905 aNewGeomGroupName.toLatin1().data(), aMeshShape);
908 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
909 myName->text().toLatin1().data(),
913 SALOMEDS::Color aColor = getGroupColor();
914 myGroupOnGeom->SetColor(aColor);
916 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
918 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
919 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
921 /* init for next operation */
922 myName->setText( "" );
923 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
926 myGroupOnGeom->SetName(myName->text().toLatin1().data());
928 SALOMEDS::Color aColor = getGroupColor();
929 myGroupOnGeom->SetColor(aColor);
931 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
932 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
933 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
936 mySMESHGUI->updateObjBrowser(true);
937 mySelectionMgr->clearSelected();
944 //=================================================================================
947 //=================================================================================
948 void SMESHGUI_GroupDlg::onOK()
954 //=================================================================================
955 // function : onListSelectionChanged()
956 // purpose : Called when selection in element list is changed
957 //=================================================================================
958 void SMESHGUI_GroupDlg::onListSelectionChanged()
960 // MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
961 if( myIsBusy || !myActor) return;
964 if (myCurrentLineEdit == 0) {
965 mySelectionMgr->clearSelected();
966 TColStd_MapOfInteger aIndexes;
967 QList<QListWidgetItem*> selItems = myElements->selectedItems();
968 QListWidgetItem* anItem;
969 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
970 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
972 aList.Append(myActor->getIO());
973 mySelectionMgr->setSelectedObjects(aList,false);
978 //=================================================================================
979 // function : onObjectSelectionChanged()
980 // purpose : Called when selection in 3D view or ObjectBrowser is changed
981 //=================================================================================
982 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
984 if ( myIsBusy || !isEnabled()) return;
985 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
990 mySelectionMgr->selectedObjects( aList );
992 int aNbSel = aList.Extent();
993 myElements->clearSelection();
995 if (myCurrentLineEdit)
997 myCurrentLineEdit->setText( "" );
998 QString aString = "";
1000 if (myCurrentLineEdit == myMeshGroupLine)
1002 mySelectSubMesh->setEnabled(false);
1003 mySelectGroup->setEnabled(false);
1004 myGroupLine->setText( "" );
1005 mySubMeshLine->setText( "" );
1007 myGeomGroupBtn->setEnabled(false);
1008 myGeomGroupLine->setEnabled(false);
1009 myGeomGroupLine->setText( "" );
1010 myGeomObjects = new GEOM::ListOfGO();
1011 myGeomObjects->length(0);
1013 if (myGeomGroupBtn->isChecked())
1014 myGeomGroupBtn->setChecked(false);
1016 myName->setText( "" );
1018 myElements->clear();
1021 myGroup = SMESH::SMESH_Group::_nil();
1022 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1023 restoreShowEntityMode();
1024 myMesh = SMESH::SMESH_Mesh::_nil();
1030 Handle(SALOME_InteractiveObject) IO = aList.First();
1033 restoreShowEntityMode();
1034 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1035 setShowEntityMode();
1037 if (myMesh->_is_nil())
1043 myGroup = SMESH::SMESH_Group::_nil();
1045 // NPAL19389: create a group with a selection in another group
1046 // set actor of myMesh, if it is visible, else try
1047 // any visible actor of group or submesh of myMesh
1048 SetAppropriateActor();
1050 aString = aList.First()->getName();
1051 myMeshGroupLine->setText(aString);
1052 myMeshGroupLine->home( false );
1054 mySelectSubMesh->setEnabled(true);
1055 mySelectGroup->setEnabled(true);
1056 myGeomGroupBtn->setEnabled(true);
1057 myGeomGroupLine->setEnabled(true);
1061 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1062 if (aGroup->_is_nil())
1068 myCurrentLineEdit = 0;
1070 myGroup = SMESH::SMESH_Group::_nil();
1071 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1075 mySelectSubMesh->setEnabled(true);
1076 mySelectGroup->setEnabled(true);
1078 myCurrentLineEdit = 0;
1083 if (myGrpTypeId == 0)
1089 myElements->clear();
1090 setSelectionMode(myTypeId);
1098 else if (myCurrentLineEdit == myGeomGroupLine)
1100 myGeomObjects = new GEOM::ListOfGO();
1103 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1105 if (aNbSel == 0 || !aMeshSO)
1107 myGeomObjects->length(0);
1113 myGeomObjects->length(aNbSel);
1115 GEOM::GEOM_Object_var aGeomGroup;
1116 Standard_Boolean testResult;
1119 SALOME_ListIteratorOfListIO anIt (aList);
1120 for (; anIt.More(); anIt.Next())
1122 testResult = Standard_False;
1123 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1125 // Check if the object is a geometry group
1126 if (!testResult || CORBA::is_nil(aGeomGroup))
1129 // Check if group constructed on the same shape as a mesh or on its child
1130 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1131 GEOM::GEOM_IGroupOperations_var anOp =
1132 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1134 // The main shape of the group
1135 GEOM::GEOM_Object_var aGroupMainShape;
1136 if (aGeomGroup->GetType() == 37)
1137 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1139 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1140 _PTR(SObject) aGroupMainShapeSO =
1141 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1142 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1144 _PTR(SObject) anObj, aRef;
1145 bool isRefOrSubShape = false;
1146 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1147 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1148 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1149 isRefOrSubShape = true;
1151 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1152 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1153 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1154 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1155 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1156 if (aRef->GetID() == aFather->GetID())
1157 isRefOrSubShape = true;
1159 aFather = aFather->GetFather();
1163 if (isRefOrSubShape)
1164 myGeomObjects[i++] = aGeomGroup;
1167 myGeomObjects->length(i);
1179 if (myCurrentLineEdit == mySubMeshLine)
1180 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1181 else if (myCurrentLineEdit == myGroupLine)
1182 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1183 else if (myCurrentLineEdit == myGeomGroupLine)
1184 aString = tr( "%1 Objects" ).arg(aNbSel);
1187 aString = aList.First()->getName();
1191 myCurrentLineEdit->setText(aString);
1192 myCurrentLineEdit->home(false);
1193 // 07.06.2008 skl for IPAL19574:
1194 // change name of group only if it is empty
1195 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1196 myOldName = myName->text();
1197 myName->blockSignals(true);
1198 myName->setText(aString);
1199 myName->blockSignals(false);
1204 else // !myCurrentLineEdit: local selection of nodes or elements
1206 if (aNbSel == 1 && myActor && myActor->hasIO())
1208 #ifdef ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
1209 // NPAL19389: create a group with a selection in another group
1210 // Switch myActor to the newly selected one, if the last
1211 // is visible and belongs to group or submesh of myMesh
1212 Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1213 Handle(SALOME_InteractiveObject) selIO = aList.First();
1214 if (curIO->hasEntry() && selIO->hasEntry()) {
1215 const char* selEntry = selIO->getEntry();
1216 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1217 // different objects: selected and myActor
1218 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1219 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1220 // newly selected actor is visible
1223 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1225 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1226 int len = strlen(meshEntry);
1228 if (strncmp(selEntry, meshEntry, len) == 0) {
1229 // selected object is myMesh or a part of it
1230 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1233 SMESH::SetPickable(myActor);
1241 #endif // ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
1243 QString aListStr = "";
1245 if (myTypeId == 0) {
1246 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1248 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1251 QListWidgetItem* anItem;
1252 QList<QListWidgetItem*> listItemsToSel;
1253 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1254 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1255 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1256 foreach(anItem, found)
1257 if (!anItem->isSelected())
1258 listItemsToSel.push_back(anItem);
1260 bool blocked = myElements->signalsBlocked();
1261 myElements->blockSignals(true);
1262 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1263 myElements->blockSignals(blocked);
1264 onListSelectionChanged();
1265 listItemsToSel.clear();
1271 if (!myGroup->_is_nil())
1272 myActor = SMESH::FindActorByObject(myGroup);
1273 else if(!myGroupOnGeom->_is_nil())
1274 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1276 myActor = SMESH::FindActorByObject(myMesh);
1279 // somehow, if we display the mesh, while selecting from another actor,
1280 // the mesh becomes pickable, and there is no way to select any element
1282 SMESH::SetPickable(myActor);
1287 //=================================================================================
1288 // function : onSelectSubMesh()
1289 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1290 //=================================================================================
1291 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1294 if (mySelectGroup->isChecked()) {
1295 mySelectGroup->setChecked(false);
1297 //VSR: else if (mySelectGeomGroup->isChecked()) {
1298 //VSR: mySelectGeomGroup->setChecked(false);
1300 myCurrentLineEdit = mySubMeshLine;
1301 setSelectionMode(4);
1304 mySubMeshLine->setText( "" );
1305 myCurrentLineEdit = 0;
1307 setSelectionMode(myTypeId);
1309 mySubMeshBtn->setEnabled(on);
1310 mySubMeshLine->setEnabled(on);
1314 //=================================================================================
1315 // function : (onSelectGroup)
1316 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1317 //=================================================================================
1318 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1321 if (mySelectSubMesh->isChecked()) {
1322 mySelectSubMesh->setChecked(false);
1324 myCurrentLineEdit = myGroupLine;
1325 setSelectionMode(5);
1328 myGroupLine->setText( "" );
1329 myCurrentLineEdit = 0;
1331 setSelectionMode(myTypeId);
1333 myGroupBtn->setEnabled(on);
1334 myGroupLine->setEnabled(on);
1338 //=================================================================================
1339 // function : (onSelectGeomGroup)
1340 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1341 //=================================================================================
1342 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1345 if (mySelectSubMesh->isChecked()) {
1346 mySelectSubMesh->setChecked(false);
1348 else if (mySelectGroup->isChecked()) {
1349 mySelectGroup->setChecked(false);
1351 myCurrentLineEdit = myGeomGroupLine;
1353 setSelectionMode(8);
1356 myGeomGroupBtn->setChecked(false);
1357 myGeomObjects->length(0);
1358 myGeomGroupLine->setText( "" );
1359 myCurrentLineEdit = 0;
1361 setSelectionMode(myTypeId);
1366 //=================================================================================
1367 // function : setCurrentSelection()
1369 //=================================================================================
1370 void SMESHGUI_GroupDlg::setCurrentSelection()
1372 QPushButton* send = (QPushButton*)sender();
1373 myCurrentLineEdit = 0;
1374 if (send == myMeshGroupBtn) {
1375 myCurrentLineEdit = myMeshGroupLine;
1377 setSelectionMode(6);
1379 setSelectionMode(5);
1380 onObjectSelectionChanged();
1382 else if (send == mySubMeshBtn) {
1383 myCurrentLineEdit = mySubMeshLine;
1384 onObjectSelectionChanged();
1386 else if (send == myGroupBtn) {
1387 myCurrentLineEdit = myGroupLine;
1388 onObjectSelectionChanged();
1393 //=================================================================================
1394 // function : setFilters()
1395 // purpose : SLOT. Called when "Filter" button pressed.
1396 //=================================================================================
1397 void SMESHGUI_GroupDlg::setFilters()
1399 SMESH::ElementType aType = SMESH::ALL;
1402 case 0 : aType = SMESH::NODE; break;
1403 case 1 : aType = SMESH::EDGE; break;
1404 case 2 : aType = SMESH::FACE; break;
1405 case 3 : aType = SMESH::VOLUME; break;
1409 if ( myFilterDlg == 0 )
1411 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1412 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1415 myFilterDlg->Init( aType );
1417 myFilterDlg->SetSelection();
1418 myFilterDlg->SetMesh( myMesh );
1419 myFilterDlg->SetSourceWg( myElements );
1421 myFilterDlg->show();
1424 //=================================================================================
1425 // function : onFilterAccepted()
1426 // purpose : SLOT. Called when Filter dlg closed with OK button.
1427 // Uncheck "Select submesh" and "Select group" checkboxes
1428 //=================================================================================
1429 void SMESHGUI_GroupDlg::onFilterAccepted()
1431 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1433 mySelectionMode = myTypeId;
1434 mySelectSubMesh->setChecked( false );
1435 mySelectGroup->setChecked( false );
1439 //=================================================================================
1440 // function : onAdd()
1442 //=================================================================================
1443 void SMESHGUI_GroupDlg::onAdd()
1445 SALOME_ListIO aList;
1446 mySelectionMgr->selectedObjects( aList );
1448 int aNbSel = aList.Extent();
1450 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1454 SMESH::ElementType aType = SMESH::ALL;
1457 aType = SMESH::NODE;
1458 mySelector->SetSelectionMode(NodeSelection);
1461 aType = SMESH::EDGE;
1462 mySelector->SetSelectionMode(EdgeSelection);
1465 aType = SMESH::FACE;
1466 mySelector->SetSelectionMode(FaceSelection);
1469 aType = SMESH::VOLUME;
1470 mySelector->SetSelectionMode(VolumeSelection);
1473 mySelector->SetSelectionMode(ActorSelection);
1476 QListWidgetItem* anItem = 0;
1477 QList<QListWidgetItem*> listItemsToSel;
1479 if (myCurrentLineEdit == 0) {
1480 //if (aNbSel != 1) { myIsBusy = false; return; }
1481 QString aListStr = "";
1483 if (myTypeId == 0) {
1484 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1487 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1490 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1491 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1492 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1493 if (found.count() == 0) {
1494 anItem = new QListWidgetItem(*it);
1495 myElements->addItem(anItem);
1496 if (!anItem->isSelected())
1497 listItemsToSel.push_back(anItem);
1500 foreach(anItem, found)
1501 if (!anItem->isSelected())
1502 listItemsToSel.push_back(anItem);
1505 bool blocked = myElements->signalsBlocked();
1506 myElements->blockSignals(true);
1507 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1508 myElements->blockSignals(blocked);
1509 onListSelectionChanged();
1510 listItemsToSel.clear();
1512 } else if (myCurrentLineEdit == mySubMeshLine) {
1513 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1515 SALOME_ListIO aList;
1516 mySelectionMgr->selectedObjects( aList );
1518 SALOME_ListIteratorOfListIO anIt (aList);
1519 for ( ; anIt.More(); anIt.Next()) {
1520 SMESH::SMESH_subMesh_var aSubMesh =
1521 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1522 if (!aSubMesh->_is_nil()) {
1523 // check if mesh is the same
1524 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1526 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1527 int k = anElements->length();
1528 for (int i = 0; i < k; i++) {
1529 QString aText = QString::number(anElements[i]);
1530 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1531 if (found.count() == 0) {
1532 anItem = new QListWidgetItem(aText);
1533 myElements->addItem(anItem);
1534 if (!anItem->isSelected())
1535 listItemsToSel.push_back(anItem);
1538 foreach(anItem, found)
1539 if (!anItem->isSelected())
1540 listItemsToSel.push_back(anItem);
1543 bool blocked = myElements->signalsBlocked();
1544 myElements->blockSignals(true);
1545 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1546 myElements->blockSignals(blocked);
1547 onListSelectionChanged();
1548 listItemsToSel.clear();
1550 catch (const SALOME::SALOME_Exception& ex) {
1551 SalomeApp_Tools::QtCatchCorbaException(ex);
1556 mySelectSubMesh->setChecked(false);
1558 onListSelectionChanged();
1560 } else if (myCurrentLineEdit == myGroupLine) {
1561 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1562 SALOME_ListIO aList;
1563 mySelectionMgr->selectedObjects( aList );
1565 SALOME_ListIteratorOfListIO anIt (aList);
1566 for ( ; anIt.More(); anIt.Next()) {
1567 SMESH::SMESH_Group_var aGroup =
1568 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1569 if (!aGroup->_is_nil()) {
1570 // check if mesh is the same
1571 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1572 SMESH::long_array_var anElements = aGroup->GetListOfID();
1573 int k = anElements->length();
1574 for (int i = 0; i < k; i++) {
1575 QString aText = QString::number(anElements[i]);
1576 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1577 if (found.count() == 0) {
1578 anItem = new QListWidgetItem(aText);
1579 myElements->addItem(anItem);
1580 if (!anItem->isSelected())
1581 listItemsToSel.push_back(anItem);
1584 foreach(anItem, found)
1585 if (!anItem->isSelected())
1586 listItemsToSel.push_back(anItem);
1589 bool blocked = myElements->signalsBlocked();
1590 myElements->blockSignals(true);
1591 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1592 myElements->blockSignals(blocked);
1593 onListSelectionChanged();
1594 listItemsToSel.clear();
1598 mySelectGroup->setChecked(false);
1600 onListSelectionChanged();
1602 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1603 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1604 GEOM::GEOM_IGroupOperations_var aGroupOp =
1605 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1607 SMESH::ElementType aGroupType = SMESH::ALL;
1608 switch(aGroupOp->GetType(myGeomObjects[0])) {
1609 case 7: aGroupType = SMESH::NODE; break;
1610 case 6: aGroupType = SMESH::EDGE; break;
1611 case 4: aGroupType = SMESH::FACE; break;
1612 case 2: aGroupType = SMESH::VOLUME; break;
1613 default: myIsBusy = false; return;
1616 if (aGroupType == aType) {
1617 _PTR(SObject) aGroupSO =
1618 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1619 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1621 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1622 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1623 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1624 aBelongToGeom->SetGeom(myGeomObjects[0]);
1625 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1626 aBelongToGeom->SetElementType(aType);
1627 aFilter->SetPredicate(aBelongToGeom);
1629 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1631 int k = anElements->length();
1632 for (int i = 0; i < k; i++) {
1633 QString aText = QString::number(anElements[i]);
1634 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1635 if (found.count() == 0) {
1636 anItem = new QListWidgetItem(aText);
1637 myElements->addItem(anItem);
1638 if (!anItem->isSelected())
1639 listItemsToSel.push_back(anItem);
1642 foreach(anItem, found)
1643 if (!anItem->isSelected())
1644 listItemsToSel.push_back(anItem);
1647 bool blocked = myElements->signalsBlocked();
1648 myElements->blockSignals(true);
1649 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1650 myElements->blockSignals(blocked);
1651 onListSelectionChanged();
1652 listItemsToSel.clear();
1655 //VSR: mySelectGeomGroup->setChecked(false);
1657 onListSelectionChanged();
1660 // mySelectionMgr->clearSelected();
1664 //=================================================================================
1665 // function : onRemove()
1667 //=================================================================================
1668 void SMESHGUI_GroupDlg::onRemove()
1671 if (myCurrentLineEdit == 0) {
1672 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1673 QListWidgetItem* item;
1674 foreach(item, selItems) delete item;
1676 SALOME_ListIO aList;
1677 mySelectionMgr->selectedObjects( aList );
1679 int aNbSel = aList.Extent();
1681 if (aNbSel == 0) { myIsBusy = false; return; }
1683 SMESH::ElementType aType = SMESH::ALL;
1685 case 0: aType = SMESH::NODE; break;
1686 case 1: aType = SMESH::EDGE; break;
1687 case 2: aType = SMESH::FACE; break;
1688 case 3: aType = SMESH::VOLUME; break;
1691 if (myCurrentLineEdit == mySubMeshLine) {
1692 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1693 SALOME_ListIO aList;
1694 mySelectionMgr->selectedObjects( aList );
1696 SALOME_ListIteratorOfListIO anIt (aList);
1697 for ( ; anIt.More(); anIt.Next()) {
1698 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1699 if (!aSubMesh->_is_nil()) {
1700 // check if mesh is the same
1701 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1702 if (aType == SMESH::NODE) {
1704 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1705 int k = anElements->length();
1706 for (int i = 0; i < k; i++) {
1707 QList<QListWidgetItem*> found =
1708 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1709 QListWidgetItem* anItem;
1710 foreach(anItem, found) delete anItem;
1713 catch (const SALOME::SALOME_Exception& ex) {
1714 SalomeApp_Tools::QtCatchCorbaException(ex);
1719 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1720 int k = anElements->length();
1721 for (int i = 0; i < k; i++) {
1722 QList<QListWidgetItem*> found =
1723 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1724 QListWidgetItem* anItem;
1725 foreach(anItem, found) delete anItem;
1728 catch (const SALOME::SALOME_Exception& ex) {
1729 SalomeApp_Tools::QtCatchCorbaException(ex);
1736 else if (myCurrentLineEdit == myGroupLine) {
1737 Standard_Boolean aRes;
1738 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1739 SALOME_ListIO aList;
1740 mySelectionMgr->selectedObjects( aList );
1742 SALOME_ListIteratorOfListIO anIt (aList);
1743 for ( ; anIt.More(); anIt.Next()) {
1744 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1745 if (aRes && !aGroup->_is_nil()) {
1746 // check if mesh is the same
1747 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1748 SMESH::long_array_var anElements = aGroup->GetListOfID();
1749 int k = anElements->length();
1750 for (int i = 0; i < k; i++) {
1751 QList<QListWidgetItem*> found =
1752 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1753 QListWidgetItem* anItem;
1754 foreach(anItem, found) delete anItem;
1765 //=================================================================================
1766 // function : onSort()
1768 //=================================================================================
1769 void SMESHGUI_GroupDlg::onSort()
1771 // PAL5412: sorts items in ascending by "string" value
1772 // myElements->sort(true);
1773 // myElements->update();
1774 int i, k = myElements->count();
1777 QList<int> aSelected;
1778 std::vector<int> anArray(k);
1779 // QMemArray<int> anArray(k);
1781 for (i = 0; i < k; i++) {
1782 int id = myElements->item(i)->text().toInt();
1784 if (myElements->item(i)->isSelected())
1785 aSelected.append(id);
1787 // sort & update list
1788 std::sort(anArray.begin(), anArray.end());
1790 myElements->clear();
1791 QListWidgetItem* anItem;
1792 QList<QListWidgetItem*> listItemsToSel;
1793 for (i = 0; i < k; i++) {
1794 anItem = new QListWidgetItem(QString::number(anArray[i]));
1795 myElements->addItem(anItem);
1796 if (aSelected.contains(anArray[i]))
1797 listItemsToSel.push_back(anItem);
1799 bool blocked = myElements->signalsBlocked();
1800 myElements->blockSignals(true);
1801 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1802 myElements->blockSignals(blocked);
1803 listItemsToSel.clear();
1808 //=================================================================================
1809 // function : closeEvent()
1811 //=================================================================================
1812 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1817 //=================================================================================
1818 // function : SMESHGUI_GroupDlg::onClose
1819 // purpose : SLOT called when "Close" button pressed. Close dialog
1820 //=================================================================================
1821 void SMESHGUI_GroupDlg::onClose()
1823 if (SMESH::GetCurrentVtkView()) {
1824 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1825 SMESH::SetPointRepresentation(false);
1826 SMESH::SetPickable();
1827 restoreShowEntityMode();
1830 mySelectionMgr->clearSelected();
1831 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1832 aViewWindow->SetSelectionMode(ActorSelection);
1833 mySelectionMgr->clearFilters();
1834 mySMESHGUI->ResetState();
1839 //=================================================================================
1840 // function : onHelp()
1842 //=================================================================================
1843 void SMESHGUI_GroupDlg::onHelp()
1845 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1847 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1851 platform = "winapplication";
1853 platform = "application";
1855 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1856 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1857 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1859 arg(myHelpFileName));
1863 //=================================================================================
1864 // function : SMESHGUI_GroupDlg::onDeactivate
1865 // purpose : SLOT called when dialog must be deativated
1866 //=================================================================================
1867 void SMESHGUI_GroupDlg::onDeactivate()
1869 mySMESHGUI->ResetState();
1873 //=================================================================================
1874 // function : SMESHGUI_GroupDlg::enterEvent
1875 // purpose : Event filter
1876 //=================================================================================
1877 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1880 mySMESHGUI->EmitSignalDeactivateDialog();
1882 mySelectionMode = -1;
1883 setSelectionMode(myTypeId);
1884 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1885 mySMESHGUI->SetActiveDialogBox(this);
1886 mySMESHGUI->SetState(800);
1890 //=================================================================================
1891 // function : hideEvent
1892 // purpose : caused by ESC key
1893 //=================================================================================
1894 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1896 if (!isMinimized() && !myIsBusy)
1900 //=================================================================================
1901 // function : keyPressEvent()
1903 //=================================================================================
1904 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1906 QDialog::keyPressEvent( e );
1907 if ( e->isAccepted() )
1910 if ( e->key() == Qt::Key_F1 )
1917 //================================================================================
1919 * \brief Enable showing of the popup when Geometry selection btn is clicked
1920 * \param enable - true to enable
1922 //================================================================================
1924 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1926 void SMESHGUI_GroupDlg::updateGeomPopup()
1928 bool enable = false;
1930 if ( !myMesh->_is_nil() )
1931 enable = myMesh->NbEdges() > 0;
1933 if ( myGeomGroupBtn )
1935 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1937 if ( !myGeomPopup ) {
1938 myGeomPopup = new QMenu(this);
1939 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
1940 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
1941 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
1943 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1949 //=================================================================================
1950 // function : onGeomSelectionButton()
1952 //=================================================================================
1953 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1955 if ( myGeomPopup && isBtnOn )
1957 myCurrentLineEdit = myGeomGroupLine;
1958 QAction* a = myGeomPopup->exec( QCursor::pos() );
1959 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
1960 setSelectionMode(7);
1964 myCurrentLineEdit = 0;
1965 setSelectionMode(8);
1969 //=================================================================================
1970 // function : onGeomPopup()
1972 //=================================================================================
1973 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
1975 int index = myActions[a];
1976 if ( index == GEOM_BY_MESH_INDEX )
1978 mySelectionMode = -1;
1979 if ( !myShapeByMeshOp ) {
1980 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1981 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1982 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1983 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1984 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1986 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1987 if ( !myMesh->_is_nil() ) {
1989 hide(); // stop processing selection
1991 myShapeByMeshOp->setModule( mySMESHGUI );
1992 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1993 myShapeByMeshOp->SetMesh( myMesh );
1994 myShapeByMeshOp->start();
1999 //================================================================================
2001 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2003 //================================================================================
2005 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2007 if ( myShapeByMeshOp == op ) {
2008 mySMESHGUI->getApp()->updateObjectBrowser();
2010 // Select a found geometry object
2011 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2012 if ( !aGeomVar->_is_nil() )
2014 QString ID = aGeomVar->GetStudyEntry();
2015 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2016 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2017 SALOME_ListIO anIOList;
2018 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2019 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2020 anIOList.Append( anIO );
2021 mySelectionMgr->setSelectedObjects( anIOList, false );
2022 onObjectSelectionChanged();
2028 //================================================================================
2030 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2032 //================================================================================
2034 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2036 if ( myShapeByMeshOp == op )
2039 setSelectionMode(7);
2043 //=================================================================================
2044 // function : setGroupColor()
2046 //=================================================================================
2047 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2049 QColor aQColor( (int)( theColor.R * 255.0 ),
2050 (int)( theColor.G * 255.0 ),
2051 (int)( theColor.B * 255.0 ) );
2052 setGroupQColor( aQColor );
2055 //=================================================================================
2056 // function : getGroupColor()
2058 //=================================================================================
2059 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2061 QColor aQColor = getGroupQColor();
2063 SALOMEDS::Color aColor;
2064 aColor.R = (float)aQColor.red() / 255.0;
2065 aColor.G = (float)aQColor.green() / 255.0;
2066 aColor.B = (float)aQColor.blue() / 255.0;
2071 //=================================================================================
2072 // function : setGroupQColor()
2074 //=================================================================================
2075 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2077 if( theColor.isValid() )
2078 myColorBtn->setColor( theColor );
2081 //=================================================================================
2082 // function : getGroupQColor()
2084 //=================================================================================
2085 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2087 return myColorBtn->color();
2090 //=================================================================================
2091 // function : setDefaultGroupColor()
2093 //=================================================================================
2094 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2096 if( myMesh->_is_nil() )
2099 bool isAutoColor = myMesh->GetAutoColor();
2104 int r = 0, g = 0, b = 0;
2105 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2106 aQColor.setRgb( r, g, b );
2110 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2112 QList<SALOMEDS::Color> aReservedColors;
2113 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2115 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2116 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2117 aReservedColors.append( aReservedColor );
2120 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2121 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2122 (int)( aColor.G * 255.0 ),
2123 (int)( aColor.B * 255.0 ) );
2127 setGroupQColor( aQColor );
2130 //=================================================================================
2131 // function : SetAppropriateActor()
2132 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2133 // NPAL19389: create a group with a selection in another group.
2134 // if mesh actor is not visible - find any first visible group or submesh
2135 //=================================================================================
2136 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2138 bool isActor = false;
2140 if (myMesh->_is_nil()) return false;
2142 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2145 myActor = SMESH::FindActorByObject(myMesh);
2146 if (myActor && myActor->hasIO())
2149 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2153 // try current group actor
2155 if (!myGroup->_is_nil()) {
2156 myActor = SMESH::FindActorByObject(myGroup);
2157 if (myActor && myActor->hasIO())
2160 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2166 // try current group on geometry actor
2168 if (!myGroupOnGeom->_is_nil()) {
2169 myActor = SMESH::FindActorByObject(myGroupOnGeom);
2170 if (myActor && myActor->hasIO())
2173 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2179 // try any visible actor of group or submesh of current mesh
2180 if (!isActor && aViewWindow) {
2182 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2184 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2185 int len = strlen(meshEntry);
2187 // iterate on all actors in current view window, search for
2188 // any visible actor, that belongs to group or submesh of current mesh
2189 vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
2190 aCollection->InitTraversal();
2191 for (vtkActor *anAct = aCollection->GetNextActor();
2193 anAct = aCollection->GetNextActor())
2195 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct);
2196 if (anActor && anActor->hasIO()) {
2197 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2198 if (aViewWindow->isVisible(anIO)) {
2199 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0) {
2210 SMESH::SetPickable(myActor);
2215 //=======================================================================
2216 //function : setShowEntityMode
2217 //purpose : make shown only entity corresponding to my type
2218 //=======================================================================
2219 void SMESHGUI_GroupDlg::setShowEntityMode()
2221 if ( !myMesh->_is_nil() ) {
2222 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2223 if (!myStoredShownEntity)
2224 myStoredShownEntity = actor->GetEntityMode();
2225 switch ( myTypeId ) {
2226 case 0: restoreShowEntityMode(); break;
2227 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2228 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2229 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2235 //=======================================================================
2236 //function : restoreShowEntityMode
2237 //purpose : restore ShowEntity mode of myActor
2238 //=======================================================================
2239 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2241 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2242 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2243 actor->SetEntityMode(myStoredShownEntity);
2246 myStoredShownEntity = 0;