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