1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESHGUI_GroupDlg.cxx
25 // Author : Natalia KOPNOVA
29 #include "SMESHGUI_GroupDlg.h"
30 #include "SMESHGUI_FilterDlg.h"
31 #include "SMESHGUI_ShapeByMeshDlg.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"
41 #include "SMESH_TypeFilter.hxx"
42 #include "SMESH_Actor.h"
45 #include "GEOM_SelectionFilter.h"
47 #include "SUIT_Desktop.h"
48 #include "SUIT_ResourceMgr.h"
49 #include "SUIT_Session.h"
50 #include "SUIT_MessageBox.h"
52 #include "SalomeApp_Tools.h"
53 #include "SalomeApp_Application.h"
54 #include "SalomeApp_Study.h"
55 #include "LightApp_Application.h"
56 #include "SALOMEDSClient_Study.hxx"
57 #include "SALOME_ListIO.hxx"
58 #include "SALOME_ListIteratorOfListIO.hxx"
60 #include "SVTK_ViewWindow.h"
61 #include "SVTK_Selector.h"
63 #include "utilities.h"
66 #include <TColStd_MapOfInteger.hxx>
69 #include <qbuttongroup.h>
71 #include <qgroupbox.h>
74 #include <qlineedit.h>
75 #include <qpushbutton.h>
76 #include <qtoolbutton.h>
77 #include <qradiobutton.h>
78 #include <qcheckbox.h>
83 #include <qmemarray.h>
84 #include <qwidgetstack.h>
86 #include <QtxIntSpinBox.h>
95 //=================================================================================
96 // function : SMESHGUI_GroupDlg()
98 //=================================================================================
99 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
100 SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl)
101 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
102 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
103 mySMESHGUI( theModule ),
104 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
105 mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
109 if (!name) setName("SMESHGUI_GroupDlg");
111 if (!theMesh->_is_nil())
114 mySelectSubMesh->setEnabled(false);
115 mySelectGroup->setEnabled(false);
116 myGeomGroupBtn->setEnabled(false);
117 myGeomGroupLine->setEnabled(false);
121 //=================================================================================
122 // function : SMESHGUI_GroupDlg()
124 //=================================================================================
125 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
126 SMESH::SMESH_GroupBase_ptr theGroup, bool modal, WFlags fl)
127 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
128 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
129 mySMESHGUI( theModule ),
130 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
131 mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
134 if (!name) setName("SMESHGUI_GroupDlg");
137 if (!theGroup->_is_nil())
140 mySelectSubMesh->setEnabled(false);
141 mySelectGroup->setEnabled(false);
143 myCurrentLineEdit = myMeshGroupLine;
148 //=================================================================================
149 // function : SMESHGUI_GroupDlg()
151 //=================================================================================
152 void SMESHGUI_GroupDlg::initDialog(bool create)
156 myCurrentLineEdit = 0;
160 myGeomObjects = new GEOM::ListOfGO();
161 myGeomObjects->length(0);
163 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
166 setCaption(tr("SMESH_CREATE_GROUP_TITLE"));
167 myHelpFileName = "/files/creating_groups.htm";
170 setCaption(tr("SMESH_EDIT_GROUP_TITLE"));
171 myHelpFileName = "/files/editing_groups.htm";
174 setSizeGripEnabled(TRUE);
176 QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
178 /***************************************************************/
179 QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
181 meshGroupLab->setText(tr("SMESH_MESH"));
183 meshGroupLab->setText(tr("SMESH_GROUP"));
184 myMeshGroupBtn = new QPushButton(this, "mesh/group button");
185 myMeshGroupBtn->setPixmap(image0);
186 myMeshGroupLine = new QLineEdit(this, "mesh/group line");
187 myMeshGroupLine->setReadOnly(true);
189 /***************************************************************/
190 myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
191 myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
192 myTypeGroup->setExclusive(true);
195 types.append(tr("MESH_NODE"));
196 types.append(tr("SMESH_EDGE"));
197 types.append(tr("SMESH_FACE"));
198 types.append(tr("SMESH_VOLUME"));
200 for (int i = 0; i < types.count(); i++) {
201 rb = new QRadioButton(types[i], myTypeGroup);
203 myTypeGroup->setEnabled(create);
206 /***************************************************************/
207 QLabel* aName = new QLabel(this, "name label");
208 aName->setText(tr("SMESH_NAME"));
209 aName->setMinimumSize(50,0);
210 myName = new QLineEdit(this, "name");
212 /***************************************************************/
213 myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
214 myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
215 myGrpTypeGroup->setExclusive(true);
216 QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
217 QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"), myGrpTypeGroup);
218 myGrpTypeGroup->setEnabled(create);
221 /***************************************************************/
222 myWGStack = new QWidgetStack( this, "widget stack");
223 QWidget* wg1 = new QFrame( myWGStack, "first widget" );
224 QWidget* wg2 = new QFrame( myWGStack, "second widget" );
226 /***************************************************************/
227 QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
228 aContentBox->setTitle(tr("SMESH_CONTENT"));
229 QFrame* aContent = new QFrame(aContentBox, "content");
230 QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
231 aLayout->setSpacing(6);
232 aLayout->setAutoAdd(false);
234 QLabel* aLabel = new QLabel(aContent, "elements label");
235 aLabel->setText(tr("SMESH_ID_ELEMENTS"));
236 myElements = new QListBox(aContent, "elements list");
237 myElements->setSelectionMode(QListBox::Extended);
239 myFilter = new QPushButton(aContent, "filter");
240 myFilter->setText(tr("SMESH_BUT_FILTER"));
241 QPushButton* aAddBtn = new QPushButton(aContent, "add");
242 aAddBtn->setText(tr("SMESH_BUT_ADD"));
243 QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
244 aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
245 QPushButton* aSortBtn = new QPushButton(aContent, "sort");
246 aSortBtn->setText(tr("SMESH_BUT_SORT"));
248 aLayout->addWidget(aLabel, 0, 0);
249 aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
250 aLayout->addWidget(myFilter, 1, 2);
251 aLayout->addWidget(aAddBtn, 3, 2);
252 aLayout->addWidget(aRemoveBtn, 4, 2);
253 aLayout->addWidget(aSortBtn, 6, 2);
255 aLayout->setColStretch(0, 1);
256 aLayout->addColSpacing(1, 20);
257 aLayout->addColSpacing(3, 20);
258 aLayout->setRowStretch(2, 1);
259 aLayout->setRowStretch(5, 1);
261 /***************************************************************/
262 QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
263 aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
265 mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
266 mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
267 mySelectSubMesh->setMinimumSize(50, 0);
268 mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
269 mySubMeshBtn->setText("");
270 mySubMeshBtn->setPixmap(image0);
271 mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
272 mySubMeshLine->setReadOnly(true);
273 onSelectSubMesh(false);
275 mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
276 mySelectGroup->setText(tr("SMESH_GROUP"));
277 mySelectGroup->setMinimumSize(50, 0);
278 myGroupBtn = new QPushButton(aSelectBox, "group button");
279 myGroupBtn->setText("");
280 myGroupBtn->setPixmap(image0);
281 myGroupLine = new QLineEdit(aSelectBox, "group line");
282 myGroupLine->setReadOnly(true);
283 onSelectGroup(false);
285 /***************************************************************/
286 QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
287 wg1Layout->addWidget(aContentBox, 0, 0);
288 wg1Layout->addWidget(aSelectBox, 1, 0);
289 wg1Layout->setRowStretch(2, 5);
291 /***************************************************************/
292 QLabel* geomObject = new QLabel(wg2, "geometry object label");
293 geomObject->setText(tr("SMESH_OBJECT_GEOM"));
294 myGeomGroupBtn = new QToolButton(wg2, "geometry group button");
295 myGeomGroupBtn->setIconSet( QIconSet(image0) );
296 myGeomGroupBtn->setToggleButton(true);
297 myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
298 myGeomGroupLine->setReadOnly(true); //VSR ???
299 onSelectGeomGroup(false);
303 myGeomGroupBtn->setEnabled(false);
304 myGeomGroupLine->setEnabled(false);
307 /***************************************************************/
308 QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
309 wg2Layout->addWidget(geomObject, 0, 0);
310 wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
311 wg2Layout->addWidget(myGeomGroupLine,0, 2);
312 wg2Layout->setRowStretch(1, 5);
314 /***************************************************************/
315 QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
316 dumb->addWidget(wg1);
317 dumb->addWidget(wg2);
318 myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
319 myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
321 /***************************************************************/
322 QGroupBox* aColorBox = new QGroupBox(2, Qt::Horizontal, this, "color box");
323 aColorBox->setTitle(tr("SMESH_SET_COLOR"));
325 mySelectColorGroup = new QCheckBox(aColorBox, "color checkbox");
326 mySelectColorGroup->setText(tr("SMESH_CHECK_COLOR"));
328 myColorSpinBox = new QtxIntSpinBox( aColorBox );
329 myColorSpinBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
330 myColorSpinBox->setMinValue( 0 );
331 myColorSpinBox->setMaxValue( 9999 );
333 onSelectColorGroup(false);
335 /***************************************************************/
337 QFrame* aButtons = new QFrame(this, "button box");
338 aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
339 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
340 aBtnLayout->setAutoAdd(false);
342 QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
343 aOKBtn->setText(tr("SMESH_BUT_OK"));
344 aOKBtn->setAutoDefault(true);
345 aOKBtn->setDefault(true);
346 QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
347 aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
348 aApplyBtn->setAutoDefault(true);
349 QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
350 aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
351 aCloseBtn->setAutoDefault(true);
352 QPushButton* aHelpBtn = new QPushButton(aButtons, "help");
353 aHelpBtn->setText(tr("SMESH_BUT_HELP"));
354 aHelpBtn->setAutoDefault(true);
356 aBtnLayout->addWidget(aOKBtn);
357 aBtnLayout->addWidget(aApplyBtn);
358 aBtnLayout->addStretch();
359 aBtnLayout->addWidget(aCloseBtn);
360 aBtnLayout->addWidget(aHelpBtn);
362 /***************************************************************/
363 aMainLayout->addWidget(meshGroupLab, 0, 0);
364 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
365 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
366 aMainLayout->addMultiCellWidget(myTypeGroup, 1, 1, 0, 2);
367 aMainLayout->addWidget(aName, 2, 0);
368 aMainLayout->addWidget(myName, 2, 2);
369 aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
370 aMainLayout->addMultiCellWidget(myWGStack, 4, 4, 0, 2);
371 aMainLayout->setRowStretch( 5, 5 );
372 aMainLayout->addMultiCellWidget(aColorBox, 6, 6, 0, 2);
373 aMainLayout->addMultiCellWidget(aButtons, 7, 7, 0, 2);
375 /* signals and slots connections */
376 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
378 connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
380 connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
382 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
383 connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
385 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
386 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
387 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
388 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
390 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
391 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
392 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
393 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
394 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
395 connect(mySelectColorGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectColorGroup(bool)));
396 connect(myColorSpinBox, SIGNAL(valueChanged(const QString&)), this, SLOT(onNbColorsChanged(const QString&)));
398 connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
399 connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
400 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
401 connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
404 mySMESHGUI->SetActiveDialogBox(this);
405 mySMESHGUI->SetState(800);
407 mySelectionMode = -1;
408 myMeshFilter = new SMESH_TypeFilter(MESH);
409 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
410 myGroupFilter = new SMESH_TypeFilter(GROUP);
411 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
412 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
414 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
415 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
416 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
418 myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
419 onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
421 if (myMesh->_is_nil() )
422 myTypeGroup->setButton(0);
425 //myName->setText(GetDefaultName(tr("SMESH_GROUP")));
428 //=================================================================================
429 // function : ~SMESHGUI_GroupDlg()
430 // purpose : Destroys the object and frees any allocated resources
431 //=================================================================================
432 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
434 // no need to delete child widgets, Qt does it all for us
435 if ( myFilterDlg != 0 )
437 myFilterDlg->reparent( 0, QPoint() );
442 //=================================================================================
443 // function : GetDefaultName()
444 // purpose : Get the Group Name if Create new Group
445 //=================================================================================
446 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
450 // collect all object names of SMESH component
451 SalomeApp_Study* appStudy =
452 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
453 if ( !appStudy ) return aName;
454 _PTR(Study) aStudy = appStudy->studyDS();
456 std::set<std::string> aSet;
457 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
459 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
461 for (it->InitEx(true); it->More(); it->Next()) {
463 aSet.insert(obj->GetName());
467 // build a unique name
469 bool isUnique = false;
471 aName = theOperation + "_" + QString::number(++aNumber);
472 isUnique = (aSet.count(aName.latin1()) == 0);
479 //=================================================================================
482 //=================================================================================
483 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
485 mySelectionMgr->installFilter(myMeshFilter);
487 /* init data from current selection */
488 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
489 myGroup = SMESH::SMESH_Group::_nil();
490 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
492 myActor = SMESH::FindActorByObject(myMesh);
493 SMESH::SetPickable(myActor);
496 mySelectionMgr->selectedObjects( aList );
497 if( !aList.IsEmpty() )
499 QString aName = aList.First()->getName();
500 myMeshGroupLine->setText(aName) ;
501 myMeshGroupLine->home( false );
504 myCurrentLineEdit = 0;
506 myTypeGroup->setButton(0);
510 //=================================================================================
513 //=================================================================================
514 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
516 myMesh = theGroup->GetMesh();
518 myName->setText(theGroup->GetName());
520 myOldName = myName->text();
522 myColorSpinBox->setValue( theGroup->GetColorNumber() );
524 myMeshGroupLine->setText(theGroup->GetName());
527 switch(theGroup->GetType()) {
528 case SMESH::NODE: aType= 0; break;
529 case SMESH::EDGE: aType = 1; break;
530 case SMESH::FACE: aType = 2; break;
531 case SMESH::VOLUME: aType = 3; break;
533 myTypeGroup->setButton(aType);
535 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
537 if ( !myGroup->_is_nil() )
539 myActor = SMESH::FindActorByObject(myMesh);
541 myActor = SMESH::FindActorByObject(myGroup);
542 SMESH::SetPickable(myActor);
544 myGrpTypeGroup->setButton(0);
547 myCurrentLineEdit = 0;
549 setSelectionMode(aType);
553 if (!myGroup->IsEmpty()) {
554 SMESH::long_array_var anElements = myGroup->GetListOfID();
555 int k = anElements->length();
556 for (int i = 0; i < k; i++) {
557 myIdList.append(anElements[i]);
558 myElements->insertItem(QString::number(anElements[i]));
560 myElements->selectAll(true);
565 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
567 if ( !myGroupOnGeom->_is_nil() )
569 myActor = SMESH::FindActorByObject(myMesh);
571 myActor = SMESH::FindActorByObject(myGroup);
572 SMESH::SetPickable(myActor);
574 myGrpTypeGroup->setButton(1);
577 QString aShapeName("");
578 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
579 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
580 if (!aGroupShape->_is_nil())
582 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
583 aShapeName = aGroupShapeSO->GetName().c_str();
585 myGeomGroupLine->setText( aShapeName );
586 myName->setText("Group On " + aShapeName);
587 cout << aShapeName << endl;
592 //=================================================================================
593 // function : updateButtons()
595 //=================================================================================
596 void SMESHGUI_GroupDlg::updateButtons()
598 bool enable = !myName->text().stripWhiteSpace().isEmpty();
600 if (myGrpTypeId == 0) {
601 enable = enable && myElements->count() > 0;
602 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
604 else if (myGrpTypeId == 1) {
605 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
606 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
611 aBtn = (QPushButton*) child("ok", "QPushButton");
612 if (aBtn) aBtn->setEnabled(enable);
613 aBtn = (QPushButton*) child("apply", "QPushButton");
614 if (aBtn) aBtn->setEnabled(enable);
617 //=================================================================================
618 // function : onNameChanged()
620 //=================================================================================
621 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
626 //=================================================================================
627 // function : onNbColorsChanged()
629 //=================================================================================
630 void SMESHGUI_GroupDlg::onNbColorsChanged (const QString& text)
635 //=================================================================================
636 // function : onTypeChanged()
637 // purpose : Group elements type radio button management
638 //=================================================================================
639 void SMESHGUI_GroupDlg::onTypeChanged (int id)
641 if (myTypeId != id) {
643 if (myCurrentLineEdit == 0)
644 setSelectionMode(id);
649 //=================================================================================
650 // function : onGrpTypeChanged()
651 // purpose : Group type radio button management
652 //=================================================================================
653 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
655 if (myGrpTypeId != id) {
656 myWGStack->raiseWidget( id );
658 myName->setText(myOldName);
659 onSelectGeomGroup(id == 1);
664 //=================================================================================
665 // function : setSelectionMode()
666 // purpose : Radio button management
667 //=================================================================================
668 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
671 if (myMesh->_is_nil())
673 if (mySelectionMode != theMode) {
674 // [PAL10408] mySelectionMgr->clearSelected();
675 mySelectionMgr->clearFilters();
677 myActor->SetPointRepresentation(false);
679 SMESH::SetPointRepresentation(false);
684 myActor->SetPointRepresentation(true);
686 SMESH::SetPointRepresentation(true);
687 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
688 aViewWindow->SetSelectionMode(NodeSelection);
691 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
692 aViewWindow->SetSelectionMode(EdgeSelection);
695 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
696 aViewWindow->SetSelectionMode(FaceSelection);
699 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
700 aViewWindow->SetSelectionMode(VolumeSelection);
704 mySelectionMgr->installFilter(mySubMeshFilter);
705 else if (theMode == 5)
706 mySelectionMgr->installFilter(myGroupFilter);
707 else if (theMode == 6)
708 mySelectionMgr->installFilter(myMeshFilter);
709 else if (theMode == 7)
710 mySelectionMgr->installFilter(myGeomFilter);
712 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
713 aViewWindow->SetSelectionMode(ActorSelection);
715 mySelectionMode = theMode;
719 //=================================================================================
720 // function : onApply()
722 //=================================================================================
723 bool SMESHGUI_GroupDlg::onApply()
725 if (mySMESHGUI->isActiveStudyLocked())
728 if (myName->text().stripWhiteSpace().isEmpty())
731 if (myGrpTypeId == 0) { // on mesh elements
732 if (!myElements->count())
735 mySelectionMgr->clearSelected();
737 if (myGroup->_is_nil()) { // creation
738 if (myMesh->_is_nil())
741 SMESH::ElementType aType = SMESH::ALL;
743 case 0: aType = SMESH::NODE; break;
744 case 1: aType = SMESH::EDGE; break;
745 case 2: aType = SMESH::FACE; break;
746 case 3: aType = SMESH::VOLUME; break;
749 SMESH::long_array_var anIdList = new SMESH::long_array;
750 int i, k = myElements->count();
752 QListBoxItem* anItem;
753 for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
754 anIdList[i] = anItem->text().toInt();
757 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
758 myGroup->Add(anIdList.inout());
760 int aColorNumber = myColorSpinBox->value();
761 myGroup->SetColorNumber(aColorNumber);
763 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
765 SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
766 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
768 /* init for next operation */
770 myColorSpinBox->setValue(0);
772 myGroup = SMESH::SMESH_Group::_nil();
775 myGroup->SetName(myName->text());
777 int aColorNumber = myColorSpinBox->value();
778 myGroup->SetColorNumber(aColorNumber);
780 QValueList<int> aAddList;
781 QValueList<int>::iterator anIt;
782 QListBoxItem* anItem;
784 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
785 int anId = anItem->text().toInt();
786 if ((anIt = myIdList.find(anId)) == myIdList.end())
787 aAddList.append(anId);
789 myIdList.remove(anIt);
791 if (!aAddList.empty()) {
792 SMESH::long_array_var anIdList = new SMESH::long_array;
793 anIdList->length(aAddList.count());
795 for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
797 myGroup->Add(anIdList.inout());
799 if (!myIdList.empty()) {
800 SMESH::long_array_var anIdList = new SMESH::long_array;
801 anIdList->length(myIdList.count());
803 for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
805 myGroup->Remove(anIdList.inout());
807 /* init for next operation */
809 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
810 myIdList.append(anItem->text().toInt());
813 mySMESHGUI->updateObjBrowser(true);
814 SMESH::UpdateView(); // asv: fix of BUG PAL5515
815 mySelectionMgr->clearSelected();
818 else if (myGrpTypeId == 1) { // on geom object
819 if (CORBA::is_nil(myGroupOnGeom)) { // creation
820 if (myMesh->_is_nil() || !myGeomObjects->length())
823 SMESH::ElementType aType = SMESH::ALL;
825 case 0: aType = SMESH::NODE; break;
826 case 1: aType = SMESH::EDGE; break;
827 case 2: aType = SMESH::FACE; break;
828 case 3: aType = SMESH::VOLUME; break;
831 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
832 GEOM::GEOM_IGroupOperations_var aGroupOp =
833 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
835 if (myGeomObjects->length() == 1) {
836 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
839 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
840 if ( aSMESHGen->_is_nil() )
843 // create a geometry group
844 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
845 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
847 if (geomGen->_is_nil() || !aStudy)
850 GEOM::GEOM_IGroupOperations_var op =
851 geomGen->GetIGroupOperations(aStudy->StudyId());
855 // check and add all selected GEOM objects: they must be
856 // a sub-shapes of the main GEOM and must be of one type
857 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
858 for ( int i =0; i < myGeomObjects->length(); i++) {
859 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
861 aGroupType = aSubShapeType;
862 else if (aSubShapeType != aGroupType) {
863 aGroupType = TopAbs_SHAPE;
868 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
869 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
870 op->UnionList(aGroupVar, myGeomObjects);
873 // publish the GEOM group in study
874 QString aNewGeomGroupName ("Auto_group_for_");
875 aNewGeomGroupName += myName->text();
876 SALOMEDS::SObject_var aNewGroupSO =
877 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
880 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
883 int aColorNumber = myColorSpinBox->value();
884 myGroupOnGeom->SetColorNumber(aColorNumber);
886 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
888 SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
890 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
892 /* init for next operation */
894 myColorSpinBox->setValue(0);
895 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
898 myGroupOnGeom->SetName(myName->text());
900 int aColorNumber = myColorSpinBox->value();
901 myGroupOnGeom->SetColorNumber(aColorNumber);
904 mySMESHGUI->updateObjBrowser(true);
905 mySelectionMgr->clearSelected();
912 //=================================================================================
915 //=================================================================================
916 void SMESHGUI_GroupDlg::onOK()
922 //=================================================================================
923 // function : onListSelectionChanged()
924 // purpose : Called when selection in element list is changed
925 //=================================================================================
926 void SMESHGUI_GroupDlg::onListSelectionChanged()
928 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
929 if( myIsBusy || !myActor) return;
932 if (myCurrentLineEdit == 0) {
933 mySelectionMgr->clearSelected();
934 TColStd_MapOfInteger aIndexes;
935 QListBoxItem* anItem;
936 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
937 if (anItem->isSelected()) {
938 int anId = anItem->text().toInt();
942 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
944 aList.Append(myActor->getIO());
945 mySelectionMgr->setSelectedObjects(aList,false);
950 //=================================================================================
951 // function : onObjectSelectionChanged()
952 // purpose : Called when selection in 3D view or ObjectBrowser is changed
953 //=================================================================================
954 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
956 if ( myIsBusy || !isEnabled()) return;
957 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
962 mySelectionMgr->selectedObjects( aList );
964 int aNbSel = aList.Extent();
965 myElements->clearSelection();
967 if (myCurrentLineEdit) {
968 myCurrentLineEdit->setText("");
969 QString aString = "";
971 if (myCurrentLineEdit == myMeshGroupLine) {
972 mySelectSubMesh->setEnabled(false);
973 mySelectGroup->setEnabled(false);
974 myGroupLine->setText("");
975 mySubMeshLine->setText("");
977 myGeomGroupBtn->setEnabled(false);
978 myGeomGroupLine->setEnabled(false);
979 myGeomGroupLine->setText("");
980 myGeomObjects = new GEOM::ListOfGO();
981 myGeomObjects->length(0);
983 if (myGeomGroupBtn->isOn())
984 myGeomGroupBtn->setOn(false);
991 myGroup = SMESH::SMESH_Group::_nil();
992 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
993 myMesh = SMESH::SMESH_Mesh::_nil();
999 Handle(SALOME_InteractiveObject) IO = aList.First();
1002 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1004 if (myMesh->_is_nil())
1010 myGroup = SMESH::SMESH_Group::_nil();
1012 myActor = SMESH::FindActorByObject(myMesh);
1013 SMESH::SetPickable(myActor);
1015 aString = aList.First()->getName();
1016 myMeshGroupLine->setText(aString) ;
1017 myMeshGroupLine->home( false );
1019 mySelectSubMesh->setEnabled(true);
1020 mySelectGroup->setEnabled(true);
1021 myGeomGroupBtn->setEnabled(true);
1022 myGeomGroupLine->setEnabled(true);
1025 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1026 if (aGroup->_is_nil())
1032 myCurrentLineEdit = 0;
1034 myGroup = SMESH::SMESH_Group::_nil();
1035 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1039 mySelectSubMesh->setEnabled(true);
1040 mySelectGroup->setEnabled(true);
1042 myCurrentLineEdit = 0;
1047 if (myGrpTypeId == 0)
1053 myElements->clear();
1054 setSelectionMode(myTypeId);
1061 } else if (myCurrentLineEdit == myGeomGroupLine) {
1063 myGeomObjects = new GEOM::ListOfGO();
1066 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1068 if (aNbSel == 0 || !aMeshSO)
1070 myGeomObjects->length(0);
1076 myGeomObjects->length(aNbSel);
1078 GEOM::GEOM_Object_var aGeomGroup;
1079 Standard_Boolean testResult;
1082 SALOME_ListIteratorOfListIO anIt (aList);
1083 for (; anIt.More(); anIt.Next()) {
1085 testResult = Standard_False;
1086 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1088 // Check if the object is a geometry group
1089 if (!testResult || CORBA::is_nil(aGeomGroup))
1093 // Check if group constructed on the same shape as a mesh or on its child
1094 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1095 GEOM::GEOM_IGroupOperations_var anOp =
1096 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1098 // The main shape of the group
1099 GEOM::GEOM_Object_var aGroupMainShape;
1100 if (aGeomGroup->GetType() == 37)
1101 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1103 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1104 _PTR(SObject) aGroupMainShapeSO =
1105 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1106 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1108 _PTR(SObject) anObj, aRef;
1109 bool isRefOrSubShape = false;
1110 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1111 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1112 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1113 isRefOrSubShape = true;
1115 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1116 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1117 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1118 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1119 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1120 if (aRef->GetID() == aFather->GetID())
1121 isRefOrSubShape = true;
1123 aFather = aFather->GetFather();
1127 if (isRefOrSubShape)
1128 myGeomObjects[i++] = aGeomGroup;
1131 myGeomObjects->length(i);
1143 if(myCurrentLineEdit == mySubMeshLine)
1144 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1145 else if(myCurrentLineEdit == myGroupLine)
1146 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1147 else if(myCurrentLineEdit == myGeomGroupLine)
1148 aString = tr("%1 Objects").arg(aNbSel);
1150 aString = aList.First()->getName();
1154 myCurrentLineEdit->setText(aString);
1155 myOldName = myName->text();
1156 myName->setText(aString);
1157 myCurrentLineEdit->home(false);
1162 if (aNbSel == 1 && myActor ) {
1163 QString aListStr = "";
1165 if (myTypeId == 0) {
1166 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1168 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1171 QStringList anElements = QStringList::split(" ", aListStr);
1172 QListBoxItem* anItem = 0;
1173 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1174 anItem = myElements->findItem(*it, Qt::ExactMatch);
1175 if (anItem) myElements->setSelected(anItem, true);
1182 if (!myGroup->_is_nil())
1183 myActor = SMESH::FindActorByObject(myGroup);
1184 else if(!myGroupOnGeom->_is_nil())
1185 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1187 myActor = SMESH::FindActorByObject(myMesh);
1193 //=================================================================================
1194 // function : onSelectSubMesh()
1195 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1196 //=================================================================================
1197 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1200 if (mySelectGroup->isChecked()) {
1201 mySelectGroup->setChecked(false);
1203 //VSR: else if (mySelectGeomGroup->isChecked()) {
1204 //VSR: mySelectGeomGroup->setChecked(false);
1206 myCurrentLineEdit = mySubMeshLine;
1207 setSelectionMode(4);
1210 mySubMeshLine->setText("");
1211 myCurrentLineEdit = 0;
1213 setSelectionMode(myTypeId);
1215 mySubMeshBtn->setEnabled(on);
1216 mySubMeshLine->setEnabled(on);
1220 //=================================================================================
1221 // function : (onSelectGroup)
1222 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1223 //=================================================================================
1224 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1227 if (mySelectSubMesh->isChecked()) {
1228 mySelectSubMesh->setChecked(false);
1230 myCurrentLineEdit = myGroupLine;
1231 setSelectionMode(5);
1234 myGroupLine->setText("");
1235 myCurrentLineEdit = 0;
1237 setSelectionMode(myTypeId);
1239 myGroupBtn->setEnabled(on);
1240 myGroupLine->setEnabled(on);
1244 //=================================================================================
1245 // function : (onSelectGeomGroup)
1246 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1247 //=================================================================================
1248 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1251 if (mySelectSubMesh->isChecked()) {
1252 mySelectSubMesh->setChecked(false);
1254 else if (mySelectGroup->isChecked()) {
1255 mySelectGroup->setChecked(false);
1257 myCurrentLineEdit = myGeomGroupLine;
1259 setSelectionMode(8);
1262 myGeomGroupBtn->setOn(false);
1263 myGeomObjects->length(0);
1264 myGeomGroupLine->setText("");
1265 myCurrentLineEdit = 0;
1267 setSelectionMode(myTypeId);
1271 //=================================================================================
1272 // function : (onSelectColorGroup)
1273 // purpose : Called when setting a color on group
1274 //=================================================================================
1275 void SMESHGUI_GroupDlg::onSelectColorGroup(bool on)
1278 myColorSpinBox->setValue(0);
1280 myColorSpinBox->setEnabled(on);
1283 //=================================================================================
1284 // function : setCurrentSelection()
1286 //=================================================================================
1287 void SMESHGUI_GroupDlg::setCurrentSelection()
1289 QPushButton* send = (QPushButton*)sender();
1290 myCurrentLineEdit = 0;
1291 if (send == myMeshGroupBtn) {
1292 myCurrentLineEdit = myMeshGroupLine;
1294 setSelectionMode(6);
1296 setSelectionMode(5);
1297 onObjectSelectionChanged();
1299 else if (send == mySubMeshBtn) {
1300 myCurrentLineEdit = mySubMeshLine;
1301 onObjectSelectionChanged();
1303 else if (send == myGroupBtn) {
1304 myCurrentLineEdit = myGroupLine;
1305 onObjectSelectionChanged();
1310 //=================================================================================
1311 // function : setFilters()
1312 // purpose : SLOT. Called when "Filter" button pressed.
1313 //=================================================================================
1314 void SMESHGUI_GroupDlg::setFilters()
1316 SMESH::ElementType aType = SMESH::ALL;
1319 case 0 : aType = SMESH::NODE; break;
1320 case 1 : aType = SMESH::EDGE; break;
1321 case 2 : aType = SMESH::FACE; break;
1322 case 3 : aType = SMESH::VOLUME; break;
1326 if ( myFilterDlg == 0 )
1328 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1329 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1332 myFilterDlg->Init( aType );
1334 myFilterDlg->SetSelection();
1335 myFilterDlg->SetMesh( myMesh );
1336 myFilterDlg->SetSourceWg( myElements );
1338 myFilterDlg->show();
1341 //=================================================================================
1342 // function : onFilterAccepted()
1343 // purpose : SLOT. Called when Filter dlg closed with OK button.
1344 // Uncheck "Select submesh" and "Select group" checkboxes
1345 //=================================================================================
1346 void SMESHGUI_GroupDlg::onFilterAccepted()
1348 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1350 mySelectionMode = myTypeId;
1351 mySelectSubMesh->setChecked( false );
1352 mySelectGroup->setChecked( false );
1356 //=================================================================================
1357 // function : onAdd()
1359 //=================================================================================
1360 void SMESHGUI_GroupDlg::onAdd()
1362 SALOME_ListIO aList;
1363 mySelectionMgr->selectedObjects( aList );
1365 int aNbSel = aList.Extent();
1367 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1371 SMESH::ElementType aType = SMESH::ALL;
1374 aType = SMESH::NODE;
1375 mySelector->SetSelectionMode(NodeSelection);
1378 aType = SMESH::EDGE;
1379 mySelector->SetSelectionMode(EdgeSelection);
1382 aType = SMESH::FACE;
1383 mySelector->SetSelectionMode(FaceSelection);
1386 aType = SMESH::VOLUME;
1387 mySelector->SetSelectionMode(VolumeSelection);
1390 mySelector->SetSelectionMode(ActorSelection);
1394 if (myCurrentLineEdit == 0) {
1395 //if (aNbSel != 1) { myIsBusy = false; return; }
1396 QString aListStr = "";
1398 if (myTypeId == 0) {
1399 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1402 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1405 QStringList anElements = QStringList::split(" ", aListStr);
1406 QListBoxItem* anItem = 0;
1407 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1408 anItem = myElements->findItem(*it, Qt::ExactMatch);
1410 anItem = new QListBoxText(*it);
1411 myElements->insertItem(anItem);
1413 myElements->setSelected(anItem, true);
1416 } else if (myCurrentLineEdit == mySubMeshLine) {
1417 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1419 SALOME_ListIO aList;
1420 mySelectionMgr->selectedObjects( aList );
1422 SALOME_ListIteratorOfListIO anIt (aList);
1423 for (; anIt.More(); anIt.Next()) {
1424 SMESH::SMESH_subMesh_var aSubMesh =
1425 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1426 if (!aSubMesh->_is_nil()) {
1427 // check if mesh is the same
1428 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1430 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1431 int k = anElements->length();
1432 QListBoxItem* anItem = 0;
1433 for (int i = 0; i < k; i++) {
1434 QString aText = QString::number(anElements[i]);
1435 anItem = myElements->findItem(aText, Qt::ExactMatch);
1437 anItem = new QListBoxText(aText);
1438 myElements->insertItem(anItem);
1440 myElements->setSelected(anItem, true);
1443 catch (const SALOME::SALOME_Exception& ex) {
1444 SalomeApp_Tools::QtCatchCorbaException(ex);
1449 mySelectSubMesh->setChecked(false);
1451 onListSelectionChanged();
1453 } else if (myCurrentLineEdit == myGroupLine) {
1454 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1455 SALOME_ListIO aList;
1456 mySelectionMgr->selectedObjects( aList );
1458 SALOME_ListIteratorOfListIO anIt (aList);
1459 for (; anIt.More(); anIt.Next()) {
1460 SMESH::SMESH_Group_var aGroup =
1461 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1462 if (!aGroup->_is_nil()) {
1463 // check if mesh is the same
1464 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1465 SMESH::long_array_var anElements = aGroup->GetListOfID();
1466 int k = anElements->length();
1467 QListBoxItem* anItem = 0;
1468 for (int i = 0; i < k; i++) {
1469 QString aText = QString::number(anElements[i]);
1470 anItem = myElements->findItem(aText, Qt::ExactMatch);
1472 anItem = new QListBoxText(aText);
1473 myElements->insertItem(anItem);
1475 myElements->setSelected(anItem, true);
1480 mySelectGroup->setChecked(false);
1482 onListSelectionChanged();
1484 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1485 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1486 GEOM::GEOM_IGroupOperations_var aGroupOp =
1487 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1489 SMESH::ElementType aGroupType = SMESH::ALL;
1490 switch(aGroupOp->GetType(myGeomObjects[0])) {
1491 case 7: aGroupType = SMESH::NODE; break;
1492 case 6: aGroupType = SMESH::EDGE; break;
1493 case 4: aGroupType = SMESH::FACE; break;
1494 case 2: aGroupType = SMESH::VOLUME; break;
1495 default: myIsBusy = false; return;
1498 if (aGroupType == aType) {
1499 _PTR(SObject) aGroupSO =
1500 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1501 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1503 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1504 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1505 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1506 aBelongToGeom->SetGeom(myGeomObjects[0]);
1507 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1508 aBelongToGeom->SetElementType(aType);
1509 aFilter->SetPredicate(aBelongToGeom);
1511 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1513 int k = anElements->length();
1514 QListBoxItem* anItem = 0;
1515 for (int i = 0; i < k; i++) {
1516 QString aText = QString::number(anElements[i]);
1517 anItem = myElements->findItem(aText, Qt::ExactMatch);
1519 anItem = new QListBoxText(aText);
1520 myElements->insertItem(anItem);
1522 myElements->setSelected(anItem, true);
1526 //VSR: mySelectGeomGroup->setChecked(false);
1528 onListSelectionChanged();
1531 // mySelectionMgr->clearSelected();
1535 //=================================================================================
1536 // function : onRemove()
1538 //=================================================================================
1539 void SMESHGUI_GroupDlg::onRemove()
1542 if (myCurrentLineEdit == 0) {
1543 for (int i = myElements->count(); i > 0; i--) {
1544 if (myElements->isSelected(i-1)) {
1545 myElements->removeItem(i-1);
1549 SALOME_ListIO aList;
1550 mySelectionMgr->selectedObjects( aList );
1552 int aNbSel = aList.Extent();
1554 if (aNbSel == 0) { myIsBusy = false; return; }
1556 SMESH::ElementType aType = SMESH::ALL;
1558 case 0: aType = SMESH::NODE; break;
1559 case 1: aType = SMESH::EDGE; break;
1560 case 2: aType = SMESH::FACE; break;
1561 case 3: aType = SMESH::VOLUME; break;
1564 if (myCurrentLineEdit == mySubMeshLine) {
1565 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1566 SALOME_ListIO aList;
1567 mySelectionMgr->selectedObjects( aList );
1569 SALOME_ListIteratorOfListIO anIt (aList);
1570 for (; anIt.More(); anIt.Next()) {
1571 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1572 if (!aSubMesh->_is_nil()) {
1573 // check if mesh is the same
1574 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1575 if (aType == SMESH::NODE) {
1577 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1578 int k = anElements->length();
1579 QListBoxItem* anItem = 0;
1580 for (int i = 0; i < k; i++) {
1581 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1582 if (anItem) delete anItem;
1585 catch (const SALOME::SALOME_Exception& ex) {
1586 SalomeApp_Tools::QtCatchCorbaException(ex);
1591 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1592 int k = anElements->length();
1593 QListBoxItem* anItem = 0;
1594 for (int i = 0; i < k; i++) {
1595 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1596 if (anItem) delete anItem;
1599 catch (const SALOME::SALOME_Exception& ex) {
1600 SalomeApp_Tools::QtCatchCorbaException(ex);
1607 else if (myCurrentLineEdit == myGroupLine) {
1608 Standard_Boolean aRes;
1609 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1610 SALOME_ListIO aList;
1611 mySelectionMgr->selectedObjects( aList );
1613 SALOME_ListIteratorOfListIO anIt (aList);
1614 for (; anIt.More(); anIt.Next()) {
1615 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1616 if (aRes && !aGroup->_is_nil()) {
1617 // check if mesh is the same
1618 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1619 SMESH::long_array_var anElements = aGroup->GetListOfID();
1620 int k = anElements->length();
1621 QListBoxItem* anItem = 0;
1622 for (int i = 0; i < k; i++) {
1623 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1624 if (anItem) delete anItem;
1635 //=================================================================================
1636 // function : onSort()
1638 //=================================================================================
1639 void SMESHGUI_GroupDlg::onSort()
1641 // PAL5412: sorts items in ascending by "string" value
1642 // myElements->sort(true);
1643 // myElements->update();
1644 int i, k = myElements->count();
1647 QStringList aSelected;
1648 std::vector<int> anArray(k);
1649 // QMemArray<int> anArray(k);
1650 QListBoxItem* anItem;
1652 for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1653 anArray[i] = anItem->text().toInt();
1654 if (anItem->isSelected())
1655 aSelected.append(anItem->text());
1657 // sort & update list
1658 std::sort(anArray.begin(), anArray.end());
1660 myElements->clear();
1661 for (i = 0; i < k; i++) {
1662 myElements->insertItem(QString::number(anArray[i]));
1664 for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1665 anItem = myElements->findItem(*it, Qt::ExactMatch);
1666 if (anItem) myElements->setSelected(anItem, true);
1672 //=================================================================================
1673 // function : closeEvent()
1675 //=================================================================================
1676 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1681 //=================================================================================
1682 // function : SMESHGUI_GroupDlg::onClose
1683 // purpose : SLOT called when "Close" button pressed. Close dialog
1684 //=================================================================================
1685 void SMESHGUI_GroupDlg::onClose()
1687 if (SMESH::GetCurrentVtkView()) {
1688 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1689 SMESH::SetPointRepresentation(false);
1690 SMESH::SetPickable();
1693 mySelectionMgr->clearSelected();
1694 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1695 aViewWindow->SetSelectionMode(ActorSelection);
1696 mySelectionMgr->clearFilters();
1697 mySMESHGUI->ResetState();
1702 //=================================================================================
1703 // function : onHelp()
1705 //=================================================================================
1706 void SMESHGUI_GroupDlg::onHelp()
1708 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1710 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1712 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1713 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1714 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
1715 QObject::tr("BUT_OK"));
1719 //=================================================================================
1720 // function : SMESHGUI_GroupDlg::onDeactivate
1721 // purpose : SLOT called when dialog must be deativated
1722 //=================================================================================
1723 void SMESHGUI_GroupDlg::onDeactivate()
1725 mySMESHGUI->ResetState();
1729 //=================================================================================
1730 // function : SMESHGUI_GroupDlg::enterEvent
1731 // purpose : Event filter
1732 //=================================================================================
1733 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1736 mySMESHGUI->EmitSignalDeactivateDialog();
1738 mySelectionMode = -1;
1739 setSelectionMode(myTypeId);
1740 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1741 mySMESHGUI->SetActiveDialogBox(this);
1742 mySMESHGUI->SetState(800);
1746 //=================================================================================
1747 // function : hideEvent
1748 // purpose : caused by ESC key
1749 //=================================================================================
1750 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1752 if (!isMinimized() && !myIsBusy)
1756 //=================================================================================
1757 // function : keyPressEvent()
1759 //=================================================================================
1760 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1762 QDialog::keyPressEvent( e );
1763 if ( e->isAccepted() )
1766 if ( e->key() == Key_F1 )
1773 //================================================================================
1775 * \brief Enable showing of the popup when Geometry selection btn is clicked
1776 * \param enable - true to enable
1778 //================================================================================
1780 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1782 void SMESHGUI_GroupDlg::updateGeomPopup()
1784 bool enable = false;
1786 if ( !myMesh->_is_nil() )
1787 enable = myMesh->NbEdges() > 0;
1789 if ( myGeomGroupBtn )
1791 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1793 if ( !myGeomPopup ) {
1794 myGeomPopup = new QPopupMenu();
1795 myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
1796 myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
1797 connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
1799 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1805 //=================================================================================
1806 // function : onGeomSelectionButton()
1808 //=================================================================================
1809 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1811 if ( myGeomPopup && isBtnOn )
1813 myCurrentLineEdit = myGeomGroupLine;
1814 int id = myGeomPopup->exec( QCursor::pos() );
1815 if (id == DIRECT_GEOM_INDEX || id == -1)
1816 setSelectionMode(7);
1820 myCurrentLineEdit = 0;
1821 setSelectionMode(8);
1825 //=================================================================================
1826 // function : onGeomPopup()
1828 //=================================================================================
1829 void SMESHGUI_GroupDlg::onGeomPopup( int index )
1831 if ( index == GEOM_BY_MESH_INDEX )
1833 mySelectionMode = -1;
1834 if ( !myShapeByMeshOp ) {
1835 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1836 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1837 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1838 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1839 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1841 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1842 if ( !myMesh->_is_nil() ) {
1844 hide(); // stop processing selection
1846 myShapeByMeshOp->setModule( mySMESHGUI );
1847 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1848 myShapeByMeshOp->SetMesh( myMesh );
1849 myShapeByMeshOp->start();
1854 //================================================================================
1856 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1858 //================================================================================
1860 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1862 if ( myShapeByMeshOp == op ) {
1863 mySMESHGUI->getApp()->updateObjectBrowser();
1865 // Select a found geometry object
1866 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1867 if ( !aGeomVar->_is_nil() )
1869 QString ID = aGeomVar->GetStudyEntry();
1870 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1871 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
1872 SALOME_ListIO anIOList;
1873 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1874 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1875 anIOList.Append( anIO );
1876 mySelectionMgr->setSelectedObjects( anIOList, false );
1877 onObjectSelectionChanged();
1883 //================================================================================
1885 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1887 //================================================================================
1889 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1891 if ( myShapeByMeshOp == op )
1894 setSelectionMode(7);