Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupDlg.cxx
1 // Copyright (C) 2007-2011  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   updateButtons();
1407 }
1408
1409 //=================================================================================
1410 // function : onSelectSubMesh()
1411 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1412 //=================================================================================
1413 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1414 {
1415   if (on) {
1416     if (mySelectGroup->isChecked()) {
1417       mySelectGroup->setChecked(false);
1418     }
1419     //VSR: else if (mySelectGeomGroup->isChecked()) {
1420     //VSR:   mySelectGeomGroup->setChecked(false);
1421     //VSR: }
1422     myCurrentLineEdit = mySubMeshLine;
1423     setSelectionMode(grpSubMeshSelection);
1424   }
1425   else {
1426     mySubMeshLine->setText( "" );
1427     myCurrentLineEdit = 0;
1428     if (myTypeId != -1)
1429       setSelectionMode(myTypeId);
1430   }
1431   mySubMeshBtn->setEnabled(on);
1432   mySubMeshLine->setEnabled(on);
1433 }
1434
1435
1436 //=================================================================================
1437 // function : (onSelectGroup)
1438 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1439 //=================================================================================
1440 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1441 {
1442   if (on) {
1443     if (mySelectSubMesh->isChecked()) {
1444       mySelectSubMesh->setChecked(false);
1445     }
1446     myCurrentLineEdit = myGroupLine;
1447     setSelectionMode(grpGroupSelection);
1448   }
1449   else {
1450     myGroupLine->setText( "" );
1451     myCurrentLineEdit = 0;
1452     if (myTypeId != -1)
1453       setSelectionMode(myTypeId);
1454   }
1455   myGroupBtn->setEnabled(on);
1456   myGroupLine->setEnabled(on);
1457 }
1458
1459
1460 //=================================================================================
1461 // function : (onSelectGeomGroup)
1462 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1463 //=================================================================================
1464 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1465 {
1466   if (on) {
1467     if (mySelectSubMesh->isChecked()) {
1468       mySelectSubMesh->setChecked(false);
1469     }
1470     else if (mySelectGroup->isChecked()) {
1471       mySelectGroup->setChecked(false);
1472     }
1473     myCurrentLineEdit = myGeomGroupLine;
1474     updateGeomPopup();
1475     setSelectionMode(grpAllSelection);
1476   }
1477   else {
1478     myGeomGroupBtn->setChecked(false);
1479     myGeomObjects->length(0);
1480     myGeomGroupLine->setText( "" );
1481     myCurrentLineEdit = 0;
1482     if (myTypeId != -1)
1483       setSelectionMode(myTypeId);
1484   }
1485 }
1486
1487
1488 //=================================================================================
1489 // function : setCurrentSelection()
1490 // purpose  :
1491 //=================================================================================
1492 void SMESHGUI_GroupDlg::setCurrentSelection()
1493 {
1494   QPushButton* send = (QPushButton*)sender();
1495   myCurrentLineEdit = 0;
1496   if (send == myMeshGroupBtn) {
1497     disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1498     mySelectionMgr->clearSelected();
1499     if (myCreate)
1500       setSelectionMode(grpMeshSelection);
1501     else
1502       setSelectionMode(grpGroupSelection);
1503     connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
1504     myCurrentLineEdit = myMeshGroupLine;
1505     onObjectSelectionChanged();
1506   }
1507   else if (send == mySubMeshBtn) {
1508     myCurrentLineEdit = mySubMeshLine;
1509     onObjectSelectionChanged();
1510   }
1511   else if (send == myGroupBtn) {
1512     myCurrentLineEdit = myGroupLine;
1513     onObjectSelectionChanged();
1514   }
1515 }
1516
1517
1518 //=================================================================================
1519 // function : setFilters()
1520 // purpose  : SLOT. Called when "Filter" button pressed.
1521 //=================================================================================
1522 void SMESHGUI_GroupDlg::setFilters()
1523 {
1524   if(myMesh->_is_nil()) {
1525     SUIT_MessageBox::critical(this,
1526                               tr("SMESH_ERROR"),
1527                               tr("NO_MESH_SELECTED"));
1528    return;
1529   }
1530
1531   SMESH::ElementType aType = SMESH::ALL;
1532   switch ( myTypeId )
1533   {
1534     case 0 : aType = SMESH::NODE; break;
1535     case 1 : aType = SMESH::EDGE; break;
1536     case 2 : aType = SMESH::FACE; break;
1537     case 3 : aType = SMESH::VOLUME; break;
1538     default: return;
1539   }
1540
1541   if ( myFilterDlg == 0 )
1542   {
1543     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1544     connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1545   }
1546   else
1547     myFilterDlg->Init( aType );
1548
1549   myFilterDlg->SetSelection();
1550   myFilterDlg->SetMesh( myMesh );
1551   myFilterDlg->SetSourceWg( myElements, false );
1552
1553   myFilterDlg->show();
1554 }
1555
1556 //=================================================================================
1557 // function : onFilterAccepted()
1558 // purpose  : SLOT. Called when Filter dlg closed with OK button.
1559 //            Uncheck "Select submesh" and "Select group" checkboxes
1560 //=================================================================================
1561 void SMESHGUI_GroupDlg::onFilterAccepted()
1562 {
1563   if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1564   {
1565     mySelectionMode = myTypeId;
1566     mySelectSubMesh->setChecked( false );
1567     mySelectGroup->setChecked( false );
1568   }
1569 }
1570
1571 //=================================================================================
1572 // function : onAdd()
1573 // purpose  :
1574 //=================================================================================
1575 void SMESHGUI_GroupDlg::onAdd()
1576 {
1577   SALOME_ListIO aList;
1578   mySelectionMgr->selectedObjects( aList );
1579
1580   int aNbSel = aList.Extent();
1581
1582   if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
1583
1584   myIsBusy = true;
1585
1586   SMESH::ElementType aType = SMESH::ALL;
1587   switch(myTypeId) {
1588   case 0:
1589     aType = SMESH::NODE;
1590     mySelector->SetSelectionMode(NodeSelection);
1591     break;
1592   case 1:
1593     aType = SMESH::EDGE;
1594     mySelector->SetSelectionMode(EdgeSelection);
1595     break;
1596   case 2:
1597     aType = SMESH::FACE;
1598     mySelector->SetSelectionMode(FaceSelection);
1599     break;
1600   case 3:
1601     aType = SMESH::VOLUME;
1602     mySelector->SetSelectionMode(VolumeSelection);
1603     break;
1604   default:
1605     mySelector->SetSelectionMode(ActorSelection);
1606   }
1607
1608   QListWidgetItem* anItem = 0;
1609   QList<QListWidgetItem*> listItemsToSel;
1610
1611   if (myCurrentLineEdit == 0) {
1612     //if (aNbSel != 1) { myIsBusy = false; return; }
1613     QString aListStr = "";
1614     int aNbItems = 0;
1615     if (myTypeId == 0) {
1616       QListIterator<SMESH_Actor*> it( myActorsList );
1617       while ( it.hasNext() ) {
1618         QString tmpStr;
1619         aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
1620         aListStr += tmpStr;
1621       }
1622     }
1623     else {
1624       QListIterator<SMESH_Actor*> it( myActorsList );
1625       while ( it.hasNext() ) {
1626         QString tmpStr;
1627         aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
1628         aListStr += tmpStr;
1629       }
1630     }
1631     if (aNbItems > 0) {
1632       QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
1633       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1634         QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
1635         if (found.count() == 0) {
1636           anItem = new QListWidgetItem(*it);
1637           myElements->addItem(anItem);
1638           if (!anItem->isSelected())
1639             listItemsToSel.push_back(anItem);
1640         }
1641         else {
1642           foreach(anItem, found)
1643             if (!anItem->isSelected())
1644               listItemsToSel.push_back(anItem);
1645         }
1646       }
1647       bool blocked = myElements->signalsBlocked();
1648       myElements->blockSignals(true);
1649       foreach(anItem, listItemsToSel) anItem->setSelected(true);
1650       myElements->blockSignals(blocked);
1651       onListSelectionChanged();
1652       listItemsToSel.clear();
1653     }
1654   } else if (myCurrentLineEdit == mySubMeshLine) {
1655     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1656
1657     SALOME_ListIO aList;
1658     mySelectionMgr->selectedObjects( aList );
1659
1660     SALOME_ListIteratorOfListIO anIt (aList);
1661     for ( ; anIt.More(); anIt.Next()) {
1662       SMESH::SMESH_subMesh_var aSubMesh =
1663         SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1664       if (!aSubMesh->_is_nil()) {
1665         // check if mesh is the same
1666         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1667           try {
1668             SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1669             int k = anElements->length();
1670             for (int i = 0; i < k; i++) {
1671               QString aText = QString::number(anElements[i]);
1672               QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1673               if (found.count() == 0) {
1674                 anItem = new QListWidgetItem(aText);
1675                 myElements->addItem(anItem);
1676                 if (!anItem->isSelected())
1677                   listItemsToSel.push_back(anItem);
1678               }
1679               else {
1680                 foreach(anItem, found)
1681                   if (!anItem->isSelected())
1682                     listItemsToSel.push_back(anItem);
1683               }
1684             }
1685             bool blocked = myElements->signalsBlocked();
1686             myElements->blockSignals(true);
1687             foreach(anItem, listItemsToSel) anItem->setSelected(true);
1688             myElements->blockSignals(blocked);
1689             onListSelectionChanged();
1690             listItemsToSel.clear();
1691           }
1692           catch (const SALOME::SALOME_Exception& ex) {
1693             SalomeApp_Tools::QtCatchCorbaException(ex);
1694           }
1695         }
1696       }
1697     }
1698     mySelectSubMesh->setChecked(false);
1699     myIsBusy = false;
1700     onListSelectionChanged();
1701
1702   } else if (myCurrentLineEdit == myGroupLine) {
1703     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1704     SALOME_ListIO aList;
1705     mySelectionMgr->selectedObjects( aList );
1706
1707     SALOME_ListIteratorOfListIO anIt (aList);
1708     for ( ; anIt.More(); anIt.Next()) {
1709       SMESH::SMESH_GroupBase_var aGroup =
1710         SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
1711       if (!aGroup->_is_nil()) {
1712         // check if mesh is the same
1713         if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1714           SMESH::long_array_var anElements = aGroup->GetListOfID();
1715           int k = anElements->length();
1716           for (int i = 0; i < k; i++) {
1717             QString aText = QString::number(anElements[i]);
1718             QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1719             if (found.count() == 0) {
1720               anItem = new QListWidgetItem(aText);
1721               myElements->addItem(anItem);
1722               if (!anItem->isSelected())
1723                 listItemsToSel.push_back(anItem);
1724             }
1725             else {
1726               foreach(anItem, found)
1727                 if (!anItem->isSelected())
1728                   listItemsToSel.push_back(anItem);
1729             }
1730           }
1731           bool blocked = myElements->signalsBlocked();
1732           myElements->blockSignals(true);
1733           foreach(anItem, listItemsToSel) anItem->setSelected(true);
1734           myElements->blockSignals(blocked);
1735           onListSelectionChanged();
1736           listItemsToSel.clear();
1737         }
1738       }
1739     }
1740     mySelectGroup->setChecked(false);
1741     myIsBusy = false;
1742     onListSelectionChanged();
1743
1744   } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1745     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1746     GEOM::GEOM_IGroupOperations_var aGroupOp =
1747       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1748
1749     SMESH::ElementType aGroupType = SMESH::ALL;
1750     switch(aGroupOp->GetType(myGeomObjects[0])) {
1751     case 7: aGroupType = SMESH::NODE; break;
1752     case 6: aGroupType = SMESH::EDGE; break;
1753     case 4: aGroupType = SMESH::FACE; break;
1754     case 2: aGroupType = SMESH::VOLUME; break;
1755     default: myIsBusy = false; return;
1756     }
1757
1758     if (aGroupType == aType) {
1759       _PTR(SObject) aGroupSO =
1760         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1761         aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1762       // Construct filter
1763       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1764       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1765       SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1766       aBelongToGeom->SetGeom(myGeomObjects[0]);
1767       aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1768       aBelongToGeom->SetElementType(aType);
1769       aFilter->SetPredicate(aBelongToGeom);
1770
1771       SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1772
1773       int k = anElements->length();
1774       for (int i = 0; i < k; i++) {
1775         QString aText = QString::number(anElements[i]);
1776         QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
1777         if (found.count() == 0) {
1778           anItem = new QListWidgetItem(aText);
1779           myElements->addItem(anItem);
1780           if (!anItem->isSelected())
1781             listItemsToSel.push_back(anItem);
1782         }
1783         else {
1784           foreach(anItem, found)
1785             if (!anItem->isSelected())
1786               listItemsToSel.push_back(anItem);
1787         }
1788       }
1789       bool blocked = myElements->signalsBlocked();
1790       myElements->blockSignals(true);
1791       foreach(anItem, listItemsToSel) anItem->setSelected(true);
1792       myElements->blockSignals(blocked);
1793       onListSelectionChanged();
1794       listItemsToSel.clear();
1795     }
1796
1797     //VSR: mySelectGeomGroup->setChecked(false);
1798     myIsBusy = false;
1799     onListSelectionChanged();
1800   }
1801   myIsBusy = false;
1802   //  mySelectionMgr->clearSelected();
1803   updateButtons();
1804 }
1805
1806 //=================================================================================
1807 // function : onRemove()
1808 // purpose  :
1809 //=================================================================================
1810 void SMESHGUI_GroupDlg::onRemove()
1811 {
1812   myIsBusy = true;
1813   if (myCurrentLineEdit == 0) {
1814     QList<QListWidgetItem*> selItems = myElements->selectedItems();
1815     QListWidgetItem* item;
1816     foreach(item, selItems) delete item;
1817   } else {
1818     SALOME_ListIO aList;
1819     mySelectionMgr->selectedObjects( aList );
1820
1821     int aNbSel = aList.Extent();
1822
1823     if (aNbSel == 0) { myIsBusy = false; return; }
1824
1825     SMESH::ElementType aType = SMESH::ALL;
1826     switch(myTypeId) {
1827     case 0: aType = SMESH::NODE; break;
1828     case 1: aType = SMESH::EDGE; break;
1829     case 2: aType = SMESH::FACE; break;
1830     case 3: aType = SMESH::VOLUME; break;
1831     }
1832
1833     if (myCurrentLineEdit == mySubMeshLine) {
1834       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1835       SALOME_ListIO aList;
1836       mySelectionMgr->selectedObjects( aList );
1837
1838       SALOME_ListIteratorOfListIO anIt (aList);
1839       for ( ; anIt.More(); anIt.Next()) {
1840         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1841         if (!aSubMesh->_is_nil()) {
1842           // check if mesh is the same
1843           if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1844             if (aType == SMESH::NODE) {
1845               try {
1846                 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1847                 int k = anElements->length();
1848                 for (int i = 0; i < k; i++) {
1849                   QList<QListWidgetItem*> found = 
1850                     myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1851                   QListWidgetItem* anItem;
1852                   foreach(anItem, found) delete anItem;
1853                 }
1854               }
1855               catch (const SALOME::SALOME_Exception& ex) {
1856                 SalomeApp_Tools::QtCatchCorbaException(ex);
1857               }
1858             }
1859             else {
1860               try {
1861                 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1862                 int k = anElements->length();
1863                 for (int i = 0; i < k; i++) {
1864                   QList<QListWidgetItem*> found = 
1865                     myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1866                   QListWidgetItem* anItem;
1867                   foreach(anItem, found) delete anItem;
1868                 }
1869               }
1870               catch (const SALOME::SALOME_Exception& ex) {
1871                 SalomeApp_Tools::QtCatchCorbaException(ex);
1872               }
1873             }
1874           }
1875         }
1876       }
1877     }
1878     else if (myCurrentLineEdit == myGroupLine) {
1879       Standard_Boolean aRes;
1880       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1881       SALOME_ListIO aList;
1882       mySelectionMgr->selectedObjects( aList );
1883
1884       SALOME_ListIteratorOfListIO anIt (aList);
1885       for ( ; anIt.More(); anIt.Next()) {
1886         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1887         if (aRes && !aGroup->_is_nil()) {
1888           // check if mesh is the same
1889           if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1890             SMESH::long_array_var anElements = aGroup->GetListOfID();
1891             int k = anElements->length();
1892             for (int i = 0; i < k; i++) {
1893               QList<QListWidgetItem*> found = 
1894                 myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
1895               QListWidgetItem* anItem;
1896               foreach(anItem, found) delete anItem;
1897             }
1898           }
1899         }
1900       }
1901     }
1902   }
1903   myIsBusy = false;
1904   updateButtons();
1905 }
1906
1907 //=================================================================================
1908 // function : onSort()
1909 // purpose  :
1910 //=================================================================================
1911 void SMESHGUI_GroupDlg::onSort()
1912 {
1913   // PAL5412: sorts items in ascending by "string" value
1914   // myElements->sort(true);
1915   // myElements->update();
1916   int i, k = myElements->count();
1917   if (k > 0) {
1918     myIsBusy = true;
1919     QList<int> aSelected;
1920     std::vector<int> anArray(k);
1921     //    QMemArray<int> anArray(k);
1922     // fill the array
1923     for (i = 0; i < k; i++) {
1924       int id = myElements->item(i)->text().toInt();
1925       anArray[i] = id;
1926       if (myElements->item(i)->isSelected())
1927         aSelected.append(id);
1928     }
1929     // sort & update list
1930     std::sort(anArray.begin(), anArray.end());
1931     //    anArray.sort();
1932     myElements->clear();
1933     QListWidgetItem* anItem;
1934     QList<QListWidgetItem*> listItemsToSel;
1935     for (i = 0; i < k; i++) {
1936       anItem = new QListWidgetItem(QString::number(anArray[i]));
1937       myElements->addItem(anItem);
1938       if (aSelected.contains(anArray[i]))
1939         listItemsToSel.push_back(anItem);
1940     }
1941     bool blocked = myElements->signalsBlocked();
1942     myElements->blockSignals(true);
1943     foreach(anItem, listItemsToSel) anItem->setSelected(true);
1944     myElements->blockSignals(blocked);
1945     listItemsToSel.clear();
1946     myIsBusy = false;
1947   }
1948 }
1949
1950 //=================================================================================
1951 // function : closeEvent()
1952 // purpose  :
1953 //=================================================================================
1954 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1955 {
1956   onClose();
1957 }
1958
1959 //=================================================================================
1960 // function : onVisibilityChanged()
1961 // purpose  :
1962 //=================================================================================
1963 void SMESHGUI_GroupDlg::onVisibilityChanged()
1964 {
1965   SetAppropriateActor();
1966 }
1967
1968 //=================================================================================
1969 // function : SMESHGUI_GroupDlg::onClose
1970 // purpose  : SLOT called when "Close" button pressed. Close dialog
1971 //=================================================================================
1972 void SMESHGUI_GroupDlg::onClose()
1973 {
1974   if (SMESH::GetCurrentVtkView()) {
1975     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1976     SMESH::SetPointRepresentation(false);
1977     SMESH::SetPickable();
1978     restoreShowEntityMode();
1979   }
1980
1981   if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
1982     SUIT_DataOwnerPtrList aList;
1983     aList.append( new LightApp_DataOwner( myObjectToSelect ) );
1984     mySelectionMgr->setSelected( aList );
1985   }
1986   else
1987     mySelectionMgr->clearSelected();
1988   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1989     aViewWindow->SetSelectionMode(ActorSelection);
1990   mySelectionMgr->clearFilters();
1991   mySMESHGUI->ResetState();
1992
1993   reject();
1994 }
1995
1996 //=================================================================================
1997 // function : onHelp()
1998 // purpose  :
1999 //=================================================================================
2000 void SMESHGUI_GroupDlg::onHelp()
2001 {
2002   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2003   if (app)
2004     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString( "" ), myHelpFileName);
2005   else {
2006     QString platform;
2007 #ifdef WIN32
2008     platform = "winapplication";
2009 #else
2010     platform = "application";
2011 #endif
2012     SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
2013                              tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
2014                              arg(app->resourceMgr()->stringValue( "ExternalBrowser",
2015                                                                  platform)).
2016                              arg(myHelpFileName));
2017   }
2018 }
2019
2020 //=================================================================================
2021 // function : SMESHGUI_GroupDlg::onDeactivate
2022 // purpose  : SLOT called when dialog must be deativated
2023 //=================================================================================
2024 void SMESHGUI_GroupDlg::onDeactivate()
2025 {
2026   mySMESHGUI->ResetState();
2027   setEnabled(false);
2028 }
2029
2030 //=================================================================================
2031 // function : SMESHGUI_GroupDlg::enterEvent
2032 // purpose  : Event filter
2033 //=================================================================================
2034 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
2035 {
2036   if (!isEnabled()) {
2037     mySMESHGUI->EmitSignalDeactivateDialog();
2038     setEnabled(true);
2039     mySelectionMode = grpNoSelection;
2040     setSelectionMode(myTypeId);
2041     //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2042     mySMESHGUI->SetActiveDialogBox(this);
2043     mySMESHGUI->SetState(800);
2044   }
2045 }
2046
2047 //=================================================================================
2048 // function : hideEvent
2049 // purpose  : caused by ESC key
2050 //=================================================================================
2051 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
2052 {
2053   if (!isMinimized() && !myIsBusy)
2054     onClose();
2055 }
2056
2057 //=================================================================================
2058 // function : keyPressEvent()
2059 // purpose  :
2060 //=================================================================================
2061 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
2062 {
2063   QDialog::keyPressEvent( e );
2064   if ( e->isAccepted() )
2065     return;
2066
2067   if ( e->key() == Qt::Key_F1 )
2068     {
2069       e->accept();
2070       onHelp();
2071     }
2072 }
2073
2074 //================================================================================
2075 /*!
2076  * \brief Enable showing of the popup when Geometry selection btn is clicked
2077   * \param enable - true to enable
2078  */
2079 //================================================================================
2080
2081 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
2082
2083 void SMESHGUI_GroupDlg::updateGeomPopup()
2084 {
2085   bool enable = false;
2086
2087   if ( !myMesh->_is_nil() )
2088     enable = myMesh->NbEdges() > 0;
2089
2090   if ( myGeomGroupBtn )
2091   {
2092     disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2093     if ( enable ) {
2094       if ( !myGeomPopup ) {
2095         myGeomPopup = new QMenu(this);
2096         myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
2097         myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
2098         connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
2099       }
2100       connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
2101     }
2102   }
2103 }
2104
2105
2106 //=================================================================================
2107 // function : onGeomSelectionButton()
2108 // purpose  :
2109 //=================================================================================
2110 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
2111 {
2112   if ( myGeomPopup && isBtnOn )
2113     {
2114       myCurrentLineEdit = myGeomGroupLine;
2115       QAction* a = myGeomPopup->exec( QCursor::pos() );
2116       if (!a || myActions[a] == DIRECT_GEOM_INDEX)
2117         setSelectionMode(grpGeomSelection);
2118     }
2119   else if (!isBtnOn)
2120     {
2121       myCurrentLineEdit = 0;
2122       setSelectionMode(grpAllSelection);
2123     }
2124 }
2125
2126 //=================================================================================
2127 // function : onGeomPopup()
2128 // purpose  :
2129 //=================================================================================
2130 void SMESHGUI_GroupDlg::onGeomPopup( QAction* a )
2131 {
2132   int index = myActions[a];
2133   if ( index == GEOM_BY_MESH_INDEX )
2134     {
2135       mySelectionMode = grpNoSelection;
2136       if ( !myShapeByMeshOp ) {
2137         myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
2138         connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
2139                 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
2140         connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
2141                 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
2142       }
2143       // set mesh object to SMESHGUI_ShapeByMeshOp and start it
2144       if ( !myMesh->_is_nil() ) {
2145         myIsBusy = true;
2146         hide(); // stop processing selection
2147         myIsBusy = false;
2148         myShapeByMeshOp->setModule( mySMESHGUI );
2149         myShapeByMeshOp->setStudy( 0 ); // it's really necessary
2150         myShapeByMeshOp->SetMesh( myMesh );
2151         myShapeByMeshOp->start();
2152       }
2153     }
2154 }
2155
2156 //================================================================================
2157 /*!
2158  * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
2159  */
2160 //================================================================================
2161
2162 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
2163 {
2164   if ( myShapeByMeshOp == op ) {
2165     mySMESHGUI->getApp()->updateObjectBrowser();
2166     show();
2167     // Select a found geometry object
2168     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
2169     if ( !aGeomVar->_is_nil() )
2170     {
2171       QString ID = aGeomVar->GetStudyEntry();
2172       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
2173       if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.toLatin1().data() )) {
2174         SALOME_ListIO anIOList;
2175         Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
2176           ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
2177         anIOList.Append( anIO );
2178         mySelectionMgr->setSelectedObjects( anIOList, false );
2179         onObjectSelectionChanged();
2180       }
2181     }
2182   }
2183 }
2184
2185 //================================================================================
2186 /*!
2187  * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
2188  */
2189 //================================================================================
2190
2191 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
2192 {
2193   if ( myShapeByMeshOp == op )
2194     {
2195       show();
2196       setSelectionMode(grpGeomSelection);
2197     }
2198 }
2199
2200 //=================================================================================
2201 // function : setGroupColor()
2202 // purpose  :
2203 //=================================================================================
2204 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
2205 {
2206   QColor aQColor( (int)( theColor.R * 255.0 ),
2207                   (int)( theColor.G * 255.0 ),
2208                   (int)( theColor.B * 255.0 ) );
2209   setGroupQColor( aQColor );
2210 }
2211
2212 //=================================================================================
2213 // function : getGroupColor()
2214 // purpose  :
2215 //=================================================================================
2216 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
2217 {
2218   QColor aQColor = getGroupQColor();
2219
2220   SALOMEDS::Color aColor;
2221   aColor.R = (float)aQColor.red() / 255.0;
2222   aColor.G = (float)aQColor.green() / 255.0;
2223   aColor.B = (float)aQColor.blue() / 255.0;
2224
2225   return aColor;
2226 }
2227
2228 //=================================================================================
2229 // function : setGroupQColor()
2230 // purpose  :
2231 //=================================================================================
2232 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
2233 {
2234   if( theColor.isValid() )
2235     myColorBtn->setColor( theColor );
2236 }
2237
2238 //=================================================================================
2239 // function : getGroupQColor()
2240 // purpose  :
2241 //=================================================================================
2242 QColor SMESHGUI_GroupDlg::getGroupQColor() const
2243 {
2244   return myColorBtn->color();
2245 }
2246
2247 //=================================================================================
2248 // function : setDefaultGroupColor()
2249 // purpose  :
2250 //=================================================================================
2251 void SMESHGUI_GroupDlg::setDefaultGroupColor()
2252 {
2253   if( myMesh->_is_nil() )
2254     return;
2255
2256   bool isAutoColor = myMesh->GetAutoColor();
2257
2258   QColor aQColor;
2259   if( !isAutoColor )
2260   {
2261     int r = 0, g = 0, b = 0;
2262     SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
2263     aQColor.setRgb( r, g, b );
2264   }
2265   else
2266   {
2267     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
2268
2269     QList<SALOMEDS::Color> aReservedColors;
2270     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
2271     {
2272       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
2273       SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
2274       aReservedColors.append( aReservedColor );
2275     }
2276
2277     SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
2278     aQColor.setRgb( (int)( aColor.R * 255.0 ),
2279                     (int)( aColor.G * 255.0 ),
2280                     (int)( aColor.B * 255.0 ) );
2281
2282   }
2283
2284   setGroupQColor( aQColor );
2285 }
2286
2287 //=================================================================================
2288 // function : SetAppropriateActor()
2289 // purpose  : Find more appropriate of visible actors, set it to myActor, allow picking
2290 //            NPAL19389: create a group with a selection in another group.
2291 //            if mesh actor is not visible - find any first visible group or submesh
2292 //=================================================================================
2293 bool SMESHGUI_GroupDlg::SetAppropriateActor()
2294 {
2295   bool isActor = false;
2296   myActorsList.clear();
2297
2298   if (myMesh->_is_nil()) return false;
2299
2300   SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2301
2302   if (myGeomGroupBtn->isChecked()) {   // try current group on geometry actor
2303     if (!isActor) {
2304       if (!myGroupOnGeom->_is_nil()) {
2305         SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
2306         if (anActor && anActor->hasIO())
2307           {
2308             isActor = true;
2309             if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2310               isActor = false;
2311             else
2312               myActorsList.append(anActor);
2313           }
2314       }
2315     }
2316   } else {
2317     // try mesh actor
2318     SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2319     if (anActor && anActor->hasIO()) {
2320       isActor = true;
2321       if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
2322         isActor = false;
2323       else
2324         myActorsList.append(anActor);
2325     }
2326     
2327     // try group actor
2328     if (!isActor && !myGroup->_is_nil()) {
2329       SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
2330       if (anActor && anActor->hasIO())
2331         myActorsList.append(anActor);
2332     }
2333     
2334     // try any visible actor of group or submesh of current mesh
2335     if (aViewWindow) {
2336       // mesh entry
2337       _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
2338       if (aSObject) {
2339         CORBA::String_var meshEntry = aSObject->GetID().c_str();
2340         int len = strlen(meshEntry);
2341         
2342         // iterate on all actors in current view window, search for
2343         // any visible actor, that belongs to group or submesh of current mesh
2344         VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
2345         vtkActorCollection *aCollection = aCopy.GetActors();
2346         int nbItems = aCollection->GetNumberOfItems();
2347         for (int i=0; i<nbItems && !isActor; i++)
2348           {
2349             SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
2350             if (anActor && anActor->hasIO()) {
2351               Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2352               if (aViewWindow->isVisible(anIO)) {
2353                 if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
2354                   myActorsList.append(anActor);
2355               }
2356             }
2357           }
2358       }
2359     }
2360   }
2361   
2362   if (myActorsList.count() > 0) {
2363     QListIterator<SMESH_Actor*> it( myActorsList );
2364     while ( it.hasNext() ) {
2365       SMESH_Actor* anActor = it.next();
2366       if ( IsActorVisible(anActor) )
2367         anActor->SetPickable(true);
2368     }
2369   }
2370   
2371   return ( isActor || (myActorsList.count() > 0) );
2372 }
2373   
2374 //=======================================================================
2375 //function : setShowEntityMode
2376 //purpose  : make shown only entity corresponding to my type
2377 //=======================================================================
2378 void SMESHGUI_GroupDlg::setShowEntityMode()
2379 {
2380   if ( !myMesh->_is_nil() ) {
2381     if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2382       if (!myStoredShownEntity)
2383         myStoredShownEntity = actor->GetEntityMode();
2384       switch ( myTypeId ) {
2385       case 0: restoreShowEntityMode(); break;
2386       case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2387       case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2388       case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2389       }
2390     }
2391   }
2392 }
2393
2394 //=======================================================================
2395 //function : restoreShowEntityMode
2396 //purpose  : restore ShowEntity mode of myActor
2397 //=======================================================================
2398 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2399 {
2400   if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2401     if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2402       actor->SetEntityMode(myStoredShownEntity);
2403     }
2404   }
2405   myStoredShownEntity = 0;
2406 }
2407
2408 //=======================================================================
2409 //function : IsActorVisible
2410 //purpose  : return visibility of the actor
2411 //=======================================================================
2412 bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
2413 {
2414   SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
2415   if (theActor && aViewWindow)
2416     return aViewWindow->isVisible(theActor->getIO());
2417   return false;
2418 }
2419
2420 //================================================================
2421 //function : setIsApplyAndClose
2422 //purpose  : Set value of the flag indicating that the dialog is
2423 //           accepted by Apply & Close button
2424 //================================================================
2425 void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
2426 {
2427   myIsApplyAndClose = theFlag;
2428 }
2429
2430 //================================================================
2431 //function : isApplyAndClose
2432 //purpose  : Get value of the flag indicating that the dialog is
2433 //           accepted by Apply & Close button
2434 //================================================================
2435 bool SMESHGUI_GroupDlg::isApplyAndClose() const
2436 {
2437   return myIsApplyAndClose;
2438 }