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