Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[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         myMesh = SMESH::SMESH_Mesh::_nil();
858         myIsBusy = false;
859         return;
860       }
861       Handle(SALOME_InteractiveObject) IO = aList.First();
862
863       if (myCreate) {
864         myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
865         if (myMesh->_is_nil())
866         {
867           myIsBusy = false;
868           return;
869         }
870         myGroup = SMESH::SMESH_Group::_nil();
871
872         myActor = SMESH::FindActorByObject(myMesh);
873         SMESH::SetPickable(myActor);
874
875         aString = aList.First()->getName();
876         myMeshGroupLine->setText(aString) ;
877         myMeshGroupLine->home( false );
878
879         mySelectSubMesh->setEnabled(true);
880         mySelectGroup->setEnabled(true);
881         myGeomGroupBtn->setEnabled(true);
882         myGeomGroupLine->setEnabled(true);
883         updateButtons();
884       } else {
885         SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
886         if (aGroup->_is_nil())
887         {
888           myIsBusy = false;
889           return;
890         }
891         myIsBusy = false;
892         myCurrentLineEdit = 0;
893         init(aGroup);
894         myIsBusy = true;
895         mySelectSubMesh->setEnabled(true);
896         mySelectGroup->setEnabled(true);
897         myGeomGroupBtn->setEnabled(true);
898         myGeomGroupLine->setEnabled(true);
899       }
900       myCurrentLineEdit = 0;
901       myIsBusy = false;
902       if (!myCreate)
903         return;
904
905       if (myTypeId == -1)
906         onTypeChanged(0);
907       else {
908         myElements->clear();
909         setSelectionMode(myTypeId);
910       }
911
912       myIsBusy = false;
913       return;
914
915     } else if (myCurrentLineEdit == myGeomGroupLine) {
916       if (aNbSel != 1) {
917         myGeomGroup = GEOM::GEOM_Object::_nil();
918         myIsBusy = false;
919         return;
920       }
921
922       Standard_Boolean testResult = Standard_False;
923       myGeomGroup = GEOMBase::ConvertIOinGEOMObject(aList.First(), testResult);
924
925       // Check if the object is a geometry group
926       if (!testResult || CORBA::is_nil(myGeomGroup)) {
927         myGeomGroup = GEOM::GEOM_Object::_nil();
928         myIsBusy = false;
929         return;
930       }
931       // Check if group constructed on the same shape as a mesh or on its child
932       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
933       GEOM::GEOM_IGroupOperations_var anOp =
934         SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
935
936       // The main shape of the group
937       GEOM::GEOM_Object_var aGroupMainShape;
938       if (myGeomGroup->GetType() == 37)
939         aGroupMainShape = anOp->GetMainShape(myGeomGroup);
940       else
941         aGroupMainShape = GEOM::GEOM_Object::_duplicate(myGeomGroup);
942       _PTR(SObject) aGroupMainShapeSO =
943         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
944         aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
945
946       // The mesh SObject
947       _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
948       if (!aMeshSO) {
949         myGeomGroup = GEOM::GEOM_Object::_nil();
950         myIsBusy = false;
951         return;
952       }
953       _PTR(SObject) anObj, aRef;
954       bool isRefOrSubShape = false;
955       if (aMeshSO->FindSubObject(1, anObj) &&  anObj->ReferencedObject(aRef)) {
956         //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
957         if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
958           isRefOrSubShape = true;
959         } else {
960           _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
961           _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
962           //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
963           while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
964             //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
965             if (aRef->GetID() == aFather->GetID())
966               isRefOrSubShape = true;
967             else
968               aFather = aFather->GetFather();
969           }
970         }
971       }
972       if (!isRefOrSubShape) {
973         myGeomGroup = GEOM::GEOM_Object::_nil();
974         myIsBusy = false;
975         return;
976       }
977     }
978
979     if(aNbSel >= 1) {
980       if(aNbSel > 1) {
981         if(myCurrentLineEdit == mySubMeshLine)
982           aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
983         else if(myCurrentLineEdit == myGroupLine || myCurrentLineEdit == myGeomGroupLine)
984           aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
985       } else {
986         aString = aList.First()->getName();
987       }
988     }
989
990     myCurrentLineEdit->setText(aString);
991     myCurrentLineEdit->home(false);
992
993     updateButtons();
994
995   } else {
996     if (aNbSel == 1 && myActor ) {
997       QString aListStr = "";
998       int aNbItems = 0;
999       if (myTypeId == 0) {
1000         aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1001       } else {
1002         aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1003       }
1004       if (aNbItems > 0) {
1005         QStringList anElements = QStringList::split(" ", aListStr);
1006         QListBoxItem* anItem = 0;
1007         for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1008           anItem = myElements->findItem(*it, Qt::ExactMatch);
1009           if (anItem) myElements->setSelected(anItem, true);
1010         }
1011       }
1012     }
1013   }
1014
1015   if (!myActor) {
1016     if (!myGroup->_is_nil())
1017       myActor = SMESH::FindActorByObject(myGroup);
1018     else if(!myGroupOnGeom->_is_nil())
1019       myActor = SMESH::FindActorByObject(myGroupOnGeom);
1020     else
1021       myActor = SMESH::FindActorByObject(myMesh);
1022   }
1023
1024   myIsBusy = false;
1025 }
1026
1027 //=================================================================================
1028 // function : onSelectSubMesh()
1029 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1030 //=================================================================================
1031 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1032 {
1033   if (on) {
1034     if (mySelectGroup->isChecked()) {
1035       mySelectGroup->setChecked(false);
1036     }
1037     //VSR: else if (mySelectGeomGroup->isChecked()) {
1038     //VSR:   mySelectGeomGroup->setChecked(false);
1039     //VSR: }
1040     myCurrentLineEdit = mySubMeshLine;
1041     setSelectionMode(4);
1042   }
1043   else {
1044     mySubMeshLine->setText("");
1045     myCurrentLineEdit = 0;
1046     if (myTypeId != -1)
1047       setSelectionMode(myTypeId);
1048   }
1049   mySubMeshBtn->setEnabled(on);
1050   mySubMeshLine->setEnabled(on);
1051 }
1052
1053
1054 //=================================================================================
1055 // function : (onSelectGroup)
1056 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1057 //=================================================================================
1058 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1059 {
1060   if (on) {
1061     if (mySelectSubMesh->isChecked()) {
1062       mySelectSubMesh->setChecked(false);
1063     }
1064     myCurrentLineEdit = myGroupLine;
1065     setSelectionMode(5);
1066   }
1067   else {
1068     myGroupLine->setText("");
1069     myCurrentLineEdit = 0;
1070     if (myTypeId != -1)
1071       setSelectionMode(myTypeId);
1072   }
1073   myGroupBtn->setEnabled(on);
1074   myGroupLine->setEnabled(on);
1075 }
1076
1077
1078 //=================================================================================
1079 // function : (onSelectGeomGroup)
1080 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1081 //=================================================================================
1082 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1083 {
1084   if (on) {
1085     if (mySelectSubMesh->isChecked()) {
1086       mySelectSubMesh->setChecked(false);
1087     }
1088     else if (mySelectGroup->isChecked()) {
1089       mySelectGroup->setChecked(false);
1090     }
1091     myCurrentLineEdit = myGeomGroupLine;
1092     setSelectionMode(7);
1093   }
1094   else {
1095     myGeomGroupLine->setText("");
1096     myCurrentLineEdit = 0;
1097     if (myTypeId != -1)
1098       setSelectionMode(myTypeId);
1099   }
1100 }
1101
1102 //=================================================================================
1103 // function : (onSelectColorGroup)
1104 // purpose  : Called when setting a color on group
1105 //=================================================================================
1106 void SMESHGUI_GroupDlg::onSelectColorGroup(bool on)
1107 {
1108   if (on) {
1109     setSelectionMode(7);
1110   }
1111   else {
1112     myColorGroupLine->setText("");
1113     myCurrentLineEdit = 0;
1114     if (myTypeId != -1)
1115       setSelectionMode(myTypeId);
1116   }
1117   myColorGroupLine->setEnabled(on);
1118 }
1119
1120 //=================================================================================
1121 // function : setCurrentSelection()
1122 // purpose  :
1123 //=================================================================================
1124 void SMESHGUI_GroupDlg::setCurrentSelection()
1125 {
1126   QPushButton* send = (QPushButton*)sender();
1127   myCurrentLineEdit = 0;
1128   if (send == myMeshGroupBtn) {
1129     myCurrentLineEdit = myMeshGroupLine;
1130     if (myCreate)
1131       setSelectionMode(6);
1132     else
1133       setSelectionMode(5);
1134     onObjectSelectionChanged();
1135   }
1136   else if (send == mySubMeshBtn) {
1137     myCurrentLineEdit = mySubMeshLine;
1138     onObjectSelectionChanged();
1139   }
1140   else if (send == myGroupBtn) {
1141     myCurrentLineEdit = myGroupLine;
1142     onObjectSelectionChanged();
1143   }
1144   else if (send == myGeomGroupBtn) {
1145     myCurrentLineEdit = myGeomGroupLine;
1146     setSelectionMode(7);
1147     onObjectSelectionChanged();
1148   }
1149 }
1150
1151
1152 //=================================================================================
1153 // function : setFilters()
1154 // purpose  : SLOT. Called when "Filter" button pressed.
1155 //=================================================================================
1156 void SMESHGUI_GroupDlg::setFilters()
1157 {
1158   SMESH::ElementType aType = SMESH::ALL;
1159   switch ( myTypeId )
1160   {
1161     case 0 : aType = SMESH::NODE; break;
1162     case 1 : aType = SMESH::EDGE; break;
1163     case 2 : aType = SMESH::FACE; break;
1164     case 3 : aType = SMESH::VOLUME; break;
1165     default: return;
1166   }
1167
1168   if ( myFilterDlg == 0 )
1169   {
1170     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1171     connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1172   }
1173   else
1174     myFilterDlg->Init( aType );
1175
1176   myFilterDlg->SetSelection();
1177   myFilterDlg->SetMesh( myMesh );
1178   myFilterDlg->SetSourceWg( myElements );
1179
1180   myFilterDlg->show();
1181 }
1182
1183 //=================================================================================
1184 // function : onFilterAccepted()
1185 // purpose  : SLOT. Called when Filter dlg closed with OK button.
1186 //            Uncheck "Select submesh" and "Select group" checkboxes
1187 //=================================================================================
1188 void SMESHGUI_GroupDlg::onFilterAccepted()
1189 {
1190   if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1191   {
1192     mySelectionMode = myTypeId;
1193     mySelectSubMesh->setChecked( false );
1194     mySelectGroup->setChecked( false );
1195   }
1196 }
1197
1198 //=================================================================================
1199 // function : onAdd()
1200 // purpose  :
1201 //=================================================================================
1202 void SMESHGUI_GroupDlg::onAdd()
1203 {
1204   SALOME_ListIO aList;
1205   mySelectionMgr->selectedObjects( aList );
1206
1207   int aNbSel = aList.Extent();
1208
1209   if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1210
1211   myIsBusy = true;
1212
1213   SMESH::ElementType aType = SMESH::ALL;
1214   switch(myTypeId) {
1215   case 0: 
1216     aType = SMESH::NODE; 
1217     mySelector->SetSelectionMode(NodeSelection);
1218     break;
1219   case 1: 
1220     aType = SMESH::EDGE; 
1221     mySelector->SetSelectionMode(EdgeSelection);
1222     break;
1223   case 2: 
1224     aType = SMESH::FACE; 
1225     mySelector->SetSelectionMode(FaceSelection);
1226     break;
1227   case 3: 
1228     aType = SMESH::VOLUME; 
1229     mySelector->SetSelectionMode(VolumeSelection);
1230     break;
1231   default:
1232     mySelector->SetSelectionMode(ActorSelection);
1233   }
1234
1235
1236   if (myCurrentLineEdit == 0) {
1237     //if (aNbSel != 1) { myIsBusy = false; return; }
1238     QString aListStr = "";
1239     int aNbItems = 0;
1240     if (myTypeId == 0) {
1241       aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1242     }
1243     else {
1244       aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1245     }
1246     if (aNbItems > 0) {
1247       QStringList anElements = QStringList::split(" ", aListStr);
1248       QListBoxItem* anItem = 0;
1249       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1250         anItem = myElements->findItem(*it, Qt::ExactMatch);
1251         if (!anItem) {
1252           anItem = new QListBoxText(*it);
1253           myElements->insertItem(anItem);
1254         }
1255         myElements->setSelected(anItem, true);
1256       }
1257     }
1258   } else if (myCurrentLineEdit == mySubMeshLine) {
1259     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1260     
1261     SALOME_ListIO aList;
1262     mySelectionMgr->selectedObjects( aList );
1263
1264     SALOME_ListIteratorOfListIO anIt (aList);
1265     for (; anIt.More(); anIt.Next()) {
1266       SMESH::SMESH_subMesh_var aSubMesh =
1267         SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1268       if (!aSubMesh->_is_nil()) {
1269         // check if mesh is the same
1270         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1271           try {
1272             SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1273             int k = anElements->length();
1274             QListBoxItem* anItem = 0;
1275             for (int i = 0; i < k; i++) {
1276               QString aText = QString::number(anElements[i]);
1277               anItem = myElements->findItem(aText, Qt::ExactMatch);
1278               if (!anItem) {
1279                 anItem = new QListBoxText(aText);
1280                 myElements->insertItem(anItem);
1281               }
1282               myElements->setSelected(anItem, true);
1283             }
1284           }
1285           catch (const SALOME::SALOME_Exception& ex) {
1286             SalomeApp_Tools::QtCatchCorbaException(ex);
1287           }
1288         }
1289       }
1290     }
1291     mySelectSubMesh->setChecked(false);
1292     myIsBusy = false;
1293     onListSelectionChanged();
1294
1295   } else if (myCurrentLineEdit == myGroupLine) {
1296     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1297     SALOME_ListIO aList;
1298     mySelectionMgr->selectedObjects( aList );
1299     
1300     SALOME_ListIteratorOfListIO anIt (aList);
1301     for (; anIt.More(); anIt.Next()) {
1302       SMESH::SMESH_Group_var aGroup =
1303         SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1304       if (!aGroup->_is_nil()) {
1305         // check if mesh is the same
1306         if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1307           SMESH::long_array_var anElements = aGroup->GetListOfID();
1308           int k = anElements->length();
1309           QListBoxItem* anItem = 0;
1310           for (int i = 0; i < k; i++) {
1311             QString aText = QString::number(anElements[i]);
1312             anItem = myElements->findItem(aText, Qt::ExactMatch);
1313             if (!anItem) {
1314               anItem = new QListBoxText(aText);
1315               myElements->insertItem(anItem);
1316             }
1317             myElements->setSelected(anItem, true);
1318           }
1319         }
1320       }
1321     }
1322     mySelectGroup->setChecked(false);
1323     myIsBusy = false;
1324     onListSelectionChanged();
1325
1326   } else if (myCurrentLineEdit == myGeomGroupLine && !CORBA::is_nil(myGeomGroup)) {
1327     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1328     GEOM::GEOM_IGroupOperations_var aGroupOp =
1329       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1330
1331     SMESH::ElementType aGroupType = SMESH::ALL;
1332     switch(aGroupOp->GetType(myGeomGroup)) {
1333     case 7: aGroupType = SMESH::NODE; break;
1334     case 6: aGroupType = SMESH::EDGE; break;
1335     case 4: aGroupType = SMESH::FACE; break;
1336     case 2: aGroupType = SMESH::VOLUME; break;
1337     default: myIsBusy = false; return;
1338     }
1339
1340     if (aGroupType == aType) {
1341       _PTR(SObject) aGroupSO =
1342         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1343         aStudy->FindObjectID(myGeomGroup->GetStudyEntry());
1344       // Construct filter
1345       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1346       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1347       SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1348       aBelongToGeom->SetGeom(myGeomGroup);
1349       aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1350       aBelongToGeom->SetElementType(aType);
1351       aFilter->SetPredicate(aBelongToGeom);
1352
1353       SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1354
1355       int k = anElements->length();
1356       QListBoxItem* anItem = 0;
1357       for (int i = 0; i < k; i++) {
1358         QString aText = QString::number(anElements[i]);
1359         anItem = myElements->findItem(aText, Qt::ExactMatch);
1360         if (!anItem) {
1361           anItem = new QListBoxText(aText);
1362           myElements->insertItem(anItem);
1363         }
1364         myElements->setSelected(anItem, true);
1365       }
1366     }
1367
1368     //VSR: mySelectGeomGroup->setChecked(false);
1369     myIsBusy = false;
1370     onListSelectionChanged();
1371   }
1372   myIsBusy = false;
1373   //  mySelectionMgr->clearSelected();
1374   updateButtons();
1375 }
1376
1377 //=================================================================================
1378 // function : onRemove()
1379 // purpose  :
1380 //=================================================================================
1381 void SMESHGUI_GroupDlg::onRemove()
1382 {
1383   myIsBusy = true;
1384   if (myCurrentLineEdit == 0) {
1385     for (int i = myElements->count(); i > 0; i--) {
1386       if (myElements->isSelected(i-1)) {
1387         myElements->removeItem(i-1);
1388       }
1389     }
1390   } else {
1391     SALOME_ListIO aList;
1392     mySelectionMgr->selectedObjects( aList );
1393
1394     int aNbSel = aList.Extent();
1395
1396     if (aNbSel == 0) { myIsBusy = false; return; }
1397
1398     SMESH::ElementType aType = SMESH::ALL;
1399     switch(myTypeId) {
1400     case 0: aType = SMESH::NODE; break;
1401     case 1: aType = SMESH::EDGE; break;
1402     case 2: aType = SMESH::FACE; break;
1403     case 3: aType = SMESH::VOLUME; break;
1404     }
1405
1406     if (myCurrentLineEdit == mySubMeshLine) {
1407       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1408       SALOME_ListIO aList;
1409       mySelectionMgr->selectedObjects( aList );
1410
1411       SALOME_ListIteratorOfListIO anIt (aList);
1412       for (; anIt.More(); anIt.Next()) {
1413         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1414         if (!aSubMesh->_is_nil()) {
1415           // check if mesh is the same
1416           if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1417             if (aType == SMESH::NODE) {
1418               try {
1419                 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1420                 int k = anElements->length();
1421                 QListBoxItem* anItem = 0;
1422                 for (int i = 0; i < k; i++) {
1423                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1424                   if (anItem) delete anItem;
1425                 }
1426               }
1427               catch (const SALOME::SALOME_Exception& ex) {
1428                 SalomeApp_Tools::QtCatchCorbaException(ex);
1429               }
1430             }
1431             else {
1432               try {
1433                 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1434                 int k = anElements->length();
1435                 QListBoxItem* anItem = 0;
1436                 for (int i = 0; i < k; i++) {
1437                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1438                   if (anItem) delete anItem;
1439                 }
1440               }
1441               catch (const SALOME::SALOME_Exception& ex) {
1442                 SalomeApp_Tools::QtCatchCorbaException(ex);
1443               }
1444             }
1445           }
1446         }
1447       }
1448     }
1449     else if (myCurrentLineEdit == myGroupLine) {
1450       Standard_Boolean aRes;
1451       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1452       SALOME_ListIO aList;
1453       mySelectionMgr->selectedObjects( aList );
1454
1455       SALOME_ListIteratorOfListIO anIt (aList);
1456       for (; anIt.More(); anIt.Next()) {
1457         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1458         if (aRes && !aGroup->_is_nil()) {
1459           // check if mesh is the same
1460           if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1461             SMESH::long_array_var anElements = aGroup->GetListOfID();
1462             int k = anElements->length();
1463             QListBoxItem* anItem = 0;
1464             for (int i = 0; i < k; i++) {
1465               anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1466               if (anItem) delete anItem;
1467             }
1468           }
1469         }
1470       }
1471     }
1472   }
1473   myIsBusy = false;
1474   updateButtons();
1475 }
1476
1477 //=================================================================================
1478 // function : onSort()
1479 // purpose  :
1480 //=================================================================================
1481 void SMESHGUI_GroupDlg::onSort()
1482 {
1483   // PAL5412: sorts items in ascending by "string" value
1484   // myElements->sort(true);
1485   // myElements->update();
1486   int i, k = myElements->count();
1487   if (k > 0) {
1488     myIsBusy = true;
1489     QStringList aSelected;
1490     std::vector<int> anArray(k);
1491     //    QMemArray<int> anArray(k);
1492     QListBoxItem* anItem;
1493     // fill the array
1494     for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1495       anArray[i] = anItem->text().toInt();
1496       if (anItem->isSelected())
1497         aSelected.append(anItem->text());
1498     }
1499     // sort & update list
1500     std::sort(anArray.begin(), anArray.end());
1501     //    anArray.sort();
1502     myElements->clear();
1503     for (i = 0; i < k; i++) {
1504       myElements->insertItem(QString::number(anArray[i]));
1505     }
1506     for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1507       anItem = myElements->findItem(*it, Qt::ExactMatch);
1508       if (anItem) myElements->setSelected(anItem, true);
1509     }
1510     myIsBusy = false;
1511   }
1512 }
1513
1514 //=================================================================================
1515 // function : closeEvent()
1516 // purpose  :
1517 //=================================================================================
1518 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1519 {
1520   onClose();
1521 }
1522
1523 //=================================================================================
1524 // function : SMESHGUI_GroupDlg::onClose
1525 // purpose  : SLOT called when "Close" button pressed. Close dialog
1526 //=================================================================================
1527 void SMESHGUI_GroupDlg::onClose()
1528 {
1529   if (SMESH::GetCurrentVtkView()) {
1530     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1531     SMESH::SetPointRepresentation(false);
1532     SMESH::SetPickable();
1533   }
1534
1535   mySelectionMgr->clearSelected();
1536   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1537     aViewWindow->SetSelectionMode(ActorSelection);
1538   mySelectionMgr->clearFilters();
1539   mySMESHGUI->ResetState();
1540
1541   reject();
1542 }
1543
1544 //=================================================================================
1545 // function : SMESHGUI_GroupDlg::onDeactivate
1546 // purpose  : SLOT called when dialog must be deativated
1547 //=================================================================================
1548 void SMESHGUI_GroupDlg::onDeactivate()
1549 {
1550   mySMESHGUI->ResetState();
1551   setEnabled(false);
1552 }
1553
1554 //=================================================================================
1555 // function : SMESHGUI_GroupDlg::enterEvent
1556 // purpose  : Event filter
1557 //=================================================================================
1558 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1559 {
1560   if (!isEnabled()) {
1561     mySMESHGUI->EmitSignalDeactivateDialog();
1562     setEnabled(true);
1563     mySelectionMode = -1;
1564     setSelectionMode(myTypeId);
1565     //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1566     mySMESHGUI->SetActiveDialogBox(this);
1567     mySMESHGUI->SetState(800);
1568   }
1569 }
1570
1571 //=================================================================================
1572 // function : hideEvent
1573 // purpose  : caused by ESC key
1574 //=================================================================================
1575 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1576 {
1577   if (!isMinimized())
1578     onClose();
1579 }