1 // Copyright (C) 2007-2010 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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_GroupDlg.cxx
25 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
28 #include "SMESHGUI_GroupDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_GroupUtils.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_GEOMGenUtils.h"
36 #include "SMESHGUI_FilterDlg.h"
37 #include "SMESHGUI_ShapeByMeshDlg.h"
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_Actor.h>
41 #include <SMESH_ActorUtils.h>
43 // SALOME GEOM includes
45 #include <GEOM_SelectionFilter.h>
47 // SALOME GUI includes
48 #include <QtxColorButton.h>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_ResourceMgr.h>
52 #include <SUIT_Session.h>
53 #include <SUIT_MessageBox.h>
55 #include <SalomeApp_Tools.h>
56 #include <SalomeApp_Application.h>
57 #include <SalomeApp_Study.h>
58 #include <LightApp_SelectionMgr.h>
60 #include <SALOME_ListIO.hxx>
61 #include <SALOME_ListIteratorOfListIO.hxx>
63 #include <SVTK_ViewWindow.h>
65 #include <VTKViewer_Algorithm.h>
67 // SALOME KERNEL includes
68 #include <SALOMEDSClient_Study.hxx>
71 #include <vtkRenderer.h>
72 #include <vtkActorCollection.h>
75 #include <TColStd_MapOfInteger.hxx>
78 #include <QButtonGroup>
82 #include <QPushButton>
83 #include <QToolButton>
84 #include <QRadioButton>
86 #include <QGridLayout>
87 #include <QHBoxLayout>
88 #include <QVBoxLayout>
89 #include <QListWidget>
90 #include <QStackedWidget>
102 //=================================================================================
103 // function : SMESHGUI_GroupDlg()
105 //=================================================================================
106 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
107 SMESH::SMESH_Mesh_ptr theMesh )
108 : QDialog( SMESH::GetDesktop( theModule ) ),
109 mySMESHGUI( theModule ),
110 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
111 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
113 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()));
416 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
418 rb1->setChecked(true); // VSR !!!
419 onGrpTypeChanged(0); // VSR!!!
421 if (myMesh->_is_nil() )
422 myTypeGroup->button(0)->setChecked(true);
425 //myName->setText(GetDefaultName(tr( "SMESH_GROUP" )));
428 //=================================================================================
429 // function : ~SMESHGUI_GroupDlg()
430 // purpose : Destroys the object and frees any allocated resources
431 //=================================================================================
432 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
434 // no need to delete child widgets, Qt does it all for us
435 if ( myFilterDlg != 0 ) {
436 myFilterDlg->setParent( 0 );
441 //=================================================================================
442 // function : GetDefaultName()
443 // purpose : Get the Group Name if Create new Group
444 //=================================================================================
445 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
449 // collect all object names of SMESH component
450 SalomeApp_Study* appStudy =
451 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
452 if ( !appStudy ) return aName;
453 _PTR(Study) aStudy = appStudy->studyDS();
455 std::set<std::string> aSet;
456 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
458 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
460 for (it->InitEx(true); it->More(); it->Next()) {
462 aSet.insert(obj->GetName());
466 // build a unique name
468 bool isUnique = false;
470 aName = theOperation + "_" + QString::number(++aNumber);
471 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
477 //=================================================================================
480 //=================================================================================
481 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
483 mySelectionMgr->installFilter(myMeshFilter);
485 /* init data from current selection */
486 restoreShowEntityMode();
487 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
489 myGroup = SMESH::SMESH_Group::_nil();
490 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
492 // NPAL19389: create a group with a selection in another group
493 // set actor of myMesh, if it is visible, else try
494 // any visible actor of group or submesh of myMesh
495 SetAppropriateActor();
497 setDefaultGroupColor();
500 mySelectionMgr->selectedObjects( aList );
501 if( !aList.IsEmpty() )
503 QString aName = aList.First()->getName();
504 myMeshGroupLine->setText(aName);
505 myMeshGroupLine->home( false );
508 myCurrentLineEdit = 0;
510 myTypeGroup->button(0)->setChecked(true);
514 //=================================================================================
517 //=================================================================================
518 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
519 const bool theIsConvert)
521 restoreShowEntityMode();
522 myMesh = theGroup->GetMesh();
525 myNameChanged = true;
526 myName->blockSignals(true);
527 myName->setText(theGroup->GetName());
528 myName->blockSignals(false);
531 SALOMEDS::Color aColor = theGroup->GetColor();
532 setGroupColor( aColor );
534 myMeshGroupLine->setText(theGroup->GetName());
537 switch(theGroup->GetType()) {
538 case SMESH::NODE: aType= 0; break;
539 case SMESH::EDGE: aType = 1; break;
540 case SMESH::FACE: aType = 2; break;
541 case SMESH::VOLUME: aType = 3; break;
543 myTypeGroup->button(aType)->setChecked(true);
545 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
546 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
548 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil())
551 // NPAL19389: create a group with a selection in another group
552 // set actor of myMesh, if it is visible, else set
553 // actor of theGroup, if it is visible, else try
554 // any visible actor of group or submesh of myMesh
555 // commented, because an attempt to set selection on not displayed cells leads to error
556 SetAppropriateActor();
558 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
560 anActor = SMESH::FindActorByObject(theGroup);
561 SMESH::SetPickable(anActor);*/
563 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : 1));
564 myGrpTypeGroup->button(grpType)->setChecked(true);
565 onGrpTypeChanged(grpType);
568 if ( grpType == 0 ) {
569 myCurrentLineEdit = 0;
571 setSelectionMode(aType);
573 setShowEntityMode(); // depends on myTypeId
576 if (!theGroup->IsEmpty()) {
577 SMESH::long_array_var anElements = theGroup->GetListOfID();
578 int k = anElements->length();
579 for (int i = 0; i < k; i++) {
580 myIdList.append(anElements[i]);
581 myElements->addItem(QString::number(anElements[i]));
583 myElements->selectAll();
588 QString aShapeName( "" );
589 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
590 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
591 if (!aGroupShape->_is_nil())
593 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
595 aShapeName = aGroupShapeSO->GetName().c_str();
597 myGeomGroupLine->setText( aShapeName );
598 myNameChanged = true;
599 myName->blockSignals(true);
600 myName->setText(theGroup->GetName());
601 myName->blockSignals(false);
606 //=================================================================================
607 // function : updateButtons()
609 //=================================================================================
610 void SMESHGUI_GroupDlg::updateButtons()
612 bool enable = !myName->text().trimmed().isEmpty();
614 if (myGrpTypeId == 0) {
615 enable = enable && myElements->count() > 0;
616 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
618 else if (myGrpTypeId == 1) {
619 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
620 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
624 myOKBtn->setEnabled(enable);
625 myApplyBtn->setEnabled(enable);
628 //=================================================================================
629 // function : onNameChanged()
631 //=================================================================================
632 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
634 myOldName = myName->text();
636 myNameChanged = !myName->text().trimmed().isEmpty();
639 //=================================================================================
640 // function : onTypeChanged()
641 // purpose : Group elements type radio button management
642 //=================================================================================
643 void SMESHGUI_GroupDlg::onTypeChanged (int id)
645 if (myTypeId != id) {
647 if (myCurrentLineEdit == 0)
648 setSelectionMode(id);
654 //=================================================================================
655 // function : onGrpTypeChanged()
656 // purpose : Group type radio button management
657 //=================================================================================
658 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
660 if (myGrpTypeId != id) {
661 myWGStack->setCurrentIndex( id );
662 myName->blockSignals(true);
663 myName->setText(myOldName);
664 myName->blockSignals(false);
665 onSelectGeomGroup(id == 1);
670 //=================================================================================
671 // function : onColorChanged()
672 // purpose : Color button management
673 //=================================================================================
674 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
679 //=================================================================================
680 // function : setSelectionMode()
681 // purpose : Radio button management
682 //=================================================================================
683 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
686 if (myMesh->_is_nil())
688 if (mySelectionMode != theMode) {
689 // [PAL10408] mySelectionMgr->clearSelected();
690 mySelectionMgr->clearFilters();
691 if (myActorsList.count() > 0) {
692 QListIterator<SMESH_Actor*> it( myActorsList );
693 while ( it.hasNext() )
694 it.next()->SetPointRepresentation(false);
697 SMESH::SetPointRepresentation(false);
701 if (myActorsList.count() > 0) {
702 QListIterator<SMESH_Actor*> it( myActorsList );
703 while ( it.hasNext() )
704 it.next()->SetPointRepresentation(true);
707 SMESH::SetPointRepresentation(true);
708 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
709 aViewWindow->SetSelectionMode(NodeSelection);
712 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
713 aViewWindow->SetSelectionMode(EdgeSelection);
716 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
717 aViewWindow->SetSelectionMode(FaceSelection);
720 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
721 aViewWindow->SetSelectionMode(VolumeSelection);
725 mySelectionMgr->installFilter(mySubMeshFilter);
726 else if (theMode == 5)
727 mySelectionMgr->installFilter(myGroupFilter);
728 else if (theMode == 6)
729 mySelectionMgr->installFilter(myMeshFilter);
730 else if (theMode == 7)
731 mySelectionMgr->installFilter(myGeomFilter);
733 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
734 aViewWindow->SetSelectionMode(ActorSelection);
736 mySelectionMode = theMode;
740 //=================================================================================
741 // function : onApply()
743 //=================================================================================
744 bool SMESHGUI_GroupDlg::onApply()
746 if (mySMESHGUI->isActiveStudyLocked())
749 if (myName->text().trimmed().isEmpty())
752 if (myGrpTypeId == 0) { // on mesh elements
753 if (!myElements->count())
756 mySelectionMgr->clearSelected();
758 if (myGroup->_is_nil()) { // creation or conversion
759 // check if group on geometry is not null
760 if (!CORBA::is_nil(myGroupOnGeom)) {
761 if (myMesh->_is_nil())
763 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
764 // nullify pointer, because object become dead
765 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
769 if (myGroup->_is_nil()) { // creation
770 if (myMesh->_is_nil())
773 SMESH::ElementType aType = SMESH::ALL;
775 case 0: aType = SMESH::NODE; break;
776 case 1: aType = SMESH::EDGE; break;
777 case 2: aType = SMESH::FACE; break;
778 case 3: aType = SMESH::VOLUME; break;
781 SMESH::long_array_var anIdList = new SMESH::long_array;
782 int i, k = myElements->count();
784 for (i = 0; i < k; i++) {
785 anIdList[i] = myElements->item(i)->text().toInt();
788 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
789 myGroup->Add(anIdList.inout());
791 SALOMEDS::Color aColor = getGroupColor();
792 myGroup->SetColor(aColor);
794 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
796 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
797 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
799 /* init for next operation */
800 myName->setText( "" );
802 myGroup = SMESH::SMESH_Group::_nil();
805 myGroup->SetName(myName->text().toLatin1().data());
807 SALOMEDS::Color aColor = getGroupColor();
808 myGroup->SetColor(aColor);
810 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
811 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
812 anActor->setName(myName->text().toLatin1().data());
813 switch ( myTypeId ) {
814 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
815 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
817 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
823 int i, total = myElements->count();
824 for (i = 0; i < total; i++) {
825 int anId = myElements->item(i)->text().toInt();
826 int idx = myIdList.indexOf(anId);
828 aAddList.append(anId);
830 myIdList.removeAt(idx);
832 if (!aAddList.empty()) {
833 SMESH::long_array_var anIdList = new SMESH::long_array;
834 int added = aAddList.count();
835 anIdList->length(added);
836 for (i = 0; i < added; i++)
837 anIdList[i] = aAddList[i];
838 myGroup->Add(anIdList.inout());
840 if (!myIdList.empty()) {
841 SMESH::long_array_var anIdList = new SMESH::long_array;
842 int removed = myIdList.count();
843 anIdList->length(removed);
844 for (i = 0; i < removed; i++)
845 anIdList[i] = myIdList[i];
846 myGroup->Remove(anIdList.inout());
848 /* init for next operation */
850 for (i = 0; i < total; i++) {
851 myIdList.append(myElements->item(i)->text().toInt());
855 mySMESHGUI->updateObjBrowser(true);
856 SMESH::UpdateView(); // asv: fix of BUG PAL5515
857 mySelectionMgr->clearSelected();
860 else if (myGrpTypeId == 1) { // on geom object
861 if (CORBA::is_nil(myGroupOnGeom)) { // creation
862 if (myMesh->_is_nil() || !myGeomObjects->length())
865 SMESH::ElementType aType = SMESH::ALL;
867 case 0: aType = SMESH::NODE; break;
868 case 1: aType = SMESH::EDGE; break;
869 case 2: aType = SMESH::FACE; break;
870 case 3: aType = SMESH::VOLUME; break;
873 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
874 GEOM::GEOM_IGroupOperations_var aGroupOp =
875 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
877 if (myGeomObjects->length() == 1) {
878 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
879 myName->text().toLatin1().data(),
883 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
884 if ( aSMESHGen->_is_nil() )
887 // create a geometry group
888 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
889 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
891 if (geomGen->_is_nil() || !aStudy)
894 GEOM::GEOM_IGroupOperations_var op =
895 geomGen->GetIGroupOperations(aStudy->StudyId());
899 // check and add all selected GEOM objects: they must be
900 // a sub-shapes of the main GEOM and must be of one type
901 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
902 for ( int i =0; i < myGeomObjects->length(); i++) {
903 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
905 aGroupType = aSubShapeType;
906 else if (aSubShapeType != aGroupType) {
907 aGroupType = TopAbs_SHAPE;
912 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
913 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
914 op->UnionList(aGroupVar, myGeomObjects);
917 // publish the GEOM group in study
918 QString aNewGeomGroupName ( "Auto_group_for_" );
919 aNewGeomGroupName += myName->text();
920 SALOMEDS::SObject_var aNewGroupSO =
921 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
922 aNewGeomGroupName.toLatin1().data(), aMeshShape);
925 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
926 myName->text().toLatin1().data(),
930 SALOMEDS::Color aColor = getGroupColor();
931 myGroupOnGeom->SetColor(aColor);
933 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
935 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
936 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
938 /* init for next operation */
939 myName->setText( "" );
940 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
943 myGroupOnGeom->SetName(myName->text().toLatin1().data());
945 SALOMEDS::Color aColor = getGroupColor();
946 myGroupOnGeom->SetColor(aColor);
948 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
949 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
950 anActor->setName(myName->text().toLatin1().data());
951 switch ( myTypeId ) {
952 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
953 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
955 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
960 mySMESHGUI->updateObjBrowser(true);
961 mySelectionMgr->clearSelected();
968 //=================================================================================
971 //=================================================================================
972 void SMESHGUI_GroupDlg::onOK()
978 //=================================================================================
979 // function : onListSelectionChanged()
980 // purpose : Called when selection in element list is changed
981 //=================================================================================
982 void SMESHGUI_GroupDlg::onListSelectionChanged()
984 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
985 if( myIsBusy || myActorsList.count() == 0 ) return;
988 if (myCurrentLineEdit == 0) {
989 mySelectionMgr->clearSelected();
990 TColStd_MapOfInteger aIndexes;
991 QList<QListWidgetItem*> selItems = myElements->selectedItems();
992 QListWidgetItem* anItem;
993 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
994 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
996 aList.Append(myActorsList.first()->getIO());
997 mySelectionMgr->setSelectedObjects(aList,false);
1002 //=================================================================================
1003 // function : onObjectSelectionChanged()
1004 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1005 //=================================================================================
1006 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1008 if ( myIsBusy || !isEnabled()) return;
1009 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1013 SALOME_ListIO aList;
1014 mySelectionMgr->selectedObjects( aList );
1016 int aNbSel = aList.Extent();
1017 myElements->clearSelection();
1019 if (myCurrentLineEdit)
1021 myCurrentLineEdit->setText( "" );
1022 QString aString = "";
1024 if (myCurrentLineEdit == myMeshGroupLine)
1026 mySelectSubMesh->setEnabled(false);
1027 mySelectGroup->setEnabled(false);
1028 myGroupLine->setText( "" );
1029 mySubMeshLine->setText( "" );
1031 myGeomGroupBtn->setEnabled(false);
1032 myGeomGroupLine->setEnabled(false);
1033 myGeomGroupLine->setText( "" );
1034 myGeomObjects = new GEOM::ListOfGO();
1035 myGeomObjects->length(0);
1037 if (myGeomGroupBtn->isChecked())
1038 myGeomGroupBtn->setChecked(false);
1040 myName->setText( "" );
1042 myElements->clear();
1045 myGroup = SMESH::SMESH_Group::_nil();
1046 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1047 restoreShowEntityMode();
1048 myMesh = SMESH::SMESH_Mesh::_nil();
1054 Handle(SALOME_InteractiveObject) IO = aList.First();
1057 restoreShowEntityMode();
1058 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1059 setShowEntityMode();
1061 if (myMesh->_is_nil())
1068 if ( myFilterDlg && !myMesh->_is_nil()){
1069 myFilterDlg->SetMesh( myMesh );
1071 myGroup = SMESH::SMESH_Group::_nil();
1073 // NPAL19389: create a group with a selection in another group
1074 // set actor of myMesh, if it is visible, else try
1075 // any visible actor of group or submesh of myMesh
1076 SetAppropriateActor();
1078 aString = aList.First()->getName();
1079 myMeshGroupLine->setText(aString);
1080 myMeshGroupLine->home( false );
1082 mySelectSubMesh->setEnabled(true);
1083 mySelectGroup->setEnabled(true);
1084 myGeomGroupBtn->setEnabled(true);
1085 myGeomGroupLine->setEnabled(true);
1089 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1090 if (aGroup->_is_nil())
1097 myGroup = SMESH::SMESH_Group::_nil();
1098 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1102 mySelectSubMesh->setEnabled(true);
1103 mySelectGroup->setEnabled(true);
1105 myCurrentLineEdit = 0;
1110 if (myGrpTypeId == 0)
1116 myElements->clear();
1117 setSelectionMode(myTypeId);
1125 else if (myCurrentLineEdit == myGeomGroupLine)
1127 myGeomObjects = new GEOM::ListOfGO();
1130 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1132 if (aNbSel == 0 || !aMeshSO)
1134 myGeomObjects->length(0);
1140 myGeomObjects->length(aNbSel);
1142 GEOM::GEOM_Object_var aGeomGroup;
1143 Standard_Boolean testResult;
1146 SALOME_ListIteratorOfListIO anIt (aList);
1147 for (; anIt.More(); anIt.Next())
1149 testResult = Standard_False;
1150 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1152 // Check if the object is a geometry group
1153 if (!testResult || CORBA::is_nil(aGeomGroup))
1156 // Check if group constructed on the same shape as a mesh or on its child
1157 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1158 GEOM::GEOM_IGroupOperations_var anOp =
1159 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1161 // The main shape of the group
1162 GEOM::GEOM_Object_var aGroupMainShape;
1163 if (aGeomGroup->GetType() == 37)
1164 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1166 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1167 _PTR(SObject) aGroupMainShapeSO =
1168 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1169 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1171 _PTR(SObject) anObj, aRef;
1172 bool isRefOrSubShape = false;
1173 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1174 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1175 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1176 isRefOrSubShape = true;
1178 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1179 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1180 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1181 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1182 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1183 if (aRef->GetID() == aFather->GetID())
1184 isRefOrSubShape = true;
1186 aFather = aFather->GetFather();
1190 if (isRefOrSubShape)
1191 myGeomObjects[i++] = aGeomGroup;
1194 myGeomObjects->length(i);
1206 if (myCurrentLineEdit == mySubMeshLine)
1207 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1208 else if (myCurrentLineEdit == myGroupLine)
1209 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1210 else if (myCurrentLineEdit == myGeomGroupLine)
1211 aString = tr( "%1 Objects" ).arg(aNbSel);
1214 aString = aList.First()->getName();
1218 myCurrentLineEdit->setText(aString);
1219 myCurrentLineEdit->home(false);
1220 // 07.06.2008 skl for IPAL19574:
1221 // change name of group only if it is empty
1222 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1223 myOldName = myName->text();
1224 myName->blockSignals(true);
1225 myName->setText(aString);
1226 myName->blockSignals(false);
1231 else // !myCurrentLineEdit: local selection of nodes or elements
1233 if (aNbSel == 1 && myActorsList.count() > 0 )
1235 // NPAL19389: create a group with a selection in another group
1236 // Switch myActor to the newly selected one, if the last
1237 // is visible and belongs to group or submesh of myMesh
1238 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1239 Handle(SALOME_InteractiveObject) selIO = aList.First();
1240 if (curIO->hasEntry() && selIO->hasEntry()) {
1241 const char* selEntry = selIO->getEntry();
1242 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1243 // different objects: selected and myActor
1244 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1245 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1246 // newly selected actor is visible
1249 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1251 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1252 int len = strlen(meshEntry);
1254 if (strncmp(selEntry, meshEntry, len) == 0) {
1255 // selected object is myMesh or a part of it
1256 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1259 SMESH::SetPickable(myActor);
1268 QString aListStr = "";
1270 if (myTypeId == 0) {
1271 QListIterator<SMESH_Actor*> it( myActorsList );
1272 while ( it.hasNext() ) {
1274 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1278 QListIterator<SMESH_Actor*> it( myActorsList );
1279 while ( it.hasNext() ) {
1281 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1286 QListWidgetItem* anItem;
1287 QList<QListWidgetItem*> listItemsToSel;
1288 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1289 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1290 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1291 foreach(anItem, found)
1292 if (!anItem->isSelected())
1293 listItemsToSel.push_back(anItem);
1295 bool blocked = myElements->signalsBlocked();
1296 myElements->blockSignals(true);
1297 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1298 myElements->blockSignals(blocked);
1299 onListSelectionChanged();
1300 listItemsToSel.clear();
1305 if (myActorsList.count() == 0) {
1306 if (!myGroup->_is_nil()) {
1307 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1309 myActorsList.append( anActor );
1311 else if(!myGroupOnGeom->_is_nil()) {
1312 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1314 myActorsList.append( anActor );
1317 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1319 myActorsList.append( anActor );
1323 // somehow, if we display the mesh, while selecting from another actor,
1324 // the mesh becomes pickable, and there is no way to select any element
1325 if (myActorsList.count() > 0) {
1326 QListIterator<SMESH_Actor*> it( myActorsList );
1327 while ( it.hasNext() ) {
1328 SMESH_Actor* anActor = it.next();
1329 if ( IsActorVisible(anActor) )
1330 anActor->SetPickable(true);
1337 //=================================================================================
1338 // function : onSelectSubMesh()
1339 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1340 //=================================================================================
1341 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1344 if (mySelectGroup->isChecked()) {
1345 mySelectGroup->setChecked(false);
1347 //VSR: else if (mySelectGeomGroup->isChecked()) {
1348 //VSR: mySelectGeomGroup->setChecked(false);
1350 myCurrentLineEdit = mySubMeshLine;
1351 setSelectionMode(4);
1354 mySubMeshLine->setText( "" );
1355 myCurrentLineEdit = 0;
1357 setSelectionMode(myTypeId);
1359 mySubMeshBtn->setEnabled(on);
1360 mySubMeshLine->setEnabled(on);
1364 //=================================================================================
1365 // function : (onSelectGroup)
1366 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1367 //=================================================================================
1368 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1371 if (mySelectSubMesh->isChecked()) {
1372 mySelectSubMesh->setChecked(false);
1374 myCurrentLineEdit = myGroupLine;
1375 setSelectionMode(5);
1378 myGroupLine->setText( "" );
1379 myCurrentLineEdit = 0;
1381 setSelectionMode(myTypeId);
1383 myGroupBtn->setEnabled(on);
1384 myGroupLine->setEnabled(on);
1388 //=================================================================================
1389 // function : (onSelectGeomGroup)
1390 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1391 //=================================================================================
1392 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1395 if (mySelectSubMesh->isChecked()) {
1396 mySelectSubMesh->setChecked(false);
1398 else if (mySelectGroup->isChecked()) {
1399 mySelectGroup->setChecked(false);
1401 myCurrentLineEdit = myGeomGroupLine;
1403 setSelectionMode(8);
1406 myGeomGroupBtn->setChecked(false);
1407 myGeomObjects->length(0);
1408 myGeomGroupLine->setText( "" );
1409 myCurrentLineEdit = 0;
1411 setSelectionMode(myTypeId);
1416 //=================================================================================
1417 // function : setCurrentSelection()
1419 //=================================================================================
1420 void SMESHGUI_GroupDlg::setCurrentSelection()
1422 QPushButton* send = (QPushButton*)sender();
1423 myCurrentLineEdit = 0;
1424 if (send == myMeshGroupBtn) {
1425 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1426 mySelectionMgr->clearSelected();
1428 setSelectionMode(6);
1430 setSelectionMode(5);
1431 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1432 myCurrentLineEdit = myMeshGroupLine;
1433 onObjectSelectionChanged();
1435 else if (send == mySubMeshBtn) {
1436 myCurrentLineEdit = mySubMeshLine;
1437 onObjectSelectionChanged();
1439 else if (send == myGroupBtn) {
1440 myCurrentLineEdit = myGroupLine;
1441 onObjectSelectionChanged();
1446 //=================================================================================
1447 // function : setFilters()
1448 // purpose : SLOT. Called when "Filter" button pressed.
1449 //=================================================================================
1450 void SMESHGUI_GroupDlg::setFilters()
1452 if(myMesh->_is_nil()) {
1453 SUIT_MessageBox::critical(this,
1455 tr("NO_MESH_SELECTED"));
1459 SMESH::ElementType aType = SMESH::ALL;
1462 case 0 : aType = SMESH::NODE; break;
1463 case 1 : aType = SMESH::EDGE; break;
1464 case 2 : aType = SMESH::FACE; break;
1465 case 3 : aType = SMESH::VOLUME; break;
1469 if ( myFilterDlg == 0 )
1471 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1472 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1475 myFilterDlg->Init( aType );
1477 myFilterDlg->SetSelection();
1478 myFilterDlg->SetMesh( myMesh );
1479 myFilterDlg->SetSourceWg( myElements, false );
1481 myFilterDlg->show();
1484 //=================================================================================
1485 // function : onFilterAccepted()
1486 // purpose : SLOT. Called when Filter dlg closed with OK button.
1487 // Uncheck "Select submesh" and "Select group" checkboxes
1488 //=================================================================================
1489 void SMESHGUI_GroupDlg::onFilterAccepted()
1491 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1493 mySelectionMode = myTypeId;
1494 mySelectSubMesh->setChecked( false );
1495 mySelectGroup->setChecked( false );
1499 //=================================================================================
1500 // function : onAdd()
1502 //=================================================================================
1503 void SMESHGUI_GroupDlg::onAdd()
1505 SALOME_ListIO aList;
1506 mySelectionMgr->selectedObjects( aList );
1508 int aNbSel = aList.Extent();
1510 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1514 SMESH::ElementType aType = SMESH::ALL;
1517 aType = SMESH::NODE;
1518 mySelector->SetSelectionMode(NodeSelection);
1521 aType = SMESH::EDGE;
1522 mySelector->SetSelectionMode(EdgeSelection);
1525 aType = SMESH::FACE;
1526 mySelector->SetSelectionMode(FaceSelection);
1529 aType = SMESH::VOLUME;
1530 mySelector->SetSelectionMode(VolumeSelection);
1533 mySelector->SetSelectionMode(ActorSelection);
1536 QListWidgetItem* anItem = 0;
1537 QList<QListWidgetItem*> listItemsToSel;
1539 if (myCurrentLineEdit == 0) {
1540 //if (aNbSel != 1) { myIsBusy = false; return; }
1541 QString aListStr = "";
1543 if (myTypeId == 0) {
1544 QListIterator<SMESH_Actor*> it( myActorsList );
1545 while ( it.hasNext() ) {
1547 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1552 QListIterator<SMESH_Actor*> it( myActorsList );
1553 while ( it.hasNext() ) {
1555 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1560 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1561 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1562 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1563 if (found.count() == 0) {
1564 anItem = new QListWidgetItem(*it);
1565 myElements->addItem(anItem);
1566 if (!anItem->isSelected())
1567 listItemsToSel.push_back(anItem);
1570 foreach(anItem, found)
1571 if (!anItem->isSelected())
1572 listItemsToSel.push_back(anItem);
1575 bool blocked = myElements->signalsBlocked();
1576 myElements->blockSignals(true);
1577 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1578 myElements->blockSignals(blocked);
1579 onListSelectionChanged();
1580 listItemsToSel.clear();
1582 } else if (myCurrentLineEdit == mySubMeshLine) {
1583 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1585 SALOME_ListIO aList;
1586 mySelectionMgr->selectedObjects( aList );
1588 SALOME_ListIteratorOfListIO anIt (aList);
1589 for ( ; anIt.More(); anIt.Next()) {
1590 SMESH::SMESH_subMesh_var aSubMesh =
1591 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1592 if (!aSubMesh->_is_nil()) {
1593 // check if mesh is the same
1594 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1596 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1597 int k = anElements->length();
1598 for (int i = 0; i < k; i++) {
1599 QString aText = QString::number(anElements[i]);
1600 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1601 if (found.count() == 0) {
1602 anItem = new QListWidgetItem(aText);
1603 myElements->addItem(anItem);
1604 if (!anItem->isSelected())
1605 listItemsToSel.push_back(anItem);
1608 foreach(anItem, found)
1609 if (!anItem->isSelected())
1610 listItemsToSel.push_back(anItem);
1613 bool blocked = myElements->signalsBlocked();
1614 myElements->blockSignals(true);
1615 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1616 myElements->blockSignals(blocked);
1617 onListSelectionChanged();
1618 listItemsToSel.clear();
1620 catch (const SALOME::SALOME_Exception& ex) {
1621 SalomeApp_Tools::QtCatchCorbaException(ex);
1626 mySelectSubMesh->setChecked(false);
1628 onListSelectionChanged();
1630 } else if (myCurrentLineEdit == myGroupLine) {
1631 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1632 SALOME_ListIO aList;
1633 mySelectionMgr->selectedObjects( aList );
1635 SALOME_ListIteratorOfListIO anIt (aList);
1636 for ( ; anIt.More(); anIt.Next()) {
1637 SMESH::SMESH_GroupBase_var aGroup =
1638 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1639 if (!aGroup->_is_nil()) {
1640 // check if mesh is the same
1641 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1642 SMESH::long_array_var anElements = aGroup->GetListOfID();
1643 int k = anElements->length();
1644 for (int i = 0; i < k; i++) {
1645 QString aText = QString::number(anElements[i]);
1646 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1647 if (found.count() == 0) {
1648 anItem = new QListWidgetItem(aText);
1649 myElements->addItem(anItem);
1650 if (!anItem->isSelected())
1651 listItemsToSel.push_back(anItem);
1654 foreach(anItem, found)
1655 if (!anItem->isSelected())
1656 listItemsToSel.push_back(anItem);
1659 bool blocked = myElements->signalsBlocked();
1660 myElements->blockSignals(true);
1661 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1662 myElements->blockSignals(blocked);
1663 onListSelectionChanged();
1664 listItemsToSel.clear();
1668 mySelectGroup->setChecked(false);
1670 onListSelectionChanged();
1672 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1673 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1674 GEOM::GEOM_IGroupOperations_var aGroupOp =
1675 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1677 SMESH::ElementType aGroupType = SMESH::ALL;
1678 switch(aGroupOp->GetType(myGeomObjects[0])) {
1679 case 7: aGroupType = SMESH::NODE; break;
1680 case 6: aGroupType = SMESH::EDGE; break;
1681 case 4: aGroupType = SMESH::FACE; break;
1682 case 2: aGroupType = SMESH::VOLUME; break;
1683 default: myIsBusy = false; return;
1686 if (aGroupType == aType) {
1687 _PTR(SObject) aGroupSO =
1688 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1689 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1691 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1692 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1693 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1694 aBelongToGeom->SetGeom(myGeomObjects[0]);
1695 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1696 aBelongToGeom->SetElementType(aType);
1697 aFilter->SetPredicate(aBelongToGeom);
1699 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1701 int k = anElements->length();
1702 for (int i = 0; i < k; i++) {
1703 QString aText = QString::number(anElements[i]);
1704 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1705 if (found.count() == 0) {
1706 anItem = new QListWidgetItem(aText);
1707 myElements->addItem(anItem);
1708 if (!anItem->isSelected())
1709 listItemsToSel.push_back(anItem);
1712 foreach(anItem, found)
1713 if (!anItem->isSelected())
1714 listItemsToSel.push_back(anItem);
1717 bool blocked = myElements->signalsBlocked();
1718 myElements->blockSignals(true);
1719 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1720 myElements->blockSignals(blocked);
1721 onListSelectionChanged();
1722 listItemsToSel.clear();
1725 //VSR: mySelectGeomGroup->setChecked(false);
1727 onListSelectionChanged();
1730 // mySelectionMgr->clearSelected();
1734 //=================================================================================
1735 // function : onRemove()
1737 //=================================================================================
1738 void SMESHGUI_GroupDlg::onRemove()
1741 if (myCurrentLineEdit == 0) {
1742 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1743 QListWidgetItem* item;
1744 foreach(item, selItems) delete item;
1746 SALOME_ListIO aList;
1747 mySelectionMgr->selectedObjects( aList );
1749 int aNbSel = aList.Extent();
1751 if (aNbSel == 0) { myIsBusy = false; return; }
1753 SMESH::ElementType aType = SMESH::ALL;
1755 case 0: aType = SMESH::NODE; break;
1756 case 1: aType = SMESH::EDGE; break;
1757 case 2: aType = SMESH::FACE; break;
1758 case 3: aType = SMESH::VOLUME; break;
1761 if (myCurrentLineEdit == mySubMeshLine) {
1762 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1763 SALOME_ListIO aList;
1764 mySelectionMgr->selectedObjects( aList );
1766 SALOME_ListIteratorOfListIO anIt (aList);
1767 for ( ; anIt.More(); anIt.Next()) {
1768 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1769 if (!aSubMesh->_is_nil()) {
1770 // check if mesh is the same
1771 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1772 if (aType == SMESH::NODE) {
1774 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1775 int k = anElements->length();
1776 for (int i = 0; i < k; i++) {
1777 QList<QListWidgetItem*> found =
1778 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1779 QListWidgetItem* anItem;
1780 foreach(anItem, found) delete anItem;
1783 catch (const SALOME::SALOME_Exception& ex) {
1784 SalomeApp_Tools::QtCatchCorbaException(ex);
1789 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1790 int k = anElements->length();
1791 for (int i = 0; i < k; i++) {
1792 QList<QListWidgetItem*> found =
1793 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1794 QListWidgetItem* anItem;
1795 foreach(anItem, found) delete anItem;
1798 catch (const SALOME::SALOME_Exception& ex) {
1799 SalomeApp_Tools::QtCatchCorbaException(ex);
1806 else if (myCurrentLineEdit == myGroupLine) {
1807 Standard_Boolean aRes;
1808 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1809 SALOME_ListIO aList;
1810 mySelectionMgr->selectedObjects( aList );
1812 SALOME_ListIteratorOfListIO anIt (aList);
1813 for ( ; anIt.More(); anIt.Next()) {
1814 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1815 if (aRes && !aGroup->_is_nil()) {
1816 // check if mesh is the same
1817 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1818 SMESH::long_array_var anElements = aGroup->GetListOfID();
1819 int k = anElements->length();
1820 for (int i = 0; i < k; i++) {
1821 QList<QListWidgetItem*> found =
1822 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1823 QListWidgetItem* anItem;
1824 foreach(anItem, found) delete anItem;
1835 //=================================================================================
1836 // function : onSort()
1838 //=================================================================================
1839 void SMESHGUI_GroupDlg::onSort()
1841 // PAL5412: sorts items in ascending by "string" value
1842 // myElements->sort(true);
1843 // myElements->update();
1844 int i, k = myElements->count();
1847 QList<int> aSelected;
1848 std::vector<int> anArray(k);
1849 // QMemArray<int> anArray(k);
1851 for (i = 0; i < k; i++) {
1852 int id = myElements->item(i)->text().toInt();
1854 if (myElements->item(i)->isSelected())
1855 aSelected.append(id);
1857 // sort & update list
1858 std::sort(anArray.begin(), anArray.end());
1860 myElements->clear();
1861 QListWidgetItem* anItem;
1862 QList<QListWidgetItem*> listItemsToSel;
1863 for (i = 0; i < k; i++) {
1864 anItem = new QListWidgetItem(QString::number(anArray[i]));
1865 myElements->addItem(anItem);
1866 if (aSelected.contains(anArray[i]))
1867 listItemsToSel.push_back(anItem);
1869 bool blocked = myElements->signalsBlocked();
1870 myElements->blockSignals(true);
1871 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1872 myElements->blockSignals(blocked);
1873 listItemsToSel.clear();
1878 //=================================================================================
1879 // function : closeEvent()
1881 //=================================================================================
1882 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1887 //=================================================================================
1888 // function : onVisibilityChanged()
1890 //=================================================================================
1891 void SMESHGUI_GroupDlg::onVisibilityChanged()
1893 SetAppropriateActor();
1896 //=================================================================================
1897 // function : SMESHGUI_GroupDlg::onClose
1898 // purpose : SLOT called when "Close" button pressed. Close dialog
1899 //=================================================================================
1900 void SMESHGUI_GroupDlg::onClose()
1902 if (SMESH::GetCurrentVtkView()) {
1903 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1904 SMESH::SetPointRepresentation(false);
1905 SMESH::SetPickable();
1906 restoreShowEntityMode();
1909 mySelectionMgr->clearSelected();
1910 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1911 aViewWindow->SetSelectionMode(ActorSelection);
1912 mySelectionMgr->clearFilters();
1913 mySMESHGUI->ResetState();
1918 //=================================================================================
1919 // function : onHelp()
1921 //=================================================================================
1922 void SMESHGUI_GroupDlg::onHelp()
1924 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1926 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1930 platform = "winapplication";
1932 platform = "application";
1934 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1935 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1936 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1938 arg(myHelpFileName));
1942 //=================================================================================
1943 // function : SMESHGUI_GroupDlg::onDeactivate
1944 // purpose : SLOT called when dialog must be deativated
1945 //=================================================================================
1946 void SMESHGUI_GroupDlg::onDeactivate()
1948 mySMESHGUI->ResetState();
1952 //=================================================================================
1953 // function : SMESHGUI_GroupDlg::enterEvent
1954 // purpose : Event filter
1955 //=================================================================================
1956 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1959 mySMESHGUI->EmitSignalDeactivateDialog();
1961 mySelectionMode = -1;
1962 setSelectionMode(myTypeId);
1963 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1964 mySMESHGUI->SetActiveDialogBox(this);
1965 mySMESHGUI->SetState(800);
1969 //=================================================================================
1970 // function : hideEvent
1971 // purpose : caused by ESC key
1972 //=================================================================================
1973 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1975 if (!isMinimized() && !myIsBusy)
1979 //=================================================================================
1980 // function : keyPressEvent()
1982 //=================================================================================
1983 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1985 QDialog::keyPressEvent( e );
1986 if ( e->isAccepted() )
1989 if ( e->key() == Qt::Key_F1 )
1996 //================================================================================
1998 * \brief Enable showing of the popup when Geometry selection btn is clicked
1999 * \param enable - true to enable
2001 //================================================================================
2003 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2005 void SMESHGUI_GroupDlg::updateGeomPopup()
2007 bool enable = false;
2009 if ( !myMesh->_is_nil() )
2010 enable = myMesh->NbEdges() > 0;
2012 if ( myGeomGroupBtn )
2014 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2016 if ( !myGeomPopup ) {
2017 myGeomPopup = new QMenu(this);
2018 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2019 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2020 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2022 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2028 //=================================================================================
2029 // function : onGeomSelectionButton()
2031 //=================================================================================
2032 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2034 if ( myGeomPopup && isBtnOn )
2036 myCurrentLineEdit = myGeomGroupLine;
2037 QAction* a = myGeomPopup->exec( QCursor::pos() );
2038 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2039 setSelectionMode(7);
2043 myCurrentLineEdit = 0;
2044 setSelectionMode(8);
2048 //=================================================================================
2049 // function : onGeomPopup()
2051 //=================================================================================
2052 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2054 int index = myActions[a];
2055 if ( index == GEOM_BY_MESH_INDEX )
2057 mySelectionMode = -1;
2058 if ( !myShapeByMeshOp ) {
2059 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2060 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2061 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2062 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2063 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2065 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2066 if ( !myMesh->_is_nil() ) {
2068 hide(); // stop processing selection
2070 myShapeByMeshOp->setModule( mySMESHGUI );
2071 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2072 myShapeByMeshOp->SetMesh( myMesh );
2073 myShapeByMeshOp->start();
2078 //================================================================================
2080 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2082 //================================================================================
2084 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2086 if ( myShapeByMeshOp == op ) {
2087 mySMESHGUI->getApp()->updateObjectBrowser();
2089 // Select a found geometry object
2090 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2091 if ( !aGeomVar->_is_nil() )
2093 QString ID = aGeomVar->GetStudyEntry();
2094 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2095 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2096 SALOME_ListIO anIOList;
2097 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2098 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2099 anIOList.Append( anIO );
2100 mySelectionMgr->setSelectedObjects( anIOList, false );
2101 onObjectSelectionChanged();
2107 //================================================================================
2109 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2111 //================================================================================
2113 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2115 if ( myShapeByMeshOp == op )
2118 setSelectionMode(7);
2122 //=================================================================================
2123 // function : setGroupColor()
2125 //=================================================================================
2126 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2128 QColor aQColor( (int)( theColor.R * 255.0 ),
2129 (int)( theColor.G * 255.0 ),
2130 (int)( theColor.B * 255.0 ) );
2131 setGroupQColor( aQColor );
2134 //=================================================================================
2135 // function : getGroupColor()
2137 //=================================================================================
2138 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2140 QColor aQColor = getGroupQColor();
2142 SALOMEDS::Color aColor;
2143 aColor.R = (float)aQColor.red() / 255.0;
2144 aColor.G = (float)aQColor.green() / 255.0;
2145 aColor.B = (float)aQColor.blue() / 255.0;
2150 //=================================================================================
2151 // function : setGroupQColor()
2153 //=================================================================================
2154 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2156 if( theColor.isValid() )
2157 myColorBtn->setColor( theColor );
2160 //=================================================================================
2161 // function : getGroupQColor()
2163 //=================================================================================
2164 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2166 return myColorBtn->color();
2169 //=================================================================================
2170 // function : setDefaultGroupColor()
2172 //=================================================================================
2173 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2175 if( myMesh->_is_nil() )
2178 bool isAutoColor = myMesh->GetAutoColor();
2183 int r = 0, g = 0, b = 0;
2184 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2185 aQColor.setRgb( r, g, b );
2189 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2191 QList<SALOMEDS::Color> aReservedColors;
2192 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2194 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2195 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2196 aReservedColors.append( aReservedColor );
2199 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2200 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2201 (int)( aColor.G * 255.0 ),
2202 (int)( aColor.B * 255.0 ) );
2206 setGroupQColor( aQColor );
2209 //=================================================================================
2210 // function : SetAppropriateActor()
2211 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2212 // NPAL19389: create a group with a selection in another group.
2213 // if mesh actor is not visible - find any first visible group or submesh
2214 //=================================================================================
2215 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2217 bool isActor = false;
2218 myActorsList.clear();
2220 if (myMesh->_is_nil()) return false;
2222 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2224 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2226 if (!myGroupOnGeom->_is_nil()) {
2227 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2228 if (anActor && anActor->hasIO())
2231 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2234 myActorsList.append(anActor);
2240 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2241 if (anActor && anActor->hasIO()) {
2243 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2246 myActorsList.append(anActor);
2250 if (!isActor && !myGroup->_is_nil()) {
2251 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2252 if (anActor && anActor->hasIO())
2253 myActorsList.append(anActor);
2256 // try any visible actor of group or submesh of current mesh
2259 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2261 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2262 int len = strlen(meshEntry);
2264 // iterate on all actors in current view window, search for
2265 // any visible actor, that belongs to group or submesh of current mesh
2266 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2267 vtkActorCollection *aCollection = aCopy.GetActors();
2268 int nbItems = aCollection->GetNumberOfItems();
2269 for (int i=0; i<nbItems && !isActor; i++)
2271 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2272 if (anActor && anActor->hasIO()) {
2273 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2274 if (aViewWindow->isVisible(anIO)) {
2275 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2276 myActorsList.append(anActor);
2284 if (myActorsList.count() > 0) {
2285 QListIterator<SMESH_Actor*> it( myActorsList );
2286 while ( it.hasNext() ) {
2287 SMESH_Actor* anActor = it.next();
2288 if ( IsActorVisible(anActor) )
2289 anActor->SetPickable(true);
2293 return ( isActor || (myActorsList.count() > 0) );
2296 //=======================================================================
2297 //function : setShowEntityMode
2298 //purpose : make shown only entity corresponding to my type
2299 //=======================================================================
2300 void SMESHGUI_GroupDlg::setShowEntityMode()
2302 if ( !myMesh->_is_nil() ) {
2303 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2304 if (!myStoredShownEntity)
2305 myStoredShownEntity = actor->GetEntityMode();
2306 switch ( myTypeId ) {
2307 case 0: restoreShowEntityMode(); break;
2308 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2309 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2310 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2316 //=======================================================================
2317 //function : restoreShowEntityMode
2318 //purpose : restore ShowEntity mode of myActor
2319 //=======================================================================
2320 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2322 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2323 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2324 actor->SetEntityMode(myStoredShownEntity);
2327 myStoredShownEntity = 0;
2330 //=======================================================================
2331 //function : IsActorVisible
2332 //purpose : return visibility of the actor
2333 //=======================================================================
2334 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2336 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2337 if (theActor && aViewWindow)
2338 return aViewWindow->isVisible(theActor->getIO());