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