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