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* aOKBtn = new QPushButton(aButtons, "ok");
339 aOKBtn->setText(tr("SMESH_BUT_OK"));
340 aOKBtn->setAutoDefault(true);
341 aOKBtn->setDefault(true);
342 QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
343 aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
344 aApplyBtn->setAutoDefault(true);
345 QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
346 aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
347 aCloseBtn->setAutoDefault(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 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
483 myGroup = SMESH::SMESH_Group::_nil();
484 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
486 myActor = SMESH::FindActorByObject(myMesh);
487 SMESH::SetPickable(myActor);
489 setDefaultGroupColor();
492 mySelectionMgr->selectedObjects( aList );
493 if( !aList.IsEmpty() )
495 QString aName = aList.First()->getName();
496 myMeshGroupLine->setText(aName) ;
497 myMeshGroupLine->home( false );
500 myCurrentLineEdit = 0;
502 myTypeGroup->setButton(0);
506 //=================================================================================
509 //=================================================================================
510 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
512 myMesh = theGroup->GetMesh();
514 myName->setText(theGroup->GetName());
516 myOldName = myName->text();
518 SALOMEDS::Color aColor = theGroup->GetColor();
519 setGroupColor( aColor );
521 myMeshGroupLine->setText(theGroup->GetName());
524 switch(theGroup->GetType()) {
525 case SMESH::NODE: aType= 0; break;
526 case SMESH::EDGE: aType = 1; break;
527 case SMESH::FACE: aType = 2; break;
528 case SMESH::VOLUME: aType = 3; break;
530 myTypeGroup->setButton(aType);
532 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
534 if ( !myGroup->_is_nil() )
536 myActor = SMESH::FindActorByObject(myMesh);
538 myActor = SMESH::FindActorByObject(myGroup);
539 SMESH::SetPickable(myActor);
541 myGrpTypeGroup->setButton(0);
544 myCurrentLineEdit = 0;
546 setSelectionMode(aType);
550 if (!myGroup->IsEmpty()) {
551 SMESH::long_array_var anElements = myGroup->GetListOfID();
552 int k = anElements->length();
553 for (int i = 0; i < k; i++) {
554 myIdList.append(anElements[i]);
555 myElements->insertItem(QString::number(anElements[i]));
557 myElements->selectAll(true);
562 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
564 if ( !myGroupOnGeom->_is_nil() )
566 myActor = SMESH::FindActorByObject(myMesh);
568 myActor = SMESH::FindActorByObject(myGroup);
569 SMESH::SetPickable(myActor);
571 myGrpTypeGroup->setButton(1);
574 QString aShapeName("");
575 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
576 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
577 if (!aGroupShape->_is_nil())
579 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
580 aShapeName = aGroupShapeSO->GetName().c_str();
582 myGeomGroupLine->setText( aShapeName );
583 myName->setText("Group On " + aShapeName);
588 //=================================================================================
589 // function : updateButtons()
591 //=================================================================================
592 void SMESHGUI_GroupDlg::updateButtons()
594 bool enable = !myName->text().stripWhiteSpace().isEmpty();
596 if (myGrpTypeId == 0) {
597 enable = enable && myElements->count() > 0;
598 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
600 else if (myGrpTypeId == 1) {
601 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
602 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
607 aBtn = (QPushButton*) child("ok", "QPushButton");
608 if (aBtn) aBtn->setEnabled(enable);
609 aBtn = (QPushButton*) child("apply", "QPushButton");
610 if (aBtn) aBtn->setEnabled(enable);
613 //=================================================================================
614 // function : onNameChanged()
616 //=================================================================================
617 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
622 //=================================================================================
623 // function : onTypeChanged()
624 // purpose : Group elements type radio button management
625 //=================================================================================
626 void SMESHGUI_GroupDlg::onTypeChanged (int id)
628 if (myTypeId != id) {
630 if (myCurrentLineEdit == 0)
631 setSelectionMode(id);
636 //=================================================================================
637 // function : onGrpTypeChanged()
638 // purpose : Group type radio button management
639 //=================================================================================
640 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
642 if (myGrpTypeId != id) {
643 myWGStack->raiseWidget( id );
645 myName->setText(myOldName);
646 onSelectGeomGroup(id == 1);
651 //=================================================================================
652 // function : onSelectColor()
654 //=================================================================================
655 void SMESHGUI_GroupDlg::onSelectColor()
657 QColor color = getGroupQColor();
658 color = QColorDialog::getColor( color );
659 setGroupQColor( color );
664 //=================================================================================
665 // function : setSelectionMode()
666 // purpose : Radio button management
667 //=================================================================================
668 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
671 if (myMesh->_is_nil())
673 if (mySelectionMode != theMode) {
674 // [PAL10408] mySelectionMgr->clearSelected();
675 mySelectionMgr->clearFilters();
677 myActor->SetPointRepresentation(false);
679 SMESH::SetPointRepresentation(false);
684 myActor->SetPointRepresentation(true);
686 SMESH::SetPointRepresentation(true);
687 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
688 aViewWindow->SetSelectionMode(NodeSelection);
691 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
692 aViewWindow->SetSelectionMode(EdgeSelection);
695 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
696 aViewWindow->SetSelectionMode(FaceSelection);
699 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
700 aViewWindow->SetSelectionMode(VolumeSelection);
704 mySelectionMgr->installFilter(mySubMeshFilter);
705 else if (theMode == 5)
706 mySelectionMgr->installFilter(myGroupFilter);
707 else if (theMode == 6)
708 mySelectionMgr->installFilter(myMeshFilter);
709 else if (theMode == 7)
710 mySelectionMgr->installFilter(myGeomFilter);
712 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
713 aViewWindow->SetSelectionMode(ActorSelection);
715 mySelectionMode = theMode;
719 //=================================================================================
720 // function : onApply()
722 //=================================================================================
723 bool SMESHGUI_GroupDlg::onApply()
725 if (mySMESHGUI->isActiveStudyLocked())
728 if (myName->text().stripWhiteSpace().isEmpty())
731 if (myGrpTypeId == 0) { // on mesh elements
732 if (!myElements->count())
735 mySelectionMgr->clearSelected();
737 if (myGroup->_is_nil()) { // creation
738 if (myMesh->_is_nil())
741 SMESH::ElementType aType = SMESH::ALL;
743 case 0: aType = SMESH::NODE; break;
744 case 1: aType = SMESH::EDGE; break;
745 case 2: aType = SMESH::FACE; break;
746 case 3: aType = SMESH::VOLUME; break;
749 SMESH::long_array_var anIdList = new SMESH::long_array;
750 int i, k = myElements->count();
752 QListBoxItem* anItem;
753 for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
754 anIdList[i] = anItem->text().toInt();
757 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
758 myGroup->Add(anIdList.inout());
760 SALOMEDS::Color aColor = getGroupColor();
761 myGroup->SetColor(aColor);
763 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
765 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
766 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
768 /* init for next operation */
771 myGroup = SMESH::SMESH_Group::_nil();
774 myGroup->SetName(myName->text());
776 SALOMEDS::Color aColor = getGroupColor();
777 myGroup->SetColor(aColor);
779 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
780 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
781 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
783 QValueList<int> aAddList;
784 QValueList<int>::iterator anIt;
785 QListBoxItem* anItem;
787 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
788 int anId = anItem->text().toInt();
789 if ((anIt = myIdList.find(anId)) == myIdList.end())
790 aAddList.append(anId);
792 myIdList.remove(anIt);
794 if (!aAddList.empty()) {
795 SMESH::long_array_var anIdList = new SMESH::long_array;
796 anIdList->length(aAddList.count());
798 for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
800 myGroup->Add(anIdList.inout());
802 if (!myIdList.empty()) {
803 SMESH::long_array_var anIdList = new SMESH::long_array;
804 anIdList->length(myIdList.count());
806 for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
808 myGroup->Remove(anIdList.inout());
810 /* init for next operation */
812 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
813 myIdList.append(anItem->text().toInt());
816 mySMESHGUI->updateObjBrowser(true);
817 SMESH::UpdateView(); // asv: fix of BUG PAL5515
818 mySelectionMgr->clearSelected();
821 else if (myGrpTypeId == 1) { // on geom object
822 if (CORBA::is_nil(myGroupOnGeom)) { // creation
823 if (myMesh->_is_nil() || !myGeomObjects->length())
826 SMESH::ElementType aType = SMESH::ALL;
828 case 0: aType = SMESH::NODE; break;
829 case 1: aType = SMESH::EDGE; break;
830 case 2: aType = SMESH::FACE; break;
831 case 3: aType = SMESH::VOLUME; break;
834 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
835 GEOM::GEOM_IGroupOperations_var aGroupOp =
836 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
838 if (myGeomObjects->length() == 1) {
839 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
842 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
843 if ( aSMESHGen->_is_nil() )
846 // create a geometry group
847 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
848 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
850 if (geomGen->_is_nil() || !aStudy)
853 GEOM::GEOM_IGroupOperations_var op =
854 geomGen->GetIGroupOperations(aStudy->StudyId());
858 // check and add all selected GEOM objects: they must be
859 // a sub-shapes of the main GEOM and must be of one type
860 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
861 for ( int i =0; i < myGeomObjects->length(); i++) {
862 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
864 aGroupType = aSubShapeType;
865 else if (aSubShapeType != aGroupType) {
866 aGroupType = TopAbs_SHAPE;
871 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
872 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
873 op->UnionList(aGroupVar, myGeomObjects);
876 // publish the GEOM group in study
877 QString aNewGeomGroupName ("Auto_group_for_");
878 aNewGeomGroupName += myName->text();
879 SALOMEDS::SObject_var aNewGroupSO =
880 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
883 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
886 SALOMEDS::Color aColor = getGroupColor();
887 myGroupOnGeom->SetColor(aColor);
889 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
891 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
892 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
894 /* init for next operation */
896 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
899 myGroupOnGeom->SetName(myName->text());
901 SALOMEDS::Color aColor = getGroupColor();
902 myGroupOnGeom->SetColor(aColor);
904 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
905 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
906 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
909 mySMESHGUI->updateObjBrowser(true);
910 mySelectionMgr->clearSelected();
917 //=================================================================================
920 //=================================================================================
921 void SMESHGUI_GroupDlg::onOK()
927 //=================================================================================
928 // function : onListSelectionChanged()
929 // purpose : Called when selection in element list is changed
930 //=================================================================================
931 void SMESHGUI_GroupDlg::onListSelectionChanged()
933 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
934 if( myIsBusy || !myActor) return;
937 if (myCurrentLineEdit == 0) {
938 mySelectionMgr->clearSelected();
939 TColStd_MapOfInteger aIndexes;
940 QListBoxItem* anItem;
941 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
942 if (anItem->isSelected()) {
943 int anId = anItem->text().toInt();
947 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
949 aList.Append(myActor->getIO());
950 mySelectionMgr->setSelectedObjects(aList,false);
955 //=================================================================================
956 // function : onObjectSelectionChanged()
957 // purpose : Called when selection in 3D view or ObjectBrowser is changed
958 //=================================================================================
959 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
961 if ( myIsBusy || !isEnabled()) return;
962 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
967 mySelectionMgr->selectedObjects( aList );
969 int aNbSel = aList.Extent();
970 myElements->clearSelection();
972 if (myCurrentLineEdit) {
973 myCurrentLineEdit->setText("");
974 QString aString = "";
976 if (myCurrentLineEdit == myMeshGroupLine) {
977 mySelectSubMesh->setEnabled(false);
978 mySelectGroup->setEnabled(false);
979 myGroupLine->setText("");
980 mySubMeshLine->setText("");
982 myGeomGroupBtn->setEnabled(false);
983 myGeomGroupLine->setEnabled(false);
984 myGeomGroupLine->setText("");
985 myGeomObjects = new GEOM::ListOfGO();
986 myGeomObjects->length(0);
988 if (myGeomGroupBtn->isOn())
989 myGeomGroupBtn->setOn(false);
996 myGroup = SMESH::SMESH_Group::_nil();
997 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
998 myMesh = SMESH::SMESH_Mesh::_nil();
1004 Handle(SALOME_InteractiveObject) IO = aList.First();
1007 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
1009 if (myMesh->_is_nil())
1015 myGroup = SMESH::SMESH_Group::_nil();
1017 myActor = SMESH::FindActorByObject(myMesh);
1018 SMESH::SetPickable(myActor);
1020 aString = aList.First()->getName();
1021 myMeshGroupLine->setText(aString) ;
1022 myMeshGroupLine->home( false );
1024 mySelectSubMesh->setEnabled(true);
1025 mySelectGroup->setEnabled(true);
1026 myGeomGroupBtn->setEnabled(true);
1027 myGeomGroupLine->setEnabled(true);
1030 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
1031 if (aGroup->_is_nil())
1037 myCurrentLineEdit = 0;
1039 myGroup = SMESH::SMESH_Group::_nil();
1040 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1044 mySelectSubMesh->setEnabled(true);
1045 mySelectGroup->setEnabled(true);
1047 myCurrentLineEdit = 0;
1052 if (myGrpTypeId == 0)
1058 myElements->clear();
1059 setSelectionMode(myTypeId);
1066 } else if (myCurrentLineEdit == myGeomGroupLine) {
1068 myGeomObjects = new GEOM::ListOfGO();
1071 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1073 if (aNbSel == 0 || !aMeshSO)
1075 myGeomObjects->length(0);
1081 myGeomObjects->length(aNbSel);
1083 GEOM::GEOM_Object_var aGeomGroup;
1084 Standard_Boolean testResult;
1087 SALOME_ListIteratorOfListIO anIt (aList);
1088 for (; anIt.More(); anIt.Next()) {
1090 testResult = Standard_False;
1091 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1093 // Check if the object is a geometry group
1094 if (!testResult || CORBA::is_nil(aGeomGroup))
1098 // Check if group constructed on the same shape as a mesh or on its child
1099 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1100 GEOM::GEOM_IGroupOperations_var anOp =
1101 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1103 // The main shape of the group
1104 GEOM::GEOM_Object_var aGroupMainShape;
1105 if (aGeomGroup->GetType() == 37)
1106 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1108 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1109 _PTR(SObject) aGroupMainShapeSO =
1110 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1111 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1113 _PTR(SObject) anObj, aRef;
1114 bool isRefOrSubShape = false;
1115 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1116 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1117 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1118 isRefOrSubShape = true;
1120 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1121 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1122 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1123 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1124 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1125 if (aRef->GetID() == aFather->GetID())
1126 isRefOrSubShape = true;
1128 aFather = aFather->GetFather();
1132 if (isRefOrSubShape)
1133 myGeomObjects[i++] = aGeomGroup;
1136 myGeomObjects->length(i);
1148 if(myCurrentLineEdit == mySubMeshLine)
1149 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1150 else if(myCurrentLineEdit == myGroupLine)
1151 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1152 else if(myCurrentLineEdit == myGeomGroupLine)
1153 aString = tr("%1 Objects").arg(aNbSel);
1155 aString = aList.First()->getName();
1159 myCurrentLineEdit->setText(aString);
1160 myOldName = myName->text();
1161 myName->setText(aString);
1162 myCurrentLineEdit->home(false);
1167 if (aNbSel == 1 && myActor ) {
1168 QString aListStr = "";
1170 if (myTypeId == 0) {
1171 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1173 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1176 QStringList anElements = QStringList::split(" ", aListStr);
1177 QListBoxItem* anItem = 0;
1178 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1179 anItem = myElements->findItem(*it, Qt::ExactMatch);
1180 if (anItem) myElements->setSelected(anItem, true);
1187 if (!myGroup->_is_nil())
1188 myActor = SMESH::FindActorByObject(myGroup);
1189 else if(!myGroupOnGeom->_is_nil())
1190 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1192 myActor = SMESH::FindActorByObject(myMesh);
1198 //=================================================================================
1199 // function : onSelectSubMesh()
1200 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1201 //=================================================================================
1202 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1205 if (mySelectGroup->isChecked()) {
1206 mySelectGroup->setChecked(false);
1208 //VSR: else if (mySelectGeomGroup->isChecked()) {
1209 //VSR: mySelectGeomGroup->setChecked(false);
1211 myCurrentLineEdit = mySubMeshLine;
1212 setSelectionMode(4);
1215 mySubMeshLine->setText("");
1216 myCurrentLineEdit = 0;
1218 setSelectionMode(myTypeId);
1220 mySubMeshBtn->setEnabled(on);
1221 mySubMeshLine->setEnabled(on);
1225 //=================================================================================
1226 // function : (onSelectGroup)
1227 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1228 //=================================================================================
1229 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1232 if (mySelectSubMesh->isChecked()) {
1233 mySelectSubMesh->setChecked(false);
1235 myCurrentLineEdit = myGroupLine;
1236 setSelectionMode(5);
1239 myGroupLine->setText("");
1240 myCurrentLineEdit = 0;
1242 setSelectionMode(myTypeId);
1244 myGroupBtn->setEnabled(on);
1245 myGroupLine->setEnabled(on);
1249 //=================================================================================
1250 // function : (onSelectGeomGroup)
1251 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1252 //=================================================================================
1253 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1256 if (mySelectSubMesh->isChecked()) {
1257 mySelectSubMesh->setChecked(false);
1259 else if (mySelectGroup->isChecked()) {
1260 mySelectGroup->setChecked(false);
1262 myCurrentLineEdit = myGeomGroupLine;
1264 setSelectionMode(8);
1267 myGeomGroupBtn->setOn(false);
1268 myGeomObjects->length(0);
1269 myGeomGroupLine->setText("");
1270 myCurrentLineEdit = 0;
1272 setSelectionMode(myTypeId);
1277 //=================================================================================
1278 // function : setCurrentSelection()
1280 //=================================================================================
1281 void SMESHGUI_GroupDlg::setCurrentSelection()
1283 QPushButton* send = (QPushButton*)sender();
1284 myCurrentLineEdit = 0;
1285 if (send == myMeshGroupBtn) {
1286 myCurrentLineEdit = myMeshGroupLine;
1288 setSelectionMode(6);
1290 setSelectionMode(5);
1291 onObjectSelectionChanged();
1293 else if (send == mySubMeshBtn) {
1294 myCurrentLineEdit = mySubMeshLine;
1295 onObjectSelectionChanged();
1297 else if (send == myGroupBtn) {
1298 myCurrentLineEdit = myGroupLine;
1299 onObjectSelectionChanged();
1304 //=================================================================================
1305 // function : setFilters()
1306 // purpose : SLOT. Called when "Filter" button pressed.
1307 //=================================================================================
1308 void SMESHGUI_GroupDlg::setFilters()
1310 SMESH::ElementType aType = SMESH::ALL;
1313 case 0 : aType = SMESH::NODE; break;
1314 case 1 : aType = SMESH::EDGE; break;
1315 case 2 : aType = SMESH::FACE; break;
1316 case 3 : aType = SMESH::VOLUME; break;
1320 if ( myFilterDlg == 0 )
1322 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1323 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1326 myFilterDlg->Init( aType );
1328 myFilterDlg->SetSelection();
1329 myFilterDlg->SetMesh( myMesh );
1330 myFilterDlg->SetSourceWg( myElements );
1332 myFilterDlg->show();
1335 //=================================================================================
1336 // function : onFilterAccepted()
1337 // purpose : SLOT. Called when Filter dlg closed with OK button.
1338 // Uncheck "Select submesh" and "Select group" checkboxes
1339 //=================================================================================
1340 void SMESHGUI_GroupDlg::onFilterAccepted()
1342 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1344 mySelectionMode = myTypeId;
1345 mySelectSubMesh->setChecked( false );
1346 mySelectGroup->setChecked( false );
1350 //=================================================================================
1351 // function : onAdd()
1353 //=================================================================================
1354 void SMESHGUI_GroupDlg::onAdd()
1356 SALOME_ListIO aList;
1357 mySelectionMgr->selectedObjects( aList );
1359 int aNbSel = aList.Extent();
1361 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1365 SMESH::ElementType aType = SMESH::ALL;
1368 aType = SMESH::NODE;
1369 mySelector->SetSelectionMode(NodeSelection);
1372 aType = SMESH::EDGE;
1373 mySelector->SetSelectionMode(EdgeSelection);
1376 aType = SMESH::FACE;
1377 mySelector->SetSelectionMode(FaceSelection);
1380 aType = SMESH::VOLUME;
1381 mySelector->SetSelectionMode(VolumeSelection);
1384 mySelector->SetSelectionMode(ActorSelection);
1388 if (myCurrentLineEdit == 0) {
1389 //if (aNbSel != 1) { myIsBusy = false; return; }
1390 QString aListStr = "";
1392 if (myTypeId == 0) {
1393 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1396 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1399 QStringList anElements = QStringList::split(" ", aListStr);
1400 QListBoxItem* anItem = 0;
1401 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1402 anItem = myElements->findItem(*it, Qt::ExactMatch);
1404 anItem = new QListBoxText(*it);
1405 myElements->insertItem(anItem);
1407 myElements->setSelected(anItem, true);
1410 } else if (myCurrentLineEdit == mySubMeshLine) {
1411 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1413 SALOME_ListIO aList;
1414 mySelectionMgr->selectedObjects( aList );
1416 SALOME_ListIteratorOfListIO anIt (aList);
1417 for (; anIt.More(); anIt.Next()) {
1418 SMESH::SMESH_subMesh_var aSubMesh =
1419 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1420 if (!aSubMesh->_is_nil()) {
1421 // check if mesh is the same
1422 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1424 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1425 int k = anElements->length();
1426 QListBoxItem* anItem = 0;
1427 for (int i = 0; i < k; i++) {
1428 QString aText = QString::number(anElements[i]);
1429 anItem = myElements->findItem(aText, Qt::ExactMatch);
1431 anItem = new QListBoxText(aText);
1432 myElements->insertItem(anItem);
1434 myElements->setSelected(anItem, true);
1437 catch (const SALOME::SALOME_Exception& ex) {
1438 SalomeApp_Tools::QtCatchCorbaException(ex);
1443 mySelectSubMesh->setChecked(false);
1445 onListSelectionChanged();
1447 } else if (myCurrentLineEdit == myGroupLine) {
1448 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1449 SALOME_ListIO aList;
1450 mySelectionMgr->selectedObjects( aList );
1452 SALOME_ListIteratorOfListIO anIt (aList);
1453 for (; anIt.More(); anIt.Next()) {
1454 SMESH::SMESH_Group_var aGroup =
1455 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1456 if (!aGroup->_is_nil()) {
1457 // check if mesh is the same
1458 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1459 SMESH::long_array_var anElements = aGroup->GetListOfID();
1460 int k = anElements->length();
1461 QListBoxItem* anItem = 0;
1462 for (int i = 0; i < k; i++) {
1463 QString aText = QString::number(anElements[i]);
1464 anItem = myElements->findItem(aText, Qt::ExactMatch);
1466 anItem = new QListBoxText(aText);
1467 myElements->insertItem(anItem);
1469 myElements->setSelected(anItem, true);
1474 mySelectGroup->setChecked(false);
1476 onListSelectionChanged();
1478 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1479 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1480 GEOM::GEOM_IGroupOperations_var aGroupOp =
1481 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1483 SMESH::ElementType aGroupType = SMESH::ALL;
1484 switch(aGroupOp->GetType(myGeomObjects[0])) {
1485 case 7: aGroupType = SMESH::NODE; break;
1486 case 6: aGroupType = SMESH::EDGE; break;
1487 case 4: aGroupType = SMESH::FACE; break;
1488 case 2: aGroupType = SMESH::VOLUME; break;
1489 default: myIsBusy = false; return;
1492 if (aGroupType == aType) {
1493 _PTR(SObject) aGroupSO =
1494 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1495 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1497 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1498 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1499 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1500 aBelongToGeom->SetGeom(myGeomObjects[0]);
1501 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1502 aBelongToGeom->SetElementType(aType);
1503 aFilter->SetPredicate(aBelongToGeom);
1505 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1507 int k = anElements->length();
1508 QListBoxItem* anItem = 0;
1509 for (int i = 0; i < k; i++) {
1510 QString aText = QString::number(anElements[i]);
1511 anItem = myElements->findItem(aText, Qt::ExactMatch);
1513 anItem = new QListBoxText(aText);
1514 myElements->insertItem(anItem);
1516 myElements->setSelected(anItem, true);
1520 //VSR: mySelectGeomGroup->setChecked(false);
1522 onListSelectionChanged();
1525 // mySelectionMgr->clearSelected();
1529 //=================================================================================
1530 // function : onRemove()
1532 //=================================================================================
1533 void SMESHGUI_GroupDlg::onRemove()
1536 if (myCurrentLineEdit == 0) {
1537 for (int i = myElements->count(); i > 0; i--) {
1538 if (myElements->isSelected(i-1)) {
1539 myElements->removeItem(i-1);
1543 SALOME_ListIO aList;
1544 mySelectionMgr->selectedObjects( aList );
1546 int aNbSel = aList.Extent();
1548 if (aNbSel == 0) { myIsBusy = false; return; }
1550 SMESH::ElementType aType = SMESH::ALL;
1552 case 0: aType = SMESH::NODE; break;
1553 case 1: aType = SMESH::EDGE; break;
1554 case 2: aType = SMESH::FACE; break;
1555 case 3: aType = SMESH::VOLUME; break;
1558 if (myCurrentLineEdit == mySubMeshLine) {
1559 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1560 SALOME_ListIO aList;
1561 mySelectionMgr->selectedObjects( aList );
1563 SALOME_ListIteratorOfListIO anIt (aList);
1564 for (; anIt.More(); anIt.Next()) {
1565 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1566 if (!aSubMesh->_is_nil()) {
1567 // check if mesh is the same
1568 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1569 if (aType == SMESH::NODE) {
1571 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1572 int k = anElements->length();
1573 QListBoxItem* anItem = 0;
1574 for (int i = 0; i < k; i++) {
1575 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1576 if (anItem) delete anItem;
1579 catch (const SALOME::SALOME_Exception& ex) {
1580 SalomeApp_Tools::QtCatchCorbaException(ex);
1585 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
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);
1601 else if (myCurrentLineEdit == myGroupLine) {
1602 Standard_Boolean aRes;
1603 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1604 SALOME_ListIO aList;
1605 mySelectionMgr->selectedObjects( aList );
1607 SALOME_ListIteratorOfListIO anIt (aList);
1608 for (; anIt.More(); anIt.Next()) {
1609 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1610 if (aRes && !aGroup->_is_nil()) {
1611 // check if mesh is the same
1612 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1613 SMESH::long_array_var anElements = aGroup->GetListOfID();
1614 int k = anElements->length();
1615 QListBoxItem* anItem = 0;
1616 for (int i = 0; i < k; i++) {
1617 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1618 if (anItem) delete anItem;
1629 //=================================================================================
1630 // function : onSort()
1632 //=================================================================================
1633 void SMESHGUI_GroupDlg::onSort()
1635 // PAL5412: sorts items in ascending by "string" value
1636 // myElements->sort(true);
1637 // myElements->update();
1638 int i, k = myElements->count();
1641 QStringList aSelected;
1642 std::vector<int> anArray(k);
1643 // QMemArray<int> anArray(k);
1644 QListBoxItem* anItem;
1646 for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1647 anArray[i] = anItem->text().toInt();
1648 if (anItem->isSelected())
1649 aSelected.append(anItem->text());
1651 // sort & update list
1652 std::sort(anArray.begin(), anArray.end());
1654 myElements->clear();
1655 for (i = 0; i < k; i++) {
1656 myElements->insertItem(QString::number(anArray[i]));
1658 for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1659 anItem = myElements->findItem(*it, Qt::ExactMatch);
1660 if (anItem) myElements->setSelected(anItem, true);
1666 //=================================================================================
1667 // function : closeEvent()
1669 //=================================================================================
1670 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1675 //=================================================================================
1676 // function : SMESHGUI_GroupDlg::onClose
1677 // purpose : SLOT called when "Close" button pressed. Close dialog
1678 //=================================================================================
1679 void SMESHGUI_GroupDlg::onClose()
1681 if (SMESH::GetCurrentVtkView()) {
1682 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1683 SMESH::SetPointRepresentation(false);
1684 SMESH::SetPickable();
1687 mySelectionMgr->clearSelected();
1688 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1689 aViewWindow->SetSelectionMode(ActorSelection);
1690 mySelectionMgr->clearFilters();
1691 mySMESHGUI->ResetState();
1696 //=================================================================================
1697 // function : onHelp()
1699 //=================================================================================
1700 void SMESHGUI_GroupDlg::onHelp()
1702 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1704 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1708 platform = "winapplication";
1710 platform = "application";
1712 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1713 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1714 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
1715 QObject::tr("BUT_OK"));
1719 //=================================================================================
1720 // function : SMESHGUI_GroupDlg::onDeactivate
1721 // purpose : SLOT called when dialog must be deativated
1722 //=================================================================================
1723 void SMESHGUI_GroupDlg::onDeactivate()
1725 mySMESHGUI->ResetState();
1729 //=================================================================================
1730 // function : SMESHGUI_GroupDlg::enterEvent
1731 // purpose : Event filter
1732 //=================================================================================
1733 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1736 mySMESHGUI->EmitSignalDeactivateDialog();
1738 mySelectionMode = -1;
1739 setSelectionMode(myTypeId);
1740 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1741 mySMESHGUI->SetActiveDialogBox(this);
1742 mySMESHGUI->SetState(800);
1746 //=================================================================================
1747 // function : hideEvent
1748 // purpose : caused by ESC key
1749 //=================================================================================
1750 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1752 if (!isMinimized() && !myIsBusy)
1756 //=================================================================================
1757 // function : keyPressEvent()
1759 //=================================================================================
1760 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1762 QDialog::keyPressEvent( e );
1763 if ( e->isAccepted() )
1766 if ( e->key() == Key_F1 )
1773 //================================================================================
1775 * \brief Enable showing of the popup when Geometry selection btn is clicked
1776 * \param enable - true to enable
1778 //================================================================================
1780 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1782 void SMESHGUI_GroupDlg::updateGeomPopup()
1784 bool enable = false;
1786 if ( !myMesh->_is_nil() )
1787 enable = myMesh->NbEdges() > 0;
1789 if ( myGeomGroupBtn )
1791 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1793 if ( !myGeomPopup ) {
1794 myGeomPopup = new QPopupMenu();
1795 myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
1796 myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
1797 connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
1799 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1805 //=================================================================================
1806 // function : onGeomSelectionButton()
1808 //=================================================================================
1809 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1811 if ( myGeomPopup && isBtnOn )
1813 myCurrentLineEdit = myGeomGroupLine;
1814 int id = myGeomPopup->exec( QCursor::pos() );
1815 if (id == DIRECT_GEOM_INDEX || id == -1)
1816 setSelectionMode(7);
1820 myCurrentLineEdit = 0;
1821 setSelectionMode(8);
1825 //=================================================================================
1826 // function : onGeomPopup()
1828 //=================================================================================
1829 void SMESHGUI_GroupDlg::onGeomPopup( int index )
1831 if ( index == GEOM_BY_MESH_INDEX )
1833 mySelectionMode = -1;
1834 if ( !myShapeByMeshOp ) {
1835 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1836 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1837 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1838 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1839 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1841 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1842 if ( !myMesh->_is_nil() ) {
1844 hide(); // stop processing selection
1846 myShapeByMeshOp->setModule( mySMESHGUI );
1847 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1848 myShapeByMeshOp->SetMesh( myMesh );
1849 myShapeByMeshOp->start();
1854 //================================================================================
1856 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1858 //================================================================================
1860 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1862 if ( myShapeByMeshOp == op ) {
1863 mySMESHGUI->getApp()->updateObjectBrowser();
1865 // Select a found geometry object
1866 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1867 if ( !aGeomVar->_is_nil() )
1869 QString ID = aGeomVar->GetStudyEntry();
1870 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1871 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
1872 SALOME_ListIO anIOList;
1873 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1874 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1875 anIOList.Append( anIO );
1876 mySelectionMgr->setSelectedObjects( anIOList, false );
1877 onObjectSelectionChanged();
1883 //================================================================================
1885 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1887 //================================================================================
1889 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1891 if ( myShapeByMeshOp == op )
1894 setSelectionMode(7);
1898 //=================================================================================
1899 // function : setGroupColor()
1901 //=================================================================================
1902 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
1904 QColor aQColor( (int)( theColor.R * 255.0 ),
1905 (int)( theColor.G * 255.0 ),
1906 (int)( theColor.B * 255.0 ) );
1907 setGroupQColor( aQColor );
1910 //=================================================================================
1911 // function : getGroupColor()
1913 //=================================================================================
1914 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
1916 QColor aQColor = getGroupQColor();
1918 SALOMEDS::Color aColor;
1919 aColor.R = (float)aQColor.red() / 255.0;
1920 aColor.G = (float)aQColor.green() / 255.0;
1921 aColor.B = (float)aQColor.blue() / 255.0;
1926 //=================================================================================
1927 // function : setGroupQColor()
1929 //=================================================================================
1930 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
1932 if( theColor.isValid() )
1934 QPalette pal = myColorBtn->palette();
1935 pal.setColor(QColorGroup::Button, theColor);
1936 myColorBtn->setPalette(pal);
1940 //=================================================================================
1941 // function : getGroupQColor()
1943 //=================================================================================
1944 QColor SMESHGUI_GroupDlg::getGroupQColor() const
1946 QColor aColor = myColorBtn->palette().active().button();
1950 //=================================================================================
1951 // function : setDefaultGroupColor()
1953 //=================================================================================
1954 void SMESHGUI_GroupDlg::setDefaultGroupColor()
1956 if( myMesh->_is_nil() )
1959 bool isAutoColor = myMesh->GetAutoColor();
1964 int r = 0, g = 0, b = 0;
1965 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
1966 aQColor.setRgb( r, g, b );
1970 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
1972 QValueList<SALOMEDS::Color> aReservedColors;
1973 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1975 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1976 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
1977 aReservedColors.append( aReservedColor );
1980 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1981 aQColor.setRgb( (int)( aColor.R * 255.0 ),
1982 (int)( aColor.G * 255.0 ),
1983 (int)( aColor.B * 255.0 ) );
1987 setGroupQColor( aQColor );