1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESHGUI_GroupDlg.cxx
25 // Author : Natalia KOPNOVA
29 #include "SMESHGUI_GroupDlg.h"
30 #include "SMESHGUI_FilterDlg.h"
31 #include "SMESHGUI_ShapeByMeshDlg.h"
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_VTKUtils.h"
36 #include "SMESHGUI_MeshUtils.h"
37 #include "SMESHGUI_GroupUtils.h"
38 #include "SMESHGUI_FilterUtils.h"
39 #include "SMESHGUI_GEOMGenUtils.h"
41 #include "SMESH_TypeFilter.hxx"
42 #include "SMESH_Actor.h"
45 #include "GEOM_SelectionFilter.h"
47 #include "SUIT_Desktop.h"
48 #include "SUIT_ResourceMgr.h"
49 #include "SUIT_Session.h"
50 #include "SUIT_MessageBox.h"
52 #include "SalomeApp_Tools.h"
53 #include "SalomeApp_Application.h"
54 #include "SalomeApp_Study.h"
55 #include "LightApp_Application.h"
56 #include "SALOMEDSClient_Study.hxx"
57 #include "SALOME_ListIO.hxx"
58 #include "SALOME_ListIteratorOfListIO.hxx"
60 #include "SVTK_ViewWindow.h"
61 #include "SVTK_Selector.h"
63 #include "utilities.h"
66 #include <TColStd_MapOfInteger.hxx>
69 #include <qbuttongroup.h>
71 #include <qgroupbox.h>
74 #include <qlineedit.h>
75 #include <qpushbutton.h>
76 #include <qtoolbutton.h>
77 #include <qradiobutton.h>
78 #include <qcheckbox.h>
83 #include <qmemarray.h>
84 #include <qwidgetstack.h>
86 #include <QtxIntSpinBox.h>
94 //=================================================================================
95 // function : SMESHGUI_GroupDlg()
97 //=================================================================================
98 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
99 SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl)
100 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
101 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
102 mySMESHGUI( theModule ),
103 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
104 mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
108 if (!name) setName("SMESHGUI_GroupDlg");
110 if (!theMesh->_is_nil())
113 mySelectSubMesh->setEnabled(false);
114 mySelectGroup->setEnabled(false);
115 myGeomGroupBtn->setEnabled(false);
116 myGeomGroupLine->setEnabled(false);
120 //=================================================================================
121 // function : SMESHGUI_GroupDlg()
123 //=================================================================================
124 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
125 SMESH::SMESH_GroupBase_ptr theGroup, bool modal, WFlags fl)
126 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
127 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
128 mySMESHGUI( theModule ),
129 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
130 mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
133 if (!name) setName("SMESHGUI_GroupDlg");
136 if (!theGroup->_is_nil())
139 mySelectSubMesh->setEnabled(false);
140 mySelectGroup->setEnabled(false);
142 myCurrentLineEdit = myMeshGroupLine;
147 //=================================================================================
148 // function : SMESHGUI_GroupDlg()
150 //=================================================================================
151 void SMESHGUI_GroupDlg::initDialog(bool create)
155 myCurrentLineEdit = 0;
159 myGeomObjects = new GEOM::ListOfGO();
160 myGeomObjects->length(0);
162 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
165 setCaption(tr("SMESH_CREATE_GROUP_TITLE"));
166 myHelpFileName = "/files/creating_groups.htm";
169 setCaption(tr("SMESH_EDIT_GROUP_TITLE"));
170 myHelpFileName = "/files/editing_groups.htm";
173 setSizeGripEnabled(TRUE);
175 QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
177 /***************************************************************/
178 QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
180 meshGroupLab->setText(tr("SMESH_MESH"));
182 meshGroupLab->setText(tr("SMESH_GROUP"));
183 myMeshGroupBtn = new QPushButton(this, "mesh/group button");
184 myMeshGroupBtn->setPixmap(image0);
185 myMeshGroupLine = new QLineEdit(this, "mesh/group line");
186 myMeshGroupLine->setReadOnly(true);
188 /***************************************************************/
189 myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
190 myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
191 myTypeGroup->setExclusive(true);
194 types.append(tr("MESH_NODE"));
195 types.append(tr("SMESH_EDGE"));
196 types.append(tr("SMESH_FACE"));
197 types.append(tr("SMESH_VOLUME"));
199 for (int i = 0; i < types.count(); i++) {
200 rb = new QRadioButton(types[i], myTypeGroup);
202 myTypeGroup->setEnabled(create);
205 /***************************************************************/
206 QLabel* aName = new QLabel(this, "name label");
207 aName->setText(tr("SMESH_NAME"));
208 aName->setMinimumSize(50,0);
209 myName = new QLineEdit(this, "name");
211 /***************************************************************/
212 myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
213 myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
214 myGrpTypeGroup->setExclusive(true);
215 QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
216 QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"), myGrpTypeGroup);
217 myGrpTypeGroup->setEnabled(create);
220 /***************************************************************/
221 myWGStack = new QWidgetStack( this, "widget stack");
222 QWidget* wg1 = new QFrame( myWGStack, "first widget" );
223 QWidget* wg2 = new QFrame( myWGStack, "second widget" );
225 /***************************************************************/
226 QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
227 aContentBox->setTitle(tr("SMESH_CONTENT"));
228 QFrame* aContent = new QFrame(aContentBox, "content");
229 QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
230 aLayout->setSpacing(6);
231 aLayout->setAutoAdd(false);
233 QLabel* aLabel = new QLabel(aContent, "elements label");
234 aLabel->setText(tr("SMESH_ID_ELEMENTS"));
235 myElements = new QListBox(aContent, "elements list");
236 myElements->setSelectionMode(QListBox::Extended);
238 myFilter = new QPushButton(aContent, "filter");
239 myFilter->setText(tr("SMESH_BUT_FILTER"));
240 QPushButton* aAddBtn = new QPushButton(aContent, "add");
241 aAddBtn->setText(tr("SMESH_BUT_ADD"));
242 QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
243 aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
244 QPushButton* aSortBtn = new QPushButton(aContent, "sort");
245 aSortBtn->setText(tr("SMESH_BUT_SORT"));
247 aLayout->addWidget(aLabel, 0, 0);
248 aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
249 aLayout->addWidget(myFilter, 1, 2);
250 aLayout->addWidget(aAddBtn, 3, 2);
251 aLayout->addWidget(aRemoveBtn, 4, 2);
252 aLayout->addWidget(aSortBtn, 6, 2);
254 aLayout->setColStretch(0, 1);
255 aLayout->addColSpacing(1, 20);
256 aLayout->addColSpacing(3, 20);
257 aLayout->setRowStretch(2, 1);
258 aLayout->setRowStretch(5, 1);
260 /***************************************************************/
261 QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
262 aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
264 mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
265 mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
266 mySelectSubMesh->setMinimumSize(50, 0);
267 mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
268 mySubMeshBtn->setText("");
269 mySubMeshBtn->setPixmap(image0);
270 mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
271 mySubMeshLine->setReadOnly(true);
272 onSelectSubMesh(false);
274 mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
275 mySelectGroup->setText(tr("SMESH_GROUP"));
276 mySelectGroup->setMinimumSize(50, 0);
277 myGroupBtn = new QPushButton(aSelectBox, "group button");
278 myGroupBtn->setText("");
279 myGroupBtn->setPixmap(image0);
280 myGroupLine = new QLineEdit(aSelectBox, "group line");
281 myGroupLine->setReadOnly(true);
282 onSelectGroup(false);
284 /***************************************************************/
285 QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
286 wg1Layout->addWidget(aContentBox, 0, 0);
287 wg1Layout->addWidget(aSelectBox, 1, 0);
288 wg1Layout->setRowStretch(2, 5);
290 /***************************************************************/
291 QLabel* geomObject = new QLabel(wg2, "geometry object label");
292 geomObject->setText(tr("SMESH_OBJECT_GEOM"));
293 myGeomGroupBtn = new QToolButton(wg2, "geometry group button");
294 myGeomGroupBtn->setIconSet( QIconSet(image0) );
295 myGeomGroupBtn->setToggleButton(true);
296 myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
297 myGeomGroupLine->setReadOnly(true); //VSR ???
298 onSelectGeomGroup(false);
302 myGeomGroupBtn->setEnabled(false);
303 myGeomGroupLine->setEnabled(false);
306 /***************************************************************/
307 QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
308 wg2Layout->addWidget(geomObject, 0, 0);
309 wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
310 wg2Layout->addWidget(myGeomGroupLine,0, 2);
311 wg2Layout->setRowStretch(1, 5);
313 /***************************************************************/
314 QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
315 dumb->addWidget(wg1);
316 dumb->addWidget(wg2);
317 myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
318 myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
320 /***************************************************************/
321 QGroupBox* aColorBox = new QGroupBox(2, Qt::Horizontal, this, "color box");
322 aColorBox->setTitle(tr("SMESH_SET_COLOR"));
324 mySelectColorGroup = new QCheckBox(aColorBox, "color checkbox");
325 mySelectColorGroup->setText(tr("SMESH_CHECK_COLOR"));
327 myColorSpinBox = new QtxIntSpinBox( aColorBox );
328 myColorSpinBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
329 myColorSpinBox->setMinValue( 0 );
330 myColorSpinBox->setMaxValue( 9999 );
332 onSelectColorGroup(false);
334 /***************************************************************/
336 QFrame* aButtons = new QFrame(this, "button box");
337 aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
338 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
339 aBtnLayout->setAutoAdd(false);
341 QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
342 aOKBtn->setText(tr("SMESH_BUT_OK"));
343 aOKBtn->setAutoDefault(true);
344 aOKBtn->setDefault(true);
345 QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
346 aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
347 aApplyBtn->setAutoDefault(true);
348 QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
349 aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
350 aCloseBtn->setAutoDefault(true);
351 QPushButton* aHelpBtn = new QPushButton(aButtons, "help");
352 aHelpBtn->setText(tr("SMESH_BUT_HELP"));
353 aHelpBtn->setAutoDefault(true);
355 aBtnLayout->addWidget(aOKBtn);
356 aBtnLayout->addWidget(aApplyBtn);
357 aBtnLayout->addStretch();
358 aBtnLayout->addWidget(aCloseBtn);
359 aBtnLayout->addWidget(aHelpBtn);
361 /***************************************************************/
362 aMainLayout->addWidget(meshGroupLab, 0, 0);
363 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
364 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
365 aMainLayout->addMultiCellWidget(myTypeGroup, 1, 1, 0, 2);
366 aMainLayout->addWidget(aName, 2, 0);
367 aMainLayout->addWidget(myName, 2, 2);
368 aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
369 aMainLayout->addMultiCellWidget(myWGStack, 4, 4, 0, 2);
370 aMainLayout->setRowStretch( 5, 5 );
371 aMainLayout->addMultiCellWidget(aColorBox, 6, 6, 0, 2);
372 aMainLayout->addMultiCellWidget(aButtons, 7, 7, 0, 2);
374 /* signals and slots connections */
375 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
377 connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
379 connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
381 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
382 connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
384 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
385 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
386 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
387 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
389 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
390 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
391 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
392 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
393 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
394 connect(mySelectColorGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectColorGroup(bool)));
395 connect(myColorSpinBox, SIGNAL(valueChanged(const QString&)), this, SLOT(onNbColorsChanged(const QString&)));
397 connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
398 connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
399 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
400 connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
403 mySMESHGUI->SetActiveDialogBox(this);
404 mySMESHGUI->SetState(800);
406 mySelectionMode = -1;
407 myMeshFilter = new SMESH_TypeFilter(MESH);
408 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
409 myGroupFilter = new SMESH_TypeFilter(GROUP);
410 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
411 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
413 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
414 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
415 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
417 myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
418 onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
420 if (myMesh->_is_nil() )
421 myTypeGroup->setButton(0);
426 //=================================================================================
427 // function : ~SMESHGUI_GroupDlg()
428 // purpose : Destroys the object and frees any allocated resources
429 //=================================================================================
430 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
432 // no need to delete child widgets, Qt does it all for us
433 if ( myFilterDlg != 0 )
435 myFilterDlg->reparent( 0, QPoint() );
440 //=================================================================================
443 //=================================================================================
444 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
446 mySelectionMgr->installFilter(myMeshFilter);
448 /* init data from current selection */
449 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
450 myGroup = SMESH::SMESH_Group::_nil();
451 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
453 myActor = SMESH::FindActorByObject(myMesh);
454 SMESH::SetPickable(myActor);
457 mySelectionMgr->selectedObjects( aList );
458 if( !aList.IsEmpty() )
460 QString aName = aList.First()->getName();
461 myMeshGroupLine->setText(aName) ;
462 myMeshGroupLine->home( false );
465 myCurrentLineEdit = 0;
467 myTypeGroup->setButton(0);
471 //=================================================================================
474 //=================================================================================
475 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
477 myMesh = theGroup->GetMesh();
479 myName->setText(theGroup->GetName());
482 myColorSpinBox->setValue( theGroup->GetColorNumber() );
484 myMeshGroupLine->setText(theGroup->GetName());
487 switch(theGroup->GetType()) {
488 case SMESH::NODE: aType= 0; break;
489 case SMESH::EDGE: aType = 1; break;
490 case SMESH::FACE: aType = 2; break;
491 case SMESH::VOLUME: aType = 3; break;
493 myTypeGroup->setButton(aType);
495 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
497 if ( !myGroup->_is_nil() )
499 myActor = SMESH::FindActorByObject(myMesh);
501 myActor = SMESH::FindActorByObject(myGroup);
502 SMESH::SetPickable(myActor);
504 myGrpTypeGroup->setButton(0);
507 myCurrentLineEdit = 0;
509 setSelectionMode(aType);
513 if (!myGroup->IsEmpty()) {
514 SMESH::long_array_var anElements = myGroup->GetListOfID();
515 int k = anElements->length();
516 for (int i = 0; i < k; i++) {
517 myIdList.append(anElements[i]);
518 myElements->insertItem(QString::number(anElements[i]));
520 myElements->selectAll(true);
525 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
527 if ( !myGroupOnGeom->_is_nil() )
529 myActor = SMESH::FindActorByObject(myMesh);
531 myActor = SMESH::FindActorByObject(myGroup);
532 SMESH::SetPickable(myActor);
534 myGrpTypeGroup->setButton(1);
537 QString aShapeName("");
538 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
539 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
540 if (!aGroupShape->_is_nil())
542 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
543 aShapeName = aGroupShapeSO->GetName().c_str();
545 myGeomGroupLine->setText( aShapeName );
550 //=================================================================================
551 // function : updateButtons()
553 //=================================================================================
554 void SMESHGUI_GroupDlg::updateButtons()
558 if (myGrpTypeId == 0)
559 enable = !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0;
560 else if (myGrpTypeId == 1)
562 bool isEditMode = !CORBA::is_nil( myGroupOnGeom );
563 enable = !myName->text().stripWhiteSpace().isEmpty() && (myGeomObjects->length() > 0 || isEditMode);
566 aBtn = (QPushButton*) child("ok", "QPushButton");
567 if (aBtn) aBtn->setEnabled(enable);
568 aBtn = (QPushButton*) child("apply", "QPushButton");
569 if (aBtn) aBtn->setEnabled(enable);
572 //=================================================================================
573 // function : onNameChanged()
575 //=================================================================================
576 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
581 //=================================================================================
582 // function : onNbColorsChanged()
584 //=================================================================================
585 void SMESHGUI_GroupDlg::onNbColorsChanged (const QString& text)
590 //=================================================================================
591 // function : onTypeChanged()
592 // purpose : Group elements type radio button management
593 //=================================================================================
594 void SMESHGUI_GroupDlg::onTypeChanged (int id)
596 if (myTypeId != id) {
598 if (myCurrentLineEdit == 0)
599 setSelectionMode(id);
604 //=================================================================================
605 // function : onGrpTypeChanged()
606 // purpose : Group type radio button management
607 //=================================================================================
608 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
610 if (myGrpTypeId != id) {
611 myWGStack->raiseWidget( id );
612 onSelectGeomGroup(id == 1);
617 //=================================================================================
618 // function : setSelectionMode()
619 // purpose : Radio button management
620 //=================================================================================
621 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
624 if (myMesh->_is_nil())
626 if (mySelectionMode != theMode) {
627 // [PAL10408] mySelectionMgr->clearSelected();
628 mySelectionMgr->clearFilters();
630 myActor->SetPointRepresentation(false);
632 SMESH::SetPointRepresentation(false);
637 myActor->SetPointRepresentation(true);
639 SMESH::SetPointRepresentation(true);
640 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
641 aViewWindow->SetSelectionMode(NodeSelection);
644 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
645 aViewWindow->SetSelectionMode(EdgeSelection);
648 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
649 aViewWindow->SetSelectionMode(FaceSelection);
652 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
653 aViewWindow->SetSelectionMode(VolumeSelection);
657 mySelectionMgr->installFilter(mySubMeshFilter);
658 else if (theMode == 5)
659 mySelectionMgr->installFilter(myGroupFilter);
660 else if (theMode == 6)
661 mySelectionMgr->installFilter(myMeshFilter);
662 else if (theMode == 7)
663 mySelectionMgr->installFilter(myGeomFilter);
665 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
666 aViewWindow->SetSelectionMode(ActorSelection);
668 mySelectionMode = theMode;
672 //=================================================================================
673 // function : onApply()
675 //=================================================================================
676 bool SMESHGUI_GroupDlg::onApply()
678 if (mySMESHGUI->isActiveStudyLocked())
681 if (myGrpTypeId == 0 &&
682 !myName->text().stripWhiteSpace().isEmpty() &&
683 myElements->count() > 0) {
684 mySelectionMgr->clearSelected();
685 if (myGroup->_is_nil()) {
686 SMESH::ElementType aType = SMESH::ALL;
688 case 0: aType = SMESH::NODE; break;
689 case 1: aType = SMESH::EDGE; break;
690 case 2: aType = SMESH::FACE; break;
691 case 3: aType = SMESH::VOLUME; break;
693 SMESH::long_array_var anIdList = new SMESH::long_array;
694 int i, k = myElements->count();
696 QListBoxItem* anItem;
697 for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
698 anIdList[i] = anItem->text().toInt();
701 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
702 myGroup->Add(anIdList.inout());
704 int aColorNumber = myColorSpinBox->value();
705 myGroup->SetColorNumber(aColorNumber);
707 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
709 SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
711 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
713 /* init for next operation */
715 myColorSpinBox->setValue(0);
717 myGroup = SMESH::SMESH_Group::_nil();
720 myGroup->SetName(myName->text());
722 int aColorNumber = myColorSpinBox->value();
723 myGroup->SetColorNumber(aColorNumber);
725 QValueList<int> aAddList;
726 QValueList<int>::iterator anIt;
727 QListBoxItem* anItem;
729 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
730 int anId = anItem->text().toInt();
731 if ((anIt = myIdList.find(anId)) == myIdList.end())
732 aAddList.append(anId);
734 myIdList.remove(anIt);
736 if (!aAddList.empty()) {
737 SMESH::long_array_var anIdList = new SMESH::long_array;
738 anIdList->length(aAddList.count());
740 for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
742 myGroup->Add(anIdList.inout());
744 if (!myIdList.empty()) {
745 SMESH::long_array_var anIdList = new SMESH::long_array;
746 anIdList->length(myIdList.count());
748 for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
750 myGroup->Remove(anIdList.inout());
752 /* init for next operation */
754 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
755 myIdList.append(anItem->text().toInt());
758 mySMESHGUI->updateObjBrowser(true);
759 SMESH::UpdateView(); // asv: fix of BUG PAL5515
760 mySelectionMgr->clearSelected();
762 } else if (myGrpTypeId == 1 &&
763 !myName->text().stripWhiteSpace().isEmpty() &&
764 (myGeomObjects->length() > 0 || !CORBA::is_nil(myGroupOnGeom)))
766 if (myGroupOnGeom->_is_nil()) {
767 SMESH::ElementType aType = SMESH::ALL;
769 case 0: aType = SMESH::NODE; break;
770 case 1: aType = SMESH::EDGE; break;
771 case 2: aType = SMESH::FACE; break;
772 case 3: aType = SMESH::VOLUME; break;
775 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
776 GEOM::GEOM_IGroupOperations_var aGroupOp =
777 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
779 if (myGeomObjects->length() == 1)
780 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
783 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
784 if ( aSMESHGen->_is_nil() )
787 // create a geometry group
788 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
789 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
791 if (geomGen->_is_nil() || !aStudy)
794 GEOM::GEOM_IGroupOperations_var op =
795 geomGen->GetIGroupOperations(aStudy->StudyId());
799 // check and add all selected GEOM objects: they must be
800 // a sub-shapes of the main GEOM and must be of one type
801 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
802 for ( int i =0; i < myGeomObjects->length(); i++)
804 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
806 aGroupType = aSubShapeType;
807 else if (aSubShapeType != aGroupType)
809 aGroupType = TopAbs_SHAPE;
814 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
815 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
816 op->UnionList(aGroupVar, myGeomObjects);
819 // publish the GEOM group in study
820 QString aNewGeomGroupName ("Auto_group_for_");
821 aNewGeomGroupName += myName->text();
822 SALOMEDS::SObject_var aNewGroupSO =
823 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
826 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
829 int aColorNumber = myColorSpinBox->value();
830 myGroupOnGeom->SetColorNumber(aColorNumber);
832 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
834 SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
836 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
838 /* init for next operation */
840 myColorSpinBox->setValue(0);
841 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
845 myGroupOnGeom->SetName(myName->text());
847 int aColorNumber = myColorSpinBox->value();
848 myGroupOnGeom->SetColorNumber(aColorNumber);
851 mySMESHGUI->updateObjBrowser(true);
852 mySelectionMgr->clearSelected();
859 //=================================================================================
862 //=================================================================================
863 void SMESHGUI_GroupDlg::onOK()
869 //=================================================================================
870 // function : onListSelectionChanged()
871 // purpose : Called when selection in element list is changed
872 //=================================================================================
873 void SMESHGUI_GroupDlg::onListSelectionChanged()
875 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
876 if( myIsBusy || !myActor) return;
879 if (myCurrentLineEdit == 0) {
880 mySelectionMgr->clearSelected();
881 TColStd_MapOfInteger aIndexes;
882 QListBoxItem* anItem;
883 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
884 if (anItem->isSelected()) {
885 int anId = anItem->text().toInt();
889 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
891 aList.Append(myActor->getIO());
892 mySelectionMgr->setSelectedObjects(aList,false);
897 //=================================================================================
898 // function : onObjectSelectionChanged()
899 // purpose : Called when selection in 3D view or ObjectBrowser is changed
900 //=================================================================================
901 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
903 if ( myIsBusy || !isEnabled()) return;
904 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
909 mySelectionMgr->selectedObjects( aList );
911 int aNbSel = aList.Extent();
912 myElements->clearSelection();
914 if (myCurrentLineEdit) {
915 myCurrentLineEdit->setText("");
916 QString aString = "";
918 if (myCurrentLineEdit == myMeshGroupLine) {
919 mySelectSubMesh->setEnabled(false);
920 mySelectGroup->setEnabled(false);
921 myGroupLine->setText("");
922 mySubMeshLine->setText("");
924 myGeomGroupBtn->setEnabled(false);
925 myGeomGroupLine->setEnabled(false);
926 myGeomGroupLine->setText("");
927 if (myGeomGroupBtn->isOn())
928 myGeomGroupBtn->setOn(false);
935 myGroup = SMESH::SMESH_Group::_nil();
936 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
937 myMesh = SMESH::SMESH_Mesh::_nil();
942 Handle(SALOME_InteractiveObject) IO = aList.First();
945 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
947 if (myMesh->_is_nil())
952 myGroup = SMESH::SMESH_Group::_nil();
954 myActor = SMESH::FindActorByObject(myMesh);
955 SMESH::SetPickable(myActor);
957 aString = aList.First()->getName();
958 myMeshGroupLine->setText(aString) ;
959 myMeshGroupLine->home( false );
961 mySelectSubMesh->setEnabled(true);
962 mySelectGroup->setEnabled(true);
963 myGeomGroupBtn->setEnabled(true);
964 myGeomGroupLine->setEnabled(true);
967 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
968 if (aGroup->_is_nil())
974 myCurrentLineEdit = 0;
976 myGroup = SMESH::SMESH_Group::_nil();
977 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
981 mySelectSubMesh->setEnabled(true);
982 mySelectGroup->setEnabled(true);
984 myCurrentLineEdit = 0;
989 if (myGrpTypeId == 0)
996 setSelectionMode(myTypeId);
1003 } else if (myCurrentLineEdit == myGeomGroupLine) {
1005 myGeomObjects = new GEOM::ListOfGO();
1008 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1010 if (aNbSel == 0 || !aMeshSO)
1012 myGeomObjects->length(0);
1017 myGeomObjects->length(aNbSel);
1019 GEOM::GEOM_Object_var aGeomGroup;
1020 Standard_Boolean testResult;
1023 SALOME_ListIteratorOfListIO anIt (aList);
1024 for (; anIt.More(); anIt.Next()) {
1026 testResult = Standard_False;
1027 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1029 // Check if the object is a geometry group
1030 if (!testResult || CORBA::is_nil(aGeomGroup))
1034 // Check if group constructed on the same shape as a mesh or on its child
1035 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1036 GEOM::GEOM_IGroupOperations_var anOp =
1037 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1039 // The main shape of the group
1040 GEOM::GEOM_Object_var aGroupMainShape;
1041 if (aGeomGroup->GetType() == 37)
1042 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1044 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1045 _PTR(SObject) aGroupMainShapeSO =
1046 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1047 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1049 _PTR(SObject) anObj, aRef;
1050 bool isRefOrSubShape = false;
1051 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1052 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1053 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1054 isRefOrSubShape = true;
1056 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1057 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1058 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1059 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1060 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1061 if (aRef->GetID() == aFather->GetID())
1062 isRefOrSubShape = true;
1064 aFather = aFather->GetFather();
1068 if (isRefOrSubShape)
1069 myGeomObjects[i++] = aGeomGroup;
1072 myGeomObjects->length(i);
1084 if(myCurrentLineEdit == mySubMeshLine)
1085 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1086 else if(myCurrentLineEdit == myGroupLine)
1087 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1088 else if(myCurrentLineEdit == myGeomGroupLine)
1089 aString = tr("%1 Objects").arg(aNbSel);
1091 aString = aList.First()->getName();
1095 myCurrentLineEdit->setText(aString);
1096 myCurrentLineEdit->home(false);
1101 if (aNbSel == 1 && myActor ) {
1102 QString aListStr = "";
1104 if (myTypeId == 0) {
1105 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1107 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1110 QStringList anElements = QStringList::split(" ", aListStr);
1111 QListBoxItem* anItem = 0;
1112 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1113 anItem = myElements->findItem(*it, Qt::ExactMatch);
1114 if (anItem) myElements->setSelected(anItem, true);
1121 if (!myGroup->_is_nil())
1122 myActor = SMESH::FindActorByObject(myGroup);
1123 else if(!myGroupOnGeom->_is_nil())
1124 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1126 myActor = SMESH::FindActorByObject(myMesh);
1132 //=================================================================================
1133 // function : onSelectSubMesh()
1134 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1135 //=================================================================================
1136 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1139 if (mySelectGroup->isChecked()) {
1140 mySelectGroup->setChecked(false);
1142 //VSR: else if (mySelectGeomGroup->isChecked()) {
1143 //VSR: mySelectGeomGroup->setChecked(false);
1145 myCurrentLineEdit = mySubMeshLine;
1146 setSelectionMode(4);
1149 mySubMeshLine->setText("");
1150 myCurrentLineEdit = 0;
1152 setSelectionMode(myTypeId);
1154 mySubMeshBtn->setEnabled(on);
1155 mySubMeshLine->setEnabled(on);
1159 //=================================================================================
1160 // function : (onSelectGroup)
1161 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1162 //=================================================================================
1163 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1166 if (mySelectSubMesh->isChecked()) {
1167 mySelectSubMesh->setChecked(false);
1169 myCurrentLineEdit = myGroupLine;
1170 setSelectionMode(5);
1173 myGroupLine->setText("");
1174 myCurrentLineEdit = 0;
1176 setSelectionMode(myTypeId);
1178 myGroupBtn->setEnabled(on);
1179 myGroupLine->setEnabled(on);
1183 //=================================================================================
1184 // function : (onSelectGeomGroup)
1185 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1186 //=================================================================================
1187 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1190 if (mySelectSubMesh->isChecked()) {
1191 mySelectSubMesh->setChecked(false);
1193 else if (mySelectGroup->isChecked()) {
1194 mySelectGroup->setChecked(false);
1196 myCurrentLineEdit = myGeomGroupLine;
1198 setSelectionMode(8);
1201 myGeomGroupBtn->setOn(false);
1202 myGeomObjects->length(0);
1203 myGeomGroupLine->setText("");
1204 myCurrentLineEdit = 0;
1206 setSelectionMode(myTypeId);
1210 //=================================================================================
1211 // function : (onSelectColorGroup)
1212 // purpose : Called when setting a color on group
1213 //=================================================================================
1214 void SMESHGUI_GroupDlg::onSelectColorGroup(bool on)
1217 myColorSpinBox->setValue(0);
1219 myColorSpinBox->setEnabled(on);
1222 //=================================================================================
1223 // function : setCurrentSelection()
1225 //=================================================================================
1226 void SMESHGUI_GroupDlg::setCurrentSelection()
1228 QPushButton* send = (QPushButton*)sender();
1229 myCurrentLineEdit = 0;
1230 if (send == myMeshGroupBtn) {
1231 myCurrentLineEdit = myMeshGroupLine;
1233 setSelectionMode(6);
1235 setSelectionMode(5);
1236 onObjectSelectionChanged();
1238 else if (send == mySubMeshBtn) {
1239 myCurrentLineEdit = mySubMeshLine;
1240 onObjectSelectionChanged();
1242 else if (send == myGroupBtn) {
1243 myCurrentLineEdit = myGroupLine;
1244 onObjectSelectionChanged();
1249 //=================================================================================
1250 // function : setFilters()
1251 // purpose : SLOT. Called when "Filter" button pressed.
1252 //=================================================================================
1253 void SMESHGUI_GroupDlg::setFilters()
1255 SMESH::ElementType aType = SMESH::ALL;
1258 case 0 : aType = SMESH::NODE; break;
1259 case 1 : aType = SMESH::EDGE; break;
1260 case 2 : aType = SMESH::FACE; break;
1261 case 3 : aType = SMESH::VOLUME; break;
1265 if ( myFilterDlg == 0 )
1267 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1268 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1271 myFilterDlg->Init( aType );
1273 myFilterDlg->SetSelection();
1274 myFilterDlg->SetMesh( myMesh );
1275 myFilterDlg->SetSourceWg( myElements );
1277 myFilterDlg->show();
1280 //=================================================================================
1281 // function : onFilterAccepted()
1282 // purpose : SLOT. Called when Filter dlg closed with OK button.
1283 // Uncheck "Select submesh" and "Select group" checkboxes
1284 //=================================================================================
1285 void SMESHGUI_GroupDlg::onFilterAccepted()
1287 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1289 mySelectionMode = myTypeId;
1290 mySelectSubMesh->setChecked( false );
1291 mySelectGroup->setChecked( false );
1295 //=================================================================================
1296 // function : onAdd()
1298 //=================================================================================
1299 void SMESHGUI_GroupDlg::onAdd()
1301 SALOME_ListIO aList;
1302 mySelectionMgr->selectedObjects( aList );
1304 int aNbSel = aList.Extent();
1306 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1310 SMESH::ElementType aType = SMESH::ALL;
1313 aType = SMESH::NODE;
1314 mySelector->SetSelectionMode(NodeSelection);
1317 aType = SMESH::EDGE;
1318 mySelector->SetSelectionMode(EdgeSelection);
1321 aType = SMESH::FACE;
1322 mySelector->SetSelectionMode(FaceSelection);
1325 aType = SMESH::VOLUME;
1326 mySelector->SetSelectionMode(VolumeSelection);
1329 mySelector->SetSelectionMode(ActorSelection);
1333 if (myCurrentLineEdit == 0) {
1334 //if (aNbSel != 1) { myIsBusy = false; return; }
1335 QString aListStr = "";
1337 if (myTypeId == 0) {
1338 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1341 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1344 QStringList anElements = QStringList::split(" ", aListStr);
1345 QListBoxItem* anItem = 0;
1346 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1347 anItem = myElements->findItem(*it, Qt::ExactMatch);
1349 anItem = new QListBoxText(*it);
1350 myElements->insertItem(anItem);
1352 myElements->setSelected(anItem, true);
1355 } else if (myCurrentLineEdit == mySubMeshLine) {
1356 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1358 SALOME_ListIO aList;
1359 mySelectionMgr->selectedObjects( aList );
1361 SALOME_ListIteratorOfListIO anIt (aList);
1362 for (; anIt.More(); anIt.Next()) {
1363 SMESH::SMESH_subMesh_var aSubMesh =
1364 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1365 if (!aSubMesh->_is_nil()) {
1366 // check if mesh is the same
1367 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1369 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1370 int k = anElements->length();
1371 QListBoxItem* anItem = 0;
1372 for (int i = 0; i < k; i++) {
1373 QString aText = QString::number(anElements[i]);
1374 anItem = myElements->findItem(aText, Qt::ExactMatch);
1376 anItem = new QListBoxText(aText);
1377 myElements->insertItem(anItem);
1379 myElements->setSelected(anItem, true);
1382 catch (const SALOME::SALOME_Exception& ex) {
1383 SalomeApp_Tools::QtCatchCorbaException(ex);
1388 mySelectSubMesh->setChecked(false);
1390 onListSelectionChanged();
1392 } else if (myCurrentLineEdit == myGroupLine) {
1393 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1394 SALOME_ListIO aList;
1395 mySelectionMgr->selectedObjects( aList );
1397 SALOME_ListIteratorOfListIO anIt (aList);
1398 for (; anIt.More(); anIt.Next()) {
1399 SMESH::SMESH_Group_var aGroup =
1400 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1401 if (!aGroup->_is_nil()) {
1402 // check if mesh is the same
1403 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1404 SMESH::long_array_var anElements = aGroup->GetListOfID();
1405 int k = anElements->length();
1406 QListBoxItem* anItem = 0;
1407 for (int i = 0; i < k; i++) {
1408 QString aText = QString::number(anElements[i]);
1409 anItem = myElements->findItem(aText, Qt::ExactMatch);
1411 anItem = new QListBoxText(aText);
1412 myElements->insertItem(anItem);
1414 myElements->setSelected(anItem, true);
1419 mySelectGroup->setChecked(false);
1421 onListSelectionChanged();
1423 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1424 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1425 GEOM::GEOM_IGroupOperations_var aGroupOp =
1426 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1428 SMESH::ElementType aGroupType = SMESH::ALL;
1429 switch(aGroupOp->GetType(myGeomObjects[0])) {
1430 case 7: aGroupType = SMESH::NODE; break;
1431 case 6: aGroupType = SMESH::EDGE; break;
1432 case 4: aGroupType = SMESH::FACE; break;
1433 case 2: aGroupType = SMESH::VOLUME; break;
1434 default: myIsBusy = false; return;
1437 if (aGroupType == aType) {
1438 _PTR(SObject) aGroupSO =
1439 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1440 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1442 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1443 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1444 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1445 aBelongToGeom->SetGeom(myGeomObjects[0]);
1446 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1447 aBelongToGeom->SetElementType(aType);
1448 aFilter->SetPredicate(aBelongToGeom);
1450 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1452 int k = anElements->length();
1453 QListBoxItem* anItem = 0;
1454 for (int i = 0; i < k; i++) {
1455 QString aText = QString::number(anElements[i]);
1456 anItem = myElements->findItem(aText, Qt::ExactMatch);
1458 anItem = new QListBoxText(aText);
1459 myElements->insertItem(anItem);
1461 myElements->setSelected(anItem, true);
1465 //VSR: mySelectGeomGroup->setChecked(false);
1467 onListSelectionChanged();
1470 // mySelectionMgr->clearSelected();
1474 //=================================================================================
1475 // function : onRemove()
1477 //=================================================================================
1478 void SMESHGUI_GroupDlg::onRemove()
1481 if (myCurrentLineEdit == 0) {
1482 for (int i = myElements->count(); i > 0; i--) {
1483 if (myElements->isSelected(i-1)) {
1484 myElements->removeItem(i-1);
1488 SALOME_ListIO aList;
1489 mySelectionMgr->selectedObjects( aList );
1491 int aNbSel = aList.Extent();
1493 if (aNbSel == 0) { myIsBusy = false; return; }
1495 SMESH::ElementType aType = SMESH::ALL;
1497 case 0: aType = SMESH::NODE; break;
1498 case 1: aType = SMESH::EDGE; break;
1499 case 2: aType = SMESH::FACE; break;
1500 case 3: aType = SMESH::VOLUME; break;
1503 if (myCurrentLineEdit == mySubMeshLine) {
1504 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1505 SALOME_ListIO aList;
1506 mySelectionMgr->selectedObjects( aList );
1508 SALOME_ListIteratorOfListIO anIt (aList);
1509 for (; anIt.More(); anIt.Next()) {
1510 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1511 if (!aSubMesh->_is_nil()) {
1512 // check if mesh is the same
1513 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1514 if (aType == SMESH::NODE) {
1516 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1517 int k = anElements->length();
1518 QListBoxItem* anItem = 0;
1519 for (int i = 0; i < k; i++) {
1520 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1521 if (anItem) delete anItem;
1524 catch (const SALOME::SALOME_Exception& ex) {
1525 SalomeApp_Tools::QtCatchCorbaException(ex);
1530 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1531 int k = anElements->length();
1532 QListBoxItem* anItem = 0;
1533 for (int i = 0; i < k; i++) {
1534 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1535 if (anItem) delete anItem;
1538 catch (const SALOME::SALOME_Exception& ex) {
1539 SalomeApp_Tools::QtCatchCorbaException(ex);
1546 else if (myCurrentLineEdit == myGroupLine) {
1547 Standard_Boolean aRes;
1548 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1549 SALOME_ListIO aList;
1550 mySelectionMgr->selectedObjects( aList );
1552 SALOME_ListIteratorOfListIO anIt (aList);
1553 for (; anIt.More(); anIt.Next()) {
1554 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1555 if (aRes && !aGroup->_is_nil()) {
1556 // check if mesh is the same
1557 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1558 SMESH::long_array_var anElements = aGroup->GetListOfID();
1559 int k = anElements->length();
1560 QListBoxItem* anItem = 0;
1561 for (int i = 0; i < k; i++) {
1562 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1563 if (anItem) delete anItem;
1574 //=================================================================================
1575 // function : onSort()
1577 //=================================================================================
1578 void SMESHGUI_GroupDlg::onSort()
1580 // PAL5412: sorts items in ascending by "string" value
1581 // myElements->sort(true);
1582 // myElements->update();
1583 int i, k = myElements->count();
1586 QStringList aSelected;
1587 std::vector<int> anArray(k);
1588 // QMemArray<int> anArray(k);
1589 QListBoxItem* anItem;
1591 for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1592 anArray[i] = anItem->text().toInt();
1593 if (anItem->isSelected())
1594 aSelected.append(anItem->text());
1596 // sort & update list
1597 std::sort(anArray.begin(), anArray.end());
1599 myElements->clear();
1600 for (i = 0; i < k; i++) {
1601 myElements->insertItem(QString::number(anArray[i]));
1603 for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1604 anItem = myElements->findItem(*it, Qt::ExactMatch);
1605 if (anItem) myElements->setSelected(anItem, true);
1611 //=================================================================================
1612 // function : closeEvent()
1614 //=================================================================================
1615 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1620 //=================================================================================
1621 // function : SMESHGUI_GroupDlg::onClose
1622 // purpose : SLOT called when "Close" button pressed. Close dialog
1623 //=================================================================================
1624 void SMESHGUI_GroupDlg::onClose()
1626 if (SMESH::GetCurrentVtkView()) {
1627 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1628 SMESH::SetPointRepresentation(false);
1629 SMESH::SetPickable();
1632 mySelectionMgr->clearSelected();
1633 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1634 aViewWindow->SetSelectionMode(ActorSelection);
1635 mySelectionMgr->clearFilters();
1636 mySMESHGUI->ResetState();
1641 //=================================================================================
1642 // function : onHelp()
1644 //=================================================================================
1645 void SMESHGUI_GroupDlg::onHelp()
1647 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1649 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1651 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1652 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1653 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
1654 QObject::tr("BUT_OK"));
1658 //=================================================================================
1659 // function : SMESHGUI_GroupDlg::onDeactivate
1660 // purpose : SLOT called when dialog must be deativated
1661 //=================================================================================
1662 void SMESHGUI_GroupDlg::onDeactivate()
1664 mySMESHGUI->ResetState();
1668 //=================================================================================
1669 // function : SMESHGUI_GroupDlg::enterEvent
1670 // purpose : Event filter
1671 //=================================================================================
1672 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1675 mySMESHGUI->EmitSignalDeactivateDialog();
1677 mySelectionMode = -1;
1678 setSelectionMode(myTypeId);
1679 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1680 mySMESHGUI->SetActiveDialogBox(this);
1681 mySMESHGUI->SetState(800);
1685 //=================================================================================
1686 // function : hideEvent
1687 // purpose : caused by ESC key
1688 //=================================================================================
1689 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1691 if (!isMinimized() && !myIsBusy)
1695 //=================================================================================
1696 // function : keyPressEvent()
1698 //=================================================================================
1699 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1701 QDialog::keyPressEvent( e );
1702 if ( e->isAccepted() )
1705 if ( e->key() == Key_F1 )
1712 //================================================================================
1714 * \brief Enable showing of the popup when Geometry selection btn is clicked
1715 * \param enable - true to enable
1717 //================================================================================
1719 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1721 void SMESHGUI_GroupDlg::updateGeomPopup()
1723 bool enable = false;
1725 if ( !myMesh->_is_nil() )
1726 enable = myMesh->NbEdges() > 0;
1728 if ( myGeomGroupBtn )
1730 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1732 if ( !myGeomPopup ) {
1733 myGeomPopup = new QPopupMenu();
1734 myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
1735 myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
1736 connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
1738 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1744 //=================================================================================
1745 // function : onGeomSelectionButton()
1747 //=================================================================================
1748 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1750 if ( myGeomPopup && isBtnOn )
1752 myCurrentLineEdit = myGeomGroupLine;
1753 int id = myGeomPopup->exec( QCursor::pos() );
1754 if (id == DIRECT_GEOM_INDEX || id == -1)
1755 setSelectionMode(7);
1759 myCurrentLineEdit = 0;
1760 setSelectionMode(8);
1764 //=================================================================================
1765 // function : onGeomPopup()
1767 //=================================================================================
1768 void SMESHGUI_GroupDlg::onGeomPopup( int index )
1770 if ( index == GEOM_BY_MESH_INDEX )
1772 mySelectionMode = -1;
1773 if ( !myShapeByMeshOp ) {
1774 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1775 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1776 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1777 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1778 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1780 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1781 if ( !myMesh->_is_nil() ) {
1783 hide(); // stop processing selection
1785 myShapeByMeshOp->setModule( mySMESHGUI );
1786 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1787 myShapeByMeshOp->SetMesh( myMesh );
1788 myShapeByMeshOp->start();
1793 //================================================================================
1795 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1797 //================================================================================
1799 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1801 if ( myShapeByMeshOp == op ) {
1802 mySMESHGUI->getApp()->updateObjectBrowser();
1804 // Select a found geometry object
1805 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1806 if ( !aGeomVar->_is_nil() )
1808 QString ID = aGeomVar->GetStudyEntry();
1809 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1810 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
1811 SALOME_ListIO anIOList;
1812 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1813 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1814 anIOList.Append( anIO );
1815 mySelectionMgr->setSelectedObjects( anIOList, false );
1816 onObjectSelectionChanged();
1822 //================================================================================
1824 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1826 //================================================================================
1828 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1830 if ( myShapeByMeshOp == op )
1833 setSelectionMode(7);