1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : SMESHGUI_GroupDlg.cxx
22 // Author : Natalia KOPNOVA, Open CASCADE S.A.S.
26 #include "SMESHGUI_GroupDlg.h"
29 #include "SMESHGUI_Utils.h"
30 #include "SMESHGUI_VTKUtils.h"
31 #include "SMESHGUI_GroupUtils.h"
32 #include "SMESHGUI_FilterUtils.h"
33 #include "SMESHGUI_GEOMGenUtils.h"
34 #include "SMESHGUI_FilterDlg.h"
35 #include "SMESHGUI_ShapeByMeshDlg.h"
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_Actor.h>
39 #include <SMESH_ActorUtils.h>
41 // SALOME GEOM includes
43 #include <GEOM_SelectionFilter.h>
45 // SALOME GUI includes
46 #include <QtxColorButton.h>
48 #include <SUIT_Desktop.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_MessageBox.h>
53 #include <SalomeApp_Tools.h>
54 #include <SalomeApp_Application.h>
55 #include <SalomeApp_Study.h>
56 #include <LightApp_SelectionMgr.h>
58 #include <SALOME_ListIO.hxx>
59 #include <SALOME_ListIteratorOfListIO.hxx>
61 #include <SVTK_ViewWindow.h>
63 // SALOME KERNEL includes
64 #include <SALOMEDSClient_Study.hxx>
67 #include <TColStd_MapOfInteger.hxx>
70 #include <QButtonGroup>
74 #include <QPushButton>
75 #include <QToolButton>
76 #include <QRadioButton>
78 #include <QGridLayout>
79 #include <QHBoxLayout>
80 #include <QVBoxLayout>
81 #include <QListWidget>
82 #include <QStackedWidget>
94 //=================================================================================
95 // function : SMESHGUI_GroupDlg()
97 //=================================================================================
98 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
99 SMESH::SMESH_Mesh_ptr theMesh )
100 : QDialog( SMESH::GetDesktop( theModule ) ),
101 mySMESHGUI( theModule ),
102 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
103 mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
108 if (!theMesh->_is_nil())
111 mySelectSubMesh->setEnabled(false);
112 mySelectGroup->setEnabled(false);
113 myGeomGroupBtn->setEnabled(false);
114 myGeomGroupLine->setEnabled(false);
118 //=================================================================================
119 // function : SMESHGUI_GroupDlg()
121 //=================================================================================
122 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
123 SMESH::SMESH_GroupBase_ptr theGroup )
124 : QDialog( SMESH::GetDesktop( theModule ) ),
125 mySMESHGUI( theModule ),
126 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
127 mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
131 if (!theGroup->_is_nil())
134 mySelectSubMesh->setEnabled(false);
135 mySelectGroup->setEnabled(false);
137 myCurrentLineEdit = myMeshGroupLine;
142 //=================================================================================
143 // function : SMESHGUI_GroupDlg()
145 //=================================================================================
146 void SMESHGUI_GroupDlg::initDialog(bool create)
149 setAttribute( Qt::WA_DeleteOnClose, true );
153 myCurrentLineEdit = 0;
157 myGeomObjects = new GEOM::ListOfGO();
158 myGeomObjects->length(0);
160 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
162 setWindowTitle(create ? tr("SMESH_CREATE_GROUP_TITLE") : tr("SMESH_EDIT_GROUP_TITLE"));
163 myHelpFileName = create ? "creating_groups_page.html" : "editing_groups_page.html";
165 setSizeGripEnabled(true);
167 QGridLayout* aMainLayout = new QGridLayout(this);
168 aMainLayout->setMargin( MARGIN );
169 aMainLayout->setSpacing( SPACING );
171 /***************************************************************/
172 QLabel* meshGroupLab = new QLabel(create ? tr("SMESH_MESH") : tr("SMESH_GROUP"), this);
173 myMeshGroupBtn = new QPushButton(this);
174 myMeshGroupBtn->setIcon(image0);
175 myMeshGroupLine = new QLineEdit(this);
176 myMeshGroupLine->setReadOnly(true);
178 /***************************************************************/
179 QGroupBox* aTypeBox = new QGroupBox(tr("SMESH_ELEMENTS_TYPE"), this);
180 myTypeGroup = new QButtonGroup(this);
181 QHBoxLayout* aTypeBoxLayout = new QHBoxLayout( aTypeBox );
182 aTypeBoxLayout->setMargin( MARGIN );
183 aTypeBoxLayout->setSpacing( SPACING );
186 types.append(tr("MESH_NODE"));
187 types.append(tr("SMESH_EDGE"));
188 types.append(tr("SMESH_FACE"));
189 types.append(tr("SMESH_VOLUME"));
191 for (int i = 0; i < types.count(); i++) {
192 rb = new QRadioButton(types[i], aTypeBox);
193 myTypeGroup->addButton(rb, i);
194 aTypeBoxLayout->addWidget( rb );
196 aTypeBox->setEnabled(create);
199 /***************************************************************/
200 QLabel* aName = new QLabel(tr("SMESH_NAME"), this);
201 aName->setMinimumWidth(50);
202 myName = new QLineEdit(this);
204 /***************************************************************/
205 QGroupBox* aGrpTypeBox = new QGroupBox(tr("SMESH_GROUP_TYPE"), this);
206 myGrpTypeGroup = new QButtonGroup(this);
207 QHBoxLayout* aGrpTypeBoxLayout = new QHBoxLayout( aGrpTypeBox );
208 aGrpTypeBoxLayout->setMargin( MARGIN );
209 aGrpTypeBoxLayout->setSpacing( SPACING );
211 QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), aGrpTypeBox);
212 QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"), aGrpTypeBox);
213 myGrpTypeGroup->addButton(rb1, 0);
214 myGrpTypeGroup->addButton(rb2, 1);
215 aGrpTypeBoxLayout->addWidget(rb1);
216 aGrpTypeBoxLayout->addWidget(rb2);
217 aGrpTypeBox->setEnabled(create);
220 /***************************************************************/
221 myWGStack = new QStackedWidget(this);
222 QWidget* wg1 = new QWidget( myWGStack );
223 QWidget* wg2 = new QWidget( myWGStack );
225 /***************************************************************/
226 QGroupBox* aContentBox = new QGroupBox(tr("SMESH_CONTENT"), wg1);
227 QGridLayout* aContentBoxLayout = new QGridLayout(aContentBox);
228 aContentBoxLayout->setMargin(MARGIN);
229 aContentBoxLayout->setSpacing(SPACING);
231 QLabel* aLabel = new QLabel(tr("SMESH_ID_ELEMENTS"), aContentBox);
232 myElements = new QListWidget(aContentBox);
233 myElements->setSelectionMode(QListWidget::ExtendedSelection);
235 myFilter = new QPushButton(tr("SMESH_BUT_FILTER"), aContentBox);
236 QPushButton* aAddBtn = new QPushButton(tr("SMESH_BUT_ADD"), aContentBox);
237 QPushButton* aRemoveBtn = new QPushButton(tr("SMESH_BUT_REMOVE"), aContentBox);
238 QPushButton* aSortBtn = new QPushButton(tr("SMESH_BUT_SORT"), aContentBox);
240 aContentBoxLayout->addWidget(aLabel, 0, 0);
241 aContentBoxLayout->addWidget(myElements, 1, 0, 6, 1);
242 aContentBoxLayout->addWidget(myFilter, 1, 1);
243 aContentBoxLayout->addWidget(aAddBtn, 3, 1);
244 aContentBoxLayout->addWidget(aRemoveBtn, 4, 1);
245 aContentBoxLayout->addWidget(aSortBtn, 6, 1);
247 aContentBoxLayout->setColumnStretch(0, 1);
248 aContentBoxLayout->setRowStretch(2, 1);
249 aContentBoxLayout->setRowStretch(5, 1);
251 /***************************************************************/
252 QGroupBox* aSelectBox = new QGroupBox(tr("SMESH_SELECT_FROM"), wg1);
253 QGridLayout* aSelectBoxLayout = new QGridLayout(aSelectBox);
254 aSelectBoxLayout->setMargin(MARGIN);
255 aSelectBoxLayout->setSpacing(SPACING);
257 mySelectSubMesh = new QCheckBox(tr("SMESH_SUBMESH"), aSelectBox);
258 mySubMeshBtn = new QPushButton(aSelectBox);
259 mySubMeshBtn->setIcon(image0);
260 mySubMeshLine = new QLineEdit(aSelectBox);
261 mySubMeshLine->setReadOnly(true);
262 onSelectSubMesh(false);
264 mySelectGroup = new QCheckBox(tr("SMESH_GROUP"), aSelectBox);
265 myGroupBtn = new QPushButton(aSelectBox);
266 myGroupBtn->setIcon(image0);
267 myGroupLine = new QLineEdit(aSelectBox);
268 myGroupLine->setReadOnly(true);
269 onSelectGroup(false);
271 aSelectBoxLayout->addWidget(mySelectSubMesh, 0, 0);
272 aSelectBoxLayout->addWidget(mySubMeshBtn, 0, 1);
273 aSelectBoxLayout->addWidget(mySubMeshLine, 0, 2);
274 aSelectBoxLayout->addWidget(mySelectGroup, 1, 0);
275 aSelectBoxLayout->addWidget(myGroupBtn, 1, 1);
276 aSelectBoxLayout->addWidget(myGroupLine, 1, 2);
278 /***************************************************************/
279 QVBoxLayout* wg1Layout = new QVBoxLayout(wg1);
280 wg1Layout->setMargin(0);
281 wg1Layout->setSpacing(SPACING);
282 wg1Layout->addWidget(aContentBox);
283 wg1Layout->addWidget(aSelectBox);
284 wg1Layout->setStretchFactor(aContentBox, 10);
286 /***************************************************************/
287 QLabel* geomObject = new QLabel(tr("SMESH_OBJECT_GEOM"), wg2);
288 myGeomGroupBtn = new QToolButton(wg2);
289 myGeomGroupBtn->setIcon(image0);
290 myGeomGroupBtn->setCheckable(true);
291 myGeomGroupLine = new QLineEdit(wg2);
292 myGeomGroupLine->setReadOnly(true); //VSR ???
293 onSelectGeomGroup(false);
295 myGeomGroupBtn->setEnabled(create);
296 myGeomGroupLine->setEnabled(create);
298 /***************************************************************/
299 QGridLayout* wg2Layout = new QGridLayout( wg2 );
300 wg2Layout->setMargin(0);
301 wg1Layout->setSpacing(SPACING);
302 wg2Layout->addWidget(geomObject, 0, 0);
303 wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
304 wg2Layout->addWidget(myGeomGroupLine,0, 2);
305 wg2Layout->setRowStretch(1, 5);
307 /***************************************************************/
308 myWGStack->insertWidget( 0, wg1 );
309 myWGStack->insertWidget( 1, wg2 );
311 /***************************************************************/
312 QGroupBox* aColorBox = new QGroupBox(tr("SMESH_SET_COLOR"), this);
313 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
314 aColorBoxLayout->setMargin(MARGIN);
315 aColorBoxLayout->setSpacing(SPACING);
317 QLabel* aColorLab = new QLabel(tr("SMESH_CHECK_COLOR"), aColorBox );
318 myColorBtn = new QtxColorButton(aColorBox);
319 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
320 myColorBtn->sizePolicy().verticalPolicy() );
322 aColorBoxLayout->addWidget(aColorLab);
323 aColorBoxLayout->addWidget(myColorBtn);
325 /***************************************************************/
327 QFrame* aButtons = new QFrame(this);
328 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
329 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
330 aBtnLayout->setMargin(MARGIN);
331 aBtnLayout->setSpacing(SPACING);
333 myOKBtn = new QPushButton(tr("SMESH_BUT_OK"), aButtons);
334 myOKBtn->setAutoDefault(true);
335 myOKBtn->setDefault(true);
336 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aButtons);
337 myApplyBtn->setAutoDefault(true);
338 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aButtons);
339 myCloseBtn->setAutoDefault(true);
340 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aButtons);
341 myHelpBtn->setAutoDefault(true);
343 aBtnLayout->addWidget(myOKBtn);
344 aBtnLayout->addSpacing(10);
345 aBtnLayout->addWidget(myApplyBtn);
346 aBtnLayout->addSpacing(10);
347 aBtnLayout->addStretch();
348 aBtnLayout->addWidget(myCloseBtn);
349 aBtnLayout->addWidget(myHelpBtn);
351 /***************************************************************/
352 aMainLayout->addWidget(meshGroupLab, 0, 0);
353 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
354 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
355 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
356 aMainLayout->addWidget(aName, 2, 0);
357 aMainLayout->addWidget(myName, 2, 2);
358 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
359 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
360 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
361 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
363 /* signals and slots connections */
364 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
365 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
366 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
368 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
369 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
371 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
372 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
373 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
374 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
376 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
377 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
378 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
379 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
380 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
382 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
383 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
384 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
385 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
388 mySMESHGUI->SetActiveDialogBox(this);
389 mySMESHGUI->SetState(800);
391 mySelectionMode = -1;
392 myMeshFilter = new SMESH_TypeFilter(MESH);
393 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
394 myGroupFilter = new SMESH_TypeFilter(GROUP);
395 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
396 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
398 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
399 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
400 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
402 rb1->setChecked(true); // VSR !!!
403 onGrpTypeChanged(0); // VSR!!!
405 if (myMesh->_is_nil() )
406 myTypeGroup->button(0)->setChecked(true);
409 //myName->setText(GetDefaultName(tr("SMESH_GROUP")));
412 //=================================================================================
413 // function : ~SMESHGUI_GroupDlg()
414 // purpose : Destroys the object and frees any allocated resources
415 //=================================================================================
416 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
418 // no need to delete child widgets, Qt does it all for us
419 if ( myFilterDlg != 0 ) {
420 myFilterDlg->setParent( 0 );
425 //=================================================================================
426 // function : GetDefaultName()
427 // purpose : Get the Group Name if Create new Group
428 //=================================================================================
429 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
433 // collect all object names of SMESH component
434 SalomeApp_Study* appStudy =
435 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
436 if ( !appStudy ) return aName;
437 _PTR(Study) aStudy = appStudy->studyDS();
439 std::set<std::string> aSet;
440 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
442 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
444 for (it->InitEx(true); it->More(); it->Next()) {
446 aSet.insert(obj->GetName());
450 // build a unique name
452 bool isUnique = false;
454 aName = theOperation + "_" + QString::number(++aNumber);
455 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
461 //=================================================================================
464 //=================================================================================
465 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
467 mySelectionMgr->installFilter(myMeshFilter);
469 /* init data from current selection */
470 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
471 myGroup = SMESH::SMESH_Group::_nil();
472 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
474 myActor = SMESH::FindActorByObject(myMesh);
475 SMESH::SetPickable(myActor);
477 setDefaultGroupColor();
480 mySelectionMgr->selectedObjects( aList );
481 if( !aList.IsEmpty() )
483 QString aName = aList.First()->getName();
484 myMeshGroupLine->setText(aName);
485 myMeshGroupLine->home( false );
488 myCurrentLineEdit = 0;
490 myTypeGroup->button(0)->setChecked(true);
494 //=================================================================================
497 //=================================================================================
498 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
500 myMesh = theGroup->GetMesh();
502 myName->setText(theGroup->GetName());
504 myOldName = myName->text();
506 SALOMEDS::Color aColor = theGroup->GetColor();
507 setGroupColor( aColor );
509 myMeshGroupLine->setText(theGroup->GetName());
512 switch(theGroup->GetType()) {
513 case SMESH::NODE: aType= 0; break;
514 case SMESH::EDGE: aType = 1; break;
515 case SMESH::FACE: aType = 2; break;
516 case SMESH::VOLUME: aType = 3; break;
518 myTypeGroup->button(aType)->setChecked(true);
520 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
522 if ( !myGroup->_is_nil() )
524 myActor = SMESH::FindActorByObject(myMesh);
526 myActor = SMESH::FindActorByObject(myGroup);
527 SMESH::SetPickable(myActor);
529 myGrpTypeGroup->button(0)->setChecked(true);
532 myCurrentLineEdit = 0;
534 setSelectionMode(aType);
538 if (!myGroup->IsEmpty()) {
539 SMESH::long_array_var anElements = myGroup->GetListOfID();
540 int k = anElements->length();
541 for (int i = 0; i < k; i++) {
542 myIdList.append(anElements[i]);
543 myElements->addItem(QString::number(anElements[i]));
545 myElements->selectAll();
550 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
552 if ( !myGroupOnGeom->_is_nil() )
554 myActor = SMESH::FindActorByObject(myMesh);
556 myActor = SMESH::FindActorByObject(myGroup);
557 SMESH::SetPickable(myActor);
559 myGrpTypeGroup->button(1)->setChecked(true);
562 QString aShapeName("");
563 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
564 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
565 if (!aGroupShape->_is_nil())
567 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
568 aShapeName = aGroupShapeSO->GetName().c_str();
570 myGeomGroupLine->setText( aShapeName );
571 myName->setText("Group On " + aShapeName);
576 //=================================================================================
577 // function : updateButtons()
579 //=================================================================================
580 void SMESHGUI_GroupDlg::updateButtons()
582 bool enable = !myName->text().trimmed().isEmpty();
584 if (myGrpTypeId == 0) {
585 enable = enable && myElements->count() > 0;
586 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
588 else if (myGrpTypeId == 1) {
589 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
590 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
594 myOKBtn->setEnabled(enable);
595 myApplyBtn->setEnabled(enable);
598 //=================================================================================
599 // function : onNameChanged()
601 //=================================================================================
602 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
607 //=================================================================================
608 // function : onTypeChanged()
609 // purpose : Group elements type radio button management
610 //=================================================================================
611 void SMESHGUI_GroupDlg::onTypeChanged (int id)
613 if (myTypeId != id) {
615 if (myCurrentLineEdit == 0)
616 setSelectionMode(id);
621 //=================================================================================
622 // function : onGrpTypeChanged()
623 // purpose : Group type radio button management
624 //=================================================================================
625 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
627 if (myGrpTypeId != id) {
628 myWGStack->setCurrentIndex( id );
630 myName->setText(myOldName);
631 onSelectGeomGroup(id == 1);
636 //=================================================================================
637 // function : setSelectionMode()
638 // purpose : Radio button management
639 //=================================================================================
640 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
643 if (myMesh->_is_nil())
645 if (mySelectionMode != theMode) {
646 // [PAL10408] mySelectionMgr->clearSelected();
647 mySelectionMgr->clearFilters();
649 myActor->SetPointRepresentation(false);
651 SMESH::SetPointRepresentation(false);
656 myActor->SetPointRepresentation(true);
658 SMESH::SetPointRepresentation(true);
659 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
660 aViewWindow->SetSelectionMode(NodeSelection);
663 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
664 aViewWindow->SetSelectionMode(EdgeSelection);
667 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
668 aViewWindow->SetSelectionMode(FaceSelection);
671 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
672 aViewWindow->SetSelectionMode(VolumeSelection);
676 mySelectionMgr->installFilter(mySubMeshFilter);
677 else if (theMode == 5)
678 mySelectionMgr->installFilter(myGroupFilter);
679 else if (theMode == 6)
680 mySelectionMgr->installFilter(myMeshFilter);
681 else if (theMode == 7)
682 mySelectionMgr->installFilter(myGeomFilter);
684 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
685 aViewWindow->SetSelectionMode(ActorSelection);
687 mySelectionMode = theMode;
691 //=================================================================================
692 // function : onApply()
694 //=================================================================================
695 bool SMESHGUI_GroupDlg::onApply()
697 if (mySMESHGUI->isActiveStudyLocked())
700 if (myName->text().trimmed().isEmpty())
703 if (myGrpTypeId == 0) { // on mesh elements
704 if (!myElements->count())
707 mySelectionMgr->clearSelected();
709 if (myGroup->_is_nil()) { // creation
710 if (myMesh->_is_nil())
713 SMESH::ElementType aType = SMESH::ALL;
715 case 0: aType = SMESH::NODE; break;
716 case 1: aType = SMESH::EDGE; break;
717 case 2: aType = SMESH::FACE; break;
718 case 3: aType = SMESH::VOLUME; break;
721 SMESH::long_array_var anIdList = new SMESH::long_array;
722 int i, k = myElements->count();
724 for (i = 0; i < k; i++) {
725 anIdList[i] = myElements->item(i)->text().toInt();
728 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
729 myGroup->Add(anIdList.inout());
731 SALOMEDS::Color aColor = getGroupColor();
732 myGroup->SetColor(aColor);
734 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
736 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
737 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
739 /* init for next operation */
742 myGroup = SMESH::SMESH_Group::_nil();
745 myGroup->SetName(myName->text().toLatin1().data());
747 SALOMEDS::Color aColor = getGroupColor();
748 myGroup->SetColor(aColor);
750 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
751 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
752 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
756 int i, total = myElements->count();
757 for (i = 0; i < total; i++) {
758 int anId = myElements->item(i)->text().toInt();
759 int idx = myIdList.indexOf(anId);
761 aAddList.append(anId);
763 myIdList.removeAt(idx);
765 if (!aAddList.empty()) {
766 SMESH::long_array_var anIdList = new SMESH::long_array;
767 int added = aAddList.count();
768 anIdList->length(added);
769 for (i = 0; i < added; i++)
770 anIdList[i] = aAddList[i];
771 myGroup->Add(anIdList.inout());
773 if (!myIdList.empty()) {
774 SMESH::long_array_var anIdList = new SMESH::long_array;
775 int removed = myIdList.count();
776 anIdList->length(removed);
777 for (i = 0; i < removed; i++)
778 anIdList[i] = myIdList[i];
779 myGroup->Remove(anIdList.inout());
781 /* init for next operation */
783 for (i = 0; i < total; i++) {
784 myIdList.append(myElements->item(i)->text().toInt());
788 mySMESHGUI->updateObjBrowser(true);
789 SMESH::UpdateView(); // asv: fix of BUG PAL5515
790 mySelectionMgr->clearSelected();
793 else if (myGrpTypeId == 1) { // on geom object
794 if (CORBA::is_nil(myGroupOnGeom)) { // creation
795 if (myMesh->_is_nil() || !myGeomObjects->length())
798 SMESH::ElementType aType = SMESH::ALL;
800 case 0: aType = SMESH::NODE; break;
801 case 1: aType = SMESH::EDGE; break;
802 case 2: aType = SMESH::FACE; break;
803 case 3: aType = SMESH::VOLUME; break;
806 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
807 GEOM::GEOM_IGroupOperations_var aGroupOp =
808 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
810 if (myGeomObjects->length() == 1) {
811 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
812 myName->text().toLatin1().data(),
816 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
817 if ( aSMESHGen->_is_nil() )
820 // create a geometry group
821 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
822 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
824 if (geomGen->_is_nil() || !aStudy)
827 GEOM::GEOM_IGroupOperations_var op =
828 geomGen->GetIGroupOperations(aStudy->StudyId());
832 // check and add all selected GEOM objects: they must be
833 // a sub-shapes of the main GEOM and must be of one type
834 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
835 for ( int i =0; i < myGeomObjects->length(); i++) {
836 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
838 aGroupType = aSubShapeType;
839 else if (aSubShapeType != aGroupType) {
840 aGroupType = TopAbs_SHAPE;
845 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
846 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
847 op->UnionList(aGroupVar, myGeomObjects);
850 // publish the GEOM group in study
851 QString aNewGeomGroupName ("Auto_group_for_");
852 aNewGeomGroupName += myName->text();
853 SALOMEDS::SObject_var aNewGroupSO =
854 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
855 aNewGeomGroupName.toLatin1().data(), aMeshShape);
858 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
859 myName->text().toLatin1().data(),
863 SALOMEDS::Color aColor = getGroupColor();
864 myGroupOnGeom->SetColor(aColor);
866 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
868 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
869 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
871 /* init for next operation */
873 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
876 myGroupOnGeom->SetName(myName->text().toLatin1().data());
878 SALOMEDS::Color aColor = getGroupColor();
879 myGroupOnGeom->SetColor(aColor);
881 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
882 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
883 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
886 mySMESHGUI->updateObjBrowser(true);
887 mySelectionMgr->clearSelected();
894 //=================================================================================
897 //=================================================================================
898 void SMESHGUI_GroupDlg::onOK()
904 //=================================================================================
905 // function : onListSelectionChanged()
906 // purpose : Called when selection in element list is changed
907 //=================================================================================
908 void SMESHGUI_GroupDlg::onListSelectionChanged()
910 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
911 if( myIsBusy || !myActor) return;
914 if (myCurrentLineEdit == 0) {
915 mySelectionMgr->clearSelected();
916 TColStd_MapOfInteger aIndexes;
917 QList<QListWidgetItem*> selItems = myElements->selectedItems();
918 QListWidgetItem* anItem;
919 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
920 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
922 aList.Append(myActor->getIO());
923 mySelectionMgr->setSelectedObjects(aList,false);
928 //=================================================================================
929 // function : onObjectSelectionChanged()
930 // purpose : Called when selection in 3D view or ObjectBrowser is changed
931 //=================================================================================
932 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
934 if ( myIsBusy || !isEnabled()) return;
935 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isDown()) return;
940 mySelectionMgr->selectedObjects( aList );
942 int aNbSel = aList.Extent();
943 myElements->clearSelection();
945 if (myCurrentLineEdit) {
946 myCurrentLineEdit->setText("");
947 QString aString = "";
949 if (myCurrentLineEdit == myMeshGroupLine) {
950 mySelectSubMesh->setEnabled(false);
951 mySelectGroup->setEnabled(false);
952 myGroupLine->setText("");
953 mySubMeshLine->setText("");
955 myGeomGroupBtn->setEnabled(false);
956 myGeomGroupLine->setEnabled(false);
957 myGeomGroupLine->setText("");
958 myGeomObjects = new GEOM::ListOfGO();
959 myGeomObjects->length(0);
961 if (myGeomGroupBtn->isDown())
962 myGeomGroupBtn->setDown(false);
969 myGroup = SMESH::SMESH_Group::_nil();
970 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
971 myMesh = SMESH::SMESH_Mesh::_nil();
977 Handle(SALOME_InteractiveObject) IO = aList.First();
980 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
982 if (myMesh->_is_nil())
988 myGroup = SMESH::SMESH_Group::_nil();
990 myActor = SMESH::FindActorByObject(myMesh);
991 SMESH::SetPickable(myActor);
993 aString = aList.First()->getName();
994 myMeshGroupLine->setText(aString);
995 myMeshGroupLine->home( false );
997 mySelectSubMesh->setEnabled(true);
998 mySelectGroup->setEnabled(true);
999 myGeomGroupBtn->setEnabled(true);
1000 myGeomGroupLine->setEnabled(true);
1003 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1004 if (aGroup->_is_nil())
1010 myCurrentLineEdit = 0;
1012 myGroup = SMESH::SMESH_Group::_nil();
1013 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1017 mySelectSubMesh->setEnabled(true);
1018 mySelectGroup->setEnabled(true);
1020 myCurrentLineEdit = 0;
1025 if (myGrpTypeId == 0)
1031 myElements->clear();
1032 setSelectionMode(myTypeId);
1039 } else if (myCurrentLineEdit == myGeomGroupLine) {
1041 myGeomObjects = new GEOM::ListOfGO();
1044 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1046 if (aNbSel == 0 || !aMeshSO)
1048 myGeomObjects->length(0);
1054 myGeomObjects->length(aNbSel);
1056 GEOM::GEOM_Object_var aGeomGroup;
1057 Standard_Boolean testResult;
1060 SALOME_ListIteratorOfListIO anIt (aList);
1061 for ( ; anIt.More(); anIt.Next()) {
1063 testResult = Standard_False;
1064 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1066 // Check if the object is a geometry group
1067 if (!testResult || CORBA::is_nil(aGeomGroup))
1071 // Check if group constructed on the same shape as a mesh or on its child
1072 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1073 GEOM::GEOM_IGroupOperations_var anOp =
1074 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1076 // The main shape of the group
1077 GEOM::GEOM_Object_var aGroupMainShape;
1078 if (aGeomGroup->GetType() == 37)
1079 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1081 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1082 _PTR(SObject) aGroupMainShapeSO =
1083 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1084 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1086 _PTR(SObject) anObj, aRef;
1087 bool isRefOrSubShape = false;
1088 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1089 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1090 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1091 isRefOrSubShape = true;
1093 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1094 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1095 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1096 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1097 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1098 if (aRef->GetID() == aFather->GetID())
1099 isRefOrSubShape = true;
1101 aFather = aFather->GetFather();
1105 if (isRefOrSubShape)
1106 myGeomObjects[i++] = aGeomGroup;
1109 myGeomObjects->length(i);
1121 if(myCurrentLineEdit == mySubMeshLine)
1122 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1123 else if(myCurrentLineEdit == myGroupLine)
1124 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1125 else if(myCurrentLineEdit == myGeomGroupLine)
1126 aString = tr("%1 Objects").arg(aNbSel);
1128 aString = aList.First()->getName();
1132 myCurrentLineEdit->setText(aString);
1133 myOldName = myName->text();
1134 myName->setText(aString);
1135 myCurrentLineEdit->home(false);
1140 if (aNbSel == 1 && myActor ) {
1141 QString aListStr = "";
1143 if (myTypeId == 0) {
1144 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1146 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1149 QStringList anElements = aListStr.split(" ", QString::SkipEmptyParts);
1150 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1151 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1152 QListWidgetItem* anItem;
1153 foreach(anItem, found) anItem->setSelected(true);
1160 if (!myGroup->_is_nil())
1161 myActor = SMESH::FindActorByObject(myGroup);
1162 else if(!myGroupOnGeom->_is_nil())
1163 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1165 myActor = SMESH::FindActorByObject(myMesh);
1171 //=================================================================================
1172 // function : onSelectSubMesh()
1173 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1174 //=================================================================================
1175 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1178 if (mySelectGroup->isChecked()) {
1179 mySelectGroup->setChecked(false);
1181 //VSR: else if (mySelectGeomGroup->isChecked()) {
1182 //VSR: mySelectGeomGroup->setChecked(false);
1184 myCurrentLineEdit = mySubMeshLine;
1185 setSelectionMode(4);
1188 mySubMeshLine->setText("");
1189 myCurrentLineEdit = 0;
1191 setSelectionMode(myTypeId);
1193 mySubMeshBtn->setEnabled(on);
1194 mySubMeshLine->setEnabled(on);
1198 //=================================================================================
1199 // function : (onSelectGroup)
1200 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1201 //=================================================================================
1202 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1205 if (mySelectSubMesh->isChecked()) {
1206 mySelectSubMesh->setChecked(false);
1208 myCurrentLineEdit = myGroupLine;
1209 setSelectionMode(5);
1212 myGroupLine->setText("");
1213 myCurrentLineEdit = 0;
1215 setSelectionMode(myTypeId);
1217 myGroupBtn->setEnabled(on);
1218 myGroupLine->setEnabled(on);
1222 //=================================================================================
1223 // function : (onSelectGeomGroup)
1224 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1225 //=================================================================================
1226 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1229 if (mySelectSubMesh->isChecked()) {
1230 mySelectSubMesh->setChecked(false);
1232 else if (mySelectGroup->isChecked()) {
1233 mySelectGroup->setChecked(false);
1235 myCurrentLineEdit = myGeomGroupLine;
1237 setSelectionMode(8);
1240 myGeomGroupBtn->setDown(false);
1241 myGeomObjects->length(0);
1242 myGeomGroupLine->setText("");
1243 myCurrentLineEdit = 0;
1245 setSelectionMode(myTypeId);
1250 //=================================================================================
1251 // function : setCurrentSelection()
1253 //=================================================================================
1254 void SMESHGUI_GroupDlg::setCurrentSelection()
1256 QPushButton* send = (QPushButton*)sender();
1257 myCurrentLineEdit = 0;
1258 if (send == myMeshGroupBtn) {
1259 myCurrentLineEdit = myMeshGroupLine;
1261 setSelectionMode(6);
1263 setSelectionMode(5);
1264 onObjectSelectionChanged();
1266 else if (send == mySubMeshBtn) {
1267 myCurrentLineEdit = mySubMeshLine;
1268 onObjectSelectionChanged();
1270 else if (send == myGroupBtn) {
1271 myCurrentLineEdit = myGroupLine;
1272 onObjectSelectionChanged();
1277 //=================================================================================
1278 // function : setFilters()
1279 // purpose : SLOT. Called when "Filter" button pressed.
1280 //=================================================================================
1281 void SMESHGUI_GroupDlg::setFilters()
1283 SMESH::ElementType aType = SMESH::ALL;
1286 case 0 : aType = SMESH::NODE; break;
1287 case 1 : aType = SMESH::EDGE; break;
1288 case 2 : aType = SMESH::FACE; break;
1289 case 3 : aType = SMESH::VOLUME; break;
1293 if ( myFilterDlg == 0 )
1295 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1296 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1299 myFilterDlg->Init( aType );
1301 myFilterDlg->SetSelection();
1302 myFilterDlg->SetMesh( myMesh );
1303 myFilterDlg->SetSourceWg( myElements );
1305 myFilterDlg->show();
1308 //=================================================================================
1309 // function : onFilterAccepted()
1310 // purpose : SLOT. Called when Filter dlg closed with OK button.
1311 // Uncheck "Select submesh" and "Select group" checkboxes
1312 //=================================================================================
1313 void SMESHGUI_GroupDlg::onFilterAccepted()
1315 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1317 mySelectionMode = myTypeId;
1318 mySelectSubMesh->setChecked( false );
1319 mySelectGroup->setChecked( false );
1323 //=================================================================================
1324 // function : onAdd()
1326 //=================================================================================
1327 void SMESHGUI_GroupDlg::onAdd()
1329 SALOME_ListIO aList;
1330 mySelectionMgr->selectedObjects( aList );
1332 int aNbSel = aList.Extent();
1334 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1338 SMESH::ElementType aType = SMESH::ALL;
1341 aType = SMESH::NODE;
1342 mySelector->SetSelectionMode(NodeSelection);
1345 aType = SMESH::EDGE;
1346 mySelector->SetSelectionMode(EdgeSelection);
1349 aType = SMESH::FACE;
1350 mySelector->SetSelectionMode(FaceSelection);
1353 aType = SMESH::VOLUME;
1354 mySelector->SetSelectionMode(VolumeSelection);
1357 mySelector->SetSelectionMode(ActorSelection);
1361 if (myCurrentLineEdit == 0) {
1362 //if (aNbSel != 1) { myIsBusy = false; return; }
1363 QString aListStr = "";
1365 if (myTypeId == 0) {
1366 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1369 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1372 QStringList anElements = aListStr.split(" ", QString::SkipEmptyParts);
1373 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1374 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1375 QListWidgetItem* anItem;
1376 if (found.count() == 0) {
1377 anItem = new QListWidgetItem(*it);
1378 myElements->addItem(anItem);
1379 anItem->setSelected(true);
1382 foreach(anItem, found) anItem->setSelected(true);
1386 } else if (myCurrentLineEdit == mySubMeshLine) {
1387 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1389 SALOME_ListIO aList;
1390 mySelectionMgr->selectedObjects( aList );
1392 SALOME_ListIteratorOfListIO anIt (aList);
1393 for ( ; anIt.More(); anIt.Next()) {
1394 SMESH::SMESH_subMesh_var aSubMesh =
1395 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1396 if (!aSubMesh->_is_nil()) {
1397 // check if mesh is the same
1398 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1400 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1401 int k = anElements->length();
1402 for (int i = 0; i < k; i++) {
1403 QString aText = QString::number(anElements[i]);
1404 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1405 QListWidgetItem* anItem = 0;
1406 if (found.count() == 0) {
1407 anItem = new QListWidgetItem(aText);
1408 myElements->addItem(anItem);
1409 anItem->setSelected(true);
1412 foreach(anItem, found) anItem->setSelected(true);
1416 catch (const SALOME::SALOME_Exception& ex) {
1417 SalomeApp_Tools::QtCatchCorbaException(ex);
1422 mySelectSubMesh->setChecked(false);
1424 onListSelectionChanged();
1426 } else if (myCurrentLineEdit == myGroupLine) {
1427 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1428 SALOME_ListIO aList;
1429 mySelectionMgr->selectedObjects( aList );
1431 SALOME_ListIteratorOfListIO anIt (aList);
1432 for ( ; anIt.More(); anIt.Next()) {
1433 SMESH::SMESH_Group_var aGroup =
1434 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1435 if (!aGroup->_is_nil()) {
1436 // check if mesh is the same
1437 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1438 SMESH::long_array_var anElements = aGroup->GetListOfID();
1439 int k = anElements->length();
1440 for (int i = 0; i < k; i++) {
1441 QString aText = QString::number(anElements[i]);
1442 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1443 QListWidgetItem* anItem = 0;
1444 if (found.count() == 0) {
1445 anItem = new QListWidgetItem(aText);
1446 myElements->addItem(anItem);
1447 anItem->setSelected(true);
1450 foreach(anItem, found) anItem->setSelected(true);
1456 mySelectGroup->setChecked(false);
1458 onListSelectionChanged();
1460 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1461 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1462 GEOM::GEOM_IGroupOperations_var aGroupOp =
1463 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1465 SMESH::ElementType aGroupType = SMESH::ALL;
1466 switch(aGroupOp->GetType(myGeomObjects[0])) {
1467 case 7: aGroupType = SMESH::NODE; break;
1468 case 6: aGroupType = SMESH::EDGE; break;
1469 case 4: aGroupType = SMESH::FACE; break;
1470 case 2: aGroupType = SMESH::VOLUME; break;
1471 default: myIsBusy = false; return;
1474 if (aGroupType == aType) {
1475 _PTR(SObject) aGroupSO =
1476 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1477 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1479 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1480 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1481 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1482 aBelongToGeom->SetGeom(myGeomObjects[0]);
1483 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1484 aBelongToGeom->SetElementType(aType);
1485 aFilter->SetPredicate(aBelongToGeom);
1487 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1489 int k = anElements->length();
1490 for (int i = 0; i < k; i++) {
1491 QString aText = QString::number(anElements[i]);
1492 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1493 QListWidgetItem* anItem = 0;
1494 if (found.count() == 0) {
1495 anItem = new QListWidgetItem(aText);
1496 myElements->addItem(anItem);
1497 anItem->setSelected(true);
1500 foreach(anItem, found) anItem->setSelected(true);
1505 //VSR: mySelectGeomGroup->setChecked(false);
1507 onListSelectionChanged();
1510 // mySelectionMgr->clearSelected();
1514 //=================================================================================
1515 // function : onRemove()
1517 //=================================================================================
1518 void SMESHGUI_GroupDlg::onRemove()
1521 if (myCurrentLineEdit == 0) {
1522 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1523 QListWidgetItem* item;
1524 foreach(item, selItems) delete item;
1526 SALOME_ListIO aList;
1527 mySelectionMgr->selectedObjects( aList );
1529 int aNbSel = aList.Extent();
1531 if (aNbSel == 0) { myIsBusy = false; return; }
1533 SMESH::ElementType aType = SMESH::ALL;
1535 case 0: aType = SMESH::NODE; break;
1536 case 1: aType = SMESH::EDGE; break;
1537 case 2: aType = SMESH::FACE; break;
1538 case 3: aType = SMESH::VOLUME; break;
1541 if (myCurrentLineEdit == mySubMeshLine) {
1542 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1543 SALOME_ListIO aList;
1544 mySelectionMgr->selectedObjects( aList );
1546 SALOME_ListIteratorOfListIO anIt (aList);
1547 for ( ; anIt.More(); anIt.Next()) {
1548 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1549 if (!aSubMesh->_is_nil()) {
1550 // check if mesh is the same
1551 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1552 if (aType == SMESH::NODE) {
1554 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1555 int k = anElements->length();
1556 for (int i = 0; i < k; i++) {
1557 QList<QListWidgetItem*> found =
1558 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1559 QListWidgetItem* anItem;
1560 foreach(anItem, found) delete anItem;
1563 catch (const SALOME::SALOME_Exception& ex) {
1564 SalomeApp_Tools::QtCatchCorbaException(ex);
1569 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1570 int k = anElements->length();
1571 for (int i = 0; i < k; i++) {
1572 QList<QListWidgetItem*> found =
1573 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1574 QListWidgetItem* anItem;
1575 foreach(anItem, found) delete anItem;
1578 catch (const SALOME::SALOME_Exception& ex) {
1579 SalomeApp_Tools::QtCatchCorbaException(ex);
1586 else if (myCurrentLineEdit == myGroupLine) {
1587 Standard_Boolean aRes;
1588 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1589 SALOME_ListIO aList;
1590 mySelectionMgr->selectedObjects( aList );
1592 SALOME_ListIteratorOfListIO anIt (aList);
1593 for ( ; anIt.More(); anIt.Next()) {
1594 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1595 if (aRes && !aGroup->_is_nil()) {
1596 // check if mesh is the same
1597 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1598 SMESH::long_array_var anElements = aGroup->GetListOfID();
1599 int k = anElements->length();
1600 for (int i = 0; i < k; i++) {
1601 QList<QListWidgetItem*> found =
1602 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1603 QListWidgetItem* anItem;
1604 foreach(anItem, found) delete anItem;
1615 //=================================================================================
1616 // function : onSort()
1618 //=================================================================================
1619 void SMESHGUI_GroupDlg::onSort()
1621 // PAL5412: sorts items in ascending by "string" value
1622 // myElements->sort(true);
1623 // myElements->update();
1624 int i, k = myElements->count();
1627 QList<int> aSelected;
1628 std::vector<int> anArray(k);
1629 // QMemArray<int> anArray(k);
1631 for (i = 0; i < k; i++) {
1632 int id = myElements->item(i)->text().toInt();
1634 if (myElements->item(i)->isSelected())
1635 aSelected.append(id);
1637 // sort & update list
1638 std::sort(anArray.begin(), anArray.end());
1640 myElements->clear();
1641 for (i = 0; i < k; i++) {
1642 QListWidgetItem* anItem = new QListWidgetItem(QString::number(anArray[i]));
1643 myElements->addItem(anItem);
1644 anItem->setSelected(aSelected.contains(anArray[i]));
1650 //=================================================================================
1651 // function : closeEvent()
1653 //=================================================================================
1654 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1659 //=================================================================================
1660 // function : SMESHGUI_GroupDlg::onClose
1661 // purpose : SLOT called when "Close" button pressed. Close dialog
1662 //=================================================================================
1663 void SMESHGUI_GroupDlg::onClose()
1665 if (SMESH::GetCurrentVtkView()) {
1666 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1667 SMESH::SetPointRepresentation(false);
1668 SMESH::SetPickable();
1671 mySelectionMgr->clearSelected();
1672 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1673 aViewWindow->SetSelectionMode(ActorSelection);
1674 mySelectionMgr->clearFilters();
1675 mySMESHGUI->ResetState();
1680 //=================================================================================
1681 // function : onHelp()
1683 //=================================================================================
1684 void SMESHGUI_GroupDlg::onHelp()
1686 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1688 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1692 platform = "winapplication";
1694 platform = "application";
1696 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
1697 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1698 arg(app->resourceMgr()->stringValue("ExternalBrowser",
1700 arg(myHelpFileName));
1704 //=================================================================================
1705 // function : SMESHGUI_GroupDlg::onDeactivate
1706 // purpose : SLOT called when dialog must be deativated
1707 //=================================================================================
1708 void SMESHGUI_GroupDlg::onDeactivate()
1710 mySMESHGUI->ResetState();
1714 //=================================================================================
1715 // function : SMESHGUI_GroupDlg::enterEvent
1716 // purpose : Event filter
1717 //=================================================================================
1718 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1721 mySMESHGUI->EmitSignalDeactivateDialog();
1723 mySelectionMode = -1;
1724 setSelectionMode(myTypeId);
1725 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1726 mySMESHGUI->SetActiveDialogBox(this);
1727 mySMESHGUI->SetState(800);
1731 //=================================================================================
1732 // function : hideEvent
1733 // purpose : caused by ESC key
1734 //=================================================================================
1735 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1737 if (!isMinimized() && !myIsBusy)
1741 //=================================================================================
1742 // function : keyPressEvent()
1744 //=================================================================================
1745 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1747 QDialog::keyPressEvent( e );
1748 if ( e->isAccepted() )
1751 if ( e->key() == Qt::Key_F1 )
1758 //================================================================================
1760 * \brief Enable showing of the popup when Geometry selection btn is clicked
1761 * \param enable - true to enable
1763 //================================================================================
1765 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1767 void SMESHGUI_GroupDlg::updateGeomPopup()
1769 bool enable = false;
1771 if ( !myMesh->_is_nil() )
1772 enable = myMesh->NbEdges() > 0;
1774 if ( myGeomGroupBtn )
1776 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1778 if ( !myGeomPopup ) {
1779 myGeomPopup = new QMenu(this);
1780 myActions[myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )] = DIRECT_GEOM_INDEX;
1781 myActions[myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )] = GEOM_BY_MESH_INDEX;
1782 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
1784 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1790 //=================================================================================
1791 // function : onGeomSelectionButton()
1793 //=================================================================================
1794 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1796 if ( myGeomPopup && isBtnOn )
1798 myCurrentLineEdit = myGeomGroupLine;
1799 QAction* a = myGeomPopup->exec( QCursor::pos() );
1800 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
1801 setSelectionMode(7);
1805 myCurrentLineEdit = 0;
1806 setSelectionMode(8);
1810 //=================================================================================
1811 // function : onGeomPopup()
1813 //=================================================================================
1814 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
1816 int index = myActions[a];
1817 if ( index == GEOM_BY_MESH_INDEX )
1819 mySelectionMode = -1;
1820 if ( !myShapeByMeshOp ) {
1821 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1822 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1823 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1824 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1825 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1827 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1828 if ( !myMesh->_is_nil() ) {
1830 hide(); // stop processing selection
1832 myShapeByMeshOp->setModule( mySMESHGUI );
1833 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1834 myShapeByMeshOp->SetMesh( myMesh );
1835 myShapeByMeshOp->start();
1840 //================================================================================
1842 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1844 //================================================================================
1846 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1848 if ( myShapeByMeshOp == op ) {
1849 mySMESHGUI->getApp()->updateObjectBrowser();
1851 // Select a found geometry object
1852 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1853 if ( !aGeomVar->_is_nil() )
1855 QString ID = aGeomVar->GetStudyEntry();
1856 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1857 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
1858 SALOME_ListIO anIOList;
1859 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1860 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1861 anIOList.Append( anIO );
1862 mySelectionMgr->setSelectedObjects( anIOList, false );
1863 onObjectSelectionChanged();
1869 //================================================================================
1871 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1873 //================================================================================
1875 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1877 if ( myShapeByMeshOp == op )
1880 setSelectionMode(7);
1884 //=================================================================================
1885 // function : setGroupColor()
1887 //=================================================================================
1888 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
1890 QColor aQColor( (int)( theColor.R * 255.0 ),
1891 (int)( theColor.G * 255.0 ),
1892 (int)( theColor.B * 255.0 ) );
1893 setGroupQColor( aQColor );
1896 //=================================================================================
1897 // function : getGroupColor()
1899 //=================================================================================
1900 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
1902 QColor aQColor = getGroupQColor();
1904 SALOMEDS::Color aColor;
1905 aColor.R = (float)aQColor.red() / 255.0;
1906 aColor.G = (float)aQColor.green() / 255.0;
1907 aColor.B = (float)aQColor.blue() / 255.0;
1912 //=================================================================================
1913 // function : setGroupQColor()
1915 //=================================================================================
1916 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
1918 if( theColor.isValid() )
1919 myColorBtn->setColor( theColor );
1922 //=================================================================================
1923 // function : getGroupQColor()
1925 //=================================================================================
1926 QColor SMESHGUI_GroupDlg::getGroupQColor() const
1928 return myColorBtn->color();
1931 //=================================================================================
1932 // function : setDefaultGroupColor()
1934 //=================================================================================
1935 void SMESHGUI_GroupDlg::setDefaultGroupColor()
1937 if( myMesh->_is_nil() )
1940 bool isAutoColor = myMesh->GetAutoColor();
1945 int r = 0, g = 0, b = 0;
1946 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
1947 aQColor.setRgb( r, g, b );
1951 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
1953 QList<SALOMEDS::Color> aReservedColors;
1954 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1956 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1957 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
1958 aReservedColors.append( aReservedColor );
1961 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1962 aQColor.setRgb( (int)( aColor.R * 255.0 ),
1963 (int)( aColor.G * 255.0 ),
1964 (int)( aColor.B * 255.0 ) );
1968 setGroupQColor( aQColor );