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 QListWidgetItem* anItem;
1150 QList<QListWidgetItem*> listItemsToSel;
1151 QStringList anElements = aListStr.split(" ", QString::SkipEmptyParts);
1152 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1153 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1154 foreach(anItem, found)
1155 if (!anItem->isSelected())
1156 listItemsToSel.push_back(anItem);
1158 bool blocked = myElements->signalsBlocked();
1159 myElements->blockSignals(true);
1160 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1161 myElements->blockSignals(blocked);
1162 onListSelectionChanged();
1163 listItemsToSel.clear();
1169 if (!myGroup->_is_nil())
1170 myActor = SMESH::FindActorByObject(myGroup);
1171 else if(!myGroupOnGeom->_is_nil())
1172 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1174 myActor = SMESH::FindActorByObject(myMesh);
1180 //=================================================================================
1181 // function : onSelectSubMesh()
1182 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1183 //=================================================================================
1184 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1187 if (mySelectGroup->isChecked()) {
1188 mySelectGroup->setChecked(false);
1190 //VSR: else if (mySelectGeomGroup->isChecked()) {
1191 //VSR: mySelectGeomGroup->setChecked(false);
1193 myCurrentLineEdit = mySubMeshLine;
1194 setSelectionMode(4);
1197 mySubMeshLine->setText("");
1198 myCurrentLineEdit = 0;
1200 setSelectionMode(myTypeId);
1202 mySubMeshBtn->setEnabled(on);
1203 mySubMeshLine->setEnabled(on);
1207 //=================================================================================
1208 // function : (onSelectGroup)
1209 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1210 //=================================================================================
1211 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1214 if (mySelectSubMesh->isChecked()) {
1215 mySelectSubMesh->setChecked(false);
1217 myCurrentLineEdit = myGroupLine;
1218 setSelectionMode(5);
1221 myGroupLine->setText("");
1222 myCurrentLineEdit = 0;
1224 setSelectionMode(myTypeId);
1226 myGroupBtn->setEnabled(on);
1227 myGroupLine->setEnabled(on);
1231 //=================================================================================
1232 // function : (onSelectGeomGroup)
1233 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1234 //=================================================================================
1235 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1238 if (mySelectSubMesh->isChecked()) {
1239 mySelectSubMesh->setChecked(false);
1241 else if (mySelectGroup->isChecked()) {
1242 mySelectGroup->setChecked(false);
1244 myCurrentLineEdit = myGeomGroupLine;
1246 setSelectionMode(8);
1249 myGeomGroupBtn->setDown(false);
1250 myGeomObjects->length(0);
1251 myGeomGroupLine->setText("");
1252 myCurrentLineEdit = 0;
1254 setSelectionMode(myTypeId);
1259 //=================================================================================
1260 // function : setCurrentSelection()
1262 //=================================================================================
1263 void SMESHGUI_GroupDlg::setCurrentSelection()
1265 QPushButton* send = (QPushButton*)sender();
1266 myCurrentLineEdit = 0;
1267 if (send == myMeshGroupBtn) {
1268 myCurrentLineEdit = myMeshGroupLine;
1270 setSelectionMode(6);
1272 setSelectionMode(5);
1273 onObjectSelectionChanged();
1275 else if (send == mySubMeshBtn) {
1276 myCurrentLineEdit = mySubMeshLine;
1277 onObjectSelectionChanged();
1279 else if (send == myGroupBtn) {
1280 myCurrentLineEdit = myGroupLine;
1281 onObjectSelectionChanged();
1286 //=================================================================================
1287 // function : setFilters()
1288 // purpose : SLOT. Called when "Filter" button pressed.
1289 //=================================================================================
1290 void SMESHGUI_GroupDlg::setFilters()
1292 SMESH::ElementType aType = SMESH::ALL;
1295 case 0 : aType = SMESH::NODE; break;
1296 case 1 : aType = SMESH::EDGE; break;
1297 case 2 : aType = SMESH::FACE; break;
1298 case 3 : aType = SMESH::VOLUME; break;
1302 if ( myFilterDlg == 0 )
1304 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1305 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1308 myFilterDlg->Init( aType );
1310 myFilterDlg->SetSelection();
1311 myFilterDlg->SetMesh( myMesh );
1312 myFilterDlg->SetSourceWg( myElements );
1314 myFilterDlg->show();
1317 //=================================================================================
1318 // function : onFilterAccepted()
1319 // purpose : SLOT. Called when Filter dlg closed with OK button.
1320 // Uncheck "Select submesh" and "Select group" checkboxes
1321 //=================================================================================
1322 void SMESHGUI_GroupDlg::onFilterAccepted()
1324 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1326 mySelectionMode = myTypeId;
1327 mySelectSubMesh->setChecked( false );
1328 mySelectGroup->setChecked( false );
1332 //=================================================================================
1333 // function : onAdd()
1335 //=================================================================================
1336 void SMESHGUI_GroupDlg::onAdd()
1338 SALOME_ListIO aList;
1339 mySelectionMgr->selectedObjects( aList );
1341 int aNbSel = aList.Extent();
1343 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1347 SMESH::ElementType aType = SMESH::ALL;
1350 aType = SMESH::NODE;
1351 mySelector->SetSelectionMode(NodeSelection);
1354 aType = SMESH::EDGE;
1355 mySelector->SetSelectionMode(EdgeSelection);
1358 aType = SMESH::FACE;
1359 mySelector->SetSelectionMode(FaceSelection);
1362 aType = SMESH::VOLUME;
1363 mySelector->SetSelectionMode(VolumeSelection);
1366 mySelector->SetSelectionMode(ActorSelection);
1369 QListWidgetItem* anItem = 0;
1370 QList<QListWidgetItem*> listItemsToSel;
1372 if (myCurrentLineEdit == 0) {
1373 //if (aNbSel != 1) { myIsBusy = false; return; }
1374 QString aListStr = "";
1376 if (myTypeId == 0) {
1377 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1380 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1383 QStringList anElements = aListStr.split(" ", QString::SkipEmptyParts);
1384 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1385 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1386 if (found.count() == 0) {
1387 anItem = new QListWidgetItem(*it);
1388 myElements->addItem(anItem);
1389 if (!anItem->isSelected())
1390 listItemsToSel.push_back(anItem);
1393 foreach(anItem, found)
1394 if (!anItem->isSelected())
1395 listItemsToSel.push_back(anItem);
1398 bool blocked = myElements->signalsBlocked();
1399 myElements->blockSignals(true);
1400 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1401 myElements->blockSignals(blocked);
1402 onListSelectionChanged();
1403 listItemsToSel.clear();
1405 } else if (myCurrentLineEdit == mySubMeshLine) {
1406 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1408 SALOME_ListIO aList;
1409 mySelectionMgr->selectedObjects( aList );
1411 SALOME_ListIteratorOfListIO anIt (aList);
1412 for ( ; anIt.More(); anIt.Next()) {
1413 SMESH::SMESH_subMesh_var aSubMesh =
1414 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1415 if (!aSubMesh->_is_nil()) {
1416 // check if mesh is the same
1417 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1419 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1420 int k = anElements->length();
1421 for (int i = 0; i < k; i++) {
1422 QString aText = QString::number(anElements[i]);
1423 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1424 if (found.count() == 0) {
1425 anItem = new QListWidgetItem(aText);
1426 myElements->addItem(anItem);
1427 if (!anItem->isSelected())
1428 listItemsToSel.push_back(anItem);
1431 foreach(anItem, found)
1432 if (!anItem->isSelected())
1433 listItemsToSel.push_back(anItem);
1436 bool blocked = myElements->signalsBlocked();
1437 myElements->blockSignals(true);
1438 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1439 myElements->blockSignals(blocked);
1440 onListSelectionChanged();
1441 listItemsToSel.clear();
1443 catch (const SALOME::SALOME_Exception& ex) {
1444 SalomeApp_Tools::QtCatchCorbaException(ex);
1449 mySelectSubMesh->setChecked(false);
1451 onListSelectionChanged();
1453 } else if (myCurrentLineEdit == myGroupLine) {
1454 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1455 SALOME_ListIO aList;
1456 mySelectionMgr->selectedObjects( aList );
1458 SALOME_ListIteratorOfListIO anIt (aList);
1459 for ( ; anIt.More(); anIt.Next()) {
1460 SMESH::SMESH_Group_var aGroup =
1461 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1462 if (!aGroup->_is_nil()) {
1463 // check if mesh is the same
1464 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1465 SMESH::long_array_var anElements = aGroup->GetListOfID();
1466 int k = anElements->length();
1467 for (int i = 0; i < k; i++) {
1468 QString aText = QString::number(anElements[i]);
1469 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1470 if (found.count() == 0) {
1471 anItem = new QListWidgetItem(aText);
1472 myElements->addItem(anItem);
1473 if (!anItem->isSelected())
1474 listItemsToSel.push_back(anItem);
1477 foreach(anItem, found)
1478 if (!anItem->isSelected())
1479 listItemsToSel.push_back(anItem);
1482 bool blocked = myElements->signalsBlocked();
1483 myElements->blockSignals(true);
1484 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1485 myElements->blockSignals(blocked);
1486 onListSelectionChanged();
1487 listItemsToSel.clear();
1491 mySelectGroup->setChecked(false);
1493 onListSelectionChanged();
1495 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1496 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1497 GEOM::GEOM_IGroupOperations_var aGroupOp =
1498 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1500 SMESH::ElementType aGroupType = SMESH::ALL;
1501 switch(aGroupOp->GetType(myGeomObjects[0])) {
1502 case 7: aGroupType = SMESH::NODE; break;
1503 case 6: aGroupType = SMESH::EDGE; break;
1504 case 4: aGroupType = SMESH::FACE; break;
1505 case 2: aGroupType = SMESH::VOLUME; break;
1506 default: myIsBusy = false; return;
1509 if (aGroupType == aType) {
1510 _PTR(SObject) aGroupSO =
1511 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1512 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1514 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1515 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1516 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1517 aBelongToGeom->SetGeom(myGeomObjects[0]);
1518 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1519 aBelongToGeom->SetElementType(aType);
1520 aFilter->SetPredicate(aBelongToGeom);
1522 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1524 int k = anElements->length();
1525 for (int i = 0; i < k; i++) {
1526 QString aText = QString::number(anElements[i]);
1527 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1528 if (found.count() == 0) {
1529 anItem = new QListWidgetItem(aText);
1530 myElements->addItem(anItem);
1531 if (!anItem->isSelected())
1532 listItemsToSel.push_back(anItem);
1535 foreach(anItem, found)
1536 if (!anItem->isSelected())
1537 listItemsToSel.push_back(anItem);
1540 bool blocked = myElements->signalsBlocked();
1541 myElements->blockSignals(true);
1542 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1543 myElements->blockSignals(blocked);
1544 onListSelectionChanged();
1545 listItemsToSel.clear();
1548 //VSR: mySelectGeomGroup->setChecked(false);
1550 onListSelectionChanged();
1553 // mySelectionMgr->clearSelected();
1557 //=================================================================================
1558 // function : onRemove()
1560 //=================================================================================
1561 void SMESHGUI_GroupDlg::onRemove()
1564 if (myCurrentLineEdit == 0) {
1565 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1566 QListWidgetItem* item;
1567 foreach(item, selItems) delete item;
1569 SALOME_ListIO aList;
1570 mySelectionMgr->selectedObjects( aList );
1572 int aNbSel = aList.Extent();
1574 if (aNbSel == 0) { myIsBusy = false; return; }
1576 SMESH::ElementType aType = SMESH::ALL;
1578 case 0: aType = SMESH::NODE; break;
1579 case 1: aType = SMESH::EDGE; break;
1580 case 2: aType = SMESH::FACE; break;
1581 case 3: aType = SMESH::VOLUME; break;
1584 if (myCurrentLineEdit == mySubMeshLine) {
1585 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1586 SALOME_ListIO aList;
1587 mySelectionMgr->selectedObjects( aList );
1589 SALOME_ListIteratorOfListIO anIt (aList);
1590 for ( ; anIt.More(); anIt.Next()) {
1591 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1592 if (!aSubMesh->_is_nil()) {
1593 // check if mesh is the same
1594 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1595 if (aType == SMESH::NODE) {
1597 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1598 int k = anElements->length();
1599 for (int i = 0; i < k; i++) {
1600 QList<QListWidgetItem*> found =
1601 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1602 QListWidgetItem* anItem;
1603 foreach(anItem, found) delete anItem;
1606 catch (const SALOME::SALOME_Exception& ex) {
1607 SalomeApp_Tools::QtCatchCorbaException(ex);
1612 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1613 int k = anElements->length();
1614 for (int i = 0; i < k; i++) {
1615 QList<QListWidgetItem*> found =
1616 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1617 QListWidgetItem* anItem;
1618 foreach(anItem, found) delete anItem;
1621 catch (const SALOME::SALOME_Exception& ex) {
1622 SalomeApp_Tools::QtCatchCorbaException(ex);
1629 else if (myCurrentLineEdit == myGroupLine) {
1630 Standard_Boolean aRes;
1631 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1632 SALOME_ListIO aList;
1633 mySelectionMgr->selectedObjects( aList );
1635 SALOME_ListIteratorOfListIO anIt (aList);
1636 for ( ; anIt.More(); anIt.Next()) {
1637 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1638 if (aRes && !aGroup->_is_nil()) {
1639 // check if mesh is the same
1640 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1641 SMESH::long_array_var anElements = aGroup->GetListOfID();
1642 int k = anElements->length();
1643 for (int i = 0; i < k; i++) {
1644 QList<QListWidgetItem*> found =
1645 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1646 QListWidgetItem* anItem;
1647 foreach(anItem, found) delete anItem;
1658 //=================================================================================
1659 // function : onSort()
1661 //=================================================================================
1662 void SMESHGUI_GroupDlg::onSort()
1664 // PAL5412: sorts items in ascending by "string" value
1665 // myElements->sort(true);
1666 // myElements->update();
1667 int i, k = myElements->count();
1670 QList<int> aSelected;
1671 std::vector<int> anArray(k);
1672 // QMemArray<int> anArray(k);
1674 for (i = 0; i < k; i++) {
1675 int id = myElements->item(i)->text().toInt();
1677 if (myElements->item(i)->isSelected())
1678 aSelected.append(id);
1680 // sort & update list
1681 std::sort(anArray.begin(), anArray.end());
1683 myElements->clear();
1684 QListWidgetItem* anItem;
1685 QList<QListWidgetItem*> listItemsToSel;
1686 for (i = 0; i < k; i++) {
1687 anItem = new QListWidgetItem(QString::number(anArray[i]));
1688 myElements->addItem(anItem);
1689 if (aSelected.contains(anArray[i]))
1690 listItemsToSel.push_back(anItem);
1692 bool blocked = myElements->signalsBlocked();
1693 myElements->blockSignals(true);
1694 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1695 myElements->blockSignals(blocked);
1696 listItemsToSel.clear();
1701 //=================================================================================
1702 // function : closeEvent()
1704 //=================================================================================
1705 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1710 //=================================================================================
1711 // function : SMESHGUI_GroupDlg::onClose
1712 // purpose : SLOT called when "Close" button pressed. Close dialog
1713 //=================================================================================
1714 void SMESHGUI_GroupDlg::onClose()
1716 if (SMESH::GetCurrentVtkView()) {
1717 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1718 SMESH::SetPointRepresentation(false);
1719 SMESH::SetPickable();
1722 mySelectionMgr->clearSelected();
1723 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1724 aViewWindow->SetSelectionMode(ActorSelection);
1725 mySelectionMgr->clearFilters();
1726 mySMESHGUI->ResetState();
1731 //=================================================================================
1732 // function : onHelp()
1734 //=================================================================================
1735 void SMESHGUI_GroupDlg::onHelp()
1737 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1739 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1743 platform = "winapplication";
1745 platform = "application";
1747 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
1748 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1749 arg(app->resourceMgr()->stringValue("ExternalBrowser",
1751 arg(myHelpFileName));
1755 //=================================================================================
1756 // function : SMESHGUI_GroupDlg::onDeactivate
1757 // purpose : SLOT called when dialog must be deativated
1758 //=================================================================================
1759 void SMESHGUI_GroupDlg::onDeactivate()
1761 mySMESHGUI->ResetState();
1765 //=================================================================================
1766 // function : SMESHGUI_GroupDlg::enterEvent
1767 // purpose : Event filter
1768 //=================================================================================
1769 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1772 mySMESHGUI->EmitSignalDeactivateDialog();
1774 mySelectionMode = -1;
1775 setSelectionMode(myTypeId);
1776 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1777 mySMESHGUI->SetActiveDialogBox(this);
1778 mySMESHGUI->SetState(800);
1782 //=================================================================================
1783 // function : hideEvent
1784 // purpose : caused by ESC key
1785 //=================================================================================
1786 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1788 if (!isMinimized() && !myIsBusy)
1792 //=================================================================================
1793 // function : keyPressEvent()
1795 //=================================================================================
1796 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1798 QDialog::keyPressEvent( e );
1799 if ( e->isAccepted() )
1802 if ( e->key() == Qt::Key_F1 )
1809 //================================================================================
1811 * \brief Enable showing of the popup when Geometry selection btn is clicked
1812 * \param enable - true to enable
1814 //================================================================================
1816 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1818 void SMESHGUI_GroupDlg::updateGeomPopup()
1820 bool enable = false;
1822 if ( !myMesh->_is_nil() )
1823 enable = myMesh->NbEdges() > 0;
1825 if ( myGeomGroupBtn )
1827 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1829 if ( !myGeomPopup ) {
1830 myGeomPopup = new QMenu(this);
1831 myActions[myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )] = DIRECT_GEOM_INDEX;
1832 myActions[myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )] = GEOM_BY_MESH_INDEX;
1833 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
1835 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1841 //=================================================================================
1842 // function : onGeomSelectionButton()
1844 //=================================================================================
1845 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1847 if ( myGeomPopup && isBtnOn )
1849 myCurrentLineEdit = myGeomGroupLine;
1850 QAction* a = myGeomPopup->exec( QCursor::pos() );
1851 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
1852 setSelectionMode(7);
1856 myCurrentLineEdit = 0;
1857 setSelectionMode(8);
1861 //=================================================================================
1862 // function : onGeomPopup()
1864 //=================================================================================
1865 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
1867 int index = myActions[a];
1868 if ( index == GEOM_BY_MESH_INDEX )
1870 mySelectionMode = -1;
1871 if ( !myShapeByMeshOp ) {
1872 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1873 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1874 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1875 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1876 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1878 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1879 if ( !myMesh->_is_nil() ) {
1881 hide(); // stop processing selection
1883 myShapeByMeshOp->setModule( mySMESHGUI );
1884 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1885 myShapeByMeshOp->SetMesh( myMesh );
1886 myShapeByMeshOp->start();
1891 //================================================================================
1893 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1895 //================================================================================
1897 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1899 if ( myShapeByMeshOp == op ) {
1900 mySMESHGUI->getApp()->updateObjectBrowser();
1902 // Select a found geometry object
1903 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1904 if ( !aGeomVar->_is_nil() )
1906 QString ID = aGeomVar->GetStudyEntry();
1907 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1908 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
1909 SALOME_ListIO anIOList;
1910 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1911 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1912 anIOList.Append( anIO );
1913 mySelectionMgr->setSelectedObjects( anIOList, false );
1914 onObjectSelectionChanged();
1920 //================================================================================
1922 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1924 //================================================================================
1926 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1928 if ( myShapeByMeshOp == op )
1931 setSelectionMode(7);
1935 //=================================================================================
1936 // function : setGroupColor()
1938 //=================================================================================
1939 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
1941 QColor aQColor( (int)( theColor.R * 255.0 ),
1942 (int)( theColor.G * 255.0 ),
1943 (int)( theColor.B * 255.0 ) );
1944 setGroupQColor( aQColor );
1947 //=================================================================================
1948 // function : getGroupColor()
1950 //=================================================================================
1951 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
1953 QColor aQColor = getGroupQColor();
1955 SALOMEDS::Color aColor;
1956 aColor.R = (float)aQColor.red() / 255.0;
1957 aColor.G = (float)aQColor.green() / 255.0;
1958 aColor.B = (float)aQColor.blue() / 255.0;
1963 //=================================================================================
1964 // function : setGroupQColor()
1966 //=================================================================================
1967 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
1969 if( theColor.isValid() )
1970 myColorBtn->setColor( theColor );
1973 //=================================================================================
1974 // function : getGroupQColor()
1976 //=================================================================================
1977 QColor SMESHGUI_GroupDlg::getGroupQColor() const
1979 return myColorBtn->color();
1982 //=================================================================================
1983 // function : setDefaultGroupColor()
1985 //=================================================================================
1986 void SMESHGUI_GroupDlg::setDefaultGroupColor()
1988 if( myMesh->_is_nil() )
1991 bool isAutoColor = myMesh->GetAutoColor();
1996 int r = 0, g = 0, b = 0;
1997 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
1998 aQColor.setRgb( r, g, b );
2002 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2004 QList<SALOMEDS::Color> aReservedColors;
2005 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2007 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2008 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2009 aReservedColors.append( aReservedColor );
2012 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2013 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2014 (int)( aColor.G * 255.0 ),
2015 (int)( aColor.B * 255.0 ) );
2019 setGroupQColor( aQColor );