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(myColorBtn, SIGNAL(changed( QColor )), this, SLOT(onColorChanged( QColor )));
384 connect(myOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
385 connect(myApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
386 connect(myCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
387 connect(myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
390 mySMESHGUI->SetActiveDialogBox(this);
391 mySMESHGUI->SetState(800);
393 mySelectionMode = -1;
394 myMeshFilter = new SMESH_TypeFilter(MESH);
395 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
396 myGroupFilter = new SMESH_TypeFilter(GROUP);
397 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
398 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
400 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
401 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
402 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
404 rb1->setChecked(true); // VSR !!!
405 onGrpTypeChanged(0); // VSR!!!
407 if (myMesh->_is_nil() )
408 myTypeGroup->button(0)->setChecked(true);
411 //myName->setText(GetDefaultName(tr("SMESH_GROUP")));
414 //=================================================================================
415 // function : ~SMESHGUI_GroupDlg()
416 // purpose : Destroys the object and frees any allocated resources
417 //=================================================================================
418 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
420 // no need to delete child widgets, Qt does it all for us
421 if ( myFilterDlg != 0 ) {
422 myFilterDlg->setParent( 0 );
427 //=================================================================================
428 // function : GetDefaultName()
429 // purpose : Get the Group Name if Create new Group
430 //=================================================================================
431 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
435 // collect all object names of SMESH component
436 SalomeApp_Study* appStudy =
437 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
438 if ( !appStudy ) return aName;
439 _PTR(Study) aStudy = appStudy->studyDS();
441 std::set<std::string> aSet;
442 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
444 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
446 for (it->InitEx(true); it->More(); it->Next()) {
448 aSet.insert(obj->GetName());
452 // build a unique name
454 bool isUnique = false;
456 aName = theOperation + "_" + QString::number(++aNumber);
457 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
463 //=================================================================================
466 //=================================================================================
467 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
469 mySelectionMgr->installFilter(myMeshFilter);
471 /* init data from current selection */
472 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
473 myGroup = SMESH::SMESH_Group::_nil();
474 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
476 myActor = SMESH::FindActorByObject(myMesh);
477 SMESH::SetPickable(myActor);
479 setDefaultGroupColor();
482 mySelectionMgr->selectedObjects( aList );
483 if( !aList.IsEmpty() )
485 QString aName = aList.First()->getName();
486 myMeshGroupLine->setText(aName);
487 myMeshGroupLine->home( false );
490 myCurrentLineEdit = 0;
492 myTypeGroup->button(0)->setChecked(true);
496 //=================================================================================
499 //=================================================================================
500 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
502 myMesh = theGroup->GetMesh();
504 myName->setText(theGroup->GetName());
506 myOldName = myName->text();
508 SALOMEDS::Color aColor = theGroup->GetColor();
509 setGroupColor( aColor );
511 myMeshGroupLine->setText(theGroup->GetName());
514 switch(theGroup->GetType()) {
515 case SMESH::NODE: aType= 0; break;
516 case SMESH::EDGE: aType = 1; break;
517 case SMESH::FACE: aType = 2; break;
518 case SMESH::VOLUME: aType = 3; break;
520 myTypeGroup->button(aType)->setChecked(true);
522 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
524 if ( !myGroup->_is_nil() )
526 myActor = SMESH::FindActorByObject(myMesh);
528 myActor = SMESH::FindActorByObject(myGroup);
529 SMESH::SetPickable(myActor);
531 myGrpTypeGroup->button(0)->setChecked(true);
534 myCurrentLineEdit = 0;
536 setSelectionMode(aType);
540 if (!myGroup->IsEmpty()) {
541 SMESH::long_array_var anElements = myGroup->GetListOfID();
542 int k = anElements->length();
543 for (int i = 0; i < k; i++) {
544 myIdList.append(anElements[i]);
545 myElements->addItem(QString::number(anElements[i]));
547 myElements->selectAll();
552 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
554 if ( !myGroupOnGeom->_is_nil() )
556 myActor = SMESH::FindActorByObject(myMesh);
558 myActor = SMESH::FindActorByObject(myGroup);
559 SMESH::SetPickable(myActor);
561 myGrpTypeGroup->button(1)->setChecked(true);
564 QString aShapeName("");
565 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
566 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
567 if (!aGroupShape->_is_nil())
569 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
570 aShapeName = aGroupShapeSO->GetName().c_str();
572 myGeomGroupLine->setText( aShapeName );
573 myName->setText("Group On " + aShapeName);
578 //=================================================================================
579 // function : updateButtons()
581 //=================================================================================
582 void SMESHGUI_GroupDlg::updateButtons()
584 bool enable = !myName->text().trimmed().isEmpty();
586 if (myGrpTypeId == 0) {
587 enable = enable && myElements->count() > 0;
588 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
590 else if (myGrpTypeId == 1) {
591 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
592 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
596 myOKBtn->setEnabled(enable);
597 myApplyBtn->setEnabled(enable);
600 //=================================================================================
601 // function : onNameChanged()
603 //=================================================================================
604 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
609 //=================================================================================
610 // function : onTypeChanged()
611 // purpose : Group elements type radio button management
612 //=================================================================================
613 void SMESHGUI_GroupDlg::onTypeChanged (int id)
615 if (myTypeId != id) {
617 if (myCurrentLineEdit == 0)
618 setSelectionMode(id);
623 //=================================================================================
624 // function : onGrpTypeChanged()
625 // purpose : Group type radio button management
626 //=================================================================================
627 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
629 if (myGrpTypeId != id) {
630 myWGStack->setCurrentIndex( id );
632 myName->setText(myOldName);
633 onSelectGeomGroup(id == 1);
638 //=================================================================================
639 // function : onColorChanged()
640 // purpose : Color button management
641 //=================================================================================
642 void SMESHGUI_GroupDlg::onColorChanged(QColor theColor)
647 //=================================================================================
648 // function : setSelectionMode()
649 // purpose : Radio button management
650 //=================================================================================
651 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
654 if (myMesh->_is_nil())
656 if (mySelectionMode != theMode) {
657 // [PAL10408] mySelectionMgr->clearSelected();
658 mySelectionMgr->clearFilters();
660 myActor->SetPointRepresentation(false);
662 SMESH::SetPointRepresentation(false);
667 myActor->SetPointRepresentation(true);
669 SMESH::SetPointRepresentation(true);
670 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
671 aViewWindow->SetSelectionMode(NodeSelection);
674 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
675 aViewWindow->SetSelectionMode(EdgeSelection);
678 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
679 aViewWindow->SetSelectionMode(FaceSelection);
682 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
683 aViewWindow->SetSelectionMode(VolumeSelection);
687 mySelectionMgr->installFilter(mySubMeshFilter);
688 else if (theMode == 5)
689 mySelectionMgr->installFilter(myGroupFilter);
690 else if (theMode == 6)
691 mySelectionMgr->installFilter(myMeshFilter);
692 else if (theMode == 7)
693 mySelectionMgr->installFilter(myGeomFilter);
695 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
696 aViewWindow->SetSelectionMode(ActorSelection);
698 mySelectionMode = theMode;
702 //=================================================================================
703 // function : onApply()
705 //=================================================================================
706 bool SMESHGUI_GroupDlg::onApply()
708 if (mySMESHGUI->isActiveStudyLocked())
711 if (myName->text().trimmed().isEmpty())
714 if (myGrpTypeId == 0) { // on mesh elements
715 if (!myElements->count())
718 mySelectionMgr->clearSelected();
720 if (myGroup->_is_nil()) { // creation
721 if (myMesh->_is_nil())
724 SMESH::ElementType aType = SMESH::ALL;
726 case 0: aType = SMESH::NODE; break;
727 case 1: aType = SMESH::EDGE; break;
728 case 2: aType = SMESH::FACE; break;
729 case 3: aType = SMESH::VOLUME; break;
732 SMESH::long_array_var anIdList = new SMESH::long_array;
733 int i, k = myElements->count();
735 for (i = 0; i < k; i++) {
736 anIdList[i] = myElements->item(i)->text().toInt();
739 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
740 myGroup->Add(anIdList.inout());
742 SALOMEDS::Color aColor = getGroupColor();
743 myGroup->SetColor(aColor);
745 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
747 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
748 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
750 /* init for next operation */
753 myGroup = SMESH::SMESH_Group::_nil();
756 myGroup->SetName(myName->text().toLatin1().data());
758 SALOMEDS::Color aColor = getGroupColor();
759 myGroup->SetColor(aColor);
761 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
762 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
763 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
767 int i, total = myElements->count();
768 for (i = 0; i < total; i++) {
769 int anId = myElements->item(i)->text().toInt();
770 int idx = myIdList.indexOf(anId);
772 aAddList.append(anId);
774 myIdList.removeAt(idx);
776 if (!aAddList.empty()) {
777 SMESH::long_array_var anIdList = new SMESH::long_array;
778 int added = aAddList.count();
779 anIdList->length(added);
780 for (i = 0; i < added; i++)
781 anIdList[i] = aAddList[i];
782 myGroup->Add(anIdList.inout());
784 if (!myIdList.empty()) {
785 SMESH::long_array_var anIdList = new SMESH::long_array;
786 int removed = myIdList.count();
787 anIdList->length(removed);
788 for (i = 0; i < removed; i++)
789 anIdList[i] = myIdList[i];
790 myGroup->Remove(anIdList.inout());
792 /* init for next operation */
794 for (i = 0; i < total; i++) {
795 myIdList.append(myElements->item(i)->text().toInt());
799 mySMESHGUI->updateObjBrowser(true);
800 SMESH::UpdateView(); // asv: fix of BUG PAL5515
801 mySelectionMgr->clearSelected();
804 else if (myGrpTypeId == 1) { // on geom object
805 if (CORBA::is_nil(myGroupOnGeom)) { // creation
806 if (myMesh->_is_nil() || !myGeomObjects->length())
809 SMESH::ElementType aType = SMESH::ALL;
811 case 0: aType = SMESH::NODE; break;
812 case 1: aType = SMESH::EDGE; break;
813 case 2: aType = SMESH::FACE; break;
814 case 3: aType = SMESH::VOLUME; break;
817 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
818 GEOM::GEOM_IGroupOperations_var aGroupOp =
819 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
821 if (myGeomObjects->length() == 1) {
822 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
823 myName->text().toLatin1().data(),
827 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
828 if ( aSMESHGen->_is_nil() )
831 // create a geometry group
832 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
833 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
835 if (geomGen->_is_nil() || !aStudy)
838 GEOM::GEOM_IGroupOperations_var op =
839 geomGen->GetIGroupOperations(aStudy->StudyId());
843 // check and add all selected GEOM objects: they must be
844 // a sub-shapes of the main GEOM and must be of one type
845 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
846 for ( int i =0; i < myGeomObjects->length(); i++) {
847 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
849 aGroupType = aSubShapeType;
850 else if (aSubShapeType != aGroupType) {
851 aGroupType = TopAbs_SHAPE;
856 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
857 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
858 op->UnionList(aGroupVar, myGeomObjects);
861 // publish the GEOM group in study
862 QString aNewGeomGroupName ("Auto_group_for_");
863 aNewGeomGroupName += myName->text();
864 SALOMEDS::SObject_var aNewGroupSO =
865 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
866 aNewGeomGroupName.toLatin1().data(), aMeshShape);
869 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
870 myName->text().toLatin1().data(),
874 SALOMEDS::Color aColor = getGroupColor();
875 myGroupOnGeom->SetColor(aColor);
877 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
879 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
880 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
882 /* init for next operation */
884 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
887 myGroupOnGeom->SetName(myName->text().toLatin1().data());
889 SALOMEDS::Color aColor = getGroupColor();
890 myGroupOnGeom->SetColor(aColor);
892 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
893 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
894 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
897 mySMESHGUI->updateObjBrowser(true);
898 mySelectionMgr->clearSelected();
905 //=================================================================================
908 //=================================================================================
909 void SMESHGUI_GroupDlg::onOK()
915 //=================================================================================
916 // function : onListSelectionChanged()
917 // purpose : Called when selection in element list is changed
918 //=================================================================================
919 void SMESHGUI_GroupDlg::onListSelectionChanged()
921 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
922 if( myIsBusy || !myActor) return;
925 if (myCurrentLineEdit == 0) {
926 mySelectionMgr->clearSelected();
927 TColStd_MapOfInteger aIndexes;
928 QList<QListWidgetItem*> selItems = myElements->selectedItems();
929 QListWidgetItem* anItem;
930 foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
931 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
933 aList.Append(myActor->getIO());
934 mySelectionMgr->setSelectedObjects(aList,false);
939 //=================================================================================
940 // function : onObjectSelectionChanged()
941 // purpose : Called when selection in 3D view or ObjectBrowser is changed
942 //=================================================================================
943 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
945 if ( myIsBusy || !isEnabled()) return;
946 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
951 mySelectionMgr->selectedObjects( aList );
953 int aNbSel = aList.Extent();
954 myElements->clearSelection();
956 if (myCurrentLineEdit) {
957 myCurrentLineEdit->setText("");
958 QString aString = "";
960 if (myCurrentLineEdit == myMeshGroupLine) {
961 mySelectSubMesh->setEnabled(false);
962 mySelectGroup->setEnabled(false);
963 myGroupLine->setText("");
964 mySubMeshLine->setText("");
966 myGeomGroupBtn->setEnabled(false);
967 myGeomGroupLine->setEnabled(false);
968 myGeomGroupLine->setText("");
969 myGeomObjects = new GEOM::ListOfGO();
970 myGeomObjects->length(0);
972 if (myGeomGroupBtn->isChecked())
973 myGeomGroupBtn->setChecked(false);
980 myGroup = SMESH::SMESH_Group::_nil();
981 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
982 myMesh = SMESH::SMESH_Mesh::_nil();
988 Handle(SALOME_InteractiveObject) IO = aList.First();
991 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
993 if (myMesh->_is_nil())
999 myGroup = SMESH::SMESH_Group::_nil();
1001 myActor = SMESH::FindActorByObject(myMesh);
1002 SMESH::SetPickable(myActor);
1004 aString = aList.First()->getName();
1005 myMeshGroupLine->setText(aString);
1006 myMeshGroupLine->home( false );
1008 mySelectSubMesh->setEnabled(true);
1009 mySelectGroup->setEnabled(true);
1010 myGeomGroupBtn->setEnabled(true);
1011 myGeomGroupLine->setEnabled(true);
1014 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1015 if (aGroup->_is_nil())
1021 myCurrentLineEdit = 0;
1023 myGroup = SMESH::SMESH_Group::_nil();
1024 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1028 mySelectSubMesh->setEnabled(true);
1029 mySelectGroup->setEnabled(true);
1031 myCurrentLineEdit = 0;
1036 if (myGrpTypeId == 0)
1042 myElements->clear();
1043 setSelectionMode(myTypeId);
1050 } else if (myCurrentLineEdit == myGeomGroupLine) {
1052 myGeomObjects = new GEOM::ListOfGO();
1055 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1057 if (aNbSel == 0 || !aMeshSO)
1059 myGeomObjects->length(0);
1065 myGeomObjects->length(aNbSel);
1067 GEOM::GEOM_Object_var aGeomGroup;
1068 Standard_Boolean testResult;
1071 SALOME_ListIteratorOfListIO anIt (aList);
1072 for ( ; anIt.More(); anIt.Next()) {
1074 testResult = Standard_False;
1075 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1077 // Check if the object is a geometry group
1078 if (!testResult || CORBA::is_nil(aGeomGroup))
1082 // Check if group constructed on the same shape as a mesh or on its child
1083 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1084 GEOM::GEOM_IGroupOperations_var anOp =
1085 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1087 // The main shape of the group
1088 GEOM::GEOM_Object_var aGroupMainShape;
1089 if (aGeomGroup->GetType() == 37)
1090 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1092 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1093 _PTR(SObject) aGroupMainShapeSO =
1094 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1095 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1097 _PTR(SObject) anObj, aRef;
1098 bool isRefOrSubShape = false;
1099 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1100 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1101 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1102 isRefOrSubShape = true;
1104 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1105 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1106 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1107 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1108 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1109 if (aRef->GetID() == aFather->GetID())
1110 isRefOrSubShape = true;
1112 aFather = aFather->GetFather();
1116 if (isRefOrSubShape)
1117 myGeomObjects[i++] = aGeomGroup;
1120 myGeomObjects->length(i);
1132 if(myCurrentLineEdit == mySubMeshLine)
1133 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1134 else if(myCurrentLineEdit == myGroupLine)
1135 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1136 else if(myCurrentLineEdit == myGeomGroupLine)
1137 aString = tr("%1 Objects").arg(aNbSel);
1139 aString = aList.First()->getName();
1143 myCurrentLineEdit->setText(aString);
1144 myOldName = myName->text();
1145 myName->setText(aString);
1146 myCurrentLineEdit->home(false);
1151 if (aNbSel == 1 && myActor ) {
1152 QString aListStr = "";
1154 if (myTypeId == 0) {
1155 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1157 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1160 QListWidgetItem* anItem;
1161 QList<QListWidgetItem*> listItemsToSel;
1162 QStringList anElements = aListStr.split(" ", QString::SkipEmptyParts);
1163 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1164 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1165 foreach(anItem, found)
1166 if (!anItem->isSelected())
1167 listItemsToSel.push_back(anItem);
1169 bool blocked = myElements->signalsBlocked();
1170 myElements->blockSignals(true);
1171 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1172 myElements->blockSignals(blocked);
1173 onListSelectionChanged();
1174 listItemsToSel.clear();
1180 if (!myGroup->_is_nil())
1181 myActor = SMESH::FindActorByObject(myGroup);
1182 else if(!myGroupOnGeom->_is_nil())
1183 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1185 myActor = SMESH::FindActorByObject(myMesh);
1191 //=================================================================================
1192 // function : onSelectSubMesh()
1193 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1194 //=================================================================================
1195 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1198 if (mySelectGroup->isChecked()) {
1199 mySelectGroup->setChecked(false);
1201 //VSR: else if (mySelectGeomGroup->isChecked()) {
1202 //VSR: mySelectGeomGroup->setChecked(false);
1204 myCurrentLineEdit = mySubMeshLine;
1205 setSelectionMode(4);
1208 mySubMeshLine->setText("");
1209 myCurrentLineEdit = 0;
1211 setSelectionMode(myTypeId);
1213 mySubMeshBtn->setEnabled(on);
1214 mySubMeshLine->setEnabled(on);
1218 //=================================================================================
1219 // function : (onSelectGroup)
1220 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1221 //=================================================================================
1222 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1225 if (mySelectSubMesh->isChecked()) {
1226 mySelectSubMesh->setChecked(false);
1228 myCurrentLineEdit = myGroupLine;
1229 setSelectionMode(5);
1232 myGroupLine->setText("");
1233 myCurrentLineEdit = 0;
1235 setSelectionMode(myTypeId);
1237 myGroupBtn->setEnabled(on);
1238 myGroupLine->setEnabled(on);
1242 //=================================================================================
1243 // function : (onSelectGeomGroup)
1244 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1245 //=================================================================================
1246 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1249 if (mySelectSubMesh->isChecked()) {
1250 mySelectSubMesh->setChecked(false);
1252 else if (mySelectGroup->isChecked()) {
1253 mySelectGroup->setChecked(false);
1255 myCurrentLineEdit = myGeomGroupLine;
1257 setSelectionMode(8);
1260 myGeomGroupBtn->setChecked(false);
1261 myGeomObjects->length(0);
1262 myGeomGroupLine->setText("");
1263 myCurrentLineEdit = 0;
1265 setSelectionMode(myTypeId);
1270 //=================================================================================
1271 // function : setCurrentSelection()
1273 //=================================================================================
1274 void SMESHGUI_GroupDlg::setCurrentSelection()
1276 QPushButton* send = (QPushButton*)sender();
1277 myCurrentLineEdit = 0;
1278 if (send == myMeshGroupBtn) {
1279 myCurrentLineEdit = myMeshGroupLine;
1281 setSelectionMode(6);
1283 setSelectionMode(5);
1284 onObjectSelectionChanged();
1286 else if (send == mySubMeshBtn) {
1287 myCurrentLineEdit = mySubMeshLine;
1288 onObjectSelectionChanged();
1290 else if (send == myGroupBtn) {
1291 myCurrentLineEdit = myGroupLine;
1292 onObjectSelectionChanged();
1297 //=================================================================================
1298 // function : setFilters()
1299 // purpose : SLOT. Called when "Filter" button pressed.
1300 //=================================================================================
1301 void SMESHGUI_GroupDlg::setFilters()
1303 SMESH::ElementType aType = SMESH::ALL;
1306 case 0 : aType = SMESH::NODE; break;
1307 case 1 : aType = SMESH::EDGE; break;
1308 case 2 : aType = SMESH::FACE; break;
1309 case 3 : aType = SMESH::VOLUME; break;
1313 if ( myFilterDlg == 0 )
1315 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1316 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1319 myFilterDlg->Init( aType );
1321 myFilterDlg->SetSelection();
1322 myFilterDlg->SetMesh( myMesh );
1323 myFilterDlg->SetSourceWg( myElements );
1325 myFilterDlg->show();
1328 //=================================================================================
1329 // function : onFilterAccepted()
1330 // purpose : SLOT. Called when Filter dlg closed with OK button.
1331 // Uncheck "Select submesh" and "Select group" checkboxes
1332 //=================================================================================
1333 void SMESHGUI_GroupDlg::onFilterAccepted()
1335 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1337 mySelectionMode = myTypeId;
1338 mySelectSubMesh->setChecked( false );
1339 mySelectGroup->setChecked( false );
1343 //=================================================================================
1344 // function : onAdd()
1346 //=================================================================================
1347 void SMESHGUI_GroupDlg::onAdd()
1349 SALOME_ListIO aList;
1350 mySelectionMgr->selectedObjects( aList );
1352 int aNbSel = aList.Extent();
1354 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1358 SMESH::ElementType aType = SMESH::ALL;
1361 aType = SMESH::NODE;
1362 mySelector->SetSelectionMode(NodeSelection);
1365 aType = SMESH::EDGE;
1366 mySelector->SetSelectionMode(EdgeSelection);
1369 aType = SMESH::FACE;
1370 mySelector->SetSelectionMode(FaceSelection);
1373 aType = SMESH::VOLUME;
1374 mySelector->SetSelectionMode(VolumeSelection);
1377 mySelector->SetSelectionMode(ActorSelection);
1380 QListWidgetItem* anItem = 0;
1381 QList<QListWidgetItem*> listItemsToSel;
1383 if (myCurrentLineEdit == 0) {
1384 //if (aNbSel != 1) { myIsBusy = false; return; }
1385 QString aListStr = "";
1387 if (myTypeId == 0) {
1388 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1391 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1394 QStringList anElements = aListStr.split(" ", QString::SkipEmptyParts);
1395 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1396 QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1397 if (found.count() == 0) {
1398 anItem = new QListWidgetItem(*it);
1399 myElements->addItem(anItem);
1400 if (!anItem->isSelected())
1401 listItemsToSel.push_back(anItem);
1404 foreach(anItem, found)
1405 if (!anItem->isSelected())
1406 listItemsToSel.push_back(anItem);
1409 bool blocked = myElements->signalsBlocked();
1410 myElements->blockSignals(true);
1411 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1412 myElements->blockSignals(blocked);
1413 onListSelectionChanged();
1414 listItemsToSel.clear();
1416 } else if (myCurrentLineEdit == mySubMeshLine) {
1417 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1419 SALOME_ListIO aList;
1420 mySelectionMgr->selectedObjects( aList );
1422 SALOME_ListIteratorOfListIO anIt (aList);
1423 for ( ; anIt.More(); anIt.Next()) {
1424 SMESH::SMESH_subMesh_var aSubMesh =
1425 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1426 if (!aSubMesh->_is_nil()) {
1427 // check if mesh is the same
1428 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1430 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1431 int k = anElements->length();
1432 for (int i = 0; i < k; i++) {
1433 QString aText = QString::number(anElements[i]);
1434 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1435 if (found.count() == 0) {
1436 anItem = new QListWidgetItem(aText);
1437 myElements->addItem(anItem);
1438 if (!anItem->isSelected())
1439 listItemsToSel.push_back(anItem);
1442 foreach(anItem, found)
1443 if (!anItem->isSelected())
1444 listItemsToSel.push_back(anItem);
1447 bool blocked = myElements->signalsBlocked();
1448 myElements->blockSignals(true);
1449 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1450 myElements->blockSignals(blocked);
1451 onListSelectionChanged();
1452 listItemsToSel.clear();
1454 catch (const SALOME::SALOME_Exception& ex) {
1455 SalomeApp_Tools::QtCatchCorbaException(ex);
1460 mySelectSubMesh->setChecked(false);
1462 onListSelectionChanged();
1464 } else if (myCurrentLineEdit == myGroupLine) {
1465 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1466 SALOME_ListIO aList;
1467 mySelectionMgr->selectedObjects( aList );
1469 SALOME_ListIteratorOfListIO anIt (aList);
1470 for ( ; anIt.More(); anIt.Next()) {
1471 SMESH::SMESH_Group_var aGroup =
1472 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1473 if (!aGroup->_is_nil()) {
1474 // check if mesh is the same
1475 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1476 SMESH::long_array_var anElements = aGroup->GetListOfID();
1477 int k = anElements->length();
1478 for (int i = 0; i < k; i++) {
1479 QString aText = QString::number(anElements[i]);
1480 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1481 if (found.count() == 0) {
1482 anItem = new QListWidgetItem(aText);
1483 myElements->addItem(anItem);
1484 if (!anItem->isSelected())
1485 listItemsToSel.push_back(anItem);
1488 foreach(anItem, found)
1489 if (!anItem->isSelected())
1490 listItemsToSel.push_back(anItem);
1493 bool blocked = myElements->signalsBlocked();
1494 myElements->blockSignals(true);
1495 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1496 myElements->blockSignals(blocked);
1497 onListSelectionChanged();
1498 listItemsToSel.clear();
1502 mySelectGroup->setChecked(false);
1504 onListSelectionChanged();
1506 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1507 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1508 GEOM::GEOM_IGroupOperations_var aGroupOp =
1509 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1511 SMESH::ElementType aGroupType = SMESH::ALL;
1512 switch(aGroupOp->GetType(myGeomObjects[0])) {
1513 case 7: aGroupType = SMESH::NODE; break;
1514 case 6: aGroupType = SMESH::EDGE; break;
1515 case 4: aGroupType = SMESH::FACE; break;
1516 case 2: aGroupType = SMESH::VOLUME; break;
1517 default: myIsBusy = false; return;
1520 if (aGroupType == aType) {
1521 _PTR(SObject) aGroupSO =
1522 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1523 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1525 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1526 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1527 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1528 aBelongToGeom->SetGeom(myGeomObjects[0]);
1529 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1530 aBelongToGeom->SetElementType(aType);
1531 aFilter->SetPredicate(aBelongToGeom);
1533 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1535 int k = anElements->length();
1536 for (int i = 0; i < k; i++) {
1537 QString aText = QString::number(anElements[i]);
1538 QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1539 if (found.count() == 0) {
1540 anItem = new QListWidgetItem(aText);
1541 myElements->addItem(anItem);
1542 if (!anItem->isSelected())
1543 listItemsToSel.push_back(anItem);
1546 foreach(anItem, found)
1547 if (!anItem->isSelected())
1548 listItemsToSel.push_back(anItem);
1551 bool blocked = myElements->signalsBlocked();
1552 myElements->blockSignals(true);
1553 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1554 myElements->blockSignals(blocked);
1555 onListSelectionChanged();
1556 listItemsToSel.clear();
1559 //VSR: mySelectGeomGroup->setChecked(false);
1561 onListSelectionChanged();
1564 // mySelectionMgr->clearSelected();
1568 //=================================================================================
1569 // function : onRemove()
1571 //=================================================================================
1572 void SMESHGUI_GroupDlg::onRemove()
1575 if (myCurrentLineEdit == 0) {
1576 QList<QListWidgetItem*> selItems = myElements->selectedItems();
1577 QListWidgetItem* item;
1578 foreach(item, selItems) delete item;
1580 SALOME_ListIO aList;
1581 mySelectionMgr->selectedObjects( aList );
1583 int aNbSel = aList.Extent();
1585 if (aNbSel == 0) { myIsBusy = false; return; }
1587 SMESH::ElementType aType = SMESH::ALL;
1589 case 0: aType = SMESH::NODE; break;
1590 case 1: aType = SMESH::EDGE; break;
1591 case 2: aType = SMESH::FACE; break;
1592 case 3: aType = SMESH::VOLUME; break;
1595 if (myCurrentLineEdit == mySubMeshLine) {
1596 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1597 SALOME_ListIO aList;
1598 mySelectionMgr->selectedObjects( aList );
1600 SALOME_ListIteratorOfListIO anIt (aList);
1601 for ( ; anIt.More(); anIt.Next()) {
1602 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1603 if (!aSubMesh->_is_nil()) {
1604 // check if mesh is the same
1605 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1606 if (aType == SMESH::NODE) {
1608 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1609 int k = anElements->length();
1610 for (int i = 0; i < k; i++) {
1611 QList<QListWidgetItem*> found =
1612 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1613 QListWidgetItem* anItem;
1614 foreach(anItem, found) delete anItem;
1617 catch (const SALOME::SALOME_Exception& ex) {
1618 SalomeApp_Tools::QtCatchCorbaException(ex);
1623 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1624 int k = anElements->length();
1625 for (int i = 0; i < k; i++) {
1626 QList<QListWidgetItem*> found =
1627 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1628 QListWidgetItem* anItem;
1629 foreach(anItem, found) delete anItem;
1632 catch (const SALOME::SALOME_Exception& ex) {
1633 SalomeApp_Tools::QtCatchCorbaException(ex);
1640 else if (myCurrentLineEdit == myGroupLine) {
1641 Standard_Boolean aRes;
1642 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1643 SALOME_ListIO aList;
1644 mySelectionMgr->selectedObjects( aList );
1646 SALOME_ListIteratorOfListIO anIt (aList);
1647 for ( ; anIt.More(); anIt.Next()) {
1648 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1649 if (aRes && !aGroup->_is_nil()) {
1650 // check if mesh is the same
1651 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1652 SMESH::long_array_var anElements = aGroup->GetListOfID();
1653 int k = anElements->length();
1654 for (int i = 0; i < k; i++) {
1655 QList<QListWidgetItem*> found =
1656 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1657 QListWidgetItem* anItem;
1658 foreach(anItem, found) delete anItem;
1669 //=================================================================================
1670 // function : onSort()
1672 //=================================================================================
1673 void SMESHGUI_GroupDlg::onSort()
1675 // PAL5412: sorts items in ascending by "string" value
1676 // myElements->sort(true);
1677 // myElements->update();
1678 int i, k = myElements->count();
1681 QList<int> aSelected;
1682 std::vector<int> anArray(k);
1683 // QMemArray<int> anArray(k);
1685 for (i = 0; i < k; i++) {
1686 int id = myElements->item(i)->text().toInt();
1688 if (myElements->item(i)->isSelected())
1689 aSelected.append(id);
1691 // sort & update list
1692 std::sort(anArray.begin(), anArray.end());
1694 myElements->clear();
1695 QListWidgetItem* anItem;
1696 QList<QListWidgetItem*> listItemsToSel;
1697 for (i = 0; i < k; i++) {
1698 anItem = new QListWidgetItem(QString::number(anArray[i]));
1699 myElements->addItem(anItem);
1700 if (aSelected.contains(anArray[i]))
1701 listItemsToSel.push_back(anItem);
1703 bool blocked = myElements->signalsBlocked();
1704 myElements->blockSignals(true);
1705 foreach(anItem, listItemsToSel) anItem->setSelected(true);
1706 myElements->blockSignals(blocked);
1707 listItemsToSel.clear();
1712 //=================================================================================
1713 // function : closeEvent()
1715 //=================================================================================
1716 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1721 //=================================================================================
1722 // function : SMESHGUI_GroupDlg::onClose
1723 // purpose : SLOT called when "Close" button pressed. Close dialog
1724 //=================================================================================
1725 void SMESHGUI_GroupDlg::onClose()
1727 if (SMESH::GetCurrentVtkView()) {
1728 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1729 SMESH::SetPointRepresentation(false);
1730 SMESH::SetPickable();
1733 mySelectionMgr->clearSelected();
1734 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1735 aViewWindow->SetSelectionMode(ActorSelection);
1736 mySelectionMgr->clearFilters();
1737 mySMESHGUI->ResetState();
1742 //=================================================================================
1743 // function : onHelp()
1745 //=================================================================================
1746 void SMESHGUI_GroupDlg::onHelp()
1748 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1750 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1754 platform = "winapplication";
1756 platform = "application";
1758 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
1759 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1760 arg(app->resourceMgr()->stringValue("ExternalBrowser",
1762 arg(myHelpFileName));
1766 //=================================================================================
1767 // function : SMESHGUI_GroupDlg::onDeactivate
1768 // purpose : SLOT called when dialog must be deativated
1769 //=================================================================================
1770 void SMESHGUI_GroupDlg::onDeactivate()
1772 mySMESHGUI->ResetState();
1776 //=================================================================================
1777 // function : SMESHGUI_GroupDlg::enterEvent
1778 // purpose : Event filter
1779 //=================================================================================
1780 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1783 mySMESHGUI->EmitSignalDeactivateDialog();
1785 mySelectionMode = -1;
1786 setSelectionMode(myTypeId);
1787 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1788 mySMESHGUI->SetActiveDialogBox(this);
1789 mySMESHGUI->SetState(800);
1793 //=================================================================================
1794 // function : hideEvent
1795 // purpose : caused by ESC key
1796 //=================================================================================
1797 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1799 if (!isMinimized() && !myIsBusy)
1803 //=================================================================================
1804 // function : keyPressEvent()
1806 //=================================================================================
1807 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1809 QDialog::keyPressEvent( e );
1810 if ( e->isAccepted() )
1813 if ( e->key() == Qt::Key_F1 )
1820 //================================================================================
1822 * \brief Enable showing of the popup when Geometry selection btn is clicked
1823 * \param enable - true to enable
1825 //================================================================================
1827 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1829 void SMESHGUI_GroupDlg::updateGeomPopup()
1831 bool enable = false;
1833 if ( !myMesh->_is_nil() )
1834 enable = myMesh->NbEdges() > 0;
1836 if ( myGeomGroupBtn )
1838 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1840 if ( !myGeomPopup ) {
1841 myGeomPopup = new QMenu(this);
1842 myActions[myGeomPopup->addAction( tr("DIRECT_GEOM_SELECTION") )] = DIRECT_GEOM_INDEX;
1843 myActions[myGeomPopup->addAction( tr("GEOM_BY_MESH_ELEM_SELECTION") )] = GEOM_BY_MESH_INDEX;
1844 connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
1846 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1852 //=================================================================================
1853 // function : onGeomSelectionButton()
1855 //=================================================================================
1856 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1858 if ( myGeomPopup && isBtnOn )
1860 myCurrentLineEdit = myGeomGroupLine;
1861 QAction* a = myGeomPopup->exec( QCursor::pos() );
1862 if (!a || myActions[a] == DIRECT_GEOM_INDEX)
1863 setSelectionMode(7);
1867 myCurrentLineEdit = 0;
1868 setSelectionMode(8);
1872 //=================================================================================
1873 // function : onGeomPopup()
1875 //=================================================================================
1876 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
1878 int index = myActions[a];
1879 if ( index == GEOM_BY_MESH_INDEX )
1881 mySelectionMode = -1;
1882 if ( !myShapeByMeshOp ) {
1883 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1884 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1885 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1886 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1887 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1889 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1890 if ( !myMesh->_is_nil() ) {
1892 hide(); // stop processing selection
1894 myShapeByMeshOp->setModule( mySMESHGUI );
1895 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1896 myShapeByMeshOp->SetMesh( myMesh );
1897 myShapeByMeshOp->start();
1902 //================================================================================
1904 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1906 //================================================================================
1908 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1910 if ( myShapeByMeshOp == op ) {
1911 mySMESHGUI->getApp()->updateObjectBrowser();
1913 // Select a found geometry object
1914 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1915 if ( !aGeomVar->_is_nil() )
1917 QString ID = aGeomVar->GetStudyEntry();
1918 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1919 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
1920 SALOME_ListIO anIOList;
1921 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1922 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1923 anIOList.Append( anIO );
1924 mySelectionMgr->setSelectedObjects( anIOList, false );
1925 onObjectSelectionChanged();
1931 //================================================================================
1933 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1935 //================================================================================
1937 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1939 if ( myShapeByMeshOp == op )
1942 setSelectionMode(7);
1946 //=================================================================================
1947 // function : setGroupColor()
1949 //=================================================================================
1950 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
1952 QColor aQColor( (int)( theColor.R * 255.0 ),
1953 (int)( theColor.G * 255.0 ),
1954 (int)( theColor.B * 255.0 ) );
1955 setGroupQColor( aQColor );
1958 //=================================================================================
1959 // function : getGroupColor()
1961 //=================================================================================
1962 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
1964 QColor aQColor = getGroupQColor();
1966 SALOMEDS::Color aColor;
1967 aColor.R = (float)aQColor.red() / 255.0;
1968 aColor.G = (float)aQColor.green() / 255.0;
1969 aColor.B = (float)aQColor.blue() / 255.0;
1974 //=================================================================================
1975 // function : setGroupQColor()
1977 //=================================================================================
1978 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
1980 if( theColor.isValid() )
1981 myColorBtn->setColor( theColor );
1984 //=================================================================================
1985 // function : getGroupQColor()
1987 //=================================================================================
1988 QColor SMESHGUI_GroupDlg::getGroupQColor() const
1990 return myColorBtn->color();
1993 //=================================================================================
1994 // function : setDefaultGroupColor()
1996 //=================================================================================
1997 void SMESHGUI_GroupDlg::setDefaultGroupColor()
1999 if( myMesh->_is_nil() )
2002 bool isAutoColor = myMesh->GetAutoColor();
2007 int r = 0, g = 0, b = 0;
2008 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2009 aQColor.setRgb( r, g, b );
2013 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2015 QList<SALOMEDS::Color> aReservedColors;
2016 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2018 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2019 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2020 aReservedColors.append( aReservedColor );
2023 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2024 aQColor.setRgb( (int)( aColor.R * 255.0 ),
2025 (int)( aColor.G * 255.0 ),
2026 (int)( aColor.B * 255.0 ) );
2030 setGroupQColor( aQColor );