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 const bool theIsConvert )
132 : QDialog( SMESH::GetDesktop( theModule ) ),
133 mySMESHGUI( theModule ),
134 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
135 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
137 myNameChanged( false )
140 if ( !theGroup->_is_nil() )
141 init( theGroup, theIsConvert );
144 mySelectSubMesh->setEnabled( false );
145 mySelectGroup->setEnabled( false );
147 myCurrentLineEdit = myMeshGroupLine;
148 setSelectionMode( 5 );
152 //=================================================================================
153 // function : SMESHGUI_GroupDlg()
155 //=================================================================================
156 void SMESHGUI_GroupDlg::initDialog( bool create)
159 setAttribute( Qt::WA_DeleteOnClose, true );
163 myCurrentLineEdit = 0;
167 myGeomObjects = new GEOM::ListOfGO();
168 myGeomObjects->length( 0 );
170 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
172 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
173 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
175 setSizeGripEnabled( true);
177 QGridLayout* aMainLayout = new QGridLayout( this );
178 aMainLayout->setMargin( MARGIN );
179 aMainLayout->setSpacing( SPACING );
181 /***************************************************************/
182 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
183 myMeshGroupBtn = new QPushButton( this );
184 myMeshGroupBtn->setIcon( image0 );
185 myMeshGroupLine = new QLineEdit( this );
186 myMeshGroupLine->setReadOnly( true );
188 /***************************************************************/
189 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
190 myTypeGroup = new QButtonGroup( this );
191 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
192 aTypeBoxLayout->setMargin( MARGIN );
193 aTypeBoxLayout->setSpacing( SPACING );
196 types.append( tr( "MESH_NODE" ) );
197 types.append( tr( "SMESH_EDGE" ) );
198 types.append( tr( "SMESH_FACE" ) );
199 types.append( tr( "SMESH_VOLUME" ) );
201 for ( int i = 0; i < types.count(); i++ )
203 rb = new QRadioButton( types[i], aTypeBox );
204 myTypeGroup->addButton( rb, i );
205 aTypeBoxLayout->addWidget( rb );
207 aTypeBox->setEnabled( create );
210 /***************************************************************/
211 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
212 aName->setMinimumWidth( 50 );
213 myName = new QLineEdit( this );
215 /***************************************************************/
216 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
217 myGrpTypeGroup = new QButtonGroup( this );
218 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
219 aGrpTypeBoxLayout->setMargin( MARGIN );
220 aGrpTypeBoxLayout->setSpacing( SPACING );
222 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
223 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
224 myGrpTypeGroup->addButton( rb1, 0 );
225 myGrpTypeGroup->addButton( rb2, 1 );
226 aGrpTypeBoxLayout->addWidget( rb1 );
227 aGrpTypeBoxLayout->addWidget( rb2 );
228 aGrpTypeBox->setEnabled( create );
231 /***************************************************************/
232 myWGStack = new QStackedWidget( this );
233 QWidget* wg1 = new QWidget( myWGStack );
234 QWidget* wg2 = new QWidget( myWGStack );
236 /***************************************************************/
237 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
238 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
239 aContentBoxLayout->setMargin( MARGIN );
240 aContentBoxLayout->setSpacing( SPACING );
242 QLabel* aLabel = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
243 myElements = new QListWidget( aContentBox );
244 myElements->setSelectionMode( QListWidget::ExtendedSelection );
246 myFilter = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
247 QPushButton* aAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
248 QPushButton* aRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
249 QPushButton* aSortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
251 aContentBoxLayout->addWidget( aLabel, 0, 0 );
252 aContentBoxLayout->addWidget( myElements, 1, 0, 6, 1 );
253 aContentBoxLayout->addWidget( myFilter, 1, 1 );
254 aContentBoxLayout->addWidget( aAddBtn, 3, 1 );
255 aContentBoxLayout->addWidget( aRemoveBtn, 4, 1 );
256 aContentBoxLayout->addWidget( aSortBtn, 6, 1 );
258 aContentBoxLayout->setColumnStretch( 0, 1 );
259 aContentBoxLayout->setRowStretch( 2, 1 );
260 aContentBoxLayout->setRowStretch( 5, 1 );
262 /***************************************************************/
263 QGroupBox* aSelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
264 QGridLayout* aSelectBoxLayout = new QGridLayout( aSelectBox );
265 aSelectBoxLayout->setMargin( MARGIN );
266 aSelectBoxLayout->setSpacing( SPACING );
268 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), aSelectBox );
269 mySubMeshBtn = new QPushButton( aSelectBox );
270 mySubMeshBtn->setIcon( image0 );
271 mySubMeshLine = new QLineEdit( aSelectBox );
272 mySubMeshLine->setReadOnly( true );
273 onSelectSubMesh( false );
275 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), aSelectBox );
276 myGroupBtn = new QPushButton( aSelectBox );
277 myGroupBtn->setIcon( image0 );
278 myGroupLine = new QLineEdit( aSelectBox );
279 myGroupLine->setReadOnly( true );
280 onSelectGroup( false );
282 aSelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
283 aSelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
284 aSelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
285 aSelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
286 aSelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
287 aSelectBoxLayout->addWidget( myGroupLine, 1, 2 );
289 /***************************************************************/
290 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
291 wg1Layout->setMargin( 0 );
292 wg1Layout->setSpacing( SPACING );
293 wg1Layout->addWidget( aContentBox );
294 wg1Layout->addWidget( aSelectBox );
295 wg1Layout->setStretchFactor( aContentBox, 10 );
297 /***************************************************************/
298 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
299 myGeomGroupBtn = new QToolButton( wg2 );
300 myGeomGroupBtn->setIcon( image0 );
301 myGeomGroupBtn->setCheckable( true );
302 myGeomGroupLine = new QLineEdit( wg2 );
303 myGeomGroupLine->setReadOnly( true ); //VSR ???
304 onSelectGeomGroup( false );
306 myGeomGroupBtn->setEnabled( create );
307 myGeomGroupLine->setEnabled( create );
309 /***************************************************************/
310 QGridLayout* wg2Layout = new QGridLayout( wg2 );
311 wg2Layout->setMargin( 0 );
312 wg1Layout->setSpacing( SPACING );
313 wg2Layout->addWidget( geomObject, 0, 0 );
314 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
315 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
316 wg2Layout->setRowStretch( 1, 5 );
318 /***************************************************************/
319 myWGStack->insertWidget( 0, wg1 );
320 myWGStack->insertWidget( 1, wg2 );
322 /***************************************************************/
323 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
324 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
325 aColorBoxLayout->setMargin(MARGIN);
326 aColorBoxLayout->setSpacing(SPACING);
328 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
329 myColorBtn = new QtxColorButton(aColorBox);
330 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
331 myColorBtn->sizePolicy().verticalPolicy() );
333 aColorBoxLayout->addWidget(aColorLab);
334 aColorBoxLayout->addWidget(myColorBtn);
336 /***************************************************************/
338 QFrame* aButtons = new QFrame(this);
339 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
340 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
341 aBtnLayout->setMargin(MARGIN);
342 aBtnLayout->setSpacing(SPACING);
344 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
345 myOKBtn->setAutoDefault(true);
346 myOKBtn->setDefault(true);
347 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
348 myApplyBtn->setAutoDefault(true);
349 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
350 myCloseBtn->setAutoDefault(true);
351 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
352 myHelpBtn->setAutoDefault(true);
354 aBtnLayout->addWidget(myOKBtn);
355 aBtnLayout->addSpacing(10);
356 aBtnLayout->addWidget(myApplyBtn);
357 aBtnLayout->addSpacing(10);
358 aBtnLayout->addStretch();
359 aBtnLayout->addWidget(myCloseBtn);
360 aBtnLayout->addWidget(myHelpBtn);
362 /***************************************************************/
363 aMainLayout->addWidget(meshGroupLab, 0, 0);
364 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
365 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
366 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
367 aMainLayout->addWidget(aName, 2, 0);
368 aMainLayout->addWidget(myName, 2, 2);
369 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
370 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
371 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
372 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
374 /* signals and slots connections */
375 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
376 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
377 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
379 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
380 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
382 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
383 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
384 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
385 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
387 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
388 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
389 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
390 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
391 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
393 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
395 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
396 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
397 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
398 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
401 mySMESHGUI->SetActiveDialogBox(this);
402 mySMESHGUI->SetState(800);
404 mySelectionMode = -1;
405 myMeshFilter = new SMESH_TypeFilter(MESH);
406 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
407 myGroupFilter = new SMESH_TypeFilter(GROUP);
408 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
409 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
411 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
412 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
413 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
415 rb1->setChecked(true); // VSR !!!
416 onGrpTypeChanged(0); // VSR!!!
418 if (myMesh->_is_nil() )
419 myTypeGroup->button(0)->setChecked(true);
422 //myName->setText(GetDefaultName(tr( "SMESH_GROUP" )));
425 //=================================================================================
426 // function : ~SMESHGUI_GroupDlg()
427 // purpose : Destroys the object and frees any allocated resources
428 //=================================================================================
429 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
431 // no need to delete child widgets, Qt does it all for us
432 if ( myFilterDlg != 0 ) {
433 myFilterDlg->setParent( 0 );
438 //=================================================================================
439 // function : GetDefaultName()
440 // purpose : Get the Group Name if Create new Group
441 //=================================================================================
442 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
446 // collect all object names of SMESH component
447 SalomeApp_Study* appStudy =
448 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
449 if ( !appStudy ) return aName;
450 _PTR(Study) aStudy = appStudy->studyDS();
452 std::set<std::string> aSet;
453 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
455 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
457 for (it->InitEx(true); it->More(); it->Next()) {
459 aSet.insert(obj->GetName());
463 // build a unique name
465 bool isUnique = false;
467 aName = theOperation + "_" + QString::number(++aNumber);
468 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
474 //=================================================================================
477 //=================================================================================
478 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
480 mySelectionMgr->installFilter(myMeshFilter);
482 /* init data from current selection */
483 restoreShowEntityMode();
484 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
486 myGroup = SMESH::SMESH_Group::_nil();
487 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
489 // NPAL19389: create a group with a selection in another group
490 // set actor of myMesh, if it is visible, else try
491 // any visible actor of group or submesh of myMesh
492 SetAppropriateActor();
494 setDefaultGroupColor();
497 mySelectionMgr->selectedObjects( aList );
498 if( !aList.IsEmpty() )
500 QString aName = aList.First()->getName();
501 myMeshGroupLine->setText(aName);
502 myMeshGroupLine->home( false );
505 myCurrentLineEdit = 0;
507 myTypeGroup->button(0)->setChecked(true);
511 //=================================================================================
514 //=================================================================================
515 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
516 const bool theIsConvert)
518 restoreShowEntityMode();
519 myMesh = theGroup->GetMesh();
522 myNameChanged = true;
523 myName->blockSignals(true);
524 myName->setText(theGroup->GetName());
525 myName->blockSignals(false);
528 SALOMEDS::Color aColor = theGroup->GetColor();
529 setGroupColor( aColor );
531 myMeshGroupLine->setText(theGroup->GetName());
534 switch(theGroup->GetType()) {
535 case SMESH::NODE: aType= 0; break;
536 case SMESH::EDGE: aType = 1; break;
537 case SMESH::FACE: aType = 2; break;
538 case SMESH::VOLUME: aType = 3; break;
540 myTypeGroup->button(aType)->setChecked(true);
542 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
543 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
545 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil())
548 // NPAL19389: create a group with a selection in another group
549 // set actor of myMesh, if it is visible, else set
550 // actor of theGroup, if it is visible, else try
551 // any visible actor of group or submesh of myMesh
552 // commented, because an attempt to set selection on not displayed cells leads to error
553 //SetAppropriateActor();
554 myActor = SMESH::FindActorByObject(myMesh);
556 myActor = SMESH::FindActorByObject(theGroup);
557 SMESH::SetPickable(myActor);
559 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : 1));
560 myGrpTypeGroup->button(grpType)->setChecked(true);
561 onGrpTypeChanged(grpType);
563 if ( grpType == 0 ) {
564 myCurrentLineEdit = 0;
566 setSelectionMode(aType);
569 setShowEntityMode(); // depends on myTypeId
572 if (!theGroup->IsEmpty()) {
573 SMESH::long_array_var anElements = theGroup->GetListOfID();
574 int k = anElements->length();
575 for (int i = 0; i < k; i++) {
576 myIdList.append(anElements[i]);
577 myElements->addItem(QString::number(anElements[i]));
579 myElements->selectAll();
584 QString aShapeName( "" );
585 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
586 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
587 if (!aGroupShape->_is_nil())
589 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
590 aShapeName = aGroupShapeSO->GetName().c_str();
592 myGeomGroupLine->setText( aShapeName );
593 myNameChanged = true;
594 myName->blockSignals(true);
595 myName->setText( "Group On " + aShapeName);
596 myName->blockSignals(false);
601 //=================================================================================
602 // function : updateButtons()
604 //=================================================================================
605 void SMESHGUI_GroupDlg::updateButtons()
607 bool enable = !myName->text().trimmed().isEmpty();
609 if (myGrpTypeId == 0) {
610 enable = enable && myElements->count() > 0;
611 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
613 else if (myGrpTypeId == 1) {
614 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
615 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
619 myOKBtn->setEnabled(enable);
620 myApplyBtn->setEnabled(enable);
623 //=================================================================================
624 // function : onNameChanged()
626 //=================================================================================
627 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
629 myOldName = myName->text();
631 myNameChanged = !myName->text().trimmed().isEmpty();
634 //=================================================================================
635 // function : onTypeChanged()
636 // purpose : Group elements type radio button management
637 //=================================================================================
638 void SMESHGUI_GroupDlg::onTypeChanged (int id)
640 if (myTypeId != id) {
642 if (myCurrentLineEdit == 0)
643 setSelectionMode(id);
649 //=================================================================================
650 // function : onGrpTypeChanged()
651 // purpose : Group type radio button management
652 //=================================================================================
653 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
655 if (myGrpTypeId != id) {
656 myWGStack->setCurrentIndex( id );
657 myName->blockSignals(true);
658 myName->setText(myOldName);
659 myName->blockSignals(false);
660 onSelectGeomGroup(id == 1);
665 //=================================================================================
666 // function : onColorChanged()
667 // purpose : Color button management
668 //=================================================================================
669 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
674 //=================================================================================
675 // function : setSelectionMode()
676 // purpose : Radio button management
677 //=================================================================================
678 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
681 if (myMesh->_is_nil())
683 if (mySelectionMode != theMode) {
684 // [PAL10408] mySelectionMgr->clearSelected();
685 mySelectionMgr->clearFilters();
687 myActor->SetPointRepresentation(false);
689 SMESH::SetPointRepresentation(false);
694 myActor->SetPointRepresentation(true);
696 SMESH::SetPointRepresentation(true);
697 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
698 aViewWindow->SetSelectionMode(NodeSelection);
701 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
702 aViewWindow->SetSelectionMode(EdgeSelection);
705 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
706 aViewWindow->SetSelectionMode(FaceSelection);
709 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
710 aViewWindow->SetSelectionMode(VolumeSelection);
714 mySelectionMgr->installFilter(mySubMeshFilter);
715 else if (theMode == 5)
716 mySelectionMgr->installFilter(myGroupFilter);
717 else if (theMode == 6)
718 mySelectionMgr->installFilter(myMeshFilter);
719 else if (theMode == 7)
720 mySelectionMgr->installFilter(myGeomFilter);
722 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
723 aViewWindow->SetSelectionMode(ActorSelection);
725 mySelectionMode = theMode;
729 //=================================================================================
730 // function : onApply()
732 //=================================================================================
733 bool SMESHGUI_GroupDlg::onApply()
735 if (mySMESHGUI->isActiveStudyLocked())
738 if (myName->text().trimmed().isEmpty())
741 if (myGrpTypeId == 0) { // on mesh elements
742 if (!myElements->count())
745 mySelectionMgr->clearSelected();
747 if (myGroup->_is_nil()) { // creation or conversion
748 // check if group on geometry is not null
749 if (!CORBA::is_nil(myGroupOnGeom)) {
750 if (myMesh->_is_nil())
752 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
753 // nullify pointer, because object become dead
754 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
758 if (myGroup->_is_nil()) { // creation
759 if (myMesh->_is_nil())
762 SMESH::ElementType aType = SMESH::ALL;
764 case 0: aType = SMESH::NODE; break;
765 case 1: aType = SMESH::EDGE; break;
766 case 2: aType = SMESH::FACE; break;
767 case 3: aType = SMESH::VOLUME; break;
770 SMESH::long_array_var anIdList = new SMESH::long_array;
771 int i, k = myElements->count();
773 for (i = 0; i < k; i++) {
774 anIdList[i] = myElements->item(i)->text().toInt();
777 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
778 myGroup->Add(anIdList.inout());
780 SALOMEDS::Color aColor = getGroupColor();
781 myGroup->SetColor(aColor);
783 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
785 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
786 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
788 /* init for next operation */
789 myName->setText( "" );
791 myGroup = SMESH::SMESH_Group::_nil();
794 myGroup->SetName(myName->text().toLatin1().data());
796 SALOMEDS::Color aColor = getGroupColor();
797 myGroup->SetColor(aColor);
799 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
800 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
801 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
805 int i, total = myElements->count();
806 for (i = 0; i < total; i++) {
807 int anId = myElements->item(i)->text().toInt();
808 int idx = myIdList.indexOf(anId);
810 aAddList.append(anId);
812 myIdList.removeAt(idx);
814 if (!aAddList.empty()) {
815 SMESH::long_array_var anIdList = new SMESH::long_array;
816 int added = aAddList.count();
817 anIdList->length(added);
818 for (i = 0; i < added; i++)
819 anIdList[i] = aAddList[i];
820 myGroup->Add(anIdList.inout());
822 if (!myIdList.empty()) {
823 SMESH::long_array_var anIdList = new SMESH::long_array;
824 int removed = myIdList.count();
825 anIdList->length(removed);
826 for (i = 0; i < removed; i++)
827 anIdList[i] = myIdList[i];
828 myGroup->Remove(anIdList.inout());
830 /* init for next operation */
832 for (i = 0; i < total; i++) {
833 myIdList.append(myElements->item(i)->text().toInt());
837 mySMESHGUI->updateObjBrowser(true);
838 SMESH::UpdateView(); // asv: fix of BUG PAL5515
839 mySelectionMgr->clearSelected();
842 else if (myGrpTypeId == 1) { // on geom object
843 if (CORBA::is_nil(myGroupOnGeom)) { // creation
844 if (myMesh->_is_nil() || !myGeomObjects->length())
847 SMESH::ElementType aType = SMESH::ALL;
849 case 0: aType = SMESH::NODE; break;
850 case 1: aType = SMESH::EDGE; break;
851 case 2: aType = SMESH::FACE; break;
852 case 3: aType = SMESH::VOLUME; break;
855 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
856 GEOM::GEOM_IGroupOperations_var aGroupOp =
857 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
859 if (myGeomObjects->length() == 1) {
860 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
861 myName->text().toLatin1().data(),
865 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
866 if ( aSMESHGen->_is_nil() )
869 // create a geometry group
870 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
871 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
873 if (geomGen->_is_nil() || !aStudy)
876 GEOM::GEOM_IGroupOperations_var op =
877 geomGen->GetIGroupOperations(aStudy->StudyId());
881 // check and add all selected GEOM objects: they must be
882 // a sub-shapes of the main GEOM and must be of one type
883 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
884 for ( int i =0; i < myGeomObjects->length(); i++) {
885 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
887 aGroupType = aSubShapeType;
888 else if (aSubShapeType != aGroupType) {
889 aGroupType = TopAbs_SHAPE;
894 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
895 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
896 op->UnionList(aGroupVar, myGeomObjects);
899 // publish the GEOM group in study
900 QString aNewGeomGroupName ( "Auto_group_for_" );
901 aNewGeomGroupName += myName->text();
902 SALOMEDS::SObject_var aNewGroupSO =
903 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
904 aNewGeomGroupName.toLatin1().data(), aMeshShape);
907 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
908 myName->text().toLatin1().data(),
912 SALOMEDS::Color aColor = getGroupColor();
913 myGroupOnGeom->SetColor(aColor);
915 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
917 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
918 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
920 /* init for next operation */
921 myName->setText( "" );
922 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
925 myGroupOnGeom->SetName(myName->text().toLatin1().data());
927 SALOMEDS::Color aColor = getGroupColor();
928 myGroupOnGeom->SetColor(aColor);
930 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
931 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
932 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
935 mySMESHGUI->updateObjBrowser(true);
936 mySelectionMgr->clearSelected();
943 //=================================================================================
946 //=================================================================================
947 void SMESHGUI_GroupDlg::onOK()
953 //=================================================================================
954 // function : onListSelectionChanged()
955 // purpose : Called when selection in element list is changed
956 //=================================================================================
957 void SMESHGUI_GroupDlg::onListSelectionChanged()
959 // MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
960 if( myIsBusy || !myActor) return;
963 if (myCurrentLineEdit == 0) {
964 mySelectionMgr->clearSelected();
965 TColStd_MapOfInteger aIndexes;
966 QList<QListWidgetItem*> selItems = myElements->selectedItems();
967 QListWidgetItem* anItem;
968 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
969 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
971 aList.Append(myActor->getIO());
972 mySelectionMgr->setSelectedObjects(aList,false);
977 //=================================================================================
978 // function : onObjectSelectionChanged()
979 // purpose : Called when selection in 3D view or ObjectBrowser is changed
980 //=================================================================================
981 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
983 if ( myIsBusy || !isEnabled()) return;
984 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
989 mySelectionMgr->selectedObjects( aList );
991 int aNbSel = aList.Extent();
992 myElements->clearSelection();
994 if (myCurrentLineEdit)
996 myCurrentLineEdit->setText( "" );
997 QString aString = "";
999 if (myCurrentLineEdit == myMeshGroupLine)
1001 mySelectSubMesh->setEnabled(false);
1002 mySelectGroup->setEnabled(false);
1003 myGroupLine->setText( "" );
1004 mySubMeshLine->setText( "" );
1006 myGeomGroupBtn->setEnabled(false);
1007 myGeomGroupLine->setEnabled(false);
1008 myGeomGroupLine->setText( "" );
1009 myGeomObjects = new GEOM::ListOfGO();
1010 myGeomObjects->length(0);
1012 if (myGeomGroupBtn->isChecked())
1013 myGeomGroupBtn->setChecked(false);
1015 myName->setText( "" );
1017 myElements->clear();
1020 myGroup = SMESH::SMESH_Group::_nil();
1021 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1022 restoreShowEntityMode();
1023 myMesh = SMESH::SMESH_Mesh::_nil();
1029 Handle(SALOME_InteractiveObject) IO = aList.First();
1032 restoreShowEntityMode();
1033 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1034 setShowEntityMode();
1036 if (myMesh->_is_nil())
1042 myGroup = SMESH::SMESH_Group::_nil();
1044 // NPAL19389: create a group with a selection in another group
1045 // set actor of myMesh, if it is visible, else try
1046 // any visible actor of group or submesh of myMesh
1047 SetAppropriateActor();
1049 aString = aList.First()->getName();
1050 myMeshGroupLine->setText(aString);
1051 myMeshGroupLine->home( false );
1053 mySelectSubMesh->setEnabled(true);
1054 mySelectGroup->setEnabled(true);
1055 myGeomGroupBtn->setEnabled(true);
1056 myGeomGroupLine->setEnabled(true);
1060 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1061 if (aGroup->_is_nil())
1067 myCurrentLineEdit = 0;
1069 myGroup = SMESH::SMESH_Group::_nil();
1070 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1074 mySelectSubMesh->setEnabled(true);
1075 mySelectGroup->setEnabled(true);
1077 myCurrentLineEdit = 0;
1082 if (myGrpTypeId == 0)
1088 myElements->clear();
1089 setSelectionMode(myTypeId);
1097 else if (myCurrentLineEdit == myGeomGroupLine)
1099 myGeomObjects = new GEOM::ListOfGO();
1102 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1104 if (aNbSel == 0 || !aMeshSO)
1106 myGeomObjects->length(0);
1112 myGeomObjects->length(aNbSel);
1114 GEOM::GEOM_Object_var aGeomGroup;
1115 Standard_Boolean testResult;
1118 SALOME_ListIteratorOfListIO anIt (aList);
1119 for (; anIt.More(); anIt.Next())
1121 testResult = Standard_False;
1122 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1124 // Check if the object is a geometry group
1125 if (!testResult || CORBA::is_nil(aGeomGroup))
1128 // Check if group constructed on the same shape as a mesh or on its child
1129 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1130 GEOM::GEOM_IGroupOperations_var anOp =
1131 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1133 // The main shape of the group
1134 GEOM::GEOM_Object_var aGroupMainShape;
1135 if (aGeomGroup->GetType() == 37)
1136 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1138 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1139 _PTR(SObject) aGroupMainShapeSO =
1140 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1141 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1143 _PTR(SObject) anObj, aRef;
1144 bool isRefOrSubShape = false;
1145 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1146 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1147 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1148 isRefOrSubShape = true;
1150 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1151 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1152 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1153 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1154 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1155 if (aRef->GetID() == aFather->GetID())
1156 isRefOrSubShape = true;
1158 aFather = aFather->GetFather();
1162 if (isRefOrSubShape)
1163 myGeomObjects[i++] = aGeomGroup;
1166 myGeomObjects->length(i);
1178 if (myCurrentLineEdit == mySubMeshLine)
1179 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1180 else if (myCurrentLineEdit == myGroupLine)
1181 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1182 else if (myCurrentLineEdit == myGeomGroupLine)
1183 aString = tr( "%1 Objects" ).arg(aNbSel);
1186 aString = aList.First()->getName();
1190 myCurrentLineEdit->setText(aString);
1191 myCurrentLineEdit->home(false);
1192 // 07.06.2008 skl for IPAL19574:
1193 // change name of group only if it is empty
1194 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1195 myOldName = myName->text();
1196 myName->blockSignals(true);
1197 myName->setText(aString);
1198 myName->blockSignals(false);
1203 else // !myCurrentLineEdit: local selection of nodes or elements
1205 if (aNbSel == 1 && myActor && myActor->hasIO())
1207 #ifdef ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
1208 // NPAL19389: create a group with a selection in another group
1209 // Switch myActor to the newly selected one, if the last
1210 // is visible and belongs to group or submesh of myMesh
1211 Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1212 Handle(SALOME_InteractiveObject) selIO = aList.First();
1213 if (curIO->hasEntry() && selIO->hasEntry()) {
1214 const char* selEntry = selIO->getEntry();
1215 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1216 // different objects: selected and myActor
1217 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1218 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1219 // newly selected actor is visible
1222 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1224 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1225 int len = strlen(meshEntry);
1227 if (strncmp(selEntry, meshEntry, len) == 0) {
1228 // selected object is myMesh or a part of it
1229 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1232 SMESH::SetPickable(myActor);
1240 #endif // ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
1242 QString aListStr = "";
1244 if (myTypeId == 0) {
1245 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1247 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1250 QListWidgetItem* anItem;
1251 QList<QListWidgetItem*> listItemsToSel;
1252 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1253 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1254 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1255 foreach(anItem, found)
1256 if (!anItem->isSelected())
1257 listItemsToSel.push_back(anItem);
1259 bool blocked = myElements->signalsBlocked();
1260 myElements->blockSignals(true);
1261 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1262 myElements->blockSignals(blocked);
1263 onListSelectionChanged();
1264 listItemsToSel.clear();
1270 if (!myGroup->_is_nil())
1271 myActor = SMESH::FindActorByObject(myGroup);
1272 else if(!myGroupOnGeom->_is_nil())
1273 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1275 myActor = SMESH::FindActorByObject(myMesh);
1278 // somehow, if we display the mesh, while selecting from another actor,
1279 // the mesh becomes pickable, and there is no way to select any element
1281 SMESH::SetPickable(myActor);
1286 //=================================================================================
1287 // function : onSelectSubMesh()
1288 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1289 //=================================================================================
1290 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1293 if (mySelectGroup->isChecked()) {
1294 mySelectGroup->setChecked(false);
1296 //VSR: else if (mySelectGeomGroup->isChecked()) {
1297 //VSR: mySelectGeomGroup->setChecked(false);
1299 myCurrentLineEdit = mySubMeshLine;
1300 setSelectionMode(4);
1303 mySubMeshLine->setText( "" );
1304 myCurrentLineEdit = 0;
1306 setSelectionMode(myTypeId);
1308 mySubMeshBtn->setEnabled(on);
1309 mySubMeshLine->setEnabled(on);
1313 //=================================================================================
1314 // function : (onSelectGroup)
1315 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1316 //=================================================================================
1317 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1320 if (mySelectSubMesh->isChecked()) {
1321 mySelectSubMesh->setChecked(false);
1323 myCurrentLineEdit = myGroupLine;
1324 setSelectionMode(5);
1327 myGroupLine->setText( "" );
1328 myCurrentLineEdit = 0;
1330 setSelectionMode(myTypeId);
1332 myGroupBtn->setEnabled(on);
1333 myGroupLine->setEnabled(on);
1337 //=================================================================================
1338 // function : (onSelectGeomGroup)
1339 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1340 //=================================================================================
1341 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1344 if (mySelectSubMesh->isChecked()) {
1345 mySelectSubMesh->setChecked(false);
1347 else if (mySelectGroup->isChecked()) {
1348 mySelectGroup->setChecked(false);
1350 myCurrentLineEdit = myGeomGroupLine;
1352 setSelectionMode(8);
1355 myGeomGroupBtn->setChecked(false);
1356 myGeomObjects->length(0);
1357 myGeomGroupLine->setText( "" );
1358 myCurrentLineEdit = 0;
1360 setSelectionMode(myTypeId);
1365 //=================================================================================
1366 // function : setCurrentSelection()
1368 //=================================================================================
1369 void SMESHGUI_GroupDlg::setCurrentSelection()
1371 QPushButton* send = (QPushButton*)sender();
1372 myCurrentLineEdit = 0;
1373 if (send == myMeshGroupBtn) {
1374 myCurrentLineEdit = myMeshGroupLine;
1376 setSelectionMode(6);
1378 setSelectionMode(5);
1379 onObjectSelectionChanged();
1381 else if (send == mySubMeshBtn) {
1382 myCurrentLineEdit = mySubMeshLine;
1383 onObjectSelectionChanged();
1385 else if (send == myGroupBtn) {
1386 myCurrentLineEdit = myGroupLine;
1387 onObjectSelectionChanged();
1392 //=================================================================================
1393 // function : setFilters()
1394 // purpose : SLOT. Called when "Filter" button pressed.
1395 //=================================================================================
1396 void SMESHGUI_GroupDlg::setFilters()
1398 SMESH::ElementType aType = SMESH::ALL;
1401 case 0 : aType = SMESH::NODE; break;
1402 case 1 : aType = SMESH::EDGE; break;
1403 case 2 : aType = SMESH::FACE; break;
1404 case 3 : aType = SMESH::VOLUME; break;
1408 if ( myFilterDlg == 0 )
1410 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1411 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1414 myFilterDlg->Init( aType );
1416 myFilterDlg->SetSelection();
1417 myFilterDlg->SetMesh( myMesh );
1418 myFilterDlg->SetSourceWg( myElements );
1420 myFilterDlg->show();
1423 //=================================================================================
1424 // function : onFilterAccepted()
1425 // purpose : SLOT. Called when Filter dlg closed with OK button.
1426 // Uncheck "Select submesh" and "Select group" checkboxes
1427 //=================================================================================
1428 void SMESHGUI_GroupDlg::onFilterAccepted()
1430 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1432 mySelectionMode = myTypeId;
1433 mySelectSubMesh->setChecked( false );
1434 mySelectGroup->setChecked( false );
1438 //=================================================================================
1439 // function : onAdd()
1441 //=================================================================================
1442 void SMESHGUI_GroupDlg::onAdd()
1444 SALOME_ListIO aList;
1445 mySelectionMgr->selectedObjects( aList );
1447 int aNbSel = aList.Extent();
1449 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1453 SMESH::ElementType aType = SMESH::ALL;
1456 aType = SMESH::NODE;
1457 mySelector->SetSelectionMode(NodeSelection);
1460 aType = SMESH::EDGE;
1461 mySelector->SetSelectionMode(EdgeSelection);
1464 aType = SMESH::FACE;
1465 mySelector->SetSelectionMode(FaceSelection);
1468 aType = SMESH::VOLUME;
1469 mySelector->SetSelectionMode(VolumeSelection);
1472 mySelector->SetSelectionMode(ActorSelection);
1475 QListWidgetItem* anItem = 0;
1476 QList<QListWidgetItem*> listItemsToSel;
1478 if (myCurrentLineEdit == 0) {
1479 //if (aNbSel != 1) { myIsBusy = false; return; }
1480 QString aListStr = "";
1482 if (myTypeId == 0) {
1483 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1486 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1489 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1490 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1491 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1492 if (found.count() == 0) {
1493 anItem = new QListWidgetItem(*it);
1494 myElements->addItem(anItem);
1495 if (!anItem->isSelected())
1496 listItemsToSel.push_back(anItem);
1499 foreach(anItem, found)
1500 if (!anItem->isSelected())
1501 listItemsToSel.push_back(anItem);
1504 bool blocked = myElements->signalsBlocked();
1505 myElements->blockSignals(true);
1506 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1507 myElements->blockSignals(blocked);
1508 onListSelectionChanged();
1509 listItemsToSel.clear();
1511 } else if (myCurrentLineEdit == mySubMeshLine) {
1512 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1514 SALOME_ListIO aList;
1515 mySelectionMgr->selectedObjects( aList );
1517 SALOME_ListIteratorOfListIO anIt (aList);
1518 for ( ; anIt.More(); anIt.Next()) {
1519 SMESH::SMESH_subMesh_var aSubMesh =
1520 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1521 if (!aSubMesh->_is_nil()) {
1522 // check if mesh is the same
1523 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1525 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1526 int k = anElements->length();
1527 for (int i = 0; i < k; i++) {
1528 QString aText = QString::number(anElements[i]);
1529 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1530 if (found.count() == 0) {
1531 anItem = new QListWidgetItem(aText);
1532 myElements->addItem(anItem);
1533 if (!anItem->isSelected())
1534 listItemsToSel.push_back(anItem);
1537 foreach(anItem, found)
1538 if (!anItem->isSelected())
1539 listItemsToSel.push_back(anItem);
1542 bool blocked = myElements->signalsBlocked();
1543 myElements->blockSignals(true);
1544 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1545 myElements->blockSignals(blocked);
1546 onListSelectionChanged();
1547 listItemsToSel.clear();
1549 catch (const SALOME::SALOME_Exception& ex) {
1550 SalomeApp_Tools::QtCatchCorbaException(ex);
1555 mySelectSubMesh->setChecked(false);
1557 onListSelectionChanged();
1559 } else if (myCurrentLineEdit == myGroupLine) {
1560 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1561 SALOME_ListIO aList;
1562 mySelectionMgr->selectedObjects( aList );
1564 SALOME_ListIteratorOfListIO anIt (aList);
1565 for ( ; anIt.More(); anIt.Next()) {
1566 SMESH::SMESH_GroupBase_var aGroup =
1567 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1568 if (!aGroup->_is_nil()) {
1569 // check if mesh is the same
1570 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1571 SMESH::long_array_var anElements = aGroup->GetListOfID();
1572 int k = anElements->length();
1573 for (int i = 0; i < k; i++) {
1574 QString aText = QString::number(anElements[i]);
1575 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1576 if (found.count() == 0) {
1577 anItem = new QListWidgetItem(aText);
1578 myElements->addItem(anItem);
1579 if (!anItem->isSelected())
1580 listItemsToSel.push_back(anItem);
1583 foreach(anItem, found)
1584 if (!anItem->isSelected())
1585 listItemsToSel.push_back(anItem);
1588 bool blocked = myElements->signalsBlocked();
1589 myElements->blockSignals(true);
1590 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1591 myElements->blockSignals(blocked);
1592 onListSelectionChanged();
1593 listItemsToSel.clear();
1597 mySelectGroup->setChecked(false);
1599 onListSelectionChanged();
1601 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1602 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1603 GEOM::GEOM_IGroupOperations_var aGroupOp =
1604 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1606 SMESH::ElementType aGroupType = SMESH::ALL;
1607 switch(aGroupOp->GetType(myGeomObjects[0])) {
1608 case 7: aGroupType = SMESH::NODE; break;
1609 case 6: aGroupType = SMESH::EDGE; break;
1610 case 4: aGroupType = SMESH::FACE; break;
1611 case 2: aGroupType = SMESH::VOLUME; break;
1612 default: myIsBusy = false; return;
1615 if (aGroupType == aType) {
1616 _PTR(SObject) aGroupSO =
1617 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1618 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1620 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1621 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1622 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1623 aBelongToGeom->SetGeom(myGeomObjects[0]);
1624 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1625 aBelongToGeom->SetElementType(aType);
1626 aFilter->SetPredicate(aBelongToGeom);
1628 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1630 int k = anElements->length();
1631 for (int i = 0; i < k; i++) {
1632 QString aText = QString::number(anElements[i]);
1633 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1634 if (found.count() == 0) {
1635 anItem = new QListWidgetItem(aText);
1636 myElements->addItem(anItem);
1637 if (!anItem->isSelected())
1638 listItemsToSel.push_back(anItem);
1641 foreach(anItem, found)
1642 if (!anItem->isSelected())
1643 listItemsToSel.push_back(anItem);
1646 bool blocked = myElements->signalsBlocked();
1647 myElements->blockSignals(true);
1648 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1649 myElements->blockSignals(blocked);
1650 onListSelectionChanged();
1651 listItemsToSel.clear();
1654 //VSR: mySelectGeomGroup->setChecked(false);
1656 onListSelectionChanged();
1659 // mySelectionMgr->clearSelected();
1663 //=================================================================================
1664 // function : onRemove()
1666 //=================================================================================
1667 void SMESHGUI_GroupDlg::onRemove()
1670 if (myCurrentLineEdit == 0) {
1671 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1672 QListWidgetItem* item;
1673 foreach(item, selItems) delete item;
1675 SALOME_ListIO aList;
1676 mySelectionMgr->selectedObjects( aList );
1678 int aNbSel = aList.Extent();
1680 if (aNbSel == 0) { myIsBusy = false; return; }
1682 SMESH::ElementType aType = SMESH::ALL;
1684 case 0: aType = SMESH::NODE; break;
1685 case 1: aType = SMESH::EDGE; break;
1686 case 2: aType = SMESH::FACE; break;
1687 case 3: aType = SMESH::VOLUME; break;
1690 if (myCurrentLineEdit == mySubMeshLine) {
1691 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1692 SALOME_ListIO aList;
1693 mySelectionMgr->selectedObjects( aList );
1695 SALOME_ListIteratorOfListIO anIt (aList);
1696 for ( ; anIt.More(); anIt.Next()) {
1697 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1698 if (!aSubMesh->_is_nil()) {
1699 // check if mesh is the same
1700 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1701 if (aType == SMESH::NODE) {
1703 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1704 int k = anElements->length();
1705 for (int i = 0; i < k; i++) {
1706 QList<QListWidgetItem*> found =
1707 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1708 QListWidgetItem* anItem;
1709 foreach(anItem, found) delete anItem;
1712 catch (const SALOME::SALOME_Exception& ex) {
1713 SalomeApp_Tools::QtCatchCorbaException(ex);
1718 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1719 int k = anElements->length();
1720 for (int i = 0; i < k; i++) {
1721 QList<QListWidgetItem*> found =
1722 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1723 QListWidgetItem* anItem;
1724 foreach(anItem, found) delete anItem;
1727 catch (const SALOME::SALOME_Exception& ex) {
1728 SalomeApp_Tools::QtCatchCorbaException(ex);
1735 else if (myCurrentLineEdit == myGroupLine) {
1736 Standard_Boolean aRes;
1737 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1738 SALOME_ListIO aList;
1739 mySelectionMgr->selectedObjects( aList );
1741 SALOME_ListIteratorOfListIO anIt (aList);
1742 for ( ; anIt.More(); anIt.Next()) {
1743 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1744 if (aRes && !aGroup->_is_nil()) {
1745 // check if mesh is the same
1746 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1747 SMESH::long_array_var anElements = aGroup->GetListOfID();
1748 int k = anElements->length();
1749 for (int i = 0; i < k; i++) {
1750 QList<QListWidgetItem*> found =
1751 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1752 QListWidgetItem* anItem;
1753 foreach(anItem, found) delete anItem;
1764 //=================================================================================
1765 // function : onSort()
1767 //=================================================================================
1768 void SMESHGUI_GroupDlg::onSort()
1770 // PAL5412: sorts items in ascending by "string" value
1771 // myElements->sort(true);
1772 // myElements->update();
1773 int i, k = myElements->count();
1776 QList<int> aSelected;
1777 std::vector<int> anArray(k);
1778 // QMemArray<int> anArray(k);
1780 for (i = 0; i < k; i++) {
1781 int id = myElements->item(i)->text().toInt();
1783 if (myElements->item(i)->isSelected())
1784 aSelected.append(id);
1786 // sort & update list
1787 std::sort(anArray.begin(), anArray.end());
1789 myElements->clear();
1790 QListWidgetItem* anItem;
1791 QList<QListWidgetItem*> listItemsToSel;
1792 for (i = 0; i < k; i++) {
1793 anItem = new QListWidgetItem(QString::number(anArray[i]));
1794 myElements->addItem(anItem);
1795 if (aSelected.contains(anArray[i]))
1796 listItemsToSel.push_back(anItem);
1798 bool blocked = myElements->signalsBlocked();
1799 myElements->blockSignals(true);
1800 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1801 myElements->blockSignals(blocked);
1802 listItemsToSel.clear();
1807 //=================================================================================
1808 // function : closeEvent()
1810 //=================================================================================
1811 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1816 //=================================================================================
1817 // function : SMESHGUI_GroupDlg::onClose
1818 // purpose : SLOT called when "Close" button pressed. Close dialog
1819 //=================================================================================
1820 void SMESHGUI_GroupDlg::onClose()
1822 if (SMESH::GetCurrentVtkView()) {
1823 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1824 SMESH::SetPointRepresentation(false);
1825 SMESH::SetPickable();
1826 restoreShowEntityMode();
1829 mySelectionMgr->clearSelected();
1830 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1831 aViewWindow->SetSelectionMode(ActorSelection);
1832 mySelectionMgr->clearFilters();
1833 mySMESHGUI->ResetState();
1838 //=================================================================================
1839 // function : onHelp()
1841 //=================================================================================
1842 void SMESHGUI_GroupDlg::onHelp()
1844 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1846 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1850 platform = "winapplication";
1852 platform = "application";
1854 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1855 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1856 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1858 arg(myHelpFileName));
1862 //=================================================================================
1863 // function : SMESHGUI_GroupDlg::onDeactivate
1864 // purpose : SLOT called when dialog must be deativated
1865 //=================================================================================
1866 void SMESHGUI_GroupDlg::onDeactivate()
1868 mySMESHGUI->ResetState();
1872 //=================================================================================
1873 // function : SMESHGUI_GroupDlg::enterEvent
1874 // purpose : Event filter
1875 //=================================================================================
1876 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1879 mySMESHGUI->EmitSignalDeactivateDialog();
1881 mySelectionMode = -1;
1882 setSelectionMode(myTypeId);
1883 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1884 mySMESHGUI->SetActiveDialogBox(this);
1885 mySMESHGUI->SetState(800);
1889 //=================================================================================
1890 // function : hideEvent
1891 // purpose : caused by ESC key
1892 //=================================================================================
1893 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1895 if (!isMinimized() && !myIsBusy)
1899 //=================================================================================
1900 // function : keyPressEvent()
1902 //=================================================================================
1903 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1905 QDialog::keyPressEvent( e );
1906 if ( e->isAccepted() )
1909 if ( e->key() == Qt::Key_F1 )
1916 //================================================================================
1918 * \brief Enable showing of the popup when Geometry selection btn is clicked
1919 * \param enable - true to enable
1921 //================================================================================
1923 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1925 void SMESHGUI_GroupDlg::updateGeomPopup()
1927 bool enable = false;
1929 if ( !myMesh->_is_nil() )
1930 enable = myMesh->NbEdges() > 0;
1932 if ( myGeomGroupBtn )
1934 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1936 if ( !myGeomPopup ) {
1937 myGeomPopup = new QMenu(this);
1938 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
1939 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
1940 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
1942 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1948 //=================================================================================
1949 // function : onGeomSelectionButton()
1951 //=================================================================================
1952 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1954 if ( myGeomPopup && isBtnOn )
1956 myCurrentLineEdit = myGeomGroupLine;
1957 QAction* a = myGeomPopup->exec( QCursor::pos() );
1958 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
1959 setSelectionMode(7);
1963 myCurrentLineEdit = 0;
1964 setSelectionMode(8);
1968 //=================================================================================
1969 // function : onGeomPopup()
1971 //=================================================================================
1972 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
1974 int index = myActions[a];
1975 if ( index == GEOM_BY_MESH_INDEX )
1977 mySelectionMode = -1;
1978 if ( !myShapeByMeshOp ) {
1979 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1980 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1981 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1982 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1983 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1985 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1986 if ( !myMesh->_is_nil() ) {
1988 hide(); // stop processing selection
1990 myShapeByMeshOp->setModule( mySMESHGUI );
1991 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1992 myShapeByMeshOp->SetMesh( myMesh );
1993 myShapeByMeshOp->start();
1998 //================================================================================
2000 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2002 //================================================================================
2004 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2006 if ( myShapeByMeshOp == op ) {
2007 mySMESHGUI->getApp()->updateObjectBrowser();
2009 // Select a found geometry object
2010 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2011 if ( !aGeomVar->_is_nil() )
2013 QString ID = aGeomVar->GetStudyEntry();
2014 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2015 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2016 SALOME_ListIO anIOList;
2017 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2018 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2019 anIOList.Append( anIO );
2020 mySelectionMgr->setSelectedObjects( anIOList, false );
2021 onObjectSelectionChanged();
2027 //================================================================================
2029 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2031 //================================================================================
2033 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2035 if ( myShapeByMeshOp == op )
2038 setSelectionMode(7);
2042 //=================================================================================
2043 // function : setGroupColor()
2045 //=================================================================================
2046 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2048 QColor aQColor( (int)( theColor.R * 255.0 ),
2049 (int)( theColor.G * 255.0 ),
2050 (int)( theColor.B * 255.0 ) );
2051 setGroupQColor( aQColor );
2054 //=================================================================================
2055 // function : getGroupColor()
2057 //=================================================================================
2058 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2060 QColor aQColor = getGroupQColor();
2062 SALOMEDS::Color aColor;
2063 aColor.R = (float)aQColor.red() / 255.0;
2064 aColor.G = (float)aQColor.green() / 255.0;
2065 aColor.B = (float)aQColor.blue() / 255.0;
2070 //=================================================================================
2071 // function : setGroupQColor()
2073 //=================================================================================
2074 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2076 if( theColor.isValid() )
2077 myColorBtn->setColor( theColor );
2080 //=================================================================================
2081 // function : getGroupQColor()
2083 //=================================================================================
2084 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2086 return myColorBtn->color();
2089 //=================================================================================
2090 // function : setDefaultGroupColor()
2092 //=================================================================================
2093 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2095 if( myMesh->_is_nil() )
2098 bool isAutoColor = myMesh->GetAutoColor();
2103 int r = 0, g = 0, b = 0;
2104 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2105 aQColor.setRgb( r, g, b );
2109 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2111 QList<SALOMEDS::Color> aReservedColors;
2112 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2114 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2115 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2116 aReservedColors.append( aReservedColor );
2119 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2120 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2121 (int)( aColor.G * 255.0 ),
2122 (int)( aColor.B * 255.0 ) );
2126 setGroupQColor( aQColor );
2129 //=================================================================================
2130 // function : SetAppropriateActor()
2131 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2132 // NPAL19389: create a group with a selection in another group.
2133 // if mesh actor is not visible - find any first visible group or submesh
2134 //=================================================================================
2135 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2137 bool isActor = false;
2139 if (myMesh->_is_nil()) return false;
2141 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2144 myActor = SMESH::FindActorByObject(myMesh);
2145 if (myActor && myActor->hasIO())
2148 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2152 // try current group actor
2154 if (!myGroup->_is_nil()) {
2155 myActor = SMESH::FindActorByObject(myGroup);
2156 if (myActor && myActor->hasIO())
2159 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2165 // try current group on geometry actor
2167 if (!myGroupOnGeom->_is_nil()) {
2168 myActor = SMESH::FindActorByObject(myGroupOnGeom);
2169 if (myActor && myActor->hasIO())
2172 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2178 // try any visible actor of group or submesh of current mesh
2179 if (!isActor && aViewWindow) {
2181 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2183 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2184 int len = strlen(meshEntry);
2186 // iterate on all actors in current view window, search for
2187 // any visible actor, that belongs to group or submesh of current mesh
2188 vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
2189 aCollection->InitTraversal();
2190 for (vtkActor *anAct = aCollection->GetNextActor();
2192 anAct = aCollection->GetNextActor())
2194 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct);
2195 if (anActor && anActor->hasIO()) {
2196 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2197 if (aViewWindow->isVisible(anIO)) {
2198 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0) {
2209 SMESH::SetPickable(myActor);
2214 //=======================================================================
2215 //function : setShowEntityMode
2216 //purpose : make shown only entity corresponding to my type
2217 //=======================================================================
2218 void SMESHGUI_GroupDlg::setShowEntityMode()
2220 if ( !myMesh->_is_nil() ) {
2221 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2222 if (!myStoredShownEntity)
2223 myStoredShownEntity = actor->GetEntityMode();
2224 switch ( myTypeId ) {
2225 case 0: restoreShowEntityMode(); break;
2226 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2227 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2228 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2234 //=======================================================================
2235 //function : restoreShowEntityMode
2236 //purpose : restore ShowEntity mode of myActor
2237 //=======================================================================
2238 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2240 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2241 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2242 actor->SetEntityMode(myStoredShownEntity);
2245 myStoredShownEntity = 0;