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());
593 aShapeName = aGroupShapeSO->GetName().c_str();
595 myGeomGroupLine->setText( aShapeName );
596 myNameChanged = true;
597 myName->blockSignals(true);
598 myName->setText(theGroup->GetName());
599 myName->blockSignals(false);
604 //=================================================================================
605 // function : updateButtons()
607 //=================================================================================
608 void SMESHGUI_GroupDlg::updateButtons()
610 bool enable = !myName->text().trimmed().isEmpty();
612 if (myGrpTypeId == 0) {
613 enable = enable && myElements->count() > 0;
614 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
616 else if (myGrpTypeId == 1) {
617 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
618 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
622 myOKBtn->setEnabled(enable);
623 myApplyBtn->setEnabled(enable);
626 //=================================================================================
627 // function : onNameChanged()
629 //=================================================================================
630 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
632 myOldName = myName->text();
634 myNameChanged = !myName->text().trimmed().isEmpty();
637 //=================================================================================
638 // function : onTypeChanged()
639 // purpose : Group elements type radio button management
640 //=================================================================================
641 void SMESHGUI_GroupDlg::onTypeChanged (int id)
643 if (myTypeId != id) {
645 if (myCurrentLineEdit == 0)
646 setSelectionMode(id);
652 //=================================================================================
653 // function : onGrpTypeChanged()
654 // purpose : Group type radio button management
655 //=================================================================================
656 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
658 if (myGrpTypeId != id) {
659 myWGStack->setCurrentIndex( id );
660 myName->blockSignals(true);
661 myName->setText(myOldName);
662 myName->blockSignals(false);
663 onSelectGeomGroup(id == 1);
668 //=================================================================================
669 // function : onColorChanged()
670 // purpose : Color button management
671 //=================================================================================
672 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
677 //=================================================================================
678 // function : setSelectionMode()
679 // purpose : Radio button management
680 //=================================================================================
681 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
684 if (myMesh->_is_nil())
686 if (mySelectionMode != theMode) {
687 // [PAL10408] mySelectionMgr->clearSelected();
688 mySelectionMgr->clearFilters();
689 if (myActorsList.count() > 0) {
690 QListIterator<SMESH_Actor*> it( myActorsList );
691 while ( it.hasNext() )
692 it.next()->SetPointRepresentation(false);
695 SMESH::SetPointRepresentation(false);
699 if (myActorsList.count() > 0) {
700 QListIterator<SMESH_Actor*> it( myActorsList );
701 while ( it.hasNext() )
702 it.next()->SetPointRepresentation(true);
705 SMESH::SetPointRepresentation(true);
706 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
707 aViewWindow->SetSelectionMode(NodeSelection);
710 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
711 aViewWindow->SetSelectionMode(EdgeSelection);
714 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
715 aViewWindow->SetSelectionMode(FaceSelection);
718 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
719 aViewWindow->SetSelectionMode(VolumeSelection);
723 mySelectionMgr->installFilter(mySubMeshFilter);
724 else if (theMode == 5)
725 mySelectionMgr->installFilter(myGroupFilter);
726 else if (theMode == 6)
727 mySelectionMgr->installFilter(myMeshFilter);
728 else if (theMode == 7)
729 mySelectionMgr->installFilter(myGeomFilter);
731 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
732 aViewWindow->SetSelectionMode(ActorSelection);
734 mySelectionMode = theMode;
738 //=================================================================================
739 // function : onApply()
741 //=================================================================================
742 bool SMESHGUI_GroupDlg::onApply()
744 if (mySMESHGUI->isActiveStudyLocked())
747 if (myName->text().trimmed().isEmpty())
750 if (myGrpTypeId == 0) { // on mesh elements
751 if (!myElements->count())
754 mySelectionMgr->clearSelected();
756 if (myGroup->_is_nil()) { // creation or conversion
757 // check if group on geometry is not null
758 if (!CORBA::is_nil(myGroupOnGeom)) {
759 if (myMesh->_is_nil())
761 myGroup = myMesh->ConvertToStandalone( myGroupOnGeom );
762 // nullify pointer, because object become dead
763 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
767 if (myGroup->_is_nil()) { // creation
768 if (myMesh->_is_nil())
771 SMESH::ElementType aType = SMESH::ALL;
773 case 0: aType = SMESH::NODE; break;
774 case 1: aType = SMESH::EDGE; break;
775 case 2: aType = SMESH::FACE; break;
776 case 3: aType = SMESH::VOLUME; break;
779 SMESH::long_array_var anIdList = new SMESH::long_array;
780 int i, k = myElements->count();
782 for (i = 0; i < k; i++) {
783 anIdList[i] = myElements->item(i)->text().toInt();
786 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
787 myGroup->Add(anIdList.inout());
789 SALOMEDS::Color aColor = getGroupColor();
790 myGroup->SetColor(aColor);
792 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
794 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
795 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
797 /* init for next operation */
798 myName->setText( "" );
800 myGroup = SMESH::SMESH_Group::_nil();
803 myGroup->SetName(myName->text().toLatin1().data());
805 SALOMEDS::Color aColor = getGroupColor();
806 myGroup->SetColor(aColor);
808 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
809 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
810 anActor->setName(myName->text().toLatin1().data());
811 switch ( myTypeId ) {
812 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
813 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
815 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
821 int i, total = myElements->count();
822 for (i = 0; i < total; i++) {
823 int anId = myElements->item(i)->text().toInt();
824 int idx = myIdList.indexOf(anId);
826 aAddList.append(anId);
828 myIdList.removeAt(idx);
830 if (!aAddList.empty()) {
831 SMESH::long_array_var anIdList = new SMESH::long_array;
832 int added = aAddList.count();
833 anIdList->length(added);
834 for (i = 0; i < added; i++)
835 anIdList[i] = aAddList[i];
836 myGroup->Add(anIdList.inout());
838 if (!myIdList.empty()) {
839 SMESH::long_array_var anIdList = new SMESH::long_array;
840 int removed = myIdList.count();
841 anIdList->length(removed);
842 for (i = 0; i < removed; i++)
843 anIdList[i] = myIdList[i];
844 myGroup->Remove(anIdList.inout());
846 /* init for next operation */
848 for (i = 0; i < total; i++) {
849 myIdList.append(myElements->item(i)->text().toInt());
853 mySMESHGUI->updateObjBrowser(true);
854 SMESH::UpdateView(); // asv: fix of BUG PAL5515
855 mySelectionMgr->clearSelected();
858 else if (myGrpTypeId == 1) { // on geom object
859 if (CORBA::is_nil(myGroupOnGeom)) { // creation
860 if (myMesh->_is_nil() || !myGeomObjects->length())
863 SMESH::ElementType aType = SMESH::ALL;
865 case 0: aType = SMESH::NODE; break;
866 case 1: aType = SMESH::EDGE; break;
867 case 2: aType = SMESH::FACE; break;
868 case 3: aType = SMESH::VOLUME; break;
871 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
872 GEOM::GEOM_IGroupOperations_var aGroupOp =
873 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
875 if (myGeomObjects->length() == 1) {
876 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
877 myName->text().toLatin1().data(),
881 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
882 if ( aSMESHGen->_is_nil() )
885 // create a geometry group
886 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
887 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
889 if (geomGen->_is_nil() || !aStudy)
892 GEOM::GEOM_IGroupOperations_var op =
893 geomGen->GetIGroupOperations(aStudy->StudyId());
897 // check and add all selected GEOM objects: they must be
898 // a sub-shapes of the main GEOM and must be of one type
899 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
900 for ( int i =0; i < myGeomObjects->length(); i++) {
901 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
903 aGroupType = aSubShapeType;
904 else if (aSubShapeType != aGroupType) {
905 aGroupType = TopAbs_SHAPE;
910 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
911 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
912 op->UnionList(aGroupVar, myGeomObjects);
915 // publish the GEOM group in study
916 QString aNewGeomGroupName ( "Auto_group_for_" );
917 aNewGeomGroupName += myName->text();
918 SALOMEDS::SObject_var aNewGroupSO =
919 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
920 aNewGeomGroupName.toLatin1().data(), aMeshShape);
923 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
924 myName->text().toLatin1().data(),
928 SALOMEDS::Color aColor = getGroupColor();
929 myGroupOnGeom->SetColor(aColor);
931 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
933 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
934 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
936 /* init for next operation */
937 myName->setText( "" );
938 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
941 myGroupOnGeom->SetName(myName->text().toLatin1().data());
943 SALOMEDS::Color aColor = getGroupColor();
944 myGroupOnGeom->SetColor(aColor);
946 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
947 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str())) {
948 anActor->setName(myName->text().toLatin1().data());
949 switch ( myTypeId ) {
950 case 0: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
951 case 1: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
953 case 3: anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B ); break;
958 mySMESHGUI->updateObjBrowser(true);
959 mySelectionMgr->clearSelected();
966 //=================================================================================
969 //=================================================================================
970 void SMESHGUI_GroupDlg::onOK()
976 //=================================================================================
977 // function : onListSelectionChanged()
978 // purpose : Called when selection in element list is changed
979 //=================================================================================
980 void SMESHGUI_GroupDlg::onListSelectionChanged()
982 //MESSAGE( "SMESHGUI_GroupDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
983 if( myIsBusy || myActorsList.count() == 0 ) return;
986 if (myCurrentLineEdit == 0) {
987 mySelectionMgr->clearSelected();
988 TColStd_MapOfInteger aIndexes;
989 QList<QListWidgetItem*> selItems = myElements->selectedItems();
990 QListWidgetItem* anItem;
991 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
992 mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
994 aList.Append(myActorsList.first()->getIO());
995 mySelectionMgr->setSelectedObjects(aList,false);
1000 //=================================================================================
1001 // function : onObjectSelectionChanged()
1002 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1003 //=================================================================================
1004 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
1006 if ( myIsBusy || !isEnabled()) return;
1007 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
1011 SALOME_ListIO aList;
1012 mySelectionMgr->selectedObjects( aList );
1014 int aNbSel = aList.Extent();
1015 myElements->clearSelection();
1017 if (myCurrentLineEdit)
1019 myCurrentLineEdit->setText( "" );
1020 QString aString = "";
1022 if (myCurrentLineEdit == myMeshGroupLine)
1024 mySelectSubMesh->setEnabled(false);
1025 mySelectGroup->setEnabled(false);
1026 myGroupLine->setText( "" );
1027 mySubMeshLine->setText( "" );
1029 myGeomGroupBtn->setEnabled(false);
1030 myGeomGroupLine->setEnabled(false);
1031 myGeomGroupLine->setText( "" );
1032 myGeomObjects = new GEOM::ListOfGO();
1033 myGeomObjects->length(0);
1035 if (myGeomGroupBtn->isChecked())
1036 myGeomGroupBtn->setChecked(false);
1038 myName->setText( "" );
1040 myElements->clear();
1043 myGroup = SMESH::SMESH_Group::_nil();
1044 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1045 restoreShowEntityMode();
1046 myMesh = SMESH::SMESH_Mesh::_nil();
1052 Handle(SALOME_InteractiveObject) IO = aList.First();
1055 restoreShowEntityMode();
1056 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1057 setShowEntityMode();
1059 if (myMesh->_is_nil())
1066 if ( myFilterDlg && !myMesh->_is_nil()){
1067 myFilterDlg->SetMesh( myMesh );
1069 myGroup = SMESH::SMESH_Group::_nil();
1071 // NPAL19389: create a group with a selection in another group
1072 // set actor of myMesh, if it is visible, else try
1073 // any visible actor of group or submesh of myMesh
1074 SetAppropriateActor();
1076 aString = aList.First()->getName();
1077 myMeshGroupLine->setText(aString);
1078 myMeshGroupLine->home( false );
1080 mySelectSubMesh->setEnabled(true);
1081 mySelectGroup->setEnabled(true);
1082 myGeomGroupBtn->setEnabled(true);
1083 myGeomGroupLine->setEnabled(true);
1087 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1088 if (aGroup->_is_nil())
1095 myGroup = SMESH::SMESH_Group::_nil();
1096 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1100 mySelectSubMesh->setEnabled(true);
1101 mySelectGroup->setEnabled(true);
1103 myCurrentLineEdit = 0;
1108 if (myGrpTypeId == 0)
1114 myElements->clear();
1115 setSelectionMode(myTypeId);
1123 else if (myCurrentLineEdit == myGeomGroupLine)
1125 myGeomObjects = new GEOM::ListOfGO();
1128 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1130 if (aNbSel == 0 || !aMeshSO)
1132 myGeomObjects->length(0);
1138 myGeomObjects->length(aNbSel);
1140 GEOM::GEOM_Object_var aGeomGroup;
1141 Standard_Boolean testResult;
1144 SALOME_ListIteratorOfListIO anIt (aList);
1145 for (; anIt.More(); anIt.Next())
1147 testResult = Standard_False;
1148 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1150 // Check if the object is a geometry group
1151 if (!testResult || CORBA::is_nil(aGeomGroup))
1154 // Check if group constructed on the same shape as a mesh or on its child
1155 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1156 GEOM::GEOM_IGroupOperations_var anOp =
1157 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1159 // The main shape of the group
1160 GEOM::GEOM_Object_var aGroupMainShape;
1161 if (aGeomGroup->GetType() == 37)
1162 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1164 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1165 _PTR(SObject) aGroupMainShapeSO =
1166 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1167 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1169 _PTR(SObject) anObj, aRef;
1170 bool isRefOrSubShape = false;
1171 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1172 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1173 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1174 isRefOrSubShape = true;
1176 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1177 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1178 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1179 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1180 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1181 if (aRef->GetID() == aFather->GetID())
1182 isRefOrSubShape = true;
1184 aFather = aFather->GetFather();
1188 if (isRefOrSubShape)
1189 myGeomObjects[i++] = aGeomGroup;
1192 myGeomObjects->length(i);
1204 if (myCurrentLineEdit == mySubMeshLine)
1205 aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
1206 else if (myCurrentLineEdit == myGroupLine)
1207 aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
1208 else if (myCurrentLineEdit == myGeomGroupLine)
1209 aString = tr( "%1 Objects" ).arg(aNbSel);
1212 aString = aList.First()->getName();
1216 myCurrentLineEdit->setText(aString);
1217 myCurrentLineEdit->home(false);
1218 // 07.06.2008 skl for IPAL19574:
1219 // change name of group only if it is empty
1220 if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
1221 myOldName = myName->text();
1222 myName->blockSignals(true);
1223 myName->setText(aString);
1224 myName->blockSignals(false);
1229 else // !myCurrentLineEdit: local selection of nodes or elements
1231 if (aNbSel == 1 && myActorsList.count() > 0 )
1233 // NPAL19389: create a group with a selection in another group
1234 // Switch myActor to the newly selected one, if the last
1235 // is visible and belongs to group or submesh of myMesh
1236 /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
1237 Handle(SALOME_InteractiveObject) selIO = aList.First();
1238 if (curIO->hasEntry() && selIO->hasEntry()) {
1239 const char* selEntry = selIO->getEntry();
1240 if (strcmp(curIO->getEntry(), selEntry) != 0) {
1241 // different objects: selected and myActor
1242 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
1243 if (aViewWindow && aViewWindow->isVisible(selIO)) {
1244 // newly selected actor is visible
1247 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
1249 CORBA::String_var meshEntry = aSObject->GetID().c_str();
1250 int len = strlen(meshEntry);
1252 if (strncmp(selEntry, meshEntry, len) == 0) {
1253 // selected object is myMesh or a part of it
1254 SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
1257 SMESH::SetPickable(myActor);
1266 QString aListStr = "";
1268 if (myTypeId == 0) {
1269 QListIterator<SMESH_Actor*> it( myActorsList );
1270 while ( it.hasNext() ) {
1272 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1276 QListIterator<SMESH_Actor*> it( myActorsList );
1277 while ( it.hasNext() ) {
1279 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1284 QListWidgetItem* anItem;
1285 QList<QListWidgetItem*> listItemsToSel;
1286 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1287 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1288 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1289 foreach(anItem, found)
1290 if (!anItem->isSelected())
1291 listItemsToSel.push_back(anItem);
1293 bool blocked = myElements->signalsBlocked();
1294 myElements->blockSignals(true);
1295 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1296 myElements->blockSignals(blocked);
1297 onListSelectionChanged();
1298 listItemsToSel.clear();
1303 if (myActorsList.count() == 0) {
1304 if (!myGroup->_is_nil()) {
1305 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
1307 myActorsList.append( anActor );
1309 else if(!myGroupOnGeom->_is_nil()) {
1310 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
1312 myActorsList.append( anActor );
1315 SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
1317 myActorsList.append( anActor );
1321 // somehow, if we display the mesh, while selecting from another actor,
1322 // the mesh becomes pickable, and there is no way to select any element
1323 if (myActorsList.count() > 0) {
1324 QListIterator<SMESH_Actor*> it( myActorsList );
1325 while ( it.hasNext() ) {
1326 SMESH_Actor* anActor = it.next();
1327 if ( IsActorVisible(anActor) )
1328 anActor->SetPickable(true);
1335 //=================================================================================
1336 // function : onSelectSubMesh()
1337 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1338 //=================================================================================
1339 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1342 if (mySelectGroup->isChecked()) {
1343 mySelectGroup->setChecked(false);
1345 //VSR: else if (mySelectGeomGroup->isChecked()) {
1346 //VSR: mySelectGeomGroup->setChecked(false);
1348 myCurrentLineEdit = mySubMeshLine;
1349 setSelectionMode(4);
1352 mySubMeshLine->setText( "" );
1353 myCurrentLineEdit = 0;
1355 setSelectionMode(myTypeId);
1357 mySubMeshBtn->setEnabled(on);
1358 mySubMeshLine->setEnabled(on);
1362 //=================================================================================
1363 // function : (onSelectGroup)
1364 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1365 //=================================================================================
1366 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1369 if (mySelectSubMesh->isChecked()) {
1370 mySelectSubMesh->setChecked(false);
1372 myCurrentLineEdit = myGroupLine;
1373 setSelectionMode(5);
1376 myGroupLine->setText( "" );
1377 myCurrentLineEdit = 0;
1379 setSelectionMode(myTypeId);
1381 myGroupBtn->setEnabled(on);
1382 myGroupLine->setEnabled(on);
1386 //=================================================================================
1387 // function : (onSelectGeomGroup)
1388 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1389 //=================================================================================
1390 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1393 if (mySelectSubMesh->isChecked()) {
1394 mySelectSubMesh->setChecked(false);
1396 else if (mySelectGroup->isChecked()) {
1397 mySelectGroup->setChecked(false);
1399 myCurrentLineEdit = myGeomGroupLine;
1401 setSelectionMode(8);
1404 myGeomGroupBtn->setChecked(false);
1405 myGeomObjects->length(0);
1406 myGeomGroupLine->setText( "" );
1407 myCurrentLineEdit = 0;
1409 setSelectionMode(myTypeId);
1414 //=================================================================================
1415 // function : setCurrentSelection()
1417 //=================================================================================
1418 void SMESHGUI_GroupDlg::setCurrentSelection()
1420 QPushButton* send = (QPushButton*)sender();
1421 myCurrentLineEdit = 0;
1422 if (send == myMeshGroupBtn) {
1423 disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1424 mySelectionMgr->clearSelected();
1426 setSelectionMode(6);
1428 setSelectionMode(5);
1429 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1430 myCurrentLineEdit = myMeshGroupLine;
1431 onObjectSelectionChanged();
1433 else if (send == mySubMeshBtn) {
1434 myCurrentLineEdit = mySubMeshLine;
1435 onObjectSelectionChanged();
1437 else if (send == myGroupBtn) {
1438 myCurrentLineEdit = myGroupLine;
1439 onObjectSelectionChanged();
1444 //=================================================================================
1445 // function : setFilters()
1446 // purpose : SLOT. Called when "Filter" button pressed.
1447 //=================================================================================
1448 void SMESHGUI_GroupDlg::setFilters()
1450 if(myMesh->_is_nil()) {
1451 SUIT_MessageBox::critical(this,
1453 tr("NO_MESH_SELECTED"));
1457 SMESH::ElementType aType = SMESH::ALL;
1460 case 0 : aType = SMESH::NODE; break;
1461 case 1 : aType = SMESH::EDGE; break;
1462 case 2 : aType = SMESH::FACE; break;
1463 case 3 : aType = SMESH::VOLUME; break;
1467 if ( myFilterDlg == 0 )
1469 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1470 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1473 myFilterDlg->Init( aType );
1475 myFilterDlg->SetSelection();
1476 myFilterDlg->SetMesh( myMesh );
1477 myFilterDlg->SetSourceWg( myElements, false );
1479 myFilterDlg->show();
1482 //=================================================================================
1483 // function : onFilterAccepted()
1484 // purpose : SLOT. Called when Filter dlg closed with OK button.
1485 // Uncheck "Select submesh" and "Select group" checkboxes
1486 //=================================================================================
1487 void SMESHGUI_GroupDlg::onFilterAccepted()
1489 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1491 mySelectionMode = myTypeId;
1492 mySelectSubMesh->setChecked( false );
1493 mySelectGroup->setChecked( false );
1497 //=================================================================================
1498 // function : onAdd()
1500 //=================================================================================
1501 void SMESHGUI_GroupDlg::onAdd()
1503 SALOME_ListIO aList;
1504 mySelectionMgr->selectedObjects( aList );
1506 int aNbSel = aList.Extent();
1508 if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1512 SMESH::ElementType aType = SMESH::ALL;
1515 aType = SMESH::NODE;
1516 mySelector->SetSelectionMode(NodeSelection);
1519 aType = SMESH::EDGE;
1520 mySelector->SetSelectionMode(EdgeSelection);
1523 aType = SMESH::FACE;
1524 mySelector->SetSelectionMode(FaceSelection);
1527 aType = SMESH::VOLUME;
1528 mySelector->SetSelectionMode(VolumeSelection);
1531 mySelector->SetSelectionMode(ActorSelection);
1534 QListWidgetItem* anItem = 0;
1535 QList<QListWidgetItem*> listItemsToSel;
1537 if (myCurrentLineEdit == 0) {
1538 //if (aNbSel != 1) { myIsBusy = false; return; }
1539 QString aListStr = "";
1541 if (myTypeId == 0) {
1542 QListIterator<SMESH_Actor*> it( myActorsList );
1543 while ( it.hasNext() ) {
1545 aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1550 QListIterator<SMESH_Actor*> it( myActorsList );
1551 while ( it.hasNext() ) {
1553 aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1558 QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1559 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1560 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1561 if (found.count() == 0) {
1562 anItem = new QListWidgetItem(*it);
1563 myElements->addItem(anItem);
1564 if (!anItem->isSelected())
1565 listItemsToSel.push_back(anItem);
1568 foreach(anItem, found)
1569 if (!anItem->isSelected())
1570 listItemsToSel.push_back(anItem);
1573 bool blocked = myElements->signalsBlocked();
1574 myElements->blockSignals(true);
1575 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1576 myElements->blockSignals(blocked);
1577 onListSelectionChanged();
1578 listItemsToSel.clear();
1580 } else if (myCurrentLineEdit == mySubMeshLine) {
1581 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1583 SALOME_ListIO aList;
1584 mySelectionMgr->selectedObjects( aList );
1586 SALOME_ListIteratorOfListIO anIt (aList);
1587 for ( ; anIt.More(); anIt.Next()) {
1588 SMESH::SMESH_subMesh_var aSubMesh =
1589 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1590 if (!aSubMesh->_is_nil()) {
1591 // check if mesh is the same
1592 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1594 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1595 int k = anElements->length();
1596 for (int i = 0; i < k; i++) {
1597 QString aText = QString::number(anElements[i]);
1598 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1599 if (found.count() == 0) {
1600 anItem = new QListWidgetItem(aText);
1601 myElements->addItem(anItem);
1602 if (!anItem->isSelected())
1603 listItemsToSel.push_back(anItem);
1606 foreach(anItem, found)
1607 if (!anItem->isSelected())
1608 listItemsToSel.push_back(anItem);
1611 bool blocked = myElements->signalsBlocked();
1612 myElements->blockSignals(true);
1613 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1614 myElements->blockSignals(blocked);
1615 onListSelectionChanged();
1616 listItemsToSel.clear();
1618 catch (const SALOME::SALOME_Exception& ex) {
1619 SalomeApp_Tools::QtCatchCorbaException(ex);
1624 mySelectSubMesh->setChecked(false);
1626 onListSelectionChanged();
1628 } else if (myCurrentLineEdit == myGroupLine) {
1629 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1630 SALOME_ListIO aList;
1631 mySelectionMgr->selectedObjects( aList );
1633 SALOME_ListIteratorOfListIO anIt (aList);
1634 for ( ; anIt.More(); anIt.Next()) {
1635 SMESH::SMESH_GroupBase_var aGroup =
1636 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1637 if (!aGroup->_is_nil()) {
1638 // check if mesh is the same
1639 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1640 SMESH::long_array_var anElements = aGroup->GetListOfID();
1641 int k = anElements->length();
1642 for (int i = 0; i < k; i++) {
1643 QString aText = QString::number(anElements[i]);
1644 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1645 if (found.count() == 0) {
1646 anItem = new QListWidgetItem(aText);
1647 myElements->addItem(anItem);
1648 if (!anItem->isSelected())
1649 listItemsToSel.push_back(anItem);
1652 foreach(anItem, found)
1653 if (!anItem->isSelected())
1654 listItemsToSel.push_back(anItem);
1657 bool blocked = myElements->signalsBlocked();
1658 myElements->blockSignals(true);
1659 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1660 myElements->blockSignals(blocked);
1661 onListSelectionChanged();
1662 listItemsToSel.clear();
1666 mySelectGroup->setChecked(false);
1668 onListSelectionChanged();
1670 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1671 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1672 GEOM::GEOM_IGroupOperations_var aGroupOp =
1673 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1675 SMESH::ElementType aGroupType = SMESH::ALL;
1676 switch(aGroupOp->GetType(myGeomObjects[0])) {
1677 case 7: aGroupType = SMESH::NODE; break;
1678 case 6: aGroupType = SMESH::EDGE; break;
1679 case 4: aGroupType = SMESH::FACE; break;
1680 case 2: aGroupType = SMESH::VOLUME; break;
1681 default: myIsBusy = false; return;
1684 if (aGroupType == aType) {
1685 _PTR(SObject) aGroupSO =
1686 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1687 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1689 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1690 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1691 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1692 aBelongToGeom->SetGeom(myGeomObjects[0]);
1693 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1694 aBelongToGeom->SetElementType(aType);
1695 aFilter->SetPredicate(aBelongToGeom);
1697 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1699 int k = anElements->length();
1700 for (int i = 0; i < k; i++) {
1701 QString aText = QString::number(anElements[i]);
1702 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1703 if (found.count() == 0) {
1704 anItem = new QListWidgetItem(aText);
1705 myElements->addItem(anItem);
1706 if (!anItem->isSelected())
1707 listItemsToSel.push_back(anItem);
1710 foreach(anItem, found)
1711 if (!anItem->isSelected())
1712 listItemsToSel.push_back(anItem);
1715 bool blocked = myElements->signalsBlocked();
1716 myElements->blockSignals(true);
1717 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1718 myElements->blockSignals(blocked);
1719 onListSelectionChanged();
1720 listItemsToSel.clear();
1723 //VSR: mySelectGeomGroup->setChecked(false);
1725 onListSelectionChanged();
1728 // mySelectionMgr->clearSelected();
1732 //=================================================================================
1733 // function : onRemove()
1735 //=================================================================================
1736 void SMESHGUI_GroupDlg::onRemove()
1739 if (myCurrentLineEdit == 0) {
1740 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1741 QListWidgetItem* item;
1742 foreach(item, selItems) delete item;
1744 SALOME_ListIO aList;
1745 mySelectionMgr->selectedObjects( aList );
1747 int aNbSel = aList.Extent();
1749 if (aNbSel == 0) { myIsBusy = false; return; }
1751 SMESH::ElementType aType = SMESH::ALL;
1753 case 0: aType = SMESH::NODE; break;
1754 case 1: aType = SMESH::EDGE; break;
1755 case 2: aType = SMESH::FACE; break;
1756 case 3: aType = SMESH::VOLUME; break;
1759 if (myCurrentLineEdit == mySubMeshLine) {
1760 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1761 SALOME_ListIO aList;
1762 mySelectionMgr->selectedObjects( aList );
1764 SALOME_ListIteratorOfListIO anIt (aList);
1765 for ( ; anIt.More(); anIt.Next()) {
1766 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1767 if (!aSubMesh->_is_nil()) {
1768 // check if mesh is the same
1769 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1770 if (aType == SMESH::NODE) {
1772 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1773 int k = anElements->length();
1774 for (int i = 0; i < k; i++) {
1775 QList<QListWidgetItem*> found =
1776 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1777 QListWidgetItem* anItem;
1778 foreach(anItem, found) delete anItem;
1781 catch (const SALOME::SALOME_Exception& ex) {
1782 SalomeApp_Tools::QtCatchCorbaException(ex);
1787 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1788 int k = anElements->length();
1789 for (int i = 0; i < k; i++) {
1790 QList<QListWidgetItem*> found =
1791 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1792 QListWidgetItem* anItem;
1793 foreach(anItem, found) delete anItem;
1796 catch (const SALOME::SALOME_Exception& ex) {
1797 SalomeApp_Tools::QtCatchCorbaException(ex);
1804 else if (myCurrentLineEdit == myGroupLine) {
1805 Standard_Boolean aRes;
1806 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1807 SALOME_ListIO aList;
1808 mySelectionMgr->selectedObjects( aList );
1810 SALOME_ListIteratorOfListIO anIt (aList);
1811 for ( ; anIt.More(); anIt.Next()) {
1812 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1813 if (aRes && !aGroup->_is_nil()) {
1814 // check if mesh is the same
1815 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1816 SMESH::long_array_var anElements = aGroup->GetListOfID();
1817 int k = anElements->length();
1818 for (int i = 0; i < k; i++) {
1819 QList<QListWidgetItem*> found =
1820 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1821 QListWidgetItem* anItem;
1822 foreach(anItem, found) delete anItem;
1833 //=================================================================================
1834 // function : onSort()
1836 //=================================================================================
1837 void SMESHGUI_GroupDlg::onSort()
1839 // PAL5412: sorts items in ascending by "string" value
1840 // myElements->sort(true);
1841 // myElements->update();
1842 int i, k = myElements->count();
1845 QList<int> aSelected;
1846 std::vector<int> anArray(k);
1847 // QMemArray<int> anArray(k);
1849 for (i = 0; i < k; i++) {
1850 int id = myElements->item(i)->text().toInt();
1852 if (myElements->item(i)->isSelected())
1853 aSelected.append(id);
1855 // sort & update list
1856 std::sort(anArray.begin(), anArray.end());
1858 myElements->clear();
1859 QListWidgetItem* anItem;
1860 QList<QListWidgetItem*> listItemsToSel;
1861 for (i = 0; i < k; i++) {
1862 anItem = new QListWidgetItem(QString::number(anArray[i]));
1863 myElements->addItem(anItem);
1864 if (aSelected.contains(anArray[i]))
1865 listItemsToSel.push_back(anItem);
1867 bool blocked = myElements->signalsBlocked();
1868 myElements->blockSignals(true);
1869 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1870 myElements->blockSignals(blocked);
1871 listItemsToSel.clear();
1876 //=================================================================================
1877 // function : closeEvent()
1879 //=================================================================================
1880 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1885 //=================================================================================
1886 // function : onVisibilityChanged()
1888 //=================================================================================
1889 void SMESHGUI_GroupDlg::onVisibilityChanged()
1891 SetAppropriateActor();
1894 //=================================================================================
1895 // function : SMESHGUI_GroupDlg::onClose
1896 // purpose : SLOT called when "Close" button pressed. Close dialog
1897 //=================================================================================
1898 void SMESHGUI_GroupDlg::onClose()
1900 if (SMESH::GetCurrentVtkView()) {
1901 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1902 SMESH::SetPointRepresentation(false);
1903 SMESH::SetPickable();
1904 restoreShowEntityMode();
1907 mySelectionMgr->clearSelected();
1908 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1909 aViewWindow->SetSelectionMode(ActorSelection);
1910 mySelectionMgr->clearFilters();
1911 mySMESHGUI->ResetState();
1916 //=================================================================================
1917 // function : onHelp()
1919 //=================================================================================
1920 void SMESHGUI_GroupDlg::onHelp()
1922 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1924 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
1928 platform = "winapplication";
1930 platform = "application";
1932 SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
1933 tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1934 arg(app->resourceMgr()->stringValue( "ExternalBrowser",
1936 arg(myHelpFileName));
1940 //=================================================================================
1941 // function : SMESHGUI_GroupDlg::onDeactivate
1942 // purpose : SLOT called when dialog must be deativated
1943 //=================================================================================
1944 void SMESHGUI_GroupDlg::onDeactivate()
1946 mySMESHGUI->ResetState();
1950 //=================================================================================
1951 // function : SMESHGUI_GroupDlg::enterEvent
1952 // purpose : Event filter
1953 //=================================================================================
1954 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1957 mySMESHGUI->EmitSignalDeactivateDialog();
1959 mySelectionMode = -1;
1960 setSelectionMode(myTypeId);
1961 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1962 mySMESHGUI->SetActiveDialogBox(this);
1963 mySMESHGUI->SetState(800);
1967 //=================================================================================
1968 // function : hideEvent
1969 // purpose : caused by ESC key
1970 //=================================================================================
1971 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1973 if (!isMinimized() && !myIsBusy)
1977 //=================================================================================
1978 // function : keyPressEvent()
1980 //=================================================================================
1981 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1983 QDialog::keyPressEvent( e );
1984 if ( e->isAccepted() )
1987 if ( e->key() == Qt::Key_F1 )
1994 //================================================================================
1996 * \brief Enable showing of the popup when Geometry selection btn is clicked
1997 * \param enable - true to enable
1999 //================================================================================
2001 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2003 void SMESHGUI_GroupDlg::updateGeomPopup()
2005 bool enable = false;
2007 if ( !myMesh->_is_nil() )
2008 enable = myMesh->NbEdges() > 0;
2010 if ( myGeomGroupBtn )
2012 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2014 if ( !myGeomPopup ) {
2015 myGeomPopup = new QMenu(this);
2016 myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2017 myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2018 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2020 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2026 //=================================================================================
2027 // function : onGeomSelectionButton()
2029 //=================================================================================
2030 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2032 if ( myGeomPopup && isBtnOn )
2034 myCurrentLineEdit = myGeomGroupLine;
2035 QAction* a = myGeomPopup->exec( QCursor::pos() );
2036 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2037 setSelectionMode(7);
2041 myCurrentLineEdit = 0;
2042 setSelectionMode(8);
2046 //=================================================================================
2047 // function : onGeomPopup()
2049 //=================================================================================
2050 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2052 int index = myActions[a];
2053 if ( index == GEOM_BY_MESH_INDEX )
2055 mySelectionMode = -1;
2056 if ( !myShapeByMeshOp ) {
2057 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2058 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2059 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2060 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2061 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2063 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2064 if ( !myMesh->_is_nil() ) {
2066 hide(); // stop processing selection
2068 myShapeByMeshOp->setModule( mySMESHGUI );
2069 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2070 myShapeByMeshOp->SetMesh( myMesh );
2071 myShapeByMeshOp->start();
2076 //================================================================================
2078 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2080 //================================================================================
2082 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2084 if ( myShapeByMeshOp == op ) {
2085 mySMESHGUI->getApp()->updateObjectBrowser();
2087 // Select a found geometry object
2088 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2089 if ( !aGeomVar->_is_nil() )
2091 QString ID = aGeomVar->GetStudyEntry();
2092 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2093 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2094 SALOME_ListIO anIOList;
2095 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2096 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2097 anIOList.Append( anIO );
2098 mySelectionMgr->setSelectedObjects( anIOList, false );
2099 onObjectSelectionChanged();
2105 //================================================================================
2107 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2109 //================================================================================
2111 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2113 if ( myShapeByMeshOp == op )
2116 setSelectionMode(7);
2120 //=================================================================================
2121 // function : setGroupColor()
2123 //=================================================================================
2124 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2126 QColor aQColor( (int)( theColor.R * 255.0 ),
2127 (int)( theColor.G * 255.0 ),
2128 (int)( theColor.B * 255.0 ) );
2129 setGroupQColor( aQColor );
2132 //=================================================================================
2133 // function : getGroupColor()
2135 //=================================================================================
2136 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2138 QColor aQColor = getGroupQColor();
2140 SALOMEDS::Color aColor;
2141 aColor.R = (float)aQColor.red() / 255.0;
2142 aColor.G = (float)aQColor.green() / 255.0;
2143 aColor.B = (float)aQColor.blue() / 255.0;
2148 //=================================================================================
2149 // function : setGroupQColor()
2151 //=================================================================================
2152 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2154 if( theColor.isValid() )
2155 myColorBtn->setColor( theColor );
2158 //=================================================================================
2159 // function : getGroupQColor()
2161 //=================================================================================
2162 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2164 return myColorBtn->color();
2167 //=================================================================================
2168 // function : setDefaultGroupColor()
2170 //=================================================================================
2171 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2173 if( myMesh->_is_nil() )
2176 bool isAutoColor = myMesh->GetAutoColor();
2181 int r = 0, g = 0, b = 0;
2182 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2183 aQColor.setRgb( r, g, b );
2187 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2189 QList<SALOMEDS::Color> aReservedColors;
2190 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2192 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2193 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2194 aReservedColors.append( aReservedColor );
2197 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2198 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2199 (int)( aColor.G * 255.0 ),
2200 (int)( aColor.B * 255.0 ) );
2204 setGroupQColor( aQColor );
2207 //=================================================================================
2208 // function : SetAppropriateActor()
2209 // purpose : Find more appropriate of visible actors, set it to myActor, allow picking
2210 // NPAL19389: create a group with a selection in another group.
2211 // if mesh actor is not visible - find any first visible group or submesh
2212 //=================================================================================
2213 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2215 bool isActor = false;
2216 myActorsList.clear();
2218 if (myMesh->_is_nil()) return false;
2220 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2222 if (myGeomGroupBtn->isChecked()) { // try current group on geometry actor
2224 if (!myGroupOnGeom->_is_nil()) {
2225 SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2226 if (anActor && anActor->hasIO())
2229 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2232 myActorsList.append(anActor);
2238 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2239 if (anActor && anActor->hasIO())
2242 if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2245 myActorsList.append(anActor);
2248 // try any visible actor of group or submesh of current mesh
2251 _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2253 CORBA::String_var meshEntry = aSObject->GetID().c_str();
2254 int len = strlen(meshEntry);
2256 // iterate on all actors in current view window, search for
2257 // any visible actor, that belongs to group or submesh of current mesh
2258 VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2259 vtkActorCollection *aCollection = aCopy.GetActors();
2260 int nbItems = aCollection->GetNumberOfItems();
2261 for (int i=0; i<nbItems && !isActor; i++)
2263 SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2264 if (anActor && anActor->hasIO()) {
2265 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2266 if (aViewWindow->isVisible(anIO)) {
2267 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0)
2268 myActorsList.append(anActor);
2276 if (myActorsList.count() > 0) {
2277 QListIterator<SMESH_Actor*> it( myActorsList );
2278 while ( it.hasNext() ) {
2279 SMESH_Actor* anActor = it.next();
2280 if ( IsActorVisible(anActor) )
2281 anActor->SetPickable(true);
2285 return ( isActor || (myActorsList.count() > 0) );
2288 //=======================================================================
2289 //function : setShowEntityMode
2290 //purpose : make shown only entity corresponding to my type
2291 //=======================================================================
2292 void SMESHGUI_GroupDlg::setShowEntityMode()
2294 if ( !myMesh->_is_nil() ) {
2295 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2296 if (!myStoredShownEntity)
2297 myStoredShownEntity = actor->GetEntityMode();
2298 switch ( myTypeId ) {
2299 case 0: restoreShowEntityMode(); break;
2300 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2301 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2302 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2308 //=======================================================================
2309 //function : restoreShowEntityMode
2310 //purpose : restore ShowEntity mode of myActor
2311 //=======================================================================
2312 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2314 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2315 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2316 actor->SetEntityMode(myStoredShownEntity);
2319 myStoredShownEntity = 0;
2322 //=======================================================================
2323 //function : IsActorVisible
2324 //purpose : return visibility of the actor
2325 //=======================================================================
2326 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2328 SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2329 if (theActor && aViewWindow)
2330 return aViewWindow->isVisible(theActor->getIO());