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