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