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