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