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