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