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 SMESHGUI::Modified();
856 mySMESHGUI->updateObjBrowser(true);
857 SMESH::UpdateView(); // asv: fix of BUG PAL5515
858 mySelectionMgr->clearSelected();
861 else if (myGrpTypeId == 1) { // on geom object
862 if (CORBA::is_nil(myGroupOnGeom)) { // creation
863 if (myMesh->_is_nil() || !myGeomObjects->length())
866 SMESH::ElementType aType = SMESH::ALL;
868 case 0: aType = SMESH::NODE; break;
869 case 1: aType = SMESH::EDGE; break;
870 case 2: aType = SMESH::FACE; break;
871 case 3: aType = SMESH::VOLUME; break;
874 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
875 GEOM::GEOM_IGroupOperations_var aGroupOp =
876 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
878 if (myGeomObjects->length() == 1) {
879 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
880 myName->text().toLatin1().data(),
884 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
885 if ( aSMESHGen->_is_nil() )
888 // create a geometry group
889 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
890 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
892 if (geomGen->_is_nil() || !aStudy)
895 GEOM::GEOM_IGroupOperations_var op =
896 geomGen->GetIGroupOperations(aStudy->StudyId());
900 // check and add all selected GEOM objects: they must be
901 // a sub-shapes of the main GEOM and must be of one type
902 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
903 for ( int i =0; i < myGeomObjects->length(); i++) {
904 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
906 aGroupType = aSubShapeType;
907 else if (aSubShapeType != aGroupType) {
908 aGroupType = TopAbs_SHAPE;
913 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
914 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
915 op->UnionList(aGroupVar, myGeomObjects);
918 // publish the GEOM group in study
919 QString aNewGeomGroupName ( "Auto_group_for_" );
920 aNewGeomGroupName += myName->text();
921 SALOMEDS::SObject_var aNewGroupSO =
922 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
923 aNewGeomGroupName.toLatin1().data(), aMeshShape);
926 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
927 myName->text().toLatin1().data(),
931 SALOMEDS::Color aColor = getGroupColor();
932 myGroupOnGeom->SetColor(aColor);
934 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
936 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
937 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
939 /* init for next operation */
940 myName->setText( "" );
941 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
944 myGroupOnGeom->SetName(myName->text().toLatin1().data());
946 SALOMEDS::Color aColor = getGroupColor();
947 myGroupOnGeom->SetColor(aColor);
949 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
950 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
951 anActor->setName(myName->text().toLatin1().data());
952 switch ( myTypeId ) {
953 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
954 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
956 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
961 SMESHGUI::Modified();
962 mySMESHGUI->updateObjBrowser(true);
963 mySelectionMgr->clearSelected();
970 //=================================================================================
973 //=================================================================================
974 void SMESHGUI_GroupDlg::onOK()
980 //=================================================================================
981 // function : onListSelectionChanged()
982 // purpose : Called when selection in element list is changed
983 //=================================================================================
984 void SMESHGUI_GroupDlg::onListSelectionChanged()
986 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
987 if( myIsBusy || myActorsList.count() == 0 ) return;
990 if (myCurrentLineEdit == 0) {
991 mySelectionMgr->clearSelected();
992 TColStd_MapOfInteger aIndexes;
993 QList<QListWidgetItem*> selItems = myElements->selectedItems();
994 QListWidgetItem* anItem;
995 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
996 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
998 aList.Append(myActorsList.first()->getIO());
999 mySelectionMgr->setSelectedObjects(aList,false);
1004 //=================================================================================
1005 // function : onObjectSelectionChanged()
1006 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1007 //=================================================================================
1008 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1010 if ( myIsBusy || !isEnabled()) return;
1011 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1015 SALOME_ListIO aList;
1016 mySelectionMgr->selectedObjects( aList );
1018 int aNbSel = aList.Extent();
1019 myElements->clearSelection();
1021 if (myCurrentLineEdit)
1023 myCurrentLineEdit->setText( "" );
1024 QString aString = "";
1026 if (myCurrentLineEdit == myMeshGroupLine)
1028 mySelectSubMesh->setEnabled(false);
1029 mySelectGroup->setEnabled(false);
1030 myGroupLine->setText( "" );
1031 mySubMeshLine->setText( "" );
1033 myGeomGroupBtn->setEnabled(false);
1034 myGeomGroupLine->setEnabled(false);
1035 myGeomGroupLine->setText( "" );
1036 myGeomObjects = new GEOM::ListOfGO();
1037 myGeomObjects->length(0);
1039 if (myGeomGroupBtn->isChecked())
1040 myGeomGroupBtn->setChecked(false);
1042 myName->setText( "" );
1044 myElements->clear();
1047 myGroup = SMESH::SMESH_Group::_nil();
1048 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1049 restoreShowEntityMode();
1050 myMesh = SMESH::SMESH_Mesh::_nil();
1056 Handle(SALOME_InteractiveObject) IO = aList.First();
1059 restoreShowEntityMode();
1060 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1061 setShowEntityMode();
1063 if (myMesh->_is_nil())
1070 if ( myFilterDlg && !myMesh->_is_nil()){
1071 myFilterDlg->SetMesh( myMesh );
1073 myGroup = SMESH::SMESH_Group::_nil();
1075 // NPAL19389: create a group with a selection in another group
1076 // set actor of myMesh, if it is visible, else try
1077 // any visible actor of group or submesh of myMesh
1078 SetAppropriateActor();
1080 aString = aList.First()->getName();
1081 myMeshGroupLine->setText(aString);
1082 myMeshGroupLine->home( false );
1084 mySelectSubMesh->setEnabled(true);
1085 mySelectGroup->setEnabled(true);
1086 myGeomGroupBtn->setEnabled(true);
1087 myGeomGroupLine->setEnabled(true);
1091 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1092 if (aGroup->_is_nil())
1099 myGroup = SMESH::SMESH_Group::_nil();
1100 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1104 mySelectSubMesh->setEnabled(true);
1105 mySelectGroup->setEnabled(true);
1107 myCurrentLineEdit = 0;
1112 if (myGrpTypeId == 0)
1118 myElements->clear();
1119 setSelectionMode(myTypeId);
1127 else if (myCurrentLineEdit == myGeomGroupLine)
1129 myGeomObjects = new GEOM::ListOfGO();
1132 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1134 if (aNbSel == 0 || !aMeshSO)
1136 myGeomObjects->length(0);
1142 myGeomObjects->length(aNbSel);
1144 GEOM::GEOM_Object_var aGeomGroup;
1145 Standard_Boolean testResult;
1148 SALOME_ListIteratorOfListIO anIt (aList);
1149 for (; anIt.More(); anIt.Next())
1151 testResult = Standard_False;
1152 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1154 // Check if the object is a geometry group
1155 if (!testResult || CORBA::is_nil(aGeomGroup))
1158 // Check if group constructed on the same shape as a mesh or on its child
1159 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1160 GEOM::GEOM_IGroupOperations_var anOp =
1161 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1163 // The main shape of the group
1164 GEOM::GEOM_Object_var aGroupMainShape;
1165 if (aGeomGroup->GetType() == 37)
1166 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1168 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1169 _PTR(SObject) aGroupMainShapeSO =
1170 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1171 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1173 _PTR(SObject) anObj, aRef;
1174 bool isRefOrSubShape = false;
1175 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1176 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1177 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1178 isRefOrSubShape = true;
1180 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1181 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1182 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1183 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1184 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1185 if (aRef->GetID() == aFather->GetID())
1186 isRefOrSubShape = true;
1188 aFather = aFather->GetFather();
1192 if (isRefOrSubShape)
1193 myGeomObjects[i++] = aGeomGroup;
1196 myGeomObjects->length(i);
1208 if (myCurrentLineEdit == mySubMeshLine)
1209 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1210 else if (myCurrentLineEdit == myGroupLine)
1211 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1212 else if (myCurrentLineEdit == myGeomGroupLine)
1213 aString = tr( "%1 Objects" ).arg(aNbSel);
1216 aString = aList.First()->getName();
1220 myCurrentLineEdit->setText(aString);
1221 myCurrentLineEdit->home(false);
1222 // 07.06.2008 skl for IPAL19574:
1223 // change name of group only if it is empty
1224 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1225 myOldName = myName->text();
1226 myName->blockSignals(true);
1227 myName->setText(aString);
1228 myName->blockSignals(false);
1233 else // !myCurrentLineEdit: local selection of nodes or elements
1235 if (aNbSel == 1 && myActorsList.count() > 0 )
1237 // NPAL19389: create a group with a selection in another group
1238 // Switch myActor to the newly selected one, if the last
1239 // is visible and belongs to group or submesh of myMesh
1240 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1241 Handle(SALOME_InteractiveObject) selIO = aList.First();
1242 if (curIO->hasEntry() && selIO->hasEntry()) {
1243 const char* selEntry = selIO->getEntry();
1244 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1245 // different objects: selected and myActor
1246 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1247 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1248 // newly selected actor is visible
1251 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1253 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1254 int len = strlen(meshEntry);
1256 if (strncmp(selEntry, meshEntry, len) == 0) {
1257 // selected object is myMesh or a part of it
1258 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1261 SMESH::SetPickable(myActor);
1270 QString aListStr = "";
1272 if (myTypeId == 0) {
1273 QListIterator<SMESH_Actor*> it( myActorsList );
1274 while ( it.hasNext() ) {
1276 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1280 QListIterator<SMESH_Actor*> it( myActorsList );
1281 while ( it.hasNext() ) {
1283 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1288 QListWidgetItem* anItem;
1289 QList<QListWidgetItem*> listItemsToSel;
1290 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1291 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1292 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1293 foreach(anItem, found)
1294 if (!anItem->isSelected())
1295 listItemsToSel.push_back(anItem);
1297 bool blocked = myElements->signalsBlocked();
1298 myElements->blockSignals(true);
1299 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1300 myElements->blockSignals(blocked);
1301 onListSelectionChanged();
1302 listItemsToSel.clear();
1307 if (myActorsList.count() == 0) {
1308 if (!myGroup->_is_nil()) {
1309 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1311 myActorsList.append( anActor );
1313 else if(!myGroupOnGeom->_is_nil()) {
1314 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1316 myActorsList.append( anActor );
1319 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1321 myActorsList.append( anActor );
1325 // somehow, if we display the mesh, while selecting from another actor,
1326 // the mesh becomes pickable, and there is no way to select any element
1327 if (myActorsList.count() > 0) {
1328 QListIterator<SMESH_Actor*> it( myActorsList );
1329 while ( it.hasNext() ) {
1330 SMESH_Actor* anActor = it.next();
1331 if ( IsActorVisible(anActor) )
1332 anActor->SetPickable(true);
1339 //=================================================================================
1340 // function : onSelectSubMesh()
1341 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1342 //=================================================================================
1343 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1346 if (mySelectGroup->isChecked()) {
1347 mySelectGroup->setChecked(false);
1349 //VSR: else if (mySelectGeomGroup->isChecked()) {
1350 //VSR: mySelectGeomGroup->setChecked(false);
1352 myCurrentLineEdit = mySubMeshLine;
1353 setSelectionMode(4);
1356 mySubMeshLine->setText( "" );
1357 myCurrentLineEdit = 0;
1359 setSelectionMode(myTypeId);
1361 mySubMeshBtn->setEnabled(on);
1362 mySubMeshLine->setEnabled(on);
1366 //=================================================================================
1367 // function : (onSelectGroup)
1368 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1369 //=================================================================================
1370 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1373 if (mySelectSubMesh->isChecked()) {
1374 mySelectSubMesh->setChecked(false);
1376 myCurrentLineEdit = myGroupLine;
1377 setSelectionMode(5);
1380 myGroupLine->setText( "" );
1381 myCurrentLineEdit = 0;
1383 setSelectionMode(myTypeId);
1385 myGroupBtn->setEnabled(on);
1386 myGroupLine->setEnabled(on);
1390 //=================================================================================
1391 // function : (onSelectGeomGroup)
1392 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1393 //=================================================================================
1394 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1397 if (mySelectSubMesh->isChecked()) {
1398 mySelectSubMesh->setChecked(false);
1400 else if (mySelectGroup->isChecked()) {
1401 mySelectGroup->setChecked(false);
1403 myCurrentLineEdit = myGeomGroupLine;
1405 setSelectionMode(8);
1408 myGeomGroupBtn->setChecked(false);
1409 myGeomObjects->length(0);
1410 myGeomGroupLine->setText( "" );
1411 myCurrentLineEdit = 0;
1413 setSelectionMode(myTypeId);
1418 //=================================================================================
1419 // function : setCurrentSelection()
1421 //=================================================================================
1422 void SMESHGUI_GroupDlg::setCurrentSelection()
1424 QPushButton* send = (QPushButton*)sender();
1425 myCurrentLineEdit = 0;
1426 if (send == myMeshGroupBtn) {
1427 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1428 mySelectionMgr->clearSelected();
1430 setSelectionMode(6);
1432 setSelectionMode(5);
1433 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1434 myCurrentLineEdit = myMeshGroupLine;
1435 onObjectSelectionChanged();
1437 else if (send == mySubMeshBtn) {
1438 myCurrentLineEdit = mySubMeshLine;
1439 onObjectSelectionChanged();
1441 else if (send == myGroupBtn) {
1442 myCurrentLineEdit = myGroupLine;
1443 onObjectSelectionChanged();
1448 //=================================================================================
1449 // function : setFilters()
1450 // purpose : SLOT. Called when "Filter" button pressed.
1451 //=================================================================================
1452 void SMESHGUI_GroupDlg::setFilters()
1454 if(myMesh->_is_nil()) {
1455 SUIT_MessageBox::critical(this,
1457 tr("NO_MESH_SELECTED"));
1461 SMESH::ElementType aType = SMESH::ALL;
1464 case 0 : aType = SMESH::NODE; break;
1465 case 1 : aType = SMESH::EDGE; break;
1466 case 2 : aType = SMESH::FACE; break;
1467 case 3 : aType = SMESH::VOLUME; break;
1471 if ( myFilterDlg == 0 )
1473 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1474 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1477 myFilterDlg->Init( aType );
1479 myFilterDlg->SetSelection();
1480 myFilterDlg->SetMesh( myMesh );
1481 myFilterDlg->SetSourceWg( myElements, false );
1483 myFilterDlg->show();
1486 //=================================================================================
1487 // function : onFilterAccepted()
1488 // purpose : SLOT. Called when Filter dlg closed with OK button.
1489 // Uncheck "Select submesh" and "Select group" checkboxes
1490 //=================================================================================
1491 void SMESHGUI_GroupDlg::onFilterAccepted()
1493 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1495 mySelectionMode = myTypeId;
1496 mySelectSubMesh->setChecked( false );
1497 mySelectGroup->setChecked( false );
1501 //=================================================================================
1502 // function : onAdd()
1504 //=================================================================================
1505 void SMESHGUI_GroupDlg::onAdd()
1507 SALOME_ListIO aList;
1508 mySelectionMgr->selectedObjects( aList );
1510 int aNbSel = aList.Extent();
1512 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1516 SMESH::ElementType aType = SMESH::ALL;
1519 aType = SMESH::NODE;
1520 mySelector->SetSelectionMode(NodeSelection);
1523 aType = SMESH::EDGE;
1524 mySelector->SetSelectionMode(EdgeSelection);
1527 aType = SMESH::FACE;
1528 mySelector->SetSelectionMode(FaceSelection);
1531 aType = SMESH::VOLUME;
1532 mySelector->SetSelectionMode(VolumeSelection);
1535 mySelector->SetSelectionMode(ActorSelection);
1538 QListWidgetItem* anItem = 0;
1539 QList<QListWidgetItem*> listItemsToSel;
1541 if (myCurrentLineEdit == 0) {
1542 //if (aNbSel != 1) { myIsBusy = false; return; }
1543 QString aListStr = "";
1545 if (myTypeId == 0) {
1546 QListIterator<SMESH_Actor*> it( myActorsList );
1547 while ( it.hasNext() ) {
1549 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1554 QListIterator<SMESH_Actor*> it( myActorsList );
1555 while ( it.hasNext() ) {
1557 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1562 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1563 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1564 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1565 if (found.count() == 0) {
1566 anItem = new QListWidgetItem(*it);
1567 myElements->addItem(anItem);
1568 if (!anItem->isSelected())
1569 listItemsToSel.push_back(anItem);
1572 foreach(anItem, found)
1573 if (!anItem->isSelected())
1574 listItemsToSel.push_back(anItem);
1577 bool blocked = myElements->signalsBlocked();
1578 myElements->blockSignals(true);
1579 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1580 myElements->blockSignals(blocked);
1581 onListSelectionChanged();
1582 listItemsToSel.clear();
1584 } else if (myCurrentLineEdit == mySubMeshLine) {
1585 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1587 SALOME_ListIO aList;
1588 mySelectionMgr->selectedObjects( aList );
1590 SALOME_ListIteratorOfListIO anIt (aList);
1591 for ( ; anIt.More(); anIt.Next()) {
1592 SMESH::SMESH_subMesh_var aSubMesh =
1593 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1594 if (!aSubMesh->_is_nil()) {
1595 // check if mesh is the same
1596 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1598 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1599 int k = anElements->length();
1600 for (int i = 0; i < k; i++) {
1601 QString aText = QString::number(anElements[i]);
1602 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1603 if (found.count() == 0) {
1604 anItem = new QListWidgetItem(aText);
1605 myElements->addItem(anItem);
1606 if (!anItem->isSelected())
1607 listItemsToSel.push_back(anItem);
1610 foreach(anItem, found)
1611 if (!anItem->isSelected())
1612 listItemsToSel.push_back(anItem);
1615 bool blocked = myElements->signalsBlocked();
1616 myElements->blockSignals(true);
1617 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1618 myElements->blockSignals(blocked);
1619 onListSelectionChanged();
1620 listItemsToSel.clear();
1622 catch (const SALOME::SALOME_Exception& ex) {
1623 SalomeApp_Tools::QtCatchCorbaException(ex);
1628 mySelectSubMesh->setChecked(false);
1630 onListSelectionChanged();
1632 } else if (myCurrentLineEdit == myGroupLine) {
1633 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1634 SALOME_ListIO aList;
1635 mySelectionMgr->selectedObjects( aList );
1637 SALOME_ListIteratorOfListIO anIt (aList);
1638 for ( ; anIt.More(); anIt.Next()) {
1639 SMESH::SMESH_GroupBase_var aGroup =
1640 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1641 if (!aGroup->_is_nil()) {
1642 // check if mesh is the same
1643 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1644 SMESH::long_array_var anElements = aGroup->GetListOfID();
1645 int k = anElements->length();
1646 for (int i = 0; i < k; i++) {
1647 QString aText = QString::number(anElements[i]);
1648 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1649 if (found.count() == 0) {
1650 anItem = new QListWidgetItem(aText);
1651 myElements->addItem(anItem);
1652 if (!anItem->isSelected())
1653 listItemsToSel.push_back(anItem);
1656 foreach(anItem, found)
1657 if (!anItem->isSelected())
1658 listItemsToSel.push_back(anItem);
1661 bool blocked = myElements->signalsBlocked();
1662 myElements->blockSignals(true);
1663 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1664 myElements->blockSignals(blocked);
1665 onListSelectionChanged();
1666 listItemsToSel.clear();
1670 mySelectGroup->setChecked(false);
1672 onListSelectionChanged();
1674 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1675 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1676 GEOM::GEOM_IGroupOperations_var aGroupOp =
1677 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1679 SMESH::ElementType aGroupType = SMESH::ALL;
1680 switch(aGroupOp->GetType(myGeomObjects[0])) {
1681 case 7: aGroupType = SMESH::NODE; break;
1682 case 6: aGroupType = SMESH::EDGE; break;
1683 case 4: aGroupType = SMESH::FACE; break;
1684 case 2: aGroupType = SMESH::VOLUME; break;
1685 default: myIsBusy = false; return;
1688 if (aGroupType == aType) {
1689 _PTR(SObject) aGroupSO =
1690 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1691 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1693 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1694 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1695 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1696 aBelongToGeom->SetGeom(myGeomObjects[0]);
1697 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1698 aBelongToGeom->SetElementType(aType);
1699 aFilter->SetPredicate(aBelongToGeom);
1701 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1703 int k = anElements->length();
1704 for (int i = 0; i < k; i++) {
1705 QString aText = QString::number(anElements[i]);
1706 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1707 if (found.count() == 0) {
1708 anItem = new QListWidgetItem(aText);
1709 myElements->addItem(anItem);
1710 if (!anItem->isSelected())
1711 listItemsToSel.push_back(anItem);
1714 foreach(anItem, found)
1715 if (!anItem->isSelected())
1716 listItemsToSel.push_back(anItem);
1719 bool blocked = myElements->signalsBlocked();
1720 myElements->blockSignals(true);
1721 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1722 myElements->blockSignals(blocked);
1723 onListSelectionChanged();
1724 listItemsToSel.clear();
1727 //VSR: mySelectGeomGroup->setChecked(false);
1729 onListSelectionChanged();
1732 // mySelectionMgr->clearSelected();
1736 //=================================================================================
1737 // function : onRemove()
1739 //=================================================================================
1740 void SMESHGUI_GroupDlg::onRemove()
1743 if (myCurrentLineEdit == 0) {
1744 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1745 QListWidgetItem* item;
1746 foreach(item, selItems) delete item;
1748 SALOME_ListIO aList;
1749 mySelectionMgr->selectedObjects( aList );
1751 int aNbSel = aList.Extent();
1753 if (aNbSel == 0) { myIsBusy = false; return; }
1755 SMESH::ElementType aType = SMESH::ALL;
1757 case 0: aType = SMESH::NODE; break;
1758 case 1: aType = SMESH::EDGE; break;
1759 case 2: aType = SMESH::FACE; break;
1760 case 3: aType = SMESH::VOLUME; break;
1763 if (myCurrentLineEdit == mySubMeshLine) {
1764 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1765 SALOME_ListIO aList;
1766 mySelectionMgr->selectedObjects( aList );
1768 SALOME_ListIteratorOfListIO anIt (aList);
1769 for ( ; anIt.More(); anIt.Next()) {
1770 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1771 if (!aSubMesh->_is_nil()) {
1772 // check if mesh is the same
1773 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1774 if (aType == SMESH::NODE) {
1776 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1777 int k = anElements->length();
1778 for (int i = 0; i < k; i++) {
1779 QList<QListWidgetItem*> found =
1780 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1781 QListWidgetItem* anItem;
1782 foreach(anItem, found) delete anItem;
1785 catch (const SALOME::SALOME_Exception& ex) {
1786 SalomeApp_Tools::QtCatchCorbaException(ex);
1791 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1792 int k = anElements->length();
1793 for (int i = 0; i < k; i++) {
1794 QList<QListWidgetItem*> found =
1795 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1796 QListWidgetItem* anItem;
1797 foreach(anItem, found) delete anItem;
1800 catch (const SALOME::SALOME_Exception& ex) {
1801 SalomeApp_Tools::QtCatchCorbaException(ex);
1808 else if (myCurrentLineEdit == myGroupLine) {
1809 Standard_Boolean aRes;
1810 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1811 SALOME_ListIO aList;
1812 mySelectionMgr->selectedObjects( aList );
1814 SALOME_ListIteratorOfListIO anIt (aList);
1815 for ( ; anIt.More(); anIt.Next()) {
1816 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1817 if (aRes && !aGroup->_is_nil()) {
1818 // check if mesh is the same
1819 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1820 SMESH::long_array_var anElements = aGroup->GetListOfID();
1821 int k = anElements->length();
1822 for (int i = 0; i < k; i++) {
1823 QList<QListWidgetItem*> found =
1824 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1825 QListWidgetItem* anItem;
1826 foreach(anItem, found) delete anItem;
1837 //=================================================================================
1838 // function : onSort()
1840 //=================================================================================
1841 void SMESHGUI_GroupDlg::onSort()
1843 // PAL5412: sorts items in ascending by "string" value
1844 // myElements->sort(true);
1845 // myElements->update();
1846 int i, k = myElements->count();
1849 QList<int> aSelected;
1850 std::vector<int> anArray(k);
1851 // QMemArray<int> anArray(k);
1853 for (i = 0; i < k; i++) {
1854 int id = myElements->item(i)->text().toInt();
1856 if (myElements->item(i)->isSelected())
1857 aSelected.append(id);
1859 // sort & update list
1860 std::sort(anArray.begin(), anArray.end());
1862 myElements->clear();
1863 QListWidgetItem* anItem;
1864 QList<QListWidgetItem*> listItemsToSel;
1865 for (i = 0; i < k; i++) {
1866 anItem = new QListWidgetItem(QString::number(anArray[i]));
1867 myElements->addItem(anItem);
1868 if (aSelected.contains(anArray[i]))
1869 listItemsToSel.push_back(anItem);
1871 bool blocked = myElements->signalsBlocked();
1872 myElements->blockSignals(true);
1873 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1874 myElements->blockSignals(blocked);
1875 listItemsToSel.clear();
1880 //=================================================================================
1881 // function : closeEvent()
1883 //=================================================================================
1884 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1889 //=================================================================================
1890 // function : onVisibilityChanged()
1892 //=================================================================================
1893 void SMESHGUI_GroupDlg::onVisibilityChanged()
1895 SetAppropriateActor();
1898 //=================================================================================
1899 // function : SMESHGUI_GroupDlg::onClose
1900 // purpose : SLOT called when "Close" button pressed. Close dialog
1901 //=================================================================================
1902 void SMESHGUI_GroupDlg::onClose()
1904 if (SMESH::GetCurrentVtkView()) {
1905 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1906 SMESH::SetPointRepresentation(false);
1907 SMESH::SetPickable();
1908 restoreShowEntityMode();
1911 mySelectionMgr->clearSelected();
1912 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1913 aViewWindow->SetSelectionMode(ActorSelection);
1914 mySelectionMgr->clearFilters();
1915 mySMESHGUI->ResetState();
1920 //=================================================================================
1921 // function : onHelp()
1923 //=================================================================================
1924 void SMESHGUI_GroupDlg::onHelp()
1926 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1928 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1932 platform = "winapplication";
1934 platform = "application";
1936 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1937 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1938 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1940 arg(myHelpFileName));
1944 //=================================================================================
1945 // function : SMESHGUI_GroupDlg::onDeactivate
1946 // purpose : SLOT called when dialog must be deativated
1947 //=================================================================================
1948 void SMESHGUI_GroupDlg::onDeactivate()
1950 mySMESHGUI->ResetState();
1954 //=================================================================================
1955 // function : SMESHGUI_GroupDlg::enterEvent
1956 // purpose : Event filter
1957 //=================================================================================
1958 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1961 mySMESHGUI->EmitSignalDeactivateDialog();
1963 mySelectionMode = -1;
1964 setSelectionMode(myTypeId);
1965 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1966 mySMESHGUI->SetActiveDialogBox(this);
1967 mySMESHGUI->SetState(800);
1971 //=================================================================================
1972 // function : hideEvent
1973 // purpose : caused by ESC key
1974 //=================================================================================
1975 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1977 if (!isMinimized() && !myIsBusy)
1981 //=================================================================================
1982 // function : keyPressEvent()
1984 //=================================================================================
1985 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1987 QDialog::keyPressEvent( e );
1988 if ( e->isAccepted() )
1991 if ( e->key() == Qt::Key_F1 )
1998 //================================================================================
2000 * \brief Enable showing of the popup when Geometry selection btn is clicked
2001 * \param enable - true to enable
2003 //================================================================================
2005 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2007 void SMESHGUI_GroupDlg::updateGeomPopup()
2009 bool enable = false;
2011 if ( !myMesh->_is_nil() )
2012 enable = myMesh->NbEdges() > 0;
2014 if ( myGeomGroupBtn )
2016 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2018 if ( !myGeomPopup ) {
2019 myGeomPopup = new QMenu(this);
2020 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2021 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2022 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2024 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2030 //=================================================================================
2031 // function : onGeomSelectionButton()
2033 //=================================================================================
2034 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2036 if ( myGeomPopup && isBtnOn )
2038 myCurrentLineEdit = myGeomGroupLine;
2039 QAction* a = myGeomPopup->exec( QCursor::pos() );
2040 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2041 setSelectionMode(7);
2045 myCurrentLineEdit = 0;
2046 setSelectionMode(8);
2050 //=================================================================================
2051 // function : onGeomPopup()
2053 //=================================================================================
2054 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2056 int index = myActions[a];
2057 if ( index == GEOM_BY_MESH_INDEX )
2059 mySelectionMode = -1;
2060 if ( !myShapeByMeshOp ) {
2061 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2062 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2063 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2064 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2065 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2067 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2068 if ( !myMesh->_is_nil() ) {
2070 hide(); // stop processing selection
2072 myShapeByMeshOp->setModule( mySMESHGUI );
2073 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2074 myShapeByMeshOp->SetMesh( myMesh );
2075 myShapeByMeshOp->start();
2080 //================================================================================
2082 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2084 //================================================================================
2086 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2088 if ( myShapeByMeshOp == op ) {
2089 mySMESHGUI->getApp()->updateObjectBrowser();
2091 // Select a found geometry object
2092 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2093 if ( !aGeomVar->_is_nil() )
2095 QString ID = aGeomVar->GetStudyEntry();
2096 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2097 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2098 SALOME_ListIO anIOList;
2099 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2100 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2101 anIOList.Append( anIO );
2102 mySelectionMgr->setSelectedObjects( anIOList, false );
2103 onObjectSelectionChanged();
2109 //================================================================================
2111 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2113 //================================================================================
2115 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2117 if ( myShapeByMeshOp == op )
2120 setSelectionMode(7);
2124 //=================================================================================
2125 // function : setGroupColor()
2127 //=================================================================================
2128 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2130 QColor aQColor( (int)( theColor.R * 255.0 ),
2131 (int)( theColor.G * 255.0 ),
2132 (int)( theColor.B * 255.0 ) );
2133 setGroupQColor( aQColor );
2136 //=================================================================================
2137 // function : getGroupColor()
2139 //=================================================================================
2140 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2142 QColor aQColor = getGroupQColor();
2144 SALOMEDS::Color aColor;
2145 aColor.R = (float)aQColor.red() / 255.0;
2146 aColor.G = (float)aQColor.green() / 255.0;
2147 aColor.B = (float)aQColor.blue() / 255.0;
2152 //=================================================================================
2153 // function : setGroupQColor()
2155 //=================================================================================
2156 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2158 if( theColor.isValid() )
2159 myColorBtn->setColor( theColor );
2162 //=================================================================================
2163 // function : getGroupQColor()
2165 //=================================================================================
2166 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2168 return myColorBtn->color();
2171 //=================================================================================
2172 // function : setDefaultGroupColor()
2174 //=================================================================================
2175 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2177 if( myMesh->_is_nil() )
2180 bool isAutoColor = myMesh->GetAutoColor();
2185 int r = 0, g = 0, b = 0;
2186 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2187 aQColor.setRgb( r, g, b );
2191 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2193 QList<SALOMEDS::Color> aReservedColors;
2194 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2196 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2197 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2198 aReservedColors.append( aReservedColor );
2201 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2202 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2203 (int)( aColor.G * 255.0 ),
2204 (int)( aColor.B * 255.0 ) );
2208 setGroupQColor( aQColor );
2211 //=================================================================================
2212 // function : SetAppropriateActor()
2213 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2214 // NPAL19389: create a group with a selection in another group.
2215 // if mesh actor is not visible - find any first visible group or submesh
2216 //=================================================================================
2217 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2219 bool isActor = false;
2220 myActorsList.clear();
2222 if (myMesh->_is_nil()) return false;
2224 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2226 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2228 if (!myGroupOnGeom->_is_nil()) {
2229 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2230 if (anActor && anActor->hasIO())
2233 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2236 myActorsList.append(anActor);
2242 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2243 if (anActor && anActor->hasIO()) {
2245 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2248 myActorsList.append(anActor);
2252 if (!isActor && !myGroup->_is_nil()) {
2253 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2254 if (anActor && anActor->hasIO())
2255 myActorsList.append(anActor);
2258 // try any visible actor of group or submesh of current mesh
2261 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2263 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2264 int len = strlen(meshEntry);
2266 // iterate on all actors in current view window, search for
2267 // any visible actor, that belongs to group or submesh of current mesh
2268 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2269 vtkActorCollection *aCollection = aCopy.GetActors();
2270 int nbItems = aCollection->GetNumberOfItems();
2271 for (int i=0; i<nbItems && !isActor; i++)
2273 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2274 if (anActor && anActor->hasIO()) {
2275 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2276 if (aViewWindow->isVisible(anIO)) {
2277 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2278 myActorsList.append(anActor);
2286 if (myActorsList.count() > 0) {
2287 QListIterator<SMESH_Actor*> it( myActorsList );
2288 while ( it.hasNext() ) {
2289 SMESH_Actor* anActor = it.next();
2290 if ( IsActorVisible(anActor) )
2291 anActor->SetPickable(true);
2295 return ( isActor || (myActorsList.count() > 0) );
2298 //=======================================================================
2299 //function : setShowEntityMode
2300 //purpose : make shown only entity corresponding to my type
2301 //=======================================================================
2302 void SMESHGUI_GroupDlg::setShowEntityMode()
2304 if ( !myMesh->_is_nil() ) {
2305 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2306 if (!myStoredShownEntity)
2307 myStoredShownEntity = actor->GetEntityMode();
2308 switch ( myTypeId ) {
2309 case 0: restoreShowEntityMode(); break;
2310 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2311 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2312 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2318 //=======================================================================
2319 //function : restoreShowEntityMode
2320 //purpose : restore ShowEntity mode of myActor
2321 //=======================================================================
2322 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2324 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2325 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2326 actor->SetEntityMode(myStoredShownEntity);
2329 myStoredShownEntity = 0;
2332 //=======================================================================
2333 //function : IsActorVisible
2334 //purpose : return visibility of the actor
2335 //=======================================================================
2336 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2338 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2339 if (theActor && aViewWindow)
2340 return aViewWindow->isVisible(theActor->getIO());