Salome HOME
+ // find out side orientation, which is important if there are several wires...
[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.com
21 //
22 //
23 //
24 //  File   : SMESHGUI_GroupDlg.cxx
25 //  Author : Natalia KOPNOVA
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESHGUI_GroupDlg.h"
30 #include "SMESHGUI_FilterDlg.h"
31 #include "SMESHGUI_ShapeByMeshDlg.h"
32
33 #include "SMESHGUI.h"
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_VTKUtils.h"
36 #include "SMESHGUI_MeshUtils.h"
37 #include "SMESHGUI_GroupUtils.h"
38 #include "SMESHGUI_FilterUtils.h"
39 #include "SMESHGUI_GEOMGenUtils.h"
40
41 #include "SMESH_TypeFilter.hxx"
42 #include "SMESH_Actor.h"
43
44 #include "GEOMBase.h"
45 #include "GEOM_SelectionFilter.h"
46
47 #include "SUIT_Desktop.h"
48 #include "SUIT_ResourceMgr.h"
49 #include "SUIT_Session.h"
50 #include "SUIT_MessageBox.h"
51
52 #include "SalomeApp_Tools.h"
53 #include "SalomeApp_Application.h"
54 #include "SalomeApp_Study.h"
55 #include "LightApp_Application.h"
56 #include "SALOMEDSClient_Study.hxx"
57 #include "SALOME_ListIO.hxx"
58 #include "SALOME_ListIteratorOfListIO.hxx"
59
60 #include "SVTK_ViewWindow.h"
61 #include "SVTK_Selector.h"
62
63 #include "utilities.h"
64
65 // OCCT Includes
66 #include <TColStd_MapOfInteger.hxx>
67
68 // QT Includes
69 #include <qbuttongroup.h>
70 #include <qcursor.h>
71 #include <qgroupbox.h>
72 #include <qhbox.h>
73 #include <qlabel.h>
74 #include <qlineedit.h>
75 #include <qpushbutton.h>
76 #include <qtoolbutton.h>
77 #include <qradiobutton.h>
78 #include <qcheckbox.h>
79 #include <qlayout.h>
80 #include <qlistbox.h>
81 #include <qimage.h>
82 #include <qpixmap.h>
83 #include <qmemarray.h>
84 #include <qwidgetstack.h>
85
86 #include <QtxIntSpinBox.h>
87
88 // STL includes
89 #include <vector>
90 #include <algorithm>
91 #include <set>
92
93 using namespace std;
94
95 //=================================================================================
96 // function : SMESHGUI_GroupDlg()
97 // purpose  :
98 //=================================================================================
99 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
100                                       SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl)
101      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
102                 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
103      mySMESHGUI( theModule ),
104      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
105      mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
106      myIsBusy( false ),
107      myActor( 0 ),
108      myOldActorMode( -1 )
109 {
110   if (!name) setName("SMESHGUI_GroupDlg");
111   initDialog(true);
112   if (!theMesh->_is_nil())
113     init(theMesh);
114   else {
115     mySelectSubMesh->setEnabled(false);
116     mySelectGroup->setEnabled(false);
117     myGeomGroupBtn->setEnabled(false);
118     myGeomGroupLine->setEnabled(false);
119   }
120 }
121
122 //=================================================================================
123 // function : SMESHGUI_GroupDlg()
124 // purpose  :
125 //=================================================================================
126 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
127                                       SMESH::SMESH_GroupBase_ptr theGroup, bool modal, WFlags fl)
128      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
129                 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
130      mySMESHGUI( theModule ),
131      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
132      mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
133      myIsBusy( false )
134 {
135   if (!name) setName("SMESHGUI_GroupDlg");
136
137   initDialog(false);
138   if (!theGroup->_is_nil())
139     init(theGroup);
140   else {
141     mySelectSubMesh->setEnabled(false);
142     mySelectGroup->setEnabled(false);
143
144     myCurrentLineEdit = myMeshGroupLine;
145     setSelectionMode(5);
146   }
147 }
148
149 //=================================================================================
150 // function : SMESHGUI_GroupDlg()
151 // purpose  :
152 //=================================================================================
153 void SMESHGUI_GroupDlg::initDialog(bool create)
154 {
155   myFilterDlg = 0;
156   myCreate = create;
157   myCurrentLineEdit = 0;
158
159   myShapeByMeshOp = 0;
160   myGeomPopup = 0;
161   myGeomObjects = new GEOM::ListOfGO();
162   myGeomObjects->length(0);
163
164   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
165
166   if (create) {
167     setCaption(tr("SMESH_CREATE_GROUP_TITLE"));
168     myHelpFileName = "/files/creating_groups.htm";
169   }
170   else {
171     setCaption(tr("SMESH_EDIT_GROUP_TITLE"));
172     myHelpFileName = "/files/editing_groups.htm";
173   }
174
175   setSizeGripEnabled(TRUE);
176
177   QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
178
179   /***************************************************************/
180   QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
181   if (create)
182     meshGroupLab->setText(tr("SMESH_MESH"));
183   else
184     meshGroupLab->setText(tr("SMESH_GROUP"));
185   myMeshGroupBtn = new QPushButton(this, "mesh/group button");
186   myMeshGroupBtn->setPixmap(image0);
187   myMeshGroupLine = new QLineEdit(this, "mesh/group line");
188   myMeshGroupLine->setReadOnly(true);
189
190   /***************************************************************/
191   myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
192   myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
193   myTypeGroup->setExclusive(true);
194
195   QStringList types;
196   types.append(tr("MESH_NODE"));
197   types.append(tr("SMESH_EDGE"));
198   types.append(tr("SMESH_FACE"));
199   types.append(tr("SMESH_VOLUME"));
200   QRadioButton* rb;
201   for (int i = 0; i < types.count(); i++) {
202     rb = new QRadioButton(types[i], myTypeGroup);
203   }
204   myTypeGroup->setEnabled(create);
205   myTypeId = -1;
206
207   /***************************************************************/
208   QLabel* aName = new QLabel(this, "name label");
209   aName->setText(tr("SMESH_NAME"));
210   aName->setMinimumSize(50,0);
211   myName = new QLineEdit(this, "name");
212
213   /***************************************************************/
214   myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
215   myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
216   myGrpTypeGroup->setExclusive(true);
217   QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
218   QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"),   myGrpTypeGroup);
219   myGrpTypeGroup->setEnabled(create);
220   myGrpTypeId = -1;
221
222   /***************************************************************/
223   myWGStack = new QWidgetStack( this, "widget stack");
224   QWidget* wg1 = new QFrame( myWGStack, "first widget" );
225   QWidget* wg2 = new QFrame( myWGStack, "second widget" );
226
227   /***************************************************************/
228   QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
229   aContentBox->setTitle(tr("SMESH_CONTENT"));
230   QFrame* aContent = new QFrame(aContentBox, "content");
231   QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
232   aLayout->setSpacing(6);
233   aLayout->setAutoAdd(false);
234
235   QLabel* aLabel = new QLabel(aContent, "elements label");
236   aLabel->setText(tr("SMESH_ID_ELEMENTS"));
237   myElements = new QListBox(aContent, "elements list");
238   myElements->setSelectionMode(QListBox::Extended);
239
240   myFilter = new QPushButton(aContent, "filter");
241   myFilter->setText(tr("SMESH_BUT_FILTER"));
242   QPushButton* aAddBtn = new QPushButton(aContent, "add");
243   aAddBtn->setText(tr("SMESH_BUT_ADD"));
244   QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
245   aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
246   QPushButton* aSortBtn = new QPushButton(aContent, "sort");
247   aSortBtn->setText(tr("SMESH_BUT_SORT"));
248
249   aLayout->addWidget(aLabel, 0, 0);
250   aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
251   aLayout->addWidget(myFilter, 1, 2);
252   aLayout->addWidget(aAddBtn, 3, 2);
253   aLayout->addWidget(aRemoveBtn, 4, 2);
254   aLayout->addWidget(aSortBtn, 6, 2);
255
256   aLayout->setColStretch(0, 1);
257   aLayout->addColSpacing(1, 20);
258   aLayout->addColSpacing(3, 20);
259   aLayout->setRowStretch(2, 1);
260   aLayout->setRowStretch(5, 1);
261
262   /***************************************************************/
263   QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
264   aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
265
266   mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
267   mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
268   mySelectSubMesh->setMinimumSize(50, 0);
269   mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
270   mySubMeshBtn->setText("");
271   mySubMeshBtn->setPixmap(image0);
272   mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
273   mySubMeshLine->setReadOnly(true);
274   onSelectSubMesh(false);
275
276   mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
277   mySelectGroup->setText(tr("SMESH_GROUP"));
278   mySelectGroup->setMinimumSize(50, 0);
279   myGroupBtn = new QPushButton(aSelectBox, "group button");
280   myGroupBtn->setText("");
281   myGroupBtn->setPixmap(image0);
282   myGroupLine = new QLineEdit(aSelectBox, "group line");
283   myGroupLine->setReadOnly(true);
284   onSelectGroup(false);
285   
286   /***************************************************************/
287   QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
288   wg1Layout->addWidget(aContentBox, 0, 0);
289   wg1Layout->addWidget(aSelectBox, 1, 0);
290   wg1Layout->setRowStretch(2, 5);
291
292   /***************************************************************/
293   QLabel* geomObject = new QLabel(wg2, "geometry object label");
294   geomObject->setText(tr("SMESH_OBJECT_GEOM"));
295   myGeomGroupBtn = new QToolButton(wg2, "geometry group button");
296   myGeomGroupBtn->setIconSet( QIconSet(image0) );
297   myGeomGroupBtn->setToggleButton(true);
298   myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
299   myGeomGroupLine->setReadOnly(true); //VSR ???
300   onSelectGeomGroup(false);
301   
302   if (!create)
303     {
304       myGeomGroupBtn->setEnabled(false);
305       myGeomGroupLine->setEnabled(false);
306     }
307    
308   /***************************************************************/
309   QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
310   wg2Layout->addWidget(geomObject,     0, 0);
311   wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
312   wg2Layout->addWidget(myGeomGroupLine,0, 2);
313   wg2Layout->setRowStretch(1, 5);
314
315   /***************************************************************/
316   QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
317   dumb->addWidget(wg1);
318   dumb->addWidget(wg2);
319   myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
320   myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
321
322   /***************************************************************/
323   QGroupBox* aColorBox = new QGroupBox(2, Qt::Horizontal, this, "color box");
324   aColorBox->setTitle(tr("SMESH_SET_COLOR"));
325
326   mySelectColorGroup = new QCheckBox(aColorBox, "color checkbox");
327   mySelectColorGroup->setText(tr("SMESH_CHECK_COLOR"));
328   
329   myColorSpinBox = new QtxIntSpinBox( aColorBox );
330   myColorSpinBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
331   myColorSpinBox->setMinValue( 0 );
332   myColorSpinBox->setMaxValue( 9999 );
333   
334   onSelectColorGroup(false);
335   
336   /***************************************************************/
337   
338   QFrame* aButtons = new QFrame(this, "button box");
339   aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
340   QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
341   aBtnLayout->setAutoAdd(false);
342
343   QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
344   aOKBtn->setText(tr("SMESH_BUT_OK"));
345   aOKBtn->setAutoDefault(true);
346   aOKBtn->setDefault(true);
347   QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
348   aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
349   aApplyBtn->setAutoDefault(true);
350   QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
351   aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
352   aCloseBtn->setAutoDefault(true);
353   QPushButton* aHelpBtn = new QPushButton(aButtons, "help");
354   aHelpBtn->setText(tr("SMESH_BUT_HELP"));
355   aHelpBtn->setAutoDefault(true);
356
357   aBtnLayout->addWidget(aOKBtn);
358   aBtnLayout->addWidget(aApplyBtn);
359   aBtnLayout->addStretch();
360   aBtnLayout->addWidget(aCloseBtn);
361   aBtnLayout->addWidget(aHelpBtn);
362
363   /***************************************************************/
364   aMainLayout->addWidget(meshGroupLab,    0, 0);
365   aMainLayout->addWidget(myMeshGroupBtn,  0, 1);
366   aMainLayout->addWidget(myMeshGroupLine, 0, 2);
367   aMainLayout->addMultiCellWidget(myTypeGroup,    1, 1, 0, 2);
368   aMainLayout->addWidget(aName,      2, 0);
369   aMainLayout->addWidget(myName,     2, 2);
370   aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
371   aMainLayout->addMultiCellWidget(myWGStack,      4, 4, 0, 2);
372   aMainLayout->setRowStretch( 5, 5 );
373   aMainLayout->addMultiCellWidget(aColorBox,   6, 6, 0, 2);
374   aMainLayout->addMultiCellWidget(aButtons,       7, 7, 0, 2);
375
376   /* signals and slots connections */
377   connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
378
379   connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
380
381   connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
382
383   connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
384   connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
385
386   connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
387   connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
388   connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
389   connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
390
391   connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
392   connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
393   connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
394   connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
395   connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
396   connect(mySelectColorGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectColorGroup(bool)));
397   connect(myColorSpinBox, SIGNAL(valueChanged(const QString&)), this, SLOT(onNbColorsChanged(const QString&)));
398   
399   connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
400   connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
401   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
402   connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
403
404   /* Init selection */
405   mySMESHGUI->SetActiveDialogBox(this);
406   mySMESHGUI->SetState(800);
407
408   mySelectionMode = -1;
409   myMeshFilter = new SMESH_TypeFilter(MESH);
410   mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
411   myGroupFilter = new SMESH_TypeFilter(GROUP);
412   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
413   myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
414   
415   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
416   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
417   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
418
419   myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
420   onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
421
422   if (myMesh->_is_nil() )
423     myTypeGroup->setButton(0);
424
425   updateButtons();
426   //myName->setText(GetDefaultName(tr("SMESH_GROUP")));
427 }
428
429 //=================================================================================
430 // function : ~SMESHGUI_GroupDlg()
431 // purpose  : Destroys the object and frees any allocated resources
432 //=================================================================================
433 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
434 {
435   // no need to delete child widgets, Qt does it all for us
436   if ( myFilterDlg != 0 )
437   {
438     myFilterDlg->reparent( 0, QPoint() );
439     delete myFilterDlg;
440   }
441 }
442
443 //=================================================================================
444 // function : GetDefaultName()
445 // purpose  : Get the Group Name if Create new Group
446 //=================================================================================
447 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
448 {
449     QString aName = "";
450
451     // collect all object names of SMESH component
452     SalomeApp_Study* appStudy =
453       dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
454     if ( !appStudy ) return aName;
455     _PTR(Study) aStudy = appStudy->studyDS();
456
457     std::set<std::string> aSet;
458     _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
459     if (aMeshCompo) {
460       _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
461       _PTR(SObject) obj;
462       for (it->InitEx(true); it->More(); it->Next()) {
463         obj = it->Value();
464         aSet.insert(obj->GetName());
465       }
466     }
467
468     // build a unique name
469     int aNumber = 0;
470     bool isUnique = false;
471     while (!isUnique) {
472       aName = theOperation + "_" + QString::number(++aNumber);
473       isUnique = (aSet.count(aName.latin1()) == 0);
474     }
475
476     return aName;
477 }
478
479
480 //=================================================================================
481 // function : Init()
482 // purpose  :
483 //=================================================================================
484 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
485 {
486   mySelectionMgr->installFilter(myMeshFilter);
487
488   /* init data from current selection */
489   myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
490   myGroup = SMESH::SMESH_Group::_nil();
491   myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
492
493   myActor = SMESH::FindActorByObject(myMesh);
494   SMESH::SetPickable(myActor);
495   storeMode();
496
497   SALOME_ListIO aList;
498   mySelectionMgr->selectedObjects( aList );
499   if( !aList.IsEmpty() )
500   {
501     QString aName = aList.First()->getName();
502     myMeshGroupLine->setText(aName) ;
503     myMeshGroupLine->home( false );
504   }
505
506   myCurrentLineEdit = 0;
507
508   myTypeGroup->setButton(0);
509   onTypeChanged(0);
510 }
511
512 //=================================================================================
513 // function : Init()
514 // purpose  :
515 //=================================================================================
516 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
517 {
518   myMesh = theGroup->GetMesh();
519   
520   myName->setText(theGroup->GetName());
521   myName->home(false);
522   myOldName = myName->text();
523
524   myColorSpinBox->setValue( theGroup->GetColorNumber() );
525   
526   myMeshGroupLine->setText(theGroup->GetName());
527
528   int aType = 0;
529   switch(theGroup->GetType()) {
530   case SMESH::NODE: aType= 0; break;
531   case SMESH::EDGE: aType = 1; break;
532   case SMESH::FACE: aType = 2; break;
533   case SMESH::VOLUME: aType = 3; break;
534   }
535   myTypeGroup->setButton(aType);
536   
537   myGroup = SMESH::SMESH_Group::_narrow( theGroup );
538
539   if ( !myGroup->_is_nil() )
540     {
541       myActor = SMESH::FindActorByObject(myMesh);
542       if ( !myActor )
543         myActor = SMESH::FindActorByObject(myGroup);
544       SMESH::SetPickable(myActor);
545       storeMode();
546       
547       myGrpTypeGroup->setButton(0);
548       onGrpTypeChanged(0);
549       
550       myCurrentLineEdit = 0;
551       myElements->clear();
552       setSelectionMode(aType);
553       myTypeId = aType;
554       
555       myIdList.clear();
556       if (!myGroup->IsEmpty()) {
557         SMESH::long_array_var anElements = myGroup->GetListOfID();
558         int k = anElements->length();
559         for (int i = 0; i < k; i++) {
560           myIdList.append(anElements[i]);
561           myElements->insertItem(QString::number(anElements[i]));
562         }
563         myElements->selectAll(true);
564       }
565     }
566   else
567     {
568       myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
569       
570       if ( !myGroupOnGeom->_is_nil() )
571         {
572           myActor = SMESH::FindActorByObject(myMesh);
573           if ( !myActor )
574             myActor = SMESH::FindActorByObject(myGroup);
575           SMESH::SetPickable(myActor);
576           storeMode();
577
578           myGrpTypeGroup->setButton(1);
579           onGrpTypeChanged(1);
580           
581           QString aShapeName("");
582           _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
583           GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
584           if (!aGroupShape->_is_nil())
585             {
586               _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
587               aShapeName = aGroupShapeSO->GetName().c_str();
588             }
589           myGeomGroupLine->setText( aShapeName );
590           myName->setText("Group On " + aShapeName);
591           cout << aShapeName << endl;
592         }
593     }
594 }
595
596 //=================================================================================
597 // function : updateButtons()
598 // purpose  :
599 //=================================================================================
600 void SMESHGUI_GroupDlg::updateButtons()
601 {
602   bool enable = !myName->text().stripWhiteSpace().isEmpty();
603
604   if (myGrpTypeId == 0) {
605     enable = enable && myElements->count() > 0;
606     enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
607   }
608   else if (myGrpTypeId == 1) {
609     if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
610       enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
611     }
612   }
613
614   QPushButton* aBtn;
615   aBtn = (QPushButton*) child("ok", "QPushButton");
616   if (aBtn) aBtn->setEnabled(enable);
617   aBtn = (QPushButton*) child("apply", "QPushButton");
618   if (aBtn) aBtn->setEnabled(enable);
619 }
620
621 //=================================================================================
622 // function : onNameChanged()
623 // purpose  :
624 //=================================================================================
625 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
626 {
627   updateButtons();
628 }
629
630 //=================================================================================
631 // function : onNbColorsChanged()
632 // purpose  :
633 //=================================================================================
634 void SMESHGUI_GroupDlg::onNbColorsChanged (const QString& text)
635 {
636   updateButtons();
637 }
638
639 //=================================================================================
640 // function : onTypeChanged()
641 // purpose  : Group elements type radio button management
642 //=================================================================================
643 void SMESHGUI_GroupDlg::onTypeChanged (int id)
644 {
645   if (myTypeId != id)
646   {
647     myElements->clear();
648     unsigned int aMode = -1;
649     switch( id )
650     {
651     case 0://node
652       aMode = SMESH_Actor::eAllEntity;
653       break;
654     case 1://edge
655       aMode = SMESH_Actor::eEdges;
656       break;
657     case 2://face
658       aMode = SMESH_Actor::eFaces;
659       break;
660     case 3://volume
661       aMode = SMESH_Actor::eVolumes;
662       break;
663     }
664     if( myActor && aMode>=0 )
665       myActor->SetEntityMode( aMode );
666     if (myCurrentLineEdit == 0)
667       setSelectionMode(id);
668   }
669   myTypeId = id;
670 }
671
672 //=================================================================================
673 // function : onGrpTypeChanged()
674 // purpose  : Group type radio button management
675 //=================================================================================
676 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
677 {
678   if (myGrpTypeId != id) {
679     myWGStack->raiseWidget( id );
680     if (id == 0)
681       myName->setText(myOldName);
682     onSelectGeomGroup(id == 1);
683   }
684   myGrpTypeId = id;
685 }
686
687 //=================================================================================
688 // function : setSelectionMode()
689 // purpose  : Radio button management
690 //=================================================================================
691 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
692 {
693   // PAL7314
694   if (myMesh->_is_nil())
695     return;
696   if (mySelectionMode != theMode) {
697     // [PAL10408] mySelectionMgr->clearSelected();
698     mySelectionMgr->clearFilters();
699     if (myActor)
700       myActor->SetPointRepresentation(false);
701     else
702       SMESH::SetPointRepresentation(false);
703     if (theMode < 4) {
704       switch (theMode) {
705       case 0:
706         if (myActor)
707           myActor->SetPointRepresentation(true);
708         else
709           SMESH::SetPointRepresentation(true);
710         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
711           aViewWindow->SetSelectionMode(NodeSelection);
712         break;
713       case 1:
714         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
715           aViewWindow->SetSelectionMode(EdgeSelection);
716         break;
717       case 2:
718         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
719           aViewWindow->SetSelectionMode(FaceSelection);
720         break;
721       default:
722         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
723           aViewWindow->SetSelectionMode(VolumeSelection);
724       }
725     } else {
726       if (theMode == 4)
727         mySelectionMgr->installFilter(mySubMeshFilter);
728       else if (theMode == 5)
729         mySelectionMgr->installFilter(myGroupFilter);
730       else if (theMode == 6)
731         mySelectionMgr->installFilter(myMeshFilter);
732       else if (theMode == 7)
733         mySelectionMgr->installFilter(myGeomFilter);
734       
735       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
736         aViewWindow->SetSelectionMode(ActorSelection);
737     }
738     mySelectionMode = theMode;
739   } 
740 }
741
742 //=================================================================================
743 // function : onApply()
744 // purpose  :
745 //=================================================================================
746 bool SMESHGUI_GroupDlg::onApply()
747 {
748   if (mySMESHGUI->isActiveStudyLocked())
749     return false;
750
751   if (myName->text().stripWhiteSpace().isEmpty())
752     return false;
753
754   if (myGrpTypeId == 0) { // on mesh elements
755     if (!myElements->count())
756       return false;
757
758     mySelectionMgr->clearSelected();
759
760     if (myGroup->_is_nil()) { // creation
761       if (myMesh->_is_nil())
762         return false;
763
764       SMESH::ElementType aType = SMESH::ALL;
765       switch (myTypeId) {
766       case 0: aType = SMESH::NODE; break;
767       case 1: aType = SMESH::EDGE; break;
768       case 2: aType = SMESH::FACE; break;
769       case 3: aType = SMESH::VOLUME; break;
770       }
771
772       SMESH::long_array_var anIdList = new SMESH::long_array;
773       int i, k = myElements->count();
774       anIdList->length(k);
775       QListBoxItem* anItem;
776       for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
777         anIdList[i] = anItem->text().toInt();
778       }
779
780       myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
781       myGroup->Add(anIdList.inout());
782
783       int aColorNumber = myColorSpinBox->value();
784       myGroup->SetColorNumber(aColorNumber);
785
786       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
787
788       SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
789       SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
790
791       /* init for next operation */
792       myName->setText("");
793       myColorSpinBox->setValue(0);
794       myElements->clear();
795       myGroup = SMESH::SMESH_Group::_nil();
796
797     } else { // edition
798       myGroup->SetName(myName->text());
799         
800       int aColorNumber = myColorSpinBox->value();
801       myGroup->SetColorNumber(aColorNumber);
802
803       QValueList<int> aAddList;
804       QValueList<int>::iterator anIt;
805       QListBoxItem* anItem;
806
807       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
808         int anId = anItem->text().toInt();
809         if ((anIt = myIdList.find(anId)) == myIdList.end())
810           aAddList.append(anId);
811         else
812           myIdList.remove(anIt);
813       }
814       if (!aAddList.empty()) {
815         SMESH::long_array_var anIdList = new SMESH::long_array;
816         anIdList->length(aAddList.count());
817         int i;
818         for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
819           anIdList[i] = *anIt;
820         myGroup->Add(anIdList.inout());
821       }
822       if (!myIdList.empty()) {
823         SMESH::long_array_var anIdList = new SMESH::long_array;
824         anIdList->length(myIdList.count());
825         int i;
826         for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
827           anIdList[i] = *anIt;
828         myGroup->Remove(anIdList.inout());
829       }
830       /* init for next operation */
831       myIdList.clear();
832       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
833         myIdList.append(anItem->text().toInt());
834     }
835
836     mySMESHGUI->updateObjBrowser(true);
837     SMESH::UpdateView(); // asv: fix of BUG PAL5515
838     mySelectionMgr->clearSelected();
839     return true;
840   }
841   else if (myGrpTypeId == 1) { // on geom object
842     if (CORBA::is_nil(myGroupOnGeom)) { // creation
843       if (myMesh->_is_nil() || !myGeomObjects->length())
844         return false;
845
846       SMESH::ElementType aType = SMESH::ALL;
847       switch (myTypeId) {
848       case 0: aType = SMESH::NODE; break;
849       case 1: aType = SMESH::EDGE; break;
850       case 2: aType = SMESH::FACE; break;
851       case 3: aType = SMESH::VOLUME; break;
852       }
853
854       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
855       GEOM::GEOM_IGroupOperations_var aGroupOp =
856         SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
857
858       if (myGeomObjects->length() == 1) {
859         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
860       }
861       else {
862         SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
863         if ( aSMESHGen->_is_nil() )
864           return false;
865
866         // create a geometry group
867         GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
868         _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
869
870         if (geomGen->_is_nil() || !aStudy)
871           return false;
872
873         GEOM::GEOM_IGroupOperations_var op =
874           geomGen->GetIGroupOperations(aStudy->StudyId());
875         if (op->_is_nil())
876           return false;
877
878         // check and add all selected GEOM objects: they must be
879         // a sub-shapes of the main GEOM and must be of one type
880         TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
881         for ( int i =0; i < myGeomObjects->length(); i++) {
882           TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
883           if (i == 0)
884             aGroupType = aSubShapeType;
885           else if (aSubShapeType != aGroupType) {
886             aGroupType = TopAbs_SHAPE;
887             break;
888           }
889         }
890
891         GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
892         GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
893         op->UnionList(aGroupVar, myGeomObjects);
894
895         if (op->IsDone()) {
896           // publish the GEOM group in study
897           QString aNewGeomGroupName ("Auto_group_for_");
898           aNewGeomGroupName += myName->text();
899           SALOMEDS::SObject_var aNewGroupSO =
900             geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
901         }
902
903         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
904       }
905
906       int aColorNumber = myColorSpinBox->value();
907       myGroupOnGeom->SetColorNumber(aColorNumber);
908
909       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
910
911       SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
912
913       SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
914
915       /* init for next operation */
916       myName->setText("");
917       myColorSpinBox->setValue(0);
918       myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
919     }
920     else { // edition
921       myGroupOnGeom->SetName(myName->text());
922
923       int aColorNumber = myColorSpinBox->value();
924       myGroupOnGeom->SetColorNumber(aColorNumber);
925     }
926
927     mySMESHGUI->updateObjBrowser(true);
928     mySelectionMgr->clearSelected();
929     return true;
930   }
931
932   return false;
933 }
934
935 //=================================================================================
936 // function : onOK()
937 // purpose  :
938 //=================================================================================
939 void SMESHGUI_GroupDlg::onOK()
940 {
941   if ( onApply() )
942     onClose();
943 }
944
945 //=================================================================================
946 // function : onListSelectionChanged()
947 // purpose  : Called when selection in element list is changed
948 //=================================================================================
949 void SMESHGUI_GroupDlg::onListSelectionChanged()
950 {
951   //  MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
952   if( myIsBusy || !myActor) return;
953     myIsBusy = true;
954
955   if (myCurrentLineEdit == 0) {
956     mySelectionMgr->clearSelected();
957     TColStd_MapOfInteger aIndexes;
958     QListBoxItem* anItem;
959     for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
960       if (anItem->isSelected()) {
961         int anId = anItem->text().toInt();
962         aIndexes.Add(anId);
963       }
964     }
965     mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
966     SALOME_ListIO aList;
967     aList.Append(myActor->getIO());
968     mySelectionMgr->setSelectedObjects(aList,false);
969   }
970   myIsBusy = false;
971 }
972
973 //=================================================================================
974 // function : onObjectSelectionChanged()
975 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
976 //=================================================================================
977 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
978 {
979   if ( myIsBusy || !isEnabled()) return;
980   if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
981
982   myIsBusy = true;
983
984   SALOME_ListIO aList;
985   mySelectionMgr->selectedObjects( aList );
986   
987   int aNbSel = aList.Extent();
988   myElements->clearSelection();
989
990   if (myCurrentLineEdit) {
991     myCurrentLineEdit->setText("");
992     QString aString = "";
993
994     if (myCurrentLineEdit == myMeshGroupLine) {
995       mySelectSubMesh->setEnabled(false);
996       mySelectGroup->setEnabled(false);
997       myGroupLine->setText("");
998       mySubMeshLine->setText("");
999
1000       myGeomGroupBtn->setEnabled(false);
1001       myGeomGroupLine->setEnabled(false);
1002       myGeomGroupLine->setText("");
1003       myGeomObjects = new GEOM::ListOfGO();
1004       myGeomObjects->length(0);
1005
1006       if (myGeomGroupBtn->isOn())
1007         myGeomGroupBtn->setOn(false);
1008       if (!myCreate)
1009         myName->setText("");
1010
1011       myElements->clear();
1012
1013       if (aNbSel != 1 ) {
1014         myGroup = SMESH::SMESH_Group::_nil();
1015         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); 
1016         myMesh = SMESH::SMESH_Mesh::_nil();
1017         updateGeomPopup();
1018         updateButtons();
1019         myIsBusy = false;
1020         return;
1021       }
1022       Handle(SALOME_InteractiveObject) IO = aList.First();
1023
1024       if (myCreate) {
1025         myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1026         updateGeomPopup();
1027         if (myMesh->_is_nil())
1028         {
1029           updateButtons();
1030           myIsBusy = false;
1031           return;
1032         }
1033         myGroup = SMESH::SMESH_Group::_nil();
1034
1035         myActor = SMESH::FindActorByObject(myMesh);
1036         SMESH::SetPickable(myActor);
1037         storeMode();
1038
1039         aString = aList.First()->getName();
1040         myMeshGroupLine->setText(aString) ;
1041         myMeshGroupLine->home( false );
1042
1043         mySelectSubMesh->setEnabled(true);
1044         mySelectGroup->setEnabled(true);
1045         myGeomGroupBtn->setEnabled(true);
1046         myGeomGroupLine->setEnabled(true);
1047         updateButtons();
1048       } else {
1049         SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1050         if (aGroup->_is_nil())
1051         {
1052           myIsBusy = false;
1053           return;
1054         }
1055         myIsBusy = false;
1056         myCurrentLineEdit = 0;
1057
1058         myGroup = SMESH::SMESH_Group::_nil();
1059         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1060         
1061         init(aGroup);
1062         myIsBusy = true;
1063         mySelectSubMesh->setEnabled(true);
1064         mySelectGroup->setEnabled(true);
1065       }
1066       myCurrentLineEdit = 0;
1067       myIsBusy = false;
1068       if (!myCreate)
1069         return;
1070
1071       if (myGrpTypeId == 0)
1072         {
1073           if (myTypeId == -1)
1074             onTypeChanged(0);
1075           else
1076             {
1077               myElements->clear();
1078               setSelectionMode(myTypeId);
1079             }
1080         }
1081
1082       myIsBusy = false;
1083       return;
1084
1085     } else if (myCurrentLineEdit == myGeomGroupLine) {
1086
1087       myGeomObjects = new GEOM::ListOfGO();
1088
1089       // The mesh SObject
1090       _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1091
1092       if (aNbSel == 0 || !aMeshSO)
1093         {
1094           myGeomObjects->length(0);
1095           updateButtons();
1096           myIsBusy = false;
1097           return;
1098         }
1099
1100       myGeomObjects->length(aNbSel);
1101
1102       GEOM::GEOM_Object_var aGeomGroup;
1103       Standard_Boolean testResult;
1104       int i = 0;
1105       
1106       SALOME_ListIteratorOfListIO anIt (aList);
1107       for (; anIt.More(); anIt.Next()) {
1108         
1109         testResult = Standard_False;
1110         aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1111
1112         // Check if the object is a geometry group
1113         if (!testResult || CORBA::is_nil(aGeomGroup))
1114           continue;
1115         
1116
1117         // Check if group constructed on the same shape as a mesh or on its child
1118         _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1119         GEOM::GEOM_IGroupOperations_var anOp =
1120           SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1121
1122         // The main shape of the group
1123         GEOM::GEOM_Object_var aGroupMainShape;
1124         if (aGeomGroup->GetType() == 37)
1125           aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1126         else
1127           aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1128         _PTR(SObject) aGroupMainShapeSO =
1129           //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1130           aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1131         
1132         _PTR(SObject) anObj, aRef;
1133         bool isRefOrSubShape = false;
1134         if (aMeshSO->FindSubObject(1, anObj) &&  anObj->ReferencedObject(aRef)) {
1135           //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1136           if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1137             isRefOrSubShape = true;
1138           } else {
1139             _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1140             _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1141             //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1142             while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1143               //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1144               if (aRef->GetID() == aFather->GetID())
1145                 isRefOrSubShape = true;
1146               else
1147                 aFather = aFather->GetFather();
1148             }
1149           }
1150         }
1151         if (isRefOrSubShape)
1152           myGeomObjects[i++] = aGeomGroup;
1153       }
1154       
1155       myGeomObjects->length(i);
1156       if ( i == 0 )
1157         {
1158           myIsBusy = false;
1159           return;
1160         }
1161       
1162       aNbSel = i;
1163     }
1164
1165     if(aNbSel >= 1) {
1166       if(aNbSel > 1) {
1167         if(myCurrentLineEdit == mySubMeshLine)
1168           aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1169         else if(myCurrentLineEdit == myGroupLine)
1170           aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1171         else if(myCurrentLineEdit == myGeomGroupLine)
1172           aString = tr("%1 Objects").arg(aNbSel);
1173       } else {
1174         aString = aList.First()->getName();
1175       }
1176     }
1177
1178     myCurrentLineEdit->setText(aString);
1179     myOldName = myName->text();
1180     myName->setText(aString);
1181     myCurrentLineEdit->home(false);
1182
1183     updateButtons();
1184
1185   } else {
1186     if (aNbSel == 1 && myActor ) {
1187       QString aListStr = "";
1188       int aNbItems = 0;
1189       if (myTypeId == 0) {
1190         aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1191       } else {
1192         aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1193       }
1194       if (aNbItems > 0) {
1195         QStringList anElements = QStringList::split(" ", aListStr);
1196         QListBoxItem* anItem = 0;
1197         for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1198           anItem = myElements->findItem(*it, Qt::ExactMatch);
1199           if (anItem) myElements->setSelected(anItem, true);
1200         }
1201       }
1202     }
1203   }
1204
1205   if (!myActor) {
1206     if (!myGroup->_is_nil())
1207       myActor = SMESH::FindActorByObject(myGroup);
1208     else if(!myGroupOnGeom->_is_nil())
1209       myActor = SMESH::FindActorByObject(myGroupOnGeom);
1210     else
1211       myActor = SMESH::FindActorByObject(myMesh);
1212     storeMode();
1213   }
1214
1215   myIsBusy = false;
1216 }
1217
1218 //=================================================================================
1219 // function : onSelectSubMesh()
1220 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1221 //=================================================================================
1222 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1223 {
1224   if (on) {
1225     if (mySelectGroup->isChecked()) {
1226       mySelectGroup->setChecked(false);
1227     }
1228     //VSR: else if (mySelectGeomGroup->isChecked()) {
1229     //VSR:   mySelectGeomGroup->setChecked(false);
1230     //VSR: }
1231     myCurrentLineEdit = mySubMeshLine;
1232     setSelectionMode(4);
1233   }
1234   else {
1235     mySubMeshLine->setText("");
1236     myCurrentLineEdit = 0;
1237     if (myTypeId != -1)
1238       setSelectionMode(myTypeId);
1239   }
1240   mySubMeshBtn->setEnabled(on);
1241   mySubMeshLine->setEnabled(on);
1242 }
1243
1244
1245 //=================================================================================
1246 // function : (onSelectGroup)
1247 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1248 //=================================================================================
1249 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1250 {
1251   if (on) {
1252     if (mySelectSubMesh->isChecked()) {
1253       mySelectSubMesh->setChecked(false);
1254     }
1255     myCurrentLineEdit = myGroupLine;
1256     setSelectionMode(5);
1257   }
1258   else {
1259     myGroupLine->setText("");
1260     myCurrentLineEdit = 0;
1261     if (myTypeId != -1)
1262       setSelectionMode(myTypeId);
1263   }
1264   myGroupBtn->setEnabled(on);
1265   myGroupLine->setEnabled(on);
1266 }
1267
1268
1269 //=================================================================================
1270 // function : (onSelectGeomGroup)
1271 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1272 //=================================================================================
1273 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1274 {
1275   if (on) {
1276     if (mySelectSubMesh->isChecked()) {
1277       mySelectSubMesh->setChecked(false);
1278     }
1279     else if (mySelectGroup->isChecked()) {
1280       mySelectGroup->setChecked(false);
1281     }
1282     myCurrentLineEdit = myGeomGroupLine;
1283     updateGeomPopup();
1284     setSelectionMode(8);
1285   }
1286   else {
1287     myGeomGroupBtn->setOn(false);
1288     myGeomObjects->length(0);
1289     myGeomGroupLine->setText("");
1290     myCurrentLineEdit = 0;
1291     if (myTypeId != -1)
1292       setSelectionMode(myTypeId);
1293   }
1294 }
1295
1296 //=================================================================================
1297 // function : (onSelectColorGroup)
1298 // purpose  : Called when setting a color on group
1299 //=================================================================================
1300 void SMESHGUI_GroupDlg::onSelectColorGroup(bool on)
1301 {
1302   if (!on)
1303     myColorSpinBox->setValue(0);
1304   
1305   myColorSpinBox->setEnabled(on);
1306 }
1307
1308 //=================================================================================
1309 // function : setCurrentSelection()
1310 // purpose  :
1311 //=================================================================================
1312 void SMESHGUI_GroupDlg::setCurrentSelection()
1313 {
1314   QPushButton* send = (QPushButton*)sender();
1315   myCurrentLineEdit = 0;
1316   if (send == myMeshGroupBtn) {
1317     myCurrentLineEdit = myMeshGroupLine;
1318     if (myCreate)
1319       setSelectionMode(6);
1320     else
1321       setSelectionMode(5);
1322     onObjectSelectionChanged();
1323   }
1324   else if (send == mySubMeshBtn) {
1325     myCurrentLineEdit = mySubMeshLine;
1326     onObjectSelectionChanged();
1327   }
1328   else if (send == myGroupBtn) {
1329     myCurrentLineEdit = myGroupLine;
1330     onObjectSelectionChanged();
1331   }
1332 }
1333
1334
1335 //=================================================================================
1336 // function : setFilters()
1337 // purpose  : SLOT. Called when "Filter" button pressed.
1338 //=================================================================================
1339 void SMESHGUI_GroupDlg::setFilters()
1340 {
1341   SMESH::ElementType aType = SMESH::ALL;
1342   switch ( myTypeId )
1343   {
1344     case 0 : aType = SMESH::NODE; break;
1345     case 1 : aType = SMESH::EDGE; break;
1346     case 2 : aType = SMESH::FACE; break;
1347     case 3 : aType = SMESH::VOLUME; break;
1348     default: return;
1349   }
1350
1351   if ( myFilterDlg == 0 )
1352   {
1353     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1354     connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1355   }
1356   else
1357     myFilterDlg->Init( aType );
1358
1359   myFilterDlg->SetSelection();
1360   myFilterDlg->SetMesh( myMesh );
1361   myFilterDlg->SetSourceWg( myElements );
1362
1363   myFilterDlg->show();
1364 }
1365
1366 //=================================================================================
1367 // function : onFilterAccepted()
1368 // purpose  : SLOT. Called when Filter dlg closed with OK button.
1369 //            Uncheck "Select submesh" and "Select group" checkboxes
1370 //=================================================================================
1371 void SMESHGUI_GroupDlg::onFilterAccepted()
1372 {
1373   if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1374   {
1375     mySelectionMode = myTypeId;
1376     mySelectSubMesh->setChecked( false );
1377     mySelectGroup->setChecked( false );
1378   }
1379 }
1380
1381 //=================================================================================
1382 // function : onAdd()
1383 // purpose  :
1384 //=================================================================================
1385 void SMESHGUI_GroupDlg::onAdd()
1386 {
1387   SALOME_ListIO aList;
1388   mySelectionMgr->selectedObjects( aList );
1389
1390   int aNbSel = aList.Extent();
1391
1392   if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1393
1394   myIsBusy = true;
1395
1396   SMESH::ElementType aType = SMESH::ALL;
1397   switch(myTypeId) {
1398   case 0: 
1399     aType = SMESH::NODE; 
1400     mySelector->SetSelectionMode(NodeSelection);
1401     break;
1402   case 1: 
1403     aType = SMESH::EDGE; 
1404     mySelector->SetSelectionMode(EdgeSelection);
1405     break;
1406   case 2: 
1407     aType = SMESH::FACE; 
1408     mySelector->SetSelectionMode(FaceSelection);
1409     break;
1410   case 3: 
1411     aType = SMESH::VOLUME; 
1412     mySelector->SetSelectionMode(VolumeSelection);
1413     break;
1414   default:
1415     mySelector->SetSelectionMode(ActorSelection);
1416   }
1417
1418
1419   if (myCurrentLineEdit == 0) {
1420     //if (aNbSel != 1) { myIsBusy = false; return; }
1421     QString aListStr = "";
1422     int aNbItems = 0;
1423     if (myTypeId == 0) {
1424       aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1425     }
1426     else {
1427       aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1428     }
1429     if (aNbItems > 0) {
1430       QStringList anElements = QStringList::split(" ", aListStr);
1431       QListBoxItem* anItem = 0;
1432       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1433         anItem = myElements->findItem(*it, Qt::ExactMatch);
1434         if (!anItem) {
1435           anItem = new QListBoxText(*it);
1436           myElements->insertItem(anItem);
1437         }
1438         myElements->setSelected(anItem, true);
1439       }
1440     }
1441   } else if (myCurrentLineEdit == mySubMeshLine) {
1442     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1443     
1444     SALOME_ListIO aList;
1445     mySelectionMgr->selectedObjects( aList );
1446
1447     SALOME_ListIteratorOfListIO anIt (aList);
1448     for (; anIt.More(); anIt.Next()) {
1449       SMESH::SMESH_subMesh_var aSubMesh =
1450         SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1451       if (!aSubMesh->_is_nil()) {
1452         // check if mesh is the same
1453         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1454           try {
1455             SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1456             int k = anElements->length();
1457             QListBoxItem* anItem = 0;
1458             for (int i = 0; i < k; i++) {
1459               QString aText = QString::number(anElements[i]);
1460               anItem = myElements->findItem(aText, Qt::ExactMatch);
1461               if (!anItem) {
1462                 anItem = new QListBoxText(aText);
1463                 myElements->insertItem(anItem);
1464               }
1465               myElements->setSelected(anItem, true);
1466             }
1467           }
1468           catch (const SALOME::SALOME_Exception& ex) {
1469             SalomeApp_Tools::QtCatchCorbaException(ex);
1470           }
1471         }
1472       }
1473     }
1474     mySelectSubMesh->setChecked(false);
1475     myIsBusy = false;
1476     onListSelectionChanged();
1477
1478   } else if (myCurrentLineEdit == myGroupLine) {
1479     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1480     SALOME_ListIO aList;
1481     mySelectionMgr->selectedObjects( aList );
1482     
1483     SALOME_ListIteratorOfListIO anIt (aList);
1484     for (; anIt.More(); anIt.Next()) {
1485       SMESH::SMESH_Group_var aGroup =
1486         SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1487       if (!aGroup->_is_nil()) {
1488         // check if mesh is the same
1489         if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1490           SMESH::long_array_var anElements = aGroup->GetListOfID();
1491           int k = anElements->length();
1492           QListBoxItem* anItem = 0;
1493           for (int i = 0; i < k; i++) {
1494             QString aText = QString::number(anElements[i]);
1495             anItem = myElements->findItem(aText, Qt::ExactMatch);
1496             if (!anItem) {
1497               anItem = new QListBoxText(aText);
1498               myElements->insertItem(anItem);
1499             }
1500             myElements->setSelected(anItem, true);
1501           }
1502         }
1503       }
1504     }
1505     mySelectGroup->setChecked(false);
1506     myIsBusy = false;
1507     onListSelectionChanged();
1508
1509   } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1510     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1511     GEOM::GEOM_IGroupOperations_var aGroupOp =
1512       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1513
1514     SMESH::ElementType aGroupType = SMESH::ALL;
1515     switch(aGroupOp->GetType(myGeomObjects[0])) {
1516     case 7: aGroupType = SMESH::NODE; break;
1517     case 6: aGroupType = SMESH::EDGE; break;
1518     case 4: aGroupType = SMESH::FACE; break;
1519     case 2: aGroupType = SMESH::VOLUME; break;
1520     default: myIsBusy = false; return;
1521     }
1522
1523     if (aGroupType == aType) {
1524       _PTR(SObject) aGroupSO =
1525         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1526         aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1527       // Construct filter
1528       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1529       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1530       SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1531       aBelongToGeom->SetGeom(myGeomObjects[0]);
1532       aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1533       aBelongToGeom->SetElementType(aType);
1534       aFilter->SetPredicate(aBelongToGeom);
1535
1536       SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1537
1538       int k = anElements->length();
1539       QListBoxItem* anItem = 0;
1540       for (int i = 0; i < k; i++) {
1541         QString aText = QString::number(anElements[i]);
1542         anItem = myElements->findItem(aText, Qt::ExactMatch);
1543         if (!anItem) {
1544           anItem = new QListBoxText(aText);
1545           myElements->insertItem(anItem);
1546         }
1547         myElements->setSelected(anItem, true);
1548       }
1549     }
1550
1551     //VSR: mySelectGeomGroup->setChecked(false);
1552     myIsBusy = false;
1553     onListSelectionChanged();
1554   }
1555   myIsBusy = false;
1556   //  mySelectionMgr->clearSelected();
1557   updateButtons();
1558 }
1559
1560 //=================================================================================
1561 // function : onRemove()
1562 // purpose  :
1563 //=================================================================================
1564 void SMESHGUI_GroupDlg::onRemove()
1565 {
1566   myIsBusy = true;
1567   if (myCurrentLineEdit == 0) {
1568     for (int i = myElements->count(); i > 0; i--) {
1569       if (myElements->isSelected(i-1)) {
1570         myElements->removeItem(i-1);
1571       }
1572     }
1573   } else {
1574     SALOME_ListIO aList;
1575     mySelectionMgr->selectedObjects( aList );
1576
1577     int aNbSel = aList.Extent();
1578
1579     if (aNbSel == 0) { myIsBusy = false; return; }
1580
1581     SMESH::ElementType aType = SMESH::ALL;
1582     switch(myTypeId) {
1583     case 0: aType = SMESH::NODE; break;
1584     case 1: aType = SMESH::EDGE; break;
1585     case 2: aType = SMESH::FACE; break;
1586     case 3: aType = SMESH::VOLUME; break;
1587     }
1588
1589     if (myCurrentLineEdit == mySubMeshLine) {
1590       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1591       SALOME_ListIO aList;
1592       mySelectionMgr->selectedObjects( aList );
1593
1594       SALOME_ListIteratorOfListIO anIt (aList);
1595       for (; anIt.More(); anIt.Next()) {
1596         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1597         if (!aSubMesh->_is_nil()) {
1598           // check if mesh is the same
1599           if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1600             if (aType == SMESH::NODE) {
1601               try {
1602                 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1603                 int k = anElements->length();
1604                 QListBoxItem* anItem = 0;
1605                 for (int i = 0; i < k; i++) {
1606                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1607                   if (anItem) delete anItem;
1608                 }
1609               }
1610               catch (const SALOME::SALOME_Exception& ex) {
1611                 SalomeApp_Tools::QtCatchCorbaException(ex);
1612               }
1613             }
1614             else {
1615               try {
1616                 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1617                 int k = anElements->length();
1618                 QListBoxItem* anItem = 0;
1619                 for (int i = 0; i < k; i++) {
1620                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1621                   if (anItem) delete anItem;
1622                 }
1623               }
1624               catch (const SALOME::SALOME_Exception& ex) {
1625                 SalomeApp_Tools::QtCatchCorbaException(ex);
1626               }
1627             }
1628           }
1629         }
1630       }
1631     }
1632     else if (myCurrentLineEdit == myGroupLine) {
1633       Standard_Boolean aRes;
1634       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1635       SALOME_ListIO aList;
1636       mySelectionMgr->selectedObjects( aList );
1637
1638       SALOME_ListIteratorOfListIO anIt (aList);
1639       for (; anIt.More(); anIt.Next()) {
1640         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1641         if (aRes && !aGroup->_is_nil()) {
1642           // check if mesh is the same
1643           if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1644             SMESH::long_array_var anElements = aGroup->GetListOfID();
1645             int k = anElements->length();
1646             QListBoxItem* anItem = 0;
1647             for (int i = 0; i < k; i++) {
1648               anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1649               if (anItem) delete anItem;
1650             }
1651           }
1652         }
1653       }
1654     }
1655   }
1656   myIsBusy = false;
1657   updateButtons();
1658 }
1659
1660 //=================================================================================
1661 // function : onSort()
1662 // purpose  :
1663 //=================================================================================
1664 void SMESHGUI_GroupDlg::onSort()
1665 {
1666   // PAL5412: sorts items in ascending by "string" value
1667   // myElements->sort(true);
1668   // myElements->update();
1669   int i, k = myElements->count();
1670   if (k > 0) {
1671     myIsBusy = true;
1672     QStringList aSelected;
1673     std::vector<int> anArray(k);
1674     //    QMemArray<int> anArray(k);
1675     QListBoxItem* anItem;
1676     // fill the array
1677     for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1678       anArray[i] = anItem->text().toInt();
1679       if (anItem->isSelected())
1680         aSelected.append(anItem->text());
1681     }
1682     // sort & update list
1683     std::sort(anArray.begin(), anArray.end());
1684     //    anArray.sort();
1685     myElements->clear();
1686     for (i = 0; i < k; i++) {
1687       myElements->insertItem(QString::number(anArray[i]));
1688     }
1689     for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1690       anItem = myElements->findItem(*it, Qt::ExactMatch);
1691       if (anItem) myElements->setSelected(anItem, true);
1692     }
1693     myIsBusy = false;
1694   }
1695 }
1696
1697 //=================================================================================
1698 // function : closeEvent()
1699 // purpose  :
1700 //=================================================================================
1701 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1702 {
1703   onClose();
1704 }
1705
1706 //=================================================================================
1707 // function : SMESHGUI_GroupDlg::onClose
1708 // purpose  : SLOT called when "Close" button pressed. Close dialog
1709 //=================================================================================
1710 void SMESHGUI_GroupDlg::onClose()
1711 {
1712   if (SMESH::GetCurrentVtkView()) {
1713     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1714     SMESH::SetPointRepresentation(false);
1715     SMESH::SetPickable();
1716   }
1717
1718   mySelectionMgr->clearSelected();
1719   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1720     aViewWindow->SetSelectionMode(ActorSelection);
1721   mySelectionMgr->clearFilters();
1722   mySMESHGUI->ResetState();
1723   if( myActor && myOldActorMode>=0 )
1724     myActor->SetEntityMode( myOldActorMode );
1725   reject();
1726 }
1727
1728 //=================================================================================
1729 // function : onHelp()
1730 // purpose  :
1731 //=================================================================================
1732 void SMESHGUI_GroupDlg::onHelp()
1733 {
1734   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1735   if (app) 
1736     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1737   else {
1738     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1739                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1740                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
1741                            QObject::tr("BUT_OK"));
1742   }
1743 }
1744
1745 //=================================================================================
1746 // function : SMESHGUI_GroupDlg::onDeactivate
1747 // purpose  : SLOT called when dialog must be deativated
1748 //=================================================================================
1749 void SMESHGUI_GroupDlg::onDeactivate()
1750 {
1751   mySMESHGUI->ResetState();
1752   setEnabled(false);
1753 }
1754
1755 //=================================================================================
1756 // function : SMESHGUI_GroupDlg::enterEvent
1757 // purpose  : Event filter
1758 //=================================================================================
1759 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1760 {
1761   if (!isEnabled()) {
1762     mySMESHGUI->EmitSignalDeactivateDialog();
1763     setEnabled(true);
1764     mySelectionMode = -1;
1765     setSelectionMode(myTypeId);
1766     //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1767     mySMESHGUI->SetActiveDialogBox(this);
1768     mySMESHGUI->SetState(800);
1769   }
1770 }
1771
1772 //=================================================================================
1773 // function : hideEvent
1774 // purpose  : caused by ESC key
1775 //=================================================================================
1776 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1777 {
1778   if (!isMinimized() && !myIsBusy)
1779     onClose();
1780 }
1781
1782 //=================================================================================
1783 // function : keyPressEvent()
1784 // purpose  :
1785 //=================================================================================
1786 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1787 {
1788   QDialog::keyPressEvent( e );
1789   if ( e->isAccepted() )
1790     return;
1791
1792   if ( e->key() == Key_F1 )
1793     {
1794       e->accept();
1795       onHelp();
1796     }
1797 }
1798
1799 //================================================================================
1800 /*!
1801  * \brief Enable showing of the popup when Geometry selection btn is clicked
1802   * \param enable - true to enable
1803  */
1804 //================================================================================
1805
1806 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1807
1808 void SMESHGUI_GroupDlg::updateGeomPopup()
1809 {
1810   bool enable = false;
1811
1812   if ( !myMesh->_is_nil() )
1813     enable = myMesh->NbEdges() > 0;
1814
1815   if ( myGeomGroupBtn )
1816   {
1817     disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1818     if ( enable ) {
1819       if ( !myGeomPopup ) {
1820         myGeomPopup = new QPopupMenu();
1821         myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
1822         myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
1823         connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
1824       }
1825       connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1826     }
1827   }
1828 }
1829
1830
1831 //=================================================================================
1832 // function : onGeomSelectionButton()
1833 // purpose  :
1834 //=================================================================================
1835 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1836 {
1837   if ( myGeomPopup && isBtnOn )
1838     {
1839       myCurrentLineEdit = myGeomGroupLine;
1840       int id = myGeomPopup->exec( QCursor::pos() );
1841       if (id == DIRECT_GEOM_INDEX || id == -1)
1842         setSelectionMode(7);
1843     }
1844   else if (!isBtnOn)
1845     {
1846       myCurrentLineEdit = 0;
1847       setSelectionMode(8);
1848     }
1849 }
1850
1851 //=================================================================================
1852 // function : onGeomPopup()
1853 // purpose  :
1854 //=================================================================================
1855 void SMESHGUI_GroupDlg::onGeomPopup( int index )
1856 {
1857   if ( index == GEOM_BY_MESH_INDEX )
1858     {
1859       mySelectionMode = -1;
1860       if ( !myShapeByMeshOp ) {
1861         myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1862         connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1863                 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1864         connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1865                 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1866       }
1867       // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1868       if ( !myMesh->_is_nil() ) {
1869         myIsBusy = true;
1870         hide(); // stop processing selection
1871         myIsBusy = false;
1872         myShapeByMeshOp->setModule( mySMESHGUI );
1873         myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1874         myShapeByMeshOp->SetMesh( myMesh );
1875         myShapeByMeshOp->start();
1876       }
1877     }
1878 }
1879
1880 //================================================================================
1881 /*!
1882  * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1883  */
1884 //================================================================================
1885
1886 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1887 {
1888   if ( myShapeByMeshOp == op ) {
1889     mySMESHGUI->getApp()->updateObjectBrowser();
1890     show();
1891     // Select a found geometry object
1892     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1893     if ( !aGeomVar->_is_nil() )
1894     {
1895       QString ID = aGeomVar->GetStudyEntry();
1896       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1897       if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
1898         SALOME_ListIO anIOList;
1899         Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1900           ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1901         anIOList.Append( anIO );
1902         mySelectionMgr->setSelectedObjects( anIOList, false );
1903         onObjectSelectionChanged();
1904       }
1905     }
1906   }
1907 }
1908
1909 //================================================================================
1910 /*!
1911  * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1912  */
1913 //================================================================================
1914
1915 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1916 {
1917   if ( myShapeByMeshOp == op )
1918     {
1919       show();
1920       setSelectionMode(7);
1921     }
1922 }
1923
1924 void SMESHGUI_GroupDlg::storeMode()
1925 {
1926   if( myActor )
1927     myOldActorMode = myActor->GetEntityMode();
1928 }