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()
556 bool enable = !myName->text().stripWhiteSpace().isEmpty();
558 if (myGrpTypeId == 0) {
559 enable = enable && myElements->count() > 0;
560 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
562 else if (myGrpTypeId == 1) {
563 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
564 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
569 aBtn = (QPushButton*) child("ok", "QPushButton");
570 if (aBtn) aBtn->setEnabled(enable);
571 aBtn = (QPushButton*) child("apply", "QPushButton");
572 if (aBtn) aBtn->setEnabled(enable);
575 //=================================================================================
576 // function : onNameChanged()
578 //=================================================================================
579 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
584 //=================================================================================
585 // function : onNbColorsChanged()
587 //=================================================================================
588 void SMESHGUI_GroupDlg::onNbColorsChanged (const QString& text)
593 //=================================================================================
594 // function : onTypeChanged()
595 // purpose : Group elements type radio button management
596 //=================================================================================
597 void SMESHGUI_GroupDlg::onTypeChanged (int id)
599 if (myTypeId != id) {
601 if (myCurrentLineEdit == 0)
602 setSelectionMode(id);
607 //=================================================================================
608 // function : onGrpTypeChanged()
609 // purpose : Group type radio button management
610 //=================================================================================
611 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
613 if (myGrpTypeId != id) {
614 myWGStack->raiseWidget( id );
615 onSelectGeomGroup(id == 1);
620 //=================================================================================
621 // function : setSelectionMode()
622 // purpose : Radio button management
623 //=================================================================================
624 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
627 if (myMesh->_is_nil())
629 if (mySelectionMode != theMode) {
630 // [PAL10408] mySelectionMgr->clearSelected();
631 mySelectionMgr->clearFilters();
633 myActor->SetPointRepresentation(false);
635 SMESH::SetPointRepresentation(false);
640 myActor->SetPointRepresentation(true);
642 SMESH::SetPointRepresentation(true);
643 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
644 aViewWindow->SetSelectionMode(NodeSelection);
647 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
648 aViewWindow->SetSelectionMode(EdgeSelection);
651 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
652 aViewWindow->SetSelectionMode(FaceSelection);
655 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
656 aViewWindow->SetSelectionMode(VolumeSelection);
660 mySelectionMgr->installFilter(mySubMeshFilter);
661 else if (theMode == 5)
662 mySelectionMgr->installFilter(myGroupFilter);
663 else if (theMode == 6)
664 mySelectionMgr->installFilter(myMeshFilter);
665 else if (theMode == 7)
666 mySelectionMgr->installFilter(myGeomFilter);
668 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
669 aViewWindow->SetSelectionMode(ActorSelection);
671 mySelectionMode = theMode;
675 //=================================================================================
676 // function : onApply()
678 //=================================================================================
679 bool SMESHGUI_GroupDlg::onApply()
681 if (mySMESHGUI->isActiveStudyLocked())
684 if (myName->text().stripWhiteSpace().isEmpty())
687 if (myGrpTypeId == 0) { // on mesh elements
688 if (!myElements->count())
691 mySelectionMgr->clearSelected();
693 if (myGroup->_is_nil()) { // creation
694 if (myMesh->_is_nil())
697 SMESH::ElementType aType = SMESH::ALL;
699 case 0: aType = SMESH::NODE; break;
700 case 1: aType = SMESH::EDGE; break;
701 case 2: aType = SMESH::FACE; break;
702 case 3: aType = SMESH::VOLUME; break;
705 SMESH::long_array_var anIdList = new SMESH::long_array;
706 int i, k = myElements->count();
708 QListBoxItem* anItem;
709 for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
710 anIdList[i] = anItem->text().toInt();
713 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
714 myGroup->Add(anIdList.inout());
716 int aColorNumber = myColorSpinBox->value();
717 myGroup->SetColorNumber(aColorNumber);
719 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
721 SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
722 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
724 /* init for next operation */
726 myColorSpinBox->setValue(0);
728 myGroup = SMESH::SMESH_Group::_nil();
731 myGroup->SetName(myName->text());
733 int aColorNumber = myColorSpinBox->value();
734 myGroup->SetColorNumber(aColorNumber);
736 QValueList<int> aAddList;
737 QValueList<int>::iterator anIt;
738 QListBoxItem* anItem;
740 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
741 int anId = anItem->text().toInt();
742 if ((anIt = myIdList.find(anId)) == myIdList.end())
743 aAddList.append(anId);
745 myIdList.remove(anIt);
747 if (!aAddList.empty()) {
748 SMESH::long_array_var anIdList = new SMESH::long_array;
749 anIdList->length(aAddList.count());
751 for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
753 myGroup->Add(anIdList.inout());
755 if (!myIdList.empty()) {
756 SMESH::long_array_var anIdList = new SMESH::long_array;
757 anIdList->length(myIdList.count());
759 for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
761 myGroup->Remove(anIdList.inout());
763 /* init for next operation */
765 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
766 myIdList.append(anItem->text().toInt());
769 mySMESHGUI->updateObjBrowser(true);
770 SMESH::UpdateView(); // asv: fix of BUG PAL5515
771 mySelectionMgr->clearSelected();
774 else if (myGrpTypeId == 1) { // on geom object
775 if (CORBA::is_nil(myGroupOnGeom)) { // creation
776 if (myMesh->_is_nil() || !myGeomObjects->length())
779 SMESH::ElementType aType = SMESH::ALL;
781 case 0: aType = SMESH::NODE; break;
782 case 1: aType = SMESH::EDGE; break;
783 case 2: aType = SMESH::FACE; break;
784 case 3: aType = SMESH::VOLUME; break;
787 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
788 GEOM::GEOM_IGroupOperations_var aGroupOp =
789 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
791 if (myGeomObjects->length() == 1) {
792 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
795 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
796 if ( aSMESHGen->_is_nil() )
799 // create a geometry group
800 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
801 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
803 if (geomGen->_is_nil() || !aStudy)
806 GEOM::GEOM_IGroupOperations_var op =
807 geomGen->GetIGroupOperations(aStudy->StudyId());
811 // check and add all selected GEOM objects: they must be
812 // a sub-shapes of the main GEOM and must be of one type
813 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
814 for ( int i =0; i < myGeomObjects->length(); i++) {
815 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
817 aGroupType = aSubShapeType;
818 else if (aSubShapeType != aGroupType) {
819 aGroupType = TopAbs_SHAPE;
824 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
825 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
826 op->UnionList(aGroupVar, myGeomObjects);
829 // publish the GEOM group in study
830 QString aNewGeomGroupName ("Auto_group_for_");
831 aNewGeomGroupName += myName->text();
832 SALOMEDS::SObject_var aNewGroupSO =
833 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
836 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
839 int aColorNumber = myColorSpinBox->value();
840 myGroupOnGeom->SetColorNumber(aColorNumber);
842 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
844 SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
846 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
848 /* init for next operation */
850 myColorSpinBox->setValue(0);
851 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
854 myGroupOnGeom->SetName(myName->text());
856 int aColorNumber = myColorSpinBox->value();
857 myGroupOnGeom->SetColorNumber(aColorNumber);
860 mySMESHGUI->updateObjBrowser(true);
861 mySelectionMgr->clearSelected();
868 //=================================================================================
871 //=================================================================================
872 void SMESHGUI_GroupDlg::onOK()
878 //=================================================================================
879 // function : onListSelectionChanged()
880 // purpose : Called when selection in element list is changed
881 //=================================================================================
882 void SMESHGUI_GroupDlg::onListSelectionChanged()
884 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
885 if( myIsBusy || !myActor) return;
888 if (myCurrentLineEdit == 0) {
889 mySelectionMgr->clearSelected();
890 TColStd_MapOfInteger aIndexes;
891 QListBoxItem* anItem;
892 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
893 if (anItem->isSelected()) {
894 int anId = anItem->text().toInt();
898 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
900 aList.Append(myActor->getIO());
901 mySelectionMgr->setSelectedObjects(aList,false);
906 //=================================================================================
907 // function : onObjectSelectionChanged()
908 // purpose : Called when selection in 3D view or ObjectBrowser is changed
909 //=================================================================================
910 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
912 if ( myIsBusy || !isEnabled()) return;
913 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
918 mySelectionMgr->selectedObjects( aList );
920 int aNbSel = aList.Extent();
921 myElements->clearSelection();
923 if (myCurrentLineEdit) {
924 myCurrentLineEdit->setText("");
925 QString aString = "";
927 if (myCurrentLineEdit == myMeshGroupLine) {
928 mySelectSubMesh->setEnabled(false);
929 mySelectGroup->setEnabled(false);
930 myGroupLine->setText("");
931 mySubMeshLine->setText("");
933 myGeomGroupBtn->setEnabled(false);
934 myGeomGroupLine->setEnabled(false);
935 myGeomGroupLine->setText("");
936 myGeomObjects = new GEOM::ListOfGO();
937 myGeomObjects->length(0);
939 if (myGeomGroupBtn->isOn())
940 myGeomGroupBtn->setOn(false);
947 myGroup = SMESH::SMESH_Group::_nil();
948 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
949 myMesh = SMESH::SMESH_Mesh::_nil();
955 Handle(SALOME_InteractiveObject) IO = aList.First();
958 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
960 if (myMesh->_is_nil())
966 myGroup = SMESH::SMESH_Group::_nil();
968 myActor = SMESH::FindActorByObject(myMesh);
969 SMESH::SetPickable(myActor);
971 aString = aList.First()->getName();
972 myMeshGroupLine->setText(aString) ;
973 myMeshGroupLine->home( false );
975 mySelectSubMesh->setEnabled(true);
976 mySelectGroup->setEnabled(true);
977 myGeomGroupBtn->setEnabled(true);
978 myGeomGroupLine->setEnabled(true);
981 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
982 if (aGroup->_is_nil())
988 myCurrentLineEdit = 0;
990 myGroup = SMESH::SMESH_Group::_nil();
991 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
995 mySelectSubMesh->setEnabled(true);
996 mySelectGroup->setEnabled(true);
998 myCurrentLineEdit = 0;
1003 if (myGrpTypeId == 0)
1009 myElements->clear();
1010 setSelectionMode(myTypeId);
1017 } else if (myCurrentLineEdit == myGeomGroupLine) {
1019 myGeomObjects = new GEOM::ListOfGO();
1022 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1024 if (aNbSel == 0 || !aMeshSO)
1026 myGeomObjects->length(0);
1032 myGeomObjects->length(aNbSel);
1034 GEOM::GEOM_Object_var aGeomGroup;
1035 Standard_Boolean testResult;
1038 SALOME_ListIteratorOfListIO anIt (aList);
1039 for (; anIt.More(); anIt.Next()) {
1041 testResult = Standard_False;
1042 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1044 // Check if the object is a geometry group
1045 if (!testResult || CORBA::is_nil(aGeomGroup))
1049 // Check if group constructed on the same shape as a mesh or on its child
1050 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1051 GEOM::GEOM_IGroupOperations_var anOp =
1052 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1054 // The main shape of the group
1055 GEOM::GEOM_Object_var aGroupMainShape;
1056 if (aGeomGroup->GetType() == 37)
1057 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1059 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1060 _PTR(SObject) aGroupMainShapeSO =
1061 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1062 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1064 _PTR(SObject) anObj, aRef;
1065 bool isRefOrSubShape = false;
1066 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1067 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1068 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1069 isRefOrSubShape = true;
1071 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1072 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1073 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1074 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1075 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1076 if (aRef->GetID() == aFather->GetID())
1077 isRefOrSubShape = true;
1079 aFather = aFather->GetFather();
1083 if (isRefOrSubShape)
1084 myGeomObjects[i++] = aGeomGroup;
1087 myGeomObjects->length(i);
1099 if(myCurrentLineEdit == mySubMeshLine)
1100 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1101 else if(myCurrentLineEdit == myGroupLine)
1102 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1103 else if(myCurrentLineEdit == myGeomGroupLine)
1104 aString = tr("%1 Objects").arg(aNbSel);
1106 aString = aList.First()->getName();
1110 myCurrentLineEdit->setText(aString);
1111 myCurrentLineEdit->home(false);
1116 if (aNbSel == 1 && myActor ) {
1117 QString aListStr = "";
1119 if (myTypeId == 0) {
1120 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1122 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1125 QStringList anElements = QStringList::split(" ", aListStr);
1126 QListBoxItem* anItem = 0;
1127 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1128 anItem = myElements->findItem(*it, Qt::ExactMatch);
1129 if (anItem) myElements->setSelected(anItem, true);
1136 if (!myGroup->_is_nil())
1137 myActor = SMESH::FindActorByObject(myGroup);
1138 else if(!myGroupOnGeom->_is_nil())
1139 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1141 myActor = SMESH::FindActorByObject(myMesh);
1147 //=================================================================================
1148 // function : onSelectSubMesh()
1149 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1150 //=================================================================================
1151 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1154 if (mySelectGroup->isChecked()) {
1155 mySelectGroup->setChecked(false);
1157 //VSR: else if (mySelectGeomGroup->isChecked()) {
1158 //VSR: mySelectGeomGroup->setChecked(false);
1160 myCurrentLineEdit = mySubMeshLine;
1161 setSelectionMode(4);
1164 mySubMeshLine->setText("");
1165 myCurrentLineEdit = 0;
1167 setSelectionMode(myTypeId);
1169 mySubMeshBtn->setEnabled(on);
1170 mySubMeshLine->setEnabled(on);
1174 //=================================================================================
1175 // function : (onSelectGroup)
1176 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1177 //=================================================================================
1178 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1181 if (mySelectSubMesh->isChecked()) {
1182 mySelectSubMesh->setChecked(false);
1184 myCurrentLineEdit = myGroupLine;
1185 setSelectionMode(5);
1188 myGroupLine->setText("");
1189 myCurrentLineEdit = 0;
1191 setSelectionMode(myTypeId);
1193 myGroupBtn->setEnabled(on);
1194 myGroupLine->setEnabled(on);
1198 //=================================================================================
1199 // function : (onSelectGeomGroup)
1200 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1201 //=================================================================================
1202 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1205 if (mySelectSubMesh->isChecked()) {
1206 mySelectSubMesh->setChecked(false);
1208 else if (mySelectGroup->isChecked()) {
1209 mySelectGroup->setChecked(false);
1211 myCurrentLineEdit = myGeomGroupLine;
1213 setSelectionMode(8);
1216 myGeomGroupBtn->setOn(false);
1217 myGeomObjects->length(0);
1218 myGeomGroupLine->setText("");
1219 myCurrentLineEdit = 0;
1221 setSelectionMode(myTypeId);
1225 //=================================================================================
1226 // function : (onSelectColorGroup)
1227 // purpose : Called when setting a color on group
1228 //=================================================================================
1229 void SMESHGUI_GroupDlg::onSelectColorGroup(bool on)
1232 myColorSpinBox->setValue(0);
1234 myColorSpinBox->setEnabled(on);
1237 //=================================================================================
1238 // function : setCurrentSelection()
1240 //=================================================================================
1241 void SMESHGUI_GroupDlg::setCurrentSelection()
1243 QPushButton* send = (QPushButton*)sender();
1244 myCurrentLineEdit = 0;
1245 if (send == myMeshGroupBtn) {
1246 myCurrentLineEdit = myMeshGroupLine;
1248 setSelectionMode(6);
1250 setSelectionMode(5);
1251 onObjectSelectionChanged();
1253 else if (send == mySubMeshBtn) {
1254 myCurrentLineEdit = mySubMeshLine;
1255 onObjectSelectionChanged();
1257 else if (send == myGroupBtn) {
1258 myCurrentLineEdit = myGroupLine;
1259 onObjectSelectionChanged();
1264 //=================================================================================
1265 // function : setFilters()
1266 // purpose : SLOT. Called when "Filter" button pressed.
1267 //=================================================================================
1268 void SMESHGUI_GroupDlg::setFilters()
1270 SMESH::ElementType aType = SMESH::ALL;
1273 case 0 : aType = SMESH::NODE; break;
1274 case 1 : aType = SMESH::EDGE; break;
1275 case 2 : aType = SMESH::FACE; break;
1276 case 3 : aType = SMESH::VOLUME; break;
1280 if ( myFilterDlg == 0 )
1282 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1283 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1286 myFilterDlg->Init( aType );
1288 myFilterDlg->SetSelection();
1289 myFilterDlg->SetMesh( myMesh );
1290 myFilterDlg->SetSourceWg( myElements );
1292 myFilterDlg->show();
1295 //=================================================================================
1296 // function : onFilterAccepted()
1297 // purpose : SLOT. Called when Filter dlg closed with OK button.
1298 // Uncheck "Select submesh" and "Select group" checkboxes
1299 //=================================================================================
1300 void SMESHGUI_GroupDlg::onFilterAccepted()
1302 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1304 mySelectionMode = myTypeId;
1305 mySelectSubMesh->setChecked( false );
1306 mySelectGroup->setChecked( false );
1310 //=================================================================================
1311 // function : onAdd()
1313 //=================================================================================
1314 void SMESHGUI_GroupDlg::onAdd()
1316 SALOME_ListIO aList;
1317 mySelectionMgr->selectedObjects( aList );
1319 int aNbSel = aList.Extent();
1321 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1325 SMESH::ElementType aType = SMESH::ALL;
1328 aType = SMESH::NODE;
1329 mySelector->SetSelectionMode(NodeSelection);
1332 aType = SMESH::EDGE;
1333 mySelector->SetSelectionMode(EdgeSelection);
1336 aType = SMESH::FACE;
1337 mySelector->SetSelectionMode(FaceSelection);
1340 aType = SMESH::VOLUME;
1341 mySelector->SetSelectionMode(VolumeSelection);
1344 mySelector->SetSelectionMode(ActorSelection);
1348 if (myCurrentLineEdit == 0) {
1349 //if (aNbSel != 1) { myIsBusy = false; return; }
1350 QString aListStr = "";
1352 if (myTypeId == 0) {
1353 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1356 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1359 QStringList anElements = QStringList::split(" ", aListStr);
1360 QListBoxItem* anItem = 0;
1361 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1362 anItem = myElements->findItem(*it, Qt::ExactMatch);
1364 anItem = new QListBoxText(*it);
1365 myElements->insertItem(anItem);
1367 myElements->setSelected(anItem, true);
1370 } else if (myCurrentLineEdit == mySubMeshLine) {
1371 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1373 SALOME_ListIO aList;
1374 mySelectionMgr->selectedObjects( aList );
1376 SALOME_ListIteratorOfListIO anIt (aList);
1377 for (; anIt.More(); anIt.Next()) {
1378 SMESH::SMESH_subMesh_var aSubMesh =
1379 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1380 if (!aSubMesh->_is_nil()) {
1381 // check if mesh is the same
1382 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1384 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1385 int k = anElements->length();
1386 QListBoxItem* anItem = 0;
1387 for (int i = 0; i < k; i++) {
1388 QString aText = QString::number(anElements[i]);
1389 anItem = myElements->findItem(aText, Qt::ExactMatch);
1391 anItem = new QListBoxText(aText);
1392 myElements->insertItem(anItem);
1394 myElements->setSelected(anItem, true);
1397 catch (const SALOME::SALOME_Exception& ex) {
1398 SalomeApp_Tools::QtCatchCorbaException(ex);
1403 mySelectSubMesh->setChecked(false);
1405 onListSelectionChanged();
1407 } else if (myCurrentLineEdit == myGroupLine) {
1408 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1409 SALOME_ListIO aList;
1410 mySelectionMgr->selectedObjects( aList );
1412 SALOME_ListIteratorOfListIO anIt (aList);
1413 for (; anIt.More(); anIt.Next()) {
1414 SMESH::SMESH_Group_var aGroup =
1415 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1416 if (!aGroup->_is_nil()) {
1417 // check if mesh is the same
1418 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1419 SMESH::long_array_var anElements = aGroup->GetListOfID();
1420 int k = anElements->length();
1421 QListBoxItem* anItem = 0;
1422 for (int i = 0; i < k; i++) {
1423 QString aText = QString::number(anElements[i]);
1424 anItem = myElements->findItem(aText, Qt::ExactMatch);
1426 anItem = new QListBoxText(aText);
1427 myElements->insertItem(anItem);
1429 myElements->setSelected(anItem, true);
1434 mySelectGroup->setChecked(false);
1436 onListSelectionChanged();
1438 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1439 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1440 GEOM::GEOM_IGroupOperations_var aGroupOp =
1441 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1443 SMESH::ElementType aGroupType = SMESH::ALL;
1444 switch(aGroupOp->GetType(myGeomObjects[0])) {
1445 case 7: aGroupType = SMESH::NODE; break;
1446 case 6: aGroupType = SMESH::EDGE; break;
1447 case 4: aGroupType = SMESH::FACE; break;
1448 case 2: aGroupType = SMESH::VOLUME; break;
1449 default: myIsBusy = false; return;
1452 if (aGroupType == aType) {
1453 _PTR(SObject) aGroupSO =
1454 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1455 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1457 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1458 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1459 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1460 aBelongToGeom->SetGeom(myGeomObjects[0]);
1461 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1462 aBelongToGeom->SetElementType(aType);
1463 aFilter->SetPredicate(aBelongToGeom);
1465 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1467 int k = anElements->length();
1468 QListBoxItem* anItem = 0;
1469 for (int i = 0; i < k; i++) {
1470 QString aText = QString::number(anElements[i]);
1471 anItem = myElements->findItem(aText, Qt::ExactMatch);
1473 anItem = new QListBoxText(aText);
1474 myElements->insertItem(anItem);
1476 myElements->setSelected(anItem, true);
1480 //VSR: mySelectGeomGroup->setChecked(false);
1482 onListSelectionChanged();
1485 // mySelectionMgr->clearSelected();
1489 //=================================================================================
1490 // function : onRemove()
1492 //=================================================================================
1493 void SMESHGUI_GroupDlg::onRemove()
1496 if (myCurrentLineEdit == 0) {
1497 for (int i = myElements->count(); i > 0; i--) {
1498 if (myElements->isSelected(i-1)) {
1499 myElements->removeItem(i-1);
1503 SALOME_ListIO aList;
1504 mySelectionMgr->selectedObjects( aList );
1506 int aNbSel = aList.Extent();
1508 if (aNbSel == 0) { myIsBusy = false; return; }
1510 SMESH::ElementType aType = SMESH::ALL;
1512 case 0: aType = SMESH::NODE; break;
1513 case 1: aType = SMESH::EDGE; break;
1514 case 2: aType = SMESH::FACE; break;
1515 case 3: aType = SMESH::VOLUME; break;
1518 if (myCurrentLineEdit == mySubMeshLine) {
1519 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1520 SALOME_ListIO aList;
1521 mySelectionMgr->selectedObjects( aList );
1523 SALOME_ListIteratorOfListIO anIt (aList);
1524 for (; anIt.More(); anIt.Next()) {
1525 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1526 if (!aSubMesh->_is_nil()) {
1527 // check if mesh is the same
1528 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1529 if (aType == SMESH::NODE) {
1531 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1532 int k = anElements->length();
1533 QListBoxItem* anItem = 0;
1534 for (int i = 0; i < k; i++) {
1535 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1536 if (anItem) delete anItem;
1539 catch (const SALOME::SALOME_Exception& ex) {
1540 SalomeApp_Tools::QtCatchCorbaException(ex);
1545 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1546 int k = anElements->length();
1547 QListBoxItem* anItem = 0;
1548 for (int i = 0; i < k; i++) {
1549 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1550 if (anItem) delete anItem;
1553 catch (const SALOME::SALOME_Exception& ex) {
1554 SalomeApp_Tools::QtCatchCorbaException(ex);
1561 else if (myCurrentLineEdit == myGroupLine) {
1562 Standard_Boolean aRes;
1563 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1564 SALOME_ListIO aList;
1565 mySelectionMgr->selectedObjects( aList );
1567 SALOME_ListIteratorOfListIO anIt (aList);
1568 for (; anIt.More(); anIt.Next()) {
1569 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1570 if (aRes && !aGroup->_is_nil()) {
1571 // check if mesh is the same
1572 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1573 SMESH::long_array_var anElements = aGroup->GetListOfID();
1574 int k = anElements->length();
1575 QListBoxItem* anItem = 0;
1576 for (int i = 0; i < k; i++) {
1577 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1578 if (anItem) delete anItem;
1589 //=================================================================================
1590 // function : onSort()
1592 //=================================================================================
1593 void SMESHGUI_GroupDlg::onSort()
1595 // PAL5412: sorts items in ascending by "string" value
1596 // myElements->sort(true);
1597 // myElements->update();
1598 int i, k = myElements->count();
1601 QStringList aSelected;
1602 std::vector<int> anArray(k);
1603 // QMemArray<int> anArray(k);
1604 QListBoxItem* anItem;
1606 for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1607 anArray[i] = anItem->text().toInt();
1608 if (anItem->isSelected())
1609 aSelected.append(anItem->text());
1611 // sort & update list
1612 std::sort(anArray.begin(), anArray.end());
1614 myElements->clear();
1615 for (i = 0; i < k; i++) {
1616 myElements->insertItem(QString::number(anArray[i]));
1618 for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1619 anItem = myElements->findItem(*it, Qt::ExactMatch);
1620 if (anItem) myElements->setSelected(anItem, true);
1626 //=================================================================================
1627 // function : closeEvent()
1629 //=================================================================================
1630 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1635 //=================================================================================
1636 // function : SMESHGUI_GroupDlg::onClose
1637 // purpose : SLOT called when "Close" button pressed. Close dialog
1638 //=================================================================================
1639 void SMESHGUI_GroupDlg::onClose()
1641 if (SMESH::GetCurrentVtkView()) {
1642 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1643 SMESH::SetPointRepresentation(false);
1644 SMESH::SetPickable();
1647 mySelectionMgr->clearSelected();
1648 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1649 aViewWindow->SetSelectionMode(ActorSelection);
1650 mySelectionMgr->clearFilters();
1651 mySMESHGUI->ResetState();
1656 //=================================================================================
1657 // function : onHelp()
1659 //=================================================================================
1660 void SMESHGUI_GroupDlg::onHelp()
1662 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1664 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1666 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1667 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1668 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
1669 QObject::tr("BUT_OK"));
1673 //=================================================================================
1674 // function : SMESHGUI_GroupDlg::onDeactivate
1675 // purpose : SLOT called when dialog must be deativated
1676 //=================================================================================
1677 void SMESHGUI_GroupDlg::onDeactivate()
1679 mySMESHGUI->ResetState();
1683 //=================================================================================
1684 // function : SMESHGUI_GroupDlg::enterEvent
1685 // purpose : Event filter
1686 //=================================================================================
1687 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1690 mySMESHGUI->EmitSignalDeactivateDialog();
1692 mySelectionMode = -1;
1693 setSelectionMode(myTypeId);
1694 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1695 mySMESHGUI->SetActiveDialogBox(this);
1696 mySMESHGUI->SetState(800);
1700 //=================================================================================
1701 // function : hideEvent
1702 // purpose : caused by ESC key
1703 //=================================================================================
1704 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1706 if (!isMinimized() && !myIsBusy)
1710 //=================================================================================
1711 // function : keyPressEvent()
1713 //=================================================================================
1714 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1716 QDialog::keyPressEvent( e );
1717 if ( e->isAccepted() )
1720 if ( e->key() == Key_F1 )
1727 //================================================================================
1729 * \brief Enable showing of the popup when Geometry selection btn is clicked
1730 * \param enable - true to enable
1732 //================================================================================
1734 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1736 void SMESHGUI_GroupDlg::updateGeomPopup()
1738 bool enable = false;
1740 if ( !myMesh->_is_nil() )
1741 enable = myMesh->NbEdges() > 0;
1743 if ( myGeomGroupBtn )
1745 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1747 if ( !myGeomPopup ) {
1748 myGeomPopup = new QPopupMenu();
1749 myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
1750 myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
1751 connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
1753 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1759 //=================================================================================
1760 // function : onGeomSelectionButton()
1762 //=================================================================================
1763 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1765 if ( myGeomPopup && isBtnOn )
1767 myCurrentLineEdit = myGeomGroupLine;
1768 int id = myGeomPopup->exec( QCursor::pos() );
1769 if (id == DIRECT_GEOM_INDEX || id == -1)
1770 setSelectionMode(7);
1774 myCurrentLineEdit = 0;
1775 setSelectionMode(8);
1779 //=================================================================================
1780 // function : onGeomPopup()
1782 //=================================================================================
1783 void SMESHGUI_GroupDlg::onGeomPopup( int index )
1785 if ( index == GEOM_BY_MESH_INDEX )
1787 mySelectionMode = -1;
1788 if ( !myShapeByMeshOp ) {
1789 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1790 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1791 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1792 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1793 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1795 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1796 if ( !myMesh->_is_nil() ) {
1798 hide(); // stop processing selection
1800 myShapeByMeshOp->setModule( mySMESHGUI );
1801 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1802 myShapeByMeshOp->SetMesh( myMesh );
1803 myShapeByMeshOp->start();
1808 //================================================================================
1810 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1812 //================================================================================
1814 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1816 if ( myShapeByMeshOp == op ) {
1817 mySMESHGUI->getApp()->updateObjectBrowser();
1819 // Select a found geometry object
1820 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1821 if ( !aGeomVar->_is_nil() )
1823 QString ID = aGeomVar->GetStudyEntry();
1824 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1825 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
1826 SALOME_ListIO anIOList;
1827 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1828 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1829 anIOList.Append( anIO );
1830 mySelectionMgr->setSelectedObjects( anIOList, false );
1831 onObjectSelectionChanged();
1837 //================================================================================
1839 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1841 //================================================================================
1843 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1845 if ( myShapeByMeshOp == op )
1848 setSelectionMode(7);