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