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