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()),
110 if (!name) setName("SMESHGUI_GroupDlg");
112 if (!theMesh->_is_nil())
115 mySelectSubMesh->setEnabled(false);
116 mySelectGroup->setEnabled(false);
117 myGeomGroupBtn->setEnabled(false);
118 myGeomGroupLine->setEnabled(false);
122 //=================================================================================
123 // function : SMESHGUI_GroupDlg()
125 //=================================================================================
126 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
127 SMESH::SMESH_GroupBase_ptr theGroup, bool modal, WFlags fl)
128 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
129 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
130 mySMESHGUI( theModule ),
131 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
132 mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
135 if (!name) setName("SMESHGUI_GroupDlg");
138 if (!theGroup->_is_nil())
141 mySelectSubMesh->setEnabled(false);
142 mySelectGroup->setEnabled(false);
144 myCurrentLineEdit = myMeshGroupLine;
149 //=================================================================================
150 // function : SMESHGUI_GroupDlg()
152 //=================================================================================
153 void SMESHGUI_GroupDlg::initDialog(bool create)
157 myCurrentLineEdit = 0;
161 myGeomObjects = new GEOM::ListOfGO();
162 myGeomObjects->length(0);
164 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
167 setCaption(tr("SMESH_CREATE_GROUP_TITLE"));
168 myHelpFileName = "/files/creating_groups.htm";
171 setCaption(tr("SMESH_EDIT_GROUP_TITLE"));
172 myHelpFileName = "/files/editing_groups.htm";
175 setSizeGripEnabled(TRUE);
177 QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
179 /***************************************************************/
180 QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
182 meshGroupLab->setText(tr("SMESH_MESH"));
184 meshGroupLab->setText(tr("SMESH_GROUP"));
185 myMeshGroupBtn = new QPushButton(this, "mesh/group button");
186 myMeshGroupBtn->setPixmap(image0);
187 myMeshGroupLine = new QLineEdit(this, "mesh/group line");
188 myMeshGroupLine->setReadOnly(true);
190 /***************************************************************/
191 myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
192 myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
193 myTypeGroup->setExclusive(true);
196 types.append(tr("MESH_NODE"));
197 types.append(tr("SMESH_EDGE"));
198 types.append(tr("SMESH_FACE"));
199 types.append(tr("SMESH_VOLUME"));
201 for (int i = 0; i < types.count(); i++) {
202 rb = new QRadioButton(types[i], myTypeGroup);
204 myTypeGroup->setEnabled(create);
207 /***************************************************************/
208 QLabel* aName = new QLabel(this, "name label");
209 aName->setText(tr("SMESH_NAME"));
210 aName->setMinimumSize(50,0);
211 myName = new QLineEdit(this, "name");
213 /***************************************************************/
214 myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
215 myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
216 myGrpTypeGroup->setExclusive(true);
217 QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
218 QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"), myGrpTypeGroup);
219 myGrpTypeGroup->setEnabled(create);
222 /***************************************************************/
223 myWGStack = new QWidgetStack( this, "widget stack");
224 QWidget* wg1 = new QFrame( myWGStack, "first widget" );
225 QWidget* wg2 = new QFrame( myWGStack, "second widget" );
227 /***************************************************************/
228 QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
229 aContentBox->setTitle(tr("SMESH_CONTENT"));
230 QFrame* aContent = new QFrame(aContentBox, "content");
231 QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
232 aLayout->setSpacing(6);
233 aLayout->setAutoAdd(false);
235 QLabel* aLabel = new QLabel(aContent, "elements label");
236 aLabel->setText(tr("SMESH_ID_ELEMENTS"));
237 myElements = new QListBox(aContent, "elements list");
238 myElements->setSelectionMode(QListBox::Extended);
240 myFilter = new QPushButton(aContent, "filter");
241 myFilter->setText(tr("SMESH_BUT_FILTER"));
242 QPushButton* aAddBtn = new QPushButton(aContent, "add");
243 aAddBtn->setText(tr("SMESH_BUT_ADD"));
244 QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
245 aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
246 QPushButton* aSortBtn = new QPushButton(aContent, "sort");
247 aSortBtn->setText(tr("SMESH_BUT_SORT"));
249 aLayout->addWidget(aLabel, 0, 0);
250 aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
251 aLayout->addWidget(myFilter, 1, 2);
252 aLayout->addWidget(aAddBtn, 3, 2);
253 aLayout->addWidget(aRemoveBtn, 4, 2);
254 aLayout->addWidget(aSortBtn, 6, 2);
256 aLayout->setColStretch(0, 1);
257 aLayout->addColSpacing(1, 20);
258 aLayout->addColSpacing(3, 20);
259 aLayout->setRowStretch(2, 1);
260 aLayout->setRowStretch(5, 1);
262 /***************************************************************/
263 QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
264 aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
266 mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
267 mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
268 mySelectSubMesh->setMinimumSize(50, 0);
269 mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
270 mySubMeshBtn->setText("");
271 mySubMeshBtn->setPixmap(image0);
272 mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
273 mySubMeshLine->setReadOnly(true);
274 onSelectSubMesh(false);
276 mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
277 mySelectGroup->setText(tr("SMESH_GROUP"));
278 mySelectGroup->setMinimumSize(50, 0);
279 myGroupBtn = new QPushButton(aSelectBox, "group button");
280 myGroupBtn->setText("");
281 myGroupBtn->setPixmap(image0);
282 myGroupLine = new QLineEdit(aSelectBox, "group line");
283 myGroupLine->setReadOnly(true);
284 onSelectGroup(false);
286 /***************************************************************/
287 QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
288 wg1Layout->addWidget(aContentBox, 0, 0);
289 wg1Layout->addWidget(aSelectBox, 1, 0);
290 wg1Layout->setRowStretch(2, 5);
292 /***************************************************************/
293 QLabel* geomObject = new QLabel(wg2, "geometry object label");
294 geomObject->setText(tr("SMESH_OBJECT_GEOM"));
295 myGeomGroupBtn = new QToolButton(wg2, "geometry group button");
296 myGeomGroupBtn->setIconSet( QIconSet(image0) );
297 myGeomGroupBtn->setToggleButton(true);
298 myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
299 myGeomGroupLine->setReadOnly(true); //VSR ???
300 onSelectGeomGroup(false);
304 myGeomGroupBtn->setEnabled(false);
305 myGeomGroupLine->setEnabled(false);
308 /***************************************************************/
309 QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
310 wg2Layout->addWidget(geomObject, 0, 0);
311 wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
312 wg2Layout->addWidget(myGeomGroupLine,0, 2);
313 wg2Layout->setRowStretch(1, 5);
315 /***************************************************************/
316 QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
317 dumb->addWidget(wg1);
318 dumb->addWidget(wg2);
319 myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
320 myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
322 /***************************************************************/
323 QGroupBox* aColorBox = new QGroupBox(2, Qt::Horizontal, this, "color box");
324 aColorBox->setTitle(tr("SMESH_SET_COLOR"));
326 mySelectColorGroup = new QCheckBox(aColorBox, "color checkbox");
327 mySelectColorGroup->setText(tr("SMESH_CHECK_COLOR"));
329 myColorSpinBox = new QtxIntSpinBox( aColorBox );
330 myColorSpinBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
331 myColorSpinBox->setMinValue( 0 );
332 myColorSpinBox->setMaxValue( 9999 );
334 onSelectColorGroup(false);
336 /***************************************************************/
338 QFrame* aButtons = new QFrame(this, "button box");
339 aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
340 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
341 aBtnLayout->setAutoAdd(false);
343 QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
344 aOKBtn->setText(tr("SMESH_BUT_OK"));
345 aOKBtn->setAutoDefault(true);
346 aOKBtn->setDefault(true);
347 QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
348 aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
349 aApplyBtn->setAutoDefault(true);
350 QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
351 aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
352 aCloseBtn->setAutoDefault(true);
353 QPushButton* aHelpBtn = new QPushButton(aButtons, "help");
354 aHelpBtn->setText(tr("SMESH_BUT_HELP"));
355 aHelpBtn->setAutoDefault(true);
357 aBtnLayout->addWidget(aOKBtn);
358 aBtnLayout->addWidget(aApplyBtn);
359 aBtnLayout->addStretch();
360 aBtnLayout->addWidget(aCloseBtn);
361 aBtnLayout->addWidget(aHelpBtn);
363 /***************************************************************/
364 aMainLayout->addWidget(meshGroupLab, 0, 0);
365 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
366 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
367 aMainLayout->addMultiCellWidget(myTypeGroup, 1, 1, 0, 2);
368 aMainLayout->addWidget(aName, 2, 0);
369 aMainLayout->addWidget(myName, 2, 2);
370 aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
371 aMainLayout->addMultiCellWidget(myWGStack, 4, 4, 0, 2);
372 aMainLayout->setRowStretch( 5, 5 );
373 aMainLayout->addMultiCellWidget(aColorBox, 6, 6, 0, 2);
374 aMainLayout->addMultiCellWidget(aButtons, 7, 7, 0, 2);
376 /* signals and slots connections */
377 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
379 connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
381 connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
383 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
384 connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
386 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
387 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
388 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
389 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
391 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
392 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
393 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
394 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
395 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
396 connect(mySelectColorGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectColorGroup(bool)));
397 connect(myColorSpinBox, SIGNAL(valueChanged(const QString&)), this, SLOT(onNbColorsChanged(const QString&)));
399 connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
400 connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
401 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
402 connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
405 mySMESHGUI->SetActiveDialogBox(this);
406 mySMESHGUI->SetState(800);
408 mySelectionMode = -1;
409 myMeshFilter = new SMESH_TypeFilter(MESH);
410 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
411 myGroupFilter = new SMESH_TypeFilter(GROUP);
412 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
413 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
415 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
416 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
417 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
419 myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
420 onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
422 if (myMesh->_is_nil() )
423 myTypeGroup->setButton(0);
426 //myName->setText(GetDefaultName(tr("SMESH_GROUP")));
429 //=================================================================================
430 // function : ~SMESHGUI_GroupDlg()
431 // purpose : Destroys the object and frees any allocated resources
432 //=================================================================================
433 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
435 // no need to delete child widgets, Qt does it all for us
436 if ( myFilterDlg != 0 )
438 myFilterDlg->reparent( 0, QPoint() );
443 //=================================================================================
444 // function : GetDefaultName()
445 // purpose : Get the Group Name if Create new Group
446 //=================================================================================
447 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
451 // collect all object names of SMESH component
452 SalomeApp_Study* appStudy =
453 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
454 if ( !appStudy ) return aName;
455 _PTR(Study) aStudy = appStudy->studyDS();
457 std::set<std::string> aSet;
458 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
460 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
462 for (it->InitEx(true); it->More(); it->Next()) {
464 aSet.insert(obj->GetName());
468 // build a unique name
470 bool isUnique = false;
472 aName = theOperation + "_" + QString::number(++aNumber);
473 isUnique = (aSet.count(aName.latin1()) == 0);
480 //=================================================================================
483 //=================================================================================
484 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
486 mySelectionMgr->installFilter(myMeshFilter);
488 /* init data from current selection */
489 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
490 myGroup = SMESH::SMESH_Group::_nil();
491 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
493 myActor = SMESH::FindActorByObject(myMesh);
494 SMESH::SetPickable(myActor);
498 mySelectionMgr->selectedObjects( aList );
499 if( !aList.IsEmpty() )
501 QString aName = aList.First()->getName();
502 myMeshGroupLine->setText(aName) ;
503 myMeshGroupLine->home( false );
506 myCurrentLineEdit = 0;
508 myTypeGroup->setButton(0);
512 //=================================================================================
515 //=================================================================================
516 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
518 myMesh = theGroup->GetMesh();
520 myName->setText(theGroup->GetName());
522 myOldName = myName->text();
524 myColorSpinBox->setValue( theGroup->GetColorNumber() );
526 myMeshGroupLine->setText(theGroup->GetName());
529 switch(theGroup->GetType()) {
530 case SMESH::NODE: aType= 0; break;
531 case SMESH::EDGE: aType = 1; break;
532 case SMESH::FACE: aType = 2; break;
533 case SMESH::VOLUME: aType = 3; break;
535 myTypeGroup->setButton(aType);
537 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
539 if ( !myGroup->_is_nil() )
541 myActor = SMESH::FindActorByObject(myMesh);
543 myActor = SMESH::FindActorByObject(myGroup);
544 SMESH::SetPickable(myActor);
547 myGrpTypeGroup->setButton(0);
550 myCurrentLineEdit = 0;
552 setSelectionMode(aType);
556 if (!myGroup->IsEmpty()) {
557 SMESH::long_array_var anElements = myGroup->GetListOfID();
558 int k = anElements->length();
559 for (int i = 0; i < k; i++) {
560 myIdList.append(anElements[i]);
561 myElements->insertItem(QString::number(anElements[i]));
563 myElements->selectAll(true);
568 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
570 if ( !myGroupOnGeom->_is_nil() )
572 myActor = SMESH::FindActorByObject(myMesh);
574 myActor = SMESH::FindActorByObject(myGroup);
575 SMESH::SetPickable(myActor);
578 myGrpTypeGroup->setButton(1);
581 QString aShapeName("");
582 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
583 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
584 if (!aGroupShape->_is_nil())
586 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
587 aShapeName = aGroupShapeSO->GetName().c_str();
589 myGeomGroupLine->setText( aShapeName );
590 myName->setText("Group On " + aShapeName);
591 cout << aShapeName << endl;
596 //=================================================================================
597 // function : updateButtons()
599 //=================================================================================
600 void SMESHGUI_GroupDlg::updateButtons()
602 bool enable = !myName->text().stripWhiteSpace().isEmpty();
604 if (myGrpTypeId == 0) {
605 enable = enable && myElements->count() > 0;
606 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
608 else if (myGrpTypeId == 1) {
609 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
610 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
615 aBtn = (QPushButton*) child("ok", "QPushButton");
616 if (aBtn) aBtn->setEnabled(enable);
617 aBtn = (QPushButton*) child("apply", "QPushButton");
618 if (aBtn) aBtn->setEnabled(enable);
621 //=================================================================================
622 // function : onNameChanged()
624 //=================================================================================
625 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
630 //=================================================================================
631 // function : onNbColorsChanged()
633 //=================================================================================
634 void SMESHGUI_GroupDlg::onNbColorsChanged (const QString& text)
639 //=================================================================================
640 // function : onTypeChanged()
641 // purpose : Group elements type radio button management
642 //=================================================================================
643 void SMESHGUI_GroupDlg::onTypeChanged (int id)
648 unsigned int aMode = -1;
652 aMode = SMESH_Actor::eAllEntity;
655 aMode = SMESH_Actor::eEdges;
658 aMode = SMESH_Actor::eFaces;
661 aMode = SMESH_Actor::eVolumes;
664 if( myActor && aMode>=0 )
665 myActor->SetEntityMode( aMode );
666 if (myCurrentLineEdit == 0)
667 setSelectionMode(id);
672 //=================================================================================
673 // function : onGrpTypeChanged()
674 // purpose : Group type radio button management
675 //=================================================================================
676 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
678 if (myGrpTypeId != id) {
679 myWGStack->raiseWidget( id );
681 myName->setText(myOldName);
682 onSelectGeomGroup(id == 1);
687 //=================================================================================
688 // function : setSelectionMode()
689 // purpose : Radio button management
690 //=================================================================================
691 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
694 if (myMesh->_is_nil())
696 if (mySelectionMode != theMode) {
697 // [PAL10408] mySelectionMgr->clearSelected();
698 mySelectionMgr->clearFilters();
700 myActor->SetPointRepresentation(false);
702 SMESH::SetPointRepresentation(false);
707 myActor->SetPointRepresentation(true);
709 SMESH::SetPointRepresentation(true);
710 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
711 aViewWindow->SetSelectionMode(NodeSelection);
714 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
715 aViewWindow->SetSelectionMode(EdgeSelection);
718 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
719 aViewWindow->SetSelectionMode(FaceSelection);
722 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
723 aViewWindow->SetSelectionMode(VolumeSelection);
727 mySelectionMgr->installFilter(mySubMeshFilter);
728 else if (theMode == 5)
729 mySelectionMgr->installFilter(myGroupFilter);
730 else if (theMode == 6)
731 mySelectionMgr->installFilter(myMeshFilter);
732 else if (theMode == 7)
733 mySelectionMgr->installFilter(myGeomFilter);
735 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
736 aViewWindow->SetSelectionMode(ActorSelection);
738 mySelectionMode = theMode;
742 //=================================================================================
743 // function : onApply()
745 //=================================================================================
746 bool SMESHGUI_GroupDlg::onApply()
748 if (mySMESHGUI->isActiveStudyLocked())
751 if (myName->text().stripWhiteSpace().isEmpty())
754 if (myGrpTypeId == 0) { // on mesh elements
755 if (!myElements->count())
758 mySelectionMgr->clearSelected();
760 if (myGroup->_is_nil()) { // creation
761 if (myMesh->_is_nil())
764 SMESH::ElementType aType = SMESH::ALL;
766 case 0: aType = SMESH::NODE; break;
767 case 1: aType = SMESH::EDGE; break;
768 case 2: aType = SMESH::FACE; break;
769 case 3: aType = SMESH::VOLUME; break;
772 SMESH::long_array_var anIdList = new SMESH::long_array;
773 int i, k = myElements->count();
775 QListBoxItem* anItem;
776 for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
777 anIdList[i] = anItem->text().toInt();
780 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
781 myGroup->Add(anIdList.inout());
783 int aColorNumber = myColorSpinBox->value();
784 myGroup->SetColorNumber(aColorNumber);
786 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
788 SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
789 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
791 /* init for next operation */
793 myColorSpinBox->setValue(0);
795 myGroup = SMESH::SMESH_Group::_nil();
798 myGroup->SetName(myName->text());
800 int aColorNumber = myColorSpinBox->value();
801 myGroup->SetColorNumber(aColorNumber);
803 QValueList<int> aAddList;
804 QValueList<int>::iterator anIt;
805 QListBoxItem* anItem;
807 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
808 int anId = anItem->text().toInt();
809 if ((anIt = myIdList.find(anId)) == myIdList.end())
810 aAddList.append(anId);
812 myIdList.remove(anIt);
814 if (!aAddList.empty()) {
815 SMESH::long_array_var anIdList = new SMESH::long_array;
816 anIdList->length(aAddList.count());
818 for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
820 myGroup->Add(anIdList.inout());
822 if (!myIdList.empty()) {
823 SMESH::long_array_var anIdList = new SMESH::long_array;
824 anIdList->length(myIdList.count());
826 for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
828 myGroup->Remove(anIdList.inout());
830 /* init for next operation */
832 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
833 myIdList.append(anItem->text().toInt());
836 mySMESHGUI->updateObjBrowser(true);
837 SMESH::UpdateView(); // asv: fix of BUG PAL5515
838 mySelectionMgr->clearSelected();
841 else if (myGrpTypeId == 1) { // on geom object
842 if (CORBA::is_nil(myGroupOnGeom)) { // creation
843 if (myMesh->_is_nil() || !myGeomObjects->length())
846 SMESH::ElementType aType = SMESH::ALL;
848 case 0: aType = SMESH::NODE; break;
849 case 1: aType = SMESH::EDGE; break;
850 case 2: aType = SMESH::FACE; break;
851 case 3: aType = SMESH::VOLUME; break;
854 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
855 GEOM::GEOM_IGroupOperations_var aGroupOp =
856 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
858 if (myGeomObjects->length() == 1) {
859 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
862 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
863 if ( aSMESHGen->_is_nil() )
866 // create a geometry group
867 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
868 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
870 if (geomGen->_is_nil() || !aStudy)
873 GEOM::GEOM_IGroupOperations_var op =
874 geomGen->GetIGroupOperations(aStudy->StudyId());
878 // check and add all selected GEOM objects: they must be
879 // a sub-shapes of the main GEOM and must be of one type
880 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
881 for ( int i =0; i < myGeomObjects->length(); i++) {
882 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
884 aGroupType = aSubShapeType;
885 else if (aSubShapeType != aGroupType) {
886 aGroupType = TopAbs_SHAPE;
891 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
892 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
893 op->UnionList(aGroupVar, myGeomObjects);
896 // publish the GEOM group in study
897 QString aNewGeomGroupName ("Auto_group_for_");
898 aNewGeomGroupName += myName->text();
899 SALOMEDS::SObject_var aNewGroupSO =
900 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
903 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
906 int aColorNumber = myColorSpinBox->value();
907 myGroupOnGeom->SetColorNumber(aColorNumber);
909 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
911 SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
913 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
915 /* init for next operation */
917 myColorSpinBox->setValue(0);
918 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
921 myGroupOnGeom->SetName(myName->text());
923 int aColorNumber = myColorSpinBox->value();
924 myGroupOnGeom->SetColorNumber(aColorNumber);
927 mySMESHGUI->updateObjBrowser(true);
928 mySelectionMgr->clearSelected();
935 //=================================================================================
938 //=================================================================================
939 void SMESHGUI_GroupDlg::onOK()
945 //=================================================================================
946 // function : onListSelectionChanged()
947 // purpose : Called when selection in element list is changed
948 //=================================================================================
949 void SMESHGUI_GroupDlg::onListSelectionChanged()
951 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
952 if( myIsBusy || !myActor) return;
955 if (myCurrentLineEdit == 0) {
956 mySelectionMgr->clearSelected();
957 TColStd_MapOfInteger aIndexes;
958 QListBoxItem* anItem;
959 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
960 if (anItem->isSelected()) {
961 int anId = anItem->text().toInt();
965 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
967 aList.Append(myActor->getIO());
968 mySelectionMgr->setSelectedObjects(aList,false);
973 //=================================================================================
974 // function : onObjectSelectionChanged()
975 // purpose : Called when selection in 3D view or ObjectBrowser is changed
976 //=================================================================================
977 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
979 if ( myIsBusy || !isEnabled()) return;
980 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
985 mySelectionMgr->selectedObjects( aList );
987 int aNbSel = aList.Extent();
988 myElements->clearSelection();
990 if (myCurrentLineEdit) {
991 myCurrentLineEdit->setText("");
992 QString aString = "";
994 if (myCurrentLineEdit == myMeshGroupLine) {
995 mySelectSubMesh->setEnabled(false);
996 mySelectGroup->setEnabled(false);
997 myGroupLine->setText("");
998 mySubMeshLine->setText("");
1000 myGeomGroupBtn->setEnabled(false);
1001 myGeomGroupLine->setEnabled(false);
1002 myGeomGroupLine->setText("");
1003 myGeomObjects = new GEOM::ListOfGO();
1004 myGeomObjects->length(0);
1006 if (myGeomGroupBtn->isOn())
1007 myGeomGroupBtn->setOn(false);
1009 myName->setText("");
1011 myElements->clear();
1014 myGroup = SMESH::SMESH_Group::_nil();
1015 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1016 myMesh = SMESH::SMESH_Mesh::_nil();
1022 Handle(SALOME_InteractiveObject) IO = aList.First();
1025 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1027 if (myMesh->_is_nil())
1033 myGroup = SMESH::SMESH_Group::_nil();
1035 myActor = SMESH::FindActorByObject(myMesh);
1036 SMESH::SetPickable(myActor);
1039 aString = aList.First()->getName();
1040 myMeshGroupLine->setText(aString) ;
1041 myMeshGroupLine->home( false );
1043 mySelectSubMesh->setEnabled(true);
1044 mySelectGroup->setEnabled(true);
1045 myGeomGroupBtn->setEnabled(true);
1046 myGeomGroupLine->setEnabled(true);
1049 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1050 if (aGroup->_is_nil())
1056 myCurrentLineEdit = 0;
1058 myGroup = SMESH::SMESH_Group::_nil();
1059 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1063 mySelectSubMesh->setEnabled(true);
1064 mySelectGroup->setEnabled(true);
1066 myCurrentLineEdit = 0;
1071 if (myGrpTypeId == 0)
1077 myElements->clear();
1078 setSelectionMode(myTypeId);
1085 } else if (myCurrentLineEdit == myGeomGroupLine) {
1087 myGeomObjects = new GEOM::ListOfGO();
1090 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1092 if (aNbSel == 0 || !aMeshSO)
1094 myGeomObjects->length(0);
1100 myGeomObjects->length(aNbSel);
1102 GEOM::GEOM_Object_var aGeomGroup;
1103 Standard_Boolean testResult;
1106 SALOME_ListIteratorOfListIO anIt (aList);
1107 for (; anIt.More(); anIt.Next()) {
1109 testResult = Standard_False;
1110 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1112 // Check if the object is a geometry group
1113 if (!testResult || CORBA::is_nil(aGeomGroup))
1117 // Check if group constructed on the same shape as a mesh or on its child
1118 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1119 GEOM::GEOM_IGroupOperations_var anOp =
1120 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1122 // The main shape of the group
1123 GEOM::GEOM_Object_var aGroupMainShape;
1124 if (aGeomGroup->GetType() == 37)
1125 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1127 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1128 _PTR(SObject) aGroupMainShapeSO =
1129 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1130 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1132 _PTR(SObject) anObj, aRef;
1133 bool isRefOrSubShape = false;
1134 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1135 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1136 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1137 isRefOrSubShape = true;
1139 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1140 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1141 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1142 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1143 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1144 if (aRef->GetID() == aFather->GetID())
1145 isRefOrSubShape = true;
1147 aFather = aFather->GetFather();
1151 if (isRefOrSubShape)
1152 myGeomObjects[i++] = aGeomGroup;
1155 myGeomObjects->length(i);
1167 if(myCurrentLineEdit == mySubMeshLine)
1168 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1169 else if(myCurrentLineEdit == myGroupLine)
1170 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1171 else if(myCurrentLineEdit == myGeomGroupLine)
1172 aString = tr("%1 Objects").arg(aNbSel);
1174 aString = aList.First()->getName();
1178 myCurrentLineEdit->setText(aString);
1179 myOldName = myName->text();
1180 myName->setText(aString);
1181 myCurrentLineEdit->home(false);
1186 if (aNbSel == 1 && myActor ) {
1187 QString aListStr = "";
1189 if (myTypeId == 0) {
1190 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1192 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1195 QStringList anElements = QStringList::split(" ", aListStr);
1196 QListBoxItem* anItem = 0;
1197 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1198 anItem = myElements->findItem(*it, Qt::ExactMatch);
1199 if (anItem) myElements->setSelected(anItem, true);
1206 if (!myGroup->_is_nil())
1207 myActor = SMESH::FindActorByObject(myGroup);
1208 else if(!myGroupOnGeom->_is_nil())
1209 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1211 myActor = SMESH::FindActorByObject(myMesh);
1218 //=================================================================================
1219 // function : onSelectSubMesh()
1220 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1221 //=================================================================================
1222 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1225 if (mySelectGroup->isChecked()) {
1226 mySelectGroup->setChecked(false);
1228 //VSR: else if (mySelectGeomGroup->isChecked()) {
1229 //VSR: mySelectGeomGroup->setChecked(false);
1231 myCurrentLineEdit = mySubMeshLine;
1232 setSelectionMode(4);
1235 mySubMeshLine->setText("");
1236 myCurrentLineEdit = 0;
1238 setSelectionMode(myTypeId);
1240 mySubMeshBtn->setEnabled(on);
1241 mySubMeshLine->setEnabled(on);
1245 //=================================================================================
1246 // function : (onSelectGroup)
1247 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1248 //=================================================================================
1249 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1252 if (mySelectSubMesh->isChecked()) {
1253 mySelectSubMesh->setChecked(false);
1255 myCurrentLineEdit = myGroupLine;
1256 setSelectionMode(5);
1259 myGroupLine->setText("");
1260 myCurrentLineEdit = 0;
1262 setSelectionMode(myTypeId);
1264 myGroupBtn->setEnabled(on);
1265 myGroupLine->setEnabled(on);
1269 //=================================================================================
1270 // function : (onSelectGeomGroup)
1271 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1272 //=================================================================================
1273 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1276 if (mySelectSubMesh->isChecked()) {
1277 mySelectSubMesh->setChecked(false);
1279 else if (mySelectGroup->isChecked()) {
1280 mySelectGroup->setChecked(false);
1282 myCurrentLineEdit = myGeomGroupLine;
1284 setSelectionMode(8);
1287 myGeomGroupBtn->setOn(false);
1288 myGeomObjects->length(0);
1289 myGeomGroupLine->setText("");
1290 myCurrentLineEdit = 0;
1292 setSelectionMode(myTypeId);
1296 //=================================================================================
1297 // function : (onSelectColorGroup)
1298 // purpose : Called when setting a color on group
1299 //=================================================================================
1300 void SMESHGUI_GroupDlg::onSelectColorGroup(bool on)
1303 myColorSpinBox->setValue(0);
1305 myColorSpinBox->setEnabled(on);
1308 //=================================================================================
1309 // function : setCurrentSelection()
1311 //=================================================================================
1312 void SMESHGUI_GroupDlg::setCurrentSelection()
1314 QPushButton* send = (QPushButton*)sender();
1315 myCurrentLineEdit = 0;
1316 if (send == myMeshGroupBtn) {
1317 myCurrentLineEdit = myMeshGroupLine;
1319 setSelectionMode(6);
1321 setSelectionMode(5);
1322 onObjectSelectionChanged();
1324 else if (send == mySubMeshBtn) {
1325 myCurrentLineEdit = mySubMeshLine;
1326 onObjectSelectionChanged();
1328 else if (send == myGroupBtn) {
1329 myCurrentLineEdit = myGroupLine;
1330 onObjectSelectionChanged();
1335 //=================================================================================
1336 // function : setFilters()
1337 // purpose : SLOT. Called when "Filter" button pressed.
1338 //=================================================================================
1339 void SMESHGUI_GroupDlg::setFilters()
1341 SMESH::ElementType aType = SMESH::ALL;
1344 case 0 : aType = SMESH::NODE; break;
1345 case 1 : aType = SMESH::EDGE; break;
1346 case 2 : aType = SMESH::FACE; break;
1347 case 3 : aType = SMESH::VOLUME; break;
1351 if ( myFilterDlg == 0 )
1353 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1354 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1357 myFilterDlg->Init( aType );
1359 myFilterDlg->SetSelection();
1360 myFilterDlg->SetMesh( myMesh );
1361 myFilterDlg->SetSourceWg( myElements );
1363 myFilterDlg->show();
1366 //=================================================================================
1367 // function : onFilterAccepted()
1368 // purpose : SLOT. Called when Filter dlg closed with OK button.
1369 // Uncheck "Select submesh" and "Select group" checkboxes
1370 //=================================================================================
1371 void SMESHGUI_GroupDlg::onFilterAccepted()
1373 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1375 mySelectionMode = myTypeId;
1376 mySelectSubMesh->setChecked( false );
1377 mySelectGroup->setChecked( false );
1381 //=================================================================================
1382 // function : onAdd()
1384 //=================================================================================
1385 void SMESHGUI_GroupDlg::onAdd()
1387 SALOME_ListIO aList;
1388 mySelectionMgr->selectedObjects( aList );
1390 int aNbSel = aList.Extent();
1392 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1396 SMESH::ElementType aType = SMESH::ALL;
1399 aType = SMESH::NODE;
1400 mySelector->SetSelectionMode(NodeSelection);
1403 aType = SMESH::EDGE;
1404 mySelector->SetSelectionMode(EdgeSelection);
1407 aType = SMESH::FACE;
1408 mySelector->SetSelectionMode(FaceSelection);
1411 aType = SMESH::VOLUME;
1412 mySelector->SetSelectionMode(VolumeSelection);
1415 mySelector->SetSelectionMode(ActorSelection);
1419 if (myCurrentLineEdit == 0) {
1420 //if (aNbSel != 1) { myIsBusy = false; return; }
1421 QString aListStr = "";
1423 if (myTypeId == 0) {
1424 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1427 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1430 QStringList anElements = QStringList::split(" ", aListStr);
1431 QListBoxItem* anItem = 0;
1432 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1433 anItem = myElements->findItem(*it, Qt::ExactMatch);
1435 anItem = new QListBoxText(*it);
1436 myElements->insertItem(anItem);
1438 myElements->setSelected(anItem, true);
1441 } else if (myCurrentLineEdit == mySubMeshLine) {
1442 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1444 SALOME_ListIO aList;
1445 mySelectionMgr->selectedObjects( aList );
1447 SALOME_ListIteratorOfListIO anIt (aList);
1448 for (; anIt.More(); anIt.Next()) {
1449 SMESH::SMESH_subMesh_var aSubMesh =
1450 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1451 if (!aSubMesh->_is_nil()) {
1452 // check if mesh is the same
1453 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1455 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1456 int k = anElements->length();
1457 QListBoxItem* anItem = 0;
1458 for (int i = 0; i < k; i++) {
1459 QString aText = QString::number(anElements[i]);
1460 anItem = myElements->findItem(aText, Qt::ExactMatch);
1462 anItem = new QListBoxText(aText);
1463 myElements->insertItem(anItem);
1465 myElements->setSelected(anItem, true);
1468 catch (const SALOME::SALOME_Exception& ex) {
1469 SalomeApp_Tools::QtCatchCorbaException(ex);
1474 mySelectSubMesh->setChecked(false);
1476 onListSelectionChanged();
1478 } else if (myCurrentLineEdit == myGroupLine) {
1479 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1480 SALOME_ListIO aList;
1481 mySelectionMgr->selectedObjects( aList );
1483 SALOME_ListIteratorOfListIO anIt (aList);
1484 for (; anIt.More(); anIt.Next()) {
1485 SMESH::SMESH_Group_var aGroup =
1486 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1487 if (!aGroup->_is_nil()) {
1488 // check if mesh is the same
1489 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1490 SMESH::long_array_var anElements = aGroup->GetListOfID();
1491 int k = anElements->length();
1492 QListBoxItem* anItem = 0;
1493 for (int i = 0; i < k; i++) {
1494 QString aText = QString::number(anElements[i]);
1495 anItem = myElements->findItem(aText, Qt::ExactMatch);
1497 anItem = new QListBoxText(aText);
1498 myElements->insertItem(anItem);
1500 myElements->setSelected(anItem, true);
1505 mySelectGroup->setChecked(false);
1507 onListSelectionChanged();
1509 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1510 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1511 GEOM::GEOM_IGroupOperations_var aGroupOp =
1512 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1514 SMESH::ElementType aGroupType = SMESH::ALL;
1515 switch(aGroupOp->GetType(myGeomObjects[0])) {
1516 case 7: aGroupType = SMESH::NODE; break;
1517 case 6: aGroupType = SMESH::EDGE; break;
1518 case 4: aGroupType = SMESH::FACE; break;
1519 case 2: aGroupType = SMESH::VOLUME; break;
1520 default: myIsBusy = false; return;
1523 if (aGroupType == aType) {
1524 _PTR(SObject) aGroupSO =
1525 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1526 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1528 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1529 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1530 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1531 aBelongToGeom->SetGeom(myGeomObjects[0]);
1532 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1533 aBelongToGeom->SetElementType(aType);
1534 aFilter->SetPredicate(aBelongToGeom);
1536 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1538 int k = anElements->length();
1539 QListBoxItem* anItem = 0;
1540 for (int i = 0; i < k; i++) {
1541 QString aText = QString::number(anElements[i]);
1542 anItem = myElements->findItem(aText, Qt::ExactMatch);
1544 anItem = new QListBoxText(aText);
1545 myElements->insertItem(anItem);
1547 myElements->setSelected(anItem, true);
1551 //VSR: mySelectGeomGroup->setChecked(false);
1553 onListSelectionChanged();
1556 // mySelectionMgr->clearSelected();
1560 //=================================================================================
1561 // function : onRemove()
1563 //=================================================================================
1564 void SMESHGUI_GroupDlg::onRemove()
1567 if (myCurrentLineEdit == 0) {
1568 for (int i = myElements->count(); i > 0; i--) {
1569 if (myElements->isSelected(i-1)) {
1570 myElements->removeItem(i-1);
1574 SALOME_ListIO aList;
1575 mySelectionMgr->selectedObjects( aList );
1577 int aNbSel = aList.Extent();
1579 if (aNbSel == 0) { myIsBusy = false; return; }
1581 SMESH::ElementType aType = SMESH::ALL;
1583 case 0: aType = SMESH::NODE; break;
1584 case 1: aType = SMESH::EDGE; break;
1585 case 2: aType = SMESH::FACE; break;
1586 case 3: aType = SMESH::VOLUME; break;
1589 if (myCurrentLineEdit == mySubMeshLine) {
1590 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1591 SALOME_ListIO aList;
1592 mySelectionMgr->selectedObjects( aList );
1594 SALOME_ListIteratorOfListIO anIt (aList);
1595 for (; anIt.More(); anIt.Next()) {
1596 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1597 if (!aSubMesh->_is_nil()) {
1598 // check if mesh is the same
1599 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1600 if (aType == SMESH::NODE) {
1602 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1603 int k = anElements->length();
1604 QListBoxItem* anItem = 0;
1605 for (int i = 0; i < k; i++) {
1606 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1607 if (anItem) delete anItem;
1610 catch (const SALOME::SALOME_Exception& ex) {
1611 SalomeApp_Tools::QtCatchCorbaException(ex);
1616 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1617 int k = anElements->length();
1618 QListBoxItem* anItem = 0;
1619 for (int i = 0; i < k; i++) {
1620 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1621 if (anItem) delete anItem;
1624 catch (const SALOME::SALOME_Exception& ex) {
1625 SalomeApp_Tools::QtCatchCorbaException(ex);
1632 else if (myCurrentLineEdit == myGroupLine) {
1633 Standard_Boolean aRes;
1634 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1635 SALOME_ListIO aList;
1636 mySelectionMgr->selectedObjects( aList );
1638 SALOME_ListIteratorOfListIO anIt (aList);
1639 for (; anIt.More(); anIt.Next()) {
1640 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1641 if (aRes && !aGroup->_is_nil()) {
1642 // check if mesh is the same
1643 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1644 SMESH::long_array_var anElements = aGroup->GetListOfID();
1645 int k = anElements->length();
1646 QListBoxItem* anItem = 0;
1647 for (int i = 0; i < k; i++) {
1648 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1649 if (anItem) delete anItem;
1660 //=================================================================================
1661 // function : onSort()
1663 //=================================================================================
1664 void SMESHGUI_GroupDlg::onSort()
1666 // PAL5412: sorts items in ascending by "string" value
1667 // myElements->sort(true);
1668 // myElements->update();
1669 int i, k = myElements->count();
1672 QStringList aSelected;
1673 std::vector<int> anArray(k);
1674 // QMemArray<int> anArray(k);
1675 QListBoxItem* anItem;
1677 for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1678 anArray[i] = anItem->text().toInt();
1679 if (anItem->isSelected())
1680 aSelected.append(anItem->text());
1682 // sort & update list
1683 std::sort(anArray.begin(), anArray.end());
1685 myElements->clear();
1686 for (i = 0; i < k; i++) {
1687 myElements->insertItem(QString::number(anArray[i]));
1689 for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1690 anItem = myElements->findItem(*it, Qt::ExactMatch);
1691 if (anItem) myElements->setSelected(anItem, true);
1697 //=================================================================================
1698 // function : closeEvent()
1700 //=================================================================================
1701 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1706 //=================================================================================
1707 // function : SMESHGUI_GroupDlg::onClose
1708 // purpose : SLOT called when "Close" button pressed. Close dialog
1709 //=================================================================================
1710 void SMESHGUI_GroupDlg::onClose()
1712 if (SMESH::GetCurrentVtkView()) {
1713 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1714 SMESH::SetPointRepresentation(false);
1715 SMESH::SetPickable();
1718 mySelectionMgr->clearSelected();
1719 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1720 aViewWindow->SetSelectionMode(ActorSelection);
1721 mySelectionMgr->clearFilters();
1722 mySMESHGUI->ResetState();
1723 if( myActor && myOldActorMode>=0 )
1724 myActor->SetEntityMode( myOldActorMode );
1728 //=================================================================================
1729 // function : onHelp()
1731 //=================================================================================
1732 void SMESHGUI_GroupDlg::onHelp()
1734 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1736 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1738 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1739 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1740 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
1741 QObject::tr("BUT_OK"));
1745 //=================================================================================
1746 // function : SMESHGUI_GroupDlg::onDeactivate
1747 // purpose : SLOT called when dialog must be deativated
1748 //=================================================================================
1749 void SMESHGUI_GroupDlg::onDeactivate()
1751 mySMESHGUI->ResetState();
1755 //=================================================================================
1756 // function : SMESHGUI_GroupDlg::enterEvent
1757 // purpose : Event filter
1758 //=================================================================================
1759 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1762 mySMESHGUI->EmitSignalDeactivateDialog();
1764 mySelectionMode = -1;
1765 setSelectionMode(myTypeId);
1766 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1767 mySMESHGUI->SetActiveDialogBox(this);
1768 mySMESHGUI->SetState(800);
1772 //=================================================================================
1773 // function : hideEvent
1774 // purpose : caused by ESC key
1775 //=================================================================================
1776 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1778 if (!isMinimized() && !myIsBusy)
1782 //=================================================================================
1783 // function : keyPressEvent()
1785 //=================================================================================
1786 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1788 QDialog::keyPressEvent( e );
1789 if ( e->isAccepted() )
1792 if ( e->key() == Key_F1 )
1799 //================================================================================
1801 * \brief Enable showing of the popup when Geometry selection btn is clicked
1802 * \param enable - true to enable
1804 //================================================================================
1806 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1808 void SMESHGUI_GroupDlg::updateGeomPopup()
1810 bool enable = false;
1812 if ( !myMesh->_is_nil() )
1813 enable = myMesh->NbEdges() > 0;
1815 if ( myGeomGroupBtn )
1817 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1819 if ( !myGeomPopup ) {
1820 myGeomPopup = new QPopupMenu();
1821 myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
1822 myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
1823 connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
1825 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1831 //=================================================================================
1832 // function : onGeomSelectionButton()
1834 //=================================================================================
1835 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1837 if ( myGeomPopup && isBtnOn )
1839 myCurrentLineEdit = myGeomGroupLine;
1840 int id = myGeomPopup->exec( QCursor::pos() );
1841 if (id == DIRECT_GEOM_INDEX || id == -1)
1842 setSelectionMode(7);
1846 myCurrentLineEdit = 0;
1847 setSelectionMode(8);
1851 //=================================================================================
1852 // function : onGeomPopup()
1854 //=================================================================================
1855 void SMESHGUI_GroupDlg::onGeomPopup( int index )
1857 if ( index == GEOM_BY_MESH_INDEX )
1859 mySelectionMode = -1;
1860 if ( !myShapeByMeshOp ) {
1861 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1862 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1863 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1864 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1865 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1867 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1868 if ( !myMesh->_is_nil() ) {
1870 hide(); // stop processing selection
1872 myShapeByMeshOp->setModule( mySMESHGUI );
1873 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1874 myShapeByMeshOp->SetMesh( myMesh );
1875 myShapeByMeshOp->start();
1880 //================================================================================
1882 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1884 //================================================================================
1886 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1888 if ( myShapeByMeshOp == op ) {
1889 mySMESHGUI->getApp()->updateObjectBrowser();
1891 // Select a found geometry object
1892 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1893 if ( !aGeomVar->_is_nil() )
1895 QString ID = aGeomVar->GetStudyEntry();
1896 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1897 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
1898 SALOME_ListIO anIOList;
1899 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1900 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1901 anIOList.Append( anIO );
1902 mySelectionMgr->setSelectedObjects( anIOList, false );
1903 onObjectSelectionChanged();
1909 //================================================================================
1911 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1913 //================================================================================
1915 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1917 if ( myShapeByMeshOp == op )
1920 setSelectionMode(7);
1924 void SMESHGUI_GroupDlg::storeMode()
1927 myOldActorMode = myActor->GetEntityMode();