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