Salome HOME
Fix for bug IPAL9258(/dn06/../current1706): SIGSEGV after trying to close dialog...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : SMESHGUI_GroupDlg.cxx
25 //  Author : Natalia KOPNOVA
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESHGUI_GroupDlg.h"
30 #include "SMESHGUI_FilterDlg.h"
31
32 #include "SMESHGUI.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_GroupUtils.h"
37 #include "SMESHGUI_FilterUtils.h"
38 #include "SMESHGUI_GEOMGenUtils.h"
39
40 #include "SMESH_TypeFilter.hxx"
41 #include "SMESH_Actor.h"
42 #include "GEOMBase.h"
43
44 #include "SUIT_Desktop.h"
45 #include "SUIT_ResourceMgr.h"
46
47 #include "SalomeApp_Tools.h"
48 #include "SALOMEDSClient_Study.hxx"
49 #include "SALOME_ListIO.hxx"
50 #include "SALOME_ListIteratorOfListIO.hxx"
51
52 #include "SVTK_ViewWindow.h"
53 #include "SVTK_Selector.h"
54
55 #include "utilities.h"
56
57 // OCCT Includes
58 #include <TColStd_MapOfInteger.hxx>
59
60 // QT Includes
61 #include <qbuttongroup.h>
62 #include <qgroupbox.h>
63 #include <qhbox.h>
64 #include <qlabel.h>
65 #include <qlineedit.h>
66 #include <qpushbutton.h>
67 #include <qradiobutton.h>
68 #include <qcheckbox.h>
69 #include <qlayout.h>
70 #include <qlistbox.h>
71 #include <qimage.h>
72 #include <qpixmap.h>
73 #include <qmemarray.h>
74 #include <qwidgetstack.h>
75
76 // STL includes
77 #include <vector>
78 #include <algorithm>
79
80 using namespace std;
81
82 //=================================================================================
83 // function : SMESHGUI_GroupDlg()
84 // purpose  :
85 //=================================================================================
86 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
87                                       SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl)
88      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
89                 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
90      mySMESHGUI( theModule ),
91      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
92      myIsBusy( false ),
93      myActor( 0 )
94 {
95   if (!name) setName("SMESHGUI_GroupDlg");
96   initDialog(true);
97   if (!theMesh->_is_nil())
98     init(theMesh);
99   else {
100     mySelectSubMesh->setEnabled(false);
101     mySelectGroup->setEnabled(false);
102     myGeomGroupBtn->setEnabled(false);
103     myGeomGroupLine->setEnabled(false);
104   }
105
106   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
107
108   /* Move widget on the botton right corner of main widget */
109   int x, y ;
110   mySMESHGUI->DefineDlgPosition(this, x, y);
111   this->move(x, y);
112 }
113
114 //=================================================================================
115 // function : SMESHGUI_GroupDlg()
116 // purpose  :
117 //=================================================================================
118 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
119                                       SMESH::SMESH_Group_ptr theGroup, bool modal, WFlags fl)
120      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
121                 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
122      mySMESHGUI( theModule ),
123      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
124      myIsBusy( false )
125 {
126   if (!name) setName("SMESHGUI_GroupDlg");
127   initDialog(false);
128   if (!theGroup->_is_nil())
129     init(theGroup);
130   else {
131     mySelectSubMesh->setEnabled(false);
132     mySelectGroup->setEnabled(false);
133   }
134
135   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
136
137   /* Move widget on the botton right corner of main widget */
138   int x, y ;
139   mySMESHGUI->DefineDlgPosition(this, x, y);
140   this->move(x, y);
141 }
142
143 //=================================================================================
144 // function : SMESHGUI_GroupDlg()
145 // purpose  :
146 //=================================================================================
147 void SMESHGUI_GroupDlg::initDialog(bool create)
148 {
149   myFilterDlg = 0;
150   myCreate = create;
151   myCurrentLineEdit = 0;
152
153   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
154
155   if (create)
156     setCaption(tr("SMESH_CREATE_GROUP_TITLE"));
157   else
158     setCaption(tr("SMESH_EDIT_GROUP_TITLE"));
159
160   setSizeGripEnabled(TRUE);
161
162   QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
163
164   /***************************************************************/
165   QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
166   if (create)
167     meshGroupLab->setText(tr("SMESH_MESH"));
168   else
169     meshGroupLab->setText(tr("SMESH_GROUP"));
170   myMeshGroupBtn = new QPushButton(this, "mesh/group button");
171   myMeshGroupBtn->setPixmap(image0);
172   myMeshGroupLine = new QLineEdit(this, "mesh/group line");
173   myMeshGroupLine->setReadOnly(true);
174
175   /***************************************************************/
176   myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
177   myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
178   myTypeGroup->setExclusive(true);
179
180   QStringList types;
181   types.append(tr("MESH_NODE"));
182   types.append(tr("SMESH_EDGE"));
183   types.append(tr("SMESH_FACE"));
184   types.append(tr("SMESH_VOLUME"));
185   QRadioButton* rb;
186   for (int i = 0; i < types.count(); i++) {
187     rb = new QRadioButton(types[i], myTypeGroup);
188   }
189   myTypeGroup->setEnabled(create);
190   myTypeId = -1;
191
192   /***************************************************************/
193   QLabel* aName = new QLabel(this, "name label");
194   aName->setText(tr("SMESH_NAME"));
195   aName->setMinimumSize(50,0);
196   myName = new QLineEdit(this, "name");
197
198   /***************************************************************/
199   myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
200   myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
201   myGrpTypeGroup->setExclusive(true);
202   QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
203   QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"),   myGrpTypeGroup);
204   myGrpTypeGroup->setEnabled(create);
205   myGrpTypeId = -1;
206
207   /***************************************************************/
208   myWGStack = new QWidgetStack( this, "widget stack");
209   QWidget* wg1 = new QFrame( myWGStack, "first widget" );
210   QWidget* wg2 = new QFrame( myWGStack, "second widget" );
211
212   /***************************************************************/
213   QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
214   aContentBox->setTitle(tr("SMESH_CONTENT"));
215   QFrame* aContent = new QFrame(aContentBox, "content");
216   QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
217   aLayout->setSpacing(6);
218   aLayout->setAutoAdd(false);
219
220   QLabel* aLabel = new QLabel(aContent, "elements label");
221   aLabel->setText(tr("SMESH_ID_ELEMENTS"));
222   myElements = new QListBox(aContent, "elements list");
223   myElements->setSelectionMode(QListBox::Extended);
224
225   myFilter = new QPushButton(aContent, "filter");
226   myFilter->setText(tr("SMESH_BUT_FILTER"));
227   QPushButton* aAddBtn = new QPushButton(aContent, "add");
228   aAddBtn->setText(tr("SMESH_BUT_ADD"));
229   QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
230   aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
231   QPushButton* aSortBtn = new QPushButton(aContent, "sort");
232   aSortBtn->setText(tr("SMESH_BUT_SORT"));
233
234   aLayout->addWidget(aLabel, 0, 0);
235   aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
236   aLayout->addWidget(myFilter, 1, 2);
237   aLayout->addWidget(aAddBtn, 3, 2);
238   aLayout->addWidget(aRemoveBtn, 4, 2);
239   aLayout->addWidget(aSortBtn, 6, 2);
240
241   aLayout->setColStretch(0, 1);
242   aLayout->addColSpacing(1, 20);
243   aLayout->addColSpacing(3, 20);
244   aLayout->setRowStretch(2, 1);
245   aLayout->setRowStretch(5, 1);
246
247   /***************************************************************/
248   QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
249   aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
250
251   mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
252   mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
253   mySelectSubMesh->setMinimumSize(50, 0);
254   mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
255   mySubMeshBtn->setText("");
256   mySubMeshBtn->setPixmap(image0);
257   mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
258   mySubMeshLine->setReadOnly(true);
259   onSelectSubMesh(false);
260
261   mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
262   mySelectGroup->setText(tr("SMESH_GROUP"));
263   mySelectGroup->setMinimumSize(50, 0);
264   myGroupBtn = new QPushButton(aSelectBox, "group button");
265   myGroupBtn->setText("");
266   myGroupBtn->setPixmap(image0);
267   myGroupLine = new QLineEdit(aSelectBox, "group line");
268   myGroupLine->setReadOnly(true);
269   onSelectGroup(false);
270
271   /***************************************************************/
272   QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
273   wg1Layout->addWidget(aContentBox, 0, 0);
274   wg1Layout->addWidget(aSelectBox, 1, 0);
275   wg1Layout->setRowStretch(2, 5);
276
277   /***************************************************************/
278   QLabel* geomObject = new QLabel(wg2, "geometry object label");
279   geomObject->setText(tr("SMESH_OBJECT_GEOM"));
280   myGeomGroupBtn = new QPushButton(wg2, "geometry group button");
281   myGeomGroupBtn->setText("");
282   myGeomGroupBtn->setPixmap(image0);
283   myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
284   myGeomGroupLine->setReadOnly(true); //VSR ???
285   onSelectGeomGroup(false);
286
287   /***************************************************************/
288   QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
289   wg2Layout->addWidget(geomObject,     0, 0);
290   wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
291   wg2Layout->addWidget(myGeomGroupLine,0, 2);
292   wg2Layout->setRowStretch(1, 5);
293
294   /***************************************************************/
295   QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
296   dumb->addWidget(wg1);
297   dumb->addWidget(wg2);
298   myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
299   myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
300
301   /***************************************************************/
302   QFrame* aButtons = new QFrame(this, "button box");
303   aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
304   QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
305   aBtnLayout->setAutoAdd(false);
306
307   QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
308   aOKBtn->setText(tr("SMESH_BUT_OK"));
309   aOKBtn->setAutoDefault(true);
310   aOKBtn->setDefault(true);
311   QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
312   aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
313   aApplyBtn->setAutoDefault(true);
314   QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
315   aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
316   aCloseBtn->setAutoDefault(true);
317
318   aBtnLayout->addWidget(aOKBtn);
319   aBtnLayout->addWidget(aApplyBtn);
320   aBtnLayout->addStretch();
321   aBtnLayout->addWidget(aCloseBtn);
322
323   /***************************************************************/
324   aMainLayout->addWidget(meshGroupLab,    0, 0);
325   aMainLayout->addWidget(myMeshGroupBtn,  0, 1);
326   aMainLayout->addWidget(myMeshGroupLine, 0, 2);
327   aMainLayout->addMultiCellWidget(myTypeGroup,    1, 1, 0, 2);
328   aMainLayout->addWidget(aName,      2, 0);
329   aMainLayout->addWidget(myName,     2, 2);
330   aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
331   aMainLayout->addMultiCellWidget(myWGStack,      4, 4, 0, 2);
332   aMainLayout->setRowStretch( 5, 5 );
333   aMainLayout->addMultiCellWidget(aButtons,       6, 6, 0, 2);
334
335   /* signals and slots connections */
336   connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
337
338   connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
339
340   connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
341
342   connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
343   connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
344
345   connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
346   connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
347   connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
348   connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
349
350   connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
351   connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
352   connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
353   connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
354   connect(myGeomGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
355
356   connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
357   connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
358   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
359
360   /* Init selection */
361   mySMESHGUI->SetActiveDialogBox(this);
362   mySMESHGUI->SetState(800);
363
364   mySelectionMode = -1;
365   myMeshFilter = new SMESH_TypeFilter(MESH);
366   mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
367   myGroupFilter = new SMESH_TypeFilter(GROUP);
368
369   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
370   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
371   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
372
373   myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
374   onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
375
376   if (myMesh->_is_nil() )
377     myTypeGroup->setButton(0);
378
379   updateButtons();
380 }
381
382 //=================================================================================
383 // function : ~SMESHGUI_GroupDlg()
384 // purpose  : Destroys the object and frees any allocated resources
385 //=================================================================================
386 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
387 {
388   // no need to delete child widgets, Qt does it all for us
389   if ( myFilterDlg != 0 )
390   {
391     myFilterDlg->reparent( 0, QPoint() );
392     delete myFilterDlg;
393   }
394 }
395
396 //=================================================================================
397 // function : Init()
398 // purpose  :
399 //=================================================================================
400 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
401 {
402   mySelectionMgr->installFilter(myMeshFilter);
403
404   /* init data from current selection */
405   myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
406   myGroup = SMESH::SMESH_Group::_nil();
407
408   myActor = SMESH::FindActorByObject(myMesh);
409   SMESH::SetPickable(myActor);
410
411   SALOME_ListIO aList;
412   mySelectionMgr->selectedObjects( aList );
413   if( !aList.IsEmpty() )
414   {
415     QString aName = aList.First()->getName();
416     myMeshGroupLine->setText(aName) ;
417     myMeshGroupLine->home( false );
418   }
419
420   myCurrentLineEdit = 0;
421
422   myTypeGroup->setButton(0);
423   onTypeChanged(0);
424 }
425
426 //=================================================================================
427 // function : Init()
428 // purpose  :
429 //=================================================================================
430 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Group_ptr theGroup)
431 {
432   myMesh = theGroup->GetMesh();
433   myGroup = SMESH::SMESH_Group::_duplicate(theGroup);
434
435   myActor = SMESH::FindActorByObject(myMesh);
436   if ( !myActor )
437     myActor = SMESH::FindActorByObject(myGroup);
438   SMESH::SetPickable(myActor);
439
440   int aType = 0;
441   switch(theGroup->GetType()) {
442   case SMESH::NODE: aType= 0; break;
443   case SMESH::EDGE: aType = 1; break;
444   case SMESH::FACE: aType = 2; break;
445   case SMESH::VOLUME: aType = 3; break;
446   }
447
448   myName->setText(myGroup->GetName());
449   myName->home(false);
450   myMeshGroupLine->setText(myGroup->GetName());
451
452   myCurrentLineEdit = 0;
453   myTypeGroup->setButton(aType);
454   myElements->clear();
455   setSelectionMode(aType);
456   myTypeId = aType;
457
458   myIdList.clear();
459   if (!theGroup->IsEmpty()) {
460     SMESH::long_array_var anElements = myGroup->GetListOfID();
461     int k = anElements->length();
462     for (int i = 0; i < k; i++) {
463       myIdList.append(anElements[i]);
464       myElements->insertItem(QString::number(anElements[i]));
465     }
466     myElements->selectAll(true);
467   }
468 }
469
470 //=================================================================================
471 // function : updateButtons()
472 // purpose  :
473 //=================================================================================
474 void SMESHGUI_GroupDlg::updateButtons()
475 {
476   bool enable;
477
478   if (myGrpTypeId == 0)
479     enable = !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0;
480   else if (myGrpTypeId == 1)
481     enable = !myName->text().stripWhiteSpace().isEmpty() && !CORBA::is_nil( myGeomGroup );
482   QPushButton* aBtn;
483   aBtn = (QPushButton*) child("ok", "QPushButton");
484   if (aBtn) aBtn->setEnabled(enable);
485   aBtn = (QPushButton*) child("apply", "QPushButton");
486   if (aBtn) aBtn->setEnabled(enable);
487 }
488
489 //=================================================================================
490 // function : onNameChanged()
491 // purpose  :
492 //=================================================================================
493 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
494 {
495   updateButtons();
496 }
497
498 //=================================================================================
499 // function : onTypeChanged()
500 // purpose  : Group elements type radio button management
501 //=================================================================================
502 void SMESHGUI_GroupDlg::onTypeChanged (int id)
503 {
504   if (myTypeId != id) {
505     myElements->clear();
506     if (myCurrentLineEdit == 0)
507       setSelectionMode(id);
508   }
509   myTypeId = id;
510 }
511
512 //=================================================================================
513 // function : onGrpTypeChanged()
514 // purpose  : Group type radio button management
515 //=================================================================================
516 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
517 {
518   if (myGrpTypeId != id) {
519     myWGStack->raiseWidget( id );
520     onSelectGeomGroup(id == 1);
521   }
522   myGrpTypeId = id;
523 }
524
525 //=================================================================================
526 // function : setSelectionMode()
527 // purpose  : Radio button management
528 //=================================================================================
529 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
530 {
531   // PAL7314
532   if (myMesh->_is_nil())
533     return;
534
535   if (mySelectionMode != theMode) {
536     mySelectionMgr->clearSelected();
537     mySelectionMgr->clearFilters();
538     SMESH::SetPointRepresentation(false);
539     if (theMode < 4) {
540       switch (theMode) {
541       case 0:
542         if (myActor)
543           myActor->SetPointRepresentation(true);
544         else
545           SMESH::SetPointRepresentation(true);
546         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
547           aViewWindow->SetSelectionMode(NodeSelection);
548         break;
549       case 1:
550         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
551           aViewWindow->SetSelectionMode(EdgeSelection);
552         break;
553       case 2:
554         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
555           aViewWindow->SetSelectionMode(FaceSelection);
556         break;
557       default:
558         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
559           aViewWindow->SetSelectionMode(VolumeSelection);
560       }
561     } else {
562       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
563         aViewWindow->SetSelectionMode(ActorSelection);
564       if (theMode == 4)
565         mySelectionMgr->installFilter(mySubMeshFilter);
566       else if (theMode == 5)
567         mySelectionMgr->installFilter(myGroupFilter);
568       else if (theMode == 6)
569         mySelectionMgr->installFilter(myMeshFilter);
570     }
571     mySelectionMode = theMode;
572   }
573 }
574
575 //=================================================================================
576 // function : onApply()
577 // purpose  :
578 //=================================================================================
579 bool SMESHGUI_GroupDlg::onApply()
580 {
581   if (mySMESHGUI->isActiveStudyLocked())
582     return false;
583
584   if (myGrpTypeId == 0 &&
585       !myName->text().stripWhiteSpace().isEmpty() &&
586       myElements->count() > 0) {
587     mySelectionMgr->clearSelected();
588     if (myGroup->_is_nil()) {
589       SMESH::ElementType aType = SMESH::ALL;
590       switch(myTypeId) {
591       case 0: aType = SMESH::NODE; break;
592       case 1: aType = SMESH::EDGE; break;
593       case 2: aType = SMESH::FACE; break;
594       case 3: aType = SMESH::VOLUME; break;
595       }
596       SMESH::long_array_var anIdList = new SMESH::long_array;
597       int i, k = myElements->count();
598       anIdList->length(k);
599       QListBoxItem* anItem;
600       for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
601         anIdList[i] = anItem->text().toInt();
602       }
603
604       myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
605       myGroup->Add(anIdList.inout());
606
607       /* init for next operation */
608       myName->setText("");
609       myElements->clear();
610       myGroup = SMESH::SMESH_Group::_nil();
611
612     } else {
613       myGroup->SetName(myName->text());
614
615       QValueList<int> aAddList;
616       QValueList<int>::iterator anIt;
617       QListBoxItem* anItem;
618
619       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
620         int anId = anItem->text().toInt();
621         if ((anIt = myIdList.find(anId)) == myIdList.end())
622           aAddList.append(anId);
623         else
624           myIdList.remove(anIt);
625       }
626       if (!aAddList.empty()) {
627         SMESH::long_array_var anIdList = new SMESH::long_array;
628         anIdList->length(aAddList.count());
629         int i;
630         for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
631           anIdList[i] = *anIt;
632         myGroup->Add(anIdList.inout());
633       }
634       if (!myIdList.empty()) {
635         SMESH::long_array_var anIdList = new SMESH::long_array;
636         anIdList->length(myIdList.count());
637         int i;
638         for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
639           anIdList[i] = *anIt;
640         myGroup->Remove(anIdList.inout());
641       }
642       /* init for next operation */
643       myIdList.clear();
644       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
645         myIdList.append(anItem->text().toInt());
646     }
647
648     mySMESHGUI->updateObjBrowser(true);
649     SMESH::UpdateView(); // asv: fix of BUG PAL5515
650     mySelectionMgr->clearSelected();
651     return true;
652   } else if (myGrpTypeId == 1 &&
653              !myName->text().stripWhiteSpace().isEmpty() &&
654              !CORBA::is_nil(myGeomGroup))
655   {
656     SMESH::ElementType aType = SMESH::ALL;
657     switch (myTypeId) {
658     case 0: aType = SMESH::NODE; break;
659     case 1: aType = SMESH::EDGE; break;
660     case 2: aType = SMESH::FACE; break;
661     case 3: aType = SMESH::VOLUME; break;
662     }
663
664     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
665     GEOM::GEOM_IGroupOperations_var aGroupOp =
666       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
667
668     SMESH::SMESH_GroupOnGeom_var aGroupOnGeom =
669       myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomGroup);
670
671     mySMESHGUI->updateObjBrowser(true);
672     mySelectionMgr->clearSelected();
673     /* init for next operation */
674     myName->setText("");
675     return true;
676   }
677
678   return false;
679 }
680
681 //=================================================================================
682 // function : onOK()
683 // purpose  :
684 //=================================================================================
685 void SMESHGUI_GroupDlg::onOK()
686 {
687   if ( onApply() )
688     onClose();
689 }
690
691 //=================================================================================
692 // function : onListSelectionChanged()
693 // purpose  : Called when selection in element list is changed
694 //=================================================================================
695 void SMESHGUI_GroupDlg::onListSelectionChanged()
696 {
697   //  MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
698   if( myIsBusy || !myActor) return;
699     myIsBusy = true;
700
701   if (myCurrentLineEdit == 0) {
702     mySelectionMgr->clearSelected();
703     TColStd_MapOfInteger aIndexes;
704     QListBoxItem* anItem;
705     for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
706       if (anItem->isSelected()) {
707         int anId = anItem->text().toInt();
708         aIndexes.Add(anId);
709       }
710     }
711     mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
712     SALOME_ListIO aList;
713     aList.Append(myActor->getIO());
714     mySelectionMgr->setSelectedObjects(aList,false);
715     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
716       aViewWindow->highlight( myActor->getIO(), true, true );
717   }
718   myIsBusy = false;
719 }
720
721 //=================================================================================
722 // function : onObjectSelectionChanged()
723 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
724 //=================================================================================
725 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
726 {
727   if ( myIsBusy || !isEnabled()) return;
728     myIsBusy = true;
729
730   SALOME_ListIO aList;
731   mySelectionMgr->selectedObjects( aList );
732   
733   int aNbSel = aList.Extent();
734   myElements->clearSelection();
735
736   if (myCurrentLineEdit) {
737     myCurrentLineEdit->setText("");
738     QString aString = "";
739
740     if (myCurrentLineEdit == myMeshGroupLine) {
741       mySelectSubMesh->setEnabled(false);
742       mySelectGroup->setEnabled(false);
743       myGroupLine->setText("");
744       mySubMeshLine->setText("");
745
746       myGeomGroupBtn->setEnabled(false);
747       myGeomGroupLine->setEnabled(false);
748       myGeomGroupLine->setText("");
749       if (!myCreate)
750         myName->setText("");
751
752       myElements->clear();
753
754       if (aNbSel != 1 ) {
755         myGroup = SMESH::SMESH_Group::_nil();
756         myMesh = SMESH::SMESH_Mesh::_nil();
757         myIsBusy = false;
758         return;
759       }
760       Handle(SALOME_InteractiveObject) IO = aList.First();
761
762       if (myCreate) {
763         myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
764         if (myMesh->_is_nil())
765         {
766           myIsBusy = false;
767           return;
768         }
769         myGroup = SMESH::SMESH_Group::_nil();
770
771         myActor = SMESH::FindActorByObject(myMesh);
772         SMESH::SetPickable(myActor);
773
774         aString = aList.First()->getName();
775         myMeshGroupLine->setText(aString) ;
776         myMeshGroupLine->home( false );
777
778         mySelectSubMesh->setEnabled(true);
779         mySelectGroup->setEnabled(true);
780         myGeomGroupBtn->setEnabled(true);
781         myGeomGroupLine->setEnabled(true);
782         updateButtons();
783       } else {
784         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(IO);
785         if (aGroup->_is_nil())
786         {
787           myIsBusy = false;
788           return;
789         }
790         myIsBusy = false;
791         myCurrentLineEdit = 0;
792         init(aGroup);
793         myIsBusy = true;
794         mySelectSubMesh->setEnabled(true);
795         mySelectGroup->setEnabled(true);
796         myGeomGroupBtn->setEnabled(true);
797         myGeomGroupLine->setEnabled(true);
798       }
799       myCurrentLineEdit = 0;
800       myIsBusy = false;
801       if (!myCreate)
802         return;
803
804       if (myTypeId == -1)
805         onTypeChanged(0);
806       else {
807         myElements->clear();
808         setSelectionMode(myTypeId);
809       }
810
811       myIsBusy = false;
812       return;
813
814     } else if (myCurrentLineEdit == myGeomGroupLine) {
815       if (aNbSel != 1) {
816         myGeomGroup = GEOM::GEOM_Object::_nil();
817         myIsBusy = false;
818         return;
819       }
820
821       Standard_Boolean testResult = Standard_False;
822       myGeomGroup = GEOMBase::ConvertIOinGEOMObject(aList.First(), testResult);
823
824       // Check if the object is a geometry group
825       if (!testResult || CORBA::is_nil(myGeomGroup)) {
826         myGeomGroup = GEOM::GEOM_Object::_nil();
827         myIsBusy = false;
828         return;
829       }
830       // Check if group constructed on the same shape as a mesh or on its child
831       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
832       GEOM::GEOM_IGroupOperations_var anOp =
833         SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
834
835       // The main shape of the group
836       GEOM::GEOM_Object_var aGroupMainShape;
837       if (myGeomGroup->GetType() == 37)
838         aGroupMainShape = anOp->GetMainShape(myGeomGroup);
839       else
840         aGroupMainShape = GEOM::GEOM_Object::_duplicate(myGeomGroup);
841       _PTR(SObject) aGroupMainShapeSO =
842         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
843         aStudy->FindObjectIOR(aGroupMainShape->GetStudyEntry());
844
845       // The mesh SObject
846       _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
847       if (!aMeshSO) {
848         myGeomGroup = GEOM::GEOM_Object::_nil();
849         myIsBusy = false;
850         return;
851       }
852       _PTR(SObject) anObj, aRef;
853       bool isRefOrSubShape = false;
854       if (aMeshSO->FindSubObject(1, anObj) &&  anObj->ReferencedObject(aRef)) {
855         //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
856         if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
857           isRefOrSubShape = true;
858         } else {
859           _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
860           _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
861           //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
862           while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
863             //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
864             if (aRef->GetID() == aFather->GetID())
865               isRefOrSubShape = true;
866             else
867               aFather = aFather->GetFather();
868           }
869         }
870       }
871       if (!isRefOrSubShape) {
872         myGeomGroup = GEOM::GEOM_Object::_nil();
873         myIsBusy = false;
874         return;
875       }
876     }
877
878     if(aNbSel >= 1) {
879       if(aNbSel > 1) {
880         if(myCurrentLineEdit == mySubMeshLine)
881           aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
882         else if(myCurrentLineEdit == myGroupLine || myCurrentLineEdit == myGeomGroupLine)
883           aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
884       } else {
885         aString = aList.First()->getName();
886       }
887     }
888
889     myCurrentLineEdit->setText(aString);
890     myCurrentLineEdit->home(false);
891
892     updateButtons();
893
894   } else {
895     if (aNbSel == 1 && myActor ) {
896       QString aListStr = "";
897       int aNbItems = 0;
898       if (myTypeId == 0) {
899         aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
900       } else {
901         aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
902       }
903       if (aNbItems > 0) {
904         QStringList anElements = QStringList::split(" ", aListStr);
905         QListBoxItem* anItem = 0;
906         for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
907           anItem = myElements->findItem(*it, Qt::ExactMatch);
908           if (anItem) myElements->setSelected(anItem, true);
909         }
910       }
911     }
912   }
913
914   if (!myActor) {
915     if (!myGroup->_is_nil())
916       myActor = SMESH::FindActorByObject(myGroup);
917     else
918       myActor = SMESH::FindActorByObject(myMesh);
919   }
920
921   myIsBusy = false;
922 }
923
924 //=================================================================================
925 // function : onSelectSubMesh()
926 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
927 //=================================================================================
928 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
929 {
930   if (on) {
931     if (mySelectGroup->isChecked()) {
932       mySelectGroup->setChecked(false);
933     }
934     //VSR: else if (mySelectGeomGroup->isChecked()) {
935     //VSR:   mySelectGeomGroup->setChecked(false);
936     //VSR: }
937     myCurrentLineEdit = mySubMeshLine;
938     setSelectionMode(4);
939   }
940   else {
941     mySubMeshLine->setText("");
942     myCurrentLineEdit = 0;
943     if (myTypeId != -1)
944       setSelectionMode(myTypeId);
945   }
946   mySubMeshBtn->setEnabled(on);
947   mySubMeshLine->setEnabled(on);
948 }
949
950
951 //=================================================================================
952 // function : (onSelectGroup)
953 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
954 //=================================================================================
955 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
956 {
957   if (on) {
958     if (mySelectSubMesh->isChecked()) {
959       mySelectSubMesh->setChecked(false);
960     }
961     myCurrentLineEdit = myGroupLine;
962     setSelectionMode(5);
963   }
964   else {
965     myGroupLine->setText("");
966     myCurrentLineEdit = 0;
967     if (myTypeId != -1)
968       setSelectionMode(myTypeId);
969   }
970   myGroupBtn->setEnabled(on);
971   myGroupLine->setEnabled(on);
972 }
973
974
975 //=================================================================================
976 // function : (onSelectGeomGroup)
977 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
978 //=================================================================================
979 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
980 {
981   if (on) {
982     if (mySelectSubMesh->isChecked()) {
983       mySelectSubMesh->setChecked(false);
984     }
985     else if (mySelectGroup->isChecked()) {
986       mySelectGroup->setChecked(false);
987     }
988     myCurrentLineEdit = myGeomGroupLine;
989     setSelectionMode(7);
990   }
991   else {
992     myGeomGroupLine->setText("");
993     myCurrentLineEdit = 0;
994     if (myTypeId != -1)
995       setSelectionMode(myTypeId);
996   }
997 }
998
999
1000 //=================================================================================
1001 // function : setCurrentSelection()
1002 // purpose  :
1003 //=================================================================================
1004 void SMESHGUI_GroupDlg::setCurrentSelection()
1005 {
1006   QPushButton* send = (QPushButton*)sender();
1007   myCurrentLineEdit = 0;
1008   if (send == myMeshGroupBtn) {
1009     myCurrentLineEdit = myMeshGroupLine;
1010     if (myCreate)
1011       setSelectionMode(6);
1012     else
1013       setSelectionMode(5);
1014     onObjectSelectionChanged();
1015   }
1016   else if (send == mySubMeshBtn) {
1017     myCurrentLineEdit = mySubMeshLine;
1018     onObjectSelectionChanged();
1019   }
1020   else if (send == myGroupBtn) {
1021     myCurrentLineEdit = myGroupLine;
1022     onObjectSelectionChanged();
1023   }
1024   else if (send == myGeomGroupBtn) {
1025     myCurrentLineEdit = myGeomGroupLine;
1026     setSelectionMode(7);
1027     onObjectSelectionChanged();
1028   }
1029 }
1030
1031
1032 //=================================================================================
1033 // function : setFilters()
1034 // purpose  : SLOT. Called when "Filter" button pressed.
1035 //=================================================================================
1036 void SMESHGUI_GroupDlg::setFilters()
1037 {
1038   SMESH::ElementType aType = SMESH::ALL;
1039   switch ( myTypeId )
1040   {
1041     case 0 : aType = SMESH::NODE; break;
1042     case 1 : aType = SMESH::EDGE; break;
1043     case 2 : aType = SMESH::FACE; break;
1044     case 3 : aType = SMESH::VOLUME; break;
1045     default: return;
1046   }
1047
1048   if ( myFilterDlg == 0 )
1049   {
1050     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1051     connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1052   }
1053   else
1054     myFilterDlg->Init( aType );
1055
1056   myFilterDlg->SetSelection();
1057   myFilterDlg->SetMesh( myMesh );
1058   myFilterDlg->SetSourceWg( myElements );
1059
1060   myFilterDlg->show();
1061 }
1062
1063 //=================================================================================
1064 // function : onFilterAccepted()
1065 // purpose  : SLOT. Called when Filter dlg closed with OK button.
1066 //            Uncheck "Select submesh" and "Select group" checkboxes
1067 //=================================================================================
1068 void SMESHGUI_GroupDlg::onFilterAccepted()
1069 {
1070   if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1071   {
1072     mySelectionMode = myTypeId;
1073     mySelectSubMesh->setChecked( false );
1074     mySelectGroup->setChecked( false );
1075   }
1076 }
1077
1078 //=================================================================================
1079 // function : onAdd()
1080 // purpose  :
1081 //=================================================================================
1082 void SMESHGUI_GroupDlg::onAdd()
1083 {
1084   SALOME_ListIO aList;
1085   mySelectionMgr->selectedObjects( aList );
1086
1087   int aNbSel = aList.Extent();
1088
1089   if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1090
1091   myIsBusy = true;
1092
1093   SMESH::ElementType aType = SMESH::ALL;
1094   switch(myTypeId) {
1095   case 0: aType = SMESH::NODE; break;
1096   case 1: aType = SMESH::EDGE; break;
1097   case 2: aType = SMESH::FACE; break;
1098   case 3: aType = SMESH::VOLUME; break;
1099   }
1100
1101   if (myCurrentLineEdit == 0) {
1102     //if (aNbSel != 1) { myIsBusy = false; return; }
1103     QString aListStr = "";
1104     int aNbItems = 0;
1105     if (myTypeId == 0) {
1106       aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1107     }
1108     else {
1109       aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1110     }
1111     if (aNbItems > 0) {
1112       QStringList anElements = QStringList::split(" ", aListStr);
1113       QListBoxItem* anItem = 0;
1114       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1115         anItem = myElements->findItem(*it, Qt::ExactMatch);
1116         if (!anItem) {
1117           anItem = new QListBoxText(*it);
1118           myElements->insertItem(anItem);
1119         }
1120         myElements->setSelected(anItem, true);
1121       }
1122     }
1123   } else if (myCurrentLineEdit == mySubMeshLine) {
1124     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1125     
1126     SALOME_ListIO aList;
1127     mySelectionMgr->selectedObjects( aList );
1128
1129     SALOME_ListIteratorOfListIO anIt (aList);
1130     for (; anIt.More(); anIt.Next()) {
1131       SMESH::SMESH_subMesh_var aSubMesh =
1132         SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1133       if (!aSubMesh->_is_nil()) {
1134         // check if mesh is the same
1135         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1136           try {
1137             SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1138             int k = anElements->length();
1139             QListBoxItem* anItem = 0;
1140             for (int i = 0; i < k; i++) {
1141               QString aText = QString::number(anElements[i]);
1142               anItem = myElements->findItem(aText, Qt::ExactMatch);
1143               if (!anItem) {
1144                 anItem = new QListBoxText(aText);
1145                 myElements->insertItem(anItem);
1146               }
1147               myElements->setSelected(anItem, true);
1148             }
1149           }
1150           catch (const SALOME::SALOME_Exception& ex) {
1151             SalomeApp_Tools::QtCatchCorbaException(ex);
1152           }
1153         }
1154       }
1155     }
1156     mySelectSubMesh->setChecked(false);
1157     myIsBusy = false;
1158     onListSelectionChanged();
1159
1160   } else if (myCurrentLineEdit == myGroupLine) {
1161     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1162     SALOME_ListIO aList;
1163     mySelectionMgr->selectedObjects( aList );
1164     
1165     SALOME_ListIteratorOfListIO anIt (aList);
1166     for (; anIt.More(); anIt.Next()) {
1167       SMESH::SMESH_Group_var aGroup =
1168         SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1169       if (!aGroup->_is_nil()) {
1170         // check if mesh is the same
1171         if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1172           SMESH::long_array_var anElements = aGroup->GetListOfID();
1173           int k = anElements->length();
1174           QListBoxItem* anItem = 0;
1175           for (int i = 0; i < k; i++) {
1176             QString aText = QString::number(anElements[i]);
1177             anItem = myElements->findItem(aText, Qt::ExactMatch);
1178             if (!anItem) {
1179               anItem = new QListBoxText(aText);
1180               myElements->insertItem(anItem);
1181             }
1182             myElements->setSelected(anItem, true);
1183           }
1184         }
1185       }
1186     }
1187     mySelectGroup->setChecked(false);
1188     myIsBusy = false;
1189     onListSelectionChanged();
1190
1191   } else if (myCurrentLineEdit == myGeomGroupLine && !CORBA::is_nil(myGeomGroup)) {
1192     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1193     GEOM::GEOM_IGroupOperations_var aGroupOp =
1194       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1195
1196     SMESH::ElementType aGroupType = SMESH::ALL;
1197     switch(aGroupOp->GetType(myGeomGroup)) {
1198     case 7: aGroupType = SMESH::NODE; break;
1199     case 6: aGroupType = SMESH::EDGE; break;
1200     case 4: aGroupType = SMESH::FACE; break;
1201     case 2: aGroupType = SMESH::VOLUME; break;
1202     default: myIsBusy = false; return;
1203     }
1204
1205     if (aGroupType == aType) {
1206       _PTR(SObject) aGroupSO =
1207         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1208         aStudy->FindObjectIOR(myGeomGroup->GetStudyEntry());
1209       // Construct filter
1210       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1211       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1212       SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1213       aBelongToGeom->SetGeom(myGeomGroup);
1214       aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1215       aBelongToGeom->SetElementType(aType);
1216       aFilter->SetPredicate(aBelongToGeom);
1217
1218       SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1219
1220       int k = anElements->length();
1221       QListBoxItem* anItem = 0;
1222       for (int i = 0; i < k; i++) {
1223         QString aText = QString::number(anElements[i]);
1224         anItem = myElements->findItem(aText, Qt::ExactMatch);
1225         if (!anItem) {
1226           anItem = new QListBoxText(aText);
1227           myElements->insertItem(anItem);
1228         }
1229         myElements->setSelected(anItem, true);
1230       }
1231     }
1232
1233     //VSR: mySelectGeomGroup->setChecked(false);
1234     myIsBusy = false;
1235     onListSelectionChanged();
1236   }
1237   myIsBusy = false;
1238   //  mySelectionMgr->clearSelected();
1239   updateButtons();
1240 }
1241
1242 //=================================================================================
1243 // function : onRemove()
1244 // purpose  :
1245 //=================================================================================
1246 void SMESHGUI_GroupDlg::onRemove()
1247 {
1248   myIsBusy = true;
1249   if (myCurrentLineEdit == 0) {
1250     for (int i = myElements->count(); i > 0; i--) {
1251       if (myElements->isSelected(i-1)) {
1252         myElements->removeItem(i-1);
1253       }
1254     }
1255   } else {
1256     SALOME_ListIO aList;
1257     mySelectionMgr->selectedObjects( aList );
1258
1259     int aNbSel = aList.Extent();
1260
1261     if (aNbSel == 0) { myIsBusy = false; return; }
1262
1263     SMESH::ElementType aType = SMESH::ALL;
1264     switch(myTypeId) {
1265     case 0: aType = SMESH::NODE; break;
1266     case 1: aType = SMESH::EDGE; break;
1267     case 2: aType = SMESH::FACE; break;
1268     case 3: aType = SMESH::VOLUME; break;
1269     }
1270
1271     if (myCurrentLineEdit == mySubMeshLine) {
1272       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1273       SALOME_ListIO aList;
1274       mySelectionMgr->selectedObjects( aList );
1275
1276       SALOME_ListIteratorOfListIO anIt (aList);
1277       for (; anIt.More(); anIt.Next()) {
1278         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1279         if (!aSubMesh->_is_nil()) {
1280           // check if mesh is the same
1281           if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1282             if (aType == SMESH::NODE) {
1283               try {
1284                 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1285                 int k = anElements->length();
1286                 QListBoxItem* anItem = 0;
1287                 for (int i = 0; i < k; i++) {
1288                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1289                   if (anItem) delete anItem;
1290                 }
1291               }
1292               catch (const SALOME::SALOME_Exception& ex) {
1293                 SalomeApp_Tools::QtCatchCorbaException(ex);
1294               }
1295             }
1296             else {
1297               try {
1298                 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1299                 int k = anElements->length();
1300                 QListBoxItem* anItem = 0;
1301                 for (int i = 0; i < k; i++) {
1302                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1303                   if (anItem) delete anItem;
1304                 }
1305               }
1306               catch (const SALOME::SALOME_Exception& ex) {
1307                 SalomeApp_Tools::QtCatchCorbaException(ex);
1308               }
1309             }
1310           }
1311         }
1312       }
1313     }
1314     else if (myCurrentLineEdit == myGroupLine) {
1315       Standard_Boolean aRes;
1316       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1317       SALOME_ListIO aList;
1318       mySelectionMgr->selectedObjects( aList );
1319
1320       SALOME_ListIteratorOfListIO anIt (aList);
1321       for (; anIt.More(); anIt.Next()) {
1322         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1323         if (aRes && !aGroup->_is_nil()) {
1324           // check if mesh is the same
1325           if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1326             SMESH::long_array_var anElements = aGroup->GetListOfID();
1327             int k = anElements->length();
1328             QListBoxItem* anItem = 0;
1329             for (int i = 0; i < k; i++) {
1330               anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1331               if (anItem) delete anItem;
1332             }
1333           }
1334         }
1335       }
1336     }
1337   }
1338   myIsBusy = false;
1339   updateButtons();
1340 }
1341
1342 //=================================================================================
1343 // function : onSort()
1344 // purpose  :
1345 //=================================================================================
1346 void SMESHGUI_GroupDlg::onSort()
1347 {
1348   // PAL5412: sorts items in ascending by "string" value
1349   // myElements->sort(true);
1350   // myElements->update();
1351   int i, k = myElements->count();
1352   if (k > 0) {
1353     myIsBusy = true;
1354     QStringList aSelected;
1355     std::vector<int> anArray(k);
1356     //    QMemArray<int> anArray(k);
1357     QListBoxItem* anItem;
1358     // fill the array
1359     for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1360       anArray[i] = anItem->text().toInt();
1361       if (anItem->isSelected())
1362         aSelected.append(anItem->text());
1363     }
1364     // sort & update list
1365     std::sort(anArray.begin(), anArray.end());
1366     //    anArray.sort();
1367     myElements->clear();
1368     for (i = 0; i < k; i++) {
1369       myElements->insertItem(QString::number(anArray[i]));
1370     }
1371     for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1372       anItem = myElements->findItem(*it, Qt::ExactMatch);
1373       if (anItem) myElements->setSelected(anItem, true);
1374     }
1375     myIsBusy = false;
1376   }
1377 }
1378
1379 //=================================================================================
1380 // function : closeEvent()
1381 // purpose  :
1382 //=================================================================================
1383 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1384 {
1385   onClose();
1386 }
1387
1388 //=================================================================================
1389 // function : SMESHGUI_GroupDlg::onClose
1390 // purpose  : SLOT called when "Close" button pressed. Close dialog
1391 //=================================================================================
1392 void SMESHGUI_GroupDlg::onClose()
1393 {
1394   if (SMESH::GetCurrentVtkView()) {
1395     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1396     SMESH::SetPointRepresentation(false);
1397     SMESH::SetPickable();
1398   }
1399
1400   mySelectionMgr->clearSelected();
1401   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1402     aViewWindow->SetSelectionMode(ActorSelection);
1403   mySelectionMgr->clearFilters();
1404   mySMESHGUI->ResetState();
1405
1406   reject();
1407 }
1408
1409 //=================================================================================
1410 // function : SMESHGUI_GroupDlg::onDeactivate
1411 // purpose  : SLOT called when dialog must be deativated
1412 //=================================================================================
1413 void SMESHGUI_GroupDlg::onDeactivate()
1414 {
1415   mySMESHGUI->ResetState();
1416   setEnabled(false);
1417 }
1418
1419 //=================================================================================
1420 // function : SMESHGUI_GroupDlg::enterEvent
1421 // purpose  : Event filter
1422 //=================================================================================
1423 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1424 {
1425   if (!isEnabled()) {
1426     mySMESHGUI->EmitSignalDeactivateDialog();
1427     setEnabled(true);
1428     mySelectionMode = -1;
1429     setSelectionMode(myTypeId);
1430     //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1431     mySMESHGUI->SetActiveDialogBox(this);
1432     mySMESHGUI->SetState(800);
1433   }
1434 }
1435
1436 //=================================================================================
1437 // function : hideEvent
1438 // purpose  : caused by ESC key
1439 //=================================================================================
1440 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1441 {
1442   if (!isMinimized())
1443     onClose();
1444 }