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);
320 aColorBoxLayout->addWidget(aColorLab);
321 aColorBoxLayout->addWidget(myColorBtn);
323 /***************************************************************/
325 QFrame* aButtons = new QFrame(this);
326 aButtons->setFrameStyle( QFrame::Box | QFrame::Sunken );
327 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons);
328 aBtnLayout->setMargin(MARGIN);
329 aBtnLayout->setSpacing(SPACING);
331 myOKBtn = new QPushButton(tr("SMESH_BUT_OK"), aButtons);
332 myOKBtn->setAutoDefault(true);
333 myOKBtn->setDefault(true);
334 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aButtons);
335 myApplyBtn->setAutoDefault(true);
336 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aButtons);
337 myCloseBtn->setAutoDefault(true);
338 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aButtons);
339 myHelpBtn->setAutoDefault(true);
341 aBtnLayout->addWidget(myOKBtn);
342 aBtnLayout->addSpacing(10);
343 aBtnLayout->addWidget(myApplyBtn);
344 aBtnLayout->addSpacing(10);
345 aBtnLayout->addStretch();
346 aBtnLayout->addWidget(myCloseBtn);
347 aBtnLayout->addWidget(myHelpBtn);
349 /***************************************************************/
350 aMainLayout->addWidget(meshGroupLab, 0, 0);
351 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
352 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
353 aMainLayout->addWidget(aTypeBox, 1, 0, 1, 3);
354 aMainLayout->addWidget(aName, 2, 0);
355 aMainLayout->addWidget(myName, 2, 2);
356 aMainLayout->addWidget(aGrpTypeBox, 3, 0, 1, 3);
357 aMainLayout->addWidget(myWGStack, 4, 0, 1, 3);
358 aMainLayout->addWidget(aColorBox, 5, 0, 1, 3);
359 aMainLayout->addWidget(aButtons, 6, 0, 1, 3);
361 /* signals and slots connections */
362 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
363 connect(myGrpTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onGrpTypeChanged(int)));
364 connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(onTypeChanged(int)));
366 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
367 connect(myElements, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged()));
369 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
370 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
371 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
372 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
374 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
375 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
376 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
377 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
378 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
380 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
381 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
382 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
383 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
386 mySMESHGUI->SetActiveDialogBox(this);
387 mySMESHGUI->SetState(800);
389 mySelectionMode = -1;
390 myMeshFilter = new SMESH_TypeFilter(MESH);
391 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
392 myGroupFilter = new SMESH_TypeFilter(GROUP);
393 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
394 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
396 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
397 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
398 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
400 rb1->setChecked(true); // VSR !!!
401 onGrpTypeChanged(0); // VSR!!!
403 if (myMesh->_is_nil() )
404 myTypeGroup->button(0)->setChecked(true);
407 //myName->setText(GetDefaultName(tr("SMESH_GROUP")));
410 //=================================================================================
411 // function : ~SMESHGUI_GroupDlg()
412 // purpose : Destroys the object and frees any allocated resources
413 //=================================================================================
414 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
416 // no need to delete child widgets, Qt does it all for us
417 if ( myFilterDlg != 0 ) {
418 myFilterDlg->setParent( 0 );
423 //=================================================================================
424 // function : GetDefaultName()
425 // purpose : Get the Group Name if Create new Group
426 //=================================================================================
427 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
431 // collect all object names of SMESH component
432 SalomeApp_Study* appStudy =
433 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
434 if ( !appStudy ) return aName;
435 _PTR(Study) aStudy = appStudy->studyDS();
437 std::set<std::string> aSet;
438 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
440 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
442 for (it->InitEx(true); it->More(); it->Next()) {
444 aSet.insert(obj->GetName());
448 // build a unique name
450 bool isUnique = false;
452 aName = theOperation + "_" + QString::number(++aNumber);
453 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
459 //=================================================================================
462 //=================================================================================
463 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
465 mySelectionMgr->installFilter(myMeshFilter);
467 /* init data from current selection */
468 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
469 myGroup = SMESH::SMESH_Group::_nil();
470 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
472 myActor = SMESH::FindActorByObject(myMesh);
473 SMESH::SetPickable(myActor);
475 setDefaultGroupColor();
478 mySelectionMgr->selectedObjects( aList );
479 if( !aList.IsEmpty() )
481 QString aName = aList.First()->getName();
482 myMeshGroupLine->setText(aName);
483 myMeshGroupLine->home( false );
486 myCurrentLineEdit = 0;
488 myTypeGroup->button(0)->setChecked(true);
492 //=================================================================================
495 //=================================================================================
496 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
498 myMesh = theGroup->GetMesh();
500 myName->setText(theGroup->GetName());
502 myOldName = myName->text();
504 SALOMEDS::Color aColor = theGroup->GetColor();
505 setGroupColor( aColor );
507 myMeshGroupLine->setText(theGroup->GetName());
510 switch(theGroup->GetType()) {
511 case SMESH::NODE: aType= 0; break;
512 case SMESH::EDGE: aType = 1; break;
513 case SMESH::FACE: aType = 2; break;
514 case SMESH::VOLUME: aType = 3; break;
516 myTypeGroup->button(aType)->setChecked(true);
518 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
520 if ( !myGroup->_is_nil() )
522 myActor = SMESH::FindActorByObject(myMesh);
524 myActor = SMESH::FindActorByObject(myGroup);
525 SMESH::SetPickable(myActor);
527 myGrpTypeGroup->button(0)->setChecked(true);
530 myCurrentLineEdit = 0;
532 setSelectionMode(aType);
536 if (!myGroup->IsEmpty()) {
537 SMESH::long_array_var anElements = myGroup->GetListOfID();
538 int k = anElements->length();
539 for (int i = 0; i < k; i++) {
540 myIdList.append(anElements[i]);
541 myElements->addItem(QString::number(anElements[i]));
543 myElements->selectAll();
548 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
550 if ( !myGroupOnGeom->_is_nil() )
552 myActor = SMESH::FindActorByObject(myMesh);
554 myActor = SMESH::FindActorByObject(myGroup);
555 SMESH::SetPickable(myActor);
557 myGrpTypeGroup->button(1)->setChecked(true);
560 QString aShapeName("");
561 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
562 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
563 if (!aGroupShape->_is_nil())
565 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
566 aShapeName = aGroupShapeSO->GetName().c_str();
568 myGeomGroupLine->setText( aShapeName );
569 myName->setText("Group On " + aShapeName);
574 //=================================================================================
575 // function : updateButtons()
577 //=================================================================================
578 void SMESHGUI_GroupDlg::updateButtons()
580 bool enable = !myName->text().trimmed().isEmpty();
582 if (myGrpTypeId == 0) {
583 enable = enable && myElements->count() > 0;
584 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
586 else if (myGrpTypeId == 1) {
587 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
588 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
592 myOKBtn->setEnabled(enable);
593 myApplyBtn->setEnabled(enable);
596 //=================================================================================
597 // function : onNameChanged()
599 //=================================================================================
600 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
605 //=================================================================================
606 // function : onTypeChanged()
607 // purpose : Group elements type radio button management
608 //=================================================================================
609 void SMESHGUI_GroupDlg::onTypeChanged (int id)
611 if (myTypeId != id) {
613 if (myCurrentLineEdit == 0)
614 setSelectionMode(id);
619 //=================================================================================
620 // function : onGrpTypeChanged()
621 // purpose : Group type radio button management
622 //=================================================================================
623 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
625 if (myGrpTypeId != id) {
626 myWGStack->setCurrentIndex( id );
628 myName->setText(myOldName);
629 onSelectGeomGroup(id == 1);
634 //=================================================================================
635 // function : setSelectionMode()
636 // purpose : Radio button management
637 //=================================================================================
638 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
641 if (myMesh->_is_nil())
643 if (mySelectionMode != theMode) {
644 // [PAL10408] mySelectionMgr->clearSelected();
645 mySelectionMgr->clearFilters();
647 myActor->SetPointRepresentation(false);
649 SMESH::SetPointRepresentation(false);
654 myActor->SetPointRepresentation(true);
656 SMESH::SetPointRepresentation(true);
657 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
658 aViewWindow->SetSelectionMode(NodeSelection);
661 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
662 aViewWindow->SetSelectionMode(EdgeSelection);
665 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
666 aViewWindow->SetSelectionMode(FaceSelection);
669 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
670 aViewWindow->SetSelectionMode(VolumeSelection);
674 mySelectionMgr->installFilter(mySubMeshFilter);
675 else if (theMode == 5)
676 mySelectionMgr->installFilter(myGroupFilter);
677 else if (theMode == 6)
678 mySelectionMgr->installFilter(myMeshFilter);
679 else if (theMode == 7)
680 mySelectionMgr->installFilter(myGeomFilter);
682 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
683 aViewWindow->SetSelectionMode(ActorSelection);
685 mySelectionMode = theMode;
689 //=================================================================================
690 // function : onApply()
692 //=================================================================================
693 bool SMESHGUI_GroupDlg::onApply()
695 if (mySMESHGUI->isActiveStudyLocked())
698 if (myName->text().trimmed().isEmpty())
701 if (myGrpTypeId == 0) { // on mesh elements
702 if (!myElements->count())
705 mySelectionMgr->clearSelected();
707 if (myGroup->_is_nil()) { // creation
708 if (myMesh->_is_nil())
711 SMESH::ElementType aType = SMESH::ALL;
713 case 0: aType = SMESH::NODE; break;
714 case 1: aType = SMESH::EDGE; break;
715 case 2: aType = SMESH::FACE; break;
716 case 3: aType = SMESH::VOLUME; break;
719 SMESH::long_array_var anIdList = new SMESH::long_array;
720 int i, k = myElements->count();
722 for (i = 0; i < k; i++) {
723 anIdList[i] = myElements->item(i)->text().toInt();
726 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
727 myGroup->Add(anIdList.inout());
729 SALOMEDS::Color aColor = getGroupColor();
730 myGroup->SetColor(aColor);
732 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
734 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
735 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
737 /* init for next operation */
740 myGroup = SMESH::SMESH_Group::_nil();
743 myGroup->SetName(myName->text().toLatin1().data());
745 SALOMEDS::Color aColor = getGroupColor();
746 myGroup->SetColor(aColor);
748 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
749 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
750 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
754 int i, total = myElements->count();
755 for (i = 0; i < total; i++) {
756 int anId = myElements->item(i)->text().toInt();
757 int idx = myIdList.indexOf(anId);
759 aAddList.append(anId);
761 myIdList.removeAt(idx);
763 if (!aAddList.empty()) {
764 SMESH::long_array_var anIdList = new SMESH::long_array;
765 int added = aAddList.count();
766 anIdList->length(added);
767 for (i = 0; i < added; i++)
768 anIdList[i] = aAddList[i];
769 myGroup->Add(anIdList.inout());
771 if (!myIdList.empty()) {
772 SMESH::long_array_var anIdList = new SMESH::long_array;
773 int removed = myIdList.count();
774 anIdList->length(removed);
775 for (i = 0; i < removed; i++)
776 anIdList[i] = myIdList[i];
777 myGroup->Remove(anIdList.inout());
779 /* init for next operation */
781 for (i = 0; i < total; i++) {
782 myIdList.append(myElements->item(i)->text().toInt());
786 mySMESHGUI->updateObjBrowser(true);
787 SMESH::UpdateView(); // asv: fix of BUG PAL5515
788 mySelectionMgr->clearSelected();
791 else if (myGrpTypeId == 1) { // on geom object
792 if (CORBA::is_nil(myGroupOnGeom)) { // creation
793 if (myMesh->_is_nil() || !myGeomObjects->length())
796 SMESH::ElementType aType = SMESH::ALL;
798 case 0: aType = SMESH::NODE; break;
799 case 1: aType = SMESH::EDGE; break;
800 case 2: aType = SMESH::FACE; break;
801 case 3: aType = SMESH::VOLUME; break;
804 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
805 GEOM::GEOM_IGroupOperations_var aGroupOp =
806 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
808 if (myGeomObjects->length() == 1) {
809 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
810 myName->text().toLatin1().data(),
814 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
815 if ( aSMESHGen->_is_nil() )
818 // create a geometry group
819 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
820 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
822 if (geomGen->_is_nil() || !aStudy)
825 GEOM::GEOM_IGroupOperations_var op =
826 geomGen->GetIGroupOperations(aStudy->StudyId());
830 // check and add all selected GEOM objects: they must be
831 // a sub-shapes of the main GEOM and must be of one type
832 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
833 for ( int i =0; i < myGeomObjects->length(); i++) {
834 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
836 aGroupType = aSubShapeType;
837 else if (aSubShapeType != aGroupType) {
838 aGroupType = TopAbs_SHAPE;
843 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
844 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
845 op->UnionList(aGroupVar, myGeomObjects);
848 // publish the GEOM group in study
849 QString aNewGeomGroupName ("Auto_group_for_");
850 aNewGeomGroupName += myName->text();
851 SALOMEDS::SObject_var aNewGroupSO =
852 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
853 aNewGeomGroupName.toLatin1().data(), aMeshShape);
856 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
857 myName->text().toLatin1().data(),
861 SALOMEDS::Color aColor = getGroupColor();
862 myGroupOnGeom->SetColor(aColor);
864 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
866 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
867 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
869 /* init for next operation */
871 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
874 myGroupOnGeom->SetName(myName->text().toLatin1().data());
876 SALOMEDS::Color aColor = getGroupColor();
877 myGroupOnGeom->SetColor(aColor);
879 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
880 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
881 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
884 mySMESHGUI->updateObjBrowser(true);
885 mySelectionMgr->clearSelected();
892 //=================================================================================
895 //=================================================================================
896 void SMESHGUI_GroupDlg::onOK()
902 //=================================================================================
903 // function : onListSelectionChanged()
904 // purpose : Called when selection in element list is changed
905 //=================================================================================
906 void SMESHGUI_GroupDlg::onListSelectionChanged()
908 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
909 if( myIsBusy || !myActor) return;
912 if (myCurrentLineEdit == 0) {
913 mySelectionMgr->clearSelected();
914 TColStd_MapOfInteger aIndexes;
915 QList<QListWidgetItem*> selItems = myElements->selectedItems();
916 QListWidgetItem* anItem;
917 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
918 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
920 aList.Append(myActor->getIO());
921 mySelectionMgr->setSelectedObjects(aList,false);
926 //=================================================================================
927 // function : onObjectSelectionChanged()
928 // purpose : Called when selection in 3D view or ObjectBrowser is changed
929 //=================================================================================
930 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
932 if ( myIsBusy || !isEnabled()) return;
933 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isDown()) return;
938 mySelectionMgr->selectedObjects( aList );
940 int aNbSel = aList.Extent();
941 myElements->clearSelection();
943 if (myCurrentLineEdit) {
944 myCurrentLineEdit->setText("");
945 QString aString = "";
947 if (myCurrentLineEdit == myMeshGroupLine) {
948 mySelectSubMesh->setEnabled(false);
949 mySelectGroup->setEnabled(false);
950 myGroupLine->setText("");
951 mySubMeshLine->setText("");
953 myGeomGroupBtn->setEnabled(false);
954 myGeomGroupLine->setEnabled(false);
955 myGeomGroupLine->setText("");
956 myGeomObjects = new GEOM::ListOfGO();
957 myGeomObjects->length(0);
959 if (myGeomGroupBtn->isDown())
960 myGeomGroupBtn->setDown(false);
967 myGroup = SMESH::SMESH_Group::_nil();
968 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
969 myMesh = SMESH::SMESH_Mesh::_nil();
975 Handle(SALOME_InteractiveObject) IO = aList.First();
978 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
980 if (myMesh->_is_nil())
986 myGroup = SMESH::SMESH_Group::_nil();
988 myActor = SMESH::FindActorByObject(myMesh);
989 SMESH::SetPickable(myActor);
991 aString = aList.First()->getName();
992 myMeshGroupLine->setText(aString);
993 myMeshGroupLine->home( false );
995 mySelectSubMesh->setEnabled(true);
996 mySelectGroup->setEnabled(true);
997 myGeomGroupBtn->setEnabled(true);
998 myGeomGroupLine->setEnabled(true);
1001 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1002 if (aGroup->_is_nil())
1008 myCurrentLineEdit = 0;
1010 myGroup = SMESH::SMESH_Group::_nil();
1011 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1015 mySelectSubMesh->setEnabled(true);
1016 mySelectGroup->setEnabled(true);
1018 myCurrentLineEdit = 0;
1023 if (myGrpTypeId == 0)
1029 myElements->clear();
1030 setSelectionMode(myTypeId);
1037 } else if (myCurrentLineEdit == myGeomGroupLine) {
1039 myGeomObjects = new GEOM::ListOfGO();
1042 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1044 if (aNbSel == 0 || !aMeshSO)
1046 myGeomObjects->length(0);
1052 myGeomObjects->length(aNbSel);
1054 GEOM::GEOM_Object_var aGeomGroup;
1055 Standard_Boolean testResult;
1058 SALOME_ListIteratorOfListIO anIt (aList);
1059 for ( ; anIt.More(); anIt.Next()) {
1061 testResult = Standard_False;
1062 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1064 // Check if the object is a geometry group
1065 if (!testResult || CORBA::is_nil(aGeomGroup))
1069 // Check if group constructed on the same shape as a mesh or on its child
1070 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1071 GEOM::GEOM_IGroupOperations_var anOp =
1072 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1074 // The main shape of the group
1075 GEOM::GEOM_Object_var aGroupMainShape;
1076 if (aGeomGroup->GetType() == 37)
1077 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1079 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1080 _PTR(SObject) aGroupMainShapeSO =
1081 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1082 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1084 _PTR(SObject) anObj, aRef;
1085 bool isRefOrSubShape = false;
1086 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1087 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1088 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1089 isRefOrSubShape = true;
1091 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1092 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1093 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1094 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1095 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1096 if (aRef->GetID() == aFather->GetID())
1097 isRefOrSubShape = true;
1099 aFather = aFather->GetFather();
1103 if (isRefOrSubShape)
1104 myGeomObjects[i++] = aGeomGroup;
1107 myGeomObjects->length(i);
1119 if(myCurrentLineEdit == mySubMeshLine)
1120 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1121 else if(myCurrentLineEdit == myGroupLine)
1122 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1123 else if(myCurrentLineEdit == myGeomGroupLine)
1124 aString = tr("%1 Objects").arg(aNbSel);
1126 aString = aList.First()->getName();
1130 myCurrentLineEdit->setText(aString);
1131 myOldName = myName->text();
1132 myName->setText(aString);
1133 myCurrentLineEdit->home(false);
1138 if (aNbSel == 1 && myActor ) {
1139 QString aListStr = "";
1141 if (myTypeId == 0) {
1142 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1144 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1147 QStringList anElements = aListStr.split(" ", QString::SkipEmptyParts);
1148 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1149 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1150 QListWidgetItem* anItem;
1151 foreach(anItem, found) anItem->setSelected(true);
1158 if (!myGroup->_is_nil())
1159 myActor = SMESH::FindActorByObject(myGroup);
1160 else if(!myGroupOnGeom->_is_nil())
1161 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1163 myActor = SMESH::FindActorByObject(myMesh);
1169 //=================================================================================
1170 // function : onSelectSubMesh()
1171 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1172 //=================================================================================
1173 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1176 if (mySelectGroup->isChecked()) {
1177 mySelectGroup->setChecked(false);
1179 //VSR: else if (mySelectGeomGroup->isChecked()) {
1180 //VSR: mySelectGeomGroup->setChecked(false);
1182 myCurrentLineEdit = mySubMeshLine;
1183 setSelectionMode(4);
1186 mySubMeshLine->setText("");
1187 myCurrentLineEdit = 0;
1189 setSelectionMode(myTypeId);
1191 mySubMeshBtn->setEnabled(on);
1192 mySubMeshLine->setEnabled(on);
1196 //=================================================================================
1197 // function : (onSelectGroup)
1198 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1199 //=================================================================================
1200 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1203 if (mySelectSubMesh->isChecked()) {
1204 mySelectSubMesh->setChecked(false);
1206 myCurrentLineEdit = myGroupLine;
1207 setSelectionMode(5);
1210 myGroupLine->setText("");
1211 myCurrentLineEdit = 0;
1213 setSelectionMode(myTypeId);
1215 myGroupBtn->setEnabled(on);
1216 myGroupLine->setEnabled(on);
1220 //=================================================================================
1221 // function : (onSelectGeomGroup)
1222 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1223 //=================================================================================
1224 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1227 if (mySelectSubMesh->isChecked()) {
1228 mySelectSubMesh->setChecked(false);
1230 else if (mySelectGroup->isChecked()) {
1231 mySelectGroup->setChecked(false);
1233 myCurrentLineEdit = myGeomGroupLine;
1235 setSelectionMode(8);
1238 myGeomGroupBtn->setDown(false);
1239 myGeomObjects->length(0);
1240 myGeomGroupLine->setText("");
1241 myCurrentLineEdit = 0;
1243 setSelectionMode(myTypeId);
1248 //=================================================================================
1249 // function : setCurrentSelection()
1251 //=================================================================================
1252 void SMESHGUI_GroupDlg::setCurrentSelection()
1254 QPushButton* send = (QPushButton*)sender();
1255 myCurrentLineEdit = 0;
1256 if (send == myMeshGroupBtn) {
1257 myCurrentLineEdit = myMeshGroupLine;
1259 setSelectionMode(6);
1261 setSelectionMode(5);
1262 onObjectSelectionChanged();
1264 else if (send == mySubMeshBtn) {
1265 myCurrentLineEdit = mySubMeshLine;
1266 onObjectSelectionChanged();
1268 else if (send == myGroupBtn) {
1269 myCurrentLineEdit = myGroupLine;
1270 onObjectSelectionChanged();
1275 //=================================================================================
1276 // function : setFilters()
1277 // purpose : SLOT. Called when "Filter" button pressed.
1278 //=================================================================================
1279 void SMESHGUI_GroupDlg::setFilters()
1281 SMESH::ElementType aType = SMESH::ALL;
1284 case 0 : aType = SMESH::NODE; break;
1285 case 1 : aType = SMESH::EDGE; break;
1286 case 2 : aType = SMESH::FACE; break;
1287 case 3 : aType = SMESH::VOLUME; break;
1291 if ( myFilterDlg == 0 )
1293 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1294 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1297 myFilterDlg->Init( aType );
1299 myFilterDlg->SetSelection();
1300 myFilterDlg->SetMesh( myMesh );
1301 myFilterDlg->SetSourceWg( myElements );
1303 myFilterDlg->show();
1306 //=================================================================================
1307 // function : onFilterAccepted()
1308 // purpose : SLOT. Called when Filter dlg closed with OK button.
1309 // Uncheck "Select submesh" and "Select group" checkboxes
1310 //=================================================================================
1311 void SMESHGUI_GroupDlg::onFilterAccepted()
1313 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1315 mySelectionMode = myTypeId;
1316 mySelectSubMesh->setChecked( false );
1317 mySelectGroup->setChecked( false );
1321 //=================================================================================
1322 // function : onAdd()
1324 //=================================================================================
1325 void SMESHGUI_GroupDlg::onAdd()
1327 SALOME_ListIO aList;
1328 mySelectionMgr->selectedObjects( aList );
1330 int aNbSel = aList.Extent();
1332 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1336 SMESH::ElementType aType = SMESH::ALL;
1339 aType = SMESH::NODE;
1340 mySelector->SetSelectionMode(NodeSelection);
1343 aType = SMESH::EDGE;
1344 mySelector->SetSelectionMode(EdgeSelection);
1347 aType = SMESH::FACE;
1348 mySelector->SetSelectionMode(FaceSelection);
1351 aType = SMESH::VOLUME;
1352 mySelector->SetSelectionMode(VolumeSelection);
1355 mySelector->SetSelectionMode(ActorSelection);
1359 if (myCurrentLineEdit == 0) {
1360 //if (aNbSel != 1) { myIsBusy = false; return; }
1361 QString aListStr = "";
1363 if (myTypeId == 0) {
1364 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1367 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1370 QStringList anElements = aListStr.split(" ", QString::SkipEmptyParts);
1371 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1372 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1373 QListWidgetItem* anItem;
1374 if (found.count() == 0) {
1375 anItem = new QListWidgetItem(*it);
1376 myElements->addItem(anItem);
1377 anItem->setSelected(true);
1380 foreach(anItem, found) anItem->setSelected(true);
1384 } else if (myCurrentLineEdit == mySubMeshLine) {
1385 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1387 SALOME_ListIO aList;
1388 mySelectionMgr->selectedObjects( aList );
1390 SALOME_ListIteratorOfListIO anIt (aList);
1391 for ( ; anIt.More(); anIt.Next()) {
1392 SMESH::SMESH_subMesh_var aSubMesh =
1393 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1394 if (!aSubMesh->_is_nil()) {
1395 // check if mesh is the same
1396 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1398 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1399 int k = anElements->length();
1400 for (int i = 0; i < k; i++) {
1401 QString aText = QString::number(anElements[i]);
1402 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1403 QListWidgetItem* anItem = 0;
1404 if (found.count() == 0) {
1405 anItem = new QListWidgetItem(aText);
1406 myElements->addItem(anItem);
1407 anItem->setSelected(true);
1410 foreach(anItem, found) anItem->setSelected(true);
1414 catch (const SALOME::SALOME_Exception& ex) {
1415 SalomeApp_Tools::QtCatchCorbaException(ex);
1420 mySelectSubMesh->setChecked(false);
1422 onListSelectionChanged();
1424 } else if (myCurrentLineEdit == myGroupLine) {
1425 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1426 SALOME_ListIO aList;
1427 mySelectionMgr->selectedObjects( aList );
1429 SALOME_ListIteratorOfListIO anIt (aList);
1430 for ( ; anIt.More(); anIt.Next()) {
1431 SMESH::SMESH_Group_var aGroup =
1432 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1433 if (!aGroup->_is_nil()) {
1434 // check if mesh is the same
1435 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1436 SMESH::long_array_var anElements = aGroup->GetListOfID();
1437 int k = anElements->length();
1438 for (int i = 0; i < k; i++) {
1439 QString aText = QString::number(anElements[i]);
1440 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1441 QListWidgetItem* anItem = 0;
1442 if (found.count() == 0) {
1443 anItem = new QListWidgetItem(aText);
1444 myElements->addItem(anItem);
1445 anItem->setSelected(true);
1448 foreach(anItem, found) anItem->setSelected(true);
1454 mySelectGroup->setChecked(false);
1456 onListSelectionChanged();
1458 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1459 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1460 GEOM::GEOM_IGroupOperations_var aGroupOp =
1461 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1463 SMESH::ElementType aGroupType = SMESH::ALL;
1464 switch(aGroupOp->GetType(myGeomObjects[0])) {
1465 case 7: aGroupType = SMESH::NODE; break;
1466 case 6: aGroupType = SMESH::EDGE; break;
1467 case 4: aGroupType = SMESH::FACE; break;
1468 case 2: aGroupType = SMESH::VOLUME; break;
1469 default: myIsBusy = false; return;
1472 if (aGroupType == aType) {
1473 _PTR(SObject) aGroupSO =
1474 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1475 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1477 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1478 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1479 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1480 aBelongToGeom->SetGeom(myGeomObjects[0]);
1481 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1482 aBelongToGeom->SetElementType(aType);
1483 aFilter->SetPredicate(aBelongToGeom);
1485 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1487 int k = anElements->length();
1488 for (int i = 0; i < k; i++) {
1489 QString aText = QString::number(anElements[i]);
1490 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1491 QListWidgetItem* anItem = 0;
1492 if (found.count() == 0) {
1493 anItem = new QListWidgetItem(aText);
1494 myElements->addItem(anItem);
1495 anItem->setSelected(true);
1498 foreach(anItem, found) anItem->setSelected(true);
1503 //VSR: mySelectGeomGroup->setChecked(false);
1505 onListSelectionChanged();
1508 // mySelectionMgr->clearSelected();
1512 //=================================================================================
1513 // function : onRemove()
1515 //=================================================================================
1516 void SMESHGUI_GroupDlg::onRemove()
1519 if (myCurrentLineEdit == 0) {
1520 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1521 QListWidgetItem* item;
1522 foreach(item, selItems) delete item;
1524 SALOME_ListIO aList;
1525 mySelectionMgr->selectedObjects( aList );
1527 int aNbSel = aList.Extent();
1529 if (aNbSel == 0) { myIsBusy = false; return; }
1531 SMESH::ElementType aType = SMESH::ALL;
1533 case 0: aType = SMESH::NODE; break;
1534 case 1: aType = SMESH::EDGE; break;
1535 case 2: aType = SMESH::FACE; break;
1536 case 3: aType = SMESH::VOLUME; break;
1539 if (myCurrentLineEdit == mySubMeshLine) {
1540 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1541 SALOME_ListIO aList;
1542 mySelectionMgr->selectedObjects( aList );
1544 SALOME_ListIteratorOfListIO anIt (aList);
1545 for ( ; anIt.More(); anIt.Next()) {
1546 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1547 if (!aSubMesh->_is_nil()) {
1548 // check if mesh is the same
1549 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1550 if (aType == SMESH::NODE) {
1552 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1553 int k = anElements->length();
1554 for (int i = 0; i < k; i++) {
1555 QList<QListWidgetItem*> found =
1556 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1557 QListWidgetItem* anItem;
1558 foreach(anItem, found) delete anItem;
1561 catch (const SALOME::SALOME_Exception& ex) {
1562 SalomeApp_Tools::QtCatchCorbaException(ex);
1567 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1568 int k = anElements->length();
1569 for (int i = 0; i < k; i++) {
1570 QList<QListWidgetItem*> found =
1571 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1572 QListWidgetItem* anItem;
1573 foreach(anItem, found) delete anItem;
1576 catch (const SALOME::SALOME_Exception& ex) {
1577 SalomeApp_Tools::QtCatchCorbaException(ex);
1584 else if (myCurrentLineEdit == myGroupLine) {
1585 Standard_Boolean aRes;
1586 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1587 SALOME_ListIO aList;
1588 mySelectionMgr->selectedObjects( aList );
1590 SALOME_ListIteratorOfListIO anIt (aList);
1591 for ( ; anIt.More(); anIt.Next()) {
1592 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1593 if (aRes && !aGroup->_is_nil()) {
1594 // check if mesh is the same
1595 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1596 SMESH::long_array_var anElements = aGroup->GetListOfID();
1597 int k = anElements->length();
1598 for (int i = 0; i < k; i++) {
1599 QList<QListWidgetItem*> found =
1600 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1601 QListWidgetItem* anItem;
1602 foreach(anItem, found) delete anItem;
1613 //=================================================================================
1614 // function : onSort()
1616 //=================================================================================
1617 void SMESHGUI_GroupDlg::onSort()
1619 // PAL5412: sorts items in ascending by "string" value
1620 // myElements->sort(true);
1621 // myElements->update();
1622 int i, k = myElements->count();
1625 QList<int> aSelected;
1626 std::vector<int> anArray(k);
1627 // QMemArray<int> anArray(k);
1629 for (i = 0; i < k; i++) {
1630 int id = myElements->item(i)->text().toInt();
1632 if (myElements->item(i)->isSelected())
1633 aSelected.append(id);
1635 // sort & update list
1636 std::sort(anArray.begin(), anArray.end());
1638 myElements->clear();
1639 for (i = 0; i < k; i++) {
1640 QListWidgetItem* anItem = new QListWidgetItem(QString::number(anArray[i]));
1641 myElements->addItem(anItem);
1642 anItem->setSelected(aSelected.contains(anArray[i]));
1648 //=================================================================================
1649 // function : closeEvent()
1651 //=================================================================================
1652 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1657 //=================================================================================
1658 // function : SMESHGUI_GroupDlg::onClose
1659 // purpose : SLOT called when "Close" button pressed. Close dialog
1660 //=================================================================================
1661 void SMESHGUI_GroupDlg::onClose()
1663 if (SMESH::GetCurrentVtkView()) {
1664 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1665 SMESH::SetPointRepresentation(false);
1666 SMESH::SetPickable();
1669 mySelectionMgr->clearSelected();
1670 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1671 aViewWindow->SetSelectionMode(ActorSelection);
1672 mySelectionMgr->clearFilters();
1673 mySMESHGUI->ResetState();
1678 //=================================================================================
1679 // function : onHelp()
1681 //=================================================================================
1682 void SMESHGUI_GroupDlg::onHelp()
1684 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1686 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1690 platform = "winapplication";
1692 platform = "application";
1694 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
1695 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1696 arg(app->resourceMgr()->stringValue("ExternalBrowser",
1698 arg(myHelpFileName));
1702 //=================================================================================
1703 // function : SMESHGUI_GroupDlg::onDeactivate
1704 // purpose : SLOT called when dialog must be deativated
1705 //=================================================================================
1706 void SMESHGUI_GroupDlg::onDeactivate()
1708 mySMESHGUI->ResetState();
1712 //=================================================================================
1713 // function : SMESHGUI_GroupDlg::enterEvent
1714 // purpose : Event filter
1715 //=================================================================================
1716 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1719 mySMESHGUI->EmitSignalDeactivateDialog();
1721 mySelectionMode = -1;
1722 setSelectionMode(myTypeId);
1723 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1724 mySMESHGUI->SetActiveDialogBox(this);
1725 mySMESHGUI->SetState(800);
1729 //=================================================================================
1730 // function : hideEvent
1731 // purpose : caused by ESC key
1732 //=================================================================================
1733 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1735 if (!isMinimized() && !myIsBusy)
1739 //=================================================================================
1740 // function : keyPressEvent()
1742 //=================================================================================
1743 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1745 QDialog::keyPressEvent( e );
1746 if ( e->isAccepted() )
1749 if ( e->key() == Qt::Key_F1 )
1756 //================================================================================
1758 * \brief Enable showing of the popup when Geometry selection btn is clicked
1759 * \param enable - true to enable
1761 //================================================================================
1763 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1765 void SMESHGUI_GroupDlg::updateGeomPopup()
1767 bool enable = false;
1769 if ( !myMesh->_is_nil() )
1770 enable = myMesh->NbEdges() > 0;
1772 if ( myGeomGroupBtn )
1774 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1776 if ( !myGeomPopup ) {
1777 myGeomPopup = new QMenu(this);
1778 myActions[myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )] = DIRECT_GEOM_INDEX;
1779 myActions[myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )] = GEOM_BY_MESH_INDEX;
1780 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
1782 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1788 //=================================================================================
1789 // function : onGeomSelectionButton()
1791 //=================================================================================
1792 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1794 if ( myGeomPopup && isBtnOn )
1796 myCurrentLineEdit = myGeomGroupLine;
1797 QAction* a = myGeomPopup->exec( QCursor::pos() );
1798 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
1799 setSelectionMode(7);
1803 myCurrentLineEdit = 0;
1804 setSelectionMode(8);
1808 //=================================================================================
1809 // function : onGeomPopup()
1811 //=================================================================================
1812 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
1814 int index = myActions[a];
1815 if ( index == GEOM_BY_MESH_INDEX )
1817 mySelectionMode = -1;
1818 if ( !myShapeByMeshOp ) {
1819 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1820 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1821 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1822 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1823 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1825 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1826 if ( !myMesh->_is_nil() ) {
1828 hide(); // stop processing selection
1830 myShapeByMeshOp->setModule( mySMESHGUI );
1831 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1832 myShapeByMeshOp->SetMesh( myMesh );
1833 myShapeByMeshOp->start();
1838 //================================================================================
1840 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1842 //================================================================================
1844 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1846 if ( myShapeByMeshOp == op ) {
1847 mySMESHGUI->getApp()->updateObjectBrowser();
1849 // Select a found geometry object
1850 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1851 if ( !aGeomVar->_is_nil() )
1853 QString ID = aGeomVar->GetStudyEntry();
1854 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1855 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
1856 SALOME_ListIO anIOList;
1857 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1858 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1859 anIOList.Append( anIO );
1860 mySelectionMgr->setSelectedObjects( anIOList, false );
1861 onObjectSelectionChanged();
1867 //================================================================================
1869 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1871 //================================================================================
1873 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1875 if ( myShapeByMeshOp == op )
1878 setSelectionMode(7);
1882 //=================================================================================
1883 // function : setGroupColor()
1885 //=================================================================================
1886 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
1888 QColor aQColor( (int)( theColor.R * 255.0 ),
1889 (int)( theColor.G * 255.0 ),
1890 (int)( theColor.B * 255.0 ) );
1891 setGroupQColor( aQColor );
1894 //=================================================================================
1895 // function : getGroupColor()
1897 //=================================================================================
1898 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
1900 QColor aQColor = getGroupQColor();
1902 SALOMEDS::Color aColor;
1903 aColor.R = (float)aQColor.red() / 255.0;
1904 aColor.G = (float)aQColor.green() / 255.0;
1905 aColor.B = (float)aQColor.blue() / 255.0;
1910 //=================================================================================
1911 // function : setGroupQColor()
1913 //=================================================================================
1914 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
1916 if( theColor.isValid() )
1917 myColorBtn->setColor( theColor );
1920 //=================================================================================
1921 // function : getGroupQColor()
1923 //=================================================================================
1924 QColor SMESHGUI_GroupDlg::getGroupQColor() const
1926 return myColorBtn->color();
1929 //=================================================================================
1930 // function : setDefaultGroupColor()
1932 //=================================================================================
1933 void SMESHGUI_GroupDlg::setDefaultGroupColor()
1935 if( myMesh->_is_nil() )
1938 bool isAutoColor = myMesh->GetAutoColor();
1943 int r = 0, g = 0, b = 0;
1944 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
1945 aQColor.setRgb( r, g, b );
1949 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
1951 QList<SALOMEDS::Color> aReservedColors;
1952 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1954 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1955 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
1956 aReservedColors.append( aReservedColor );
1959 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1960 aQColor.setRgb( (int)( aColor.R * 255.0 ),
1961 (int)( aColor.G * 255.0 ),
1962 (int)( aColor.B * 255.0 ) );
1966 setGroupQColor( aQColor );