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