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