1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_GroupDlg.cxx
24 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
27 #include "SMESHGUI_GroupDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_GroupUtils.h"
33 #include "SMESHGUI_FilterUtils.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
35 #include "SMESHGUI_FilterDlg.h"
36 #include "SMESHGUI_ShapeByMeshDlg.h"
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_Actor.h>
40 #include <SMESH_ActorUtils.h>
42 // SALOME GEOM includes
44 #include <GEOM_SelectionFilter.h>
46 // SALOME GUI includes
47 #include <QtxColorButton.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_ResourceMgr.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_MessageBox.h>
54 #include <SalomeApp_Tools.h>
55 #include <SalomeApp_Application.h>
56 #include <SalomeApp_Study.h>
57 #include <LightApp_SelectionMgr.h>
59 #include <SALOME_ListIO.hxx>
60 #include <SALOME_ListIteratorOfListIO.hxx>
62 #include <SVTK_ViewWindow.h>
64 #include <VTKViewer_Algorithm.h>
66 // SALOME KERNEL includes
67 #include <SALOMEDSClient_Study.hxx>
70 #include <vtkRenderer.h>
71 #include <vtkActorCollection.h>
74 #include <TColStd_MapOfInteger.hxx>
77 #include <QButtonGroup>
81 #include <QPushButton>
82 #include <QToolButton>
83 #include <QRadioButton>
85 #include <QGridLayout>
86 #include <QHBoxLayout>
87 #include <QVBoxLayout>
88 #include <QListWidget>
89 #include <QStackedWidget>
101 //=================================================================================
102 // function : SMESHGUI_GroupDlg()
104 //=================================================================================
105 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
106 SMESH::SMESH_Mesh_ptr theMesh )
107 : QDialog( SMESH::GetDesktop( theModule ) ),
108 mySMESHGUI( theModule ),
109 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
110 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
112 myNameChanged( false )
115 if ( !theMesh->_is_nil() )
119 mySelectSubMesh->setEnabled( false );
120 mySelectGroup->setEnabled( false );
121 myGeomGroupBtn->setEnabled( false );
122 myGeomGroupLine->setEnabled( false );
126 //=================================================================================
127 // function : SMESHGUI_GroupDlg()
129 //=================================================================================
130 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
131 SMESH::SMESH_GroupBase_ptr theGroup,
132 const bool theIsConvert )
133 : QDialog( SMESH::GetDesktop( theModule ) ),
134 mySMESHGUI( theModule ),
135 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
136 mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
138 myNameChanged( false )
141 if ( !theGroup->_is_nil() )
142 init( theGroup, theIsConvert );
145 mySelectSubMesh->setEnabled( false );
146 mySelectGroup->setEnabled( false );
148 myCurrentLineEdit = myMeshGroupLine;
149 setSelectionMode( 5 );
153 //=================================================================================
154 // function : SMESHGUI_GroupDlg()
156 //=================================================================================
157 void SMESHGUI_GroupDlg::initDialog( bool create)
160 setAttribute( Qt::WA_DeleteOnClose, true );
164 myCurrentLineEdit = 0;
168 myGeomObjects = new GEOM::ListOfGO();
169 myGeomObjects->length( 0 );
171 QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) );
173 setWindowTitle( create ? tr( "SMESH_CREATE_GROUP_TITLE" ) : tr( "SMESH_EDIT_GROUP_TITLE" ) );
174 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
176 setSizeGripEnabled( true);
178 QGridLayout* aMainLayout = new QGridLayout( this );
179 aMainLayout->setMargin( MARGIN );
180 aMainLayout->setSpacing( SPACING );
182 /***************************************************************/
183 QLabel* meshGroupLab = new QLabel( create ? tr( "SMESH_MESH" ) : tr( "SMESH_GROUP" ), this );
184 myMeshGroupBtn = new QPushButton( this );
185 myMeshGroupBtn->setIcon( image0 );
186 myMeshGroupLine = new QLineEdit( this );
187 myMeshGroupLine->setReadOnly( true );
189 /***************************************************************/
190 QGroupBox* aTypeBox = new QGroupBox( tr( "SMESH_ELEMENTS_TYPE" ), this );
191 myTypeGroup = new QButtonGroup( this );
192 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
193 aTypeBoxLayout->setMargin( MARGIN );
194 aTypeBoxLayout->setSpacing( SPACING );
197 types.append( tr( "MESH_NODE" ) );
198 types.append( tr( "SMESH_EDGE" ) );
199 types.append( tr( "SMESH_FACE" ) );
200 types.append( tr( "SMESH_VOLUME" ) );
202 for ( int i = 0; i < types.count(); i++ )
204 rb = new QRadioButton( types[i], aTypeBox );
205 myTypeGroup->addButton( rb, i );
206 aTypeBoxLayout->addWidget( rb );
208 aTypeBox->setEnabled( create );
211 /***************************************************************/
212 QLabel* aName = new QLabel( tr( "SMESH_NAME" ), this );
213 aName->setMinimumWidth( 50 );
214 myName = new QLineEdit( this );
216 /***************************************************************/
217 QGroupBox* aGrpTypeBox = new QGroupBox( tr( "SMESH_GROUP_TYPE" ), this );
218 myGrpTypeGroup = new QButtonGroup( this );
219 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
220 aGrpTypeBoxLayout->setMargin( MARGIN );
221 aGrpTypeBoxLayout->setSpacing( SPACING );
223 QRadioButton* rb1 = new QRadioButton( tr( "SMESH_GROUP_STANDALONE" ), aGrpTypeBox );
224 QRadioButton* rb2 = new QRadioButton( tr( "SMESH_GROUP_GEOMETRY" ), aGrpTypeBox );
225 myGrpTypeGroup->addButton( rb1, 0 );
226 myGrpTypeGroup->addButton( rb2, 1 );
227 aGrpTypeBoxLayout->addWidget( rb1 );
228 aGrpTypeBoxLayout->addWidget( rb2 );
229 aGrpTypeBox->setEnabled( create );
232 /***************************************************************/
233 myWGStack = new QStackedWidget( this );
234 QWidget* wg1 = new QWidget( myWGStack );
235 QWidget* wg2 = new QWidget( myWGStack );
237 /***************************************************************/
238 QGroupBox* aContentBox = new QGroupBox( tr( "SMESH_CONTENT" ), wg1 );
239 QGridLayout* aContentBoxLayout = new QGridLayout( aContentBox );
240 aContentBoxLayout->setMargin( MARGIN );
241 aContentBoxLayout->setSpacing( SPACING );
243 QLabel* aLabel = new QLabel( tr( "SMESH_ID_ELEMENTS" ), aContentBox );
244 myElements = new QListWidget( aContentBox );
245 myElements->setSelectionMode( QListWidget::ExtendedSelection );
247 myFilter = new QPushButton( tr( "SMESH_BUT_FILTER" ), aContentBox );
248 QPushButton* aAddBtn = new QPushButton( tr( "SMESH_BUT_ADD" ), aContentBox );
249 QPushButton* aRemoveBtn = new QPushButton( tr( "SMESH_BUT_REMOVE" ), aContentBox );
250 QPushButton* aSortBtn = new QPushButton( tr( "SMESH_BUT_SORT" ), aContentBox );
252 aContentBoxLayout->addWidget( aLabel, 0, 0 );
253 aContentBoxLayout->addWidget( myElements, 1, 0, 6, 1 );
254 aContentBoxLayout->addWidget( myFilter, 1, 1 );
255 aContentBoxLayout->addWidget( aAddBtn, 3, 1 );
256 aContentBoxLayout->addWidget( aRemoveBtn, 4, 1 );
257 aContentBoxLayout->addWidget( aSortBtn, 6, 1 );
259 aContentBoxLayout->setColumnStretch( 0, 1 );
260 aContentBoxLayout->setRowStretch( 2, 1 );
261 aContentBoxLayout->setRowStretch( 5, 1 );
263 /***************************************************************/
264 QGroupBox* aSelectBox = new QGroupBox( tr( "SMESH_SELECT_FROM" ), wg1 );
265 QGridLayout* aSelectBoxLayout = new QGridLayout( aSelectBox );
266 aSelectBoxLayout->setMargin( MARGIN );
267 aSelectBoxLayout->setSpacing( SPACING );
269 mySelectSubMesh = new QCheckBox( tr( "SMESH_SUBMESH" ), aSelectBox );
270 mySubMeshBtn = new QPushButton( aSelectBox );
271 mySubMeshBtn->setIcon( image0 );
272 mySubMeshLine = new QLineEdit( aSelectBox );
273 mySubMeshLine->setReadOnly( true );
274 onSelectSubMesh( false );
276 mySelectGroup = new QCheckBox( tr( "SMESH_GROUP" ), aSelectBox );
277 myGroupBtn = new QPushButton( aSelectBox );
278 myGroupBtn->setIcon( image0 );
279 myGroupLine = new QLineEdit( aSelectBox );
280 myGroupLine->setReadOnly( true );
281 onSelectGroup( false );
283 aSelectBoxLayout->addWidget( mySelectSubMesh, 0, 0 );
284 aSelectBoxLayout->addWidget( mySubMeshBtn, 0, 1 );
285 aSelectBoxLayout->addWidget( mySubMeshLine, 0, 2 );
286 aSelectBoxLayout->addWidget( mySelectGroup, 1, 0 );
287 aSelectBoxLayout->addWidget( myGroupBtn, 1, 1 );
288 aSelectBoxLayout->addWidget( myGroupLine, 1, 2 );
290 /***************************************************************/
291 QVBoxLayout* wg1Layout = new QVBoxLayout( wg1 );
292 wg1Layout->setMargin( 0 );
293 wg1Layout->setSpacing( SPACING );
294 wg1Layout->addWidget( aContentBox );
295 wg1Layout->addWidget( aSelectBox );
296 wg1Layout->setStretchFactor( aContentBox, 10 );
298 /***************************************************************/
299 QLabel* geomObject = new QLabel( tr( "SMESH_OBJECT_GEOM" ), wg2 );
300 myGeomGroupBtn = new QToolButton( wg2 );
301 myGeomGroupBtn->setIcon( image0 );
302 myGeomGroupBtn->setCheckable( true );
303 myGeomGroupLine = new QLineEdit( wg2 );
304 myGeomGroupLine->setReadOnly( true ); //VSR ???
305 onSelectGeomGroup( false );
307 myGeomGroupBtn->setEnabled( create );
308 myGeomGroupLine->setEnabled( create );
310 /***************************************************************/
311 QGridLayout* wg2Layout = new QGridLayout( wg2 );
312 wg2Layout->setMargin( 0 );
313 wg1Layout->setSpacing( SPACING );
314 wg2Layout->addWidget( geomObject, 0, 0 );
315 wg2Layout->addWidget( myGeomGroupBtn, 0, 1 );
316 wg2Layout->addWidget( myGeomGroupLine,0, 2 );
317 wg2Layout->setRowStretch( 1, 5 );
319 /***************************************************************/
320 myWGStack->insertWidget( 0, wg1 );
321 myWGStack->insertWidget( 1, wg2 );
323 /***************************************************************/
324 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
325 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
326 aColorBoxLayout->setMargin(MARGIN);
327 aColorBoxLayout->setSpacing(SPACING);
329 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
330 myColorBtn = new QtxColorButton(aColorBox);
331 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
332 myColorBtn->sizePolicy().verticalPolicy() );
334 aColorBoxLayout->addWidget(aColorLab);
335 aColorBoxLayout->addWidget(myColorBtn);
337 /***************************************************************/
339 QFrame* aButtons = new QFrame(this);
340 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
341 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
342 aBtnLayout->setMargin(MARGIN);
343 aBtnLayout->setSpacing(SPACING);
345 myOKBtn = new QPushButton(tr( "SMESH_BUT_APPLY_AND_CLOSE" ), aButtons);
346 myOKBtn->setAutoDefault(true);
347 myOKBtn->setDefault(true);
348 myApplyBtn = new QPushButton(tr( "SMESH_BUT_APPLY" ), aButtons);
349 myApplyBtn->setAutoDefault(true);
350 myCloseBtn = new QPushButton(tr( "SMESH_BUT_CLOSE" ), aButtons);
351 myCloseBtn->setAutoDefault(true);
352 myHelpBtn = new QPushButton(tr( "SMESH_BUT_HELP" ), aButtons);
353 myHelpBtn->setAutoDefault(true);
355 aBtnLayout->addWidget(myOKBtn);
356 aBtnLayout->addSpacing(10);
357 aBtnLayout->addWidget(myApplyBtn);
358 aBtnLayout->addSpacing(10);
359 aBtnLayout->addStretch();
360 aBtnLayout->addWidget(myCloseBtn);
361 aBtnLayout->addWidget(myHelpBtn);
363 /***************************************************************/
364 aMainLayout->addWidget(meshGroupLab, 0, 0);
365 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
366 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
367 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
368 aMainLayout->addWidget(aName, 2, 0);
369 aMainLayout->addWidget(myName, 2, 2);
370 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
371 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
372 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
373 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
375 /* signals and slots connections */
376 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
377 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
378 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
380 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
381 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
383 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
384 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
385 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
386 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
388 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
389 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
390 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
391 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
392 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
394 connect(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
396 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
397 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
398 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
399 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
402 mySMESHGUI->SetActiveDialogBox(this);
403 mySMESHGUI->SetState(800);
405 mySelectionMode = -1;
406 myMeshFilter = new SMESH_TypeFilter(MESH);
407 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
408 myGroupFilter = new SMESH_TypeFilter(GROUP);
409 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
410 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
412 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
413 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
414 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
415 connect(mySMESHGUI, SIGNAL(SignalVisibilityChanged()), this, SLOT(onVisibilityChanged()));
417 rb1->setChecked(true); // VSR !!!
418 onGrpTypeChanged(0); // VSR!!!
420 if (myMesh->_is_nil() )
421 myTypeGroup->button(0)->setChecked(true);
424 //myName->setText(GetDefaultName(tr( "SMESH_GROUP" )));
427 //=================================================================================
428 // function : ~SMESHGUI_GroupDlg()
429 // purpose : Destroys the object and frees any allocated resources
430 //=================================================================================
431 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
433 // no need to delete child widgets, Qt does it all for us
434 if ( myFilterDlg != 0 ) {
435 myFilterDlg->setParent( 0 );
440 //=================================================================================
441 // function : GetDefaultName()
442 // purpose : Get the Group Name if Create new Group
443 //=================================================================================
444 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
448 // collect all object names of SMESH component
449 SalomeApp_Study* appStudy =
450 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
451 if ( !appStudy ) return aName;
452 _PTR(Study) aStudy = appStudy->studyDS();
454 std::set<std::string> aSet;
455 _PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
457 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
459 for (it->InitEx(true); it->More(); it->Next()) {
461 aSet.insert(obj->GetName());
465 // build a unique name
467 bool isUnique = false;
469 aName = theOperation + "_" + QString::number(++aNumber);
470 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
476 //=================================================================================
479 //=================================================================================
480 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
482 mySelectionMgr->installFilter(myMeshFilter);
484 /* init data from current selection */
485 restoreShowEntityMode();
486 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
488 myGroup = SMESH::SMESH_Group::_nil();
489 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
491 // NPAL19389: create a group with a selection in another group
492 // set actor of myMesh, if it is visible, else try
493 // any visible actor of group or submesh of myMesh
494 SetAppropriateActor();
496 setDefaultGroupColor();
499 mySelectionMgr->selectedObjects( aList );
500 if( !aList.IsEmpty() )
502 QString aName = aList.First()->getName();
503 myMeshGroupLine->setText(aName);
504 myMeshGroupLine->home( false );
507 myCurrentLineEdit = 0;
509 myTypeGroup->button(0)->setChecked(true);
513 //=================================================================================
516 //=================================================================================
517 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup,
518 const bool theIsConvert)
520 restoreShowEntityMode();
521 myMesh = theGroup->GetMesh();
524 myNameChanged = true;
525 myName->blockSignals(true);
526 myName->setText(theGroup->GetName());
527 myName->blockSignals(false);
530 SALOMEDS::Color aColor = theGroup->GetColor();
531 setGroupColor( aColor );
533 myMeshGroupLine->setText(theGroup->GetName());
536 switch(theGroup->GetType()) {
537 case SMESH::NODE: aType= 0; break;
538 case SMESH::EDGE: aType = 1; break;
539 case SMESH::FACE: aType = 2; break;
540 case SMESH::VOLUME: aType = 3; break;
542 myTypeGroup->button(aType)->setChecked(true);
544 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
545 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
547 if (myGroup->_is_nil() && myGroupOnGeom->_is_nil())
550 // NPAL19389: create a group with a selection in another group
551 // set actor of myMesh, if it is visible, else set
552 // actor of theGroup, if it is visible, else try
553 // any visible actor of group or submesh of myMesh
554 // commented, because an attempt to set selection on not displayed cells leads to error
555 SetAppropriateActor();
557 /* SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
559 anActor = SMESH::FindActorByObject(theGroup);
560 SMESH::SetPickable(anActor);*/
562 int grpType = (!myGroup->_is_nil() ? 0 : (theIsConvert ? 0 : 1));
563 myGrpTypeGroup->button(grpType)->setChecked(true);
564 onGrpTypeChanged(grpType);
567 if ( grpType == 0 ) {
568 myCurrentLineEdit = 0;
570 setSelectionMode(aType);
572 setShowEntityMode(); // depends on myTypeId
575 if (!theGroup->IsEmpty()) {
576 SMESH::long_array_var anElements = theGroup->GetListOfID();
577 int k = anElements->length();
578 for (int i = 0; i < k; i++) {
579 myIdList.append(anElements[i]);
580 myElements->addItem(QString::number(anElements[i]));
582 myElements->selectAll();
587 QString aShapeName( "" );
588 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
589 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
590 if (!aGroupShape->_is_nil())
592 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
594 aShapeName = aGroupShapeSO->GetName().c_str();
596 myGeomGroupLine->setText( aShapeName );
597 myNameChanged = true;
598 myName->blockSignals(true);
599 myName->setText(theGroup->GetName());
600 myName->blockSignals(false);
605 //=================================================================================
606 // function : updateButtons()
608 //=================================================================================
609 void SMESHGUI_GroupDlg::updateButtons()
611 bool enable = !myName->text().trimmed().isEmpty();
613 if (myGrpTypeId == 0) {
614 enable = enable && myElements->count() > 0;
615 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
617 else if (myGrpTypeId == 1) {
618 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
619 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
623 myOKBtn->setEnabled(enable);
624 myApplyBtn->setEnabled(enable);
627 //=================================================================================
628 // function : onNameChanged()
630 //=================================================================================
631 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
633 myOldName = myName->text();
635 myNameChanged = !myName->text().trimmed().isEmpty();
638 //=================================================================================
639 // function : onTypeChanged()
640 // purpose : Group elements type radio button management
641 //=================================================================================
642 void SMESHGUI_GroupDlg::onTypeChanged (int id)
644 if (myTypeId != id) {
646 if (myCurrentLineEdit == 0)
647 setSelectionMode(id);
653 //=================================================================================
654 // function : onGrpTypeChanged()
655 // purpose : Group type radio button management
656 //=================================================================================
657 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
659 if (myGrpTypeId != id) {
660 myWGStack->setCurrentIndex( id );
661 myName->blockSignals(true);
662 myName->setText(myOldName);
663 myName->blockSignals(false);
664 onSelectGeomGroup(id == 1);
669 //=================================================================================
670 // function : onColorChanged()
671 // purpose : Color button management
672 //=================================================================================
673 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
678 //=================================================================================
679 // function : setSelectionMode()
680 // purpose : Radio button management
681 //=================================================================================
682 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
685 if (myMesh->_is_nil())
687 if (mySelectionMode != theMode) {
688 // [PAL10408] mySelectionMgr->clearSelected();
689 mySelectionMgr->clearFilters();
690 if (myActorsList.count() > 0) {
691 QListIterator<SMESH_Actor*> it( myActorsList );
692 while ( it.hasNext() )
693 it.next()->SetPointRepresentation(false);
696 SMESH::SetPointRepresentation(false);
700 if (myActorsList.count() > 0) {
701 QListIterator<SMESH_Actor*> it( myActorsList );
702 while ( it.hasNext() )
703 it.next()->SetPointRepresentation(true);
706 SMESH::SetPointRepresentation(true);
707 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
708 aViewWindow->SetSelectionMode(NodeSelection);
711 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
712 aViewWindow->SetSelectionMode(EdgeSelection);
715 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
716 aViewWindow->SetSelectionMode(FaceSelection);
719 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
720 aViewWindow->SetSelectionMode(VolumeSelection);
724 mySelectionMgr->installFilter(mySubMeshFilter);
725 else if (theMode == 5)
726 mySelectionMgr->installFilter(myGroupFilter);
727 else if (theMode == 6)
728 mySelectionMgr->installFilter(myMeshFilter);
729 else if (theMode == 7)
730 mySelectionMgr->installFilter(myGeomFilter);
732 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
733 aViewWindow->SetSelectionMode(ActorSelection);
735 mySelectionMode = theMode;
739 //=================================================================================
740 // function : onApply()
742 //=================================================================================
743 bool SMESHGUI_GroupDlg::onApply()
745 if (mySMESHGUI->isActiveStudyLocked())
748 if (myName->text().trimmed().isEmpty())
751 if (myGrpTypeId == 0) { // on mesh elements
752 if (!myElements->count())
755 mySelectionMgr->clearSelected();
757 if (myGroup->_is_nil()) { // creation or conversion
758 // check if group on geometry is not null
759 if (!CORBA::is_nil(myGroupOnGeom)) {
760 if (myMesh->_is_nil())
762 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
763 // nullify pointer, because object become dead
764 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
768 if (myGroup->_is_nil()) { // creation
769 if (myMesh->_is_nil())
772 SMESH::ElementType aType = SMESH::ALL;
774 case 0: aType = SMESH::NODE; break;
775 case 1: aType = SMESH::EDGE; break;
776 case 2: aType = SMESH::FACE; break;
777 case 3: aType = SMESH::VOLUME; break;
780 SMESH::long_array_var anIdList = new SMESH::long_array;
781 int i, k = myElements->count();
783 for (i = 0; i < k; i++) {
784 anIdList[i] = myElements->item(i)->text().toInt();
787 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
788 myGroup->Add(anIdList.inout());
790 SALOMEDS::Color aColor = getGroupColor();
791 myGroup->SetColor(aColor);
793 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
795 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
796 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
798 /* init for next operation */
799 myName->setText( "" );
801 myGroup = SMESH::SMESH_Group::_nil();
804 myGroup->SetName(myName->text().toLatin1().data());
806 SALOMEDS::Color aColor = getGroupColor();
807 myGroup->SetColor(aColor);
809 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
810 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
811 anActor->setName(myName->text().toLatin1().data());
812 switch ( myTypeId ) {
813 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
814 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
816 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
822 int i, total = myElements->count();
823 for (i = 0; i < total; i++) {
824 int anId = myElements->item(i)->text().toInt();
825 int idx = myIdList.indexOf(anId);
827 aAddList.append(anId);
829 myIdList.removeAt(idx);
831 if (!aAddList.empty()) {
832 SMESH::long_array_var anIdList = new SMESH::long_array;
833 int added = aAddList.count();
834 anIdList->length(added);
835 for (i = 0; i < added; i++)
836 anIdList[i] = aAddList[i];
837 myGroup->Add(anIdList.inout());
839 if (!myIdList.empty()) {
840 SMESH::long_array_var anIdList = new SMESH::long_array;
841 int removed = myIdList.count();
842 anIdList->length(removed);
843 for (i = 0; i < removed; i++)
844 anIdList[i] = myIdList[i];
845 myGroup->Remove(anIdList.inout());
847 /* init for next operation */
849 for (i = 0; i < total; i++) {
850 myIdList.append(myElements->item(i)->text().toInt());
854 mySMESHGUI->updateObjBrowser(true);
855 SMESH::UpdateView(); // asv: fix of BUG PAL5515
856 mySelectionMgr->clearSelected();
859 else if (myGrpTypeId == 1) { // on geom object
860 if (CORBA::is_nil(myGroupOnGeom)) { // creation
861 if (myMesh->_is_nil() || !myGeomObjects->length())
864 SMESH::ElementType aType = SMESH::ALL;
866 case 0: aType = SMESH::NODE; break;
867 case 1: aType = SMESH::EDGE; break;
868 case 2: aType = SMESH::FACE; break;
869 case 3: aType = SMESH::VOLUME; break;
872 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
873 GEOM::GEOM_IGroupOperations_var aGroupOp =
874 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
876 if (myGeomObjects->length() == 1) {
877 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
878 myName->text().toLatin1().data(),
882 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
883 if ( aSMESHGen->_is_nil() )
886 // create a geometry group
887 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
888 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
890 if (geomGen->_is_nil() || !aStudy)
893 GEOM::GEOM_IGroupOperations_var op =
894 geomGen->GetIGroupOperations(aStudy->StudyId());
898 // check and add all selected GEOM objects: they must be
899 // a sub-shapes of the main GEOM and must be of one type
900 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
901 for ( int i =0; i < myGeomObjects->length(); i++) {
902 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
904 aGroupType = aSubShapeType;
905 else if (aSubShapeType != aGroupType) {
906 aGroupType = TopAbs_SHAPE;
911 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
912 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
913 op->UnionList(aGroupVar, myGeomObjects);
916 // publish the GEOM group in study
917 QString aNewGeomGroupName ( "Auto_group_for_" );
918 aNewGeomGroupName += myName->text();
919 SALOMEDS::SObject_var aNewGroupSO =
920 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
921 aNewGeomGroupName.toLatin1().data(), aMeshShape);
924 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
925 myName->text().toLatin1().data(),
929 SALOMEDS::Color aColor = getGroupColor();
930 myGroupOnGeom->SetColor(aColor);
932 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
934 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
935 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
937 /* init for next operation */
938 myName->setText( "" );
939 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
942 myGroupOnGeom->SetName(myName->text().toLatin1().data());
944 SALOMEDS::Color aColor = getGroupColor();
945 myGroupOnGeom->SetColor(aColor);
947 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
948 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
949 anActor->setName(myName->text().toLatin1().data());
950 switch ( myTypeId ) {
951 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
952 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
954 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
959 mySMESHGUI->updateObjBrowser(true);
960 mySelectionMgr->clearSelected();
967 //=================================================================================
970 //=================================================================================
971 void SMESHGUI_GroupDlg::onOK()
977 //=================================================================================
978 // function : onListSelectionChanged()
979 // purpose : Called when selection in element list is changed
980 //=================================================================================
981 void SMESHGUI_GroupDlg::onListSelectionChanged()
983 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
984 if( myIsBusy || myActorsList.count() == 0 ) return;
987 if (myCurrentLineEdit == 0) {
988 mySelectionMgr->clearSelected();
989 TColStd_MapOfInteger aIndexes;
990 QList<QListWidgetItem*> selItems = myElements->selectedItems();
991 QListWidgetItem* anItem;
992 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
993 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
995 aList.Append(myActorsList.first()->getIO());
996 mySelectionMgr->setSelectedObjects(aList,false);
1001 //=================================================================================
1002 // function : onObjectSelectionChanged()
1003 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1004 //=================================================================================
1005 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1007 if ( myIsBusy || !isEnabled()) return;
1008 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1012 SALOME_ListIO aList;
1013 mySelectionMgr->selectedObjects( aList );
1015 int aNbSel = aList.Extent();
1016 myElements->clearSelection();
1018 if (myCurrentLineEdit)
1020 myCurrentLineEdit->setText( "" );
1021 QString aString = "";
1023 if (myCurrentLineEdit == myMeshGroupLine)
1025 mySelectSubMesh->setEnabled(false);
1026 mySelectGroup->setEnabled(false);
1027 myGroupLine->setText( "" );
1028 mySubMeshLine->setText( "" );
1030 myGeomGroupBtn->setEnabled(false);
1031 myGeomGroupLine->setEnabled(false);
1032 myGeomGroupLine->setText( "" );
1033 myGeomObjects = new GEOM::ListOfGO();
1034 myGeomObjects->length(0);
1036 if (myGeomGroupBtn->isChecked())
1037 myGeomGroupBtn->setChecked(false);
1039 myName->setText( "" );
1041 myElements->clear();
1044 myGroup = SMESH::SMESH_Group::_nil();
1045 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1046 restoreShowEntityMode();
1047 myMesh = SMESH::SMESH_Mesh::_nil();
1053 Handle(SALOME_InteractiveObject) IO = aList.First();
1056 restoreShowEntityMode();
1057 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1058 setShowEntityMode();
1060 if (myMesh->_is_nil())
1067 if ( myFilterDlg && !myMesh->_is_nil()){
1068 myFilterDlg->SetMesh( myMesh );
1070 myGroup = SMESH::SMESH_Group::_nil();
1072 // NPAL19389: create a group with a selection in another group
1073 // set actor of myMesh, if it is visible, else try
1074 // any visible actor of group or submesh of myMesh
1075 SetAppropriateActor();
1077 aString = aList.First()->getName();
1078 myMeshGroupLine->setText(aString);
1079 myMeshGroupLine->home( false );
1081 mySelectSubMesh->setEnabled(true);
1082 mySelectGroup->setEnabled(true);
1083 myGeomGroupBtn->setEnabled(true);
1084 myGeomGroupLine->setEnabled(true);
1088 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1089 if (aGroup->_is_nil())
1096 myGroup = SMESH::SMESH_Group::_nil();
1097 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1101 mySelectSubMesh->setEnabled(true);
1102 mySelectGroup->setEnabled(true);
1104 myCurrentLineEdit = 0;
1109 if (myGrpTypeId == 0)
1115 myElements->clear();
1116 setSelectionMode(myTypeId);
1124 else if (myCurrentLineEdit == myGeomGroupLine)
1126 myGeomObjects = new GEOM::ListOfGO();
1129 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1131 if (aNbSel == 0 || !aMeshSO)
1133 myGeomObjects->length(0);
1139 myGeomObjects->length(aNbSel);
1141 GEOM::GEOM_Object_var aGeomGroup;
1142 Standard_Boolean testResult;
1145 SALOME_ListIteratorOfListIO anIt (aList);
1146 for (; anIt.More(); anIt.Next())
1148 testResult = Standard_False;
1149 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1151 // Check if the object is a geometry group
1152 if (!testResult || CORBA::is_nil(aGeomGroup))
1155 // Check if group constructed on the same shape as a mesh or on its child
1156 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1157 GEOM::GEOM_IGroupOperations_var anOp =
1158 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1160 // The main shape of the group
1161 GEOM::GEOM_Object_var aGroupMainShape;
1162 if (aGeomGroup->GetType() == 37)
1163 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1165 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1166 _PTR(SObject) aGroupMainShapeSO =
1167 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1168 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1170 _PTR(SObject) anObj, aRef;
1171 bool isRefOrSubShape = false;
1172 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1173 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1174 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1175 isRefOrSubShape = true;
1177 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1178 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1179 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1180 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1181 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1182 if (aRef->GetID() == aFather->GetID())
1183 isRefOrSubShape = true;
1185 aFather = aFather->GetFather();
1189 if (isRefOrSubShape)
1190 myGeomObjects[i++] = aGeomGroup;
1193 myGeomObjects->length(i);
1205 if (myCurrentLineEdit == mySubMeshLine)
1206 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1207 else if (myCurrentLineEdit == myGroupLine)
1208 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1209 else if (myCurrentLineEdit == myGeomGroupLine)
1210 aString = tr( "%1 Objects" ).arg(aNbSel);
1213 aString = aList.First()->getName();
1217 myCurrentLineEdit->setText(aString);
1218 myCurrentLineEdit->home(false);
1219 // 07.06.2008 skl for IPAL19574:
1220 // change name of group only if it is empty
1221 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1222 myOldName = myName->text();
1223 myName->blockSignals(true);
1224 myName->setText(aString);
1225 myName->blockSignals(false);
1230 else // !myCurrentLineEdit: local selection of nodes or elements
1232 if (aNbSel == 1 && myActorsList.count() > 0 )
1234 // NPAL19389: create a group with a selection in another group
1235 // Switch myActor to the newly selected one, if the last
1236 // is visible and belongs to group or submesh of myMesh
1237 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1238 Handle(SALOME_InteractiveObject) selIO = aList.First();
1239 if (curIO->hasEntry() && selIO->hasEntry()) {
1240 const char* selEntry = selIO->getEntry();
1241 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1242 // different objects: selected and myActor
1243 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1244 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1245 // newly selected actor is visible
1248 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1250 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1251 int len = strlen(meshEntry);
1253 if (strncmp(selEntry, meshEntry, len) == 0) {
1254 // selected object is myMesh or a part of it
1255 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1258 SMESH::SetPickable(myActor);
1267 QString aListStr = "";
1269 if (myTypeId == 0) {
1270 QListIterator<SMESH_Actor*> it( myActorsList );
1271 while ( it.hasNext() ) {
1273 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1277 QListIterator<SMESH_Actor*> it( myActorsList );
1278 while ( it.hasNext() ) {
1280 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1285 QListWidgetItem* anItem;
1286 QList<QListWidgetItem*> listItemsToSel;
1287 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1288 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1289 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1290 foreach(anItem, found)
1291 if (!anItem->isSelected())
1292 listItemsToSel.push_back(anItem);
1294 bool blocked = myElements->signalsBlocked();
1295 myElements->blockSignals(true);
1296 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1297 myElements->blockSignals(blocked);
1298 onListSelectionChanged();
1299 listItemsToSel.clear();
1304 if (myActorsList.count() == 0) {
1305 if (!myGroup->_is_nil()) {
1306 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1308 myActorsList.append( anActor );
1310 else if(!myGroupOnGeom->_is_nil()) {
1311 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1313 myActorsList.append( anActor );
1316 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1318 myActorsList.append( anActor );
1322 // somehow, if we display the mesh, while selecting from another actor,
1323 // the mesh becomes pickable, and there is no way to select any element
1324 if (myActorsList.count() > 0) {
1325 QListIterator<SMESH_Actor*> it( myActorsList );
1326 while ( it.hasNext() ) {
1327 SMESH_Actor* anActor = it.next();
1328 if ( IsActorVisible(anActor) )
1329 anActor->SetPickable(true);
1336 //=================================================================================
1337 // function : onSelectSubMesh()
1338 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1339 //=================================================================================
1340 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1343 if (mySelectGroup->isChecked()) {
1344 mySelectGroup->setChecked(false);
1346 //VSR: else if (mySelectGeomGroup->isChecked()) {
1347 //VSR: mySelectGeomGroup->setChecked(false);
1349 myCurrentLineEdit = mySubMeshLine;
1350 setSelectionMode(4);
1353 mySubMeshLine->setText( "" );
1354 myCurrentLineEdit = 0;
1356 setSelectionMode(myTypeId);
1358 mySubMeshBtn->setEnabled(on);
1359 mySubMeshLine->setEnabled(on);
1363 //=================================================================================
1364 // function : (onSelectGroup)
1365 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1366 //=================================================================================
1367 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1370 if (mySelectSubMesh->isChecked()) {
1371 mySelectSubMesh->setChecked(false);
1373 myCurrentLineEdit = myGroupLine;
1374 setSelectionMode(5);
1377 myGroupLine->setText( "" );
1378 myCurrentLineEdit = 0;
1380 setSelectionMode(myTypeId);
1382 myGroupBtn->setEnabled(on);
1383 myGroupLine->setEnabled(on);
1387 //=================================================================================
1388 // function : (onSelectGeomGroup)
1389 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1390 //=================================================================================
1391 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1394 if (mySelectSubMesh->isChecked()) {
1395 mySelectSubMesh->setChecked(false);
1397 else if (mySelectGroup->isChecked()) {
1398 mySelectGroup->setChecked(false);
1400 myCurrentLineEdit = myGeomGroupLine;
1402 setSelectionMode(8);
1405 myGeomGroupBtn->setChecked(false);
1406 myGeomObjects->length(0);
1407 myGeomGroupLine->setText( "" );
1408 myCurrentLineEdit = 0;
1410 setSelectionMode(myTypeId);
1415 //=================================================================================
1416 // function : setCurrentSelection()
1418 //=================================================================================
1419 void SMESHGUI_GroupDlg::setCurrentSelection()
1421 QPushButton* send = (QPushButton*)sender();
1422 myCurrentLineEdit = 0;
1423 if (send == myMeshGroupBtn) {
1424 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1425 mySelectionMgr->clearSelected();
1427 setSelectionMode(6);
1429 setSelectionMode(5);
1430 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1431 myCurrentLineEdit = myMeshGroupLine;
1432 onObjectSelectionChanged();
1434 else if (send == mySubMeshBtn) {
1435 myCurrentLineEdit = mySubMeshLine;
1436 onObjectSelectionChanged();
1438 else if (send == myGroupBtn) {
1439 myCurrentLineEdit = myGroupLine;
1440 onObjectSelectionChanged();
1445 //=================================================================================
1446 // function : setFilters()
1447 // purpose : SLOT. Called when "Filter" button pressed.
1448 //=================================================================================
1449 void SMESHGUI_GroupDlg::setFilters()
1451 if(myMesh->_is_nil()) {
1452 SUIT_MessageBox::critical(this,
1454 tr("NO_MESH_SELECTED"));
1458 SMESH::ElementType aType = SMESH::ALL;
1461 case 0 : aType = SMESH::NODE; break;
1462 case 1 : aType = SMESH::EDGE; break;
1463 case 2 : aType = SMESH::FACE; break;
1464 case 3 : aType = SMESH::VOLUME; break;
1468 if ( myFilterDlg == 0 )
1470 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1471 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1474 myFilterDlg->Init( aType );
1476 myFilterDlg->SetSelection();
1477 myFilterDlg->SetMesh( myMesh );
1478 myFilterDlg->SetSourceWg( myElements, false );
1480 myFilterDlg->show();
1483 //=================================================================================
1484 // function : onFilterAccepted()
1485 // purpose : SLOT. Called when Filter dlg closed with OK button.
1486 // Uncheck "Select submesh" and "Select group" checkboxes
1487 //=================================================================================
1488 void SMESHGUI_GroupDlg::onFilterAccepted()
1490 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1492 mySelectionMode = myTypeId;
1493 mySelectSubMesh->setChecked( false );
1494 mySelectGroup->setChecked( false );
1498 //=================================================================================
1499 // function : onAdd()
1501 //=================================================================================
1502 void SMESHGUI_GroupDlg::onAdd()
1504 SALOME_ListIO aList;
1505 mySelectionMgr->selectedObjects( aList );
1507 int aNbSel = aList.Extent();
1509 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1513 SMESH::ElementType aType = SMESH::ALL;
1516 aType = SMESH::NODE;
1517 mySelector->SetSelectionMode(NodeSelection);
1520 aType = SMESH::EDGE;
1521 mySelector->SetSelectionMode(EdgeSelection);
1524 aType = SMESH::FACE;
1525 mySelector->SetSelectionMode(FaceSelection);
1528 aType = SMESH::VOLUME;
1529 mySelector->SetSelectionMode(VolumeSelection);
1532 mySelector->SetSelectionMode(ActorSelection);
1535 QListWidgetItem* anItem = 0;
1536 QList<QListWidgetItem*> listItemsToSel;
1538 if (myCurrentLineEdit == 0) {
1539 //if (aNbSel != 1) { myIsBusy = false; return; }
1540 QString aListStr = "";
1542 if (myTypeId == 0) {
1543 QListIterator<SMESH_Actor*> it( myActorsList );
1544 while ( it.hasNext() ) {
1546 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1551 QListIterator<SMESH_Actor*> it( myActorsList );
1552 while ( it.hasNext() ) {
1554 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1559 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1560 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1561 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1562 if (found.count() == 0) {
1563 anItem = new QListWidgetItem(*it);
1564 myElements->addItem(anItem);
1565 if (!anItem->isSelected())
1566 listItemsToSel.push_back(anItem);
1569 foreach(anItem, found)
1570 if (!anItem->isSelected())
1571 listItemsToSel.push_back(anItem);
1574 bool blocked = myElements->signalsBlocked();
1575 myElements->blockSignals(true);
1576 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1577 myElements->blockSignals(blocked);
1578 onListSelectionChanged();
1579 listItemsToSel.clear();
1581 } else if (myCurrentLineEdit == mySubMeshLine) {
1582 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1584 SALOME_ListIO aList;
1585 mySelectionMgr->selectedObjects( aList );
1587 SALOME_ListIteratorOfListIO anIt (aList);
1588 for ( ; anIt.More(); anIt.Next()) {
1589 SMESH::SMESH_subMesh_var aSubMesh =
1590 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1591 if (!aSubMesh->_is_nil()) {
1592 // check if mesh is the same
1593 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1595 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1596 int k = anElements->length();
1597 for (int i = 0; i < k; i++) {
1598 QString aText = QString::number(anElements[i]);
1599 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1600 if (found.count() == 0) {
1601 anItem = new QListWidgetItem(aText);
1602 myElements->addItem(anItem);
1603 if (!anItem->isSelected())
1604 listItemsToSel.push_back(anItem);
1607 foreach(anItem, found)
1608 if (!anItem->isSelected())
1609 listItemsToSel.push_back(anItem);
1612 bool blocked = myElements->signalsBlocked();
1613 myElements->blockSignals(true);
1614 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1615 myElements->blockSignals(blocked);
1616 onListSelectionChanged();
1617 listItemsToSel.clear();
1619 catch (const SALOME::SALOME_Exception& ex) {
1620 SalomeApp_Tools::QtCatchCorbaException(ex);
1625 mySelectSubMesh->setChecked(false);
1627 onListSelectionChanged();
1629 } else if (myCurrentLineEdit == myGroupLine) {
1630 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1631 SALOME_ListIO aList;
1632 mySelectionMgr->selectedObjects( aList );
1634 SALOME_ListIteratorOfListIO anIt (aList);
1635 for ( ; anIt.More(); anIt.Next()) {
1636 SMESH::SMESH_GroupBase_var aGroup =
1637 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1638 if (!aGroup->_is_nil()) {
1639 // check if mesh is the same
1640 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1641 SMESH::long_array_var anElements = aGroup->GetListOfID();
1642 int k = anElements->length();
1643 for (int i = 0; i < k; i++) {
1644 QString aText = QString::number(anElements[i]);
1645 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1646 if (found.count() == 0) {
1647 anItem = new QListWidgetItem(aText);
1648 myElements->addItem(anItem);
1649 if (!anItem->isSelected())
1650 listItemsToSel.push_back(anItem);
1653 foreach(anItem, found)
1654 if (!anItem->isSelected())
1655 listItemsToSel.push_back(anItem);
1658 bool blocked = myElements->signalsBlocked();
1659 myElements->blockSignals(true);
1660 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1661 myElements->blockSignals(blocked);
1662 onListSelectionChanged();
1663 listItemsToSel.clear();
1667 mySelectGroup->setChecked(false);
1669 onListSelectionChanged();
1671 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1672 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1673 GEOM::GEOM_IGroupOperations_var aGroupOp =
1674 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1676 SMESH::ElementType aGroupType = SMESH::ALL;
1677 switch(aGroupOp->GetType(myGeomObjects[0])) {
1678 case 7: aGroupType = SMESH::NODE; break;
1679 case 6: aGroupType = SMESH::EDGE; break;
1680 case 4: aGroupType = SMESH::FACE; break;
1681 case 2: aGroupType = SMESH::VOLUME; break;
1682 default: myIsBusy = false; return;
1685 if (aGroupType == aType) {
1686 _PTR(SObject) aGroupSO =
1687 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1688 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1690 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1691 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1692 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1693 aBelongToGeom->SetGeom(myGeomObjects[0]);
1694 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1695 aBelongToGeom->SetElementType(aType);
1696 aFilter->SetPredicate(aBelongToGeom);
1698 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1700 int k = anElements->length();
1701 for (int i = 0; i < k; i++) {
1702 QString aText = QString::number(anElements[i]);
1703 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1704 if (found.count() == 0) {
1705 anItem = new QListWidgetItem(aText);
1706 myElements->addItem(anItem);
1707 if (!anItem->isSelected())
1708 listItemsToSel.push_back(anItem);
1711 foreach(anItem, found)
1712 if (!anItem->isSelected())
1713 listItemsToSel.push_back(anItem);
1716 bool blocked = myElements->signalsBlocked();
1717 myElements->blockSignals(true);
1718 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1719 myElements->blockSignals(blocked);
1720 onListSelectionChanged();
1721 listItemsToSel.clear();
1724 //VSR: mySelectGeomGroup->setChecked(false);
1726 onListSelectionChanged();
1729 // mySelectionMgr->clearSelected();
1733 //=================================================================================
1734 // function : onRemove()
1736 //=================================================================================
1737 void SMESHGUI_GroupDlg::onRemove()
1740 if (myCurrentLineEdit == 0) {
1741 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1742 QListWidgetItem* item;
1743 foreach(item, selItems) delete item;
1745 SALOME_ListIO aList;
1746 mySelectionMgr->selectedObjects( aList );
1748 int aNbSel = aList.Extent();
1750 if (aNbSel == 0) { myIsBusy = false; return; }
1752 SMESH::ElementType aType = SMESH::ALL;
1754 case 0: aType = SMESH::NODE; break;
1755 case 1: aType = SMESH::EDGE; break;
1756 case 2: aType = SMESH::FACE; break;
1757 case 3: aType = SMESH::VOLUME; break;
1760 if (myCurrentLineEdit == mySubMeshLine) {
1761 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1762 SALOME_ListIO aList;
1763 mySelectionMgr->selectedObjects( aList );
1765 SALOME_ListIteratorOfListIO anIt (aList);
1766 for ( ; anIt.More(); anIt.Next()) {
1767 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1768 if (!aSubMesh->_is_nil()) {
1769 // check if mesh is the same
1770 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1771 if (aType == SMESH::NODE) {
1773 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1774 int k = anElements->length();
1775 for (int i = 0; i < k; i++) {
1776 QList<QListWidgetItem*> found =
1777 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1778 QListWidgetItem* anItem;
1779 foreach(anItem, found) delete anItem;
1782 catch (const SALOME::SALOME_Exception& ex) {
1783 SalomeApp_Tools::QtCatchCorbaException(ex);
1788 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1789 int k = anElements->length();
1790 for (int i = 0; i < k; i++) {
1791 QList<QListWidgetItem*> found =
1792 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1793 QListWidgetItem* anItem;
1794 foreach(anItem, found) delete anItem;
1797 catch (const SALOME::SALOME_Exception& ex) {
1798 SalomeApp_Tools::QtCatchCorbaException(ex);
1805 else if (myCurrentLineEdit == myGroupLine) {
1806 Standard_Boolean aRes;
1807 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1808 SALOME_ListIO aList;
1809 mySelectionMgr->selectedObjects( aList );
1811 SALOME_ListIteratorOfListIO anIt (aList);
1812 for ( ; anIt.More(); anIt.Next()) {
1813 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1814 if (aRes && !aGroup->_is_nil()) {
1815 // check if mesh is the same
1816 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1817 SMESH::long_array_var anElements = aGroup->GetListOfID();
1818 int k = anElements->length();
1819 for (int i = 0; i < k; i++) {
1820 QList<QListWidgetItem*> found =
1821 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1822 QListWidgetItem* anItem;
1823 foreach(anItem, found) delete anItem;
1834 //=================================================================================
1835 // function : onSort()
1837 //=================================================================================
1838 void SMESHGUI_GroupDlg::onSort()
1840 // PAL5412: sorts items in ascending by "string" value
1841 // myElements->sort(true);
1842 // myElements->update();
1843 int i, k = myElements->count();
1846 QList<int> aSelected;
1847 std::vector<int> anArray(k);
1848 // QMemArray<int> anArray(k);
1850 for (i = 0; i < k; i++) {
1851 int id = myElements->item(i)->text().toInt();
1853 if (myElements->item(i)->isSelected())
1854 aSelected.append(id);
1856 // sort & update list
1857 std::sort(anArray.begin(), anArray.end());
1859 myElements->clear();
1860 QListWidgetItem* anItem;
1861 QList<QListWidgetItem*> listItemsToSel;
1862 for (i = 0; i < k; i++) {
1863 anItem = new QListWidgetItem(QString::number(anArray[i]));
1864 myElements->addItem(anItem);
1865 if (aSelected.contains(anArray[i]))
1866 listItemsToSel.push_back(anItem);
1868 bool blocked = myElements->signalsBlocked();
1869 myElements->blockSignals(true);
1870 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1871 myElements->blockSignals(blocked);
1872 listItemsToSel.clear();
1877 //=================================================================================
1878 // function : closeEvent()
1880 //=================================================================================
1881 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1886 //=================================================================================
1887 // function : onVisibilityChanged()
1889 //=================================================================================
1890 void SMESHGUI_GroupDlg::onVisibilityChanged()
1892 SetAppropriateActor();
1895 //=================================================================================
1896 // function : SMESHGUI_GroupDlg::onClose
1897 // purpose : SLOT called when "Close" button pressed. Close dialog
1898 //=================================================================================
1899 void SMESHGUI_GroupDlg::onClose()
1901 if (SMESH::GetCurrentVtkView()) {
1902 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1903 SMESH::SetPointRepresentation(false);
1904 SMESH::SetPickable();
1905 restoreShowEntityMode();
1908 mySelectionMgr->clearSelected();
1909 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1910 aViewWindow->SetSelectionMode(ActorSelection);
1911 mySelectionMgr->clearFilters();
1912 mySMESHGUI->ResetState();
1917 //=================================================================================
1918 // function : onHelp()
1920 //=================================================================================
1921 void SMESHGUI_GroupDlg::onHelp()
1923 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1925 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1929 platform = "winapplication";
1931 platform = "application";
1933 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1934 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1935 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1937 arg(myHelpFileName));
1941 //=================================================================================
1942 // function : SMESHGUI_GroupDlg::onDeactivate
1943 // purpose : SLOT called when dialog must be deativated
1944 //=================================================================================
1945 void SMESHGUI_GroupDlg::onDeactivate()
1947 mySMESHGUI->ResetState();
1951 //=================================================================================
1952 // function : SMESHGUI_GroupDlg::enterEvent
1953 // purpose : Event filter
1954 //=================================================================================
1955 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1958 mySMESHGUI->EmitSignalDeactivateDialog();
1960 mySelectionMode = -1;
1961 setSelectionMode(myTypeId);
1962 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1963 mySMESHGUI->SetActiveDialogBox(this);
1964 mySMESHGUI->SetState(800);
1968 //=================================================================================
1969 // function : hideEvent
1970 // purpose : caused by ESC key
1971 //=================================================================================
1972 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1974 if (!isMinimized() && !myIsBusy)
1978 //=================================================================================
1979 // function : keyPressEvent()
1981 //=================================================================================
1982 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1984 QDialog::keyPressEvent( e );
1985 if ( e->isAccepted() )
1988 if ( e->key() == Qt::Key_F1 )
1995 //================================================================================
1997 * \brief Enable showing of the popup when Geometry selection btn is clicked
1998 * \param enable - true to enable
2000 //================================================================================
2002 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2004 void SMESHGUI_GroupDlg::updateGeomPopup()
2006 bool enable = false;
2008 if ( !myMesh->_is_nil() )
2009 enable = myMesh->NbEdges() > 0;
2011 if ( myGeomGroupBtn )
2013 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2015 if ( !myGeomPopup ) {
2016 myGeomPopup = new QMenu(this);
2017 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2018 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2019 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2021 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2027 //=================================================================================
2028 // function : onGeomSelectionButton()
2030 //=================================================================================
2031 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2033 if ( myGeomPopup && isBtnOn )
2035 myCurrentLineEdit = myGeomGroupLine;
2036 QAction* a = myGeomPopup->exec( QCursor::pos() );
2037 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2038 setSelectionMode(7);
2042 myCurrentLineEdit = 0;
2043 setSelectionMode(8);
2047 //=================================================================================
2048 // function : onGeomPopup()
2050 //=================================================================================
2051 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2053 int index = myActions[a];
2054 if ( index == GEOM_BY_MESH_INDEX )
2056 mySelectionMode = -1;
2057 if ( !myShapeByMeshOp ) {
2058 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2059 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2060 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2061 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2062 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2064 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2065 if ( !myMesh->_is_nil() ) {
2067 hide(); // stop processing selection
2069 myShapeByMeshOp->setModule( mySMESHGUI );
2070 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2071 myShapeByMeshOp->SetMesh( myMesh );
2072 myShapeByMeshOp->start();
2077 //================================================================================
2079 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2081 //================================================================================
2083 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2085 if ( myShapeByMeshOp == op ) {
2086 mySMESHGUI->getApp()->updateObjectBrowser();
2088 // Select a found geometry object
2089 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2090 if ( !aGeomVar->_is_nil() )
2092 QString ID = aGeomVar->GetStudyEntry();
2093 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2094 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2095 SALOME_ListIO anIOList;
2096 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2097 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2098 anIOList.Append( anIO );
2099 mySelectionMgr->setSelectedObjects( anIOList, false );
2100 onObjectSelectionChanged();
2106 //================================================================================
2108 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2110 //================================================================================
2112 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2114 if ( myShapeByMeshOp == op )
2117 setSelectionMode(7);
2121 //=================================================================================
2122 // function : setGroupColor()
2124 //=================================================================================
2125 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2127 QColor aQColor( (int)( theColor.R * 255.0 ),
2128 (int)( theColor.G * 255.0 ),
2129 (int)( theColor.B * 255.0 ) );
2130 setGroupQColor( aQColor );
2133 //=================================================================================
2134 // function : getGroupColor()
2136 //=================================================================================
2137 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2139 QColor aQColor = getGroupQColor();
2141 SALOMEDS::Color aColor;
2142 aColor.R = (float)aQColor.red() / 255.0;
2143 aColor.G = (float)aQColor.green() / 255.0;
2144 aColor.B = (float)aQColor.blue() / 255.0;
2149 //=================================================================================
2150 // function : setGroupQColor()
2152 //=================================================================================
2153 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2155 if( theColor.isValid() )
2156 myColorBtn->setColor( theColor );
2159 //=================================================================================
2160 // function : getGroupQColor()
2162 //=================================================================================
2163 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2165 return myColorBtn->color();
2168 //=================================================================================
2169 // function : setDefaultGroupColor()
2171 //=================================================================================
2172 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2174 if( myMesh->_is_nil() )
2177 bool isAutoColor = myMesh->GetAutoColor();
2182 int r = 0, g = 0, b = 0;
2183 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2184 aQColor.setRgb( r, g, b );
2188 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2190 QList<SALOMEDS::Color> aReservedColors;
2191 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2193 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2194 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2195 aReservedColors.append( aReservedColor );
2198 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2199 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2200 (int)( aColor.G * 255.0 ),
2201 (int)( aColor.B * 255.0 ) );
2205 setGroupQColor( aQColor );
2208 //=================================================================================
2209 // function : SetAppropriateActor()
2210 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2211 // NPAL19389: create a group with a selection in another group.
2212 // if mesh actor is not visible - find any first visible group or submesh
2213 //=================================================================================
2214 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2216 bool isActor = false;
2217 myActorsList.clear();
2219 if (myMesh->_is_nil()) return false;
2221 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2223 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2225 if (!myGroupOnGeom->_is_nil()) {
2226 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2227 if (anActor && anActor->hasIO())
2230 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2233 myActorsList.append(anActor);
2239 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2240 if (anActor && anActor->hasIO()) {
2242 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2245 myActorsList.append(anActor);
2249 if (!isActor && !myGroup->_is_nil()) {
2250 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2251 if (anActor && anActor->hasIO())
2252 myActorsList.append(anActor);
2255 // try any visible actor of group or submesh of current mesh
2258 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2260 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2261 int len = strlen(meshEntry);
2263 // iterate on all actors in current view window, search for
2264 // any visible actor, that belongs to group or submesh of current mesh
2265 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2266 vtkActorCollection *aCollection = aCopy.GetActors();
2267 int nbItems = aCollection->GetNumberOfItems();
2268 for (int i=0; i<nbItems && !isActor; i++)
2270 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2271 if (anActor && anActor->hasIO()) {
2272 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2273 if (aViewWindow->isVisible(anIO)) {
2274 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2275 myActorsList.append(anActor);
2283 if (myActorsList.count() > 0) {
2284 QListIterator<SMESH_Actor*> it( myActorsList );
2285 while ( it.hasNext() ) {
2286 SMESH_Actor* anActor = it.next();
2287 if ( IsActorVisible(anActor) )
2288 anActor->SetPickable(true);
2292 return ( isActor || (myActorsList.count() > 0) );
2295 //=======================================================================
2296 //function : setShowEntityMode
2297 //purpose : make shown only entity corresponding to my type
2298 //=======================================================================
2299 void SMESHGUI_GroupDlg::setShowEntityMode()
2301 if ( !myMesh->_is_nil() ) {
2302 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2303 if (!myStoredShownEntity)
2304 myStoredShownEntity = actor->GetEntityMode();
2305 switch ( myTypeId ) {
2306 case 0: restoreShowEntityMode(); break;
2307 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2308 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2309 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2315 //=======================================================================
2316 //function : restoreShowEntityMode
2317 //purpose : restore ShowEntity mode of myActor
2318 //=======================================================================
2319 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2321 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2322 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2323 actor->SetEntityMode(myStoredShownEntity);
2326 myStoredShownEntity = 0;
2329 //=======================================================================
2330 //function : IsActorVisible
2331 //purpose : return visibility of the actor
2332 //=======================================================================
2333 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2335 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2336 if (theActor && aViewWindow)
2337 return aViewWindow->isVisible(theActor->getIO());