Salome HOME
Fix for bug ( IPAL9603 3.0.0(current2707): SMESH ? edit mesh does not work ).
[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
128   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
129
130   initDialog(false);
131   if (!theGroup->_is_nil())
132     init(theGroup);
133   else {
134     mySelectSubMesh->setEnabled(false);
135     mySelectGroup->setEnabled(false);
136   }
137   
138   /* Move widget on the botton right corner of main widget */
139   int x, y ;
140   mySMESHGUI->DefineDlgPosition(this, x, y);
141   this->move(x, y);
142 }
143
144 //=================================================================================
145 // function : SMESHGUI_GroupDlg()
146 // purpose  :
147 //=================================================================================
148 void SMESHGUI_GroupDlg::initDialog(bool create)
149 {
150   myFilterDlg = 0;
151   myCreate = create;
152   myCurrentLineEdit = 0;
153
154   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
155
156   if (create)
157     setCaption(tr("SMESH_CREATE_GROUP_TITLE"));
158   else
159     setCaption(tr("SMESH_EDIT_GROUP_TITLE"));
160
161   setSizeGripEnabled(TRUE);
162
163   QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
164
165   /***************************************************************/
166   QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
167   if (create)
168     meshGroupLab->setText(tr("SMESH_MESH"));
169   else
170     meshGroupLab->setText(tr("SMESH_GROUP"));
171   myMeshGroupBtn = new QPushButton(this, "mesh/group button");
172   myMeshGroupBtn->setPixmap(image0);
173   myMeshGroupLine = new QLineEdit(this, "mesh/group line");
174   myMeshGroupLine->setReadOnly(true);
175
176   /***************************************************************/
177   myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
178   myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
179   myTypeGroup->setExclusive(true);
180
181   QStringList types;
182   types.append(tr("MESH_NODE"));
183   types.append(tr("SMESH_EDGE"));
184   types.append(tr("SMESH_FACE"));
185   types.append(tr("SMESH_VOLUME"));
186   QRadioButton* rb;
187   for (int i = 0; i < types.count(); i++) {
188     rb = new QRadioButton(types[i], myTypeGroup);
189   }
190   myTypeGroup->setEnabled(create);
191   myTypeId = -1;
192
193   /***************************************************************/
194   QLabel* aName = new QLabel(this, "name label");
195   aName->setText(tr("SMESH_NAME"));
196   aName->setMinimumSize(50,0);
197   myName = new QLineEdit(this, "name");
198
199   /***************************************************************/
200   myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
201   myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
202   myGrpTypeGroup->setExclusive(true);
203   QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
204   QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"),   myGrpTypeGroup);
205   myGrpTypeGroup->setEnabled(create);
206   myGrpTypeId = -1;
207
208   /***************************************************************/
209   myWGStack = new QWidgetStack( this, "widget stack");
210   QWidget* wg1 = new QFrame( myWGStack, "first widget" );
211   QWidget* wg2 = new QFrame( myWGStack, "second widget" );
212
213   /***************************************************************/
214   QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
215   aContentBox->setTitle(tr("SMESH_CONTENT"));
216   QFrame* aContent = new QFrame(aContentBox, "content");
217   QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
218   aLayout->setSpacing(6);
219   aLayout->setAutoAdd(false);
220
221   QLabel* aLabel = new QLabel(aContent, "elements label");
222   aLabel->setText(tr("SMESH_ID_ELEMENTS"));
223   myElements = new QListBox(aContent, "elements list");
224   myElements->setSelectionMode(QListBox::Extended);
225
226   myFilter = new QPushButton(aContent, "filter");
227   myFilter->setText(tr("SMESH_BUT_FILTER"));
228   QPushButton* aAddBtn = new QPushButton(aContent, "add");
229   aAddBtn->setText(tr("SMESH_BUT_ADD"));
230   QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
231   aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
232   QPushButton* aSortBtn = new QPushButton(aContent, "sort");
233   aSortBtn->setText(tr("SMESH_BUT_SORT"));
234
235   aLayout->addWidget(aLabel, 0, 0);
236   aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
237   aLayout->addWidget(myFilter, 1, 2);
238   aLayout->addWidget(aAddBtn, 3, 2);
239   aLayout->addWidget(aRemoveBtn, 4, 2);
240   aLayout->addWidget(aSortBtn, 6, 2);
241
242   aLayout->setColStretch(0, 1);
243   aLayout->addColSpacing(1, 20);
244   aLayout->addColSpacing(3, 20);
245   aLayout->setRowStretch(2, 1);
246   aLayout->setRowStretch(5, 1);
247
248   /***************************************************************/
249   QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
250   aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
251
252   mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
253   mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
254   mySelectSubMesh->setMinimumSize(50, 0);
255   mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
256   mySubMeshBtn->setText("");
257   mySubMeshBtn->setPixmap(image0);
258   mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
259   mySubMeshLine->setReadOnly(true);
260   onSelectSubMesh(false);
261
262   mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
263   mySelectGroup->setText(tr("SMESH_GROUP"));
264   mySelectGroup->setMinimumSize(50, 0);
265   myGroupBtn = new QPushButton(aSelectBox, "group button");
266   myGroupBtn->setText("");
267   myGroupBtn->setPixmap(image0);
268   myGroupLine = new QLineEdit(aSelectBox, "group line");
269   myGroupLine->setReadOnly(true);
270   onSelectGroup(false);
271
272   /***************************************************************/
273   QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
274   wg1Layout->addWidget(aContentBox, 0, 0);
275   wg1Layout->addWidget(aSelectBox, 1, 0);
276   wg1Layout->setRowStretch(2, 5);
277
278   /***************************************************************/
279   QLabel* geomObject = new QLabel(wg2, "geometry object label");
280   geomObject->setText(tr("SMESH_OBJECT_GEOM"));
281   myGeomGroupBtn = new QPushButton(wg2, "geometry group button");
282   myGeomGroupBtn->setText("");
283   myGeomGroupBtn->setPixmap(image0);
284   myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
285   myGeomGroupLine->setReadOnly(true); //VSR ???
286   onSelectGeomGroup(false);
287
288   /***************************************************************/
289   QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
290   wg2Layout->addWidget(geomObject,     0, 0);
291   wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
292   wg2Layout->addWidget(myGeomGroupLine,0, 2);
293   wg2Layout->setRowStretch(1, 5);
294
295   /***************************************************************/
296   QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
297   dumb->addWidget(wg1);
298   dumb->addWidget(wg2);
299   myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
300   myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
301
302   /***************************************************************/
303   QFrame* aButtons = new QFrame(this, "button box");
304   aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
305   QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
306   aBtnLayout->setAutoAdd(false);
307
308   QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
309   aOKBtn->setText(tr("SMESH_BUT_OK"));
310   aOKBtn->setAutoDefault(true);
311   aOKBtn->setDefault(true);
312   QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
313   aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
314   aApplyBtn->setAutoDefault(true);
315   QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
316   aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
317   aCloseBtn->setAutoDefault(true);
318
319   aBtnLayout->addWidget(aOKBtn);
320   aBtnLayout->addWidget(aApplyBtn);
321   aBtnLayout->addStretch();
322   aBtnLayout->addWidget(aCloseBtn);
323
324   /***************************************************************/
325   aMainLayout->addWidget(meshGroupLab,    0, 0);
326   aMainLayout->addWidget(myMeshGroupBtn,  0, 1);
327   aMainLayout->addWidget(myMeshGroupLine, 0, 2);
328   aMainLayout->addMultiCellWidget(myTypeGroup,    1, 1, 0, 2);
329   aMainLayout->addWidget(aName,      2, 0);
330   aMainLayout->addWidget(myName,     2, 2);
331   aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
332   aMainLayout->addMultiCellWidget(myWGStack,      4, 4, 0, 2);
333   aMainLayout->setRowStretch( 5, 5 );
334   aMainLayout->addMultiCellWidget(aButtons,       6, 6, 0, 2);
335
336   /* signals and slots connections */
337   connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
338
339   connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
340
341   connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
342
343   connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
344   connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
345
346   connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
347   connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
348   connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
349   connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
350
351   connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
352   connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
353   connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
354   connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
355   connect(myGeomGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
356
357   connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
358   connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
359   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
360
361   /* Init selection */
362   mySMESHGUI->SetActiveDialogBox(this);
363   mySMESHGUI->SetState(800);
364
365   mySelectionMode = -1;
366   myMeshFilter = new SMESH_TypeFilter(MESH);
367   mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
368   myGroupFilter = new SMESH_TypeFilter(GROUP);
369
370   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
371   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
372   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
373
374   myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
375   onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
376
377   if (myMesh->_is_nil() )
378     myTypeGroup->setButton(0);
379
380   updateButtons();
381 }
382
383 //=================================================================================
384 // function : ~SMESHGUI_GroupDlg()
385 // purpose  : Destroys the object and frees any allocated resources
386 //=================================================================================
387 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
388 {
389   // no need to delete child widgets, Qt does it all for us
390   if ( myFilterDlg != 0 )
391   {
392     myFilterDlg->reparent( 0, QPoint() );
393     delete myFilterDlg;
394   }
395 }
396
397 //=================================================================================
398 // function : Init()
399 // purpose  :
400 //=================================================================================
401 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
402 {
403   mySelectionMgr->installFilter(myMeshFilter);
404
405   /* init data from current selection */
406   myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
407   myGroup = SMESH::SMESH_Group::_nil();
408
409   myActor = SMESH::FindActorByObject(myMesh);
410   SMESH::SetPickable(myActor);
411
412   SALOME_ListIO aList;
413   mySelectionMgr->selectedObjects( aList );
414   if( !aList.IsEmpty() )
415   {
416     QString aName = aList.First()->getName();
417     myMeshGroupLine->setText(aName) ;
418     myMeshGroupLine->home( false );
419   }
420
421   myCurrentLineEdit = 0;
422
423   myTypeGroup->setButton(0);
424   onTypeChanged(0);
425 }
426
427 //=================================================================================
428 // function : Init()
429 // purpose  :
430 //=================================================================================
431 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Group_ptr theGroup)
432 {
433   myMesh = theGroup->GetMesh();
434   myGroup = SMESH::SMESH_Group::_duplicate(theGroup);
435
436   myActor = SMESH::FindActorByObject(myMesh);
437   if ( !myActor )
438     myActor = SMESH::FindActorByObject(myGroup);
439   SMESH::SetPickable(myActor);
440
441   int aType = 0;
442   switch(theGroup->GetType()) {
443   case SMESH::NODE: aType= 0; break;
444   case SMESH::EDGE: aType = 1; break;
445   case SMESH::FACE: aType = 2; break;
446   case SMESH::VOLUME: aType = 3; break;
447   }
448
449   myName->setText(myGroup->GetName());
450   myName->home(false);
451   myMeshGroupLine->setText(myGroup->GetName());
452
453   myCurrentLineEdit = 0;
454   myTypeGroup->setButton(aType);
455   myElements->clear();
456   setSelectionMode(aType);
457   myTypeId = aType;
458
459   myIdList.clear();
460   if (!theGroup->IsEmpty()) {
461     SMESH::long_array_var anElements = myGroup->GetListOfID();
462     int k = anElements->length();
463     for (int i = 0; i < k; i++) {
464       myIdList.append(anElements[i]);
465       myElements->insertItem(QString::number(anElements[i]));
466     }
467     myElements->selectAll(true);
468   }
469 }
470
471 //=================================================================================
472 // function : updateButtons()
473 // purpose  :
474 //=================================================================================
475 void SMESHGUI_GroupDlg::updateButtons()
476 {
477   bool enable;
478
479   if (myGrpTypeId == 0)
480     enable = !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0;
481   else if (myGrpTypeId == 1)
482     enable = !myName->text().stripWhiteSpace().isEmpty() && !CORBA::is_nil( myGeomGroup );
483   QPushButton* aBtn;
484   aBtn = (QPushButton*) child("ok", "QPushButton");
485   if (aBtn) aBtn->setEnabled(enable);
486   aBtn = (QPushButton*) child("apply", "QPushButton");
487   if (aBtn) aBtn->setEnabled(enable);
488 }
489
490 //=================================================================================
491 // function : onNameChanged()
492 // purpose  :
493 //=================================================================================
494 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
495 {
496   updateButtons();
497 }
498
499 //=================================================================================
500 // function : onTypeChanged()
501 // purpose  : Group elements type radio button management
502 //=================================================================================
503 void SMESHGUI_GroupDlg::onTypeChanged (int id)
504 {
505   if (myTypeId != id) {
506     myElements->clear();
507     if (myCurrentLineEdit == 0)
508       setSelectionMode(id);
509   }
510   myTypeId = id;
511 }
512
513 //=================================================================================
514 // function : onGrpTypeChanged()
515 // purpose  : Group type radio button management
516 //=================================================================================
517 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
518 {
519   if (myGrpTypeId != id) {
520     myWGStack->raiseWidget( id );
521     onSelectGeomGroup(id == 1);
522   }
523   myGrpTypeId = id;
524 }
525
526 //=================================================================================
527 // function : setSelectionMode()
528 // purpose  : Radio button management
529 //=================================================================================
530 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
531 {
532   // PAL7314
533   if (myMesh->_is_nil())
534     return;
535
536   if (mySelectionMode != theMode) {
537     mySelectionMgr->clearSelected();
538     mySelectionMgr->clearFilters();
539     SMESH::SetPointRepresentation(false);
540     if (theMode < 4) {
541       switch (theMode) {
542       case 0:
543         if (myActor)
544           myActor->SetPointRepresentation(true);
545         else
546           SMESH::SetPointRepresentation(true);
547         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
548           aViewWindow->SetSelectionMode(NodeSelection);
549         break;
550       case 1:
551         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
552           aViewWindow->SetSelectionMode(EdgeSelection);
553         break;
554       case 2:
555         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
556           aViewWindow->SetSelectionMode(FaceSelection);
557         break;
558       default:
559         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
560           aViewWindow->SetSelectionMode(VolumeSelection);
561       }
562     } else {
563       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
564         aViewWindow->SetSelectionMode(ActorSelection);
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     }
572     mySelectionMode = theMode;
573   }
574 }
575
576 //=================================================================================
577 // function : onApply()
578 // purpose  :
579 //=================================================================================
580 bool SMESHGUI_GroupDlg::onApply()
581 {
582   if (mySMESHGUI->isActiveStudyLocked())
583     return false;
584
585   if (myGrpTypeId == 0 &&
586       !myName->text().stripWhiteSpace().isEmpty() &&
587       myElements->count() > 0) {
588     mySelectionMgr->clearSelected();
589     if (myGroup->_is_nil()) {
590       SMESH::ElementType aType = SMESH::ALL;
591       switch(myTypeId) {
592       case 0: aType = SMESH::NODE; break;
593       case 1: aType = SMESH::EDGE; break;
594       case 2: aType = SMESH::FACE; break;
595       case 3: aType = SMESH::VOLUME; break;
596       }
597       SMESH::long_array_var anIdList = new SMESH::long_array;
598       int i, k = myElements->count();
599       anIdList->length(k);
600       QListBoxItem* anItem;
601       for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
602         anIdList[i] = anItem->text().toInt();
603       }
604
605       myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
606       myGroup->Add(anIdList.inout());
607
608       /* init for next operation */
609       myName->setText("");
610       myElements->clear();
611       myGroup = SMESH::SMESH_Group::_nil();
612
613     } else {
614       myGroup->SetName(myName->text());
615
616       QValueList<int> aAddList;
617       QValueList<int>::iterator anIt;
618       QListBoxItem* anItem;
619
620       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
621         int anId = anItem->text().toInt();
622         if ((anIt = myIdList.find(anId)) == myIdList.end())
623           aAddList.append(anId);
624         else
625           myIdList.remove(anIt);
626       }
627       if (!aAddList.empty()) {
628         SMESH::long_array_var anIdList = new SMESH::long_array;
629         anIdList->length(aAddList.count());
630         int i;
631         for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
632           anIdList[i] = *anIt;
633         myGroup->Add(anIdList.inout());
634       }
635       if (!myIdList.empty()) {
636         SMESH::long_array_var anIdList = new SMESH::long_array;
637         anIdList->length(myIdList.count());
638         int i;
639         for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
640           anIdList[i] = *anIt;
641         myGroup->Remove(anIdList.inout());
642       }
643       /* init for next operation */
644       myIdList.clear();
645       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
646         myIdList.append(anItem->text().toInt());
647     }
648
649     mySMESHGUI->updateObjBrowser(true);
650     SMESH::UpdateView(); // asv: fix of BUG PAL5515
651     mySelectionMgr->clearSelected();
652     return true;
653   } else if (myGrpTypeId == 1 &&
654              !myName->text().stripWhiteSpace().isEmpty() &&
655              !CORBA::is_nil(myGeomGroup))
656   {
657     SMESH::ElementType aType = SMESH::ALL;
658     switch (myTypeId) {
659     case 0: aType = SMESH::NODE; break;
660     case 1: aType = SMESH::EDGE; break;
661     case 2: aType = SMESH::FACE; break;
662     case 3: aType = SMESH::VOLUME; break;
663     }
664
665     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
666     GEOM::GEOM_IGroupOperations_var aGroupOp =
667       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
668
669     SMESH::SMESH_GroupOnGeom_var aGroupOnGeom =
670       myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomGroup);
671
672     mySMESHGUI->updateObjBrowser(true);
673     mySelectionMgr->clearSelected();
674     /* init for next operation */
675     myName->setText("");
676     return true;
677   }
678
679   return false;
680 }
681
682 //=================================================================================
683 // function : onOK()
684 // purpose  :
685 //=================================================================================
686 void SMESHGUI_GroupDlg::onOK()
687 {
688   if ( onApply() )
689     onClose();
690 }
691
692 //=================================================================================
693 // function : onListSelectionChanged()
694 // purpose  : Called when selection in element list is changed
695 //=================================================================================
696 void SMESHGUI_GroupDlg::onListSelectionChanged()
697 {
698   //  MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
699   if( myIsBusy || !myActor) return;
700     myIsBusy = true;
701
702   if (myCurrentLineEdit == 0) {
703     mySelectionMgr->clearSelected();
704     TColStd_MapOfInteger aIndexes;
705     QListBoxItem* anItem;
706     for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
707       if (anItem->isSelected()) {
708         int anId = anItem->text().toInt();
709         aIndexes.Add(anId);
710       }
711     }
712     mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
713     SALOME_ListIO aList;
714     aList.Append(myActor->getIO());
715     mySelectionMgr->setSelectedObjects(aList,false);
716     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
717       aViewWindow->highlight( myActor->getIO(), true, true );
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->FindObjectIOR(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: aType = SMESH::NODE; break;
1097   case 1: aType = SMESH::EDGE; break;
1098   case 2: aType = SMESH::FACE; break;
1099   case 3: aType = SMESH::VOLUME; break;
1100   }
1101
1102   if (myCurrentLineEdit == 0) {
1103     //if (aNbSel != 1) { myIsBusy = false; return; }
1104     QString aListStr = "";
1105     int aNbItems = 0;
1106     if (myTypeId == 0) {
1107       aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1108     }
1109     else {
1110       aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1111     }
1112     if (aNbItems > 0) {
1113       QStringList anElements = QStringList::split(" ", aListStr);
1114       QListBoxItem* anItem = 0;
1115       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1116         anItem = myElements->findItem(*it, Qt::ExactMatch);
1117         if (!anItem) {
1118           anItem = new QListBoxText(*it);
1119           myElements->insertItem(anItem);
1120         }
1121         myElements->setSelected(anItem, true);
1122       }
1123     }
1124   } else if (myCurrentLineEdit == mySubMeshLine) {
1125     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1126     
1127     SALOME_ListIO aList;
1128     mySelectionMgr->selectedObjects( aList );
1129
1130     SALOME_ListIteratorOfListIO anIt (aList);
1131     for (; anIt.More(); anIt.Next()) {
1132       SMESH::SMESH_subMesh_var aSubMesh =
1133         SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1134       if (!aSubMesh->_is_nil()) {
1135         // check if mesh is the same
1136         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1137           try {
1138             SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1139             int k = anElements->length();
1140             QListBoxItem* anItem = 0;
1141             for (int i = 0; i < k; i++) {
1142               QString aText = QString::number(anElements[i]);
1143               anItem = myElements->findItem(aText, Qt::ExactMatch);
1144               if (!anItem) {
1145                 anItem = new QListBoxText(aText);
1146                 myElements->insertItem(anItem);
1147               }
1148               myElements->setSelected(anItem, true);
1149             }
1150           }
1151           catch (const SALOME::SALOME_Exception& ex) {
1152             SalomeApp_Tools::QtCatchCorbaException(ex);
1153           }
1154         }
1155       }
1156     }
1157     mySelectSubMesh->setChecked(false);
1158     myIsBusy = false;
1159     onListSelectionChanged();
1160
1161   } else if (myCurrentLineEdit == myGroupLine) {
1162     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1163     SALOME_ListIO aList;
1164     mySelectionMgr->selectedObjects( aList );
1165     
1166     SALOME_ListIteratorOfListIO anIt (aList);
1167     for (; anIt.More(); anIt.Next()) {
1168       SMESH::SMESH_Group_var aGroup =
1169         SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1170       if (!aGroup->_is_nil()) {
1171         // check if mesh is the same
1172         if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1173           SMESH::long_array_var anElements = aGroup->GetListOfID();
1174           int k = anElements->length();
1175           QListBoxItem* anItem = 0;
1176           for (int i = 0; i < k; i++) {
1177             QString aText = QString::number(anElements[i]);
1178             anItem = myElements->findItem(aText, Qt::ExactMatch);
1179             if (!anItem) {
1180               anItem = new QListBoxText(aText);
1181               myElements->insertItem(anItem);
1182             }
1183             myElements->setSelected(anItem, true);
1184           }
1185         }
1186       }
1187     }
1188     mySelectGroup->setChecked(false);
1189     myIsBusy = false;
1190     onListSelectionChanged();
1191
1192   } else if (myCurrentLineEdit == myGeomGroupLine && !CORBA::is_nil(myGeomGroup)) {
1193     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1194     GEOM::GEOM_IGroupOperations_var aGroupOp =
1195       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1196
1197     SMESH::ElementType aGroupType = SMESH::ALL;
1198     switch(aGroupOp->GetType(myGeomGroup)) {
1199     case 7: aGroupType = SMESH::NODE; break;
1200     case 6: aGroupType = SMESH::EDGE; break;
1201     case 4: aGroupType = SMESH::FACE; break;
1202     case 2: aGroupType = SMESH::VOLUME; break;
1203     default: myIsBusy = false; return;
1204     }
1205
1206     if (aGroupType == aType) {
1207       _PTR(SObject) aGroupSO =
1208         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1209         aStudy->FindObjectIOR(myGeomGroup->GetStudyEntry());
1210       // Construct filter
1211       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1212       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1213       SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1214       aBelongToGeom->SetGeom(myGeomGroup);
1215       aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1216       aBelongToGeom->SetElementType(aType);
1217       aFilter->SetPredicate(aBelongToGeom);
1218
1219       SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1220
1221       int k = anElements->length();
1222       QListBoxItem* anItem = 0;
1223       for (int i = 0; i < k; i++) {
1224         QString aText = QString::number(anElements[i]);
1225         anItem = myElements->findItem(aText, Qt::ExactMatch);
1226         if (!anItem) {
1227           anItem = new QListBoxText(aText);
1228           myElements->insertItem(anItem);
1229         }
1230         myElements->setSelected(anItem, true);
1231       }
1232     }
1233
1234     //VSR: mySelectGeomGroup->setChecked(false);
1235     myIsBusy = false;
1236     onListSelectionChanged();
1237   }
1238   myIsBusy = false;
1239   //  mySelectionMgr->clearSelected();
1240   updateButtons();
1241 }
1242
1243 //=================================================================================
1244 // function : onRemove()
1245 // purpose  :
1246 //=================================================================================
1247 void SMESHGUI_GroupDlg::onRemove()
1248 {
1249   myIsBusy = true;
1250   if (myCurrentLineEdit == 0) {
1251     for (int i = myElements->count(); i > 0; i--) {
1252       if (myElements->isSelected(i-1)) {
1253         myElements->removeItem(i-1);
1254       }
1255     }
1256   } else {
1257     SALOME_ListIO aList;
1258     mySelectionMgr->selectedObjects( aList );
1259
1260     int aNbSel = aList.Extent();
1261
1262     if (aNbSel == 0) { myIsBusy = false; return; }
1263
1264     SMESH::ElementType aType = SMESH::ALL;
1265     switch(myTypeId) {
1266     case 0: aType = SMESH::NODE; break;
1267     case 1: aType = SMESH::EDGE; break;
1268     case 2: aType = SMESH::FACE; break;
1269     case 3: aType = SMESH::VOLUME; break;
1270     }
1271
1272     if (myCurrentLineEdit == mySubMeshLine) {
1273       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1274       SALOME_ListIO aList;
1275       mySelectionMgr->selectedObjects( aList );
1276
1277       SALOME_ListIteratorOfListIO anIt (aList);
1278       for (; anIt.More(); anIt.Next()) {
1279         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1280         if (!aSubMesh->_is_nil()) {
1281           // check if mesh is the same
1282           if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1283             if (aType == SMESH::NODE) {
1284               try {
1285                 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1286                 int k = anElements->length();
1287                 QListBoxItem* anItem = 0;
1288                 for (int i = 0; i < k; i++) {
1289                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1290                   if (anItem) delete anItem;
1291                 }
1292               }
1293               catch (const SALOME::SALOME_Exception& ex) {
1294                 SalomeApp_Tools::QtCatchCorbaException(ex);
1295               }
1296             }
1297             else {
1298               try {
1299                 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1300                 int k = anElements->length();
1301                 QListBoxItem* anItem = 0;
1302                 for (int i = 0; i < k; i++) {
1303                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1304                   if (anItem) delete anItem;
1305                 }
1306               }
1307               catch (const SALOME::SALOME_Exception& ex) {
1308                 SalomeApp_Tools::QtCatchCorbaException(ex);
1309               }
1310             }
1311           }
1312         }
1313       }
1314     }
1315     else if (myCurrentLineEdit == myGroupLine) {
1316       Standard_Boolean aRes;
1317       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1318       SALOME_ListIO aList;
1319       mySelectionMgr->selectedObjects( aList );
1320
1321       SALOME_ListIteratorOfListIO anIt (aList);
1322       for (; anIt.More(); anIt.Next()) {
1323         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1324         if (aRes && !aGroup->_is_nil()) {
1325           // check if mesh is the same
1326           if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1327             SMESH::long_array_var anElements = aGroup->GetListOfID();
1328             int k = anElements->length();
1329             QListBoxItem* anItem = 0;
1330             for (int i = 0; i < k; i++) {
1331               anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1332               if (anItem) delete anItem;
1333             }
1334           }
1335         }
1336       }
1337     }
1338   }
1339   myIsBusy = false;
1340   updateButtons();
1341 }
1342
1343 //=================================================================================
1344 // function : onSort()
1345 // purpose  :
1346 //=================================================================================
1347 void SMESHGUI_GroupDlg::onSort()
1348 {
1349   // PAL5412: sorts items in ascending by "string" value
1350   // myElements->sort(true);
1351   // myElements->update();
1352   int i, k = myElements->count();
1353   if (k > 0) {
1354     myIsBusy = true;
1355     QStringList aSelected;
1356     std::vector<int> anArray(k);
1357     //    QMemArray<int> anArray(k);
1358     QListBoxItem* anItem;
1359     // fill the array
1360     for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1361       anArray[i] = anItem->text().toInt();
1362       if (anItem->isSelected())
1363         aSelected.append(anItem->text());
1364     }
1365     // sort & update list
1366     std::sort(anArray.begin(), anArray.end());
1367     //    anArray.sort();
1368     myElements->clear();
1369     for (i = 0; i < k; i++) {
1370       myElements->insertItem(QString::number(anArray[i]));
1371     }
1372     for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1373       anItem = myElements->findItem(*it, Qt::ExactMatch);
1374       if (anItem) myElements->setSelected(anItem, true);
1375     }
1376     myIsBusy = false;
1377   }
1378 }
1379
1380 //=================================================================================
1381 // function : closeEvent()
1382 // purpose  :
1383 //=================================================================================
1384 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1385 {
1386   onClose();
1387 }
1388
1389 //=================================================================================
1390 // function : SMESHGUI_GroupDlg::onClose
1391 // purpose  : SLOT called when "Close" button pressed. Close dialog
1392 //=================================================================================
1393 void SMESHGUI_GroupDlg::onClose()
1394 {
1395   if (SMESH::GetCurrentVtkView()) {
1396     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1397     SMESH::SetPointRepresentation(false);
1398     SMESH::SetPickable();
1399   }
1400
1401   mySelectionMgr->clearSelected();
1402   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1403     aViewWindow->SetSelectionMode(ActorSelection);
1404   mySelectionMgr->clearFilters();
1405   mySMESHGUI->ResetState();
1406
1407   reject();
1408 }
1409
1410 //=================================================================================
1411 // function : SMESHGUI_GroupDlg::onDeactivate
1412 // purpose  : SLOT called when dialog must be deativated
1413 //=================================================================================
1414 void SMESHGUI_GroupDlg::onDeactivate()
1415 {
1416   mySMESHGUI->ResetState();
1417   setEnabled(false);
1418 }
1419
1420 //=================================================================================
1421 // function : SMESHGUI_GroupDlg::enterEvent
1422 // purpose  : Event filter
1423 //=================================================================================
1424 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1425 {
1426   if (!isEnabled()) {
1427     mySMESHGUI->EmitSignalDeactivateDialog();
1428     setEnabled(true);
1429     mySelectionMode = -1;
1430     setSelectionMode(myTypeId);
1431     //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1432     mySMESHGUI->SetActiveDialogBox(this);
1433     mySMESHGUI->SetState(800);
1434   }
1435 }
1436
1437 //=================================================================================
1438 // function : hideEvent
1439 // purpose  : caused by ESC key
1440 //=================================================================================
1441 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1442 {
1443   if (!isMinimized())
1444     onClose();
1445 }