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