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