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 if(myMesh->_is_nil()) {
1399 SUIT_MessageBox::critical(this,
1401 tr("NO_MESH_SELECTED"));
1405 SMESH::ElementType aType = SMESH::ALL;
1408 case 0 : aType = SMESH::NODE; break;
1409 case 1 : aType = SMESH::EDGE; break;
1410 case 2 : aType = SMESH::FACE; break;
1411 case 3 : aType = SMESH::VOLUME; break;
1415 if ( myFilterDlg == 0 )
1417 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1418 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1421 myFilterDlg->Init( aType );
1423 myFilterDlg->SetSelection();
1424 myFilterDlg->SetMesh( myMesh );
1425 myFilterDlg->SetSourceWg( myElements, false );
1427 myFilterDlg->show();
1430 //=================================================================================
1431 // function : onFilterAccepted()
1432 // purpose : SLOT. Called when Filter dlg closed with OK button.
1433 // Uncheck "Select submesh" and "Select group" checkboxes
1434 //=================================================================================
1435 void SMESHGUI_GroupDlg::onFilterAccepted()
1437 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1439 mySelectionMode = myTypeId;
1440 mySelectSubMesh->setChecked( false );
1441 mySelectGroup->setChecked( false );
1445 //=================================================================================
1446 // function : onAdd()
1448 //=================================================================================
1449 void SMESHGUI_GroupDlg::onAdd()
1451 SALOME_ListIO aList;
1452 mySelectionMgr->selectedObjects( aList );
1454 int aNbSel = aList.Extent();
1456 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1460 SMESH::ElementType aType = SMESH::ALL;
1463 aType = SMESH::NODE;
1464 mySelector->SetSelectionMode(NodeSelection);
1467 aType = SMESH::EDGE;
1468 mySelector->SetSelectionMode(EdgeSelection);
1471 aType = SMESH::FACE;
1472 mySelector->SetSelectionMode(FaceSelection);
1475 aType = SMESH::VOLUME;
1476 mySelector->SetSelectionMode(VolumeSelection);
1479 mySelector->SetSelectionMode(ActorSelection);
1482 QListWidgetItem* anItem = 0;
1483 QList<QListWidgetItem*> listItemsToSel;
1485 if (myCurrentLineEdit == 0) {
1486 //if (aNbSel != 1) { myIsBusy = false; return; }
1487 QString aListStr = "";
1489 if (myTypeId == 0) {
1490 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1493 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1496 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1497 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1498 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1499 if (found.count() == 0) {
1500 anItem = new QListWidgetItem(*it);
1501 myElements->addItem(anItem);
1502 if (!anItem->isSelected())
1503 listItemsToSel.push_back(anItem);
1506 foreach(anItem, found)
1507 if (!anItem->isSelected())
1508 listItemsToSel.push_back(anItem);
1511 bool blocked = myElements->signalsBlocked();
1512 myElements->blockSignals(true);
1513 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1514 myElements->blockSignals(blocked);
1515 onListSelectionChanged();
1516 listItemsToSel.clear();
1518 } else if (myCurrentLineEdit == mySubMeshLine) {
1519 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1521 SALOME_ListIO aList;
1522 mySelectionMgr->selectedObjects( aList );
1524 SALOME_ListIteratorOfListIO anIt (aList);
1525 for ( ; anIt.More(); anIt.Next()) {
1526 SMESH::SMESH_subMesh_var aSubMesh =
1527 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1528 if (!aSubMesh->_is_nil()) {
1529 // check if mesh is the same
1530 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1532 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1533 int k = anElements->length();
1534 for (int i = 0; i < k; i++) {
1535 QString aText = QString::number(anElements[i]);
1536 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1537 if (found.count() == 0) {
1538 anItem = new QListWidgetItem(aText);
1539 myElements->addItem(anItem);
1540 if (!anItem->isSelected())
1541 listItemsToSel.push_back(anItem);
1544 foreach(anItem, found)
1545 if (!anItem->isSelected())
1546 listItemsToSel.push_back(anItem);
1549 bool blocked = myElements->signalsBlocked();
1550 myElements->blockSignals(true);
1551 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1552 myElements->blockSignals(blocked);
1553 onListSelectionChanged();
1554 listItemsToSel.clear();
1556 catch (const SALOME::SALOME_Exception& ex) {
1557 SalomeApp_Tools::QtCatchCorbaException(ex);
1562 mySelectSubMesh->setChecked(false);
1564 onListSelectionChanged();
1566 } else if (myCurrentLineEdit == myGroupLine) {
1567 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1568 SALOME_ListIO aList;
1569 mySelectionMgr->selectedObjects( aList );
1571 SALOME_ListIteratorOfListIO anIt (aList);
1572 for ( ; anIt.More(); anIt.Next()) {
1573 SMESH::SMESH_GroupBase_var aGroup =
1574 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1575 if (!aGroup->_is_nil()) {
1576 // check if mesh is the same
1577 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1578 SMESH::long_array_var anElements = aGroup->GetListOfID();
1579 int k = anElements->length();
1580 for (int i = 0; i < k; i++) {
1581 QString aText = QString::number(anElements[i]);
1582 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1583 if (found.count() == 0) {
1584 anItem = new QListWidgetItem(aText);
1585 myElements->addItem(anItem);
1586 if (!anItem->isSelected())
1587 listItemsToSel.push_back(anItem);
1590 foreach(anItem, found)
1591 if (!anItem->isSelected())
1592 listItemsToSel.push_back(anItem);
1595 bool blocked = myElements->signalsBlocked();
1596 myElements->blockSignals(true);
1597 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1598 myElements->blockSignals(blocked);
1599 onListSelectionChanged();
1600 listItemsToSel.clear();
1604 mySelectGroup->setChecked(false);
1606 onListSelectionChanged();
1608 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1609 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1610 GEOM::GEOM_IGroupOperations_var aGroupOp =
1611 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1613 SMESH::ElementType aGroupType = SMESH::ALL;
1614 switch(aGroupOp->GetType(myGeomObjects[0])) {
1615 case 7: aGroupType = SMESH::NODE; break;
1616 case 6: aGroupType = SMESH::EDGE; break;
1617 case 4: aGroupType = SMESH::FACE; break;
1618 case 2: aGroupType = SMESH::VOLUME; break;
1619 default: myIsBusy = false; return;
1622 if (aGroupType == aType) {
1623 _PTR(SObject) aGroupSO =
1624 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1625 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1627 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1628 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1629 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1630 aBelongToGeom->SetGeom(myGeomObjects[0]);
1631 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1632 aBelongToGeom->SetElementType(aType);
1633 aFilter->SetPredicate(aBelongToGeom);
1635 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1637 int k = anElements->length();
1638 for (int i = 0; i < k; i++) {
1639 QString aText = QString::number(anElements[i]);
1640 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1641 if (found.count() == 0) {
1642 anItem = new QListWidgetItem(aText);
1643 myElements->addItem(anItem);
1644 if (!anItem->isSelected())
1645 listItemsToSel.push_back(anItem);
1648 foreach(anItem, found)
1649 if (!anItem->isSelected())
1650 listItemsToSel.push_back(anItem);
1653 bool blocked = myElements->signalsBlocked();
1654 myElements->blockSignals(true);
1655 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1656 myElements->blockSignals(blocked);
1657 onListSelectionChanged();
1658 listItemsToSel.clear();
1661 //VSR: mySelectGeomGroup->setChecked(false);
1663 onListSelectionChanged();
1666 // mySelectionMgr->clearSelected();
1670 //=================================================================================
1671 // function : onRemove()
1673 //=================================================================================
1674 void SMESHGUI_GroupDlg::onRemove()
1677 if (myCurrentLineEdit == 0) {
1678 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1679 QListWidgetItem* item;
1680 foreach(item, selItems) delete item;
1682 SALOME_ListIO aList;
1683 mySelectionMgr->selectedObjects( aList );
1685 int aNbSel = aList.Extent();
1687 if (aNbSel == 0) { myIsBusy = false; return; }
1689 SMESH::ElementType aType = SMESH::ALL;
1691 case 0: aType = SMESH::NODE; break;
1692 case 1: aType = SMESH::EDGE; break;
1693 case 2: aType = SMESH::FACE; break;
1694 case 3: aType = SMESH::VOLUME; break;
1697 if (myCurrentLineEdit == mySubMeshLine) {
1698 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1699 SALOME_ListIO aList;
1700 mySelectionMgr->selectedObjects( aList );
1702 SALOME_ListIteratorOfListIO anIt (aList);
1703 for ( ; anIt.More(); anIt.Next()) {
1704 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1705 if (!aSubMesh->_is_nil()) {
1706 // check if mesh is the same
1707 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1708 if (aType == SMESH::NODE) {
1710 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1711 int k = anElements->length();
1712 for (int i = 0; i < k; i++) {
1713 QList<QListWidgetItem*> found =
1714 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1715 QListWidgetItem* anItem;
1716 foreach(anItem, found) delete anItem;
1719 catch (const SALOME::SALOME_Exception& ex) {
1720 SalomeApp_Tools::QtCatchCorbaException(ex);
1725 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1726 int k = anElements->length();
1727 for (int i = 0; i < k; i++) {
1728 QList<QListWidgetItem*> found =
1729 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1730 QListWidgetItem* anItem;
1731 foreach(anItem, found) delete anItem;
1734 catch (const SALOME::SALOME_Exception& ex) {
1735 SalomeApp_Tools::QtCatchCorbaException(ex);
1742 else if (myCurrentLineEdit == myGroupLine) {
1743 Standard_Boolean aRes;
1744 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1745 SALOME_ListIO aList;
1746 mySelectionMgr->selectedObjects( aList );
1748 SALOME_ListIteratorOfListIO anIt (aList);
1749 for ( ; anIt.More(); anIt.Next()) {
1750 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1751 if (aRes && !aGroup->_is_nil()) {
1752 // check if mesh is the same
1753 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1754 SMESH::long_array_var anElements = aGroup->GetListOfID();
1755 int k = anElements->length();
1756 for (int i = 0; i < k; i++) {
1757 QList<QListWidgetItem*> found =
1758 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1759 QListWidgetItem* anItem;
1760 foreach(anItem, found) delete anItem;
1771 //=================================================================================
1772 // function : onSort()
1774 //=================================================================================
1775 void SMESHGUI_GroupDlg::onSort()
1777 // PAL5412: sorts items in ascending by "string" value
1778 // myElements->sort(true);
1779 // myElements->update();
1780 int i, k = myElements->count();
1783 QList<int> aSelected;
1784 std::vector<int> anArray(k);
1785 // QMemArray<int> anArray(k);
1787 for (i = 0; i < k; i++) {
1788 int id = myElements->item(i)->text().toInt();
1790 if (myElements->item(i)->isSelected())
1791 aSelected.append(id);
1793 // sort & update list
1794 std::sort(anArray.begin(), anArray.end());
1796 myElements->clear();
1797 QListWidgetItem* anItem;
1798 QList<QListWidgetItem*> listItemsToSel;
1799 for (i = 0; i < k; i++) {
1800 anItem = new QListWidgetItem(QString::number(anArray[i]));
1801 myElements->addItem(anItem);
1802 if (aSelected.contains(anArray[i]))
1803 listItemsToSel.push_back(anItem);
1805 bool blocked = myElements->signalsBlocked();
1806 myElements->blockSignals(true);
1807 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1808 myElements->blockSignals(blocked);
1809 listItemsToSel.clear();
1814 //=================================================================================
1815 // function : closeEvent()
1817 //=================================================================================
1818 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1823 //=================================================================================
1824 // function : SMESHGUI_GroupDlg::onClose
1825 // purpose : SLOT called when "Close" button pressed. Close dialog
1826 //=================================================================================
1827 void SMESHGUI_GroupDlg::onClose()
1829 if (SMESH::GetCurrentVtkView()) {
1830 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1831 SMESH::SetPointRepresentation(false);
1832 SMESH::SetPickable();
1833 restoreShowEntityMode();
1836 mySelectionMgr->clearSelected();
1837 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1838 aViewWindow->SetSelectionMode(ActorSelection);
1839 mySelectionMgr->clearFilters();
1840 mySMESHGUI->ResetState();
1845 //=================================================================================
1846 // function : onHelp()
1848 //=================================================================================
1849 void SMESHGUI_GroupDlg::onHelp()
1851 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1853 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1857 platform = "winapplication";
1859 platform = "application";
1861 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1862 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1863 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1865 arg(myHelpFileName));
1869 //=================================================================================
1870 // function : SMESHGUI_GroupDlg::onDeactivate
1871 // purpose : SLOT called when dialog must be deativated
1872 //=================================================================================
1873 void SMESHGUI_GroupDlg::onDeactivate()
1875 mySMESHGUI->ResetState();
1879 //=================================================================================
1880 // function : SMESHGUI_GroupDlg::enterEvent
1881 // purpose : Event filter
1882 //=================================================================================
1883 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1886 mySMESHGUI->EmitSignalDeactivateDialog();
1888 mySelectionMode = -1;
1889 setSelectionMode(myTypeId);
1890 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1891 mySMESHGUI->SetActiveDialogBox(this);
1892 mySMESHGUI->SetState(800);
1896 //=================================================================================
1897 // function : hideEvent
1898 // purpose : caused by ESC key
1899 //=================================================================================
1900 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1902 if (!isMinimized() && !myIsBusy)
1906 //=================================================================================
1907 // function : keyPressEvent()
1909 //=================================================================================
1910 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1912 QDialog::keyPressEvent( e );
1913 if ( e->isAccepted() )
1916 if ( e->key() == Qt::Key_F1 )
1923 //================================================================================
1925 * \brief Enable showing of the popup when Geometry selection btn is clicked
1926 * \param enable - true to enable
1928 //================================================================================
1930 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1932 void SMESHGUI_GroupDlg::updateGeomPopup()
1934 bool enable = false;
1936 if ( !myMesh->_is_nil() )
1937 enable = myMesh->NbEdges() > 0;
1939 if ( myGeomGroupBtn )
1941 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1943 if ( !myGeomPopup ) {
1944 myGeomPopup = new QMenu(this);
1945 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
1946 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
1947 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
1949 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1955 //=================================================================================
1956 // function : onGeomSelectionButton()
1958 //=================================================================================
1959 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1961 if ( myGeomPopup && isBtnOn )
1963 myCurrentLineEdit = myGeomGroupLine;
1964 QAction* a = myGeomPopup->exec( QCursor::pos() );
1965 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
1966 setSelectionMode(7);
1970 myCurrentLineEdit = 0;
1971 setSelectionMode(8);
1975 //=================================================================================
1976 // function : onGeomPopup()
1978 //=================================================================================
1979 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
1981 int index = myActions[a];
1982 if ( index == GEOM_BY_MESH_INDEX )
1984 mySelectionMode = -1;
1985 if ( !myShapeByMeshOp ) {
1986 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1987 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1988 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1989 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1990 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1992 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1993 if ( !myMesh->_is_nil() ) {
1995 hide(); // stop processing selection
1997 myShapeByMeshOp->setModule( mySMESHGUI );
1998 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1999 myShapeByMeshOp->SetMesh( myMesh );
2000 myShapeByMeshOp->start();
2005 //================================================================================
2007 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2009 //================================================================================
2011 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2013 if ( myShapeByMeshOp == op ) {
2014 mySMESHGUI->getApp()->updateObjectBrowser();
2016 // Select a found geometry object
2017 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2018 if ( !aGeomVar->_is_nil() )
2020 QString ID = aGeomVar->GetStudyEntry();
2021 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2022 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2023 SALOME_ListIO anIOList;
2024 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2025 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2026 anIOList.Append( anIO );
2027 mySelectionMgr->setSelectedObjects( anIOList, false );
2028 onObjectSelectionChanged();
2034 //================================================================================
2036 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2038 //================================================================================
2040 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2042 if ( myShapeByMeshOp == op )
2045 setSelectionMode(7);
2049 //=================================================================================
2050 // function : setGroupColor()
2052 //=================================================================================
2053 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2055 QColor aQColor( (int)( theColor.R * 255.0 ),
2056 (int)( theColor.G * 255.0 ),
2057 (int)( theColor.B * 255.0 ) );
2058 setGroupQColor( aQColor );
2061 //=================================================================================
2062 // function : getGroupColor()
2064 //=================================================================================
2065 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2067 QColor aQColor = getGroupQColor();
2069 SALOMEDS::Color aColor;
2070 aColor.R = (float)aQColor.red() / 255.0;
2071 aColor.G = (float)aQColor.green() / 255.0;
2072 aColor.B = (float)aQColor.blue() / 255.0;
2077 //=================================================================================
2078 // function : setGroupQColor()
2080 //=================================================================================
2081 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2083 if( theColor.isValid() )
2084 myColorBtn->setColor( theColor );
2087 //=================================================================================
2088 // function : getGroupQColor()
2090 //=================================================================================
2091 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2093 return myColorBtn->color();
2096 //=================================================================================
2097 // function : setDefaultGroupColor()
2099 //=================================================================================
2100 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2102 if( myMesh->_is_nil() )
2105 bool isAutoColor = myMesh->GetAutoColor();
2110 int r = 0, g = 0, b = 0;
2111 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2112 aQColor.setRgb( r, g, b );
2116 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2118 QList<SALOMEDS::Color> aReservedColors;
2119 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2121 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2122 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2123 aReservedColors.append( aReservedColor );
2126 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2127 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2128 (int)( aColor.G * 255.0 ),
2129 (int)( aColor.B * 255.0 ) );
2133 setGroupQColor( aQColor );
2136 //=================================================================================
2137 // function : SetAppropriateActor()
2138 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2139 // NPAL19389: create a group with a selection in another group.
2140 // if mesh actor is not visible - find any first visible group or submesh
2141 //=================================================================================
2142 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2144 bool isActor = false;
2146 if (myMesh->_is_nil()) return false;
2148 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2151 myActor = SMESH::FindActorByObject(myMesh);
2152 if (myActor && myActor->hasIO())
2155 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2159 // try current group actor
2161 if (!myGroup->_is_nil()) {
2162 myActor = SMESH::FindActorByObject(myGroup);
2163 if (myActor && myActor->hasIO())
2166 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2172 // try current group on geometry actor
2174 if (!myGroupOnGeom->_is_nil()) {
2175 myActor = SMESH::FindActorByObject(myGroupOnGeom);
2176 if (myActor && myActor->hasIO())
2179 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2185 // try any visible actor of group or submesh of current mesh
2186 if (!isActor && aViewWindow) {
2188 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2190 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2191 int len = strlen(meshEntry);
2193 // iterate on all actors in current view window, search for
2194 // any visible actor, that belongs to group or submesh of current mesh
2195 vtkActorCollection *aCollection = aViewWindow->getRenderer()->GetActors();
2196 aCollection->InitTraversal();
2197 for (vtkActor *anAct = aCollection->GetNextActor();
2199 anAct = aCollection->GetNextActor())
2201 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct);
2202 if (anActor && anActor->hasIO()) {
2203 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2204 if (aViewWindow->isVisible(anIO)) {
2205 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0) {
2216 SMESH::SetPickable(myActor);
2221 //=======================================================================
2222 //function : setShowEntityMode
2223 //purpose : make shown only entity corresponding to my type
2224 //=======================================================================
2225 void SMESHGUI_GroupDlg::setShowEntityMode()
2227 if ( !myMesh->_is_nil() ) {
2228 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2229 if (!myStoredShownEntity)
2230 myStoredShownEntity = actor->GetEntityMode();
2231 switch ( myTypeId ) {
2232 case 0: restoreShowEntityMode(); break;
2233 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2234 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2235 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2241 //=======================================================================
2242 //function : restoreShowEntityMode
2243 //purpose : restore ShowEntity mode of myActor
2244 //=======================================================================
2245 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2247 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2248 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2249 actor->SetEntityMode(myStoredShownEntity);
2252 myStoredShownEntity = 0;