Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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* aOKBtn = new QPushButton(aButtons, "ok");
339   aOKBtn->setText(tr("SMESH_BUT_OK"));
340   aOKBtn->setAutoDefault(true);
341   aOKBtn->setDefault(true);
342   QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
343   aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
344   aApplyBtn->setAutoDefault(true);
345   QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
346   aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
347   aCloseBtn->setAutoDefault(true);
348   QPushButton* aHelpBtn = new QPushButton(aButtons, "help");
349   aHelpBtn->setText(tr("SMESH_BUT_HELP"));
350   aHelpBtn->setAutoDefault(true);
351
352   aBtnLayout->addWidget(aOKBtn);
353   aBtnLayout->addWidget(aApplyBtn);
354   aBtnLayout->addStretch();
355   aBtnLayout->addWidget(aCloseBtn);
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   myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
483   myGroup = SMESH::SMESH_Group::_nil();
484   myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
485
486   myActor = SMESH::FindActorByObject(myMesh);
487   SMESH::SetPickable(myActor);
488
489   setDefaultGroupColor();
490
491   SALOME_ListIO aList;
492   mySelectionMgr->selectedObjects( aList );
493   if( !aList.IsEmpty() )
494   {
495     QString aName = aList.First()->getName();
496     myMeshGroupLine->setText(aName) ;
497     myMeshGroupLine->home( false );
498   }
499
500   myCurrentLineEdit = 0;
501
502   myTypeGroup->setButton(0);
503   onTypeChanged(0);
504 }
505
506 //=================================================================================
507 // function : Init()
508 // purpose  :
509 //=================================================================================
510 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
511 {
512   myMesh = theGroup->GetMesh();
513   
514   myName->setText(theGroup->GetName());
515   myName->home(false);
516   myOldName = myName->text();
517
518   SALOMEDS::Color aColor = theGroup->GetColor();
519   setGroupColor( aColor );
520   
521   myMeshGroupLine->setText(theGroup->GetName());
522
523   int aType = 0;
524   switch(theGroup->GetType()) {
525   case SMESH::NODE: aType= 0; break;
526   case SMESH::EDGE: aType = 1; break;
527   case SMESH::FACE: aType = 2; break;
528   case SMESH::VOLUME: aType = 3; break;
529   }
530   myTypeGroup->setButton(aType);
531   
532   myGroup = SMESH::SMESH_Group::_narrow( theGroup );
533
534   if ( !myGroup->_is_nil() )
535     {
536       myActor = SMESH::FindActorByObject(myMesh);
537       if ( !myActor )
538         myActor = SMESH::FindActorByObject(myGroup);
539       SMESH::SetPickable(myActor);
540
541       myGrpTypeGroup->setButton(0);
542       onGrpTypeChanged(0);
543       
544       myCurrentLineEdit = 0;
545       myElements->clear();
546       setSelectionMode(aType);
547       myTypeId = aType;
548       
549       myIdList.clear();
550       if (!myGroup->IsEmpty()) {
551         SMESH::long_array_var anElements = myGroup->GetListOfID();
552         int k = anElements->length();
553         for (int i = 0; i < k; i++) {
554           myIdList.append(anElements[i]);
555           myElements->insertItem(QString::number(anElements[i]));
556         }
557         myElements->selectAll(true);
558       }
559     }
560   else
561     {
562       myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
563       
564       if ( !myGroupOnGeom->_is_nil() )
565         {
566           myActor = SMESH::FindActorByObject(myMesh);
567           if ( !myActor )
568             myActor = SMESH::FindActorByObject(myGroup);
569           SMESH::SetPickable(myActor);
570
571           myGrpTypeGroup->setButton(1);
572           onGrpTypeChanged(1);
573           
574           QString aShapeName("");
575           _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
576           GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
577           if (!aGroupShape->_is_nil())
578             {
579               _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
580               aShapeName = aGroupShapeSO->GetName().c_str();
581             }
582           myGeomGroupLine->setText( aShapeName );
583           myName->setText("Group On " + aShapeName);
584         }
585     }
586 }
587
588 //=================================================================================
589 // function : updateButtons()
590 // purpose  :
591 //=================================================================================
592 void SMESHGUI_GroupDlg::updateButtons()
593 {
594   bool enable = !myName->text().stripWhiteSpace().isEmpty();
595
596   if (myGrpTypeId == 0) {
597     enable = enable && myElements->count() > 0;
598     enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
599   }
600   else if (myGrpTypeId == 1) {
601     if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
602       enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
603     }
604   }
605
606   QPushButton* aBtn;
607   aBtn = (QPushButton*) child("ok", "QPushButton");
608   if (aBtn) aBtn->setEnabled(enable);
609   aBtn = (QPushButton*) child("apply", "QPushButton");
610   if (aBtn) aBtn->setEnabled(enable);
611 }
612
613 //=================================================================================
614 // function : onNameChanged()
615 // purpose  :
616 //=================================================================================
617 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
618 {
619   updateButtons();
620 }
621
622 //=================================================================================
623 // function : onTypeChanged()
624 // purpose  : Group elements type radio button management
625 //=================================================================================
626 void SMESHGUI_GroupDlg::onTypeChanged (int id)
627 {
628   if (myTypeId != id) {
629     myElements->clear();
630     if (myCurrentLineEdit == 0)
631       setSelectionMode(id);
632   }
633   myTypeId = id;
634 }
635
636 //=================================================================================
637 // function : onGrpTypeChanged()
638 // purpose  : Group type radio button management
639 //=================================================================================
640 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
641 {
642   if (myGrpTypeId != id) {
643     myWGStack->raiseWidget( id );
644     if (id == 0)
645       myName->setText(myOldName);
646     onSelectGeomGroup(id == 1);
647   }
648   myGrpTypeId = id;
649 }
650
651 //=================================================================================
652 // function : onSelectColor()
653 // purpose  :
654 //=================================================================================
655 void SMESHGUI_GroupDlg::onSelectColor()
656 {
657   QColor color = getGroupQColor();
658   color = QColorDialog::getColor( color );
659   setGroupQColor( color );
660
661   updateButtons();
662 }
663
664 //=================================================================================
665 // function : setSelectionMode()
666 // purpose  : Radio button management
667 //=================================================================================
668 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
669 {
670   // PAL7314
671   if (myMesh->_is_nil())
672     return;
673   if (mySelectionMode != theMode) {
674     // [PAL10408] mySelectionMgr->clearSelected();
675     mySelectionMgr->clearFilters();
676     if (myActor)
677       myActor->SetPointRepresentation(false);
678     else
679       SMESH::SetPointRepresentation(false);
680     if (theMode < 4) {
681       switch (theMode) {
682       case 0:
683         if (myActor)
684           myActor->SetPointRepresentation(true);
685         else
686           SMESH::SetPointRepresentation(true);
687         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
688           aViewWindow->SetSelectionMode(NodeSelection);
689         break;
690       case 1:
691         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
692           aViewWindow->SetSelectionMode(EdgeSelection);
693         break;
694       case 2:
695         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
696           aViewWindow->SetSelectionMode(FaceSelection);
697         break;
698       default:
699         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
700           aViewWindow->SetSelectionMode(VolumeSelection);
701       }
702     } else {
703       if (theMode == 4)
704         mySelectionMgr->installFilter(mySubMeshFilter);
705       else if (theMode == 5)
706         mySelectionMgr->installFilter(myGroupFilter);
707       else if (theMode == 6)
708         mySelectionMgr->installFilter(myMeshFilter);
709       else if (theMode == 7)
710         mySelectionMgr->installFilter(myGeomFilter);
711       
712       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
713         aViewWindow->SetSelectionMode(ActorSelection);
714     }
715     mySelectionMode = theMode;
716   } 
717 }
718
719 //=================================================================================
720 // function : onApply()
721 // purpose  :
722 //=================================================================================
723 bool SMESHGUI_GroupDlg::onApply()
724 {
725   if (mySMESHGUI->isActiveStudyLocked())
726     return false;
727
728   if (myName->text().stripWhiteSpace().isEmpty())
729     return false;
730
731   if (myGrpTypeId == 0) { // on mesh elements
732     if (!myElements->count())
733       return false;
734
735     mySelectionMgr->clearSelected();
736
737     if (myGroup->_is_nil()) { // creation
738       if (myMesh->_is_nil())
739         return false;
740
741       SMESH::ElementType aType = SMESH::ALL;
742       switch (myTypeId) {
743       case 0: aType = SMESH::NODE; break;
744       case 1: aType = SMESH::EDGE; break;
745       case 2: aType = SMESH::FACE; break;
746       case 3: aType = SMESH::VOLUME; break;
747       }
748
749       SMESH::long_array_var anIdList = new SMESH::long_array;
750       int i, k = myElements->count();
751       anIdList->length(k);
752       QListBoxItem* anItem;
753       for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
754         anIdList[i] = anItem->text().toInt();
755       }
756
757       myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
758       myGroup->Add(anIdList.inout());
759
760       SALOMEDS::Color aColor = getGroupColor();
761       myGroup->SetColor(aColor);
762
763       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
764
765       //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
766       SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
767
768       /* init for next operation */
769       myName->setText("");
770       myElements->clear();
771       myGroup = SMESH::SMESH_Group::_nil();
772
773     } else { // edition
774       myGroup->SetName(myName->text());
775         
776       SALOMEDS::Color aColor = getGroupColor();
777       myGroup->SetColor(aColor);
778
779       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
780       if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
781         anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
782
783       QValueList<int> aAddList;
784       QValueList<int>::iterator anIt;
785       QListBoxItem* anItem;
786
787       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
788         int anId = anItem->text().toInt();
789         if ((anIt = myIdList.find(anId)) == myIdList.end())
790           aAddList.append(anId);
791         else
792           myIdList.remove(anIt);
793       }
794       if (!aAddList.empty()) {
795         SMESH::long_array_var anIdList = new SMESH::long_array;
796         anIdList->length(aAddList.count());
797         int i;
798         for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
799           anIdList[i] = *anIt;
800         myGroup->Add(anIdList.inout());
801       }
802       if (!myIdList.empty()) {
803         SMESH::long_array_var anIdList = new SMESH::long_array;
804         anIdList->length(myIdList.count());
805         int i;
806         for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
807           anIdList[i] = *anIt;
808         myGroup->Remove(anIdList.inout());
809       }
810       /* init for next operation */
811       myIdList.clear();
812       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
813         myIdList.append(anItem->text().toInt());
814     }
815
816     mySMESHGUI->updateObjBrowser(true);
817     SMESH::UpdateView(); // asv: fix of BUG PAL5515
818     mySelectionMgr->clearSelected();
819     return true;
820   }
821   else if (myGrpTypeId == 1) { // on geom object
822     if (CORBA::is_nil(myGroupOnGeom)) { // creation
823       if (myMesh->_is_nil() || !myGeomObjects->length())
824         return false;
825
826       SMESH::ElementType aType = SMESH::ALL;
827       switch (myTypeId) {
828       case 0: aType = SMESH::NODE; break;
829       case 1: aType = SMESH::EDGE; break;
830       case 2: aType = SMESH::FACE; break;
831       case 3: aType = SMESH::VOLUME; break;
832       }
833
834       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
835       GEOM::GEOM_IGroupOperations_var aGroupOp =
836         SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
837
838       if (myGeomObjects->length() == 1) {
839         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
840       }
841       else {
842         SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
843         if ( aSMESHGen->_is_nil() )
844           return false;
845
846         // create a geometry group
847         GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
848         _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
849
850         if (geomGen->_is_nil() || !aStudy)
851           return false;
852
853         GEOM::GEOM_IGroupOperations_var op =
854           geomGen->GetIGroupOperations(aStudy->StudyId());
855         if (op->_is_nil())
856           return false;
857
858         // check and add all selected GEOM objects: they must be
859         // a sub-shapes of the main GEOM and must be of one type
860         TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
861         for ( int i =0; i < myGeomObjects->length(); i++) {
862           TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
863           if (i == 0)
864             aGroupType = aSubShapeType;
865           else if (aSubShapeType != aGroupType) {
866             aGroupType = TopAbs_SHAPE;
867             break;
868           }
869         }
870
871         GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
872         GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
873         op->UnionList(aGroupVar, myGeomObjects);
874
875         if (op->IsDone()) {
876           // publish the GEOM group in study
877           QString aNewGeomGroupName ("Auto_group_for_");
878           aNewGeomGroupName += myName->text();
879           SALOMEDS::SObject_var aNewGroupSO =
880             geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
881         }
882
883         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
884       }
885
886       SALOMEDS::Color aColor = getGroupColor();
887       myGroupOnGeom->SetColor(aColor);
888
889       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
890
891       //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
892       SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
893
894       /* init for next operation */
895       myName->setText("");
896       myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
897     }
898     else { // edition
899       myGroupOnGeom->SetName(myName->text());
900
901       SALOMEDS::Color aColor = getGroupColor();
902       myGroupOnGeom->SetColor(aColor);
903
904       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
905       if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
906         anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
907     }
908
909     mySMESHGUI->updateObjBrowser(true);
910     mySelectionMgr->clearSelected();
911     return true;
912   }
913
914   return false;
915 }
916
917 //=================================================================================
918 // function : onOK()
919 // purpose  :
920 //=================================================================================
921 void SMESHGUI_GroupDlg::onOK()
922 {
923   if ( onApply() )
924     onClose();
925 }
926
927 //=================================================================================
928 // function : onListSelectionChanged()
929 // purpose  : Called when selection in element list is changed
930 //=================================================================================
931 void SMESHGUI_GroupDlg::onListSelectionChanged()
932 {
933   //  MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
934   if( myIsBusy || !myActor) return;
935     myIsBusy = true;
936
937   if (myCurrentLineEdit == 0) {
938     mySelectionMgr->clearSelected();
939     TColStd_MapOfInteger aIndexes;
940     QListBoxItem* anItem;
941     for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
942       if (anItem->isSelected()) {
943         int anId = anItem->text().toInt();
944         aIndexes.Add(anId);
945       }
946     }
947     mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
948     SALOME_ListIO aList;
949     aList.Append(myActor->getIO());
950     mySelectionMgr->setSelectedObjects(aList,false);
951   }
952   myIsBusy = false;
953 }
954
955 //=================================================================================
956 // function : onObjectSelectionChanged()
957 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
958 //=================================================================================
959 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
960 {
961   if ( myIsBusy || !isEnabled()) return;
962   if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
963
964   myIsBusy = true;
965
966   SALOME_ListIO aList;
967   mySelectionMgr->selectedObjects( aList );
968   
969   int aNbSel = aList.Extent();
970   myElements->clearSelection();
971
972   if (myCurrentLineEdit) {
973     myCurrentLineEdit->setText("");
974     QString aString = "";
975
976     if (myCurrentLineEdit == myMeshGroupLine) {
977       mySelectSubMesh->setEnabled(false);
978       mySelectGroup->setEnabled(false);
979       myGroupLine->setText("");
980       mySubMeshLine->setText("");
981
982       myGeomGroupBtn->setEnabled(false);
983       myGeomGroupLine->setEnabled(false);
984       myGeomGroupLine->setText("");
985       myGeomObjects = new GEOM::ListOfGO();
986       myGeomObjects->length(0);
987
988       if (myGeomGroupBtn->isOn())
989         myGeomGroupBtn->setOn(false);
990       if (!myCreate)
991         myName->setText("");
992
993       myElements->clear();
994
995       if (aNbSel != 1 ) {
996         myGroup = SMESH::SMESH_Group::_nil();
997         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); 
998         myMesh = SMESH::SMESH_Mesh::_nil();
999         updateGeomPopup();
1000         updateButtons();
1001         myIsBusy = false;
1002         return;
1003       }
1004       Handle(SALOME_InteractiveObject) IO = aList.First();
1005
1006       if (myCreate) {
1007         myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1008         updateGeomPopup();
1009         if (myMesh->_is_nil())
1010         {
1011           updateButtons();
1012           myIsBusy = false;
1013           return;
1014         }
1015         myGroup = SMESH::SMESH_Group::_nil();
1016
1017         myActor = SMESH::FindActorByObject(myMesh);
1018         SMESH::SetPickable(myActor);
1019
1020         aString = aList.First()->getName();
1021         myMeshGroupLine->setText(aString) ;
1022         myMeshGroupLine->home( false );
1023
1024         mySelectSubMesh->setEnabled(true);
1025         mySelectGroup->setEnabled(true);
1026         myGeomGroupBtn->setEnabled(true);
1027         myGeomGroupLine->setEnabled(true);
1028         updateButtons();
1029       } else {
1030         SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1031         if (aGroup->_is_nil())
1032         {
1033           myIsBusy = false;
1034           return;
1035         }
1036         myIsBusy = false;
1037         myCurrentLineEdit = 0;
1038
1039         myGroup = SMESH::SMESH_Group::_nil();
1040         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1041         
1042         init(aGroup);
1043         myIsBusy = true;
1044         mySelectSubMesh->setEnabled(true);
1045         mySelectGroup->setEnabled(true);
1046       }
1047       myCurrentLineEdit = 0;
1048       myIsBusy = false;
1049       if (!myCreate)
1050         return;
1051
1052       if (myGrpTypeId == 0)
1053         {
1054           if (myTypeId == -1)
1055             onTypeChanged(0);
1056           else
1057             {
1058               myElements->clear();
1059               setSelectionMode(myTypeId);
1060             }
1061         }
1062
1063       myIsBusy = false;
1064       return;
1065
1066     } else if (myCurrentLineEdit == myGeomGroupLine) {
1067
1068       myGeomObjects = new GEOM::ListOfGO();
1069
1070       // The mesh SObject
1071       _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1072
1073       if (aNbSel == 0 || !aMeshSO)
1074         {
1075           myGeomObjects->length(0);
1076           updateButtons();
1077           myIsBusy = false;
1078           return;
1079         }
1080
1081       myGeomObjects->length(aNbSel);
1082
1083       GEOM::GEOM_Object_var aGeomGroup;
1084       Standard_Boolean testResult;
1085       int i = 0;
1086       
1087       SALOME_ListIteratorOfListIO anIt (aList);
1088       for (; anIt.More(); anIt.Next()) {
1089         
1090         testResult = Standard_False;
1091         aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1092
1093         // Check if the object is a geometry group
1094         if (!testResult || CORBA::is_nil(aGeomGroup))
1095           continue;
1096         
1097
1098         // Check if group constructed on the same shape as a mesh or on its child
1099         _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1100         GEOM::GEOM_IGroupOperations_var anOp =
1101           SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1102
1103         // The main shape of the group
1104         GEOM::GEOM_Object_var aGroupMainShape;
1105         if (aGeomGroup->GetType() == 37)
1106           aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1107         else
1108           aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1109         _PTR(SObject) aGroupMainShapeSO =
1110           //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1111           aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1112         
1113         _PTR(SObject) anObj, aRef;
1114         bool isRefOrSubShape = false;
1115         if (aMeshSO->FindSubObject(1, anObj) &&  anObj->ReferencedObject(aRef)) {
1116           //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1117           if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1118             isRefOrSubShape = true;
1119           } else {
1120             _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1121             _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1122             //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1123             while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1124               //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1125               if (aRef->GetID() == aFather->GetID())
1126                 isRefOrSubShape = true;
1127               else
1128                 aFather = aFather->GetFather();
1129             }
1130           }
1131         }
1132         if (isRefOrSubShape)
1133           myGeomObjects[i++] = aGeomGroup;
1134       }
1135       
1136       myGeomObjects->length(i);
1137       if ( i == 0 )
1138         {
1139           myIsBusy = false;
1140           return;
1141         }
1142       
1143       aNbSel = i;
1144     }
1145
1146     if(aNbSel >= 1) {
1147       if(aNbSel > 1) {
1148         if(myCurrentLineEdit == mySubMeshLine)
1149           aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1150         else if(myCurrentLineEdit == myGroupLine)
1151           aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1152         else if(myCurrentLineEdit == myGeomGroupLine)
1153           aString = tr("%1 Objects").arg(aNbSel);
1154       } else {
1155         aString = aList.First()->getName();
1156       }
1157     }
1158
1159     myCurrentLineEdit->setText(aString);
1160     myOldName = myName->text();
1161     myName->setText(aString);
1162     myCurrentLineEdit->home(false);
1163
1164     updateButtons();
1165
1166   } else {
1167     if (aNbSel == 1 && myActor ) {
1168       QString aListStr = "";
1169       int aNbItems = 0;
1170       if (myTypeId == 0) {
1171         aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1172       } else {
1173         aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1174       }
1175       if (aNbItems > 0) {
1176         QStringList anElements = QStringList::split(" ", aListStr);
1177         QListBoxItem* anItem = 0;
1178         for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1179           anItem = myElements->findItem(*it, Qt::ExactMatch);
1180           if (anItem) myElements->setSelected(anItem, true);
1181         }
1182       }
1183     }
1184   }
1185
1186   if (!myActor) {
1187     if (!myGroup->_is_nil())
1188       myActor = SMESH::FindActorByObject(myGroup);
1189     else if(!myGroupOnGeom->_is_nil())
1190       myActor = SMESH::FindActorByObject(myGroupOnGeom);
1191     else
1192       myActor = SMESH::FindActorByObject(myMesh);
1193   }
1194
1195   myIsBusy = false;
1196 }
1197
1198 //=================================================================================
1199 // function : onSelectSubMesh()
1200 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1201 //=================================================================================
1202 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1203 {
1204   if (on) {
1205     if (mySelectGroup->isChecked()) {
1206       mySelectGroup->setChecked(false);
1207     }
1208     //VSR: else if (mySelectGeomGroup->isChecked()) {
1209     //VSR:   mySelectGeomGroup->setChecked(false);
1210     //VSR: }
1211     myCurrentLineEdit = mySubMeshLine;
1212     setSelectionMode(4);
1213   }
1214   else {
1215     mySubMeshLine->setText("");
1216     myCurrentLineEdit = 0;
1217     if (myTypeId != -1)
1218       setSelectionMode(myTypeId);
1219   }
1220   mySubMeshBtn->setEnabled(on);
1221   mySubMeshLine->setEnabled(on);
1222 }
1223
1224
1225 //=================================================================================
1226 // function : (onSelectGroup)
1227 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1228 //=================================================================================
1229 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1230 {
1231   if (on) {
1232     if (mySelectSubMesh->isChecked()) {
1233       mySelectSubMesh->setChecked(false);
1234     }
1235     myCurrentLineEdit = myGroupLine;
1236     setSelectionMode(5);
1237   }
1238   else {
1239     myGroupLine->setText("");
1240     myCurrentLineEdit = 0;
1241     if (myTypeId != -1)
1242       setSelectionMode(myTypeId);
1243   }
1244   myGroupBtn->setEnabled(on);
1245   myGroupLine->setEnabled(on);
1246 }
1247
1248
1249 //=================================================================================
1250 // function : (onSelectGeomGroup)
1251 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1252 //=================================================================================
1253 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1254 {
1255   if (on) {
1256     if (mySelectSubMesh->isChecked()) {
1257       mySelectSubMesh->setChecked(false);
1258     }
1259     else if (mySelectGroup->isChecked()) {
1260       mySelectGroup->setChecked(false);
1261     }
1262     myCurrentLineEdit = myGeomGroupLine;
1263     updateGeomPopup();
1264     setSelectionMode(8);
1265   }
1266   else {
1267     myGeomGroupBtn->setOn(false);
1268     myGeomObjects->length(0);
1269     myGeomGroupLine->setText("");
1270     myCurrentLineEdit = 0;
1271     if (myTypeId != -1)
1272       setSelectionMode(myTypeId);
1273   }
1274 }
1275
1276
1277 //=================================================================================
1278 // function : setCurrentSelection()
1279 // purpose  :
1280 //=================================================================================
1281 void SMESHGUI_GroupDlg::setCurrentSelection()
1282 {
1283   QPushButton* send = (QPushButton*)sender();
1284   myCurrentLineEdit = 0;
1285   if (send == myMeshGroupBtn) {
1286     myCurrentLineEdit = myMeshGroupLine;
1287     if (myCreate)
1288       setSelectionMode(6);
1289     else
1290       setSelectionMode(5);
1291     onObjectSelectionChanged();
1292   }
1293   else if (send == mySubMeshBtn) {
1294     myCurrentLineEdit = mySubMeshLine;
1295     onObjectSelectionChanged();
1296   }
1297   else if (send == myGroupBtn) {
1298     myCurrentLineEdit = myGroupLine;
1299     onObjectSelectionChanged();
1300   }
1301 }
1302
1303
1304 //=================================================================================
1305 // function : setFilters()
1306 // purpose  : SLOT. Called when "Filter" button pressed.
1307 //=================================================================================
1308 void SMESHGUI_GroupDlg::setFilters()
1309 {
1310   SMESH::ElementType aType = SMESH::ALL;
1311   switch ( myTypeId )
1312   {
1313     case 0 : aType = SMESH::NODE; break;
1314     case 1 : aType = SMESH::EDGE; break;
1315     case 2 : aType = SMESH::FACE; break;
1316     case 3 : aType = SMESH::VOLUME; break;
1317     default: return;
1318   }
1319
1320   if ( myFilterDlg == 0 )
1321   {
1322     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1323     connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1324   }
1325   else
1326     myFilterDlg->Init( aType );
1327
1328   myFilterDlg->SetSelection();
1329   myFilterDlg->SetMesh( myMesh );
1330   myFilterDlg->SetSourceWg( myElements );
1331
1332   myFilterDlg->show();
1333 }
1334
1335 //=================================================================================
1336 // function : onFilterAccepted()
1337 // purpose  : SLOT. Called when Filter dlg closed with OK button.
1338 //            Uncheck "Select submesh" and "Select group" checkboxes
1339 //=================================================================================
1340 void SMESHGUI_GroupDlg::onFilterAccepted()
1341 {
1342   if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1343   {
1344     mySelectionMode = myTypeId;
1345     mySelectSubMesh->setChecked( false );
1346     mySelectGroup->setChecked( false );
1347   }
1348 }
1349
1350 //=================================================================================
1351 // function : onAdd()
1352 // purpose  :
1353 //=================================================================================
1354 void SMESHGUI_GroupDlg::onAdd()
1355 {
1356   SALOME_ListIO aList;
1357   mySelectionMgr->selectedObjects( aList );
1358
1359   int aNbSel = aList.Extent();
1360
1361   if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1362
1363   myIsBusy = true;
1364
1365   SMESH::ElementType aType = SMESH::ALL;
1366   switch(myTypeId) {
1367   case 0: 
1368     aType = SMESH::NODE; 
1369     mySelector->SetSelectionMode(NodeSelection);
1370     break;
1371   case 1: 
1372     aType = SMESH::EDGE; 
1373     mySelector->SetSelectionMode(EdgeSelection);
1374     break;
1375   case 2: 
1376     aType = SMESH::FACE; 
1377     mySelector->SetSelectionMode(FaceSelection);
1378     break;
1379   case 3: 
1380     aType = SMESH::VOLUME; 
1381     mySelector->SetSelectionMode(VolumeSelection);
1382     break;
1383   default:
1384     mySelector->SetSelectionMode(ActorSelection);
1385   }
1386
1387
1388   if (myCurrentLineEdit == 0) {
1389     //if (aNbSel != 1) { myIsBusy = false; return; }
1390     QString aListStr = "";
1391     int aNbItems = 0;
1392     if (myTypeId == 0) {
1393       aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1394     }
1395     else {
1396       aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1397     }
1398     if (aNbItems > 0) {
1399       QStringList anElements = QStringList::split(" ", aListStr);
1400       QListBoxItem* anItem = 0;
1401       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1402         anItem = myElements->findItem(*it, Qt::ExactMatch);
1403         if (!anItem) {
1404           anItem = new QListBoxText(*it);
1405           myElements->insertItem(anItem);
1406         }
1407         myElements->setSelected(anItem, true);
1408       }
1409     }
1410   } else if (myCurrentLineEdit == mySubMeshLine) {
1411     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1412     
1413     SALOME_ListIO aList;
1414     mySelectionMgr->selectedObjects( aList );
1415
1416     SALOME_ListIteratorOfListIO anIt (aList);
1417     for (; anIt.More(); anIt.Next()) {
1418       SMESH::SMESH_subMesh_var aSubMesh =
1419         SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1420       if (!aSubMesh->_is_nil()) {
1421         // check if mesh is the same
1422         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1423           try {
1424             SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1425             int k = anElements->length();
1426             QListBoxItem* anItem = 0;
1427             for (int i = 0; i < k; i++) {
1428               QString aText = QString::number(anElements[i]);
1429               anItem = myElements->findItem(aText, Qt::ExactMatch);
1430               if (!anItem) {
1431                 anItem = new QListBoxText(aText);
1432                 myElements->insertItem(anItem);
1433               }
1434               myElements->setSelected(anItem, true);
1435             }
1436           }
1437           catch (const SALOME::SALOME_Exception& ex) {
1438             SalomeApp_Tools::QtCatchCorbaException(ex);
1439           }
1440         }
1441       }
1442     }
1443     mySelectSubMesh->setChecked(false);
1444     myIsBusy = false;
1445     onListSelectionChanged();
1446
1447   } else if (myCurrentLineEdit == myGroupLine) {
1448     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1449     SALOME_ListIO aList;
1450     mySelectionMgr->selectedObjects( aList );
1451     
1452     SALOME_ListIteratorOfListIO anIt (aList);
1453     for (; anIt.More(); anIt.Next()) {
1454       SMESH::SMESH_Group_var aGroup =
1455         SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1456       if (!aGroup->_is_nil()) {
1457         // check if mesh is the same
1458         if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1459           SMESH::long_array_var anElements = aGroup->GetListOfID();
1460           int k = anElements->length();
1461           QListBoxItem* anItem = 0;
1462           for (int i = 0; i < k; i++) {
1463             QString aText = QString::number(anElements[i]);
1464             anItem = myElements->findItem(aText, Qt::ExactMatch);
1465             if (!anItem) {
1466               anItem = new QListBoxText(aText);
1467               myElements->insertItem(anItem);
1468             }
1469             myElements->setSelected(anItem, true);
1470           }
1471         }
1472       }
1473     }
1474     mySelectGroup->setChecked(false);
1475     myIsBusy = false;
1476     onListSelectionChanged();
1477
1478   } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1479     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1480     GEOM::GEOM_IGroupOperations_var aGroupOp =
1481       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1482
1483     SMESH::ElementType aGroupType = SMESH::ALL;
1484     switch(aGroupOp->GetType(myGeomObjects[0])) {
1485     case 7: aGroupType = SMESH::NODE; break;
1486     case 6: aGroupType = SMESH::EDGE; break;
1487     case 4: aGroupType = SMESH::FACE; break;
1488     case 2: aGroupType = SMESH::VOLUME; break;
1489     default: myIsBusy = false; return;
1490     }
1491
1492     if (aGroupType == aType) {
1493       _PTR(SObject) aGroupSO =
1494         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1495         aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1496       // Construct filter
1497       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1498       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1499       SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1500       aBelongToGeom->SetGeom(myGeomObjects[0]);
1501       aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1502       aBelongToGeom->SetElementType(aType);
1503       aFilter->SetPredicate(aBelongToGeom);
1504
1505       SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1506
1507       int k = anElements->length();
1508       QListBoxItem* anItem = 0;
1509       for (int i = 0; i < k; i++) {
1510         QString aText = QString::number(anElements[i]);
1511         anItem = myElements->findItem(aText, Qt::ExactMatch);
1512         if (!anItem) {
1513           anItem = new QListBoxText(aText);
1514           myElements->insertItem(anItem);
1515         }
1516         myElements->setSelected(anItem, true);
1517       }
1518     }
1519
1520     //VSR: mySelectGeomGroup->setChecked(false);
1521     myIsBusy = false;
1522     onListSelectionChanged();
1523   }
1524   myIsBusy = false;
1525   //  mySelectionMgr->clearSelected();
1526   updateButtons();
1527 }
1528
1529 //=================================================================================
1530 // function : onRemove()
1531 // purpose  :
1532 //=================================================================================
1533 void SMESHGUI_GroupDlg::onRemove()
1534 {
1535   myIsBusy = true;
1536   if (myCurrentLineEdit == 0) {
1537     for (int i = myElements->count(); i > 0; i--) {
1538       if (myElements->isSelected(i-1)) {
1539         myElements->removeItem(i-1);
1540       }
1541     }
1542   } else {
1543     SALOME_ListIO aList;
1544     mySelectionMgr->selectedObjects( aList );
1545
1546     int aNbSel = aList.Extent();
1547
1548     if (aNbSel == 0) { myIsBusy = false; return; }
1549
1550     SMESH::ElementType aType = SMESH::ALL;
1551     switch(myTypeId) {
1552     case 0: aType = SMESH::NODE; break;
1553     case 1: aType = SMESH::EDGE; break;
1554     case 2: aType = SMESH::FACE; break;
1555     case 3: aType = SMESH::VOLUME; break;
1556     }
1557
1558     if (myCurrentLineEdit == mySubMeshLine) {
1559       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1560       SALOME_ListIO aList;
1561       mySelectionMgr->selectedObjects( aList );
1562
1563       SALOME_ListIteratorOfListIO anIt (aList);
1564       for (; anIt.More(); anIt.Next()) {
1565         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1566         if (!aSubMesh->_is_nil()) {
1567           // check if mesh is the same
1568           if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1569             if (aType == SMESH::NODE) {
1570               try {
1571                 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1572                 int k = anElements->length();
1573                 QListBoxItem* anItem = 0;
1574                 for (int i = 0; i < k; i++) {
1575                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1576                   if (anItem) delete anItem;
1577                 }
1578               }
1579               catch (const SALOME::SALOME_Exception& ex) {
1580                 SalomeApp_Tools::QtCatchCorbaException(ex);
1581               }
1582             }
1583             else {
1584               try {
1585                 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1586                 int k = anElements->length();
1587                 QListBoxItem* anItem = 0;
1588                 for (int i = 0; i < k; i++) {
1589                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1590                   if (anItem) delete anItem;
1591                 }
1592               }
1593               catch (const SALOME::SALOME_Exception& ex) {
1594                 SalomeApp_Tools::QtCatchCorbaException(ex);
1595               }
1596             }
1597           }
1598         }
1599       }
1600     }
1601     else if (myCurrentLineEdit == myGroupLine) {
1602       Standard_Boolean aRes;
1603       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1604       SALOME_ListIO aList;
1605       mySelectionMgr->selectedObjects( aList );
1606
1607       SALOME_ListIteratorOfListIO anIt (aList);
1608       for (; anIt.More(); anIt.Next()) {
1609         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1610         if (aRes && !aGroup->_is_nil()) {
1611           // check if mesh is the same
1612           if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1613             SMESH::long_array_var anElements = aGroup->GetListOfID();
1614             int k = anElements->length();
1615             QListBoxItem* anItem = 0;
1616             for (int i = 0; i < k; i++) {
1617               anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1618               if (anItem) delete anItem;
1619             }
1620           }
1621         }
1622       }
1623     }
1624   }
1625   myIsBusy = false;
1626   updateButtons();
1627 }
1628
1629 //=================================================================================
1630 // function : onSort()
1631 // purpose  :
1632 //=================================================================================
1633 void SMESHGUI_GroupDlg::onSort()
1634 {
1635   // PAL5412: sorts items in ascending by "string" value
1636   // myElements->sort(true);
1637   // myElements->update();
1638   int i, k = myElements->count();
1639   if (k > 0) {
1640     myIsBusy = true;
1641     QStringList aSelected;
1642     std::vector<int> anArray(k);
1643     //    QMemArray<int> anArray(k);
1644     QListBoxItem* anItem;
1645     // fill the array
1646     for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1647       anArray[i] = anItem->text().toInt();
1648       if (anItem->isSelected())
1649         aSelected.append(anItem->text());
1650     }
1651     // sort & update list
1652     std::sort(anArray.begin(), anArray.end());
1653     //    anArray.sort();
1654     myElements->clear();
1655     for (i = 0; i < k; i++) {
1656       myElements->insertItem(QString::number(anArray[i]));
1657     }
1658     for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1659       anItem = myElements->findItem(*it, Qt::ExactMatch);
1660       if (anItem) myElements->setSelected(anItem, true);
1661     }
1662     myIsBusy = false;
1663   }
1664 }
1665
1666 //=================================================================================
1667 // function : closeEvent()
1668 // purpose  :
1669 //=================================================================================
1670 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1671 {
1672   onClose();
1673 }
1674
1675 //=================================================================================
1676 // function : SMESHGUI_GroupDlg::onClose
1677 // purpose  : SLOT called when "Close" button pressed. Close dialog
1678 //=================================================================================
1679 void SMESHGUI_GroupDlg::onClose()
1680 {
1681   if (SMESH::GetCurrentVtkView()) {
1682     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1683     SMESH::SetPointRepresentation(false);
1684     SMESH::SetPickable();
1685   }
1686
1687   mySelectionMgr->clearSelected();
1688   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1689     aViewWindow->SetSelectionMode(ActorSelection);
1690   mySelectionMgr->clearFilters();
1691   mySMESHGUI->ResetState();
1692
1693   reject();
1694 }
1695
1696 //=================================================================================
1697 // function : onHelp()
1698 // purpose  :
1699 //=================================================================================
1700 void SMESHGUI_GroupDlg::onHelp()
1701 {
1702   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1703   if (app) 
1704     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1705   else {
1706                 QString platform;
1707 #ifdef WIN32
1708                 platform = "winapplication";
1709 #else
1710                 platform = "application";
1711 #endif
1712     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1713                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1714                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
1715                            QObject::tr("BUT_OK"));
1716   }
1717 }
1718
1719 //=================================================================================
1720 // function : SMESHGUI_GroupDlg::onDeactivate
1721 // purpose  : SLOT called when dialog must be deativated
1722 //=================================================================================
1723 void SMESHGUI_GroupDlg::onDeactivate()
1724 {
1725   mySMESHGUI->ResetState();
1726   setEnabled(false);
1727 }
1728
1729 //=================================================================================
1730 // function : SMESHGUI_GroupDlg::enterEvent
1731 // purpose  : Event filter
1732 //=================================================================================
1733 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1734 {
1735   if (!isEnabled()) {
1736     mySMESHGUI->EmitSignalDeactivateDialog();
1737     setEnabled(true);
1738     mySelectionMode = -1;
1739     setSelectionMode(myTypeId);
1740     //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1741     mySMESHGUI->SetActiveDialogBox(this);
1742     mySMESHGUI->SetState(800);
1743   }
1744 }
1745
1746 //=================================================================================
1747 // function : hideEvent
1748 // purpose  : caused by ESC key
1749 //=================================================================================
1750 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1751 {
1752   if (!isMinimized() && !myIsBusy)
1753     onClose();
1754 }
1755
1756 //=================================================================================
1757 // function : keyPressEvent()
1758 // purpose  :
1759 //=================================================================================
1760 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1761 {
1762   QDialog::keyPressEvent( e );
1763   if ( e->isAccepted() )
1764     return;
1765
1766   if ( e->key() == Key_F1 )
1767     {
1768       e->accept();
1769       onHelp();
1770     }
1771 }
1772
1773 //================================================================================
1774 /*!
1775  * \brief Enable showing of the popup when Geometry selection btn is clicked
1776   * \param enable - true to enable
1777  */
1778 //================================================================================
1779
1780 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1781
1782 void SMESHGUI_GroupDlg::updateGeomPopup()
1783 {
1784   bool enable = false;
1785
1786   if ( !myMesh->_is_nil() )
1787     enable = myMesh->NbEdges() > 0;
1788
1789   if ( myGeomGroupBtn )
1790   {
1791     disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1792     if ( enable ) {
1793       if ( !myGeomPopup ) {
1794         myGeomPopup = new QPopupMenu();
1795         myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
1796         myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
1797         connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
1798       }
1799       connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1800     }
1801   }
1802 }
1803
1804
1805 //=================================================================================
1806 // function : onGeomSelectionButton()
1807 // purpose  :
1808 //=================================================================================
1809 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1810 {
1811   if ( myGeomPopup && isBtnOn )
1812     {
1813       myCurrentLineEdit = myGeomGroupLine;
1814       int id = myGeomPopup->exec( QCursor::pos() );
1815       if (id == DIRECT_GEOM_INDEX || id == -1)
1816         setSelectionMode(7);
1817     }
1818   else if (!isBtnOn)
1819     {
1820       myCurrentLineEdit = 0;
1821       setSelectionMode(8);
1822     }
1823 }
1824
1825 //=================================================================================
1826 // function : onGeomPopup()
1827 // purpose  :
1828 //=================================================================================
1829 void SMESHGUI_GroupDlg::onGeomPopup( int index )
1830 {
1831   if ( index == GEOM_BY_MESH_INDEX )
1832     {
1833       mySelectionMode = -1;
1834       if ( !myShapeByMeshOp ) {
1835         myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1836         connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1837                 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1838         connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1839                 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1840       }
1841       // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1842       if ( !myMesh->_is_nil() ) {
1843         myIsBusy = true;
1844         hide(); // stop processing selection
1845         myIsBusy = false;
1846         myShapeByMeshOp->setModule( mySMESHGUI );
1847         myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1848         myShapeByMeshOp->SetMesh( myMesh );
1849         myShapeByMeshOp->start();
1850       }
1851     }
1852 }
1853
1854 //================================================================================
1855 /*!
1856  * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1857  */
1858 //================================================================================
1859
1860 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1861 {
1862   if ( myShapeByMeshOp == op ) {
1863     mySMESHGUI->getApp()->updateObjectBrowser();
1864     show();
1865     // Select a found geometry object
1866     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1867     if ( !aGeomVar->_is_nil() )
1868     {
1869       QString ID = aGeomVar->GetStudyEntry();
1870       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1871       if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
1872         SALOME_ListIO anIOList;
1873         Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1874           ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1875         anIOList.Append( anIO );
1876         mySelectionMgr->setSelectedObjects( anIOList, false );
1877         onObjectSelectionChanged();
1878       }
1879     }
1880   }
1881 }
1882
1883 //================================================================================
1884 /*!
1885  * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1886  */
1887 //================================================================================
1888
1889 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1890 {
1891   if ( myShapeByMeshOp == op )
1892     {
1893       show();
1894       setSelectionMode(7);
1895     }
1896 }
1897
1898 //=================================================================================
1899 // function : setGroupColor()
1900 // purpose  :
1901 //=================================================================================
1902 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
1903 {
1904   QColor aQColor( (int)( theColor.R * 255.0 ),
1905                   (int)( theColor.G * 255.0 ),
1906                   (int)( theColor.B * 255.0 ) );
1907   setGroupQColor( aQColor );
1908 }
1909
1910 //=================================================================================
1911 // function : getGroupColor()
1912 // purpose  :
1913 //=================================================================================
1914 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
1915 {
1916   QColor aQColor = getGroupQColor();
1917
1918   SALOMEDS::Color aColor;
1919   aColor.R = (float)aQColor.red() / 255.0;
1920   aColor.G = (float)aQColor.green() / 255.0;
1921   aColor.B = (float)aQColor.blue() / 255.0;
1922
1923   return aColor;
1924 }
1925
1926 //=================================================================================
1927 // function : setGroupQColor()
1928 // purpose  :
1929 //=================================================================================
1930 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
1931 {
1932   if( theColor.isValid() )
1933   {
1934     QPalette pal = myColorBtn->palette();
1935     pal.setColor(QColorGroup::Button, theColor);
1936     myColorBtn->setPalette(pal);
1937   }
1938 }
1939
1940 //=================================================================================
1941 // function : getGroupQColor()
1942 // purpose  :
1943 //=================================================================================
1944 QColor SMESHGUI_GroupDlg::getGroupQColor() const
1945 {
1946   QColor aColor = myColorBtn->palette().active().button();
1947   return aColor;
1948 }
1949
1950 //=================================================================================
1951 // function : setDefaultGroupColor()
1952 // purpose  :
1953 //=================================================================================
1954 void SMESHGUI_GroupDlg::setDefaultGroupColor()
1955 {
1956   if( myMesh->_is_nil() )
1957     return;
1958
1959   bool isAutoColor = myMesh->GetAutoColor();
1960
1961   QColor aQColor;
1962   if( !isAutoColor )
1963   {
1964     int r = 0, g = 0, b = 0;
1965     SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
1966     aQColor.setRgb( r, g, b );
1967   }
1968   else
1969   {
1970     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
1971
1972     QValueList<SALOMEDS::Color> aReservedColors;
1973     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1974     {
1975       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1976       SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
1977       aReservedColors.append( aReservedColor );
1978     }
1979
1980     SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1981     aQColor.setRgb( (int)( aColor.R * 255.0 ),
1982                     (int)( aColor.G * 255.0 ),
1983                     (int)( aColor.B * 255.0 ) );
1984
1985   }
1986
1987   setGroupQColor( aQColor );
1988 }