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