Salome HOME
Update Help references (bug 17577)
[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.com
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 #include "SMESHGUI_ShapeByMeshDlg.h"
32
33 #include "SMESHGUI.h"
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_VTKUtils.h"
36 #include "SMESHGUI_MeshUtils.h"
37 #include "SMESHGUI_GroupUtils.h"
38 #include "SMESHGUI_FilterUtils.h"
39 #include "SMESHGUI_GEOMGenUtils.h"
40
41 #include "SMESH_TypeFilter.hxx"
42 #include "SMESH_Actor.h"
43 #include "SMESH_ActorUtils.h"
44
45 #include "GEOMBase.h"
46 #include "GEOM_SelectionFilter.h"
47
48 #include "SUIT_Desktop.h"
49 #include "SUIT_ResourceMgr.h"
50 #include "SUIT_Session.h"
51 #include "SUIT_MessageBox.h"
52
53 #include "SalomeApp_Tools.h"
54 #include "SalomeApp_Application.h"
55 #include "SalomeApp_Study.h"
56 #include "LightApp_Application.h"
57 #include "SALOMEDSClient_Study.hxx"
58 #include "SALOME_ListIO.hxx"
59 #include "SALOME_ListIteratorOfListIO.hxx"
60
61 #include "SVTK_ViewWindow.h"
62 #include "SVTK_Selector.h"
63
64 #include "utilities.h"
65
66 // OCCT Includes
67 #include <TColStd_MapOfInteger.hxx>
68
69 // QT Includes
70 #include <qbuttongroup.h>
71 #include <qcursor.h>
72 #include <qgroupbox.h>
73 #include <qhbox.h>
74 #include <qlabel.h>
75 #include <qlineedit.h>
76 #include <qpushbutton.h>
77 #include <qtoolbutton.h>
78 #include <qradiobutton.h>
79 #include <qcheckbox.h>
80 #include <qlayout.h>
81 #include <qlistbox.h>
82 #include <qimage.h>
83 #include <qpixmap.h>
84 #include <qmemarray.h>
85 #include <qwidgetstack.h>
86 #include <qcolordialog.h>
87
88 #include <QtxIntSpinBox.h>
89
90 // STL includes
91 #include <vector>
92 #include <algorithm>
93
94 using namespace std;
95
96 //=================================================================================
97 // function : SMESHGUI_GroupDlg()
98 // purpose  :
99 //=================================================================================
100 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
101                                       SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl)
102      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
103                 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
104      mySMESHGUI( theModule ),
105      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
106      mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
107      myIsBusy( false ),
108      myActor( 0 )
109 {
110   if (!name) setName("SMESHGUI_GroupDlg");
111   initDialog(true);
112   if (!theMesh->_is_nil())
113     init(theMesh);
114   else {
115     mySelectSubMesh->setEnabled(false);
116     mySelectGroup->setEnabled(false);
117     myGeomGroupBtn->setEnabled(false);
118     myGeomGroupLine->setEnabled(false);
119   }
120 }
121
122 //=================================================================================
123 // function : SMESHGUI_GroupDlg()
124 // purpose  :
125 //=================================================================================
126 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
127                                       SMESH::SMESH_GroupBase_ptr theGroup, bool modal, WFlags fl)
128      : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
129                 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
130      mySMESHGUI( theModule ),
131      mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
132      mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
133      myIsBusy( false )
134 {
135   if (!name) setName("SMESHGUI_GroupDlg");
136
137   initDialog(false);
138   if (!theGroup->_is_nil())
139     init(theGroup);
140   else {
141     mySelectSubMesh->setEnabled(false);
142     mySelectGroup->setEnabled(false);
143
144     myCurrentLineEdit = myMeshGroupLine;
145     setSelectionMode(5);
146   }
147 }
148
149 //=================================================================================
150 // function : SMESHGUI_GroupDlg()
151 // purpose  :
152 //=================================================================================
153 void SMESHGUI_GroupDlg::initDialog(bool create)
154 {
155   myFilterDlg = 0;
156   myCreate = create;
157   myCurrentLineEdit = 0;
158
159   myShapeByMeshOp = 0;
160   myGeomPopup = 0;
161   myGeomObjects = new GEOM::ListOfGO();
162   myGeomObjects->length(0);
163
164   QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
165
166   if (create) {
167     setCaption(tr("SMESH_CREATE_GROUP_TITLE"));
168     myHelpFileName = "creating_groups_page.html";
169   }
170   else {
171     setCaption(tr("SMESH_EDIT_GROUP_TITLE"));
172     myHelpFileName = "editing_groups_page.html";
173   }
174
175   setSizeGripEnabled(TRUE);
176
177   QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
178
179   /***************************************************************/
180   QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
181   if (create)
182     meshGroupLab->setText(tr("SMESH_MESH"));
183   else
184     meshGroupLab->setText(tr("SMESH_GROUP"));
185   myMeshGroupBtn = new QPushButton(this, "mesh/group button");
186   myMeshGroupBtn->setPixmap(image0);
187   myMeshGroupLine = new QLineEdit(this, "mesh/group line");
188   myMeshGroupLine->setReadOnly(true);
189
190   /***************************************************************/
191   myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
192   myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
193   myTypeGroup->setExclusive(true);
194
195   QStringList types;
196   types.append(tr("MESH_NODE"));
197   types.append(tr("SMESH_EDGE"));
198   types.append(tr("SMESH_FACE"));
199   types.append(tr("SMESH_VOLUME"));
200   QRadioButton* rb;
201   for (int i = 0; i < types.count(); i++) {
202     rb = new QRadioButton(types[i], myTypeGroup);
203   }
204   myTypeGroup->setEnabled(create);
205   myTypeId = -1;
206
207   /***************************************************************/
208   QLabel* aName = new QLabel(this, "name label");
209   aName->setText(tr("SMESH_NAME"));
210   aName->setMinimumSize(50,0);
211   myName = new QLineEdit(this, "name");
212
213   /***************************************************************/
214   myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
215   myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
216   myGrpTypeGroup->setExclusive(true);
217   QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
218   QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"),   myGrpTypeGroup);
219   myGrpTypeGroup->setEnabled(create);
220   myGrpTypeId = -1;
221
222   /***************************************************************/
223   myWGStack = new QWidgetStack( this, "widget stack");
224   QWidget* wg1 = new QFrame( myWGStack, "first widget" );
225   QWidget* wg2 = new QFrame( myWGStack, "second widget" );
226
227   /***************************************************************/
228   QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
229   aContentBox->setTitle(tr("SMESH_CONTENT"));
230   QFrame* aContent = new QFrame(aContentBox, "content");
231   QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
232   aLayout->setSpacing(6);
233   aLayout->setAutoAdd(false);
234
235   QLabel* aLabel = new QLabel(aContent, "elements label");
236   aLabel->setText(tr("SMESH_ID_ELEMENTS"));
237   myElements = new QListBox(aContent, "elements list");
238   myElements->setSelectionMode(QListBox::Extended);
239
240   myFilter = new QPushButton(aContent, "filter");
241   myFilter->setText(tr("SMESH_BUT_FILTER"));
242   QPushButton* aAddBtn = new QPushButton(aContent, "add");
243   aAddBtn->setText(tr("SMESH_BUT_ADD"));
244   QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
245   aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
246   QPushButton* aSortBtn = new QPushButton(aContent, "sort");
247   aSortBtn->setText(tr("SMESH_BUT_SORT"));
248
249   aLayout->addWidget(aLabel, 0, 0);
250   aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
251   aLayout->addWidget(myFilter, 1, 2);
252   aLayout->addWidget(aAddBtn, 3, 2);
253   aLayout->addWidget(aRemoveBtn, 4, 2);
254   aLayout->addWidget(aSortBtn, 6, 2);
255
256   aLayout->setColStretch(0, 1);
257   aLayout->addColSpacing(1, 20);
258   aLayout->addColSpacing(3, 20);
259   aLayout->setRowStretch(2, 1);
260   aLayout->setRowStretch(5, 1);
261
262   /***************************************************************/
263   QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
264   aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
265
266   mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
267   mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
268   mySelectSubMesh->setMinimumSize(50, 0);
269   mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
270   mySubMeshBtn->setText("");
271   mySubMeshBtn->setPixmap(image0);
272   mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
273   mySubMeshLine->setReadOnly(true);
274   onSelectSubMesh(false);
275
276   mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
277   mySelectGroup->setText(tr("SMESH_GROUP"));
278   mySelectGroup->setMinimumSize(50, 0);
279   myGroupBtn = new QPushButton(aSelectBox, "group button");
280   myGroupBtn->setText("");
281   myGroupBtn->setPixmap(image0);
282   myGroupLine = new QLineEdit(aSelectBox, "group line");
283   myGroupLine->setReadOnly(true);
284   onSelectGroup(false);
285   
286   /***************************************************************/
287   QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
288   wg1Layout->addWidget(aContentBox, 0, 0);
289   wg1Layout->addWidget(aSelectBox, 1, 0);
290   wg1Layout->setRowStretch(2, 5);
291
292   /***************************************************************/
293   QLabel* geomObject = new QLabel(wg2, "geometry object label");
294   geomObject->setText(tr("SMESH_OBJECT_GEOM"));
295   myGeomGroupBtn = new QToolButton(wg2, "geometry group button");
296   myGeomGroupBtn->setIconSet( QIconSet(image0) );
297   myGeomGroupBtn->setToggleButton(true);
298   myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
299   myGeomGroupLine->setReadOnly(true); //VSR ???
300   onSelectGeomGroup(false);
301   
302   if (!create)
303     {
304       myGeomGroupBtn->setEnabled(false);
305       myGeomGroupLine->setEnabled(false);
306     }
307    
308   /***************************************************************/
309   QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
310   wg2Layout->addWidget(geomObject,     0, 0);
311   wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
312   wg2Layout->addWidget(myGeomGroupLine,0, 2);
313   wg2Layout->setRowStretch(1, 5);
314
315   /***************************************************************/
316   QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
317   dumb->addWidget(wg1);
318   dumb->addWidget(wg2);
319   myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
320   myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
321
322   /***************************************************************/
323   QGroupBox* aColorBox = new QGroupBox(2, Qt::Horizontal, this, "color box");
324   aColorBox->setTitle(tr("SMESH_SET_COLOR"));
325
326   new QLabel( tr("SMESH_CHECK_COLOR"), aColorBox, "color label" );
327   myColorBtn = new QPushButton(aColorBox, "color button");
328   myColorBtn->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
329
330   /***************************************************************/
331   
332   QFrame* aButtons = new QFrame(this, "button box");
333   aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
334   QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
335   aBtnLayout->setAutoAdd(false);
336
337   QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
338   aOKBtn->setText(tr("SMESH_BUT_OK"));
339   aOKBtn->setAutoDefault(true);
340   aOKBtn->setDefault(true);
341   QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
342   aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
343   aApplyBtn->setAutoDefault(true);
344   QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
345   aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
346   aCloseBtn->setAutoDefault(true);
347   QPushButton* aHelpBtn = new QPushButton(aButtons, "help");
348   aHelpBtn->setText(tr("SMESH_BUT_HELP"));
349   aHelpBtn->setAutoDefault(true);
350
351   aBtnLayout->addWidget(aOKBtn);
352   aBtnLayout->addWidget(aApplyBtn);
353   aBtnLayout->addStretch();
354   aBtnLayout->addWidget(aCloseBtn);
355   aBtnLayout->addWidget(aHelpBtn);
356
357   /***************************************************************/
358   aMainLayout->addWidget(meshGroupLab,    0, 0);
359   aMainLayout->addWidget(myMeshGroupBtn,  0, 1);
360   aMainLayout->addWidget(myMeshGroupLine, 0, 2);
361   aMainLayout->addMultiCellWidget(myTypeGroup,    1, 1, 0, 2);
362   aMainLayout->addWidget(aName,      2, 0);
363   aMainLayout->addWidget(myName,     2, 2);
364   aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
365   aMainLayout->addMultiCellWidget(myWGStack,      4, 4, 0, 2);
366   aMainLayout->setRowStretch( 5, 5 );
367   aMainLayout->addMultiCellWidget(aColorBox,   6, 6, 0, 2);
368   aMainLayout->addMultiCellWidget(aButtons,       7, 7, 0, 2);
369
370   /* signals and slots connections */
371   connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
372
373   connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
374
375   connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
376
377   connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
378   connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
379
380   connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
381   connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
382   connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
383   connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
384
385   connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
386   connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
387   connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
388   connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
389   connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
390   connect(myColorBtn, SIGNAL(clicked()), this, SLOT(onSelectColor()));
391   
392   connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
393   connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
394   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
395   connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
396
397   /* Init selection */
398   mySMESHGUI->SetActiveDialogBox(this);
399   mySMESHGUI->SetState(800);
400
401   mySelectionMode = -1;
402   myMeshFilter = new SMESH_TypeFilter(MESH);
403   mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
404   myGroupFilter = new SMESH_TypeFilter(GROUP);
405   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
406   myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
407   
408   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
409   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
410   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
411
412   myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
413   onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
414
415   if (myMesh->_is_nil() )
416     myTypeGroup->setButton(0);
417
418   updateButtons();
419 }
420
421 //=================================================================================
422 // function : ~SMESHGUI_GroupDlg()
423 // purpose  : Destroys the object and frees any allocated resources
424 //=================================================================================
425 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
426 {
427   // no need to delete child widgets, Qt does it all for us
428   if ( myFilterDlg != 0 )
429   {
430     myFilterDlg->reparent( 0, QPoint() );
431     delete myFilterDlg;
432   }
433 }
434
435 //=================================================================================
436 // function : Init()
437 // purpose  :
438 //=================================================================================
439 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
440 {
441   mySelectionMgr->installFilter(myMeshFilter);
442
443   /* init data from current selection */
444   myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
445   myGroup = SMESH::SMESH_Group::_nil();
446   myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
447
448   myActor = SMESH::FindActorByObject(myMesh);
449   SMESH::SetPickable(myActor);
450
451   setDefaultGroupColor();
452
453   SALOME_ListIO aList;
454   mySelectionMgr->selectedObjects( aList );
455   if( !aList.IsEmpty() )
456   {
457     QString aName = aList.First()->getName();
458     myMeshGroupLine->setText(aName) ;
459     myMeshGroupLine->home( false );
460   }
461
462   myCurrentLineEdit = 0;
463
464   myTypeGroup->setButton(0);
465   onTypeChanged(0);
466 }
467
468 //=================================================================================
469 // function : Init()
470 // purpose  :
471 //=================================================================================
472 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
473 {
474   myMesh = theGroup->GetMesh();
475   
476   myName->setText(theGroup->GetName());
477   myName->home(false);
478
479   SALOMEDS::Color aColor = theGroup->GetColor();
480   setGroupColor( aColor );
481   
482   myMeshGroupLine->setText(theGroup->GetName());
483
484   int aType = 0;
485   switch(theGroup->GetType()) {
486   case SMESH::NODE: aType= 0; break;
487   case SMESH::EDGE: aType = 1; break;
488   case SMESH::FACE: aType = 2; break;
489   case SMESH::VOLUME: aType = 3; break;
490   }
491   myTypeGroup->setButton(aType);
492   
493   myGroup = SMESH::SMESH_Group::_narrow( theGroup );
494
495   if ( !myGroup->_is_nil() )
496     {
497       myActor = SMESH::FindActorByObject(myMesh);
498       if ( !myActor )
499         myActor = SMESH::FindActorByObject(myGroup);
500       SMESH::SetPickable(myActor);
501
502       myGrpTypeGroup->setButton(0);
503       onGrpTypeChanged(0);
504       
505       myCurrentLineEdit = 0;
506       myElements->clear();
507       setSelectionMode(aType);
508       myTypeId = aType;
509       
510       myIdList.clear();
511       if (!myGroup->IsEmpty()) {
512         SMESH::long_array_var anElements = myGroup->GetListOfID();
513         int k = anElements->length();
514         for (int i = 0; i < k; i++) {
515           myIdList.append(anElements[i]);
516           myElements->insertItem(QString::number(anElements[i]));
517         }
518         myElements->selectAll(true);
519       }
520     }
521   else
522     {
523       myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
524       
525       if ( !myGroupOnGeom->_is_nil() )
526         {
527           myActor = SMESH::FindActorByObject(myMesh);
528           if ( !myActor )
529             myActor = SMESH::FindActorByObject(myGroup);
530           SMESH::SetPickable(myActor);
531
532           myGrpTypeGroup->setButton(1);
533           onGrpTypeChanged(1);
534           
535           QString aShapeName("");
536           _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
537           GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
538           if (!aGroupShape->_is_nil())
539             {
540               _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
541               aShapeName = aGroupShapeSO->GetName().c_str();
542             }
543           myGeomGroupLine->setText( aShapeName );
544         }
545     }
546 }
547
548 //=================================================================================
549 // function : updateButtons()
550 // purpose  :
551 //=================================================================================
552 void SMESHGUI_GroupDlg::updateButtons()
553 {
554   bool enable = !myName->text().stripWhiteSpace().isEmpty();
555
556   if (myGrpTypeId == 0) {
557     enable = enable && myElements->count() > 0;
558     enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
559   }
560   else if (myGrpTypeId == 1) {
561     if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
562       enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
563     }
564   }
565
566   QPushButton* aBtn;
567   aBtn = (QPushButton*) child("ok", "QPushButton");
568   if (aBtn) aBtn->setEnabled(enable);
569   aBtn = (QPushButton*) child("apply", "QPushButton");
570   if (aBtn) aBtn->setEnabled(enable);
571 }
572
573 //=================================================================================
574 // function : onNameChanged()
575 // purpose  :
576 //=================================================================================
577 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
578 {
579   updateButtons();
580 }
581
582 //=================================================================================
583 // function : onTypeChanged()
584 // purpose  : Group elements type radio button management
585 //=================================================================================
586 void SMESHGUI_GroupDlg::onTypeChanged (int id)
587 {
588   if (myTypeId != id) {
589     myElements->clear();
590     if (myCurrentLineEdit == 0)
591       setSelectionMode(id);
592   }
593   myTypeId = id;
594 }
595
596 //=================================================================================
597 // function : onGrpTypeChanged()
598 // purpose  : Group type radio button management
599 //=================================================================================
600 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
601 {
602   if (myGrpTypeId != id) {
603     myWGStack->raiseWidget( id );
604     onSelectGeomGroup(id == 1);
605   }
606   myGrpTypeId = id;
607 }
608
609 //=================================================================================
610 // function : onSelectColor()
611 // purpose  :
612 //=================================================================================
613 void SMESHGUI_GroupDlg::onSelectColor()
614 {
615   QColor color = getGroupQColor();
616   color = QColorDialog::getColor( color );
617   setGroupQColor( color );
618
619   updateButtons();
620 }
621
622 //=================================================================================
623 // function : setSelectionMode()
624 // purpose  : Radio button management
625 //=================================================================================
626 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
627 {
628   // PAL7314
629   if (myMesh->_is_nil())
630     return;
631   if (mySelectionMode != theMode) {
632     // [PAL10408] mySelectionMgr->clearSelected();
633     mySelectionMgr->clearFilters();
634     if (myActor)
635       myActor->SetPointRepresentation(false);
636     else
637       SMESH::SetPointRepresentation(false);
638     if (theMode < 4) {
639       switch (theMode) {
640       case 0:
641         if (myActor)
642           myActor->SetPointRepresentation(true);
643         else
644           SMESH::SetPointRepresentation(true);
645         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
646           aViewWindow->SetSelectionMode(NodeSelection);
647         break;
648       case 1:
649         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
650           aViewWindow->SetSelectionMode(EdgeSelection);
651         break;
652       case 2:
653         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
654           aViewWindow->SetSelectionMode(FaceSelection);
655         break;
656       default:
657         if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
658           aViewWindow->SetSelectionMode(VolumeSelection);
659       }
660     } else {
661       if (theMode == 4)
662         mySelectionMgr->installFilter(mySubMeshFilter);
663       else if (theMode == 5)
664         mySelectionMgr->installFilter(myGroupFilter);
665       else if (theMode == 6)
666         mySelectionMgr->installFilter(myMeshFilter);
667       else if (theMode == 7)
668         mySelectionMgr->installFilter(myGeomFilter);
669       
670       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
671         aViewWindow->SetSelectionMode(ActorSelection);
672     }
673     mySelectionMode = theMode;
674   } 
675 }
676
677 //=================================================================================
678 // function : onApply()
679 // purpose  :
680 //=================================================================================
681 bool SMESHGUI_GroupDlg::onApply()
682 {
683   if (mySMESHGUI->isActiveStudyLocked())
684     return false;
685
686   if (myName->text().stripWhiteSpace().isEmpty())
687     return false;
688
689   if (myGrpTypeId == 0) { // on mesh elements
690     if (!myElements->count())
691       return false;
692
693     mySelectionMgr->clearSelected();
694
695     if (myGroup->_is_nil()) { // creation
696       if (myMesh->_is_nil())
697         return false;
698
699       SMESH::ElementType aType = SMESH::ALL;
700       switch (myTypeId) {
701       case 0: aType = SMESH::NODE; break;
702       case 1: aType = SMESH::EDGE; break;
703       case 2: aType = SMESH::FACE; break;
704       case 3: aType = SMESH::VOLUME; break;
705       }
706
707       SMESH::long_array_var anIdList = new SMESH::long_array;
708       int i, k = myElements->count();
709       anIdList->length(k);
710       QListBoxItem* anItem;
711       for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
712         anIdList[i] = anItem->text().toInt();
713       }
714
715       myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
716       myGroup->Add(anIdList.inout());
717
718       SALOMEDS::Color aColor = getGroupColor();
719       myGroup->SetColor(aColor);
720
721       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
722
723       //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
724       SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
725
726       /* init for next operation */
727       myName->setText("");
728       myElements->clear();
729       myGroup = SMESH::SMESH_Group::_nil();
730
731     } else { // edition
732       myGroup->SetName(myName->text());
733         
734       SALOMEDS::Color aColor = getGroupColor();
735       myGroup->SetColor(aColor);
736
737       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
738       if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
739         anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
740
741       QValueList<int> aAddList;
742       QValueList<int>::iterator anIt;
743       QListBoxItem* anItem;
744
745       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
746         int anId = anItem->text().toInt();
747         if ((anIt = myIdList.find(anId)) == myIdList.end())
748           aAddList.append(anId);
749         else
750           myIdList.remove(anIt);
751       }
752       if (!aAddList.empty()) {
753         SMESH::long_array_var anIdList = new SMESH::long_array;
754         anIdList->length(aAddList.count());
755         int i;
756         for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
757           anIdList[i] = *anIt;
758         myGroup->Add(anIdList.inout());
759       }
760       if (!myIdList.empty()) {
761         SMESH::long_array_var anIdList = new SMESH::long_array;
762         anIdList->length(myIdList.count());
763         int i;
764         for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
765           anIdList[i] = *anIt;
766         myGroup->Remove(anIdList.inout());
767       }
768       /* init for next operation */
769       myIdList.clear();
770       for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
771         myIdList.append(anItem->text().toInt());
772     }
773
774     mySMESHGUI->updateObjBrowser(true);
775     SMESH::UpdateView(); // asv: fix of BUG PAL5515
776     mySelectionMgr->clearSelected();
777     return true;
778   }
779   else if (myGrpTypeId == 1) { // on geom object
780     if (CORBA::is_nil(myGroupOnGeom)) { // creation
781       if (myMesh->_is_nil() || !myGeomObjects->length())
782         return false;
783
784       SMESH::ElementType aType = SMESH::ALL;
785       switch (myTypeId) {
786       case 0: aType = SMESH::NODE; break;
787       case 1: aType = SMESH::EDGE; break;
788       case 2: aType = SMESH::FACE; break;
789       case 3: aType = SMESH::VOLUME; break;
790       }
791
792       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
793       GEOM::GEOM_IGroupOperations_var aGroupOp =
794         SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
795
796       if (myGeomObjects->length() == 1) {
797         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
798       }
799       else {
800         SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
801         if ( aSMESHGen->_is_nil() )
802           return false;
803
804         // create a geometry group
805         GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
806         _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
807
808         if (geomGen->_is_nil() || !aStudy)
809           return false;
810
811         GEOM::GEOM_IGroupOperations_var op =
812           geomGen->GetIGroupOperations(aStudy->StudyId());
813         if (op->_is_nil())
814           return false;
815
816         // check and add all selected GEOM objects: they must be
817         // a sub-shapes of the main GEOM and must be of one type
818         TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
819         for ( int i =0; i < myGeomObjects->length(); i++) {
820           TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
821           if (i == 0)
822             aGroupType = aSubShapeType;
823           else if (aSubShapeType != aGroupType) {
824             aGroupType = TopAbs_SHAPE;
825             break;
826           }
827         }
828
829         GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
830         GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
831         op->UnionList(aGroupVar, myGeomObjects);
832
833         if (op->IsDone()) {
834           // publish the GEOM group in study
835           QString aNewGeomGroupName ("Auto_group_for_");
836           aNewGeomGroupName += myName->text();
837           SALOMEDS::SObject_var aNewGroupSO =
838             geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
839         }
840
841         myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
842       }
843
844       SALOMEDS::Color aColor = getGroupColor();
845       myGroupOnGeom->SetColor(aColor);
846
847       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
848
849       //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
850       SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
851
852       /* init for next operation */
853       myName->setText("");
854       myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
855     }
856     else { // edition
857       myGroupOnGeom->SetName(myName->text());
858
859       SALOMEDS::Color aColor = getGroupColor();
860       myGroupOnGeom->SetColor(aColor);
861
862       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
863       if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
864         anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
865     }
866
867     mySMESHGUI->updateObjBrowser(true);
868     mySelectionMgr->clearSelected();
869     return true;
870   }
871
872   return false;
873 }
874
875 //=================================================================================
876 // function : onOK()
877 // purpose  :
878 //=================================================================================
879 void SMESHGUI_GroupDlg::onOK()
880 {
881   if ( onApply() )
882     onClose();
883 }
884
885 //=================================================================================
886 // function : onListSelectionChanged()
887 // purpose  : Called when selection in element list is changed
888 //=================================================================================
889 void SMESHGUI_GroupDlg::onListSelectionChanged()
890 {
891   //  MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
892   if( myIsBusy || !myActor) return;
893     myIsBusy = true;
894
895   if (myCurrentLineEdit == 0) {
896     mySelectionMgr->clearSelected();
897     TColStd_MapOfInteger aIndexes;
898     QListBoxItem* anItem;
899     for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
900       if (anItem->isSelected()) {
901         int anId = anItem->text().toInt();
902         aIndexes.Add(anId);
903       }
904     }
905     mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
906     SALOME_ListIO aList;
907     aList.Append(myActor->getIO());
908     mySelectionMgr->setSelectedObjects(aList,false);
909   }
910   myIsBusy = false;
911 }
912
913 //=================================================================================
914 // function : onObjectSelectionChanged()
915 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
916 //=================================================================================
917 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
918 {
919   if ( myIsBusy || !isEnabled()) return;
920   if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
921
922   myIsBusy = true;
923
924   SALOME_ListIO aList;
925   mySelectionMgr->selectedObjects( aList );
926   
927   int aNbSel = aList.Extent();
928   myElements->clearSelection();
929
930   if (myCurrentLineEdit) {
931     myCurrentLineEdit->setText("");
932     QString aString = "";
933
934     if (myCurrentLineEdit == myMeshGroupLine) {
935       mySelectSubMesh->setEnabled(false);
936       mySelectGroup->setEnabled(false);
937       myGroupLine->setText("");
938       mySubMeshLine->setText("");
939
940       myGeomGroupBtn->setEnabled(false);
941       myGeomGroupLine->setEnabled(false);
942       myGeomGroupLine->setText("");
943       myGeomObjects = new GEOM::ListOfGO();
944       myGeomObjects->length(0);
945
946       if (myGeomGroupBtn->isOn())
947         myGeomGroupBtn->setOn(false);
948       if (!myCreate)
949         myName->setText("");
950
951       myElements->clear();
952
953       if (aNbSel != 1 ) {
954         myGroup = SMESH::SMESH_Group::_nil();
955         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil(); 
956         myMesh = SMESH::SMESH_Mesh::_nil();
957         updateGeomPopup();
958         updateButtons();
959         myIsBusy = false;
960         return;
961       }
962       Handle(SALOME_InteractiveObject) IO = aList.First();
963
964       if (myCreate) {
965         myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
966         updateGeomPopup();
967         if (myMesh->_is_nil())
968         {
969           updateButtons();
970           myIsBusy = false;
971           return;
972         }
973         myGroup = SMESH::SMESH_Group::_nil();
974
975         myActor = SMESH::FindActorByObject(myMesh);
976         SMESH::SetPickable(myActor);
977
978         aString = aList.First()->getName();
979         myMeshGroupLine->setText(aString) ;
980         myMeshGroupLine->home( false );
981
982         mySelectSubMesh->setEnabled(true);
983         mySelectGroup->setEnabled(true);
984         myGeomGroupBtn->setEnabled(true);
985         myGeomGroupLine->setEnabled(true);
986         updateButtons();
987       } else {
988         SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
989         if (aGroup->_is_nil())
990         {
991           myIsBusy = false;
992           return;
993         }
994         myIsBusy = false;
995         myCurrentLineEdit = 0;
996
997         myGroup = SMESH::SMESH_Group::_nil();
998         myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
999         
1000         init(aGroup);
1001         myIsBusy = true;
1002         mySelectSubMesh->setEnabled(true);
1003         mySelectGroup->setEnabled(true);
1004       }
1005       myCurrentLineEdit = 0;
1006       myIsBusy = false;
1007       if (!myCreate)
1008         return;
1009
1010       if (myGrpTypeId == 0)
1011         {
1012           if (myTypeId == -1)
1013             onTypeChanged(0);
1014           else
1015             {
1016               myElements->clear();
1017               setSelectionMode(myTypeId);
1018             }
1019         }
1020
1021       myIsBusy = false;
1022       return;
1023
1024     } else if (myCurrentLineEdit == myGeomGroupLine) {
1025
1026       myGeomObjects = new GEOM::ListOfGO();
1027
1028       // The mesh SObject
1029       _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1030
1031       if (aNbSel == 0 || !aMeshSO)
1032         {
1033           myGeomObjects->length(0);
1034           updateButtons();
1035           myIsBusy = false;
1036           return;
1037         }
1038
1039       myGeomObjects->length(aNbSel);
1040
1041       GEOM::GEOM_Object_var aGeomGroup;
1042       Standard_Boolean testResult;
1043       int i = 0;
1044       
1045       SALOME_ListIteratorOfListIO anIt (aList);
1046       for (; anIt.More(); anIt.Next()) {
1047         
1048         testResult = Standard_False;
1049         aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1050
1051         // Check if the object is a geometry group
1052         if (!testResult || CORBA::is_nil(aGeomGroup))
1053           continue;
1054         
1055
1056         // Check if group constructed on the same shape as a mesh or on its child
1057         _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1058         GEOM::GEOM_IGroupOperations_var anOp =
1059           SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1060
1061         // The main shape of the group
1062         GEOM::GEOM_Object_var aGroupMainShape;
1063         if (aGeomGroup->GetType() == 37)
1064           aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1065         else
1066           aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1067         _PTR(SObject) aGroupMainShapeSO =
1068           //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1069           aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1070         
1071         _PTR(SObject) anObj, aRef;
1072         bool isRefOrSubShape = false;
1073         if (aMeshSO->FindSubObject(1, anObj) &&  anObj->ReferencedObject(aRef)) {
1074           //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1075           if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1076             isRefOrSubShape = true;
1077           } else {
1078             _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1079             _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1080             //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1081             while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1082               //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1083               if (aRef->GetID() == aFather->GetID())
1084                 isRefOrSubShape = true;
1085               else
1086                 aFather = aFather->GetFather();
1087             }
1088           }
1089         }
1090         if (isRefOrSubShape)
1091           myGeomObjects[i++] = aGeomGroup;
1092       }
1093       
1094       myGeomObjects->length(i);
1095       if ( i == 0 )
1096         {
1097           myIsBusy = false;
1098           return;
1099         }
1100       
1101       aNbSel = i;
1102     }
1103
1104     if(aNbSel >= 1) {
1105       if(aNbSel > 1) {
1106         if(myCurrentLineEdit == mySubMeshLine)
1107           aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1108         else if(myCurrentLineEdit == myGroupLine)
1109           aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1110         else if(myCurrentLineEdit == myGeomGroupLine)
1111           aString = tr("%1 Objects").arg(aNbSel);
1112       } else {
1113         aString = aList.First()->getName();
1114       }
1115     }
1116
1117     myCurrentLineEdit->setText(aString);
1118     myCurrentLineEdit->home(false);
1119
1120     updateButtons();
1121
1122   } else {
1123     if (aNbSel == 1 && myActor ) {
1124       QString aListStr = "";
1125       int aNbItems = 0;
1126       if (myTypeId == 0) {
1127         aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1128       } else {
1129         aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1130       }
1131       if (aNbItems > 0) {
1132         QStringList anElements = QStringList::split(" ", aListStr);
1133         QListBoxItem* anItem = 0;
1134         for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1135           anItem = myElements->findItem(*it, Qt::ExactMatch);
1136           if (anItem) myElements->setSelected(anItem, true);
1137         }
1138       }
1139     }
1140   }
1141
1142   if (!myActor) {
1143     if (!myGroup->_is_nil())
1144       myActor = SMESH::FindActorByObject(myGroup);
1145     else if(!myGroupOnGeom->_is_nil())
1146       myActor = SMESH::FindActorByObject(myGroupOnGeom);
1147     else
1148       myActor = SMESH::FindActorByObject(myMesh);
1149   }
1150
1151   myIsBusy = false;
1152 }
1153
1154 //=================================================================================
1155 // function : onSelectSubMesh()
1156 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1157 //=================================================================================
1158 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1159 {
1160   if (on) {
1161     if (mySelectGroup->isChecked()) {
1162       mySelectGroup->setChecked(false);
1163     }
1164     //VSR: else if (mySelectGeomGroup->isChecked()) {
1165     //VSR:   mySelectGeomGroup->setChecked(false);
1166     //VSR: }
1167     myCurrentLineEdit = mySubMeshLine;
1168     setSelectionMode(4);
1169   }
1170   else {
1171     mySubMeshLine->setText("");
1172     myCurrentLineEdit = 0;
1173     if (myTypeId != -1)
1174       setSelectionMode(myTypeId);
1175   }
1176   mySubMeshBtn->setEnabled(on);
1177   mySubMeshLine->setEnabled(on);
1178 }
1179
1180
1181 //=================================================================================
1182 // function : (onSelectGroup)
1183 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1184 //=================================================================================
1185 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1186 {
1187   if (on) {
1188     if (mySelectSubMesh->isChecked()) {
1189       mySelectSubMesh->setChecked(false);
1190     }
1191     myCurrentLineEdit = myGroupLine;
1192     setSelectionMode(5);
1193   }
1194   else {
1195     myGroupLine->setText("");
1196     myCurrentLineEdit = 0;
1197     if (myTypeId != -1)
1198       setSelectionMode(myTypeId);
1199   }
1200   myGroupBtn->setEnabled(on);
1201   myGroupLine->setEnabled(on);
1202 }
1203
1204
1205 //=================================================================================
1206 // function : (onSelectGeomGroup)
1207 // purpose  : Called when selection in 3D view or ObjectBrowser is changed
1208 //=================================================================================
1209 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1210 {
1211   if (on) {
1212     if (mySelectSubMesh->isChecked()) {
1213       mySelectSubMesh->setChecked(false);
1214     }
1215     else if (mySelectGroup->isChecked()) {
1216       mySelectGroup->setChecked(false);
1217     }
1218     myCurrentLineEdit = myGeomGroupLine;
1219     updateGeomPopup();
1220     setSelectionMode(8);
1221   }
1222   else {
1223     myGeomGroupBtn->setOn(false);
1224     myGeomObjects->length(0);
1225     myGeomGroupLine->setText("");
1226     myCurrentLineEdit = 0;
1227     if (myTypeId != -1)
1228       setSelectionMode(myTypeId);
1229   }
1230 }
1231
1232
1233 //=================================================================================
1234 // function : setCurrentSelection()
1235 // purpose  :
1236 //=================================================================================
1237 void SMESHGUI_GroupDlg::setCurrentSelection()
1238 {
1239   QPushButton* send = (QPushButton*)sender();
1240   myCurrentLineEdit = 0;
1241   if (send == myMeshGroupBtn) {
1242     myCurrentLineEdit = myMeshGroupLine;
1243     if (myCreate)
1244       setSelectionMode(6);
1245     else
1246       setSelectionMode(5);
1247     onObjectSelectionChanged();
1248   }
1249   else if (send == mySubMeshBtn) {
1250     myCurrentLineEdit = mySubMeshLine;
1251     onObjectSelectionChanged();
1252   }
1253   else if (send == myGroupBtn) {
1254     myCurrentLineEdit = myGroupLine;
1255     onObjectSelectionChanged();
1256   }
1257 }
1258
1259
1260 //=================================================================================
1261 // function : setFilters()
1262 // purpose  : SLOT. Called when "Filter" button pressed.
1263 //=================================================================================
1264 void SMESHGUI_GroupDlg::setFilters()
1265 {
1266   SMESH::ElementType aType = SMESH::ALL;
1267   switch ( myTypeId )
1268   {
1269     case 0 : aType = SMESH::NODE; break;
1270     case 1 : aType = SMESH::EDGE; break;
1271     case 2 : aType = SMESH::FACE; break;
1272     case 3 : aType = SMESH::VOLUME; break;
1273     default: return;
1274   }
1275
1276   if ( myFilterDlg == 0 )
1277   {
1278     myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1279     connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1280   }
1281   else
1282     myFilterDlg->Init( aType );
1283
1284   myFilterDlg->SetSelection();
1285   myFilterDlg->SetMesh( myMesh );
1286   myFilterDlg->SetSourceWg( myElements );
1287
1288   myFilterDlg->show();
1289 }
1290
1291 //=================================================================================
1292 // function : onFilterAccepted()
1293 // purpose  : SLOT. Called when Filter dlg closed with OK button.
1294 //            Uncheck "Select submesh" and "Select group" checkboxes
1295 //=================================================================================
1296 void SMESHGUI_GroupDlg::onFilterAccepted()
1297 {
1298   if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1299   {
1300     mySelectionMode = myTypeId;
1301     mySelectSubMesh->setChecked( false );
1302     mySelectGroup->setChecked( false );
1303   }
1304 }
1305
1306 //=================================================================================
1307 // function : onAdd()
1308 // purpose  :
1309 //=================================================================================
1310 void SMESHGUI_GroupDlg::onAdd()
1311 {
1312   SALOME_ListIO aList;
1313   mySelectionMgr->selectedObjects( aList );
1314
1315   int aNbSel = aList.Extent();
1316
1317   if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1318
1319   myIsBusy = true;
1320
1321   SMESH::ElementType aType = SMESH::ALL;
1322   switch(myTypeId) {
1323   case 0: 
1324     aType = SMESH::NODE; 
1325     mySelector->SetSelectionMode(NodeSelection);
1326     break;
1327   case 1: 
1328     aType = SMESH::EDGE; 
1329     mySelector->SetSelectionMode(EdgeSelection);
1330     break;
1331   case 2: 
1332     aType = SMESH::FACE; 
1333     mySelector->SetSelectionMode(FaceSelection);
1334     break;
1335   case 3: 
1336     aType = SMESH::VOLUME; 
1337     mySelector->SetSelectionMode(VolumeSelection);
1338     break;
1339   default:
1340     mySelector->SetSelectionMode(ActorSelection);
1341   }
1342
1343
1344   if (myCurrentLineEdit == 0) {
1345     //if (aNbSel != 1) { myIsBusy = false; return; }
1346     QString aListStr = "";
1347     int aNbItems = 0;
1348     if (myTypeId == 0) {
1349       aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1350     }
1351     else {
1352       aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1353     }
1354     if (aNbItems > 0) {
1355       QStringList anElements = QStringList::split(" ", aListStr);
1356       QListBoxItem* anItem = 0;
1357       for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1358         anItem = myElements->findItem(*it, Qt::ExactMatch);
1359         if (!anItem) {
1360           anItem = new QListBoxText(*it);
1361           myElements->insertItem(anItem);
1362         }
1363         myElements->setSelected(anItem, true);
1364       }
1365     }
1366   } else if (myCurrentLineEdit == mySubMeshLine) {
1367     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1368     
1369     SALOME_ListIO aList;
1370     mySelectionMgr->selectedObjects( aList );
1371
1372     SALOME_ListIteratorOfListIO anIt (aList);
1373     for (; anIt.More(); anIt.Next()) {
1374       SMESH::SMESH_subMesh_var aSubMesh =
1375         SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1376       if (!aSubMesh->_is_nil()) {
1377         // check if mesh is the same
1378         if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1379           try {
1380             SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1381             int k = anElements->length();
1382             QListBoxItem* anItem = 0;
1383             for (int i = 0; i < k; i++) {
1384               QString aText = QString::number(anElements[i]);
1385               anItem = myElements->findItem(aText, Qt::ExactMatch);
1386               if (!anItem) {
1387                 anItem = new QListBoxText(aText);
1388                 myElements->insertItem(anItem);
1389               }
1390               myElements->setSelected(anItem, true);
1391             }
1392           }
1393           catch (const SALOME::SALOME_Exception& ex) {
1394             SalomeApp_Tools::QtCatchCorbaException(ex);
1395           }
1396         }
1397       }
1398     }
1399     mySelectSubMesh->setChecked(false);
1400     myIsBusy = false;
1401     onListSelectionChanged();
1402
1403   } else if (myCurrentLineEdit == myGroupLine) {
1404     //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1405     SALOME_ListIO aList;
1406     mySelectionMgr->selectedObjects( aList );
1407     
1408     SALOME_ListIteratorOfListIO anIt (aList);
1409     for (; anIt.More(); anIt.Next()) {
1410       SMESH::SMESH_Group_var aGroup =
1411         SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1412       if (!aGroup->_is_nil()) {
1413         // check if mesh is the same
1414         if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1415           SMESH::long_array_var anElements = aGroup->GetListOfID();
1416           int k = anElements->length();
1417           QListBoxItem* anItem = 0;
1418           for (int i = 0; i < k; i++) {
1419             QString aText = QString::number(anElements[i]);
1420             anItem = myElements->findItem(aText, Qt::ExactMatch);
1421             if (!anItem) {
1422               anItem = new QListBoxText(aText);
1423               myElements->insertItem(anItem);
1424             }
1425             myElements->setSelected(anItem, true);
1426           }
1427         }
1428       }
1429     }
1430     mySelectGroup->setChecked(false);
1431     myIsBusy = false;
1432     onListSelectionChanged();
1433
1434   } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1435     _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1436     GEOM::GEOM_IGroupOperations_var aGroupOp =
1437       SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1438
1439     SMESH::ElementType aGroupType = SMESH::ALL;
1440     switch(aGroupOp->GetType(myGeomObjects[0])) {
1441     case 7: aGroupType = SMESH::NODE; break;
1442     case 6: aGroupType = SMESH::EDGE; break;
1443     case 4: aGroupType = SMESH::FACE; break;
1444     case 2: aGroupType = SMESH::VOLUME; break;
1445     default: myIsBusy = false; return;
1446     }
1447
1448     if (aGroupType == aType) {
1449       _PTR(SObject) aGroupSO =
1450         //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1451         aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1452       // Construct filter
1453       SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1454       SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1455       SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1456       aBelongToGeom->SetGeom(myGeomObjects[0]);
1457       aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1458       aBelongToGeom->SetElementType(aType);
1459       aFilter->SetPredicate(aBelongToGeom);
1460
1461       SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1462
1463       int k = anElements->length();
1464       QListBoxItem* anItem = 0;
1465       for (int i = 0; i < k; i++) {
1466         QString aText = QString::number(anElements[i]);
1467         anItem = myElements->findItem(aText, Qt::ExactMatch);
1468         if (!anItem) {
1469           anItem = new QListBoxText(aText);
1470           myElements->insertItem(anItem);
1471         }
1472         myElements->setSelected(anItem, true);
1473       }
1474     }
1475
1476     //VSR: mySelectGeomGroup->setChecked(false);
1477     myIsBusy = false;
1478     onListSelectionChanged();
1479   }
1480   myIsBusy = false;
1481   //  mySelectionMgr->clearSelected();
1482   updateButtons();
1483 }
1484
1485 //=================================================================================
1486 // function : onRemove()
1487 // purpose  :
1488 //=================================================================================
1489 void SMESHGUI_GroupDlg::onRemove()
1490 {
1491   myIsBusy = true;
1492   if (myCurrentLineEdit == 0) {
1493     for (int i = myElements->count(); i > 0; i--) {
1494       if (myElements->isSelected(i-1)) {
1495         myElements->removeItem(i-1);
1496       }
1497     }
1498   } else {
1499     SALOME_ListIO aList;
1500     mySelectionMgr->selectedObjects( aList );
1501
1502     int aNbSel = aList.Extent();
1503
1504     if (aNbSel == 0) { myIsBusy = false; return; }
1505
1506     SMESH::ElementType aType = SMESH::ALL;
1507     switch(myTypeId) {
1508     case 0: aType = SMESH::NODE; break;
1509     case 1: aType = SMESH::EDGE; break;
1510     case 2: aType = SMESH::FACE; break;
1511     case 3: aType = SMESH::VOLUME; break;
1512     }
1513
1514     if (myCurrentLineEdit == mySubMeshLine) {
1515       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1516       SALOME_ListIO aList;
1517       mySelectionMgr->selectedObjects( aList );
1518
1519       SALOME_ListIteratorOfListIO anIt (aList);
1520       for (; anIt.More(); anIt.Next()) {
1521         SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1522         if (!aSubMesh->_is_nil()) {
1523           // check if mesh is the same
1524           if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1525             if (aType == SMESH::NODE) {
1526               try {
1527                 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1528                 int k = anElements->length();
1529                 QListBoxItem* anItem = 0;
1530                 for (int i = 0; i < k; i++) {
1531                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1532                   if (anItem) delete anItem;
1533                 }
1534               }
1535               catch (const SALOME::SALOME_Exception& ex) {
1536                 SalomeApp_Tools::QtCatchCorbaException(ex);
1537               }
1538             }
1539             else {
1540               try {
1541                 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1542                 int k = anElements->length();
1543                 QListBoxItem* anItem = 0;
1544                 for (int i = 0; i < k; i++) {
1545                   anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1546                   if (anItem) delete anItem;
1547                 }
1548               }
1549               catch (const SALOME::SALOME_Exception& ex) {
1550                 SalomeApp_Tools::QtCatchCorbaException(ex);
1551               }
1552             }
1553           }
1554         }
1555       }
1556     }
1557     else if (myCurrentLineEdit == myGroupLine) {
1558       Standard_Boolean aRes;
1559       //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1560       SALOME_ListIO aList;
1561       mySelectionMgr->selectedObjects( aList );
1562
1563       SALOME_ListIteratorOfListIO anIt (aList);
1564       for (; anIt.More(); anIt.Next()) {
1565         SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1566         if (aRes && !aGroup->_is_nil()) {
1567           // check if mesh is the same
1568           if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1569             SMESH::long_array_var anElements = aGroup->GetListOfID();
1570             int k = anElements->length();
1571             QListBoxItem* anItem = 0;
1572             for (int i = 0; i < k; i++) {
1573               anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1574               if (anItem) delete anItem;
1575             }
1576           }
1577         }
1578       }
1579     }
1580   }
1581   myIsBusy = false;
1582   updateButtons();
1583 }
1584
1585 //=================================================================================
1586 // function : onSort()
1587 // purpose  :
1588 //=================================================================================
1589 void SMESHGUI_GroupDlg::onSort()
1590 {
1591   // PAL5412: sorts items in ascending by "string" value
1592   // myElements->sort(true);
1593   // myElements->update();
1594   int i, k = myElements->count();
1595   if (k > 0) {
1596     myIsBusy = true;
1597     QStringList aSelected;
1598     std::vector<int> anArray(k);
1599     //    QMemArray<int> anArray(k);
1600     QListBoxItem* anItem;
1601     // fill the array
1602     for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1603       anArray[i] = anItem->text().toInt();
1604       if (anItem->isSelected())
1605         aSelected.append(anItem->text());
1606     }
1607     // sort & update list
1608     std::sort(anArray.begin(), anArray.end());
1609     //    anArray.sort();
1610     myElements->clear();
1611     for (i = 0; i < k; i++) {
1612       myElements->insertItem(QString::number(anArray[i]));
1613     }
1614     for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1615       anItem = myElements->findItem(*it, Qt::ExactMatch);
1616       if (anItem) myElements->setSelected(anItem, true);
1617     }
1618     myIsBusy = false;
1619   }
1620 }
1621
1622 //=================================================================================
1623 // function : closeEvent()
1624 // purpose  :
1625 //=================================================================================
1626 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1627 {
1628   onClose();
1629 }
1630
1631 //=================================================================================
1632 // function : SMESHGUI_GroupDlg::onClose
1633 // purpose  : SLOT called when "Close" button pressed. Close dialog
1634 //=================================================================================
1635 void SMESHGUI_GroupDlg::onClose()
1636 {
1637   if (SMESH::GetCurrentVtkView()) {
1638     SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1639     SMESH::SetPointRepresentation(false);
1640     SMESH::SetPickable();
1641   }
1642
1643   mySelectionMgr->clearSelected();
1644   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1645     aViewWindow->SetSelectionMode(ActorSelection);
1646   mySelectionMgr->clearFilters();
1647   mySMESHGUI->ResetState();
1648
1649   reject();
1650 }
1651
1652 //=================================================================================
1653 // function : onHelp()
1654 // purpose  :
1655 //=================================================================================
1656 void SMESHGUI_GroupDlg::onHelp()
1657 {
1658   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1659   if (app) 
1660     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1661   else {
1662                 QString platform;
1663 #ifdef WIN32
1664                 platform = "winapplication";
1665 #else
1666                 platform = "application";
1667 #endif
1668     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1669                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1670                            arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
1671                            QObject::tr("BUT_OK"));
1672   }
1673 }
1674
1675 //=================================================================================
1676 // function : SMESHGUI_GroupDlg::onDeactivate
1677 // purpose  : SLOT called when dialog must be deativated
1678 //=================================================================================
1679 void SMESHGUI_GroupDlg::onDeactivate()
1680 {
1681   mySMESHGUI->ResetState();
1682   setEnabled(false);
1683 }
1684
1685 //=================================================================================
1686 // function : SMESHGUI_GroupDlg::enterEvent
1687 // purpose  : Event filter
1688 //=================================================================================
1689 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1690 {
1691   if (!isEnabled()) {
1692     mySMESHGUI->EmitSignalDeactivateDialog();
1693     setEnabled(true);
1694     mySelectionMode = -1;
1695     setSelectionMode(myTypeId);
1696     //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1697     mySMESHGUI->SetActiveDialogBox(this);
1698     mySMESHGUI->SetState(800);
1699   }
1700 }
1701
1702 //=================================================================================
1703 // function : hideEvent
1704 // purpose  : caused by ESC key
1705 //=================================================================================
1706 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1707 {
1708   if (!isMinimized() && !myIsBusy)
1709     onClose();
1710 }
1711
1712 //=================================================================================
1713 // function : keyPressEvent()
1714 // purpose  :
1715 //=================================================================================
1716 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1717 {
1718   QDialog::keyPressEvent( e );
1719   if ( e->isAccepted() )
1720     return;
1721
1722   if ( e->key() == Key_F1 )
1723     {
1724       e->accept();
1725       onHelp();
1726     }
1727 }
1728
1729 //================================================================================
1730 /*!
1731  * \brief Enable showing of the popup when Geometry selection btn is clicked
1732   * \param enable - true to enable
1733  */
1734 //================================================================================
1735
1736 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1737
1738 void SMESHGUI_GroupDlg::updateGeomPopup()
1739 {
1740   bool enable = false;
1741
1742   if ( !myMesh->_is_nil() )
1743     enable = myMesh->NbEdges() > 0;
1744
1745   if ( myGeomGroupBtn )
1746   {
1747     disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1748     if ( enable ) {
1749       if ( !myGeomPopup ) {
1750         myGeomPopup = new QPopupMenu();
1751         myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
1752         myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
1753         connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
1754       }
1755       connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1756     }
1757   }
1758 }
1759
1760
1761 //=================================================================================
1762 // function : onGeomSelectionButton()
1763 // purpose  :
1764 //=================================================================================
1765 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1766 {
1767   if ( myGeomPopup && isBtnOn )
1768     {
1769       myCurrentLineEdit = myGeomGroupLine;
1770       int id = myGeomPopup->exec( QCursor::pos() );
1771       if (id == DIRECT_GEOM_INDEX || id == -1)
1772         setSelectionMode(7);
1773     }
1774   else if (!isBtnOn)
1775     {
1776       myCurrentLineEdit = 0;
1777       setSelectionMode(8);
1778     }
1779 }
1780
1781 //=================================================================================
1782 // function : onGeomPopup()
1783 // purpose  :
1784 //=================================================================================
1785 void SMESHGUI_GroupDlg::onGeomPopup( int index )
1786 {
1787   if ( index == GEOM_BY_MESH_INDEX )
1788     {
1789       mySelectionMode = -1;
1790       if ( !myShapeByMeshOp ) {
1791         myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1792         connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1793                 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1794         connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1795                 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1796       }
1797       // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1798       if ( !myMesh->_is_nil() ) {
1799         myIsBusy = true;
1800         hide(); // stop processing selection
1801         myIsBusy = false;
1802         myShapeByMeshOp->setModule( mySMESHGUI );
1803         myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1804         myShapeByMeshOp->SetMesh( myMesh );
1805         myShapeByMeshOp->start();
1806       }
1807     }
1808 }
1809
1810 //================================================================================
1811 /*!
1812  * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1813  */
1814 //================================================================================
1815
1816 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1817 {
1818   if ( myShapeByMeshOp == op ) {
1819     mySMESHGUI->getApp()->updateObjectBrowser();
1820     show();
1821     // Select a found geometry object
1822     GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1823     if ( !aGeomVar->_is_nil() )
1824     {
1825       QString ID = aGeomVar->GetStudyEntry();
1826       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1827       if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
1828         SALOME_ListIO anIOList;
1829         Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1830           ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1831         anIOList.Append( anIO );
1832         mySelectionMgr->setSelectedObjects( anIOList, false );
1833         onObjectSelectionChanged();
1834       }
1835     }
1836   }
1837 }
1838
1839 //================================================================================
1840 /*!
1841  * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1842  */
1843 //================================================================================
1844
1845 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1846 {
1847   if ( myShapeByMeshOp == op )
1848     {
1849       show();
1850       setSelectionMode(7);
1851     }
1852 }
1853
1854 //=================================================================================
1855 // function : setGroupColor()
1856 // purpose  :
1857 //=================================================================================
1858 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
1859 {
1860   QColor aQColor( (int)( theColor.R * 255.0 ),
1861                   (int)( theColor.G * 255.0 ),
1862                   (int)( theColor.B * 255.0 ) );
1863   setGroupQColor( aQColor );
1864 }
1865
1866 //=================================================================================
1867 // function : getGroupColor()
1868 // purpose  :
1869 //=================================================================================
1870 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
1871 {
1872   QColor aQColor = getGroupQColor();
1873
1874   SALOMEDS::Color aColor;
1875   aColor.R = (float)aQColor.red() / 255.0;
1876   aColor.G = (float)aQColor.green() / 255.0;
1877   aColor.B = (float)aQColor.blue() / 255.0;
1878
1879   return aColor;
1880 }
1881
1882 //=================================================================================
1883 // function : setGroupQColor()
1884 // purpose  :
1885 //=================================================================================
1886 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
1887 {
1888   if( theColor.isValid() )
1889   {
1890     QPalette pal = myColorBtn->palette();
1891     pal.setColor(QColorGroup::Button, theColor);
1892     myColorBtn->setPalette(pal);
1893   }
1894 }
1895
1896 //=================================================================================
1897 // function : getGroupQColor()
1898 // purpose  :
1899 //=================================================================================
1900 QColor SMESHGUI_GroupDlg::getGroupQColor() const
1901 {
1902   QColor aColor = myColorBtn->palette().active().button();
1903   return aColor;
1904 }
1905
1906 //=================================================================================
1907 // function : setDefaultGroupColor()
1908 // purpose  :
1909 //=================================================================================
1910 void SMESHGUI_GroupDlg::setDefaultGroupColor()
1911 {
1912   if( myMesh->_is_nil() )
1913     return;
1914
1915   bool isAutoColor = myMesh->GetAutoColor();
1916
1917   QColor aQColor;
1918   if( !isAutoColor )
1919   {
1920     int r = 0, g = 0, b = 0;
1921     SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
1922     aQColor.setRgb( r, g, b );
1923   }
1924   else
1925   {
1926     SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
1927
1928     QValueList<SALOMEDS::Color> aReservedColors;
1929     for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1930     {
1931       SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1932       SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
1933       aReservedColors.append( aReservedColor );
1934     }
1935
1936     SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1937     aQColor.setRgb( (int)( aColor.R * 255.0 ),
1938                     (int)( aColor.G * 255.0 ),
1939                     (int)( aColor.B * 255.0 ) );
1940
1941   }
1942
1943   setGroupQColor( aQColor );
1944 }