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