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