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"
43 #include "SMESH_ActorUtils.h"
46 #include "GEOM_SelectionFilter.h"
48 #include "SUIT_Desktop.h"
49 #include "SUIT_ResourceMgr.h"
50 #include "SUIT_Session.h"
51 #include "SUIT_MessageBox.h"
53 #include "SalomeApp_Tools.h"
54 #include "SalomeApp_Application.h"
55 #include "SalomeApp_Study.h"
56 #include "LightApp_Application.h"
57 #include "SALOMEDSClient_Study.hxx"
58 #include "SALOME_ListIO.hxx"
59 #include "SALOME_ListIteratorOfListIO.hxx"
61 #include "SVTK_ViewWindow.h"
62 #include "SVTK_Selector.h"
64 #include "utilities.h"
67 #include <TColStd_MapOfInteger.hxx>
70 #include <qbuttongroup.h>
72 #include <qgroupbox.h>
75 #include <qlineedit.h>
76 #include <qpushbutton.h>
77 #include <qtoolbutton.h>
78 #include <qradiobutton.h>
79 #include <qcheckbox.h>
84 #include <qmemarray.h>
85 #include <qwidgetstack.h>
86 #include <qcolordialog.h>
88 #include <QtxIntSpinBox.h>
97 //=================================================================================
98 // function : SMESHGUI_GroupDlg()
100 //=================================================================================
101 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
102 SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl)
103 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
104 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
105 mySMESHGUI( theModule ),
106 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
107 mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
111 if (!name) setName("SMESHGUI_GroupDlg");
113 if (!theMesh->_is_nil())
116 mySelectSubMesh->setEnabled(false);
117 mySelectGroup->setEnabled(false);
118 myGeomGroupBtn->setEnabled(false);
119 myGeomGroupLine->setEnabled(false);
123 //=================================================================================
124 // function : SMESHGUI_GroupDlg()
126 //=================================================================================
127 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
128 SMESH::SMESH_GroupBase_ptr theGroup, bool modal, WFlags fl)
129 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
130 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
131 mySMESHGUI( theModule ),
132 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
133 mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
136 if (!name) setName("SMESHGUI_GroupDlg");
139 if (!theGroup->_is_nil())
142 mySelectSubMesh->setEnabled(false);
143 mySelectGroup->setEnabled(false);
145 myCurrentLineEdit = myMeshGroupLine;
150 //=================================================================================
151 // function : SMESHGUI_GroupDlg()
153 //=================================================================================
154 void SMESHGUI_GroupDlg::initDialog(bool create)
158 myCurrentLineEdit = 0;
162 myGeomObjects = new GEOM::ListOfGO();
163 myGeomObjects->length(0);
165 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
168 setCaption(tr("SMESH_CREATE_GROUP_TITLE"));
169 myHelpFileName = "creating_groups_page.html";
172 setCaption(tr("SMESH_EDIT_GROUP_TITLE"));
173 myHelpFileName = "editing_groups_page.html";
176 setSizeGripEnabled(TRUE);
178 QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
180 /***************************************************************/
181 QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
183 meshGroupLab->setText(tr("SMESH_MESH"));
185 meshGroupLab->setText(tr("SMESH_GROUP"));
186 myMeshGroupBtn = new QPushButton(this, "mesh/group button");
187 myMeshGroupBtn->setPixmap(image0);
188 myMeshGroupLine = new QLineEdit(this, "mesh/group line");
189 myMeshGroupLine->setReadOnly(true);
191 /***************************************************************/
192 myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
193 myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
194 myTypeGroup->setExclusive(true);
197 types.append(tr("MESH_NODE"));
198 types.append(tr("SMESH_EDGE"));
199 types.append(tr("SMESH_FACE"));
200 types.append(tr("SMESH_VOLUME"));
202 for (int i = 0; i < types.count(); i++) {
203 rb = new QRadioButton(types[i], myTypeGroup);
205 myTypeGroup->setEnabled(create);
208 /***************************************************************/
209 QLabel* aName = new QLabel(this, "name label");
210 aName->setText(tr("SMESH_NAME"));
211 aName->setMinimumSize(50,0);
212 myName = new QLineEdit(this, "name");
214 /***************************************************************/
215 myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
216 myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
217 myGrpTypeGroup->setExclusive(true);
218 QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
219 QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"), myGrpTypeGroup);
220 myGrpTypeGroup->setEnabled(create);
223 /***************************************************************/
224 myWGStack = new QWidgetStack( this, "widget stack");
225 QWidget* wg1 = new QFrame( myWGStack, "first widget" );
226 QWidget* wg2 = new QFrame( myWGStack, "second widget" );
228 /***************************************************************/
229 QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
230 aContentBox->setTitle(tr("SMESH_CONTENT"));
231 QFrame* aContent = new QFrame(aContentBox, "content");
232 QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
233 aLayout->setSpacing(6);
234 aLayout->setAutoAdd(false);
236 QLabel* aLabel = new QLabel(aContent, "elements label");
237 aLabel->setText(tr("SMESH_ID_ELEMENTS"));
238 myElements = new QListBox(aContent, "elements list");
239 myElements->setSelectionMode(QListBox::Extended);
241 myFilter = new QPushButton(aContent, "filter");
242 myFilter->setText(tr("SMESH_BUT_FILTER"));
243 QPushButton* aAddBtn = new QPushButton(aContent, "add");
244 aAddBtn->setText(tr("SMESH_BUT_ADD"));
245 QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
246 aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
247 QPushButton* aSortBtn = new QPushButton(aContent, "sort");
248 aSortBtn->setText(tr("SMESH_BUT_SORT"));
250 aLayout->addWidget(aLabel, 0, 0);
251 aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
252 aLayout->addWidget(myFilter, 1, 2);
253 aLayout->addWidget(aAddBtn, 3, 2);
254 aLayout->addWidget(aRemoveBtn, 4, 2);
255 aLayout->addWidget(aSortBtn, 6, 2);
257 aLayout->setColStretch(0, 1);
258 aLayout->addColSpacing(1, 20);
259 aLayout->addColSpacing(3, 20);
260 aLayout->setRowStretch(2, 1);
261 aLayout->setRowStretch(5, 1);
263 /***************************************************************/
264 QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
265 aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
267 mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
268 mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
269 mySelectSubMesh->setMinimumSize(50, 0);
270 mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
271 mySubMeshBtn->setText("");
272 mySubMeshBtn->setPixmap(image0);
273 mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
274 mySubMeshLine->setReadOnly(true);
275 onSelectSubMesh(false);
277 mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
278 mySelectGroup->setText(tr("SMESH_GROUP"));
279 mySelectGroup->setMinimumSize(50, 0);
280 myGroupBtn = new QPushButton(aSelectBox, "group button");
281 myGroupBtn->setText("");
282 myGroupBtn->setPixmap(image0);
283 myGroupLine = new QLineEdit(aSelectBox, "group line");
284 myGroupLine->setReadOnly(true);
285 onSelectGroup(false);
287 /***************************************************************/
288 QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
289 wg1Layout->addWidget(aContentBox, 0, 0);
290 wg1Layout->addWidget(aSelectBox, 1, 0);
291 wg1Layout->setRowStretch(2, 5);
293 /***************************************************************/
294 QLabel* geomObject = new QLabel(wg2, "geometry object label");
295 geomObject->setText(tr("SMESH_OBJECT_GEOM"));
296 myGeomGroupBtn = new QToolButton(wg2, "geometry group button");
297 myGeomGroupBtn->setIconSet( QIconSet(image0) );
298 myGeomGroupBtn->setToggleButton(true);
299 myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
300 myGeomGroupLine->setReadOnly(true); //VSR ???
301 onSelectGeomGroup(false);
305 myGeomGroupBtn->setEnabled(false);
306 myGeomGroupLine->setEnabled(false);
309 /***************************************************************/
310 QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
311 wg2Layout->addWidget(geomObject, 0, 0);
312 wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
313 wg2Layout->addWidget(myGeomGroupLine,0, 2);
314 wg2Layout->setRowStretch(1, 5);
316 /***************************************************************/
317 QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
318 dumb->addWidget(wg1);
319 dumb->addWidget(wg2);
320 myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
321 myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
323 /***************************************************************/
324 QGroupBox* aColorBox = new QGroupBox(2, Qt::Horizontal, this, "color box");
325 aColorBox->setTitle(tr("SMESH_SET_COLOR"));
327 new QLabel( tr("SMESH_CHECK_COLOR"), aColorBox, "color label" );
328 myColorBtn = new QPushButton(aColorBox, "color button");
329 myColorBtn->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
331 /***************************************************************/
333 QFrame* aButtons = new QFrame(this, "button box");
334 aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
335 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
336 aBtnLayout->setAutoAdd(false);
338 QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
339 aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
340 aApplyBtn->setAutoDefault(true);
341 QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
342 aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
343 aCloseBtn->setAutoDefault(true);
344 QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
345 aOKBtn->setText(tr("SMESH_BUT_APPLY_AND_CLOSE"));
346 aOKBtn->setAutoDefault(true);
347 aOKBtn->setDefault(true);
348 QPushButton* aHelpBtn = new QPushButton(aButtons, "help");
349 aHelpBtn->setText(tr("SMESH_BUT_HELP"));
350 aHelpBtn->setAutoDefault(true);
352 aBtnLayout->addWidget(aOKBtn);
353 aBtnLayout->addWidget(aApplyBtn);
354 aBtnLayout->addStretch();
355 aBtnLayout->addWidget(aCloseBtn);
356 aBtnLayout->addWidget(aHelpBtn);
358 /***************************************************************/
359 aMainLayout->addWidget(meshGroupLab, 0, 0);
360 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
361 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
362 aMainLayout->addMultiCellWidget(myTypeGroup, 1, 1, 0, 2);
363 aMainLayout->addWidget(aName, 2, 0);
364 aMainLayout->addWidget(myName, 2, 2);
365 aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
366 aMainLayout->addMultiCellWidget(myWGStack, 4, 4, 0, 2);
367 aMainLayout->setRowStretch( 5, 5 );
368 aMainLayout->addMultiCellWidget(aColorBox, 6, 6, 0, 2);
369 aMainLayout->addMultiCellWidget(aButtons, 7, 7, 0, 2);
371 /* signals and slots connections */
372 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
374 connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
376 connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
378 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
379 connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
381 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
382 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
383 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
384 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
386 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
387 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
388 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
389 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
390 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
391 connect(myColorBtn, SIGNAL(clicked()), this, SLOT(onSelectColor()));
393 connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
394 connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
395 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
396 connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
399 mySMESHGUI->SetActiveDialogBox(this);
400 mySMESHGUI->SetState(800);
402 mySelectionMode = -1;
403 myMeshFilter = new SMESH_TypeFilter(MESH);
404 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
405 myGroupFilter = new SMESH_TypeFilter(GROUP);
406 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
407 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
409 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
410 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
411 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
413 myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
414 onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
416 if (myMesh->_is_nil() )
417 myTypeGroup->setButton(0);
420 //myName->setText(GetDefaultName(tr("SMESH_GROUP")));
423 //=================================================================================
424 // function : ~SMESHGUI_GroupDlg()
425 // purpose : Destroys the object and frees any allocated resources
426 //=================================================================================
427 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
429 // no need to delete child widgets, Qt does it all for us
430 if ( myFilterDlg != 0 )
432 myFilterDlg->reparent( 0, QPoint() );
437 //=================================================================================
438 // function : GetDefaultName()
439 // purpose : Get the Group Name if Create new Group
440 //=================================================================================
441 QString SMESHGUI_GroupDlg::GetDefaultName(const QString& theOperation)
445 // collect all object names of SMESH component
446 SalomeApp_Study* appStudy =
447 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
448 if ( !appStudy ) return aName;
449 _PTR(Study) aStudy = appStudy->studyDS();
451 std::set<std::string> aSet;
452 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
454 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
456 for (it->InitEx(true); it->More(); it->Next()) {
458 aSet.insert(obj->GetName());
462 // build a unique name
464 bool isUnique = false;
466 aName = theOperation + "_" + QString::number(++aNumber);
467 isUnique = (aSet.count(aName.latin1()) == 0);
473 //=================================================================================
476 //=================================================================================
477 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
479 mySelectionMgr->installFilter(myMeshFilter);
481 /* init data from current selection */
482 restoreShowEntityMode();
483 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
485 myGroup = SMESH::SMESH_Group::_nil();
486 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
488 myActor = SMESH::FindActorByObject(myMesh);
489 SMESH::SetPickable(myActor);
491 setDefaultGroupColor();
494 mySelectionMgr->selectedObjects( aList );
495 if( !aList.IsEmpty() )
497 QString aName = aList.First()->getName();
498 myMeshGroupLine->setText(aName) ;
499 myMeshGroupLine->home( false );
502 myCurrentLineEdit = 0;
504 myTypeGroup->setButton(0);
508 //=================================================================================
511 //=================================================================================
512 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
514 restoreShowEntityMode();
515 myMesh = theGroup->GetMesh();
518 myName->setText(theGroup->GetName());
521 SALOMEDS::Color aColor = theGroup->GetColor();
522 setGroupColor( aColor );
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);
591 //=================================================================================
592 // function : updateButtons()
594 //=================================================================================
595 void SMESHGUI_GroupDlg::updateButtons()
597 bool enable = !myName->text().stripWhiteSpace().isEmpty();
599 if (myGrpTypeId == 0) {
600 enable = enable && myElements->count() > 0;
601 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
603 else if (myGrpTypeId == 1) {
604 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
605 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
610 aBtn = (QPushButton*) child("ok", "QPushButton");
611 if (aBtn) aBtn->setEnabled(enable);
612 aBtn = (QPushButton*) child("apply", "QPushButton");
613 if (aBtn) aBtn->setEnabled(enable);
616 //=================================================================================
617 // function : onNameChanged()
619 //=================================================================================
620 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
622 myOldName = myName->text();
626 //=================================================================================
627 // function : onTypeChanged()
628 // purpose : Group elements type radio button management
629 //=================================================================================
630 void SMESHGUI_GroupDlg::onTypeChanged (int id)
632 if (myTypeId != id) {
634 if (myCurrentLineEdit == 0)
635 setSelectionMode(id);
641 //=================================================================================
642 // function : onGrpTypeChanged()
643 // purpose : Group type radio button management
644 //=================================================================================
645 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
647 if (myGrpTypeId != id) {
648 myWGStack->raiseWidget( id );
649 myName->setText(myOldName);
650 onSelectGeomGroup(id == 1);
655 //=================================================================================
656 // function : onSelectColor()
658 //=================================================================================
659 void SMESHGUI_GroupDlg::onSelectColor()
661 QColor color = getGroupQColor();
662 color = QColorDialog::getColor( color );
663 setGroupQColor( color );
668 //=================================================================================
669 // function : setSelectionMode()
670 // purpose : Radio button management
671 //=================================================================================
672 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
675 if (myMesh->_is_nil())
677 if (mySelectionMode != theMode) {
678 // [PAL10408] mySelectionMgr->clearSelected();
679 mySelectionMgr->clearFilters();
681 myActor->SetPointRepresentation(false);
683 SMESH::SetPointRepresentation(false);
688 myActor->SetPointRepresentation(true);
690 SMESH::SetPointRepresentation(true);
691 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
692 aViewWindow->SetSelectionMode(NodeSelection);
695 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
696 aViewWindow->SetSelectionMode(EdgeSelection);
699 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
700 aViewWindow->SetSelectionMode(FaceSelection);
703 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
704 aViewWindow->SetSelectionMode(VolumeSelection);
708 mySelectionMgr->installFilter(mySubMeshFilter);
709 else if (theMode == 5)
710 mySelectionMgr->installFilter(myGroupFilter);
711 else if (theMode == 6)
712 mySelectionMgr->installFilter(myMeshFilter);
713 else if (theMode == 7)
714 mySelectionMgr->installFilter(myGeomFilter);
716 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
717 aViewWindow->SetSelectionMode(ActorSelection);
719 mySelectionMode = theMode;
723 //=================================================================================
724 // function : onApply()
726 //=================================================================================
727 bool SMESHGUI_GroupDlg::onApply()
729 if (mySMESHGUI->isActiveStudyLocked())
732 if (myName->text().stripWhiteSpace().isEmpty())
735 if (myGrpTypeId == 0) { // on mesh elements
736 if (!myElements->count())
739 mySelectionMgr->clearSelected();
741 if (myGroup->_is_nil()) { // creation
742 if (myMesh->_is_nil())
745 SMESH::ElementType aType = SMESH::ALL;
747 case 0: aType = SMESH::NODE; break;
748 case 1: aType = SMESH::EDGE; break;
749 case 2: aType = SMESH::FACE; break;
750 case 3: aType = SMESH::VOLUME; break;
753 SMESH::long_array_var anIdList = new SMESH::long_array;
754 int i, k = myElements->count();
756 QListBoxItem* anItem;
757 for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
758 anIdList[i] = anItem->text().toInt();
761 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
762 myGroup->Add(anIdList.inout());
764 SALOMEDS::Color aColor = getGroupColor();
765 myGroup->SetColor(aColor);
767 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
769 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
770 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
772 /* init for next operation */
775 myGroup = SMESH::SMESH_Group::_nil();
778 myGroup->SetName(myName->text());
780 SALOMEDS::Color aColor = getGroupColor();
781 myGroup->SetColor(aColor);
783 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
784 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
785 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
787 QValueList<int> aAddList;
788 QValueList<int>::iterator anIt;
789 QListBoxItem* anItem;
791 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
792 int anId = anItem->text().toInt();
793 if ((anIt = myIdList.find(anId)) == myIdList.end())
794 aAddList.append(anId);
796 myIdList.remove(anIt);
798 if (!aAddList.empty()) {
799 SMESH::long_array_var anIdList = new SMESH::long_array;
800 anIdList->length(aAddList.count());
802 for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
804 myGroup->Add(anIdList.inout());
806 if (!myIdList.empty()) {
807 SMESH::long_array_var anIdList = new SMESH::long_array;
808 anIdList->length(myIdList.count());
810 for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
812 myGroup->Remove(anIdList.inout());
814 /* init for next operation */
816 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
817 myIdList.append(anItem->text().toInt());
820 mySMESHGUI->updateObjBrowser(true);
821 SMESH::UpdateView(); // asv: fix of BUG PAL5515
822 mySelectionMgr->clearSelected();
825 else if (myGrpTypeId == 1) { // on geom object
826 if (CORBA::is_nil(myGroupOnGeom)) { // creation
827 if (myMesh->_is_nil() || !myGeomObjects->length())
830 SMESH::ElementType aType = SMESH::ALL;
832 case 0: aType = SMESH::NODE; break;
833 case 1: aType = SMESH::EDGE; break;
834 case 2: aType = SMESH::FACE; break;
835 case 3: aType = SMESH::VOLUME; break;
838 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
839 GEOM::GEOM_IGroupOperations_var aGroupOp =
840 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
842 if (myGeomObjects->length() == 1) {
843 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
846 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
847 if ( aSMESHGen->_is_nil() )
850 // create a geometry group
851 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
852 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
854 if (geomGen->_is_nil() || !aStudy)
857 GEOM::GEOM_IGroupOperations_var op =
858 geomGen->GetIGroupOperations(aStudy->StudyId());
862 // check and add all selected GEOM objects: they must be
863 // a sub-shapes of the main GEOM and must be of one type
864 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
865 for ( int i =0; i < myGeomObjects->length(); i++) {
866 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
868 aGroupType = aSubShapeType;
869 else if (aSubShapeType != aGroupType) {
870 aGroupType = TopAbs_SHAPE;
875 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
876 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
877 op->UnionList(aGroupVar, myGeomObjects);
880 // publish the GEOM group in study
881 QString aNewGeomGroupName ("Auto_group_for_");
882 aNewGeomGroupName += myName->text();
883 SALOMEDS::SObject_var aNewGroupSO =
884 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
887 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
890 SALOMEDS::Color aColor = getGroupColor();
891 myGroupOnGeom->SetColor(aColor);
893 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
895 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
896 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
898 /* init for next operation */
900 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
903 myGroupOnGeom->SetName(myName->text());
905 SALOMEDS::Color aColor = getGroupColor();
906 myGroupOnGeom->SetColor(aColor);
908 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
909 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
910 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
913 mySMESHGUI->updateObjBrowser(true);
914 mySelectionMgr->clearSelected();
921 //=================================================================================
924 //=================================================================================
925 void SMESHGUI_GroupDlg::onOK()
931 //=================================================================================
932 // function : onListSelectionChanged()
933 // purpose : Called when selection in element list is changed
934 //=================================================================================
935 void SMESHGUI_GroupDlg::onListSelectionChanged()
937 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
938 if( myIsBusy || !myActor) return;
941 if (myCurrentLineEdit == 0) {
942 mySelectionMgr->clearSelected();
943 TColStd_MapOfInteger aIndexes;
944 QListBoxItem* anItem;
945 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
946 if (anItem->isSelected()) {
947 int anId = anItem->text().toInt();
951 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
953 aList.Append(myActor->getIO());
954 mySelectionMgr->setSelectedObjects(aList,false);
959 //=================================================================================
960 // function : onObjectSelectionChanged()
961 // purpose : Called when selection in 3D view or ObjectBrowser is changed
962 //=================================================================================
963 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
965 if ( myIsBusy || !isEnabled()) return;
966 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
971 mySelectionMgr->selectedObjects( aList );
973 int aNbSel = aList.Extent();
974 myElements->clearSelection();
976 if (myCurrentLineEdit) {
977 myCurrentLineEdit->setText("");
978 QString aString = "";
980 if (myCurrentLineEdit == myMeshGroupLine) {
981 mySelectSubMesh->setEnabled(false);
982 mySelectGroup->setEnabled(false);
983 myGroupLine->setText("");
984 mySubMeshLine->setText("");
986 myGeomGroupBtn->setEnabled(false);
987 myGeomGroupLine->setEnabled(false);
988 myGeomGroupLine->setText("");
989 myGeomObjects = new GEOM::ListOfGO();
990 myGeomObjects->length(0);
992 if (myGeomGroupBtn->isOn())
993 myGeomGroupBtn->setOn(false);
1000 myGroup = SMESH::SMESH_Group::_nil();
1001 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1002 restoreShowEntityMode();
1003 myMesh = SMESH::SMESH_Mesh::_nil();
1009 Handle(SALOME_InteractiveObject) IO = aList.First();
1012 restoreShowEntityMode();
1013 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1014 setShowEntityMode();
1016 if (myMesh->_is_nil())
1022 myGroup = SMESH::SMESH_Group::_nil();
1024 myActor = SMESH::FindActorByObject(myMesh);
1025 SMESH::SetPickable(myActor);
1027 aString = aList.First()->getName();
1028 myMeshGroupLine->setText(aString) ;
1029 myMeshGroupLine->home( false );
1031 mySelectSubMesh->setEnabled(true);
1032 mySelectGroup->setEnabled(true);
1033 myGeomGroupBtn->setEnabled(true);
1034 myGeomGroupLine->setEnabled(true);
1037 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1038 if (aGroup->_is_nil())
1044 myCurrentLineEdit = 0;
1046 myGroup = SMESH::SMESH_Group::_nil();
1047 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1051 mySelectSubMesh->setEnabled(true);
1052 mySelectGroup->setEnabled(true);
1054 myCurrentLineEdit = 0;
1059 if (myGrpTypeId == 0)
1065 myElements->clear();
1066 setSelectionMode(myTypeId);
1073 } else if (myCurrentLineEdit == myGeomGroupLine) {
1075 myGeomObjects = new GEOM::ListOfGO();
1078 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1080 if (aNbSel == 0 || !aMeshSO)
1082 myGeomObjects->length(0);
1088 myGeomObjects->length(aNbSel);
1090 GEOM::GEOM_Object_var aGeomGroup;
1091 Standard_Boolean testResult;
1094 SALOME_ListIteratorOfListIO anIt (aList);
1095 for (; anIt.More(); anIt.Next()) {
1097 testResult = Standard_False;
1098 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1100 // Check if the object is a geometry group
1101 if (!testResult || CORBA::is_nil(aGeomGroup))
1105 // Check if group constructed on the same shape as a mesh or on its child
1106 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1107 GEOM::GEOM_IGroupOperations_var anOp =
1108 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1110 // The main shape of the group
1111 GEOM::GEOM_Object_var aGroupMainShape;
1112 if (aGeomGroup->GetType() == 37)
1113 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1115 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1116 _PTR(SObject) aGroupMainShapeSO =
1117 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1118 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1120 _PTR(SObject) anObj, aRef;
1121 bool isRefOrSubShape = false;
1122 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1123 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1124 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1125 isRefOrSubShape = true;
1127 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1128 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1129 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1130 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1131 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1132 if (aRef->GetID() == aFather->GetID())
1133 isRefOrSubShape = true;
1135 aFather = aFather->GetFather();
1139 if (isRefOrSubShape)
1140 myGeomObjects[i++] = aGeomGroup;
1143 myGeomObjects->length(i);
1155 if(myCurrentLineEdit == mySubMeshLine)
1156 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1157 else if(myCurrentLineEdit == myGroupLine)
1158 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1159 else if(myCurrentLineEdit == myGeomGroupLine)
1160 aString = tr("%1 Objects").arg(aNbSel);
1163 aString = aList.First()->getName();
1167 myCurrentLineEdit->setText(aString);
1168 myCurrentLineEdit->home(false);
1169 // 07.06.2008 skl for IPAL19574:
1170 // change name of group only if it is empty
1171 QString tmp = myName->text();
1172 tmp.stripWhiteSpace();
1174 myOldName = myName->text();
1175 myName->setText(aString);
1181 if (aNbSel == 1 && myActor ) {
1182 QString aListStr = "";
1184 if (myTypeId == 0) {
1185 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1187 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1190 QStringList anElements = QStringList::split(" ", aListStr);
1191 QListBoxItem* anItem = 0;
1192 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1193 anItem = myElements->findItem(*it, Qt::ExactMatch);
1194 if (anItem) myElements->setSelected(anItem, true);
1201 if (!myGroup->_is_nil())
1202 myActor = SMESH::FindActorByObject(myGroup);
1203 else if(!myGroupOnGeom->_is_nil())
1204 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1206 myActor = SMESH::FindActorByObject(myMesh);
1212 //=================================================================================
1213 // function : onSelectSubMesh()
1214 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1215 //=================================================================================
1216 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1219 if (mySelectGroup->isChecked()) {
1220 mySelectGroup->setChecked(false);
1222 //VSR: else if (mySelectGeomGroup->isChecked()) {
1223 //VSR: mySelectGeomGroup->setChecked(false);
1225 myCurrentLineEdit = mySubMeshLine;
1226 setSelectionMode(4);
1229 mySubMeshLine->setText("");
1230 myCurrentLineEdit = 0;
1232 setSelectionMode(myTypeId);
1234 mySubMeshBtn->setEnabled(on);
1235 mySubMeshLine->setEnabled(on);
1239 //=================================================================================
1240 // function : (onSelectGroup)
1241 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1242 //=================================================================================
1243 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1246 if (mySelectSubMesh->isChecked()) {
1247 mySelectSubMesh->setChecked(false);
1249 myCurrentLineEdit = myGroupLine;
1250 setSelectionMode(5);
1253 myGroupLine->setText("");
1254 myCurrentLineEdit = 0;
1256 setSelectionMode(myTypeId);
1258 myGroupBtn->setEnabled(on);
1259 myGroupLine->setEnabled(on);
1263 //=================================================================================
1264 // function : (onSelectGeomGroup)
1265 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1266 //=================================================================================
1267 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1270 if (mySelectSubMesh->isChecked()) {
1271 mySelectSubMesh->setChecked(false);
1273 else if (mySelectGroup->isChecked()) {
1274 mySelectGroup->setChecked(false);
1276 myCurrentLineEdit = myGeomGroupLine;
1278 setSelectionMode(8);
1281 myGeomGroupBtn->setOn(false);
1282 myGeomObjects->length(0);
1283 myGeomGroupLine->setText("");
1284 myCurrentLineEdit = 0;
1286 setSelectionMode(myTypeId);
1291 //=================================================================================
1292 // function : setCurrentSelection()
1294 //=================================================================================
1295 void SMESHGUI_GroupDlg::setCurrentSelection()
1297 QPushButton* send = (QPushButton*)sender();
1298 myCurrentLineEdit = 0;
1299 if (send == myMeshGroupBtn) {
1300 myCurrentLineEdit = myMeshGroupLine;
1302 setSelectionMode(6);
1304 setSelectionMode(5);
1305 onObjectSelectionChanged();
1307 else if (send == mySubMeshBtn) {
1308 myCurrentLineEdit = mySubMeshLine;
1309 onObjectSelectionChanged();
1311 else if (send == myGroupBtn) {
1312 myCurrentLineEdit = myGroupLine;
1313 onObjectSelectionChanged();
1318 //=================================================================================
1319 // function : setFilters()
1320 // purpose : SLOT. Called when "Filter" button pressed.
1321 //=================================================================================
1322 void SMESHGUI_GroupDlg::setFilters()
1324 SMESH::ElementType aType = SMESH::ALL;
1327 case 0 : aType = SMESH::NODE; break;
1328 case 1 : aType = SMESH::EDGE; break;
1329 case 2 : aType = SMESH::FACE; break;
1330 case 3 : aType = SMESH::VOLUME; break;
1334 if ( myFilterDlg == 0 )
1336 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1337 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1340 myFilterDlg->Init( aType );
1342 myFilterDlg->SetSelection();
1343 myFilterDlg->SetMesh( myMesh );
1344 myFilterDlg->SetSourceWg( myElements );
1346 myFilterDlg->show();
1349 //=================================================================================
1350 // function : onFilterAccepted()
1351 // purpose : SLOT. Called when Filter dlg closed with OK button.
1352 // Uncheck "Select submesh" and "Select group" checkboxes
1353 //=================================================================================
1354 void SMESHGUI_GroupDlg::onFilterAccepted()
1356 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1358 mySelectionMode = myTypeId;
1359 mySelectSubMesh->setChecked( false );
1360 mySelectGroup->setChecked( false );
1364 //=================================================================================
1365 // function : onAdd()
1367 //=================================================================================
1368 void SMESHGUI_GroupDlg::onAdd()
1370 SALOME_ListIO aList;
1371 mySelectionMgr->selectedObjects( aList );
1373 int aNbSel = aList.Extent();
1375 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1379 SMESH::ElementType aType = SMESH::ALL;
1382 aType = SMESH::NODE;
1383 mySelector->SetSelectionMode(NodeSelection);
1386 aType = SMESH::EDGE;
1387 mySelector->SetSelectionMode(EdgeSelection);
1390 aType = SMESH::FACE;
1391 mySelector->SetSelectionMode(FaceSelection);
1394 aType = SMESH::VOLUME;
1395 mySelector->SetSelectionMode(VolumeSelection);
1398 mySelector->SetSelectionMode(ActorSelection);
1402 if (myCurrentLineEdit == 0) {
1403 //if (aNbSel != 1) { myIsBusy = false; return; }
1404 QString aListStr = "";
1406 if (myTypeId == 0) {
1407 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1410 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1413 QStringList anElements = QStringList::split(" ", aListStr);
1414 QListBoxItem* anItem = 0;
1415 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1416 anItem = myElements->findItem(*it, Qt::ExactMatch);
1418 anItem = new QListBoxText(*it);
1419 myElements->insertItem(anItem);
1421 myElements->setSelected(anItem, true);
1424 } else if (myCurrentLineEdit == mySubMeshLine) {
1425 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1427 SALOME_ListIO aList;
1428 mySelectionMgr->selectedObjects( aList );
1430 SALOME_ListIteratorOfListIO anIt (aList);
1431 for (; anIt.More(); anIt.Next()) {
1432 SMESH::SMESH_subMesh_var aSubMesh =
1433 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1434 if (!aSubMesh->_is_nil()) {
1435 // check if mesh is the same
1436 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1438 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1439 int k = anElements->length();
1440 QListBoxItem* anItem = 0;
1441 for (int i = 0; i < k; i++) {
1442 QString aText = QString::number(anElements[i]);
1443 anItem = myElements->findItem(aText, Qt::ExactMatch);
1445 anItem = new QListBoxText(aText);
1446 myElements->insertItem(anItem);
1448 myElements->setSelected(anItem, true);
1451 catch (const SALOME::SALOME_Exception& ex) {
1452 SalomeApp_Tools::QtCatchCorbaException(ex);
1457 mySelectSubMesh->setChecked(false);
1459 onListSelectionChanged();
1461 } else if (myCurrentLineEdit == myGroupLine) {
1462 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1463 SALOME_ListIO aList;
1464 mySelectionMgr->selectedObjects( aList );
1466 SALOME_ListIteratorOfListIO anIt (aList);
1467 for (; anIt.More(); anIt.Next()) {
1468 SMESH::SMESH_Group_var aGroup =
1469 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1470 if (!aGroup->_is_nil()) {
1471 // check if mesh is the same
1472 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1473 SMESH::long_array_var anElements = aGroup->GetListOfID();
1474 int k = anElements->length();
1475 QListBoxItem* anItem = 0;
1476 for (int i = 0; i < k; i++) {
1477 QString aText = QString::number(anElements[i]);
1478 anItem = myElements->findItem(aText, Qt::ExactMatch);
1480 anItem = new QListBoxText(aText);
1481 myElements->insertItem(anItem);
1483 myElements->setSelected(anItem, true);
1488 mySelectGroup->setChecked(false);
1490 onListSelectionChanged();
1492 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1493 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1494 GEOM::GEOM_IGroupOperations_var aGroupOp =
1495 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1497 SMESH::ElementType aGroupType = SMESH::ALL;
1498 switch(aGroupOp->GetType(myGeomObjects[0])) {
1499 case 7: aGroupType = SMESH::NODE; break;
1500 case 6: aGroupType = SMESH::EDGE; break;
1501 case 4: aGroupType = SMESH::FACE; break;
1502 case 2: aGroupType = SMESH::VOLUME; break;
1503 default: myIsBusy = false; return;
1506 if (aGroupType == aType) {
1507 _PTR(SObject) aGroupSO =
1508 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1509 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1511 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1512 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1513 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1514 aBelongToGeom->SetGeom(myGeomObjects[0]);
1515 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1516 aBelongToGeom->SetElementType(aType);
1517 aFilter->SetPredicate(aBelongToGeom);
1519 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1521 int k = anElements->length();
1522 QListBoxItem* anItem = 0;
1523 for (int i = 0; i < k; i++) {
1524 QString aText = QString::number(anElements[i]);
1525 anItem = myElements->findItem(aText, Qt::ExactMatch);
1527 anItem = new QListBoxText(aText);
1528 myElements->insertItem(anItem);
1530 myElements->setSelected(anItem, true);
1534 //VSR: mySelectGeomGroup->setChecked(false);
1536 onListSelectionChanged();
1539 // mySelectionMgr->clearSelected();
1543 //=================================================================================
1544 // function : onRemove()
1546 //=================================================================================
1547 void SMESHGUI_GroupDlg::onRemove()
1550 if (myCurrentLineEdit == 0) {
1551 for (int i = myElements->count(); i > 0; i--) {
1552 if (myElements->isSelected(i-1)) {
1553 myElements->removeItem(i-1);
1557 SALOME_ListIO aList;
1558 mySelectionMgr->selectedObjects( aList );
1560 int aNbSel = aList.Extent();
1562 if (aNbSel == 0) { myIsBusy = false; return; }
1564 SMESH::ElementType aType = SMESH::ALL;
1566 case 0: aType = SMESH::NODE; break;
1567 case 1: aType = SMESH::EDGE; break;
1568 case 2: aType = SMESH::FACE; break;
1569 case 3: aType = SMESH::VOLUME; break;
1572 if (myCurrentLineEdit == mySubMeshLine) {
1573 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1574 SALOME_ListIO aList;
1575 mySelectionMgr->selectedObjects( aList );
1577 SALOME_ListIteratorOfListIO anIt (aList);
1578 for (; anIt.More(); anIt.Next()) {
1579 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1580 if (!aSubMesh->_is_nil()) {
1581 // check if mesh is the same
1582 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1583 if (aType == SMESH::NODE) {
1585 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1586 int k = anElements->length();
1587 QListBoxItem* anItem = 0;
1588 for (int i = 0; i < k; i++) {
1589 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1590 if (anItem) delete anItem;
1593 catch (const SALOME::SALOME_Exception& ex) {
1594 SalomeApp_Tools::QtCatchCorbaException(ex);
1599 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1600 int k = anElements->length();
1601 QListBoxItem* anItem = 0;
1602 for (int i = 0; i < k; i++) {
1603 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1604 if (anItem) delete anItem;
1607 catch (const SALOME::SALOME_Exception& ex) {
1608 SalomeApp_Tools::QtCatchCorbaException(ex);
1615 else if (myCurrentLineEdit == myGroupLine) {
1616 Standard_Boolean aRes;
1617 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1618 SALOME_ListIO aList;
1619 mySelectionMgr->selectedObjects( aList );
1621 SALOME_ListIteratorOfListIO anIt (aList);
1622 for (; anIt.More(); anIt.Next()) {
1623 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1624 if (aRes && !aGroup->_is_nil()) {
1625 // check if mesh is the same
1626 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1627 SMESH::long_array_var anElements = aGroup->GetListOfID();
1628 int k = anElements->length();
1629 QListBoxItem* anItem = 0;
1630 for (int i = 0; i < k; i++) {
1631 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1632 if (anItem) delete anItem;
1643 //=================================================================================
1644 // function : onSort()
1646 //=================================================================================
1647 void SMESHGUI_GroupDlg::onSort()
1649 // PAL5412: sorts items in ascending by "string" value
1650 // myElements->sort(true);
1651 // myElements->update();
1652 int i, k = myElements->count();
1655 QStringList aSelected;
1656 std::vector<int> anArray(k);
1657 // QMemArray<int> anArray(k);
1658 QListBoxItem* anItem;
1660 for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1661 anArray[i] = anItem->text().toInt();
1662 if (anItem->isSelected())
1663 aSelected.append(anItem->text());
1665 // sort & update list
1666 std::sort(anArray.begin(), anArray.end());
1668 myElements->clear();
1669 for (i = 0; i < k; i++) {
1670 myElements->insertItem(QString::number(anArray[i]));
1672 for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1673 anItem = myElements->findItem(*it, Qt::ExactMatch);
1674 if (anItem) myElements->setSelected(anItem, true);
1680 //=================================================================================
1681 // function : closeEvent()
1683 //=================================================================================
1684 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1689 //=================================================================================
1690 // function : SMESHGUI_GroupDlg::onClose
1691 // purpose : SLOT called when "Close" button pressed. Close dialog
1692 //=================================================================================
1693 void SMESHGUI_GroupDlg::onClose()
1695 if (SMESH::GetCurrentVtkView()) {
1696 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1697 SMESH::SetPointRepresentation(false);
1698 SMESH::SetPickable();
1699 restoreShowEntityMode();
1702 mySelectionMgr->clearSelected();
1703 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1704 aViewWindow->SetSelectionMode(ActorSelection);
1705 mySelectionMgr->clearFilters();
1706 mySMESHGUI->ResetState();
1711 //=================================================================================
1712 // function : onHelp()
1714 //=================================================================================
1715 void SMESHGUI_GroupDlg::onHelp()
1717 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1719 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1723 platform = "winapplication";
1725 platform = "application";
1727 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1728 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1729 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
1730 QObject::tr("BUT_OK"));
1734 //=================================================================================
1735 // function : SMESHGUI_GroupDlg::onDeactivate
1736 // purpose : SLOT called when dialog must be deativated
1737 //=================================================================================
1738 void SMESHGUI_GroupDlg::onDeactivate()
1740 mySMESHGUI->ResetState();
1744 //=================================================================================
1745 // function : SMESHGUI_GroupDlg::enterEvent
1746 // purpose : Event filter
1747 //=================================================================================
1748 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1751 mySMESHGUI->EmitSignalDeactivateDialog();
1753 mySelectionMode = -1;
1754 setSelectionMode(myTypeId);
1755 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1756 mySMESHGUI->SetActiveDialogBox(this);
1757 mySMESHGUI->SetState(800);
1761 //=================================================================================
1762 // function : hideEvent
1763 // purpose : caused by ESC key
1764 //=================================================================================
1765 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1767 if (!isMinimized() && !myIsBusy)
1771 //=================================================================================
1772 // function : keyPressEvent()
1774 //=================================================================================
1775 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1777 QDialog::keyPressEvent( e );
1778 if ( e->isAccepted() )
1781 if ( e->key() == Key_F1 )
1788 //================================================================================
1790 * \brief Enable showing of the popup when Geometry selection btn is clicked
1791 * \param enable - true to enable
1793 //================================================================================
1795 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1797 void SMESHGUI_GroupDlg::updateGeomPopup()
1799 bool enable = false;
1801 if ( !myMesh->_is_nil() )
1802 enable = myMesh->NbEdges() > 0;
1804 if ( myGeomGroupBtn )
1806 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1808 if ( !myGeomPopup ) {
1809 myGeomPopup = new QPopupMenu();
1810 myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
1811 myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
1812 connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
1814 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1820 //=================================================================================
1821 // function : onGeomSelectionButton()
1823 //=================================================================================
1824 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1826 if ( myGeomPopup && isBtnOn )
1828 myCurrentLineEdit = myGeomGroupLine;
1829 int id = myGeomPopup->exec( QCursor::pos() );
1830 if (id == DIRECT_GEOM_INDEX || id == -1)
1831 setSelectionMode(7);
1835 myCurrentLineEdit = 0;
1836 setSelectionMode(8);
1840 //=================================================================================
1841 // function : onGeomPopup()
1843 //=================================================================================
1844 void SMESHGUI_GroupDlg::onGeomPopup( int index )
1846 if ( index == GEOM_BY_MESH_INDEX )
1848 mySelectionMode = -1;
1849 if ( !myShapeByMeshOp ) {
1850 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1851 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1852 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1853 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1854 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1856 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1857 if ( !myMesh->_is_nil() ) {
1859 hide(); // stop processing selection
1861 myShapeByMeshOp->setModule( mySMESHGUI );
1862 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1863 myShapeByMeshOp->SetMesh( myMesh );
1864 myShapeByMeshOp->start();
1869 //================================================================================
1871 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1873 //================================================================================
1875 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1877 if ( myShapeByMeshOp == op ) {
1878 mySMESHGUI->getApp()->updateObjectBrowser();
1880 // Select a found geometry object
1881 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1882 if ( !aGeomVar->_is_nil() )
1884 QString ID = aGeomVar->GetStudyEntry();
1885 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1886 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
1887 SALOME_ListIO anIOList;
1888 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1889 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1890 anIOList.Append( anIO );
1891 mySelectionMgr->setSelectedObjects( anIOList, false );
1892 onObjectSelectionChanged();
1898 //================================================================================
1900 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1902 //================================================================================
1904 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1906 if ( myShapeByMeshOp == op )
1909 setSelectionMode(7);
1913 //=================================================================================
1914 // function : setGroupColor()
1916 //=================================================================================
1917 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
1919 QColor aQColor( (int)( theColor.R * 255.0 ),
1920 (int)( theColor.G * 255.0 ),
1921 (int)( theColor.B * 255.0 ) );
1922 setGroupQColor( aQColor );
1925 //=================================================================================
1926 // function : getGroupColor()
1928 //=================================================================================
1929 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
1931 QColor aQColor = getGroupQColor();
1933 SALOMEDS::Color aColor;
1934 aColor.R = (float)aQColor.red() / 255.0;
1935 aColor.G = (float)aQColor.green() / 255.0;
1936 aColor.B = (float)aQColor.blue() / 255.0;
1941 //=================================================================================
1942 // function : setGroupQColor()
1944 //=================================================================================
1945 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
1947 if( theColor.isValid() )
1949 QPalette pal = myColorBtn->palette();
1950 pal.setColor(QColorGroup::Button, theColor);
1951 myColorBtn->setPalette(pal);
1955 //=================================================================================
1956 // function : getGroupQColor()
1958 //=================================================================================
1959 QColor SMESHGUI_GroupDlg::getGroupQColor() const
1961 QColor aColor = myColorBtn->palette().active().button();
1965 //=================================================================================
1966 // function : setDefaultGroupColor()
1968 //=================================================================================
1969 void SMESHGUI_GroupDlg::setDefaultGroupColor()
1971 if( myMesh->_is_nil() )
1974 bool isAutoColor = myMesh->GetAutoColor();
1979 int r = 0, g = 0, b = 0;
1980 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
1981 aQColor.setRgb( r, g, b );
1985 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
1987 QValueList<SALOMEDS::Color> aReservedColors;
1988 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1990 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1991 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
1992 aReservedColors.append( aReservedColor );
1995 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1996 aQColor.setRgb( (int)( aColor.R * 255.0 ),
1997 (int)( aColor.G * 255.0 ),
1998 (int)( aColor.B * 255.0 ) );
2002 setGroupQColor( aQColor );
2005 //=======================================================================
2006 //function : setShowEntityMode
2007 //purpose : make shown only entity corresponding to my type
2008 //=======================================================================
2010 void SMESHGUI_GroupDlg::setShowEntityMode()
2012 if ( !myMesh->_is_nil() ) {
2013 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2014 if (!myStoredShownEntity)
2015 myStoredShownEntity = actor->GetEntityMode();
2016 switch ( myTypeId ) {
2017 case 0: restoreShowEntityMode(); break;
2018 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2019 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2020 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2026 //=======================================================================
2027 //function : restoreShowEntityMode
2028 //purpose : restore ShowEntity mode of myActor
2029 //=======================================================================
2031 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2033 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2034 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2035 actor->SetEntityMode(myStoredShownEntity);
2038 myStoredShownEntity = 0;