Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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 //
24 //  File   : SMESHGUI_GroupDlg.cxx
25 //  Author : Natalia KOPNOVA
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESHGUI_GroupDlg.h"
30 #include "SMESHGUI_FilterDlg.h"
31
32 #include "SMESHGUI.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_GroupUtils.h"
37 #include "SMESHGUI_FilterUtils.h"
38 #include "SMESHGUI_GEOMGenUtils.h"
39
40 #include "SMESH_TypeFilter.hxx"
41 #include "SMESH_Actor.h"
42 #include "GEOMBase.h"
43
44 #include "SUIT_Desktop.h"
45 #include "SUIT_ResourceMgr.h"
46 #include "SUIT_Session.h"
47 #include "SUIT_MessageBox.h"
48
49 #include "SalomeApp_Tools.h"
50 #include "LightApp_Application.h"
51 #include "SALOMEDSClient_Study.hxx"
52 #include "SALOME_ListIO.hxx"
53 #include "SALOME_ListIteratorOfListIO.hxx"
54
55 #include "SVTK_ViewWindow.h"
56 #include "SVTK_Selector.h"
57
58 #include "utilities.h"
59
60 // OCCT Includes
61 #include <TColStd_MapOfInteger.hxx>
62
63 // QT Includes
64 #include <qbuttongroup.h>
65 #include <qgroupbox.h>
66 #include <qhbox.h>
67 #include <qlabel.h>
68 #include <qlineedit.h>
69 #include <qpushbutton.h>
70 #include <qradiobutton.h>
71 #include <qcheckbox.h>
72 #include <qlayout.h>
73 #include <qlistbox.h>
74 #include <qimage.h>
75 #include <qpixmap.h>
76 #include <qmemarray.h>
77 #include <qwidgetstack.h>
78
79 #include <QtxIntSpinBox.h>
80
81 // STL includes
82 #include <vector>
83 #include <algorithm>
84
85 using namespace std;
86
87 //=================================================================================
88 // function : SMESHGUI_GroupDlg()
89 // purpose  :
90 //=================================================================================
91 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
92                                       SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl)
93      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
94                 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
95      mySMESHGUI( theModule ),
96      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
97      mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
98      myIsBusy( false ),
99      myActor( 0 )
100 {
101   if (!name) setName("SMESHGUI_GroupDlg");
102   initDialog(true);
103   if (!theMesh->_is_nil())
104     init(theMesh);
105   else {
106     mySelectSubMesh->setEnabled(false);
107     mySelectGroup->setEnabled(false);
108     myGeomGroupBtn->setEnabled(false);
109     myGeomGroupLine->setEnabled(false);
110   }
111 }
112
113 //=================================================================================
114 // function : SMESHGUI_GroupDlg()
115 // purpose  :
116 //=================================================================================
117 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
118                                       SMESH::SMESH_GroupBase_ptr theGroup, bool modal, WFlags fl)
119      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
120                 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
121      mySMESHGUI( theModule ),
122      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
123      mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
124      myIsBusy( false )
125 {
126   if (!name) setName("SMESHGUI_GroupDlg");
127
128   initDialog(false);
129   if (!theGroup->_is_nil())
130     init(theGroup);
131   else {
132     mySelectSubMesh->setEnabled(false);
133     mySelectGroup->setEnabled(false);
134
135     myCurrentLineEdit = myMeshGroupLine;
136     setSelectionMode(5);
137   }
138 }
139
140 //=================================================================================
141 // function : SMESHGUI_GroupDlg()
142 // purpose  :
143 //=================================================================================
144 void SMESHGUI_GroupDlg::initDialog(bool create)
145 {
146   myFilterDlg = 0;
147   myCreate = create;
148   myCurrentLineEdit = 0;
149
150   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
151
152   if (create) {
153     setCaption(tr("SMESH_CREATE_GROUP_TITLE"));
154     myHelpFileName = "/files/creating_groups.htm";
155   }
156   else {
157     setCaption(tr("SMESH_EDIT_GROUP_TITLE"));
158     myHelpFileName = "/files/editing_groups.htm";
159   }
160
161   setSizeGripEnabled(TRUE);
162
163   QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
164
165   /***************************************************************/
166   QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
167   if (create)
168     meshGroupLab->setText(tr("SMESH_MESH"));
169   else
170     meshGroupLab->setText(tr("SMESH_GROUP"));
171   myMeshGroupBtn = new QPushButton(this, "mesh/group button");
172   myMeshGroupBtn->setPixmap(image0);
173   myMeshGroupLine = new QLineEdit(this, "mesh/group line");
174   myMeshGroupLine->setReadOnly(true);
175
176   /***************************************************************/
177   myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
178   myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
179   myTypeGroup->setExclusive(true);
180
181   QStringList types;
182   types.append(tr("MESH_NODE"));
183   types.append(tr("SMESH_EDGE"));
184   types.append(tr("SMESH_FACE"));
185   types.append(tr("SMESH_VOLUME"));
186   QRadioButton* rb;
187   for (int i = 0; i < types.count(); i++) {
188     rb = new QRadioButton(types[i], myTypeGroup);
189   }
190   myTypeGroup->setEnabled(create);
191   myTypeId = -1;
192
193   /***************************************************************/
194   QLabel* aName = new QLabel(this, "name label");
195   aName->setText(tr("SMESH_NAME"));
196   aName->setMinimumSize(50,0);
197   myName = new QLineEdit(this, "name");
198
199   /***************************************************************/
200   myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
201   myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
202   myGrpTypeGroup->setExclusive(true);
203   QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
204   QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"),   myGrpTypeGroup);
205   myGrpTypeGroup->setEnabled(create);
206   myGrpTypeId = -1;
207
208   /***************************************************************/
209   myWGStack = new QWidgetStack( this, "widget stack");
210   QWidget* wg1 = new QFrame( myWGStack, "first widget" );
211   QWidget* wg2 = new QFrame( myWGStack, "second widget" );
212
213   /***************************************************************/
214   QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
215   aContentBox->setTitle(tr("SMESH_CONTENT"));
216   QFrame* aContent = new QFrame(aContentBox, "content");
217   QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
218   aLayout->setSpacing(6);
219   aLayout->setAutoAdd(false);
220
221   QLabel* aLabel = new QLabel(aContent, "elements label");
222   aLabel->setText(tr("SMESH_ID_ELEMENTS"));
223   myElements = new QListBox(aContent, "elements list");
224   myElements->setSelectionMode(QListBox::Extended);
225
226   myFilter = new QPushButton(aContent, "filter");
227   myFilter->setText(tr("SMESH_BUT_FILTER"));
228   QPushButton* aAddBtn = new QPushButton(aContent, "add");
229   aAddBtn->setText(tr("SMESH_BUT_ADD"));
230   QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
231   aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
232   QPushButton* aSortBtn = new QPushButton(aContent, "sort");
233   aSortBtn->setText(tr("SMESH_BUT_SORT"));
234
235   aLayout->addWidget(aLabel, 0, 0);
236   aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
237   aLayout->addWidget(myFilter, 1, 2);
238   aLayout->addWidget(aAddBtn, 3, 2);
239   aLayout->addWidget(aRemoveBtn, 4, 2);
240   aLayout->addWidget(aSortBtn, 6, 2);
241
242   aLayout->setColStretch(0, 1);
243   aLayout->addColSpacing(1, 20);
244   aLayout->addColSpacing(3, 20);
245   aLayout->setRowStretch(2, 1);
246   aLayout->setRowStretch(5, 1);
247
248   /***************************************************************/
249   QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
250   aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
251
252   mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
253   mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
254   mySelectSubMesh->setMinimumSize(50, 0);
255   mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
256   mySubMeshBtn->setText("");
257   mySubMeshBtn->setPixmap(image0);
258   mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
259   mySubMeshLine->setReadOnly(true);
260   onSelectSubMesh(false);
261
262   mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
263   mySelectGroup->setText(tr("SMESH_GROUP"));
264   mySelectGroup->setMinimumSize(50, 0);
265   myGroupBtn = new QPushButton(aSelectBox, "group button");
266   myGroupBtn->setText("");
267   myGroupBtn->setPixmap(image0);
268   myGroupLine = new QLineEdit(aSelectBox, "group line");
269   myGroupLine->setReadOnly(true);
270   onSelectGroup(false);
271   
272   /***************************************************************/
273   QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
274   wg1Layout->addWidget(aContentBox, 0, 0);
275   wg1Layout->addWidget(aSelectBox, 1, 0);
276   wg1Layout->setRowStretch(2, 5);
277
278   /***************************************************************/
279   QLabel* geomObject = new QLabel(wg2, "geometry object label");
280   geomObject->setText(tr("SMESH_OBJECT_GEOM"));
281   myGeomGroupBtn = new QPushButton(wg2, "geometry group button");
282   myGeomGroupBtn->setText("");
283   myGeomGroupBtn->setPixmap(image0);
284   myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
285   myGeomGroupLine->setReadOnly(true); //VSR ???
286   onSelectGeomGroup(false);
287
288   if (!create)
289     {
290       myGeomGroupBtn->setEnabled(false);
291       myGeomGroupLine->setEnabled(false);
292     }
293
294   /***************************************************************/
295   QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
296   wg2Layout->addWidget(geomObject,     0, 0);
297   wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
298   wg2Layout->addWidget(myGeomGroupLine,0, 2);
299   wg2Layout->setRowStretch(1, 5);
300
301   /***************************************************************/
302   QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
303   dumb->addWidget(wg1);
304   dumb->addWidget(wg2);
305   myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
306   myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
307
308   /***************************************************************/
309   QGroupBox* aColorBox = new QGroupBox(2, Qt::Horizontal, this, "color box");
310   aColorBox->setTitle(tr("SMESH_SET_COLOR"));
311
312   mySelectColorGroup = new QCheckBox(aColorBox, "color checkbox");
313   mySelectColorGroup->setText(tr("SMESH_CHECK_COLOR"));
314   
315   myColorSpinBox = new QtxIntSpinBox( aColorBox );
316   myColorSpinBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
317   myColorSpinBox->setMinValue( 0 );
318   myColorSpinBox->setMaxValue( 9999 );
319   
320   onSelectColorGroup(false);
321   
322   /***************************************************************/
323   
324   QFrame* aButtons = new QFrame(this, "button box");
325   aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
326   QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
327   aBtnLayout->setAutoAdd(false);
328
329   QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
330   aOKBtn->setText(tr("SMESH_BUT_OK"));
331   aOKBtn->setAutoDefault(true);
332   aOKBtn->setDefault(true);
333   QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
334   aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
335   aApplyBtn->setAutoDefault(true);
336   QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
337   aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
338   aCloseBtn->setAutoDefault(true);
339   QPushButton* aHelpBtn = new QPushButton(aButtons, "help");
340   aHelpBtn->setText(tr("SMESH_BUT_HELP"));
341   aHelpBtn->setAutoDefault(true);
342
343   aBtnLayout->addWidget(aOKBtn);
344   aBtnLayout->addWidget(aApplyBtn);
345   aBtnLayout->addStretch();
346   aBtnLayout->addWidget(aCloseBtn);
347   aBtnLayout->addWidget(aHelpBtn);
348
349   /***************************************************************/
350   aMainLayout->addWidget(meshGroupLab,    0, 0);
351   aMainLayout->addWidget(myMeshGroupBtn,  0, 1);
352   aMainLayout->addWidget(myMeshGroupLine, 0, 2);
353   aMainLayout->addMultiCellWidget(myTypeGroup,    1, 1, 0, 2);
354   aMainLayout->addWidget(aName,      2, 0);
355   aMainLayout->addWidget(myName,     2, 2);
356   aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
357   aMainLayout->addMultiCellWidget(myWGStack,      4, 4, 0, 2);
358   aMainLayout->setRowStretch( 5, 5 );
359   aMainLayout->addMultiCellWidget(aColorBox,   6, 6, 0, 2);
360   aMainLayout->addMultiCellWidget(aButtons,       7, 7, 0, 2);
361
362   /* signals and slots connections */
363   connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
364
365   connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
366
367   connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
368
369   connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
370   connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
371
372   connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
373   connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
374   connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
375   connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
376
377   connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
378   connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
379   connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
380   connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
381   connect(myGeomGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
382   connect(mySelectColorGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectColorGroup(bool)));
383   connect(myColorSpinBox, SIGNAL(valueChanged(const QString&)), this, SLOT(onNbColorsChanged(const QString&)));
384   
385   connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
386   connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
387   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
388   connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
389
390   /* Init selection */
391   mySMESHGUI->SetActiveDialogBox(this);
392   mySMESHGUI->SetState(800);
393
394   mySelectionMode = -1;
395   myMeshFilter = new SMESH_TypeFilter(MESH);
396   mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
397   myGroupFilter = new SMESH_TypeFilter(GROUP);
398
399   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
400   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
401   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
402
403   myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
404   onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
405
406   if (myMesh->_is_nil() )
407     myTypeGroup->setButton(0);
408
409   updateButtons();
410 }
411
412 //=================================================================================
413 // function : ~SMESHGUI_GroupDlg()
414 // purpose  : Destroys the object and frees any allocated resources
415 //=================================================================================
416 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
417 {
418   // no need to delete child widgets, Qt does it all for us
419   if ( myFilterDlg != 0 )
420   {
421     myFilterDlg->reparent( 0, QPoint() );
422     delete myFilterDlg;
423   }
424 }
425
426 //=================================================================================
427 // function : Init()
428 // purpose  :
429 //=================================================================================
430 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
431 {
432   mySelectionMgr->installFilter(myMeshFilter);
433
434   /* init data from current selection */
435   myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
436   myGroup = SMESH::SMESH_Group::_nil();
437   myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
438
439   myActor = SMESH::FindActorByObject(myMesh);
440   SMESH::SetPickable(myActor);
441
442   SALOME_ListIO aList;
443   mySelectionMgr->selectedObjects( aList );
444   if( !aList.IsEmpty() )
445   {
446     QString aName = aList.First()->getName();
447     myMeshGroupLine->setText(aName) ;
448     myMeshGroupLine->home( false );
449   }
450
451   myCurrentLineEdit = 0;
452
453   myTypeGroup->setButton(0);
454   onTypeChanged(0);
455 }
456
457 //=================================================================================
458 // function : Init()
459 // purpose  :
460 //=================================================================================
461 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
462 {
463   myMesh = theGroup->GetMesh();
464   
465   myName->setText(theGroup->GetName());
466   myName->home(false);
467
468   myColorSpinBox->setValue( theGroup->GetColorNumber() );
469   
470   myMeshGroupLine->setText(theGroup->GetName());
471
472   int aType = 0;
473   switch(theGroup->GetType()) {
474   case SMESH::NODE: aType= 0; break;
475   case SMESH::EDGE: aType = 1; break;
476   case SMESH::FACE: aType = 2; break;
477   case SMESH::VOLUME: aType = 3; break;
478   }
479   myTypeGroup->setButton(aType);
480   
481   myGroup = SMESH::SMESH_Group::_narrow( theGroup );
482
483   if ( !myGroup->_is_nil() )
484     {
485       myGrpTypeGroup->setButton(0);
486       onGrpTypeChanged(0);
487
488       myActor = SMESH::FindActorByObject(myMesh);
489       if ( !myActor )
490         myActor = SMESH::FindActorByObject(myGroup);
491       SMESH::SetPickable(myActor);
492       
493       myCurrentLineEdit = 0;
494       myElements->clear();
495       setSelectionMode(aType);
496       myTypeId = aType;
497       
498       myIdList.clear();
499       if (!myGroup->IsEmpty()) {
500         SMESH::long_array_var anElements = myGroup->GetListOfID();
501         int k = anElements->length();
502         for (int i = 0; i < k; i++) {
503           myIdList.append(anElements[i]);
504           myElements->insertItem(QString::number(anElements[i]));
505         }
506         myElements->selectAll(true);
507       }
508     }
509   else
510     {
511       myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
512       
513       if ( !myGroupOnGeom->_is_nil() )
514         {
515           myGrpTypeGroup->setButton(1);
516           onGrpTypeChanged(1);
517
518           myActor = SMESH::FindActorByObject(myMesh);
519           if ( !myActor )
520             myActor = SMESH::FindActorByObject(myGroup);
521           SMESH::SetPickable(myActor);
522           
523           QString aShapeName("");
524           _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
525           GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
526           if (!aGroupShape->_is_nil())
527             {
528               _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
529               aShapeName = aGroupShapeSO->GetName().c_str();
530             }
531           myGeomGroupLine->setText( aShapeName );
532         }
533     }
534 }
535
536 //=================================================================================
537 // function : updateButtons()
538 // purpose  :
539 //=================================================================================
540 void SMESHGUI_GroupDlg::updateButtons()
541 {
542   bool enable;
543
544   if (myGrpTypeId == 0)
545     enable = !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0;
546   else if (myGrpTypeId == 1)
547     {
548       bool isEditMode = !CORBA::is_nil( myGroupOnGeom );
549       enable = !myName->text().stripWhiteSpace().isEmpty() && (!CORBA::is_nil( myGeomGroup ) || isEditMode);
550     }
551   QPushButton* aBtn;
552   aBtn = (QPushButton*) child("ok", "QPushButton");
553   if (aBtn) aBtn->setEnabled(enable);
554   aBtn = (QPushButton*) child("apply", "QPushButton");
555   if (aBtn) aBtn->setEnabled(enable);
556 }
557
558 //=================================================================================
559 // function : onNameChanged()
560 // purpose  :
561 //=================================================================================
562 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
563 {
564   updateButtons();
565 }
566
567 //=================================================================================
568 // function : onNbColorsChanged()
569 // purpose  :
570 //=================================================================================
571 void SMESHGUI_GroupDlg::onNbColorsChanged (const QString& text)
572 {
573   updateButtons();
574 }
575
576 //=================================================================================
577 // function : onTypeChanged()
578 // purpose  : Group elements type radio button management
579 //=================================================================================
580 void SMESHGUI_GroupDlg::onTypeChanged (int id)
581 {
582   if (myTypeId != id) {
583     myElements->clear();
584     if (myCurrentLineEdit == 0)
585       setSelectionMode(id);
586   }
587   myTypeId = id;
588 }
589
590 //=================================================================================
591 // function : onGrpTypeChanged()
592 // purpose  : Group type radio button management
593 //=================================================================================
594 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
595 {
596   if (myGrpTypeId != id) {
597     myWGStack->raiseWidget( id );
598     onSelectGeomGroup(id == 1);
599   }
600   myGrpTypeId = id;
601 }
602
603 //=================================================================================
604 // function : setSelectionMode()
605 // purpose  : Radio button management
606 //=================================================================================
607 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
608 {
609   // PAL7314
610   if (myMesh->_is_nil())
611     return;
612
613   if (mySelectionMode != theMode) {
614     // [PAL10408] mySelectionMgr->clearSelected();
615     mySelectionMgr->clearFilters();
616     SMESH::SetPointRepresentation(false);
617     if (theMode < 4) {
618       switch (theMode) {
619       case 0:
620         if (myActor)
621           myActor->SetPointRepresentation(true);
622         else
623           SMESH::SetPointRepresentation(true);
624         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
625           aViewWindow->SetSelectionMode(NodeSelection);
626         break;
627       case 1:
628         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
629           aViewWindow->SetSelectionMode(EdgeSelection);
630         break;
631       case 2:
632         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
633           aViewWindow->SetSelectionMode(FaceSelection);
634         break;
635       default:
636         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
637           aViewWindow->SetSelectionMode(VolumeSelection);
638       }
639     } else {
640       if (theMode == 4)
641         mySelectionMgr->installFilter(mySubMeshFilter);
642       else if (theMode == 5)
643         mySelectionMgr->installFilter(myGroupFilter);
644       else if (theMode == 6)
645         mySelectionMgr->installFilter(myMeshFilter);
646       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
647         aViewWindow->SetSelectionMode(ActorSelection);
648     }
649     mySelectionMode = theMode;
650   }
651 }
652
653 //=================================================================================
654 // function : onApply()
655 // purpose  :
656 //=================================================================================
657 bool SMESHGUI_GroupDlg::onApply()
658 {
659   if (mySMESHGUI->isActiveStudyLocked())
660     return false;
661
662   if (myGrpTypeId == 0 &&
663       !myName->text().stripWhiteSpace().isEmpty() &&
664       myElements->count() > 0) {
665     mySelectionMgr->clearSelected();
666     if (myGroup->_is_nil()) {
667       SMESH::ElementType aType = SMESH::ALL;
668       switch(myTypeId) {
669       case 0: aType = SMESH::NODE; break;
670       case 1: aType = SMESH::EDGE; break;
671       case 2: aType = SMESH::FACE; break;
672       case 3: aType = SMESH::VOLUME; break;
673       }
674       SMESH::long_array_var anIdList = new SMESH::long_array;
675       int i, k = myElements->count();
676       anIdList->length(k);
677       QListBoxItem* anItem;
678       for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
679         anIdList[i] = anItem->text().toInt();
680       }
681
682       myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
683       myGroup->Add(anIdList.inout());
684       
685       int aColorNumber = myColorSpinBox->value();
686       myGroup->SetColorNumber(aColorNumber);
687       
688       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
689
690       SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
691       
692       SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
693       
694       /* init for next operation */
695       myName->setText("");
696       myColorSpinBox->setValue(0);
697       myElements->clear();
698       myGroup = SMESH::SMESH_Group::_nil();
699
700     } else {
701       myGroup->SetName(myName->text());
702         
703       int aColorNumber = myColorSpinBox->value();
704       myGroup->SetColorNumber(aColorNumber);
705
706       QValueList<int> aAddList;
707       QValueList<int>::iterator anIt;
708       QListBoxItem* anItem;
709
710       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
711         int anId = anItem->text().toInt();
712         if ((anIt = myIdList.find(anId)) == myIdList.end())
713           aAddList.append(anId);
714         else
715           myIdList.remove(anIt);
716       }
717       if (!aAddList.empty()) {
718         SMESH::long_array_var anIdList = new SMESH::long_array;
719         anIdList->length(aAddList.count());
720         int i;
721         for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
722           anIdList[i] = *anIt;
723         myGroup->Add(anIdList.inout());
724       }
725       if (!myIdList.empty()) {
726         SMESH::long_array_var anIdList = new SMESH::long_array;
727         anIdList->length(myIdList.count());
728         int i;
729         for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
730           anIdList[i] = *anIt;
731         myGroup->Remove(anIdList.inout());
732       }
733       /* init for next operation */
734       myIdList.clear();
735       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
736         myIdList.append(anItem->text().toInt());
737     }
738
739     mySMESHGUI->updateObjBrowser(true);
740     SMESH::UpdateView(); // asv: fix of BUG PAL5515
741     mySelectionMgr->clearSelected();
742     return true;
743   } else if (myGrpTypeId == 1 &&
744              !myName->text().stripWhiteSpace().isEmpty() &&
745              (!CORBA::is_nil(myGeomGroup) || !CORBA::is_nil(myGroupOnGeom)))
746   {
747     if (myGroupOnGeom->_is_nil()) {
748       SMESH::ElementType aType = SMESH::ALL;
749       switch (myTypeId) {
750       case 0: aType = SMESH::NODE; break;
751       case 1: aType = SMESH::EDGE; break;
752       case 2: aType = SMESH::FACE; break;
753       case 3: aType = SMESH::VOLUME; break;
754       }
755       
756       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
757       GEOM::GEOM_IGroupOperations_var aGroupOp =
758         SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
759       
760       myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomGroup);
761       
762       int aColorNumber = myColorSpinBox->value();
763       myGroupOnGeom->SetColorNumber(aColorNumber);
764       
765       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
766       
767       SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
768       
769       SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
770       
771       /* init for next operation */
772       myName->setText("");
773       myColorSpinBox->setValue(0);
774       myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
775     }
776     else
777       {
778         myGroupOnGeom->SetName(myName->text());
779         
780         int aColorNumber = myColorSpinBox->value();
781         myGroupOnGeom->SetColorNumber(aColorNumber);
782       }
783     
784     mySMESHGUI->updateObjBrowser(true);
785     mySelectionMgr->clearSelected();
786     return true;
787   }
788   
789   return false;
790 }
791
792 //=================================================================================
793 // function : onOK()
794 // purpose  :
795 //=================================================================================
796 void SMESHGUI_GroupDlg::onOK()
797 {
798   if ( onApply() )
799     onClose();
800 }
801
802 //=================================================================================
803 // function : onListSelectionChanged()
804 // purpose  : Called when selection in element list is changed
805 //=================================================================================
806 void SMESHGUI_GroupDlg::onListSelectionChanged()
807 {
808   //  MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
809   if( myIsBusy || !myActor) return;
810     myIsBusy = true;
811
812   if (myCurrentLineEdit == 0) {
813     mySelectionMgr->clearSelected();
814     TColStd_MapOfInteger aIndexes;
815     QListBoxItem* anItem;
816     for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
817       if (anItem->isSelected()) {
818         int anId = anItem->text().toInt();
819         aIndexes.Add(anId);
820       }
821     }
822     mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
823     SALOME_ListIO aList;
824     aList.Append(myActor->getIO());
825     mySelectionMgr->setSelectedObjects(aList,false);
826   }
827   myIsBusy = false;
828 }
829
830 //=================================================================================
831 // function : onObjectSelectionChanged()
832 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
833 //=================================================================================
834 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
835 {
836   if ( myIsBusy || !isEnabled()) return;
837     myIsBusy = true;
838
839   SALOME_ListIO aList;
840   mySelectionMgr->selectedObjects( aList );
841   
842   int aNbSel = aList.Extent();
843   myElements->clearSelection();
844
845   if (myCurrentLineEdit) {
846     myCurrentLineEdit->setText("");
847     QString aString = "";
848
849     if (myCurrentLineEdit == myMeshGroupLine) {
850       mySelectSubMesh->setEnabled(false);
851       mySelectGroup->setEnabled(false);
852       myGroupLine->setText("");
853       mySubMeshLine->setText("");
854
855       myGeomGroupBtn->setEnabled(false);
856       myGeomGroupLine->setEnabled(false);
857       myGeomGroupLine->setText("");
858       if (!myCreate)
859         myName->setText("");
860
861       myElements->clear();
862
863       if (aNbSel != 1 ) {
864         myGroup = SMESH::SMESH_Group::_nil();
865         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); 
866         myMesh = SMESH::SMESH_Mesh::_nil();
867         myIsBusy = false;
868         return;
869       }
870       Handle(SALOME_InteractiveObject) IO = aList.First();
871
872       if (myCreate) {
873         myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
874         if (myMesh->_is_nil())
875         {
876           myIsBusy = false;
877           return;
878         }
879         myGroup = SMESH::SMESH_Group::_nil();
880
881         myActor = SMESH::FindActorByObject(myMesh);
882         SMESH::SetPickable(myActor);
883
884         aString = aList.First()->getName();
885         myMeshGroupLine->setText(aString) ;
886         myMeshGroupLine->home( false );
887
888         mySelectSubMesh->setEnabled(true);
889         mySelectGroup->setEnabled(true);
890         myGeomGroupBtn->setEnabled(true);
891         myGeomGroupLine->setEnabled(true);
892         updateButtons();
893       } else {
894         SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
895         if (aGroup->_is_nil())
896         {
897           myIsBusy = false;
898           return;
899         }
900         myIsBusy = false;
901         myCurrentLineEdit = 0;
902
903         myGroup = SMESH::SMESH_Group::_nil();
904         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
905         
906         init(aGroup);
907         myIsBusy = true;
908         mySelectSubMesh->setEnabled(true);
909         mySelectGroup->setEnabled(true);
910       }
911       myCurrentLineEdit = 0;
912       myIsBusy = false;
913       if (!myCreate)
914         return;
915
916       if (myTypeId == -1)
917         onTypeChanged(0);
918       else {
919         myElements->clear();
920         setSelectionMode(myTypeId);
921       }
922
923       myIsBusy = false;
924       return;
925
926     } else if (myCurrentLineEdit == myGeomGroupLine) {
927       if (aNbSel != 1) {
928         myGeomGroup = GEOM::GEOM_Object::_nil();
929         myIsBusy = false;
930         return;
931       }
932
933       Standard_Boolean testResult = Standard_False;
934       myGeomGroup = GEOMBase::ConvertIOinGEOMObject(aList.First(), testResult);
935
936       // Check if the object is a geometry group
937       if (!testResult || CORBA::is_nil(myGeomGroup)) {
938         myGeomGroup = GEOM::GEOM_Object::_nil();
939         myIsBusy = false;
940         return;
941       }
942       // Check if group constructed on the same shape as a mesh or on its child
943       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
944       GEOM::GEOM_IGroupOperations_var anOp =
945         SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
946
947       // The main shape of the group
948       GEOM::GEOM_Object_var aGroupMainShape;
949       if (myGeomGroup->GetType() == 37)
950         aGroupMainShape = anOp->GetMainShape(myGeomGroup);
951       else
952         aGroupMainShape = GEOM::GEOM_Object::_duplicate(myGeomGroup);
953       _PTR(SObject) aGroupMainShapeSO =
954         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
955         aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
956
957       // The mesh SObject
958       _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
959       if (!aMeshSO) {
960         myGeomGroup = GEOM::GEOM_Object::_nil();
961         myIsBusy = false;
962         return;
963       }
964       _PTR(SObject) anObj, aRef;
965       bool isRefOrSubShape = false;
966       if (aMeshSO->FindSubObject(1, anObj) &&  anObj->ReferencedObject(aRef)) {
967         //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
968         if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
969           isRefOrSubShape = true;
970         } else {
971           _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
972           _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
973           //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
974           while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
975             //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
976             if (aRef->GetID() == aFather->GetID())
977               isRefOrSubShape = true;
978             else
979               aFather = aFather->GetFather();
980           }
981         }
982       }
983       if (!isRefOrSubShape) {
984         myGeomGroup = GEOM::GEOM_Object::_nil();
985         myIsBusy = false;
986         return;
987       }
988     }
989
990     if(aNbSel >= 1) {
991       if(aNbSel > 1) {
992         if(myCurrentLineEdit == mySubMeshLine)
993           aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
994         else if(myCurrentLineEdit == myGroupLine || myCurrentLineEdit == myGeomGroupLine)
995           aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
996       } else {
997         aString = aList.First()->getName();
998       }
999     }
1000
1001     myCurrentLineEdit->setText(aString);
1002     myCurrentLineEdit->home(false);
1003
1004     updateButtons();
1005
1006   } else {
1007     if (aNbSel == 1 && myActor ) {
1008       QString aListStr = "";
1009       int aNbItems = 0;
1010       if (myTypeId == 0) {
1011         aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1012       } else {
1013         aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1014       }
1015       if (aNbItems > 0) {
1016         QStringList anElements = QStringList::split(" ", aListStr);
1017         QListBoxItem* anItem = 0;
1018         for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1019           anItem = myElements->findItem(*it, Qt::ExactMatch);
1020           if (anItem) myElements->setSelected(anItem, true);
1021         }
1022       }
1023     }
1024   }
1025
1026   if (!myActor) {
1027     if (!myGroup->_is_nil())
1028       myActor = SMESH::FindActorByObject(myGroup);
1029     else if(!myGroupOnGeom->_is_nil())
1030       myActor = SMESH::FindActorByObject(myGroupOnGeom);
1031     else
1032       myActor = SMESH::FindActorByObject(myMesh);
1033   }
1034
1035   myIsBusy = false;
1036 }
1037
1038 //=================================================================================
1039 // function : onSelectSubMesh()
1040 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1041 //=================================================================================
1042 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1043 {
1044   if (on) {
1045     if (mySelectGroup->isChecked()) {
1046       mySelectGroup->setChecked(false);
1047     }
1048     //VSR: else if (mySelectGeomGroup->isChecked()) {
1049     //VSR:   mySelectGeomGroup->setChecked(false);
1050     //VSR: }
1051     myCurrentLineEdit = mySubMeshLine;
1052     setSelectionMode(4);
1053   }
1054   else {
1055     mySubMeshLine->setText("");
1056     myCurrentLineEdit = 0;
1057     if (myTypeId != -1)
1058       setSelectionMode(myTypeId);
1059   }
1060   mySubMeshBtn->setEnabled(on);
1061   mySubMeshLine->setEnabled(on);
1062 }
1063
1064
1065 //=================================================================================
1066 // function : (onSelectGroup)
1067 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1068 //=================================================================================
1069 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1070 {
1071   if (on) {
1072     if (mySelectSubMesh->isChecked()) {
1073       mySelectSubMesh->setChecked(false);
1074     }
1075     myCurrentLineEdit = myGroupLine;
1076     setSelectionMode(5);
1077   }
1078   else {
1079     myGroupLine->setText("");
1080     myCurrentLineEdit = 0;
1081     if (myTypeId != -1)
1082       setSelectionMode(myTypeId);
1083   }
1084   myGroupBtn->setEnabled(on);
1085   myGroupLine->setEnabled(on);
1086 }
1087
1088
1089 //=================================================================================
1090 // function : (onSelectGeomGroup)
1091 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1092 //=================================================================================
1093 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1094 {
1095   if (on) {
1096     if (mySelectSubMesh->isChecked()) {
1097       mySelectSubMesh->setChecked(false);
1098     }
1099     else if (mySelectGroup->isChecked()) {
1100       mySelectGroup->setChecked(false);
1101     }
1102     myCurrentLineEdit = myGeomGroupLine;
1103     setSelectionMode(7);
1104   }
1105   else {
1106     myGeomGroupLine->setText("");
1107     myCurrentLineEdit = 0;
1108     if (myTypeId != -1)
1109       setSelectionMode(myTypeId);
1110   }
1111 }
1112
1113 //=================================================================================
1114 // function : (onSelectColorGroup)
1115 // purpose  : Called when setting a color on group
1116 //=================================================================================
1117 void SMESHGUI_GroupDlg::onSelectColorGroup(bool on)
1118 {
1119   if (!on)
1120     myColorSpinBox->setValue(0);
1121   
1122   myColorSpinBox->setEnabled(on);
1123 }
1124
1125 //=================================================================================
1126 // function : setCurrentSelection()
1127 // purpose  :
1128 //=================================================================================
1129 void SMESHGUI_GroupDlg::setCurrentSelection()
1130 {
1131   QPushButton* send = (QPushButton*)sender();
1132   myCurrentLineEdit = 0;
1133   if (send == myMeshGroupBtn) {
1134     myCurrentLineEdit = myMeshGroupLine;
1135     if (myCreate)
1136       setSelectionMode(6);
1137     else
1138       setSelectionMode(5);
1139     onObjectSelectionChanged();
1140   }
1141   else if (send == mySubMeshBtn) {
1142     myCurrentLineEdit = mySubMeshLine;
1143     onObjectSelectionChanged();
1144   }
1145   else if (send == myGroupBtn) {
1146     myCurrentLineEdit = myGroupLine;
1147     onObjectSelectionChanged();
1148   }
1149   else if (send == myGeomGroupBtn) {
1150     myCurrentLineEdit = myGeomGroupLine;
1151     setSelectionMode(7);
1152     onObjectSelectionChanged();
1153   }
1154 }
1155
1156
1157 //=================================================================================
1158 // function : setFilters()
1159 // purpose  : SLOT. Called when "Filter" button pressed.
1160 //=================================================================================
1161 void SMESHGUI_GroupDlg::setFilters()
1162 {
1163   SMESH::ElementType aType = SMESH::ALL;
1164   switch ( myTypeId )
1165   {
1166     case 0 : aType = SMESH::NODE; break;
1167     case 1 : aType = SMESH::EDGE; break;
1168     case 2 : aType = SMESH::FACE; break;
1169     case 3 : aType = SMESH::VOLUME; break;
1170     default: return;
1171   }
1172
1173   if ( myFilterDlg == 0 )
1174   {
1175     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1176     connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1177   }
1178   else
1179     myFilterDlg->Init( aType );
1180
1181   myFilterDlg->SetSelection();
1182   myFilterDlg->SetMesh( myMesh );
1183   myFilterDlg->SetSourceWg( myElements );
1184
1185   myFilterDlg->show();
1186 }
1187
1188 //=================================================================================
1189 // function : onFilterAccepted()
1190 // purpose  : SLOT. Called when Filter dlg closed with OK button.
1191 //            Uncheck "Select submesh" and "Select group" checkboxes
1192 //=================================================================================
1193 void SMESHGUI_GroupDlg::onFilterAccepted()
1194 {
1195   if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1196   {
1197     mySelectionMode = myTypeId;
1198     mySelectSubMesh->setChecked( false );
1199     mySelectGroup->setChecked( false );
1200   }
1201 }
1202
1203 //=================================================================================
1204 // function : onAdd()
1205 // purpose  :
1206 //=================================================================================
1207 void SMESHGUI_GroupDlg::onAdd()
1208 {
1209   SALOME_ListIO aList;
1210   mySelectionMgr->selectedObjects( aList );
1211
1212   int aNbSel = aList.Extent();
1213
1214   if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1215
1216   myIsBusy = true;
1217
1218   SMESH::ElementType aType = SMESH::ALL;
1219   switch(myTypeId) {
1220   case 0: 
1221     aType = SMESH::NODE; 
1222     mySelector->SetSelectionMode(NodeSelection);
1223     break;
1224   case 1: 
1225     aType = SMESH::EDGE; 
1226     mySelector->SetSelectionMode(EdgeSelection);
1227     break;
1228   case 2: 
1229     aType = SMESH::FACE; 
1230     mySelector->SetSelectionMode(FaceSelection);
1231     break;
1232   case 3: 
1233     aType = SMESH::VOLUME; 
1234     mySelector->SetSelectionMode(VolumeSelection);
1235     break;
1236   default:
1237     mySelector->SetSelectionMode(ActorSelection);
1238   }
1239
1240
1241   if (myCurrentLineEdit == 0) {
1242     //if (aNbSel != 1) { myIsBusy = false; return; }
1243     QString aListStr = "";
1244     int aNbItems = 0;
1245     if (myTypeId == 0) {
1246       aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1247     }
1248     else {
1249       aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1250     }
1251     if (aNbItems > 0) {
1252       QStringList anElements = QStringList::split(" ", aListStr);
1253       QListBoxItem* anItem = 0;
1254       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1255         anItem = myElements->findItem(*it, Qt::ExactMatch);
1256         if (!anItem) {
1257           anItem = new QListBoxText(*it);
1258           myElements->insertItem(anItem);
1259         }
1260         myElements->setSelected(anItem, true);
1261       }
1262     }
1263   } else if (myCurrentLineEdit == mySubMeshLine) {
1264     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1265     
1266     SALOME_ListIO aList;
1267     mySelectionMgr->selectedObjects( aList );
1268
1269     SALOME_ListIteratorOfListIO anIt (aList);
1270     for (; anIt.More(); anIt.Next()) {
1271       SMESH::SMESH_subMesh_var aSubMesh =
1272         SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1273       if (!aSubMesh->_is_nil()) {
1274         // check if mesh is the same
1275         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1276           try {
1277             SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1278             int k = anElements->length();
1279             QListBoxItem* anItem = 0;
1280             for (int i = 0; i < k; i++) {
1281               QString aText = QString::number(anElements[i]);
1282               anItem = myElements->findItem(aText, Qt::ExactMatch);
1283               if (!anItem) {
1284                 anItem = new QListBoxText(aText);
1285                 myElements->insertItem(anItem);
1286               }
1287               myElements->setSelected(anItem, true);
1288             }
1289           }
1290           catch (const SALOME::SALOME_Exception& ex) {
1291             SalomeApp_Tools::QtCatchCorbaException(ex);
1292           }
1293         }
1294       }
1295     }
1296     mySelectSubMesh->setChecked(false);
1297     myIsBusy = false;
1298     onListSelectionChanged();
1299
1300   } else if (myCurrentLineEdit == myGroupLine) {
1301     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1302     SALOME_ListIO aList;
1303     mySelectionMgr->selectedObjects( aList );
1304     
1305     SALOME_ListIteratorOfListIO anIt (aList);
1306     for (; anIt.More(); anIt.Next()) {
1307       SMESH::SMESH_Group_var aGroup =
1308         SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1309       if (!aGroup->_is_nil()) {
1310         // check if mesh is the same
1311         if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1312           SMESH::long_array_var anElements = aGroup->GetListOfID();
1313           int k = anElements->length();
1314           QListBoxItem* anItem = 0;
1315           for (int i = 0; i < k; i++) {
1316             QString aText = QString::number(anElements[i]);
1317             anItem = myElements->findItem(aText, Qt::ExactMatch);
1318             if (!anItem) {
1319               anItem = new QListBoxText(aText);
1320               myElements->insertItem(anItem);
1321             }
1322             myElements->setSelected(anItem, true);
1323           }
1324         }
1325       }
1326     }
1327     mySelectGroup->setChecked(false);
1328     myIsBusy = false;
1329     onListSelectionChanged();
1330
1331   } else if (myCurrentLineEdit == myGeomGroupLine && !CORBA::is_nil(myGeomGroup)) {
1332     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1333     GEOM::GEOM_IGroupOperations_var aGroupOp =
1334       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1335
1336     SMESH::ElementType aGroupType = SMESH::ALL;
1337     switch(aGroupOp->GetType(myGeomGroup)) {
1338     case 7: aGroupType = SMESH::NODE; break;
1339     case 6: aGroupType = SMESH::EDGE; break;
1340     case 4: aGroupType = SMESH::FACE; break;
1341     case 2: aGroupType = SMESH::VOLUME; break;
1342     default: myIsBusy = false; return;
1343     }
1344
1345     if (aGroupType == aType) {
1346       _PTR(SObject) aGroupSO =
1347         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1348         aStudy->FindObjectID(myGeomGroup->GetStudyEntry());
1349       // Construct filter
1350       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1351       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1352       SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1353       aBelongToGeom->SetGeom(myGeomGroup);
1354       aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1355       aBelongToGeom->SetElementType(aType);
1356       aFilter->SetPredicate(aBelongToGeom);
1357
1358       SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1359
1360       int k = anElements->length();
1361       QListBoxItem* anItem = 0;
1362       for (int i = 0; i < k; i++) {
1363         QString aText = QString::number(anElements[i]);
1364         anItem = myElements->findItem(aText, Qt::ExactMatch);
1365         if (!anItem) {
1366           anItem = new QListBoxText(aText);
1367           myElements->insertItem(anItem);
1368         }
1369         myElements->setSelected(anItem, true);
1370       }
1371     }
1372
1373     //VSR: mySelectGeomGroup->setChecked(false);
1374     myIsBusy = false;
1375     onListSelectionChanged();
1376   }
1377   myIsBusy = false;
1378   //  mySelectionMgr->clearSelected();
1379   updateButtons();
1380 }
1381
1382 //=================================================================================
1383 // function : onRemove()
1384 // purpose  :
1385 //=================================================================================
1386 void SMESHGUI_GroupDlg::onRemove()
1387 {
1388   myIsBusy = true;
1389   if (myCurrentLineEdit == 0) {
1390     for (int i = myElements->count(); i > 0; i--) {
1391       if (myElements->isSelected(i-1)) {
1392         myElements->removeItem(i-1);
1393       }
1394     }
1395   } else {
1396     SALOME_ListIO aList;
1397     mySelectionMgr->selectedObjects( aList );
1398
1399     int aNbSel = aList.Extent();
1400
1401     if (aNbSel == 0) { myIsBusy = false; return; }
1402
1403     SMESH::ElementType aType = SMESH::ALL;
1404     switch(myTypeId) {
1405     case 0: aType = SMESH::NODE; break;
1406     case 1: aType = SMESH::EDGE; break;
1407     case 2: aType = SMESH::FACE; break;
1408     case 3: aType = SMESH::VOLUME; break;
1409     }
1410
1411     if (myCurrentLineEdit == mySubMeshLine) {
1412       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1413       SALOME_ListIO aList;
1414       mySelectionMgr->selectedObjects( aList );
1415
1416       SALOME_ListIteratorOfListIO anIt (aList);
1417       for (; anIt.More(); anIt.Next()) {
1418         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1419         if (!aSubMesh->_is_nil()) {
1420           // check if mesh is the same
1421           if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1422             if (aType == SMESH::NODE) {
1423               try {
1424                 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1425                 int k = anElements->length();
1426                 QListBoxItem* anItem = 0;
1427                 for (int i = 0; i < k; i++) {
1428                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1429                   if (anItem) delete anItem;
1430                 }
1431               }
1432               catch (const SALOME::SALOME_Exception& ex) {
1433                 SalomeApp_Tools::QtCatchCorbaException(ex);
1434               }
1435             }
1436             else {
1437               try {
1438                 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1439                 int k = anElements->length();
1440                 QListBoxItem* anItem = 0;
1441                 for (int i = 0; i < k; i++) {
1442                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1443                   if (anItem) delete anItem;
1444                 }
1445               }
1446               catch (const SALOME::SALOME_Exception& ex) {
1447                 SalomeApp_Tools::QtCatchCorbaException(ex);
1448               }
1449             }
1450           }
1451         }
1452       }
1453     }
1454     else if (myCurrentLineEdit == myGroupLine) {
1455       Standard_Boolean aRes;
1456       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1457       SALOME_ListIO aList;
1458       mySelectionMgr->selectedObjects( aList );
1459
1460       SALOME_ListIteratorOfListIO anIt (aList);
1461       for (; anIt.More(); anIt.Next()) {
1462         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1463         if (aRes && !aGroup->_is_nil()) {
1464           // check if mesh is the same
1465           if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1466             SMESH::long_array_var anElements = aGroup->GetListOfID();
1467             int k = anElements->length();
1468             QListBoxItem* anItem = 0;
1469             for (int i = 0; i < k; i++) {
1470               anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1471               if (anItem) delete anItem;
1472             }
1473           }
1474         }
1475       }
1476     }
1477   }
1478   myIsBusy = false;
1479   updateButtons();
1480 }
1481
1482 //=================================================================================
1483 // function : onSort()
1484 // purpose  :
1485 //=================================================================================
1486 void SMESHGUI_GroupDlg::onSort()
1487 {
1488   // PAL5412: sorts items in ascending by "string" value
1489   // myElements->sort(true);
1490   // myElements->update();
1491   int i, k = myElements->count();
1492   if (k > 0) {
1493     myIsBusy = true;
1494     QStringList aSelected;
1495     std::vector<int> anArray(k);
1496     //    QMemArray<int> anArray(k);
1497     QListBoxItem* anItem;
1498     // fill the array
1499     for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1500       anArray[i] = anItem->text().toInt();
1501       if (anItem->isSelected())
1502         aSelected.append(anItem->text());
1503     }
1504     // sort & update list
1505     std::sort(anArray.begin(), anArray.end());
1506     //    anArray.sort();
1507     myElements->clear();
1508     for (i = 0; i < k; i++) {
1509       myElements->insertItem(QString::number(anArray[i]));
1510     }
1511     for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1512       anItem = myElements->findItem(*it, Qt::ExactMatch);
1513       if (anItem) myElements->setSelected(anItem, true);
1514     }
1515     myIsBusy = false;
1516   }
1517 }
1518
1519 //=================================================================================
1520 // function : closeEvent()
1521 // purpose  :
1522 //=================================================================================
1523 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1524 {
1525   onClose();
1526 }
1527
1528 //=================================================================================
1529 // function : SMESHGUI_GroupDlg::onClose
1530 // purpose  : SLOT called when "Close" button pressed. Close dialog
1531 //=================================================================================
1532 void SMESHGUI_GroupDlg::onClose()
1533 {
1534   if (SMESH::GetCurrentVtkView()) {
1535     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1536     SMESH::SetPointRepresentation(false);
1537     SMESH::SetPickable();
1538   }
1539
1540   mySelectionMgr->clearSelected();
1541   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1542     aViewWindow->SetSelectionMode(ActorSelection);
1543   mySelectionMgr->clearFilters();
1544   mySMESHGUI->ResetState();
1545
1546   reject();
1547 }
1548
1549 //=================================================================================
1550 // function : onHelp()
1551 // purpose  :
1552 //=================================================================================
1553 void SMESHGUI_GroupDlg::onHelp()
1554 {
1555   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1556   if (app) 
1557     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1558   else {
1559     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1560                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1561                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
1562                            QObject::tr("BUT_OK"));
1563   }
1564 }
1565
1566 //=================================================================================
1567 // function : SMESHGUI_GroupDlg::onDeactivate
1568 // purpose  : SLOT called when dialog must be deativated
1569 //=================================================================================
1570 void SMESHGUI_GroupDlg::onDeactivate()
1571 {
1572   mySMESHGUI->ResetState();
1573   setEnabled(false);
1574 }
1575
1576 //=================================================================================
1577 // function : SMESHGUI_GroupDlg::enterEvent
1578 // purpose  : Event filter
1579 //=================================================================================
1580 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1581 {
1582   if (!isEnabled()) {
1583     mySMESHGUI->EmitSignalDeactivateDialog();
1584     setEnabled(true);
1585     mySelectionMode = -1;
1586     setSelectionMode(myTypeId);
1587     //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1588     mySMESHGUI->SetActiveDialogBox(this);
1589     mySMESHGUI->SetState(800);
1590   }
1591 }
1592
1593 //=================================================================================
1594 // function : hideEvent
1595 // purpose  : caused by ESC key
1596 //=================================================================================
1597 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1598 {
1599   if (!isMinimized())
1600     onClose();
1601 }