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());
520 myOldName = myName->text();
522 SALOMEDS::Color aColor = theGroup->GetColor();
523 setGroupColor( aColor );
525 myMeshGroupLine->setText(theGroup->GetName());
528 switch(theGroup->GetType()) {
529 case SMESH::NODE: aType= 0; break;
530 case SMESH::EDGE: aType = 1; break;
531 case SMESH::FACE: aType = 2; break;
532 case SMESH::VOLUME: aType = 3; break;
534 myTypeGroup->setButton(aType);
536 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
538 if ( !myGroup->_is_nil() )
540 myActor = SMESH::FindActorByObject(myMesh);
542 myActor = SMESH::FindActorByObject(myGroup);
543 SMESH::SetPickable(myActor);
545 myGrpTypeGroup->setButton(0);
548 myCurrentLineEdit = 0;
550 setSelectionMode(aType);
554 if (!myGroup->IsEmpty()) {
555 SMESH::long_array_var anElements = myGroup->GetListOfID();
556 int k = anElements->length();
557 for (int i = 0; i < k; i++) {
558 myIdList.append(anElements[i]);
559 myElements->insertItem(QString::number(anElements[i]));
561 myElements->selectAll(true);
566 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
568 if ( !myGroupOnGeom->_is_nil() )
570 myActor = SMESH::FindActorByObject(myMesh);
572 myActor = SMESH::FindActorByObject(myGroup);
573 SMESH::SetPickable(myActor);
575 myGrpTypeGroup->setButton(1);
578 QString aShapeName("");
579 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
580 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
581 if (!aGroupShape->_is_nil())
583 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
584 aShapeName = aGroupShapeSO->GetName().c_str();
586 myGeomGroupLine->setText( aShapeName );
587 myName->setText("Group On " + aShapeName);
592 //=================================================================================
593 // function : updateButtons()
595 //=================================================================================
596 void SMESHGUI_GroupDlg::updateButtons()
598 bool enable = !myName->text().stripWhiteSpace().isEmpty();
600 if (myGrpTypeId == 0) {
601 enable = enable && myElements->count() > 0;
602 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
604 else if (myGrpTypeId == 1) {
605 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
606 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
611 aBtn = (QPushButton*) child("ok", "QPushButton");
612 if (aBtn) aBtn->setEnabled(enable);
613 aBtn = (QPushButton*) child("apply", "QPushButton");
614 if (aBtn) aBtn->setEnabled(enable);
617 //=================================================================================
618 // function : onNameChanged()
620 //=================================================================================
621 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
626 //=================================================================================
627 // function : 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 );
650 myName->setText(myOldName);
651 onSelectGeomGroup(id == 1);
656 //=================================================================================
657 // function : onSelectColor()
659 //=================================================================================
660 void SMESHGUI_GroupDlg::onSelectColor()
662 QColor color = getGroupQColor();
663 color = QColorDialog::getColor( color );
664 setGroupQColor( color );
669 //=================================================================================
670 // function : setSelectionMode()
671 // purpose : Radio button management
672 //=================================================================================
673 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
676 if (myMesh->_is_nil())
678 if (mySelectionMode != theMode) {
679 // [PAL10408] mySelectionMgr->clearSelected();
680 mySelectionMgr->clearFilters();
682 myActor->SetPointRepresentation(false);
684 SMESH::SetPointRepresentation(false);
689 myActor->SetPointRepresentation(true);
691 SMESH::SetPointRepresentation(true);
692 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
693 aViewWindow->SetSelectionMode(NodeSelection);
696 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
697 aViewWindow->SetSelectionMode(EdgeSelection);
700 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
701 aViewWindow->SetSelectionMode(FaceSelection);
704 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
705 aViewWindow->SetSelectionMode(VolumeSelection);
709 mySelectionMgr->installFilter(mySubMeshFilter);
710 else if (theMode == 5)
711 mySelectionMgr->installFilter(myGroupFilter);
712 else if (theMode == 6)
713 mySelectionMgr->installFilter(myMeshFilter);
714 else if (theMode == 7)
715 mySelectionMgr->installFilter(myGeomFilter);
717 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
718 aViewWindow->SetSelectionMode(ActorSelection);
720 mySelectionMode = theMode;
724 //=================================================================================
725 // function : onApply()
727 //=================================================================================
728 bool SMESHGUI_GroupDlg::onApply()
730 if (mySMESHGUI->isActiveStudyLocked())
733 if (myName->text().stripWhiteSpace().isEmpty())
736 if (myGrpTypeId == 0) { // on mesh elements
737 if (!myElements->count())
740 mySelectionMgr->clearSelected();
742 if (myGroup->_is_nil()) { // creation
743 if (myMesh->_is_nil())
746 SMESH::ElementType aType = SMESH::ALL;
748 case 0: aType = SMESH::NODE; break;
749 case 1: aType = SMESH::EDGE; break;
750 case 2: aType = SMESH::FACE; break;
751 case 3: aType = SMESH::VOLUME; break;
754 SMESH::long_array_var anIdList = new SMESH::long_array;
755 int i, k = myElements->count();
757 QListBoxItem* anItem;
758 for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
759 anIdList[i] = anItem->text().toInt();
762 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
763 myGroup->Add(anIdList.inout());
765 SALOMEDS::Color aColor = getGroupColor();
766 myGroup->SetColor(aColor);
768 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
770 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
771 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
773 /* init for next operation */
776 myGroup = SMESH::SMESH_Group::_nil();
779 myGroup->SetName(myName->text());
781 SALOMEDS::Color aColor = getGroupColor();
782 myGroup->SetColor(aColor);
784 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
785 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
786 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
788 QValueList<int> aAddList;
789 QValueList<int>::iterator anIt;
790 QListBoxItem* anItem;
792 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
793 int anId = anItem->text().toInt();
794 if ((anIt = myIdList.find(anId)) == myIdList.end())
795 aAddList.append(anId);
797 myIdList.remove(anIt);
799 if (!aAddList.empty()) {
800 SMESH::long_array_var anIdList = new SMESH::long_array;
801 anIdList->length(aAddList.count());
803 for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
805 myGroup->Add(anIdList.inout());
807 if (!myIdList.empty()) {
808 SMESH::long_array_var anIdList = new SMESH::long_array;
809 anIdList->length(myIdList.count());
811 for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
813 myGroup->Remove(anIdList.inout());
815 /* init for next operation */
817 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
818 myIdList.append(anItem->text().toInt());
821 mySMESHGUI->updateObjBrowser(true);
822 SMESH::UpdateView(); // asv: fix of BUG PAL5515
823 mySelectionMgr->clearSelected();
826 else if (myGrpTypeId == 1) { // on geom object
827 if (CORBA::is_nil(myGroupOnGeom)) { // creation
828 if (myMesh->_is_nil() || !myGeomObjects->length())
831 SMESH::ElementType aType = SMESH::ALL;
833 case 0: aType = SMESH::NODE; break;
834 case 1: aType = SMESH::EDGE; break;
835 case 2: aType = SMESH::FACE; break;
836 case 3: aType = SMESH::VOLUME; break;
839 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
840 GEOM::GEOM_IGroupOperations_var aGroupOp =
841 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
843 if (myGeomObjects->length() == 1) {
844 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
847 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
848 if ( aSMESHGen->_is_nil() )
851 // create a geometry group
852 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
853 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
855 if (geomGen->_is_nil() || !aStudy)
858 GEOM::GEOM_IGroupOperations_var op =
859 geomGen->GetIGroupOperations(aStudy->StudyId());
863 // check and add all selected GEOM objects: they must be
864 // a sub-shapes of the main GEOM and must be of one type
865 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
866 for ( int i =0; i < myGeomObjects->length(); i++) {
867 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
869 aGroupType = aSubShapeType;
870 else if (aSubShapeType != aGroupType) {
871 aGroupType = TopAbs_SHAPE;
876 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
877 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
878 op->UnionList(aGroupVar, myGeomObjects);
881 // publish the GEOM group in study
882 QString aNewGeomGroupName ("Auto_group_for_");
883 aNewGeomGroupName += myName->text();
884 SALOMEDS::SObject_var aNewGroupSO =
885 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
888 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
891 SALOMEDS::Color aColor = getGroupColor();
892 myGroupOnGeom->SetColor(aColor);
894 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
896 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
897 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
899 /* init for next operation */
901 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
904 myGroupOnGeom->SetName(myName->text());
906 SALOMEDS::Color aColor = getGroupColor();
907 myGroupOnGeom->SetColor(aColor);
909 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
910 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
911 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
914 mySMESHGUI->updateObjBrowser(true);
915 mySelectionMgr->clearSelected();
922 //=================================================================================
925 //=================================================================================
926 void SMESHGUI_GroupDlg::onOK()
932 //=================================================================================
933 // function : onListSelectionChanged()
934 // purpose : Called when selection in element list is changed
935 //=================================================================================
936 void SMESHGUI_GroupDlg::onListSelectionChanged()
938 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
939 if( myIsBusy || !myActor) return;
942 if (myCurrentLineEdit == 0) {
943 mySelectionMgr->clearSelected();
944 TColStd_MapOfInteger aIndexes;
945 QListBoxItem* anItem;
946 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
947 if (anItem->isSelected()) {
948 int anId = anItem->text().toInt();
952 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
954 aList.Append(myActor->getIO());
955 mySelectionMgr->setSelectedObjects(aList,false);
960 //=================================================================================
961 // function : onObjectSelectionChanged()
962 // purpose : Called when selection in 3D view or ObjectBrowser is changed
963 //=================================================================================
964 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
966 if ( myIsBusy || !isEnabled()) return;
967 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
972 mySelectionMgr->selectedObjects( aList );
974 int aNbSel = aList.Extent();
975 myElements->clearSelection();
977 if (myCurrentLineEdit) {
978 myCurrentLineEdit->setText("");
979 QString aString = "";
981 if (myCurrentLineEdit == myMeshGroupLine) {
982 mySelectSubMesh->setEnabled(false);
983 mySelectGroup->setEnabled(false);
984 myGroupLine->setText("");
985 mySubMeshLine->setText("");
987 myGeomGroupBtn->setEnabled(false);
988 myGeomGroupLine->setEnabled(false);
989 myGeomGroupLine->setText("");
990 myGeomObjects = new GEOM::ListOfGO();
991 myGeomObjects->length(0);
993 if (myGeomGroupBtn->isOn())
994 myGeomGroupBtn->setOn(false);
1001 myGroup = SMESH::SMESH_Group::_nil();
1002 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1003 restoreShowEntityMode();
1004 myMesh = SMESH::SMESH_Mesh::_nil();
1010 Handle(SALOME_InteractiveObject) IO = aList.First();
1013 restoreShowEntityMode();
1014 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1015 setShowEntityMode();
1017 if (myMesh->_is_nil())
1023 myGroup = SMESH::SMESH_Group::_nil();
1025 myActor = SMESH::FindActorByObject(myMesh);
1026 SMESH::SetPickable(myActor);
1028 aString = aList.First()->getName();
1029 myMeshGroupLine->setText(aString) ;
1030 myMeshGroupLine->home( false );
1032 mySelectSubMesh->setEnabled(true);
1033 mySelectGroup->setEnabled(true);
1034 myGeomGroupBtn->setEnabled(true);
1035 myGeomGroupLine->setEnabled(true);
1038 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1039 if (aGroup->_is_nil())
1045 myCurrentLineEdit = 0;
1047 myGroup = SMESH::SMESH_Group::_nil();
1048 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1052 mySelectSubMesh->setEnabled(true);
1053 mySelectGroup->setEnabled(true);
1055 myCurrentLineEdit = 0;
1060 if (myGrpTypeId == 0)
1066 myElements->clear();
1067 setSelectionMode(myTypeId);
1074 } else if (myCurrentLineEdit == myGeomGroupLine) {
1076 myGeomObjects = new GEOM::ListOfGO();
1079 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1081 if (aNbSel == 0 || !aMeshSO)
1083 myGeomObjects->length(0);
1089 myGeomObjects->length(aNbSel);
1091 GEOM::GEOM_Object_var aGeomGroup;
1092 Standard_Boolean testResult;
1095 SALOME_ListIteratorOfListIO anIt (aList);
1096 for (; anIt.More(); anIt.Next()) {
1098 testResult = Standard_False;
1099 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1101 // Check if the object is a geometry group
1102 if (!testResult || CORBA::is_nil(aGeomGroup))
1106 // Check if group constructed on the same shape as a mesh or on its child
1107 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1108 GEOM::GEOM_IGroupOperations_var anOp =
1109 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1111 // The main shape of the group
1112 GEOM::GEOM_Object_var aGroupMainShape;
1113 if (aGeomGroup->GetType() == 37)
1114 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1116 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1117 _PTR(SObject) aGroupMainShapeSO =
1118 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1119 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1121 _PTR(SObject) anObj, aRef;
1122 bool isRefOrSubShape = false;
1123 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1124 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1125 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1126 isRefOrSubShape = true;
1128 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1129 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1130 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1131 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1132 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1133 if (aRef->GetID() == aFather->GetID())
1134 isRefOrSubShape = true;
1136 aFather = aFather->GetFather();
1140 if (isRefOrSubShape)
1141 myGeomObjects[i++] = aGeomGroup;
1144 myGeomObjects->length(i);
1156 if(myCurrentLineEdit == mySubMeshLine)
1157 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1158 else if(myCurrentLineEdit == myGroupLine)
1159 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1160 else if(myCurrentLineEdit == myGeomGroupLine)
1161 aString = tr("%1 Objects").arg(aNbSel);
1163 aString = aList.First()->getName();
1167 myCurrentLineEdit->setText(aString);
1168 myOldName = myName->text();
1169 myName->setText(aString);
1170 myCurrentLineEdit->home(false);
1175 if (aNbSel == 1 && myActor ) {
1176 QString aListStr = "";
1178 if (myTypeId == 0) {
1179 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1181 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1184 QStringList anElements = QStringList::split(" ", aListStr);
1185 QListBoxItem* anItem = 0;
1186 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1187 anItem = myElements->findItem(*it, Qt::ExactMatch);
1188 if (anItem) myElements->setSelected(anItem, true);
1195 if (!myGroup->_is_nil())
1196 myActor = SMESH::FindActorByObject(myGroup);
1197 else if(!myGroupOnGeom->_is_nil())
1198 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1200 myActor = SMESH::FindActorByObject(myMesh);
1206 //=================================================================================
1207 // function : onSelectSubMesh()
1208 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1209 //=================================================================================
1210 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1213 if (mySelectGroup->isChecked()) {
1214 mySelectGroup->setChecked(false);
1216 //VSR: else if (mySelectGeomGroup->isChecked()) {
1217 //VSR: mySelectGeomGroup->setChecked(false);
1219 myCurrentLineEdit = mySubMeshLine;
1220 setSelectionMode(4);
1223 mySubMeshLine->setText("");
1224 myCurrentLineEdit = 0;
1226 setSelectionMode(myTypeId);
1228 mySubMeshBtn->setEnabled(on);
1229 mySubMeshLine->setEnabled(on);
1233 //=================================================================================
1234 // function : (onSelectGroup)
1235 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1236 //=================================================================================
1237 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1240 if (mySelectSubMesh->isChecked()) {
1241 mySelectSubMesh->setChecked(false);
1243 myCurrentLineEdit = myGroupLine;
1244 setSelectionMode(5);
1247 myGroupLine->setText("");
1248 myCurrentLineEdit = 0;
1250 setSelectionMode(myTypeId);
1252 myGroupBtn->setEnabled(on);
1253 myGroupLine->setEnabled(on);
1257 //=================================================================================
1258 // function : (onSelectGeomGroup)
1259 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1260 //=================================================================================
1261 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1264 if (mySelectSubMesh->isChecked()) {
1265 mySelectSubMesh->setChecked(false);
1267 else if (mySelectGroup->isChecked()) {
1268 mySelectGroup->setChecked(false);
1270 myCurrentLineEdit = myGeomGroupLine;
1272 setSelectionMode(8);
1275 myGeomGroupBtn->setOn(false);
1276 myGeomObjects->length(0);
1277 myGeomGroupLine->setText("");
1278 myCurrentLineEdit = 0;
1280 setSelectionMode(myTypeId);
1285 //=================================================================================
1286 // function : setCurrentSelection()
1288 //=================================================================================
1289 void SMESHGUI_GroupDlg::setCurrentSelection()
1291 QPushButton* send = (QPushButton*)sender();
1292 myCurrentLineEdit = 0;
1293 if (send == myMeshGroupBtn) {
1294 myCurrentLineEdit = myMeshGroupLine;
1296 setSelectionMode(6);
1298 setSelectionMode(5);
1299 onObjectSelectionChanged();
1301 else if (send == mySubMeshBtn) {
1302 myCurrentLineEdit = mySubMeshLine;
1303 onObjectSelectionChanged();
1305 else if (send == myGroupBtn) {
1306 myCurrentLineEdit = myGroupLine;
1307 onObjectSelectionChanged();
1312 //=================================================================================
1313 // function : setFilters()
1314 // purpose : SLOT. Called when "Filter" button pressed.
1315 //=================================================================================
1316 void SMESHGUI_GroupDlg::setFilters()
1318 SMESH::ElementType aType = SMESH::ALL;
1321 case 0 : aType = SMESH::NODE; break;
1322 case 1 : aType = SMESH::EDGE; break;
1323 case 2 : aType = SMESH::FACE; break;
1324 case 3 : aType = SMESH::VOLUME; break;
1328 if ( myFilterDlg == 0 )
1330 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1331 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1334 myFilterDlg->Init( aType );
1336 myFilterDlg->SetSelection();
1337 myFilterDlg->SetMesh( myMesh );
1338 myFilterDlg->SetSourceWg( myElements );
1340 myFilterDlg->show();
1343 //=================================================================================
1344 // function : onFilterAccepted()
1345 // purpose : SLOT. Called when Filter dlg closed with OK button.
1346 // Uncheck "Select submesh" and "Select group" checkboxes
1347 //=================================================================================
1348 void SMESHGUI_GroupDlg::onFilterAccepted()
1350 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1352 mySelectionMode = myTypeId;
1353 mySelectSubMesh->setChecked( false );
1354 mySelectGroup->setChecked( false );
1358 //=================================================================================
1359 // function : onAdd()
1361 //=================================================================================
1362 void SMESHGUI_GroupDlg::onAdd()
1364 SALOME_ListIO aList;
1365 mySelectionMgr->selectedObjects( aList );
1367 int aNbSel = aList.Extent();
1369 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1373 SMESH::ElementType aType = SMESH::ALL;
1376 aType = SMESH::NODE;
1377 mySelector->SetSelectionMode(NodeSelection);
1380 aType = SMESH::EDGE;
1381 mySelector->SetSelectionMode(EdgeSelection);
1384 aType = SMESH::FACE;
1385 mySelector->SetSelectionMode(FaceSelection);
1388 aType = SMESH::VOLUME;
1389 mySelector->SetSelectionMode(VolumeSelection);
1392 mySelector->SetSelectionMode(ActorSelection);
1396 if (myCurrentLineEdit == 0) {
1397 //if (aNbSel != 1) { myIsBusy = false; return; }
1398 QString aListStr = "";
1400 if (myTypeId == 0) {
1401 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1404 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1407 QStringList anElements = QStringList::split(" ", aListStr);
1408 QListBoxItem* anItem = 0;
1409 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1410 anItem = myElements->findItem(*it, Qt::ExactMatch);
1412 anItem = new QListBoxText(*it);
1413 myElements->insertItem(anItem);
1415 myElements->setSelected(anItem, true);
1418 } else if (myCurrentLineEdit == mySubMeshLine) {
1419 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1421 SALOME_ListIO aList;
1422 mySelectionMgr->selectedObjects( aList );
1424 SALOME_ListIteratorOfListIO anIt (aList);
1425 for (; anIt.More(); anIt.Next()) {
1426 SMESH::SMESH_subMesh_var aSubMesh =
1427 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1428 if (!aSubMesh->_is_nil()) {
1429 // check if mesh is the same
1430 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1432 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1433 int k = anElements->length();
1434 QListBoxItem* anItem = 0;
1435 for (int i = 0; i < k; i++) {
1436 QString aText = QString::number(anElements[i]);
1437 anItem = myElements->findItem(aText, Qt::ExactMatch);
1439 anItem = new QListBoxText(aText);
1440 myElements->insertItem(anItem);
1442 myElements->setSelected(anItem, true);
1445 catch (const SALOME::SALOME_Exception& ex) {
1446 SalomeApp_Tools::QtCatchCorbaException(ex);
1451 mySelectSubMesh->setChecked(false);
1453 onListSelectionChanged();
1455 } else if (myCurrentLineEdit == myGroupLine) {
1456 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1457 SALOME_ListIO aList;
1458 mySelectionMgr->selectedObjects( aList );
1460 SALOME_ListIteratorOfListIO anIt (aList);
1461 for (; anIt.More(); anIt.Next()) {
1462 SMESH::SMESH_Group_var aGroup =
1463 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1464 if (!aGroup->_is_nil()) {
1465 // check if mesh is the same
1466 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1467 SMESH::long_array_var anElements = aGroup->GetListOfID();
1468 int k = anElements->length();
1469 QListBoxItem* anItem = 0;
1470 for (int i = 0; i < k; i++) {
1471 QString aText = QString::number(anElements[i]);
1472 anItem = myElements->findItem(aText, Qt::ExactMatch);
1474 anItem = new QListBoxText(aText);
1475 myElements->insertItem(anItem);
1477 myElements->setSelected(anItem, true);
1482 mySelectGroup->setChecked(false);
1484 onListSelectionChanged();
1486 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1487 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1488 GEOM::GEOM_IGroupOperations_var aGroupOp =
1489 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1491 SMESH::ElementType aGroupType = SMESH::ALL;
1492 switch(aGroupOp->GetType(myGeomObjects[0])) {
1493 case 7: aGroupType = SMESH::NODE; break;
1494 case 6: aGroupType = SMESH::EDGE; break;
1495 case 4: aGroupType = SMESH::FACE; break;
1496 case 2: aGroupType = SMESH::VOLUME; break;
1497 default: myIsBusy = false; return;
1500 if (aGroupType == aType) {
1501 _PTR(SObject) aGroupSO =
1502 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1503 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1505 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1506 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1507 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1508 aBelongToGeom->SetGeom(myGeomObjects[0]);
1509 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1510 aBelongToGeom->SetElementType(aType);
1511 aFilter->SetPredicate(aBelongToGeom);
1513 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1515 int k = anElements->length();
1516 QListBoxItem* anItem = 0;
1517 for (int i = 0; i < k; i++) {
1518 QString aText = QString::number(anElements[i]);
1519 anItem = myElements->findItem(aText, Qt::ExactMatch);
1521 anItem = new QListBoxText(aText);
1522 myElements->insertItem(anItem);
1524 myElements->setSelected(anItem, true);
1528 //VSR: mySelectGeomGroup->setChecked(false);
1530 onListSelectionChanged();
1533 // mySelectionMgr->clearSelected();
1537 //=================================================================================
1538 // function : onRemove()
1540 //=================================================================================
1541 void SMESHGUI_GroupDlg::onRemove()
1544 if (myCurrentLineEdit == 0) {
1545 for (int i = myElements->count(); i > 0; i--) {
1546 if (myElements->isSelected(i-1)) {
1547 myElements->removeItem(i-1);
1551 SALOME_ListIO aList;
1552 mySelectionMgr->selectedObjects( aList );
1554 int aNbSel = aList.Extent();
1556 if (aNbSel == 0) { myIsBusy = false; return; }
1558 SMESH::ElementType aType = SMESH::ALL;
1560 case 0: aType = SMESH::NODE; break;
1561 case 1: aType = SMESH::EDGE; break;
1562 case 2: aType = SMESH::FACE; break;
1563 case 3: aType = SMESH::VOLUME; break;
1566 if (myCurrentLineEdit == mySubMeshLine) {
1567 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1568 SALOME_ListIO aList;
1569 mySelectionMgr->selectedObjects( aList );
1571 SALOME_ListIteratorOfListIO anIt (aList);
1572 for (; anIt.More(); anIt.Next()) {
1573 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1574 if (!aSubMesh->_is_nil()) {
1575 // check if mesh is the same
1576 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1577 if (aType == SMESH::NODE) {
1579 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1580 int k = anElements->length();
1581 QListBoxItem* anItem = 0;
1582 for (int i = 0; i < k; i++) {
1583 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1584 if (anItem) delete anItem;
1587 catch (const SALOME::SALOME_Exception& ex) {
1588 SalomeApp_Tools::QtCatchCorbaException(ex);
1593 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1594 int k = anElements->length();
1595 QListBoxItem* anItem = 0;
1596 for (int i = 0; i < k; i++) {
1597 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1598 if (anItem) delete anItem;
1601 catch (const SALOME::SALOME_Exception& ex) {
1602 SalomeApp_Tools::QtCatchCorbaException(ex);
1609 else if (myCurrentLineEdit == myGroupLine) {
1610 Standard_Boolean aRes;
1611 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1612 SALOME_ListIO aList;
1613 mySelectionMgr->selectedObjects( aList );
1615 SALOME_ListIteratorOfListIO anIt (aList);
1616 for (; anIt.More(); anIt.Next()) {
1617 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1618 if (aRes && !aGroup->_is_nil()) {
1619 // check if mesh is the same
1620 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1621 SMESH::long_array_var anElements = aGroup->GetListOfID();
1622 int k = anElements->length();
1623 QListBoxItem* anItem = 0;
1624 for (int i = 0; i < k; i++) {
1625 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1626 if (anItem) delete anItem;
1637 //=================================================================================
1638 // function : onSort()
1640 //=================================================================================
1641 void SMESHGUI_GroupDlg::onSort()
1643 // PAL5412: sorts items in ascending by "string" value
1644 // myElements->sort(true);
1645 // myElements->update();
1646 int i, k = myElements->count();
1649 QStringList aSelected;
1650 std::vector<int> anArray(k);
1651 // QMemArray<int> anArray(k);
1652 QListBoxItem* anItem;
1654 for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1655 anArray[i] = anItem->text().toInt();
1656 if (anItem->isSelected())
1657 aSelected.append(anItem->text());
1659 // sort & update list
1660 std::sort(anArray.begin(), anArray.end());
1662 myElements->clear();
1663 for (i = 0; i < k; i++) {
1664 myElements->insertItem(QString::number(anArray[i]));
1666 for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1667 anItem = myElements->findItem(*it, Qt::ExactMatch);
1668 if (anItem) myElements->setSelected(anItem, true);
1674 //=================================================================================
1675 // function : closeEvent()
1677 //=================================================================================
1678 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1683 //=================================================================================
1684 // function : SMESHGUI_GroupDlg::onClose
1685 // purpose : SLOT called when "Close" button pressed. Close dialog
1686 //=================================================================================
1687 void SMESHGUI_GroupDlg::onClose()
1689 if (SMESH::GetCurrentVtkView()) {
1690 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1691 SMESH::SetPointRepresentation(false);
1692 SMESH::SetPickable();
1693 restoreShowEntityMode();
1696 mySelectionMgr->clearSelected();
1697 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1698 aViewWindow->SetSelectionMode(ActorSelection);
1699 mySelectionMgr->clearFilters();
1700 mySMESHGUI->ResetState();
1705 //=================================================================================
1706 // function : onHelp()
1708 //=================================================================================
1709 void SMESHGUI_GroupDlg::onHelp()
1711 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1713 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1717 platform = "winapplication";
1719 platform = "application";
1721 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1722 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1723 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
1724 QObject::tr("BUT_OK"));
1728 //=================================================================================
1729 // function : SMESHGUI_GroupDlg::onDeactivate
1730 // purpose : SLOT called when dialog must be deativated
1731 //=================================================================================
1732 void SMESHGUI_GroupDlg::onDeactivate()
1734 mySMESHGUI->ResetState();
1738 //=================================================================================
1739 // function : SMESHGUI_GroupDlg::enterEvent
1740 // purpose : Event filter
1741 //=================================================================================
1742 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1745 mySMESHGUI->EmitSignalDeactivateDialog();
1747 mySelectionMode = -1;
1748 setSelectionMode(myTypeId);
1749 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1750 mySMESHGUI->SetActiveDialogBox(this);
1751 mySMESHGUI->SetState(800);
1755 //=================================================================================
1756 // function : hideEvent
1757 // purpose : caused by ESC key
1758 //=================================================================================
1759 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1761 if (!isMinimized() && !myIsBusy)
1765 //=================================================================================
1766 // function : keyPressEvent()
1768 //=================================================================================
1769 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1771 QDialog::keyPressEvent( e );
1772 if ( e->isAccepted() )
1775 if ( e->key() == Key_F1 )
1782 //================================================================================
1784 * \brief Enable showing of the popup when Geometry selection btn is clicked
1785 * \param enable - true to enable
1787 //================================================================================
1789 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1791 void SMESHGUI_GroupDlg::updateGeomPopup()
1793 bool enable = false;
1795 if ( !myMesh->_is_nil() )
1796 enable = myMesh->NbEdges() > 0;
1798 if ( myGeomGroupBtn )
1800 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1802 if ( !myGeomPopup ) {
1803 myGeomPopup = new QPopupMenu();
1804 myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
1805 myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
1806 connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
1808 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1814 //=================================================================================
1815 // function : onGeomSelectionButton()
1817 //=================================================================================
1818 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1820 if ( myGeomPopup && isBtnOn )
1822 myCurrentLineEdit = myGeomGroupLine;
1823 int id = myGeomPopup->exec( QCursor::pos() );
1824 if (id == DIRECT_GEOM_INDEX || id == -1)
1825 setSelectionMode(7);
1829 myCurrentLineEdit = 0;
1830 setSelectionMode(8);
1834 //=================================================================================
1835 // function : onGeomPopup()
1837 //=================================================================================
1838 void SMESHGUI_GroupDlg::onGeomPopup( int index )
1840 if ( index == GEOM_BY_MESH_INDEX )
1842 mySelectionMode = -1;
1843 if ( !myShapeByMeshOp ) {
1844 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1845 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1846 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1847 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1848 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1850 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1851 if ( !myMesh->_is_nil() ) {
1853 hide(); // stop processing selection
1855 myShapeByMeshOp->setModule( mySMESHGUI );
1856 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1857 myShapeByMeshOp->SetMesh( myMesh );
1858 myShapeByMeshOp->start();
1863 //================================================================================
1865 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1867 //================================================================================
1869 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1871 if ( myShapeByMeshOp == op ) {
1872 mySMESHGUI->getApp()->updateObjectBrowser();
1874 // Select a found geometry object
1875 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1876 if ( !aGeomVar->_is_nil() )
1878 QString ID = aGeomVar->GetStudyEntry();
1879 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1880 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
1881 SALOME_ListIO anIOList;
1882 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1883 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1884 anIOList.Append( anIO );
1885 mySelectionMgr->setSelectedObjects( anIOList, false );
1886 onObjectSelectionChanged();
1892 //================================================================================
1894 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1896 //================================================================================
1898 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1900 if ( myShapeByMeshOp == op )
1903 setSelectionMode(7);
1907 //=================================================================================
1908 // function : setGroupColor()
1910 //=================================================================================
1911 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
1913 QColor aQColor( (int)( theColor.R * 255.0 ),
1914 (int)( theColor.G * 255.0 ),
1915 (int)( theColor.B * 255.0 ) );
1916 setGroupQColor( aQColor );
1919 //=================================================================================
1920 // function : getGroupColor()
1922 //=================================================================================
1923 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
1925 QColor aQColor = getGroupQColor();
1927 SALOMEDS::Color aColor;
1928 aColor.R = (float)aQColor.red() / 255.0;
1929 aColor.G = (float)aQColor.green() / 255.0;
1930 aColor.B = (float)aQColor.blue() / 255.0;
1935 //=================================================================================
1936 // function : setGroupQColor()
1938 //=================================================================================
1939 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
1941 if( theColor.isValid() )
1943 QPalette pal = myColorBtn->palette();
1944 pal.setColor(QColorGroup::Button, theColor);
1945 myColorBtn->setPalette(pal);
1949 //=================================================================================
1950 // function : getGroupQColor()
1952 //=================================================================================
1953 QColor SMESHGUI_GroupDlg::getGroupQColor() const
1955 QColor aColor = myColorBtn->palette().active().button();
1959 //=================================================================================
1960 // function : setDefaultGroupColor()
1962 //=================================================================================
1963 void SMESHGUI_GroupDlg::setDefaultGroupColor()
1965 if( myMesh->_is_nil() )
1968 bool isAutoColor = myMesh->GetAutoColor();
1973 int r = 0, g = 0, b = 0;
1974 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
1975 aQColor.setRgb( r, g, b );
1979 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
1981 QValueList<SALOMEDS::Color> aReservedColors;
1982 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1984 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1985 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
1986 aReservedColors.append( aReservedColor );
1989 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1990 aQColor.setRgb( (int)( aColor.R * 255.0 ),
1991 (int)( aColor.G * 255.0 ),
1992 (int)( aColor.B * 255.0 ) );
1996 setGroupQColor( aQColor );
1999 //=======================================================================
2000 //function : setShowEntityMode
2001 //purpose : make shown only entity corresponding to my type
2002 //=======================================================================
2004 void SMESHGUI_GroupDlg::setShowEntityMode()
2006 if ( !myMesh->_is_nil() ) {
2007 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2008 if (!myStoredShownEntity)
2009 myStoredShownEntity = actor->GetEntityMode();
2010 switch ( myTypeId ) {
2011 case 0: restoreShowEntityMode(); break;
2012 case 1: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
2013 case 2: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
2014 case 3: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
2020 //=======================================================================
2021 //function : restoreShowEntityMode
2022 //purpose : restore ShowEntity mode of myActor
2023 //=======================================================================
2025 void SMESHGUI_GroupDlg::restoreShowEntityMode()
2027 if ( myStoredShownEntity && !myMesh->_is_nil() ) {
2028 if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
2029 actor->SetEntityMode(myStoredShownEntity);
2032 myStoredShownEntity = 0;