1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_GroupDlg.cxx
24 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
27 #include "SMESHGUI_GroupDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_GroupUtils.h"
33 #include "SMESHGUI_FilterUtils.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
35 #include "SMESHGUI_FilterDlg.h"
36 #include "SMESHGUI_ShapeByMeshDlg.h"
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_Actor.h>
40 #include <SMESH_ActorUtils.h>
42 // SALOME GEOM includes
44 #include <GEOM_SelectionFilter.h>
46 // SALOME GUI includes
47 #include <QtxColorButton.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_ResourceMgr.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_MessageBox.h>
54 #include <SalomeApp_Tools.h>
55 #include <SalomeApp_Application.h>
56 #include <SalomeApp_Study.h>
57 #include <LightApp_SelectionMgr.h>
59 #include <SALOME_ListIO.hxx>
60 #include <SALOME_ListIteratorOfListIO.hxx>
62 #include <SVTK_ViewWindow.h>
64 #include <VTKViewer_Algorithm.h>
66 // SALOME KERNEL includes
67 #include <SALOMEDSClient_Study.hxx>
70 #include <vtkRenderer.h>
71 #include <vtkActorCollection.h>
74 #include <TColStd_MapOfInteger.hxx>
77 #include <QButtonGroup>
81 #include <QPushButton>
82 #include <QToolButton>
83 #include <QRadioButton>
85 #include <QGridLayout>
86 #include <QHBoxLayout>
87 #include <QVBoxLayout>
88 #include <QListWidget>
89 #include <QStackedWidget>
101 //=================================================================================
102 // function : SMESHGUI_GroupDlg()
104 //=================================================================================
105 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
106 SMESH::SMESH_Mesh_ptr theMesh )
107 : QDialog( SMESH::GetDesktop( theModule ) ),
108 mySMESHGUI( theModule ),
109 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
110 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
112 myNameChanged( false ),
116 if ( !theMesh->_is_nil() )
120 mySelectSubMesh->setEnabled( false );
121 mySelectGroup->setEnabled( false );
122 myGeomGroupBtn->setEnabled( false );
123 myGeomGroupLine->setEnabled( false );
127 //=================================================================================
128 // function : SMESHGUI_GroupDlg()
130 //=================================================================================
131 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
132 SMESH::SMESH_GroupBase_ptr theGroup,
133 const bool theIsConvert )
134 : QDialog( SMESH::GetDesktop( theModule ) ),
135 mySMESHGUI( theModule ),
136 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
137 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
139 myNameChanged( false )
142 if ( !theGroup->_is_nil() )
143 init( theGroup, theIsConvert );
146 mySelectSubMesh->setEnabled( false );
147 mySelectGroup->setEnabled( false );
149 myCurrentLineEdit = myMeshGroupLine;
150 setSelectionMode( 5 );
154 //=================================================================================
155 // function : SMESHGUI_GroupDlg()
157 //=================================================================================
158 void SMESHGUI_GroupDlg::initDialog( bool create)
161 setAttribute( Qt::WA_DeleteOnClose, true );
165 myCurrentLineEdit = 0;
169 myGeomObjects = new GEOM::ListOfGO();
170 myGeomObjects->length( 0 );
172 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
174 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
175 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
177 setSizeGripEnabled( true);
179 QGridLayout* aMainLayout = new QGridLayout( this );
180 aMainLayout->setMargin( MARGIN );
181 aMainLayout->setSpacing( SPACING );
183 /***************************************************************/
184 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
185 myMeshGroupBtn = new QPushButton( this );
186 myMeshGroupBtn->setIcon( image0 );
187 myMeshGroupLine = new QLineEdit( this );
188 myMeshGroupLine->setReadOnly( true );
190 /***************************************************************/
191 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
192 myTypeGroup = new QButtonGroup( this );
193 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
194 aTypeBoxLayout->setMargin( MARGIN );
195 aTypeBoxLayout->setSpacing( SPACING );
198 types.append( tr( "MESH_NODE" ) );
199 types.append( tr( "SMESH_EDGE" ) );
200 types.append( tr( "SMESH_FACE" ) );
201 types.append( tr( "SMESH_VOLUME" ) );
203 for ( int i = 0; i < types.count(); i++ )
205 rb = new QRadioButton( types[i], aTypeBox );
206 myTypeGroup->addButton( rb, i );
207 aTypeBoxLayout->addWidget( rb );
209 aTypeBox->setEnabled( create );
212 /***************************************************************/
213 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
214 aName->setMinimumWidth( 50 );
215 myName = new QLineEdit( this );
217 /***************************************************************/
218 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
219 myGrpTypeGroup = new QButtonGroup( this );
220 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
221 aGrpTypeBoxLayout->setMargin( MARGIN );
222 aGrpTypeBoxLayout->setSpacing( SPACING );
224 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
225 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
226 myGrpTypeGroup->addButton( rb1, 0 );
227 myGrpTypeGroup->addButton( rb2, 1 );
228 aGrpTypeBoxLayout->addWidget( rb1 );
229 aGrpTypeBoxLayout->addWidget( rb2 );
230 aGrpTypeBox->setEnabled( create );
233 /***************************************************************/
234 myWGStack = new QStackedWidget( this );
235 QWidget* wg1 = new QWidget( myWGStack );
236 QWidget* wg2 = new QWidget( myWGStack );
238 /***************************************************************/
239 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
240 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
241 aContentBoxLayout->setMargin( MARGIN );
242 aContentBoxLayout->setSpacing( SPACING );
244 QLabel* aLabel = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
245 myElements = new QListWidget( aContentBox );
246 myElements->setSelectionMode( QListWidget::ExtendedSelection );
248 myFilter = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
249 QPushButton* aAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
250 QPushButton* aRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
251 QPushButton* aSortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
253 aContentBoxLayout->addWidget( aLabel, 0, 0 );
254 aContentBoxLayout->addWidget( myElements, 1, 0, 6, 1 );
255 aContentBoxLayout->addWidget( myFilter, 1, 1 );
256 aContentBoxLayout->addWidget( aAddBtn, 3, 1 );
257 aContentBoxLayout->addWidget( aRemoveBtn, 4, 1 );
258 aContentBoxLayout->addWidget( aSortBtn, 6, 1 );
260 aContentBoxLayout->setColumnStretch( 0, 1 );
261 aContentBoxLayout->setRowStretch( 2, 1 );
262 aContentBoxLayout->setRowStretch( 5, 1 );
264 /***************************************************************/
265 QGroupBox* aSelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
266 QGridLayout* aSelectBoxLayout = new QGridLayout( aSelectBox );
267 aSelectBoxLayout->setMargin( MARGIN );
268 aSelectBoxLayout->setSpacing( SPACING );
270 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), aSelectBox );
271 mySubMeshBtn = new QPushButton( aSelectBox );
272 mySubMeshBtn->setIcon( image0 );
273 mySubMeshLine = new QLineEdit( aSelectBox );
274 mySubMeshLine->setReadOnly( true );
275 onSelectSubMesh( false );
277 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), aSelectBox );
278 myGroupBtn = new QPushButton( aSelectBox );
279 myGroupBtn->setIcon( image0 );
280 myGroupLine = new QLineEdit( aSelectBox );
281 myGroupLine->setReadOnly( true );
282 onSelectGroup( false );
284 aSelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
285 aSelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
286 aSelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
287 aSelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
288 aSelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
289 aSelectBoxLayout->addWidget( myGroupLine, 1, 2 );
291 /***************************************************************/
292 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
293 wg1Layout->setMargin( 0 );
294 wg1Layout->setSpacing( SPACING );
295 wg1Layout->addWidget( aContentBox );
296 wg1Layout->addWidget( aSelectBox );
297 wg1Layout->setStretchFactor( aContentBox, 10 );
299 /***************************************************************/
300 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
301 myGeomGroupBtn = new QToolButton( wg2 );
302 myGeomGroupBtn->setIcon( image0 );
303 myGeomGroupBtn->setCheckable( true );
304 myGeomGroupLine = new QLineEdit( wg2 );
305 myGeomGroupLine->setReadOnly( true ); //VSR ???
306 onSelectGeomGroup( false );
308 myGeomGroupBtn->setEnabled( create );
309 myGeomGroupLine->setEnabled( create );
311 /***************************************************************/
312 QGridLayout* wg2Layout = new QGridLayout( wg2 );
313 wg2Layout->setMargin( 0 );
314 wg1Layout->setSpacing( SPACING );
315 wg2Layout->addWidget( geomObject, 0, 0 );
316 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
317 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
318 wg2Layout->setRowStretch( 1, 5 );
320 /***************************************************************/
321 myWGStack->insertWidget( 0, wg1 );
322 myWGStack->insertWidget( 1, wg2 );
324 /***************************************************************/
325 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
326 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
327 aColorBoxLayout->setMargin(MARGIN);
328 aColorBoxLayout->setSpacing(SPACING);
330 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
331 myColorBtn = new QtxColorButton(aColorBox);
332 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
333 myColorBtn->sizePolicy().verticalPolicy() );
335 aColorBoxLayout->addWidget(aColorLab);
336 aColorBoxLayout->addWidget(myColorBtn);
338 /***************************************************************/
340 QFrame* aButtons = new QFrame(this);
341 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
342 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
343 aBtnLayout->setMargin(MARGIN);
344 aBtnLayout->setSpacing(SPACING);
346 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
347 myOKBtn->setAutoDefault(true);
348 myOKBtn->setDefault(true);
349 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
350 myApplyBtn->setAutoDefault(true);
351 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
352 myCloseBtn->setAutoDefault(true);
353 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
354 myHelpBtn->setAutoDefault(true);
356 aBtnLayout->addWidget(myOKBtn);
357 aBtnLayout->addSpacing(10);
358 aBtnLayout->addWidget(myApplyBtn);
359 aBtnLayout->addSpacing(10);
360 aBtnLayout->addStretch();
361 aBtnLayout->addWidget(myCloseBtn);
362 aBtnLayout->addWidget(myHelpBtn);
364 /***************************************************************/
365 aMainLayout->addWidget(meshGroupLab, 0, 0);
366 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
367 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
368 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
369 aMainLayout->addWidget(aName, 2, 0);
370 aMainLayout->addWidget(myName, 2, 2);
371 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
372 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
373 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
374 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
376 /* signals and slots connections */
377 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
378 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
379 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
381 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
382 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
384 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
385 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
386 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
387 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
389 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
390 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
391 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
392 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
393 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
395 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
397 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
398 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
399 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
400 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
403 mySMESHGUI->SetActiveDialogBox(this);
404 mySMESHGUI->SetState(800);
406 mySelectionMode = -1;
407 myMeshFilter = new SMESH_TypeFilter(MESH);
408 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
409 myGroupFilter = new SMESH_TypeFilter(GROUP);
410 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
411 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
413 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
414 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
415 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
417 rb1->setChecked(true); // VSR !!!
418 onGrpTypeChanged(0); // VSR!!!
420 if (myMesh->_is_nil() )
421 myTypeGroup->button(0)->setChecked(true);
424 //myName->setText(GetDefaultName(tr( "SMESH_GROUP" )));
427 //=================================================================================
428 // function : ~SMESHGUI_GroupDlg()
429 // purpose : Destroys the object and frees any allocated resources
430 //=================================================================================
431 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
433 // no need to delete child widgets, Qt does it all for us
434 if ( myFilterDlg != 0 ) {
435 myFilterDlg->setParent( 0 );
440 //=================================================================================
441 // function : GetDefaultName()
442 // purpose : Get the Group Name if Create new Group
443 //=================================================================================
444 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
448 // collect all object names of SMESH component
449 SalomeApp_Study* appStudy =
450 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
451 if ( !appStudy ) return aName;
452 _PTR(Study) aStudy = appStudy->studyDS();
454 std::set<std::string> aSet;
455 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
457 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
459 for (it->InitEx(true); it->More(); it->Next()) {
461 aSet.insert(obj->GetName());
465 // build a unique name
467 bool isUnique = false;
469 aName = theOperation + "_" + QString::number(++aNumber);
470 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
476 //=================================================================================
479 //=================================================================================
480 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
482 mySelectionMgr->installFilter(myMeshFilter);
484 /* init data from current selection */
485 restoreShowEntityMode();
486 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
488 myGroup = SMESH::SMESH_Group::_nil();
489 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
491 // NPAL19389: create a group with a selection in another group
492 // set actor of myMesh, if it is visible, else try
493 // any visible actor of group or submesh of myMesh
494 SetAppropriateActor();
496 setDefaultGroupColor();
499 mySelectionMgr->selectedObjects( aList );
500 if( !aList.IsEmpty() )
502 QString aName = aList.First()->getName();
503 myMeshGroupLine->setText(aName);
504 myMeshGroupLine->home( false );
507 myCurrentLineEdit = 0;
509 myTypeGroup->button(0)->setChecked(true);
513 //=================================================================================
516 //=================================================================================
517 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
518 const bool theIsConvert)
520 restoreShowEntityMode();
521 myMesh = theGroup->GetMesh();
524 myNameChanged = true;
525 myName->blockSignals(true);
526 myName->setText(theGroup->GetName());
527 myName->blockSignals(false);
530 SALOMEDS::Color aColor = theGroup->GetColor();
531 setGroupColor( aColor );
533 myMeshGroupLine->setText(theGroup->GetName());
536 switch(theGroup->GetType()) {
537 case SMESH::NODE: aType= 0; break;
538 case SMESH::EDGE: aType = 1; break;
539 case SMESH::FACE: aType = 2; break;
540 case SMESH::VOLUME: aType = 3; break;
542 myTypeGroup->button(aType)->setChecked(true);
544 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
545 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
547 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil())
550 // NPAL19389: create a group with a selection in another group
551 // set actor of myMesh, if it is visible, else set
552 // actor of theGroup, if it is visible, else try
553 // any visible actor of group or submesh of myMesh
554 // commented, because an attempt to set selection on not displayed cells leads to error
555 //SetAppropriateActor();
556 myActor = SMESH::FindActorByObject(myMesh);
558 myActor = SMESH::FindActorByObject(theGroup);
559 SMESH::SetPickable(myActor);
561 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : 1));
562 myGrpTypeGroup->button(grpType)->setChecked(true);
563 onGrpTypeChanged(grpType);
566 if ( grpType == 0 ) {
567 myCurrentLineEdit = 0;
569 setSelectionMode(aType);
571 setShowEntityMode(); // depends on myTypeId
574 if (!theGroup->IsEmpty()) {
575 SMESH::long_array_var anElements = theGroup->GetListOfID();
576 int k = anElements->length();
577 for (int i = 0; i < k; i++) {
578 myIdList.append(anElements[i]);
579 myElements->addItem(QString::number(anElements[i]));
581 myElements->selectAll();
586 QString aShapeName( "" );
587 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
588 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
589 if (!aGroupShape->_is_nil())
591 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
592 aShapeName = aGroupShapeSO->GetName().c_str();
594 myGeomGroupLine->setText( aShapeName );
595 myNameChanged = true;
596 myName->blockSignals(true);
597 myName->setText(theGroup->GetName());
598 myName->blockSignals(false);
603 //=================================================================================
604 // function : updateButtons()
606 //=================================================================================
607 void SMESHGUI_GroupDlg::updateButtons()
609 bool enable = !myName->text().trimmed().isEmpty();
611 if (myGrpTypeId == 0) {
612 enable = enable && myElements->count() > 0;
613 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
615 else if (myGrpTypeId == 1) {
616 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
617 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
621 myOKBtn->setEnabled(enable);
622 myApplyBtn->setEnabled(enable);
625 //=================================================================================
626 // function : onNameChanged()
628 //=================================================================================
629 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
631 myOldName = myName->text();
633 myNameChanged = !myName->text().trimmed().isEmpty();
636 //=================================================================================
637 // function : onTypeChanged()
638 // purpose : Group elements type radio button management
639 //=================================================================================
640 void SMESHGUI_GroupDlg::onTypeChanged (int id)
642 if (myTypeId != id) {
644 if (myCurrentLineEdit == 0)
645 setSelectionMode(id);
651 //=================================================================================
652 // function : onGrpTypeChanged()
653 // purpose : Group type radio button management
654 //=================================================================================
655 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
657 if (myGrpTypeId != id) {
658 myWGStack->setCurrentIndex( id );
659 myName->blockSignals(true);
660 myName->setText(myOldName);
661 myName->blockSignals(false);
662 onSelectGeomGroup(id == 1);
667 //=================================================================================
668 // function : onColorChanged()
669 // purpose : Color button management
670 //=================================================================================
671 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
676 //=================================================================================
677 // function : setSelectionMode()
678 // purpose : Radio button management
679 //=================================================================================
680 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
683 if (myMesh->_is_nil())
685 if (mySelectionMode != theMode) {
686 // [PAL10408] mySelectionMgr->clearSelected();
687 mySelectionMgr->clearFilters();
689 myActor->SetPointRepresentation(false);
691 SMESH::SetPointRepresentation(false);
696 myActor->SetPointRepresentation(true);
698 SMESH::SetPointRepresentation(true);
699 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
700 aViewWindow->SetSelectionMode(NodeSelection);
703 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
704 aViewWindow->SetSelectionMode(EdgeSelection);
707 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
708 aViewWindow->SetSelectionMode(FaceSelection);
711 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
712 aViewWindow->SetSelectionMode(VolumeSelection);
716 mySelectionMgr->installFilter(mySubMeshFilter);
717 else if (theMode == 5)
718 mySelectionMgr->installFilter(myGroupFilter);
719 else if (theMode == 6)
720 mySelectionMgr->installFilter(myMeshFilter);
721 else if (theMode == 7)
722 mySelectionMgr->installFilter(myGeomFilter);
724 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
725 aViewWindow->SetSelectionMode(ActorSelection);
727 mySelectionMode = theMode;
731 //=================================================================================
732 // function : onApply()
734 //=================================================================================
735 bool SMESHGUI_GroupDlg::onApply()
737 if (mySMESHGUI->isActiveStudyLocked())
740 if (myName->text().trimmed().isEmpty())
743 if (myGrpTypeId == 0) { // on mesh elements
744 if (!myElements->count())
747 mySelectionMgr->clearSelected();
749 if (myGroup->_is_nil()) { // creation or conversion
750 // check if group on geometry is not null
751 if (!CORBA::is_nil(myGroupOnGeom)) {
752 if (myMesh->_is_nil())
754 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
755 // nullify pointer, because object become dead
756 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
760 if (myGroup->_is_nil()) { // creation
761 if (myMesh->_is_nil())
764 SMESH::ElementType aType = SMESH::ALL;
766 case 0: aType = SMESH::NODE; break;
767 case 1: aType = SMESH::EDGE; break;
768 case 2: aType = SMESH::FACE; break;
769 case 3: aType = SMESH::VOLUME; break;
772 SMESH::long_array_var anIdList = new SMESH::long_array;
773 int i, k = myElements->count();
775 for (i = 0; i < k; i++) {
776 anIdList[i] = myElements->item(i)->text().toInt();
779 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
780 myGroup->Add(anIdList.inout());
782 SALOMEDS::Color aColor = getGroupColor();
783 myGroup->SetColor(aColor);
785 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
787 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
788 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
790 /* init for next operation */
791 myName->setText( "" );
793 myGroup = SMESH::SMESH_Group::_nil();
796 myGroup->SetName(myName->text().toLatin1().data());
798 SALOMEDS::Color aColor = getGroupColor();
799 myGroup->SetColor(aColor);
801 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
802 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
803 anActor->setName(myName->text().toLatin1().data());
804 switch ( myTypeId ) {
805 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
806 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
808 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
814 int i, total = myElements->count();
815 for (i = 0; i < total; i++) {
816 int anId = myElements->item(i)->text().toInt();
817 int idx = myIdList.indexOf(anId);
819 aAddList.append(anId);
821 myIdList.removeAt(idx);
823 if (!aAddList.empty()) {
824 SMESH::long_array_var anIdList = new SMESH::long_array;
825 int added = aAddList.count();
826 anIdList->length(added);
827 for (i = 0; i < added; i++)
828 anIdList[i] = aAddList[i];
829 myGroup->Add(anIdList.inout());
831 if (!myIdList.empty()) {
832 SMESH::long_array_var anIdList = new SMESH::long_array;
833 int removed = myIdList.count();
834 anIdList->length(removed);
835 for (i = 0; i < removed; i++)
836 anIdList[i] = myIdList[i];
837 myGroup->Remove(anIdList.inout());
839 /* init for next operation */
841 for (i = 0; i < total; i++) {
842 myIdList.append(myElements->item(i)->text().toInt());
846 mySMESHGUI->updateObjBrowser(true);
847 SMESH::UpdateView(); // asv: fix of BUG PAL5515
848 mySelectionMgr->clearSelected();
851 else if (myGrpTypeId == 1) { // on geom object
852 if (CORBA::is_nil(myGroupOnGeom)) { // creation
853 if (myMesh->_is_nil() || !myGeomObjects->length())
856 SMESH::ElementType aType = SMESH::ALL;
858 case 0: aType = SMESH::NODE; break;
859 case 1: aType = SMESH::EDGE; break;
860 case 2: aType = SMESH::FACE; break;
861 case 3: aType = SMESH::VOLUME; break;
864 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
865 GEOM::GEOM_IGroupOperations_var aGroupOp =
866 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
868 if (myGeomObjects->length() == 1) {
869 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
870 myName->text().toLatin1().data(),
874 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
875 if ( aSMESHGen->_is_nil() )
878 // create a geometry group
879 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
880 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
882 if (geomGen->_is_nil() || !aStudy)
885 GEOM::GEOM_IGroupOperations_var op =
886 geomGen->GetIGroupOperations(aStudy->StudyId());
890 // check and add all selected GEOM objects: they must be
891 // a sub-shapes of the main GEOM and must be of one type
892 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
893 for ( int i =0; i < myGeomObjects->length(); i++) {
894 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
896 aGroupType = aSubShapeType;
897 else if (aSubShapeType != aGroupType) {
898 aGroupType = TopAbs_SHAPE;
903 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
904 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
905 op->UnionList(aGroupVar, myGeomObjects);
908 // publish the GEOM group in study
909 QString aNewGeomGroupName ( "Auto_group_for_" );
910 aNewGeomGroupName += myName->text();
911 SALOMEDS::SObject_var aNewGroupSO =
912 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
913 aNewGeomGroupName.toLatin1().data(), aMeshShape);
916 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
917 myName->text().toLatin1().data(),
921 SALOMEDS::Color aColor = getGroupColor();
922 myGroupOnGeom->SetColor(aColor);
924 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
926 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
927 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
929 /* init for next operation */
930 myName->setText( "" );
931 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
934 myGroupOnGeom->SetName(myName->text().toLatin1().data());
936 SALOMEDS::Color aColor = getGroupColor();
937 myGroupOnGeom->SetColor(aColor);
939 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
940 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
941 anActor->setName(myName->text().toLatin1().data());
942 switch ( myTypeId ) {
943 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
944 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
946 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
951 mySMESHGUI->updateObjBrowser(true);
952 mySelectionMgr->clearSelected();
959 //=================================================================================
962 //=================================================================================
963 void SMESHGUI_GroupDlg::onOK()
969 //=================================================================================
970 // function : onListSelectionChanged()
971 // purpose : Called when selection in element list is changed
972 //=================================================================================
973 void SMESHGUI_GroupDlg::onListSelectionChanged()
975 // MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
976 if( myIsBusy || !myActor) return;
979 if (myCurrentLineEdit == 0) {
980 mySelectionMgr->clearSelected();
981 TColStd_MapOfInteger aIndexes;
982 QList<QListWidgetItem*> selItems = myElements->selectedItems();
983 QListWidgetItem* anItem;
984 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
985 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
987 aList.Append(myActor->getIO());
988 mySelectionMgr->setSelectedObjects(aList,false);
993 //=================================================================================
994 // function : onObjectSelectionChanged()
995 // purpose : Called when selection in 3D view or ObjectBrowser is changed
996 //=================================================================================
997 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
999 if ( myIsBusy || !isEnabled()) return;
1000 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1004 SALOME_ListIO aList;
1005 mySelectionMgr->selectedObjects( aList );
1007 int aNbSel = aList.Extent();
1008 myElements->clearSelection();
1010 if (myCurrentLineEdit)
1012 myCurrentLineEdit->setText( "" );
1013 QString aString = "";
1015 if (myCurrentLineEdit == myMeshGroupLine)
1017 mySelectSubMesh->setEnabled(false);
1018 mySelectGroup->setEnabled(false);
1019 myGroupLine->setText( "" );
1020 mySubMeshLine->setText( "" );
1022 myGeomGroupBtn->setEnabled(false);
1023 myGeomGroupLine->setEnabled(false);
1024 myGeomGroupLine->setText( "" );
1025 myGeomObjects = new GEOM::ListOfGO();
1026 myGeomObjects->length(0);
1028 if (myGeomGroupBtn->isChecked())
1029 myGeomGroupBtn->setChecked(false);
1031 myName->setText( "" );
1033 myElements->clear();
1036 myGroup = SMESH::SMESH_Group::_nil();
1037 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1038 restoreShowEntityMode();
1039 myMesh = SMESH::SMESH_Mesh::_nil();
1045 Handle(SALOME_InteractiveObject) IO = aList.First();
1048 restoreShowEntityMode();
1049 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1050 setShowEntityMode();
1052 if (myMesh->_is_nil())
1058 myGroup = SMESH::SMESH_Group::_nil();
1060 // NPAL19389: create a group with a selection in another group
1061 // set actor of myMesh, if it is visible, else try
1062 // any visible actor of group or submesh of myMesh
1063 SetAppropriateActor();
1065 aString = aList.First()->getName();
1066 myMeshGroupLine->setText(aString);
1067 myMeshGroupLine->home( false );
1069 mySelectSubMesh->setEnabled(true);
1070 mySelectGroup->setEnabled(true);
1071 myGeomGroupBtn->setEnabled(true);
1072 myGeomGroupLine->setEnabled(true);
1076 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1077 if (aGroup->_is_nil())
1083 myCurrentLineEdit = 0;
1085 myGroup = SMESH::SMESH_Group::_nil();
1086 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1090 mySelectSubMesh->setEnabled(true);
1091 mySelectGroup->setEnabled(true);
1093 myCurrentLineEdit = 0;
1098 if (myGrpTypeId == 0)
1104 myElements->clear();
1105 setSelectionMode(myTypeId);
1113 else if (myCurrentLineEdit == myGeomGroupLine)
1115 myGeomObjects = new GEOM::ListOfGO();
1118 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1120 if (aNbSel == 0 || !aMeshSO)
1122 myGeomObjects->length(0);
1128 myGeomObjects->length(aNbSel);
1130 GEOM::GEOM_Object_var aGeomGroup;
1131 Standard_Boolean testResult;
1134 SALOME_ListIteratorOfListIO anIt (aList);
1135 for (; anIt.More(); anIt.Next())
1137 testResult = Standard_False;
1138 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1140 // Check if the object is a geometry group
1141 if (!testResult || CORBA::is_nil(aGeomGroup))
1144 // Check if group constructed on the same shape as a mesh or on its child
1145 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1146 GEOM::GEOM_IGroupOperations_var anOp =
1147 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1149 // The main shape of the group
1150 GEOM::GEOM_Object_var aGroupMainShape;
1151 if (aGeomGroup->GetType() == 37)
1152 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1154 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1155 _PTR(SObject) aGroupMainShapeSO =
1156 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1157 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1159 _PTR(SObject) anObj, aRef;
1160 bool isRefOrSubShape = false;
1161 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1162 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1163 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1164 isRefOrSubShape = true;
1166 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1167 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1168 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1169 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1170 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1171 if (aRef->GetID() == aFather->GetID())
1172 isRefOrSubShape = true;
1174 aFather = aFather->GetFather();
1178 if (isRefOrSubShape)
1179 myGeomObjects[i++] = aGeomGroup;
1182 myGeomObjects->length(i);
1194 if (myCurrentLineEdit == mySubMeshLine)
1195 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1196 else if (myCurrentLineEdit == myGroupLine)
1197 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1198 else if (myCurrentLineEdit == myGeomGroupLine)
1199 aString = tr( "%1 Objects" ).arg(aNbSel);
1202 aString = aList.First()->getName();
1206 myCurrentLineEdit->setText(aString);
1207 myCurrentLineEdit->home(false);
1208 // 07.06.2008 skl for IPAL19574:
1209 // change name of group only if it is empty
1210 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1211 myOldName = myName->text();
1212 myName->blockSignals(true);
1213 myName->setText(aString);
1214 myName->blockSignals(false);
1219 else // !myCurrentLineEdit: local selection of nodes or elements
1221 if (aNbSel == 1 && myActor && myActor->hasIO())
1223 #ifdef ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
1224 // NPAL19389: create a group with a selection in another group
1225 // Switch myActor to the newly selected one, if the last
1226 // is visible and belongs to group or submesh of myMesh
1227 Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1228 Handle(SALOME_InteractiveObject) selIO = aList.First();
1229 if (curIO->hasEntry() && selIO->hasEntry()) {
1230 const char* selEntry = selIO->getEntry();
1231 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1232 // different objects: selected and myActor
1233 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1234 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1235 // newly selected actor is visible
1238 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1240 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1241 int len = strlen(meshEntry);
1243 if (strncmp(selEntry, meshEntry, len) == 0) {
1244 // selected object is myMesh or a part of it
1245 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1248 SMESH::SetPickable(myActor);
1256 #endif // ENABLE_SWITCH_ACTOR_DURING_ELEMENTS_SELECTION
1258 QString aListStr = "";
1260 if (myTypeId == 0) {
1261 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1263 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1266 QListWidgetItem* anItem;
1267 QList<QListWidgetItem*> listItemsToSel;
1268 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1269 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1270 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1271 foreach(anItem, found)
1272 if (!anItem->isSelected())
1273 listItemsToSel.push_back(anItem);
1275 bool blocked = myElements->signalsBlocked();
1276 myElements->blockSignals(true);
1277 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1278 myElements->blockSignals(blocked);
1279 onListSelectionChanged();
1280 listItemsToSel.clear();
1286 if (!myGroup->_is_nil())
1287 myActor = SMESH::FindActorByObject(myGroup);
1288 else if(!myGroupOnGeom->_is_nil())
1289 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1291 myActor = SMESH::FindActorByObject(myMesh);
1294 // somehow, if we display the mesh, while selecting from another actor,
1295 // the mesh becomes pickable, and there is no way to select any element
1297 SMESH::SetPickable(myActor);
1302 //=================================================================================
1303 // function : onSelectSubMesh()
1304 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1305 //=================================================================================
1306 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1309 if (mySelectGroup->isChecked()) {
1310 mySelectGroup->setChecked(false);
1312 //VSR: else if (mySelectGeomGroup->isChecked()) {
1313 //VSR: mySelectGeomGroup->setChecked(false);
1315 myCurrentLineEdit = mySubMeshLine;
1316 setSelectionMode(4);
1319 mySubMeshLine->setText( "" );
1320 myCurrentLineEdit = 0;
1322 setSelectionMode(myTypeId);
1324 mySubMeshBtn->setEnabled(on);
1325 mySubMeshLine->setEnabled(on);
1329 //=================================================================================
1330 // function : (onSelectGroup)
1331 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1332 //=================================================================================
1333 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1336 if (mySelectSubMesh->isChecked()) {
1337 mySelectSubMesh->setChecked(false);
1339 myCurrentLineEdit = myGroupLine;
1340 setSelectionMode(5);
1343 myGroupLine->setText( "" );
1344 myCurrentLineEdit = 0;
1346 setSelectionMode(myTypeId);
1348 myGroupBtn->setEnabled(on);
1349 myGroupLine->setEnabled(on);
1353 //=================================================================================
1354 // function : (onSelectGeomGroup)
1355 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1356 //=================================================================================
1357 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1360 if (mySelectSubMesh->isChecked()) {
1361 mySelectSubMesh->setChecked(false);
1363 else if (mySelectGroup->isChecked()) {
1364 mySelectGroup->setChecked(false);
1366 myCurrentLineEdit = myGeomGroupLine;
1368 setSelectionMode(8);
1371 myGeomGroupBtn->setChecked(false);
1372 myGeomObjects->length(0);
1373 myGeomGroupLine->setText( "" );
1374 myCurrentLineEdit = 0;
1376 setSelectionMode(myTypeId);
1381 //=================================================================================
1382 // function : setCurrentSelection()
1384 //=================================================================================
1385 void SMESHGUI_GroupDlg::setCurrentSelection()
1387 QPushButton* send = (QPushButton*)sender();
1388 myCurrentLineEdit = 0;
1389 if (send == myMeshGroupBtn) {
1390 myCurrentLineEdit = myMeshGroupLine;
1392 setSelectionMode(6);
1394 setSelectionMode(5);
1395 onObjectSelectionChanged();
1397 else if (send == mySubMeshBtn) {
1398 myCurrentLineEdit = mySubMeshLine;
1399 onObjectSelectionChanged();
1401 else if (send == myGroupBtn) {
1402 myCurrentLineEdit = myGroupLine;
1403 onObjectSelectionChanged();
1408 //=================================================================================
1409 // function : setFilters()
1410 // purpose : SLOT. Called when "Filter" button pressed.
1411 //=================================================================================
1412 void SMESHGUI_GroupDlg::setFilters()
1414 if(myMesh->_is_nil()) {
1415 SUIT_MessageBox::critical(this,
1417 tr("NO_MESH_SELECTED"));
1421 SMESH::ElementType aType = SMESH::ALL;
1424 case 0 : aType = SMESH::NODE; break;
1425 case 1 : aType = SMESH::EDGE; break;
1426 case 2 : aType = SMESH::FACE; break;
1427 case 3 : aType = SMESH::VOLUME; break;
1431 if ( myFilterDlg == 0 )
1433 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1434 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1437 myFilterDlg->Init( aType );
1439 myFilterDlg->SetSelection();
1440 myFilterDlg->SetMesh( myMesh );
1441 myFilterDlg->SetSourceWg( myElements, false );
1443 myFilterDlg->show();
1446 //=================================================================================
1447 // function : onFilterAccepted()
1448 // purpose : SLOT. Called when Filter dlg closed with OK button.
1449 // Uncheck "Select submesh" and "Select group" checkboxes
1450 //=================================================================================
1451 void SMESHGUI_GroupDlg::onFilterAccepted()
1453 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1455 mySelectionMode = myTypeId;
1456 mySelectSubMesh->setChecked( false );
1457 mySelectGroup->setChecked( false );
1461 //=================================================================================
1462 // function : onAdd()
1464 //=================================================================================
1465 void SMESHGUI_GroupDlg::onAdd()
1467 SALOME_ListIO aList;
1468 mySelectionMgr->selectedObjects( aList );
1470 int aNbSel = aList.Extent();
1472 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1476 SMESH::ElementType aType = SMESH::ALL;
1479 aType = SMESH::NODE;
1480 mySelector->SetSelectionMode(NodeSelection);
1483 aType = SMESH::EDGE;
1484 mySelector->SetSelectionMode(EdgeSelection);
1487 aType = SMESH::FACE;
1488 mySelector->SetSelectionMode(FaceSelection);
1491 aType = SMESH::VOLUME;
1492 mySelector->SetSelectionMode(VolumeSelection);
1495 mySelector->SetSelectionMode(ActorSelection);
1498 QListWidgetItem* anItem = 0;
1499 QList<QListWidgetItem*> listItemsToSel;
1501 if (myCurrentLineEdit == 0) {
1502 //if (aNbSel != 1) { myIsBusy = false; return; }
1503 QString aListStr = "";
1505 if (myTypeId == 0) {
1506 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1509 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1512 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1513 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1514 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1515 if (found.count() == 0) {
1516 anItem = new QListWidgetItem(*it);
1517 myElements->addItem(anItem);
1518 if (!anItem->isSelected())
1519 listItemsToSel.push_back(anItem);
1522 foreach(anItem, found)
1523 if (!anItem->isSelected())
1524 listItemsToSel.push_back(anItem);
1527 bool blocked = myElements->signalsBlocked();
1528 myElements->blockSignals(true);
1529 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1530 myElements->blockSignals(blocked);
1531 onListSelectionChanged();
1532 listItemsToSel.clear();
1534 } else if (myCurrentLineEdit == mySubMeshLine) {
1535 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1537 SALOME_ListIO aList;
1538 mySelectionMgr->selectedObjects( aList );
1540 SALOME_ListIteratorOfListIO anIt (aList);
1541 for ( ; anIt.More(); anIt.Next()) {
1542 SMESH::SMESH_subMesh_var aSubMesh =
1543 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1544 if (!aSubMesh->_is_nil()) {
1545 // check if mesh is the same
1546 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1548 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1549 int k = anElements->length();
1550 for (int i = 0; i < k; i++) {
1551 QString aText = QString::number(anElements[i]);
1552 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1553 if (found.count() == 0) {
1554 anItem = new QListWidgetItem(aText);
1555 myElements->addItem(anItem);
1556 if (!anItem->isSelected())
1557 listItemsToSel.push_back(anItem);
1560 foreach(anItem, found)
1561 if (!anItem->isSelected())
1562 listItemsToSel.push_back(anItem);
1565 bool blocked = myElements->signalsBlocked();
1566 myElements->blockSignals(true);
1567 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1568 myElements->blockSignals(blocked);
1569 onListSelectionChanged();
1570 listItemsToSel.clear();
1572 catch (const SALOME::SALOME_Exception& ex) {
1573 SalomeApp_Tools::QtCatchCorbaException(ex);
1578 mySelectSubMesh->setChecked(false);
1580 onListSelectionChanged();
1582 } else if (myCurrentLineEdit == myGroupLine) {
1583 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1584 SALOME_ListIO aList;
1585 mySelectionMgr->selectedObjects( aList );
1587 SALOME_ListIteratorOfListIO anIt (aList);
1588 for ( ; anIt.More(); anIt.Next()) {
1589 SMESH::SMESH_GroupBase_var aGroup =
1590 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1591 if (!aGroup->_is_nil()) {
1592 // check if mesh is the same
1593 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1594 SMESH::long_array_var anElements = aGroup->GetListOfID();
1595 int k = anElements->length();
1596 for (int i = 0; i < k; i++) {
1597 QString aText = QString::number(anElements[i]);
1598 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1599 if (found.count() == 0) {
1600 anItem = new QListWidgetItem(aText);
1601 myElements->addItem(anItem);
1602 if (!anItem->isSelected())
1603 listItemsToSel.push_back(anItem);
1606 foreach(anItem, found)
1607 if (!anItem->isSelected())
1608 listItemsToSel.push_back(anItem);
1611 bool blocked = myElements->signalsBlocked();
1612 myElements->blockSignals(true);
1613 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1614 myElements->blockSignals(blocked);
1615 onListSelectionChanged();
1616 listItemsToSel.clear();
1620 mySelectGroup->setChecked(false);
1622 onListSelectionChanged();
1624 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1625 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1626 GEOM::GEOM_IGroupOperations_var aGroupOp =
1627 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1629 SMESH::ElementType aGroupType = SMESH::ALL;
1630 switch(aGroupOp->GetType(myGeomObjects[0])) {
1631 case 7: aGroupType = SMESH::NODE; break;
1632 case 6: aGroupType = SMESH::EDGE; break;
1633 case 4: aGroupType = SMESH::FACE; break;
1634 case 2: aGroupType = SMESH::VOLUME; break;
1635 default: myIsBusy = false; return;
1638 if (aGroupType == aType) {
1639 _PTR(SObject) aGroupSO =
1640 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1641 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1643 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1644 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1645 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1646 aBelongToGeom->SetGeom(myGeomObjects[0]);
1647 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1648 aBelongToGeom->SetElementType(aType);
1649 aFilter->SetPredicate(aBelongToGeom);
1651 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1653 int k = anElements->length();
1654 for (int i = 0; i < k; i++) {
1655 QString aText = QString::number(anElements[i]);
1656 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1657 if (found.count() == 0) {
1658 anItem = new QListWidgetItem(aText);
1659 myElements->addItem(anItem);
1660 if (!anItem->isSelected())
1661 listItemsToSel.push_back(anItem);
1664 foreach(anItem, found)
1665 if (!anItem->isSelected())
1666 listItemsToSel.push_back(anItem);
1669 bool blocked = myElements->signalsBlocked();
1670 myElements->blockSignals(true);
1671 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1672 myElements->blockSignals(blocked);
1673 onListSelectionChanged();
1674 listItemsToSel.clear();
1677 //VSR: mySelectGeomGroup->setChecked(false);
1679 onListSelectionChanged();
1682 // mySelectionMgr->clearSelected();
1686 //=================================================================================
1687 // function : onRemove()
1689 //=================================================================================
1690 void SMESHGUI_GroupDlg::onRemove()
1693 if (myCurrentLineEdit == 0) {
1694 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1695 QListWidgetItem* item;
1696 foreach(item, selItems) delete item;
1698 SALOME_ListIO aList;
1699 mySelectionMgr->selectedObjects( aList );
1701 int aNbSel = aList.Extent();
1703 if (aNbSel == 0) { myIsBusy = false; return; }
1705 SMESH::ElementType aType = SMESH::ALL;
1707 case 0: aType = SMESH::NODE; break;
1708 case 1: aType = SMESH::EDGE; break;
1709 case 2: aType = SMESH::FACE; break;
1710 case 3: aType = SMESH::VOLUME; break;
1713 if (myCurrentLineEdit == mySubMeshLine) {
1714 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1715 SALOME_ListIO aList;
1716 mySelectionMgr->selectedObjects( aList );
1718 SALOME_ListIteratorOfListIO anIt (aList);
1719 for ( ; anIt.More(); anIt.Next()) {
1720 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1721 if (!aSubMesh->_is_nil()) {
1722 // check if mesh is the same
1723 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1724 if (aType == SMESH::NODE) {
1726 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1727 int k = anElements->length();
1728 for (int i = 0; i < k; i++) {
1729 QList<QListWidgetItem*> found =
1730 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1731 QListWidgetItem* anItem;
1732 foreach(anItem, found) delete anItem;
1735 catch (const SALOME::SALOME_Exception& ex) {
1736 SalomeApp_Tools::QtCatchCorbaException(ex);
1741 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1742 int k = anElements->length();
1743 for (int i = 0; i < k; i++) {
1744 QList<QListWidgetItem*> found =
1745 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1746 QListWidgetItem* anItem;
1747 foreach(anItem, found) delete anItem;
1750 catch (const SALOME::SALOME_Exception& ex) {
1751 SalomeApp_Tools::QtCatchCorbaException(ex);
1758 else if (myCurrentLineEdit == myGroupLine) {
1759 Standard_Boolean aRes;
1760 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1761 SALOME_ListIO aList;
1762 mySelectionMgr->selectedObjects( aList );
1764 SALOME_ListIteratorOfListIO anIt (aList);
1765 for ( ; anIt.More(); anIt.Next()) {
1766 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1767 if (aRes && !aGroup->_is_nil()) {
1768 // check if mesh is the same
1769 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1770 SMESH::long_array_var anElements = aGroup->GetListOfID();
1771 int k = anElements->length();
1772 for (int i = 0; i < k; i++) {
1773 QList<QListWidgetItem*> found =
1774 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1775 QListWidgetItem* anItem;
1776 foreach(anItem, found) delete anItem;
1787 //=================================================================================
1788 // function : onSort()
1790 //=================================================================================
1791 void SMESHGUI_GroupDlg::onSort()
1793 // PAL5412: sorts items in ascending by "string" value
1794 // myElements->sort(true);
1795 // myElements->update();
1796 int i, k = myElements->count();
1799 QList<int> aSelected;
1800 std::vector<int> anArray(k);
1801 // QMemArray<int> anArray(k);
1803 for (i = 0; i < k; i++) {
1804 int id = myElements->item(i)->text().toInt();
1806 if (myElements->item(i)->isSelected())
1807 aSelected.append(id);
1809 // sort & update list
1810 std::sort(anArray.begin(), anArray.end());
1812 myElements->clear();
1813 QListWidgetItem* anItem;
1814 QList<QListWidgetItem*> listItemsToSel;
1815 for (i = 0; i < k; i++) {
1816 anItem = new QListWidgetItem(QString::number(anArray[i]));
1817 myElements->addItem(anItem);
1818 if (aSelected.contains(anArray[i]))
1819 listItemsToSel.push_back(anItem);
1821 bool blocked = myElements->signalsBlocked();
1822 myElements->blockSignals(true);
1823 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1824 myElements->blockSignals(blocked);
1825 listItemsToSel.clear();
1830 //=================================================================================
1831 // function : closeEvent()
1833 //=================================================================================
1834 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1839 //=================================================================================
1840 // function : SMESHGUI_GroupDlg::onClose
1841 // purpose : SLOT called when "Close" button pressed. Close dialog
1842 //=================================================================================
1843 void SMESHGUI_GroupDlg::onClose()
1845 if (SMESH::GetCurrentVtkView()) {
1846 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1847 SMESH::SetPointRepresentation(false);
1848 SMESH::SetPickable();
1849 restoreShowEntityMode();
1852 mySelectionMgr->clearSelected();
1853 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1854 aViewWindow->SetSelectionMode(ActorSelection);
1855 mySelectionMgr->clearFilters();
1856 mySMESHGUI->ResetState();
1861 //=================================================================================
1862 // function : onHelp()
1864 //=================================================================================
1865 void SMESHGUI_GroupDlg::onHelp()
1867 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1869 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1873 platform = "winapplication";
1875 platform = "application";
1877 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1878 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1879 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1881 arg(myHelpFileName));
1885 //=================================================================================
1886 // function : SMESHGUI_GroupDlg::onDeactivate
1887 // purpose : SLOT called when dialog must be deativated
1888 //=================================================================================
1889 void SMESHGUI_GroupDlg::onDeactivate()
1891 mySMESHGUI->ResetState();
1895 //=================================================================================
1896 // function : SMESHGUI_GroupDlg::enterEvent
1897 // purpose : Event filter
1898 //=================================================================================
1899 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1902 mySMESHGUI->EmitSignalDeactivateDialog();
1904 mySelectionMode = -1;
1905 setSelectionMode(myTypeId);
1906 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1907 mySMESHGUI->SetActiveDialogBox(this);
1908 mySMESHGUI->SetState(800);
1912 //=================================================================================
1913 // function : hideEvent
1914 // purpose : caused by ESC key
1915 //=================================================================================
1916 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1918 if (!isMinimized() && !myIsBusy)
1922 //=================================================================================
1923 // function : keyPressEvent()
1925 //=================================================================================
1926 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1928 QDialog::keyPressEvent( e );
1929 if ( e->isAccepted() )
1932 if ( e->key() == Qt::Key_F1 )
1939 //================================================================================
1941 * \brief Enable showing of the popup when Geometry selection btn is clicked
1942 * \param enable - true to enable
1944 //================================================================================
1946 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1948 void SMESHGUI_GroupDlg::updateGeomPopup()
1950 bool enable = false;
1952 if ( !myMesh->_is_nil() )
1953 enable = myMesh->NbEdges() > 0;
1955 if ( myGeomGroupBtn )
1957 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1959 if ( !myGeomPopup ) {
1960 myGeomPopup = new QMenu(this);
1961 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
1962 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
1963 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
1965 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1971 //=================================================================================
1972 // function : onGeomSelectionButton()
1974 //=================================================================================
1975 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1977 if ( myGeomPopup && isBtnOn )
1979 myCurrentLineEdit = myGeomGroupLine;
1980 QAction* a = myGeomPopup->exec( QCursor::pos() );
1981 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
1982 setSelectionMode(7);
1986 myCurrentLineEdit = 0;
1987 setSelectionMode(8);
1991 //=================================================================================
1992 // function : onGeomPopup()
1994 //=================================================================================
1995 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
1997 int index = myActions[a];
1998 if ( index == GEOM_BY_MESH_INDEX )
2000 mySelectionMode = -1;
2001 if ( !myShapeByMeshOp ) {
2002 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2003 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2004 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2005 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2006 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2008 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2009 if ( !myMesh->_is_nil() ) {
2011 hide(); // stop processing selection
2013 myShapeByMeshOp->setModule( mySMESHGUI );
2014 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2015 myShapeByMeshOp->SetMesh( myMesh );
2016 myShapeByMeshOp->start();
2021 //================================================================================
2023 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2025 //================================================================================
2027 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2029 if ( myShapeByMeshOp == op ) {
2030 mySMESHGUI->getApp()->updateObjectBrowser();
2032 // Select a found geometry object
2033 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2034 if ( !aGeomVar->_is_nil() )
2036 QString ID = aGeomVar->GetStudyEntry();
2037 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2038 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2039 SALOME_ListIO anIOList;
2040 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2041 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2042 anIOList.Append( anIO );
2043 mySelectionMgr->setSelectedObjects( anIOList, false );
2044 onObjectSelectionChanged();
2050 //================================================================================
2052 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2054 //================================================================================
2056 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2058 if ( myShapeByMeshOp == op )
2061 setSelectionMode(7);
2065 //=================================================================================
2066 // function : setGroupColor()
2068 //=================================================================================
2069 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2071 QColor aQColor( (int)( theColor.R * 255.0 ),
2072 (int)( theColor.G * 255.0 ),
2073 (int)( theColor.B * 255.0 ) );
2074 setGroupQColor( aQColor );
2077 //=================================================================================
2078 // function : getGroupColor()
2080 //=================================================================================
2081 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2083 QColor aQColor = getGroupQColor();
2085 SALOMEDS::Color aColor;
2086 aColor.R = (float)aQColor.red() / 255.0;
2087 aColor.G = (float)aQColor.green() / 255.0;
2088 aColor.B = (float)aQColor.blue() / 255.0;
2093 //=================================================================================
2094 // function : setGroupQColor()
2096 //=================================================================================
2097 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2099 if( theColor.isValid() )
2100 myColorBtn->setColor( theColor );
2103 //=================================================================================
2104 // function : getGroupQColor()
2106 //=================================================================================
2107 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2109 return myColorBtn->color();
2112 //=================================================================================
2113 // function : setDefaultGroupColor()
2115 //=================================================================================
2116 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2118 if( myMesh->_is_nil() )
2121 bool isAutoColor = myMesh->GetAutoColor();
2126 int r = 0, g = 0, b = 0;
2127 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2128 aQColor.setRgb( r, g, b );
2132 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2134 QList<SALOMEDS::Color> aReservedColors;
2135 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2137 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2138 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2139 aReservedColors.append( aReservedColor );
2142 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2143 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2144 (int)( aColor.G * 255.0 ),
2145 (int)( aColor.B * 255.0 ) );
2149 setGroupQColor( aQColor );
2152 //=================================================================================
2153 // function : SetAppropriateActor()
2154 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2155 // NPAL19389: create a group with a selection in another group.
2156 // if mesh actor is not visible - find any first visible group or submesh
2157 //=================================================================================
2158 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2160 bool isActor = false;
2162 if (myMesh->_is_nil()) return false;
2164 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2167 myActor = SMESH::FindActorByObject(myMesh);
2168 if (myActor && myActor->hasIO())
2171 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2175 // try current group actor
2177 if (!myGroup->_is_nil()) {
2178 myActor = SMESH::FindActorByObject(myGroup);
2179 if (myActor && myActor->hasIO())
2182 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2188 // try current group on geometry actor
2190 if (!myGroupOnGeom->_is_nil()) {
2191 myActor = SMESH::FindActorByObject(myGroupOnGeom);
2192 if (myActor && myActor->hasIO())
2195 if (aViewWindow && !aViewWindow->isVisible(myActor->getIO()))
2201 // try any visible actor of group or submesh of current mesh
2202 if (!isActor && aViewWindow) {
2204 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2206 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2207 int len = strlen(meshEntry);
2209 // iterate on all actors in current view window, search for
2210 // any visible actor, that belongs to group or submesh of current mesh
2211 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2212 vtkActorCollection *aCollection = aCopy.GetActors();
2213 int nbItems = aCollection->GetNumberOfItems();
2214 for (int i=0; i<nbItems && !isActor; i++)
2216 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2217 if (anActor && anActor->hasIO()) {
2218 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2219 if (aViewWindow->isVisible(anIO)) {
2220 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0) {
2231 SMESH::SetPickable(myActor);
2236 //=======================================================================
2237 //function : setShowEntityMode
2238 //purpose : make shown only entity corresponding to my type
2239 //=======================================================================
2240 void SMESHGUI_GroupDlg::setShowEntityMode()
2242 if ( !myMesh->_is_nil() ) {
2243 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2244 if (!myStoredShownEntity)
2245 myStoredShownEntity = actor->GetEntityMode();
2246 switch ( myTypeId ) {
2247 case 0: restoreShowEntityMode(); break;
2248 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2249 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2250 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2256 //=======================================================================
2257 //function : restoreShowEntityMode
2258 //purpose : restore ShowEntity mode of myActor
2259 //=======================================================================
2260 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2262 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2263 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2264 actor->SetEntityMode(myStoredShownEntity);
2267 myStoredShownEntity = 0;