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