1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : SMESHGUI_GroupDlg.cxx
22 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
26 #include "SMESHGUI_GroupDlg.h"
29 #include "SMESHGUI_Utils.h"
30 #include "SMESHGUI_VTKUtils.h"
31 #include "SMESHGUI_GroupUtils.h"
32 #include "SMESHGUI_FilterUtils.h"
33 #include "SMESHGUI_GEOMGenUtils.h"
34 #include "SMESHGUI_FilterDlg.h"
35 #include "SMESHGUI_ShapeByMeshDlg.h"
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_Actor.h>
39 #include <SMESH_ActorUtils.h>
41 // SALOME GEOM includes
43 #include <GEOM_SelectionFilter.h>
45 // SALOME GUI includes
46 #include <QtxColorButton.h>
48 #include <SUIT_Desktop.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_MessageBox.h>
53 #include <SalomeApp_Tools.h>
54 #include <SalomeApp_Application.h>
55 #include <SalomeApp_Study.h>
56 #include <LightApp_SelectionMgr.h>
58 #include <SALOME_ListIO.hxx>
59 #include <SALOME_ListIteratorOfListIO.hxx>
61 #include <SVTK_ViewWindow.h>
63 // SALOME KERNEL includes
64 #include <SALOMEDSClient_Study.hxx>
67 #include <vtkRenderer.h>
68 #include <vtkActorCollection.h>
71 #include <TColStd_MapOfInteger.hxx>
74 #include <QButtonGroup>
78 #include <QPushButton>
79 #include <QToolButton>
80 #include <QRadioButton>
82 #include <QGridLayout>
83 #include <QHBoxLayout>
84 #include <QVBoxLayout>
85 #include <QListWidget>
86 #include <QStackedWidget>
98 //=================================================================================
99 // function : SMESHGUI_GroupDlg()
101 //=================================================================================
102 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
103 SMESH::SMESH_Mesh_ptr theMesh )
104 : QDialog( SMESH::GetDesktop( theModule ) ),
105 mySMESHGUI( theModule ),
106 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
107 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
109 myNameChanged( false ),
113 if ( !theMesh->_is_nil() )
117 mySelectSubMesh->setEnabled( false );
118 mySelectGroup->setEnabled( false );
119 myGeomGroupBtn->setEnabled( false );
120 myGeomGroupLine->setEnabled( false );
124 //=================================================================================
125 // function : SMESHGUI_GroupDlg()
127 //=================================================================================
128 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
129 SMESH::SMESH_GroupBase_ptr theGroup,
130 const bool theIsConvert )
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() )
140 init( theGroup, theIsConvert );
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,
515 const bool theIsConvert)
517 restoreShowEntityMode();
518 myMesh = theGroup->GetMesh();
521 myNameChanged = true;
522 myName->blockSignals(true);
523 myName->setText(theGroup->GetName());
524 myName->blockSignals(false);
527 SALOMEDS::Color aColor = theGroup->GetColor();
528 setGroupColor( aColor );
530 myMeshGroupLine->setText(theGroup->GetName());
533 switch(theGroup->GetType()) {
534 case SMESH::NODE: aType= 0; break;
535 case SMESH::EDGE: aType = 1; break;
536 case SMESH::FACE: aType = 2; break;
537 case SMESH::VOLUME: aType = 3; break;
539 myTypeGroup->button(aType)->setChecked(true);
541 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
542 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
544 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil())
547 // NPAL19389: create a group with a selection in another group
548 // set actor of myMesh, if it is visible, else set
549 // actor of theGroup, if it is visible, else try
550 // any visible actor of group or submesh of myMesh
551 // commented, because an attempt to set selection on not displayed cells leads to error
552 //SetAppropriateActor();
553 myActor = SMESH::FindActorByObject(myMesh);
555 myActor = SMESH::FindActorByObject(theGroup);
556 SMESH::SetPickable(myActor);
558 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : 1));
559 myGrpTypeGroup->button(grpType)->setChecked(true);
560 onGrpTypeChanged(grpType);
562 if ( grpType == 0 ) {
563 myCurrentLineEdit = 0;
565 setSelectionMode(aType);
568 setShowEntityMode(); // depends on myTypeId
571 if (!theGroup->IsEmpty()) {
572 SMESH::long_array_var anElements = theGroup->GetListOfID();
573 int k = anElements->length();
574 for (int i = 0; i < k; i++) {
575 myIdList.append(anElements[i]);
576 myElements->addItem(QString::number(anElements[i]));
578 myElements->selectAll();
583 QString aShapeName( "" );
584 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
585 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
586 if (!aGroupShape->_is_nil())
588 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
589 aShapeName = aGroupShapeSO->GetName().c_str();
591 myGeomGroupLine->setText( aShapeName );
592 myNameChanged = true;
593 myName->blockSignals(true);
594 myName->setText( "Group On " + aShapeName);
595 myName->blockSignals(false);
599 //=================================================================================
600 // function : updateButtons()
602 //=================================================================================
603 void SMESHGUI_GroupDlg::updateButtons()
605 bool enable = !myName->text().trimmed().isEmpty();
607 if (myGrpTypeId == 0) {
608 enable = enable && myElements->count() > 0;
609 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
611 else if (myGrpTypeId == 1) {
612 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
613 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
617 myOKBtn->setEnabled(enable);
618 myApplyBtn->setEnabled(enable);
621 //=================================================================================
622 // function : onNameChanged()
624 //=================================================================================
625 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
627 myOldName = myName->text();
629 myNameChanged = !myName->text().trimmed().isEmpty();
632 //=================================================================================
633 // function : onTypeChanged()
634 // purpose : Group elements type radio button management
635 //=================================================================================
636 void SMESHGUI_GroupDlg::onTypeChanged (int id)
638 if (myTypeId != id) {
640 if (myCurrentLineEdit == 0)
641 setSelectionMode(id);
647 //=================================================================================
648 // function : onGrpTypeChanged()
649 // purpose : Group type radio button management
650 //=================================================================================
651 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
653 if (myGrpTypeId != id) {
654 myWGStack->setCurrentIndex( id );
655 myName->blockSignals(true);
656 myName->setText(myOldName);
657 myName->blockSignals(false);
658 onSelectGeomGroup(id == 1);
663 //=================================================================================
664 // function : onColorChanged()
665 // purpose : Color button management
666 //=================================================================================
667 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
672 //=================================================================================
673 // function : setSelectionMode()
674 // purpose : Radio button management
675 //=================================================================================
676 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
679 if (myMesh->_is_nil())
681 if (mySelectionMode != theMode) {
682 // [PAL10408] mySelectionMgr->clearSelected();
683 mySelectionMgr->clearFilters();
685 myActor->SetPointRepresentation(false);
687 SMESH::SetPointRepresentation(false);
692 myActor->SetPointRepresentation(true);
694 SMESH::SetPointRepresentation(true);
695 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
696 aViewWindow->SetSelectionMode(NodeSelection);
699 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
700 aViewWindow->SetSelectionMode(EdgeSelection);
703 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
704 aViewWindow->SetSelectionMode(FaceSelection);
707 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
708 aViewWindow->SetSelectionMode(VolumeSelection);
712 mySelectionMgr->installFilter(mySubMeshFilter);
713 else if (theMode == 5)
714 mySelectionMgr->installFilter(myGroupFilter);
715 else if (theMode == 6)
716 mySelectionMgr->installFilter(myMeshFilter);
717 else if (theMode == 7)
718 mySelectionMgr->installFilter(myGeomFilter);
720 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
721 aViewWindow->SetSelectionMode(ActorSelection);
723 mySelectionMode = theMode;
727 //=================================================================================
728 // function : onApply()
730 //=================================================================================
731 bool SMESHGUI_GroupDlg::onApply()
733 if (mySMESHGUI->isActiveStudyLocked())
736 if (myName->text().trimmed().isEmpty())
739 if (myGrpTypeId == 0) { // on mesh elements
740 if (!myElements->count())
743 mySelectionMgr->clearSelected();
745 if (myGroup->_is_nil()) { // creation or conversion
746 // check if group on geometry is not null
747 if (!CORBA::is_nil(myGroupOnGeom)) {
748 if (myMesh->_is_nil())
750 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
751 // nullify pointer, because object become dead
752 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
756 if (myGroup->_is_nil()) { // creation
757 if (myMesh->_is_nil())
760 SMESH::ElementType aType = SMESH::ALL;
762 case 0: aType = SMESH::NODE; break;
763 case 1: aType = SMESH::EDGE; break;
764 case 2: aType = SMESH::FACE; break;
765 case 3: aType = SMESH::VOLUME; break;
768 SMESH::long_array_var anIdList = new SMESH::long_array;
769 int i, k = myElements->count();
771 for (i = 0; i < k; i++) {
772 anIdList[i] = myElements->item(i)->text().toInt();
775 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
776 myGroup->Add(anIdList.inout());
778 SALOMEDS::Color aColor = getGroupColor();
779 myGroup->SetColor(aColor);
781 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
783 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
784 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
786 /* init for next operation */
787 myName->setText( "" );
789 myGroup = SMESH::SMESH_Group::_nil();
792 myGroup->SetName(myName->text().toLatin1().data());
794 SALOMEDS::Color aColor = getGroupColor();
795 myGroup->SetColor(aColor);
797 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
798 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
799 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
803 int i, total = myElements->count();
804 for (i = 0; i < total; i++) {
805 int anId = myElements->item(i)->text().toInt();
806 int idx = myIdList.indexOf(anId);
808 aAddList.append(anId);
810 myIdList.removeAt(idx);
812 if (!aAddList.empty()) {
813 SMESH::long_array_var anIdList = new SMESH::long_array;
814 int added = aAddList.count();
815 anIdList->length(added);
816 for (i = 0; i < added; i++)
817 anIdList[i] = aAddList[i];
818 myGroup->Add(anIdList.inout());
820 if (!myIdList.empty()) {
821 SMESH::long_array_var anIdList = new SMESH::long_array;
822 int removed = myIdList.count();
823 anIdList->length(removed);
824 for (i = 0; i < removed; i++)
825 anIdList[i] = myIdList[i];
826 myGroup->Remove(anIdList.inout());
828 /* init for next operation */
830 for (i = 0; i < total; i++) {
831 myIdList.append(myElements->item(i)->text().toInt());
835 mySMESHGUI->updateObjBrowser(true);
836 SMESH::UpdateView(); // asv: fix of BUG PAL5515
837 mySelectionMgr->clearSelected();
840 else if (myGrpTypeId == 1) { // on geom object
841 if (CORBA::is_nil(myGroupOnGeom)) { // creation
842 if (myMesh->_is_nil() || !myGeomObjects->length())
845 SMESH::ElementType aType = SMESH::ALL;
847 case 0: aType = SMESH::NODE; break;
848 case 1: aType = SMESH::EDGE; break;
849 case 2: aType = SMESH::FACE; break;
850 case 3: aType = SMESH::VOLUME; break;
853 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
854 GEOM::GEOM_IGroupOperations_var aGroupOp =
855 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
857 if (myGeomObjects->length() == 1) {
858 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
859 myName->text().toLatin1().data(),
863 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
864 if ( aSMESHGen->_is_nil() )
867 // create a geometry group
868 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
869 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
871 if (geomGen->_is_nil() || !aStudy)
874 GEOM::GEOM_IGroupOperations_var op =
875 geomGen->GetIGroupOperations(aStudy->StudyId());
879 // check and add all selected GEOM objects: they must be
880 // a sub-shapes of the main GEOM and must be of one type
881 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
882 for ( int i =0; i < myGeomObjects->length(); i++) {
883 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
885 aGroupType = aSubShapeType;
886 else if (aSubShapeType != aGroupType) {
887 aGroupType = TopAbs_SHAPE;
892 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
893 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
894 op->UnionList(aGroupVar, myGeomObjects);
897 // publish the GEOM group in study
898 QString aNewGeomGroupName ( "Auto_group_for_" );
899 aNewGeomGroupName += myName->text();
900 SALOMEDS::SObject_var aNewGroupSO =
901 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
902 aNewGeomGroupName.toLatin1().data(), aMeshShape);
905 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
906 myName->text().toLatin1().data(),
910 SALOMEDS::Color aColor = getGroupColor();
911 myGroupOnGeom->SetColor(aColor);
913 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
915 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
916 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
918 /* init for next operation */
919 myName->setText( "" );
920 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
923 myGroupOnGeom->SetName(myName->text().toLatin1().data());
925 SALOMEDS::Color aColor = getGroupColor();
926 myGroupOnGeom->SetColor(aColor);
928 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
929 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
930 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
933 mySMESHGUI->updateObjBrowser(true);
934 mySelectionMgr->clearSelected();
941 //=================================================================================
944 //=================================================================================
945 void SMESHGUI_GroupDlg::onOK()
951 //=================================================================================
952 // function : onListSelectionChanged()
953 // purpose : Called when selection in element list is changed
954 //=================================================================================
955 void SMESHGUI_GroupDlg::onListSelectionChanged()
957 // MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
958 if( myIsBusy || !myActor) return;
961 if (myCurrentLineEdit == 0) {
962 mySelectionMgr->clearSelected();
963 TColStd_MapOfInteger aIndexes;
964 QList<QListWidgetItem*> selItems = myElements->selectedItems();
965 QListWidgetItem* anItem;
966 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
967 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
969 aList.Append(myActor->getIO());
970 mySelectionMgr->setSelectedObjects(aList,false);
975 //=================================================================================
976 // function : onObjectSelectionChanged()
977 // purpose : Called when selection in 3D view or ObjectBrowser is changed
978 //=================================================================================
979 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
981 if ( myIsBusy || !isEnabled()) return;
982 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
987 mySelectionMgr->selectedObjects( aList );
989 int aNbSel = aList.Extent();
990 myElements->clearSelection();
992 if (myCurrentLineEdit)
994 myCurrentLineEdit->setText( "" );
995 QString aString = "";
997 if (myCurrentLineEdit == myMeshGroupLine)
999 mySelectSubMesh->setEnabled(false);
1000 mySelectGroup->setEnabled(false);
1001 myGroupLine->setText( "" );
1002 mySubMeshLine->setText( "" );
1004 myGeomGroupBtn->setEnabled(false);
1005 myGeomGroupLine->setEnabled(false);
1006 myGeomGroupLine->setText( "" );
1007 myGeomObjects = new GEOM::ListOfGO();
1008 myGeomObjects->length(0);
1010 if (myGeomGroupBtn->isChecked())
1011 myGeomGroupBtn->setChecked(false);
1013 myName->setText( "" );
1015 myElements->clear();
1018 myGroup = SMESH::SMESH_Group::_nil();
1019 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1020 restoreShowEntityMode();
1021 myMesh = SMESH::SMESH_Mesh::_nil();
1027 Handle(SALOME_InteractiveObject) IO = aList.First();
1030 restoreShowEntityMode();
1031 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1032 setShowEntityMode();
1034 if (myMesh->_is_nil())
1040 myGroup = SMESH::SMESH_Group::_nil();
1042 // NPAL19389: create a group with a selection in another group
1043 // set actor of myMesh, if it is visible, else try
1044 // any visible actor of group or submesh of myMesh
1045 SetAppropriateActor();
1047 aString = aList.First()->getName();
1048 myMeshGroupLine->setText(aString);
1049 myMeshGroupLine->home( false );
1051 mySelectSubMesh->setEnabled(true);
1052 mySelectGroup->setEnabled(true);
1053 myGeomGroupBtn->setEnabled(true);
1054 myGeomGroupLine->setEnabled(true);
1058 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1059 if (aGroup->_is_nil())
1065 myCurrentLineEdit = 0;
1067 myGroup = SMESH::SMESH_Group::_nil();
1068 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1072 mySelectSubMesh->setEnabled(true);
1073 mySelectGroup->setEnabled(true);
1075 myCurrentLineEdit = 0;
1080 if (myGrpTypeId == 0)
1086 myElements->clear();
1087 setSelectionMode(myTypeId);
1095 else if (myCurrentLineEdit == myGeomGroupLine)
1097 myGeomObjects = new GEOM::ListOfGO();
1100 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1102 if (aNbSel == 0 || !aMeshSO)
1104 myGeomObjects->length(0);
1110 myGeomObjects->length(aNbSel);
1112 GEOM::GEOM_Object_var aGeomGroup;
1113 Standard_Boolean testResult;
1116 SALOME_ListIteratorOfListIO anIt (aList);
1117 for (; anIt.More(); anIt.Next())
1119 testResult = Standard_False;
1120 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1122 // Check if the object is a geometry group
1123 if (!testResult || CORBA::is_nil(aGeomGroup))
1126 // Check if group constructed on the same shape as a mesh or on its child
1127 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1128 GEOM::GEOM_IGroupOperations_var anOp =
1129 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1131 // The main shape of the group
1132 GEOM::GEOM_Object_var aGroupMainShape;
1133 if (aGeomGroup->GetType() == 37)
1134 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1136 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1137 _PTR(SObject) aGroupMainShapeSO =
1138 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1139 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1141 _PTR(SObject) anObj, aRef;
1142 bool isRefOrSubShape = false;
1143 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1144 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1145 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1146 isRefOrSubShape = true;
1148 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1149 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1150 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1151 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1152 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1153 if (aRef->GetID() == aFather->GetID())
1154 isRefOrSubShape = true;
1156 aFather = aFather->GetFather();
1160 if (isRefOrSubShape)
1161 myGeomObjects[i++] = aGeomGroup;
1164 myGeomObjects->length(i);
1176 if (myCurrentLineEdit == mySubMeshLine)
1177 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1178 else if (myCurrentLineEdit == myGroupLine)
1179 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1180 else if (myCurrentLineEdit == myGeomGroupLine)
1181 aString = tr( "%1 Objects" ).arg(aNbSel);
1184 aString = aList.First()->getName();
1188 myCurrentLineEdit->setText(aString);
1189 myCurrentLineEdit->home(false);
1190 // 07.06.2008 skl for IPAL19574:
1191 // change name of group only if it is empty
1192 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1193 myOldName = myName->text();
1194 myName->blockSignals(true);
1195 myName->setText(aString);
1196 myName->blockSignals(false);
1201 else // !myCurrentLineEdit: local selection of nodes or elements
1203 if (aNbSel == 1 && myActor && myActor->hasIO())
1205 #ifdef ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
1206 // NPAL19389: create a group with a selection in another group
1207 // Switch myActor to the newly selected one, if the last
1208 // is visible and belongs to group or submesh of myMesh
1209 Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1210 Handle(SALOME_InteractiveObject) selIO = aList.First();
1211 if (curIO->hasEntry() && selIO->hasEntry()) {
1212 const char* selEntry = selIO->getEntry();
1213 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1214 // different objects: selected and myActor
1215 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1216 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1217 // newly selected actor is visible
1220 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1222 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1223 int len = strlen(meshEntry);
1225 if (strncmp(selEntry, meshEntry, len) == 0) {
1226 // selected object is myMesh or a part of it
1227 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1230 SMESH::SetPickable(myActor);
1238 #endif // ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
1240 QString aListStr = "";
1242 if (myTypeId == 0) {
1243 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1245 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1248 QListWidgetItem* anItem;
1249 QList<QListWidgetItem*> listItemsToSel;
1250 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1251 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1252 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1253 foreach(anItem, found)
1254 if (!anItem->isSelected())
1255 listItemsToSel.push_back(anItem);
1257 bool blocked = myElements->signalsBlocked();
1258 myElements->blockSignals(true);
1259 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1260 myElements->blockSignals(blocked);
1261 onListSelectionChanged();
1262 listItemsToSel.clear();
1268 if (!myGroup->_is_nil())
1269 myActor = SMESH::FindActorByObject(myGroup);
1270 else if(!myGroupOnGeom->_is_nil())
1271 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1273 myActor = SMESH::FindActorByObject(myMesh);
1276 // somehow, if we display the mesh, while selecting from another actor,
1277 // the mesh becomes pickable, and there is no way to select any element
1279 SMESH::SetPickable(myActor);
1284 //=================================================================================
1285 // function : onSelectSubMesh()
1286 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1287 //=================================================================================
1288 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1291 if (mySelectGroup->isChecked()) {
1292 mySelectGroup->setChecked(false);
1294 //VSR: else if (mySelectGeomGroup->isChecked()) {
1295 //VSR: mySelectGeomGroup->setChecked(false);
1297 myCurrentLineEdit = mySubMeshLine;
1298 setSelectionMode(4);
1301 mySubMeshLine->setText( "" );
1302 myCurrentLineEdit = 0;
1304 setSelectionMode(myTypeId);
1306 mySubMeshBtn->setEnabled(on);
1307 mySubMeshLine->setEnabled(on);
1311 //=================================================================================
1312 // function : (onSelectGroup)
1313 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1314 //=================================================================================
1315 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1318 if (mySelectSubMesh->isChecked()) {
1319 mySelectSubMesh->setChecked(false);
1321 myCurrentLineEdit = myGroupLine;
1322 setSelectionMode(5);
1325 myGroupLine->setText( "" );
1326 myCurrentLineEdit = 0;
1328 setSelectionMode(myTypeId);
1330 myGroupBtn->setEnabled(on);
1331 myGroupLine->setEnabled(on);
1335 //=================================================================================
1336 // function : (onSelectGeomGroup)
1337 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1338 //=================================================================================
1339 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1342 if (mySelectSubMesh->isChecked()) {
1343 mySelectSubMesh->setChecked(false);
1345 else if (mySelectGroup->isChecked()) {
1346 mySelectGroup->setChecked(false);
1348 myCurrentLineEdit = myGeomGroupLine;
1350 setSelectionMode(8);
1353 myGeomGroupBtn->setChecked(false);
1354 myGeomObjects->length(0);
1355 myGeomGroupLine->setText( "" );
1356 myCurrentLineEdit = 0;
1358 setSelectionMode(myTypeId);
1363 //=================================================================================
1364 // function : setCurrentSelection()
1366 //=================================================================================
1367 void SMESHGUI_GroupDlg::setCurrentSelection()
1369 QPushButton* send = (QPushButton*)sender();
1370 myCurrentLineEdit = 0;
1371 if (send == myMeshGroupBtn) {
1372 myCurrentLineEdit = myMeshGroupLine;
1374 setSelectionMode(6);
1376 setSelectionMode(5);
1377 onObjectSelectionChanged();
1379 else if (send == mySubMeshBtn) {
1380 myCurrentLineEdit = mySubMeshLine;
1381 onObjectSelectionChanged();
1383 else if (send == myGroupBtn) {
1384 myCurrentLineEdit = myGroupLine;
1385 onObjectSelectionChanged();
1390 //=================================================================================
1391 // function : setFilters()
1392 // purpose : SLOT. Called when "Filter" button pressed.
1393 //=================================================================================
1394 void SMESHGUI_GroupDlg::setFilters()
1396 SMESH::ElementType aType = SMESH::ALL;
1399 case 0 : aType = SMESH::NODE; break;
1400 case 1 : aType = SMESH::EDGE; break;
1401 case 2 : aType = SMESH::FACE; break;
1402 case 3 : aType = SMESH::VOLUME; break;
1406 if ( myFilterDlg == 0 )
1408 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1409 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1412 myFilterDlg->Init( aType );
1414 myFilterDlg->SetSelection();
1415 myFilterDlg->SetMesh( myMesh );
1416 myFilterDlg->SetSourceWg( myElements );
1418 myFilterDlg->show();
1421 //=================================================================================
1422 // function : onFilterAccepted()
1423 // purpose : SLOT. Called when Filter dlg closed with OK button.
1424 // Uncheck "Select submesh" and "Select group" checkboxes
1425 //=================================================================================
1426 void SMESHGUI_GroupDlg::onFilterAccepted()
1428 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1430 mySelectionMode = myTypeId;
1431 mySelectSubMesh->setChecked( false );
1432 mySelectGroup->setChecked( false );
1436 //=================================================================================
1437 // function : onAdd()
1439 //=================================================================================
1440 void SMESHGUI_GroupDlg::onAdd()
1442 SALOME_ListIO aList;
1443 mySelectionMgr->selectedObjects( aList );
1445 int aNbSel = aList.Extent();
1447 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1451 SMESH::ElementType aType = SMESH::ALL;
1454 aType = SMESH::NODE;
1455 mySelector->SetSelectionMode(NodeSelection);
1458 aType = SMESH::EDGE;
1459 mySelector->SetSelectionMode(EdgeSelection);
1462 aType = SMESH::FACE;
1463 mySelector->SetSelectionMode(FaceSelection);
1466 aType = SMESH::VOLUME;
1467 mySelector->SetSelectionMode(VolumeSelection);
1470 mySelector->SetSelectionMode(ActorSelection);
1473 QListWidgetItem* anItem = 0;
1474 QList<QListWidgetItem*> listItemsToSel;
1476 if (myCurrentLineEdit == 0) {
1477 //if (aNbSel != 1) { myIsBusy = false; return; }
1478 QString aListStr = "";
1480 if (myTypeId == 0) {
1481 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1484 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1487 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1488 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1489 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1490 if (found.count() == 0) {
1491 anItem = new QListWidgetItem(*it);
1492 myElements->addItem(anItem);
1493 if (!anItem->isSelected())
1494 listItemsToSel.push_back(anItem);
1497 foreach(anItem, found)
1498 if (!anItem->isSelected())
1499 listItemsToSel.push_back(anItem);
1502 bool blocked = myElements->signalsBlocked();
1503 myElements->blockSignals(true);
1504 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1505 myElements->blockSignals(blocked);
1506 onListSelectionChanged();
1507 listItemsToSel.clear();
1509 } else if (myCurrentLineEdit == mySubMeshLine) {
1510 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1512 SALOME_ListIO aList;
1513 mySelectionMgr->selectedObjects( aList );
1515 SALOME_ListIteratorOfListIO anIt (aList);
1516 for ( ; anIt.More(); anIt.Next()) {
1517 SMESH::SMESH_subMesh_var aSubMesh =
1518 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1519 if (!aSubMesh->_is_nil()) {
1520 // check if mesh is the same
1521 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1523 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1524 int k = anElements->length();
1525 for (int i = 0; i < k; i++) {
1526 QString aText = QString::number(anElements[i]);
1527 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1528 if (found.count() == 0) {
1529 anItem = new QListWidgetItem(aText);
1530 myElements->addItem(anItem);
1531 if (!anItem->isSelected())
1532 listItemsToSel.push_back(anItem);
1535 foreach(anItem, found)
1536 if (!anItem->isSelected())
1537 listItemsToSel.push_back(anItem);
1540 bool blocked = myElements->signalsBlocked();
1541 myElements->blockSignals(true);
1542 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1543 myElements->blockSignals(blocked);
1544 onListSelectionChanged();
1545 listItemsToSel.clear();
1547 catch (const SALOME::SALOME_Exception& ex) {
1548 SalomeApp_Tools::QtCatchCorbaException(ex);
1553 mySelectSubMesh->setChecked(false);
1555 onListSelectionChanged();
1557 } else if (myCurrentLineEdit == myGroupLine) {
1558 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1559 SALOME_ListIO aList;
1560 mySelectionMgr->selectedObjects( aList );
1562 SALOME_ListIteratorOfListIO anIt (aList);
1563 for ( ; anIt.More(); anIt.Next()) {
1564 SMESH::SMESH_GroupBase_var aGroup =
1565 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1566 if (!aGroup->_is_nil()) {
1567 // check if mesh is the same
1568 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1569 SMESH::long_array_var anElements = aGroup->GetListOfID();
1570 int k = anElements->length();
1571 for (int i = 0; i < k; i++) {
1572 QString aText = QString::number(anElements[i]);
1573 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1574 if (found.count() == 0) {
1575 anItem = new QListWidgetItem(aText);
1576 myElements->addItem(anItem);
1577 if (!anItem->isSelected())
1578 listItemsToSel.push_back(anItem);
1581 foreach(anItem, found)
1582 if (!anItem->isSelected())
1583 listItemsToSel.push_back(anItem);
1586 bool blocked = myElements->signalsBlocked();
1587 myElements->blockSignals(true);
1588 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1589 myElements->blockSignals(blocked);
1590 onListSelectionChanged();
1591 listItemsToSel.clear();
1595 mySelectGroup->setChecked(false);
1597 onListSelectionChanged();
1599 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1600 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1601 GEOM::GEOM_IGroupOperations_var aGroupOp =
1602 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1604 SMESH::ElementType aGroupType = SMESH::ALL;
1605 switch(aGroupOp->GetType(myGeomObjects[0])) {
1606 case 7: aGroupType = SMESH::NODE; break;
1607 case 6: aGroupType = SMESH::EDGE; break;
1608 case 4: aGroupType = SMESH::FACE; break;
1609 case 2: aGroupType = SMESH::VOLUME; break;
1610 default: myIsBusy = false; return;
1613 if (aGroupType == aType) {
1614 _PTR(SObject) aGroupSO =
1615 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1616 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1618 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1619 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1620 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1621 aBelongToGeom->SetGeom(myGeomObjects[0]);
1622 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1623 aBelongToGeom->SetElementType(aType);
1624 aFilter->SetPredicate(aBelongToGeom);
1626 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1628 int k = anElements->length();
1629 for (int i = 0; i < k; i++) {
1630 QString aText = QString::number(anElements[i]);
1631 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1632 if (found.count() == 0) {
1633 anItem = new QListWidgetItem(aText);
1634 myElements->addItem(anItem);
1635 if (!anItem->isSelected())
1636 listItemsToSel.push_back(anItem);
1639 foreach(anItem, found)
1640 if (!anItem->isSelected())
1641 listItemsToSel.push_back(anItem);
1644 bool blocked = myElements->signalsBlocked();
1645 myElements->blockSignals(true);
1646 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1647 myElements->blockSignals(blocked);
1648 onListSelectionChanged();
1649 listItemsToSel.clear();
1652 //VSR: mySelectGeomGroup->setChecked(false);
1654 onListSelectionChanged();
1657 // mySelectionMgr->clearSelected();
1661 //=================================================================================
1662 // function : onRemove()
1664 //=================================================================================
1665 void SMESHGUI_GroupDlg::onRemove()
1668 if (myCurrentLineEdit == 0) {
1669 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1670 QListWidgetItem* item;
1671 foreach(item, selItems) delete item;
1673 SALOME_ListIO aList;
1674 mySelectionMgr->selectedObjects( aList );
1676 int aNbSel = aList.Extent();
1678 if (aNbSel == 0) { myIsBusy = false; return; }
1680 SMESH::ElementType aType = SMESH::ALL;
1682 case 0: aType = SMESH::NODE; break;
1683 case 1: aType = SMESH::EDGE; break;
1684 case 2: aType = SMESH::FACE; break;
1685 case 3: aType = SMESH::VOLUME; break;
1688 if (myCurrentLineEdit == mySubMeshLine) {
1689 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1690 SALOME_ListIO aList;
1691 mySelectionMgr->selectedObjects( aList );
1693 SALOME_ListIteratorOfListIO anIt (aList);
1694 for ( ; anIt.More(); anIt.Next()) {
1695 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1696 if (!aSubMesh->_is_nil()) {
1697 // check if mesh is the same
1698 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1699 if (aType == SMESH::NODE) {
1701 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1702 int k = anElements->length();
1703 for (int i = 0; i < k; i++) {
1704 QList<QListWidgetItem*> found =
1705 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1706 QListWidgetItem* anItem;
1707 foreach(anItem, found) delete anItem;
1710 catch (const SALOME::SALOME_Exception& ex) {
1711 SalomeApp_Tools::QtCatchCorbaException(ex);
1716 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1717 int k = anElements->length();
1718 for (int i = 0; i < k; i++) {
1719 QList<QListWidgetItem*> found =
1720 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1721 QListWidgetItem* anItem;
1722 foreach(anItem, found) delete anItem;
1725 catch (const SALOME::SALOME_Exception& ex) {
1726 SalomeApp_Tools::QtCatchCorbaException(ex);
1733 else if (myCurrentLineEdit == myGroupLine) {
1734 Standard_Boolean aRes;
1735 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1736 SALOME_ListIO aList;
1737 mySelectionMgr->selectedObjects( aList );
1739 SALOME_ListIteratorOfListIO anIt (aList);
1740 for ( ; anIt.More(); anIt.Next()) {
1741 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1742 if (aRes && !aGroup->_is_nil()) {
1743 // check if mesh is the same
1744 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1745 SMESH::long_array_var anElements = aGroup->GetListOfID();
1746 int k = anElements->length();
1747 for (int i = 0; i < k; i++) {
1748 QList<QListWidgetItem*> found =
1749 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1750 QListWidgetItem* anItem;
1751 foreach(anItem, found) delete anItem;
1762 //=================================================================================
1763 // function : onSort()
1765 //=================================================================================
1766 void SMESHGUI_GroupDlg::onSort()
1768 // PAL5412: sorts items in ascending by "string" value
1769 // myElements->sort(true);
1770 // myElements->update();
1771 int i, k = myElements->count();
1774 QList<int> aSelected;
1775 std::vector<int> anArray(k);
1776 // QMemArray<int> anArray(k);
1778 for (i = 0; i < k; i++) {
1779 int id = myElements->item(i)->text().toInt();
1781 if (myElements->item(i)->isSelected())
1782 aSelected.append(id);
1784 // sort & update list
1785 std::sort(anArray.begin(), anArray.end());
1787 myElements->clear();
1788 QListWidgetItem* anItem;
1789 QList<QListWidgetItem*> listItemsToSel;
1790 for (i = 0; i < k; i++) {
1791 anItem = new QListWidgetItem(QString::number(anArray[i]));
1792 myElements->addItem(anItem);
1793 if (aSelected.contains(anArray[i]))
1794 listItemsToSel.push_back(anItem);
1796 bool blocked = myElements->signalsBlocked();
1797 myElements->blockSignals(true);
1798 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1799 myElements->blockSignals(blocked);
1800 listItemsToSel.clear();
1805 //=================================================================================
1806 // function : closeEvent()
1808 //=================================================================================
1809 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1814 //=================================================================================
1815 // function : SMESHGUI_GroupDlg::onClose
1816 // purpose : SLOT called when "Close" button pressed. Close dialog
1817 //=================================================================================
1818 void SMESHGUI_GroupDlg::onClose()
1820 if (SMESH::GetCurrentVtkView()) {
1821 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1822 SMESH::SetPointRepresentation(false);
1823 SMESH::SetPickable();
1824 restoreShowEntityMode();
1827 mySelectionMgr->clearSelected();
1828 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1829 aViewWindow->SetSelectionMode(ActorSelection);
1830 mySelectionMgr->clearFilters();
1831 mySMESHGUI->ResetState();
1836 //=================================================================================
1837 // function : onHelp()
1839 //=================================================================================
1840 void SMESHGUI_GroupDlg::onHelp()
1842 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1844 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1848 platform = "winapplication";
1850 platform = "application";
1852 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1853 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1854 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1856 arg(myHelpFileName));
1860 //=================================================================================
1861 // function : SMESHGUI_GroupDlg::onDeactivate
1862 // purpose : SLOT called when dialog must be deativated
1863 //=================================================================================
1864 void SMESHGUI_GroupDlg::onDeactivate()
1866 mySMESHGUI->ResetState();
1870 //=================================================================================
1871 // function : SMESHGUI_GroupDlg::enterEvent
1872 // purpose : Event filter
1873 //=================================================================================
1874 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1877 mySMESHGUI->EmitSignalDeactivateDialog();
1879 mySelectionMode = -1;
1880 setSelectionMode(myTypeId);
1881 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1882 mySMESHGUI->SetActiveDialogBox(this);
1883 mySMESHGUI->SetState(800);
1887 //=================================================================================
1888 // function : hideEvent
1889 // purpose : caused by ESC key
1890 //=================================================================================
1891 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1893 if (!isMinimized() && !myIsBusy)
1897 //=================================================================================
1898 // function : keyPressEvent()
1900 //=================================================================================
1901 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1903 QDialog::keyPressEvent( e );
1904 if ( e->isAccepted() )
1907 if ( e->key() == Qt::Key_F1 )
1914 //================================================================================
1916 * \brief Enable showing of the popup when Geometry selection btn is clicked
1917 * \param enable - true to enable
1919 //================================================================================
1921 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1923 void SMESHGUI_GroupDlg::updateGeomPopup()
1925 bool enable = false;
1927 if ( !myMesh->_is_nil() )
1928 enable = myMesh->NbEdges() > 0;
1930 if ( myGeomGroupBtn )
1932 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1934 if ( !myGeomPopup ) {
1935 myGeomPopup = new QMenu(this);
1936 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
1937 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
1938 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
1940 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1946 //=================================================================================
1947 // function : onGeomSelectionButton()
1949 //=================================================================================
1950 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1952 if ( myGeomPopup && isBtnOn )
1954 myCurrentLineEdit = myGeomGroupLine;
1955 QAction* a = myGeomPopup->exec( QCursor::pos() );
1956 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
1957 setSelectionMode(7);
1961 myCurrentLineEdit = 0;
1962 setSelectionMode(8);
1966 //=================================================================================
1967 // function : onGeomPopup()
1969 //=================================================================================
1970 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
1972 int index = myActions[a];
1973 if ( index == GEOM_BY_MESH_INDEX )
1975 mySelectionMode = -1;
1976 if ( !myShapeByMeshOp ) {
1977 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1978 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1979 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1980 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1981 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1983 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1984 if ( !myMesh->_is_nil() ) {
1986 hide(); // stop processing selection
1988 myShapeByMeshOp->setModule( mySMESHGUI );
1989 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1990 myShapeByMeshOp->SetMesh( myMesh );
1991 myShapeByMeshOp->start();
1996 //================================================================================
1998 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2000 //================================================================================
2002 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2004 if ( myShapeByMeshOp == op ) {
2005 mySMESHGUI->getApp()->updateObjectBrowser();
2007 // Select a found geometry object
2008 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2009 if ( !aGeomVar->_is_nil() )
2011 QString ID = aGeomVar->GetStudyEntry();
2012 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2013 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2014 SALOME_ListIO anIOList;
2015 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2016 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2017 anIOList.Append( anIO );
2018 mySelectionMgr->setSelectedObjects( anIOList, false );
2019 onObjectSelectionChanged();
2025 //================================================================================
2027 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2029 //================================================================================
2031 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2033 if ( myShapeByMeshOp == op )
2036 setSelectionMode(7);
2040 //=================================================================================
2041 // function : setGroupColor()
2043 //=================================================================================
2044 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2046 QColor aQColor( (int)( theColor.R * 255.0 ),
2047 (int)( theColor.G * 255.0 ),
2048 (int)( theColor.B * 255.0 ) );
2049 setGroupQColor( aQColor );
2052 //=================================================================================
2053 // function : getGroupColor()
2055 //=================================================================================
2056 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2058 QColor aQColor = getGroupQColor();
2060 SALOMEDS::Color aColor;
2061 aColor.R = (float)aQColor.red() / 255.0;
2062 aColor.G = (float)aQColor.green() / 255.0;
2063 aColor.B = (float)aQColor.blue() / 255.0;
2068 //=================================================================================
2069 // function : setGroupQColor()
2071 //=================================================================================
2072 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2074 if( theColor.isValid() )
2075 myColorBtn->setColor( theColor );
2078 //=================================================================================
2079 // function : getGroupQColor()
2081 //=================================================================================
2082 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2084 return myColorBtn->color();
2087 //=================================================================================
2088 // function : setDefaultGroupColor()
2090 //=================================================================================
2091 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2093 if( myMesh->_is_nil() )
2096 bool isAutoColor = myMesh->GetAutoColor();
2101 int r = 0, g = 0, b = 0;
2102 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2103 aQColor.setRgb( r, g, b );
2107 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2109 QList<SALOMEDS::Color> aReservedColors;
2110 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2112 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2113 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2114 aReservedColors.append( aReservedColor );
2117 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2118 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2119 (int)( aColor.G * 255.0 ),
2120 (int)( aColor.B * 255.0 ) );
2124 setGroupQColor( aQColor );
2127 //=================================================================================
2128 // function : SetAppropriateActor()
2129 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2130 // NPAL19389: create a group with a selection in another group.
2131 // if mesh actor is not visible - find any first visible group or submesh
2132 //=================================================================================
2133 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2135 bool isActor = false;
2137 if (myMesh->_is_nil()) return false;
2139 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2142 myActor = SMESH::FindActorByObject(myMesh);
2143 if (myActor && myActor->hasIO())
2146 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2150 // try current group actor
2152 if (!myGroup->_is_nil()) {
2153 myActor = SMESH::FindActorByObject(myGroup);
2154 if (myActor && myActor->hasIO())
2157 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2163 // try current group on geometry actor
2165 if (!myGroupOnGeom->_is_nil()) {
2166 myActor = SMESH::FindActorByObject(myGroupOnGeom);
2167 if (myActor && myActor->hasIO())
2170 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2176 // try any visible actor of group or submesh of current mesh
2177 if (!isActor && aViewWindow) {
2179 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2181 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2182 int len = strlen(meshEntry);
2184 // iterate on all actors in current view window, search for
2185 // any visible actor, that belongs to group or submesh of current mesh
2186 vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
2187 aCollection->InitTraversal();
2188 for (vtkActor *anAct = aCollection->GetNextActor();
2190 anAct = aCollection->GetNextActor())
2192 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct);
2193 if (anActor && anActor->hasIO()) {
2194 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2195 if (aViewWindow->isVisible(anIO)) {
2196 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0) {
2207 SMESH::SetPickable(myActor);
2212 //=======================================================================
2213 //function : setShowEntityMode
2214 //purpose : make shown only entity corresponding to my type
2215 //=======================================================================
2216 void SMESHGUI_GroupDlg::setShowEntityMode()
2218 if ( !myMesh->_is_nil() ) {
2219 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2220 if (!myStoredShownEntity)
2221 myStoredShownEntity = actor->GetEntityMode();
2222 switch ( myTypeId ) {
2223 case 0: restoreShowEntityMode(); break;
2224 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2225 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2226 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2232 //=======================================================================
2233 //function : restoreShowEntityMode
2234 //purpose : restore ShowEntity mode of myActor
2235 //=======================================================================
2236 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2238 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2239 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2240 actor->SetEntityMode(myStoredShownEntity);
2243 myStoredShownEntity = 0;