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