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