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>
96 //=================================================================================
97 // function : SMESHGUI_GroupDlg()
99 //=================================================================================
100 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
101 SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl)
102 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
103 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
104 mySMESHGUI( theModule ),
105 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
106 mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
110 if (!name) setName("SMESHGUI_GroupDlg");
112 if (!theMesh->_is_nil())
115 mySelectSubMesh->setEnabled(false);
116 mySelectGroup->setEnabled(false);
117 myGeomGroupBtn->setEnabled(false);
118 myGeomGroupLine->setEnabled(false);
122 //=================================================================================
123 // function : SMESHGUI_GroupDlg()
125 //=================================================================================
126 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name,
127 SMESH::SMESH_GroupBase_ptr theGroup, bool modal, WFlags fl)
128 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
129 WStyle_Title | WStyle_SysMenu | WDestructiveClose),
130 mySMESHGUI( theModule ),
131 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
132 mySelector(SMESH::GetViewWindow( theModule )->GetSelector()),
135 if (!name) setName("SMESHGUI_GroupDlg");
138 if (!theGroup->_is_nil())
141 mySelectSubMesh->setEnabled(false);
142 mySelectGroup->setEnabled(false);
144 myCurrentLineEdit = myMeshGroupLine;
149 //=================================================================================
150 // function : SMESHGUI_GroupDlg()
152 //=================================================================================
153 void SMESHGUI_GroupDlg::initDialog(bool create)
157 myCurrentLineEdit = 0;
161 myGeomObjects = new GEOM::ListOfGO();
162 myGeomObjects->length(0);
164 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
167 setCaption(tr("SMESH_CREATE_GROUP_TITLE"));
168 myHelpFileName = "creating_groups_page.html";
171 setCaption(tr("SMESH_EDIT_GROUP_TITLE"));
172 myHelpFileName = "editing_groups_page.html";
175 setSizeGripEnabled(TRUE);
177 QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
179 /***************************************************************/
180 QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
182 meshGroupLab->setText(tr("SMESH_MESH"));
184 meshGroupLab->setText(tr("SMESH_GROUP"));
185 myMeshGroupBtn = new QPushButton(this, "mesh/group button");
186 myMeshGroupBtn->setPixmap(image0);
187 myMeshGroupLine = new QLineEdit(this, "mesh/group line");
188 myMeshGroupLine->setReadOnly(true);
190 /***************************************************************/
191 myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
192 myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
193 myTypeGroup->setExclusive(true);
196 types.append(tr("MESH_NODE"));
197 types.append(tr("SMESH_EDGE"));
198 types.append(tr("SMESH_FACE"));
199 types.append(tr("SMESH_VOLUME"));
201 for (int i = 0; i < types.count(); i++) {
202 rb = new QRadioButton(types[i], myTypeGroup);
204 myTypeGroup->setEnabled(create);
207 /***************************************************************/
208 QLabel* aName = new QLabel(this, "name label");
209 aName->setText(tr("SMESH_NAME"));
210 aName->setMinimumSize(50,0);
211 myName = new QLineEdit(this, "name");
213 /***************************************************************/
214 myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
215 myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
216 myGrpTypeGroup->setExclusive(true);
217 QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
218 QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"), myGrpTypeGroup);
219 myGrpTypeGroup->setEnabled(create);
222 /***************************************************************/
223 myWGStack = new QWidgetStack( this, "widget stack");
224 QWidget* wg1 = new QFrame( myWGStack, "first widget" );
225 QWidget* wg2 = new QFrame( myWGStack, "second widget" );
227 /***************************************************************/
228 QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
229 aContentBox->setTitle(tr("SMESH_CONTENT"));
230 QFrame* aContent = new QFrame(aContentBox, "content");
231 QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
232 aLayout->setSpacing(6);
233 aLayout->setAutoAdd(false);
235 QLabel* aLabel = new QLabel(aContent, "elements label");
236 aLabel->setText(tr("SMESH_ID_ELEMENTS"));
237 myElements = new QListBox(aContent, "elements list");
238 myElements->setSelectionMode(QListBox::Extended);
240 myFilter = new QPushButton(aContent, "filter");
241 myFilter->setText(tr("SMESH_BUT_FILTER"));
242 QPushButton* aAddBtn = new QPushButton(aContent, "add");
243 aAddBtn->setText(tr("SMESH_BUT_ADD"));
244 QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
245 aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
246 QPushButton* aSortBtn = new QPushButton(aContent, "sort");
247 aSortBtn->setText(tr("SMESH_BUT_SORT"));
249 aLayout->addWidget(aLabel, 0, 0);
250 aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
251 aLayout->addWidget(myFilter, 1, 2);
252 aLayout->addWidget(aAddBtn, 3, 2);
253 aLayout->addWidget(aRemoveBtn, 4, 2);
254 aLayout->addWidget(aSortBtn, 6, 2);
256 aLayout->setColStretch(0, 1);
257 aLayout->addColSpacing(1, 20);
258 aLayout->addColSpacing(3, 20);
259 aLayout->setRowStretch(2, 1);
260 aLayout->setRowStretch(5, 1);
262 /***************************************************************/
263 QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
264 aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
266 mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
267 mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
268 mySelectSubMesh->setMinimumSize(50, 0);
269 mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
270 mySubMeshBtn->setText("");
271 mySubMeshBtn->setPixmap(image0);
272 mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
273 mySubMeshLine->setReadOnly(true);
274 onSelectSubMesh(false);
276 mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
277 mySelectGroup->setText(tr("SMESH_GROUP"));
278 mySelectGroup->setMinimumSize(50, 0);
279 myGroupBtn = new QPushButton(aSelectBox, "group button");
280 myGroupBtn->setText("");
281 myGroupBtn->setPixmap(image0);
282 myGroupLine = new QLineEdit(aSelectBox, "group line");
283 myGroupLine->setReadOnly(true);
284 onSelectGroup(false);
286 /***************************************************************/
287 QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
288 wg1Layout->addWidget(aContentBox, 0, 0);
289 wg1Layout->addWidget(aSelectBox, 1, 0);
290 wg1Layout->setRowStretch(2, 5);
292 /***************************************************************/
293 QLabel* geomObject = new QLabel(wg2, "geometry object label");
294 geomObject->setText(tr("SMESH_OBJECT_GEOM"));
295 myGeomGroupBtn = new QToolButton(wg2, "geometry group button");
296 myGeomGroupBtn->setIconSet( QIconSet(image0) );
297 myGeomGroupBtn->setToggleButton(true);
298 myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
299 myGeomGroupLine->setReadOnly(true); //VSR ???
300 onSelectGeomGroup(false);
304 myGeomGroupBtn->setEnabled(false);
305 myGeomGroupLine->setEnabled(false);
308 /***************************************************************/
309 QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
310 wg2Layout->addWidget(geomObject, 0, 0);
311 wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
312 wg2Layout->addWidget(myGeomGroupLine,0, 2);
313 wg2Layout->setRowStretch(1, 5);
315 /***************************************************************/
316 QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
317 dumb->addWidget(wg1);
318 dumb->addWidget(wg2);
319 myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
320 myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
322 /***************************************************************/
323 QGroupBox* aColorBox = new QGroupBox(2, Qt::Horizontal, this, "color box");
324 aColorBox->setTitle(tr("SMESH_SET_COLOR"));
326 new QLabel( tr("SMESH_CHECK_COLOR"), aColorBox, "color label" );
327 myColorBtn = new QPushButton(aColorBox, "color button");
328 myColorBtn->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
330 /***************************************************************/
332 QFrame* aButtons = new QFrame(this, "button box");
333 aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
334 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
335 aBtnLayout->setAutoAdd(false);
337 QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
338 aOKBtn->setText(tr("SMESH_BUT_OK"));
339 aOKBtn->setAutoDefault(true);
340 aOKBtn->setDefault(true);
341 QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
342 aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
343 aApplyBtn->setAutoDefault(true);
344 QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
345 aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
346 aCloseBtn->setAutoDefault(true);
347 QPushButton* aHelpBtn = new QPushButton(aButtons, "help");
348 aHelpBtn->setText(tr("SMESH_BUT_HELP"));
349 aHelpBtn->setAutoDefault(true);
351 aBtnLayout->addWidget(aOKBtn);
352 aBtnLayout->addWidget(aApplyBtn);
353 aBtnLayout->addStretch();
354 aBtnLayout->addWidget(aCloseBtn);
355 aBtnLayout->addWidget(aHelpBtn);
357 /***************************************************************/
358 aMainLayout->addWidget(meshGroupLab, 0, 0);
359 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
360 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
361 aMainLayout->addMultiCellWidget(myTypeGroup, 1, 1, 0, 2);
362 aMainLayout->addWidget(aName, 2, 0);
363 aMainLayout->addWidget(myName, 2, 2);
364 aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
365 aMainLayout->addMultiCellWidget(myWGStack, 4, 4, 0, 2);
366 aMainLayout->setRowStretch( 5, 5 );
367 aMainLayout->addMultiCellWidget(aColorBox, 6, 6, 0, 2);
368 aMainLayout->addMultiCellWidget(aButtons, 7, 7, 0, 2);
370 /* signals and slots connections */
371 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
373 connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
375 connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
377 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
378 connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
380 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
381 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
382 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
383 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
385 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
386 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
387 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
388 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
389 connect(myGeomGroupBtn, SIGNAL(toggled(bool)), this, SLOT(onGeomSelectionButton(bool)));
390 connect(myColorBtn, SIGNAL(clicked()), this, SLOT(onSelectColor()));
392 connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
393 connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
394 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
395 connect(aHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
398 mySMESHGUI->SetActiveDialogBox(this);
399 mySMESHGUI->SetState(800);
401 mySelectionMode = -1;
402 myMeshFilter = new SMESH_TypeFilter(MESH);
403 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
404 myGroupFilter = new SMESH_TypeFilter(GROUP);
405 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
406 myGeomFilter = new GEOM_SelectionFilter( aStudy, true );
408 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
409 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
410 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
412 myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
413 onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
415 if (myMesh->_is_nil() )
416 myTypeGroup->setButton(0);
421 //=================================================================================
422 // function : ~SMESHGUI_GroupDlg()
423 // purpose : Destroys the object and frees any allocated resources
424 //=================================================================================
425 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
427 // no need to delete child widgets, Qt does it all for us
428 if ( myFilterDlg != 0 )
430 myFilterDlg->reparent( 0, QPoint() );
435 //=================================================================================
438 //=================================================================================
439 void SMESHGUI_GroupDlg::init (SMESH::SMESH_Mesh_ptr theMesh)
441 mySelectionMgr->installFilter(myMeshFilter);
443 /* init data from current selection */
444 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
445 myGroup = SMESH::SMESH_Group::_nil();
446 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
448 myActor = SMESH::FindActorByObject(myMesh);
449 SMESH::SetPickable(myActor);
451 setDefaultGroupColor();
454 mySelectionMgr->selectedObjects( aList );
455 if( !aList.IsEmpty() )
457 QString aName = aList.First()->getName();
458 myMeshGroupLine->setText(aName) ;
459 myMeshGroupLine->home( false );
462 myCurrentLineEdit = 0;
464 myTypeGroup->setButton(0);
468 //=================================================================================
471 //=================================================================================
472 void SMESHGUI_GroupDlg::init (SMESH::SMESH_GroupBase_ptr theGroup)
474 myMesh = theGroup->GetMesh();
476 myName->setText(theGroup->GetName());
479 SALOMEDS::Color aColor = theGroup->GetColor();
480 setGroupColor( aColor );
482 myMeshGroupLine->setText(theGroup->GetName());
485 switch(theGroup->GetType()) {
486 case SMESH::NODE: aType= 0; break;
487 case SMESH::EDGE: aType = 1; break;
488 case SMESH::FACE: aType = 2; break;
489 case SMESH::VOLUME: aType = 3; break;
491 myTypeGroup->setButton(aType);
493 myGroup = SMESH::SMESH_Group::_narrow( theGroup );
495 if ( !myGroup->_is_nil() )
497 myActor = SMESH::FindActorByObject(myMesh);
499 myActor = SMESH::FindActorByObject(myGroup);
500 SMESH::SetPickable(myActor);
502 myGrpTypeGroup->setButton(0);
505 myCurrentLineEdit = 0;
507 setSelectionMode(aType);
511 if (!myGroup->IsEmpty()) {
512 SMESH::long_array_var anElements = myGroup->GetListOfID();
513 int k = anElements->length();
514 for (int i = 0; i < k; i++) {
515 myIdList.append(anElements[i]);
516 myElements->insertItem(QString::number(anElements[i]));
518 myElements->selectAll(true);
523 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow( theGroup );
525 if ( !myGroupOnGeom->_is_nil() )
527 myActor = SMESH::FindActorByObject(myMesh);
529 myActor = SMESH::FindActorByObject(myGroup);
530 SMESH::SetPickable(myActor);
532 myGrpTypeGroup->setButton(1);
535 QString aShapeName("");
536 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
537 GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
538 if (!aGroupShape->_is_nil())
540 _PTR(SObject) aGroupShapeSO = aStudy->FindObjectID(aGroupShape->GetStudyEntry());
541 aShapeName = aGroupShapeSO->GetName().c_str();
543 myGeomGroupLine->setText( aShapeName );
548 //=================================================================================
549 // function : updateButtons()
551 //=================================================================================
552 void SMESHGUI_GroupDlg::updateButtons()
554 bool enable = !myName->text().stripWhiteSpace().isEmpty();
556 if (myGrpTypeId == 0) {
557 enable = enable && myElements->count() > 0;
558 enable = enable && (!myGroup->_is_nil() || !myMesh->_is_nil());
560 else if (myGrpTypeId == 1) {
561 if (CORBA::is_nil(myGroupOnGeom)) { // creation mode
562 enable = enable && myGeomObjects->length() > 0 && !myMesh->_is_nil();
567 aBtn = (QPushButton*) child("ok", "QPushButton");
568 if (aBtn) aBtn->setEnabled(enable);
569 aBtn = (QPushButton*) child("apply", "QPushButton");
570 if (aBtn) aBtn->setEnabled(enable);
573 //=================================================================================
574 // function : onNameChanged()
576 //=================================================================================
577 void SMESHGUI_GroupDlg::onNameChanged (const QString& text)
582 //=================================================================================
583 // function : onTypeChanged()
584 // purpose : Group elements type radio button management
585 //=================================================================================
586 void SMESHGUI_GroupDlg::onTypeChanged (int id)
588 if (myTypeId != id) {
590 if (myCurrentLineEdit == 0)
591 setSelectionMode(id);
596 //=================================================================================
597 // function : onGrpTypeChanged()
598 // purpose : Group type radio button management
599 //=================================================================================
600 void SMESHGUI_GroupDlg::onGrpTypeChanged (int id)
602 if (myGrpTypeId != id) {
603 myWGStack->raiseWidget( id );
604 onSelectGeomGroup(id == 1);
609 //=================================================================================
610 // function : onSelectColor()
612 //=================================================================================
613 void SMESHGUI_GroupDlg::onSelectColor()
615 QColor color = getGroupQColor();
616 color = QColorDialog::getColor( color );
617 setGroupQColor( color );
622 //=================================================================================
623 // function : setSelectionMode()
624 // purpose : Radio button management
625 //=================================================================================
626 void SMESHGUI_GroupDlg::setSelectionMode (int theMode)
629 if (myMesh->_is_nil())
631 if (mySelectionMode != theMode) {
632 // [PAL10408] mySelectionMgr->clearSelected();
633 mySelectionMgr->clearFilters();
635 myActor->SetPointRepresentation(false);
637 SMESH::SetPointRepresentation(false);
642 myActor->SetPointRepresentation(true);
644 SMESH::SetPointRepresentation(true);
645 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
646 aViewWindow->SetSelectionMode(NodeSelection);
649 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
650 aViewWindow->SetSelectionMode(EdgeSelection);
653 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
654 aViewWindow->SetSelectionMode(FaceSelection);
657 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
658 aViewWindow->SetSelectionMode(VolumeSelection);
662 mySelectionMgr->installFilter(mySubMeshFilter);
663 else if (theMode == 5)
664 mySelectionMgr->installFilter(myGroupFilter);
665 else if (theMode == 6)
666 mySelectionMgr->installFilter(myMeshFilter);
667 else if (theMode == 7)
668 mySelectionMgr->installFilter(myGeomFilter);
670 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
671 aViewWindow->SetSelectionMode(ActorSelection);
673 mySelectionMode = theMode;
677 //=================================================================================
678 // function : onApply()
680 //=================================================================================
681 bool SMESHGUI_GroupDlg::onApply()
683 if (mySMESHGUI->isActiveStudyLocked())
686 if (myName->text().stripWhiteSpace().isEmpty())
689 if (myGrpTypeId == 0) { // on mesh elements
690 if (!myElements->count())
693 mySelectionMgr->clearSelected();
695 if (myGroup->_is_nil()) { // creation
696 if (myMesh->_is_nil())
699 SMESH::ElementType aType = SMESH::ALL;
701 case 0: aType = SMESH::NODE; break;
702 case 1: aType = SMESH::EDGE; break;
703 case 2: aType = SMESH::FACE; break;
704 case 3: aType = SMESH::VOLUME; break;
707 SMESH::long_array_var anIdList = new SMESH::long_array;
708 int i, k = myElements->count();
710 QListBoxItem* anItem;
711 for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
712 anIdList[i] = anItem->text().toInt();
715 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
716 myGroup->Add(anIdList.inout());
718 SALOMEDS::Color aColor = getGroupColor();
719 myGroup->SetColor(aColor);
721 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
723 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
724 SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
726 /* init for next operation */
729 myGroup = SMESH::SMESH_Group::_nil();
732 myGroup->SetName(myName->text());
734 SALOMEDS::Color aColor = getGroupColor();
735 myGroup->SetColor(aColor);
737 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
738 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
739 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
741 QValueList<int> aAddList;
742 QValueList<int>::iterator anIt;
743 QListBoxItem* anItem;
745 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
746 int anId = anItem->text().toInt();
747 if ((anIt = myIdList.find(anId)) == myIdList.end())
748 aAddList.append(anId);
750 myIdList.remove(anIt);
752 if (!aAddList.empty()) {
753 SMESH::long_array_var anIdList = new SMESH::long_array;
754 anIdList->length(aAddList.count());
756 for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
758 myGroup->Add(anIdList.inout());
760 if (!myIdList.empty()) {
761 SMESH::long_array_var anIdList = new SMESH::long_array;
762 anIdList->length(myIdList.count());
764 for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
766 myGroup->Remove(anIdList.inout());
768 /* init for next operation */
770 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
771 myIdList.append(anItem->text().toInt());
774 mySMESHGUI->updateObjBrowser(true);
775 SMESH::UpdateView(); // asv: fix of BUG PAL5515
776 mySelectionMgr->clearSelected();
779 else if (myGrpTypeId == 1) { // on geom object
780 if (CORBA::is_nil(myGroupOnGeom)) { // creation
781 if (myMesh->_is_nil() || !myGeomObjects->length())
784 SMESH::ElementType aType = SMESH::ALL;
786 case 0: aType = SMESH::NODE; break;
787 case 1: aType = SMESH::EDGE; break;
788 case 2: aType = SMESH::FACE; break;
789 case 3: aType = SMESH::VOLUME; break;
792 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
793 GEOM::GEOM_IGroupOperations_var aGroupOp =
794 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
796 if (myGeomObjects->length() == 1) {
797 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomObjects[0]);
800 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
801 if ( aSMESHGen->_is_nil() )
804 // create a geometry group
805 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
806 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
808 if (geomGen->_is_nil() || !aStudy)
811 GEOM::GEOM_IGroupOperations_var op =
812 geomGen->GetIGroupOperations(aStudy->StudyId());
816 // check and add all selected GEOM objects: they must be
817 // a sub-shapes of the main GEOM and must be of one type
818 TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
819 for ( int i =0; i < myGeomObjects->length(); i++) {
820 TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
822 aGroupType = aSubShapeType;
823 else if (aSubShapeType != aGroupType) {
824 aGroupType = TopAbs_SHAPE;
829 GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
830 GEOM::GEOM_Object_var aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
831 op->UnionList(aGroupVar, myGeomObjects);
834 // publish the GEOM group in study
835 QString aNewGeomGroupName ("Auto_group_for_");
836 aNewGeomGroupName += myName->text();
837 SALOMEDS::SObject_var aNewGroupSO =
838 geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar, aNewGeomGroupName, aMeshShape);
841 myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(), aGroupVar);
844 SALOMEDS::Color aColor = getGroupColor();
845 myGroupOnGeom->SetColor(aColor);
847 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
849 //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
850 SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
852 /* init for next operation */
854 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
857 myGroupOnGeom->SetName(myName->text());
859 SALOMEDS::Color aColor = getGroupColor();
860 myGroupOnGeom->SetColor(aColor);
862 _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
863 if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
864 anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
867 mySMESHGUI->updateObjBrowser(true);
868 mySelectionMgr->clearSelected();
875 //=================================================================================
878 //=================================================================================
879 void SMESHGUI_GroupDlg::onOK()
885 //=================================================================================
886 // function : onListSelectionChanged()
887 // purpose : Called when selection in element list is changed
888 //=================================================================================
889 void SMESHGUI_GroupDlg::onListSelectionChanged()
891 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
892 if( myIsBusy || !myActor) return;
895 if (myCurrentLineEdit == 0) {
896 mySelectionMgr->clearSelected();
897 TColStd_MapOfInteger aIndexes;
898 QListBoxItem* anItem;
899 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
900 if (anItem->isSelected()) {
901 int anId = anItem->text().toInt();
905 mySelector->AddOrRemoveIndex(myActor->getIO(), aIndexes, false);
907 aList.Append(myActor->getIO());
908 mySelectionMgr->setSelectedObjects(aList,false);
913 //=================================================================================
914 // function : onObjectSelectionChanged()
915 // purpose : Called when selection in 3D view or ObjectBrowser is changed
916 //=================================================================================
917 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
919 if ( myIsBusy || !isEnabled()) return;
920 if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isOn()) return;
925 mySelectionMgr->selectedObjects( aList );
927 int aNbSel = aList.Extent();
928 myElements->clearSelection();
930 if (myCurrentLineEdit) {
931 myCurrentLineEdit->setText("");
932 QString aString = "";
934 if (myCurrentLineEdit == myMeshGroupLine) {
935 mySelectSubMesh->setEnabled(false);
936 mySelectGroup->setEnabled(false);
937 myGroupLine->setText("");
938 mySubMeshLine->setText("");
940 myGeomGroupBtn->setEnabled(false);
941 myGeomGroupLine->setEnabled(false);
942 myGeomGroupLine->setText("");
943 myGeomObjects = new GEOM::ListOfGO();
944 myGeomObjects->length(0);
946 if (myGeomGroupBtn->isOn())
947 myGeomGroupBtn->setOn(false);
954 myGroup = SMESH::SMESH_Group::_nil();
955 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
956 myMesh = SMESH::SMESH_Mesh::_nil();
962 Handle(SALOME_InteractiveObject) IO = aList.First();
965 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
967 if (myMesh->_is_nil())
973 myGroup = SMESH::SMESH_Group::_nil();
975 myActor = SMESH::FindActorByObject(myMesh);
976 SMESH::SetPickable(myActor);
978 aString = aList.First()->getName();
979 myMeshGroupLine->setText(aString) ;
980 myMeshGroupLine->home( false );
982 mySelectSubMesh->setEnabled(true);
983 mySelectGroup->setEnabled(true);
984 myGeomGroupBtn->setEnabled(true);
985 myGeomGroupLine->setEnabled(true);
988 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
989 if (aGroup->_is_nil())
995 myCurrentLineEdit = 0;
997 myGroup = SMESH::SMESH_Group::_nil();
998 myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
1002 mySelectSubMesh->setEnabled(true);
1003 mySelectGroup->setEnabled(true);
1005 myCurrentLineEdit = 0;
1010 if (myGrpTypeId == 0)
1016 myElements->clear();
1017 setSelectionMode(myTypeId);
1024 } else if (myCurrentLineEdit == myGeomGroupLine) {
1026 myGeomObjects = new GEOM::ListOfGO();
1029 _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
1031 if (aNbSel == 0 || !aMeshSO)
1033 myGeomObjects->length(0);
1039 myGeomObjects->length(aNbSel);
1041 GEOM::GEOM_Object_var aGeomGroup;
1042 Standard_Boolean testResult;
1045 SALOME_ListIteratorOfListIO anIt (aList);
1046 for (; anIt.More(); anIt.Next()) {
1048 testResult = Standard_False;
1049 aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
1051 // Check if the object is a geometry group
1052 if (!testResult || CORBA::is_nil(aGeomGroup))
1056 // Check if group constructed on the same shape as a mesh or on its child
1057 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1058 GEOM::GEOM_IGroupOperations_var anOp =
1059 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1061 // The main shape of the group
1062 GEOM::GEOM_Object_var aGroupMainShape;
1063 if (aGeomGroup->GetType() == 37)
1064 aGroupMainShape = anOp->GetMainShape(aGeomGroup);
1066 aGroupMainShape = GEOM::GEOM_Object::_duplicate(aGeomGroup);
1067 _PTR(SObject) aGroupMainShapeSO =
1068 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(aGroupMainShape));
1069 aStudy->FindObjectID(aGroupMainShape->GetStudyEntry());
1071 _PTR(SObject) anObj, aRef;
1072 bool isRefOrSubShape = false;
1073 if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
1074 //if (strcmp(aRef->GetID(), aGroupMainShapeSO->GetID()) == 0) {
1075 if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
1076 isRefOrSubShape = true;
1078 _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
1079 _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
1080 //while (!isRefOrSubShape && strcmp(aFather->GetID(), aComponent->GetID()) != 0) {
1081 while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
1082 //if (strcmp(aRef->GetID(), aFather->GetID()) == 0)
1083 if (aRef->GetID() == aFather->GetID())
1084 isRefOrSubShape = true;
1086 aFather = aFather->GetFather();
1090 if (isRefOrSubShape)
1091 myGeomObjects[i++] = aGeomGroup;
1094 myGeomObjects->length(i);
1106 if(myCurrentLineEdit == mySubMeshLine)
1107 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
1108 else if(myCurrentLineEdit == myGroupLine)
1109 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
1110 else if(myCurrentLineEdit == myGeomGroupLine)
1111 aString = tr("%1 Objects").arg(aNbSel);
1113 aString = aList.First()->getName();
1117 myCurrentLineEdit->setText(aString);
1118 myCurrentLineEdit->home(false);
1123 if (aNbSel == 1 && myActor ) {
1124 QString aListStr = "";
1126 if (myTypeId == 0) {
1127 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1129 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1132 QStringList anElements = QStringList::split(" ", aListStr);
1133 QListBoxItem* anItem = 0;
1134 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1135 anItem = myElements->findItem(*it, Qt::ExactMatch);
1136 if (anItem) myElements->setSelected(anItem, true);
1143 if (!myGroup->_is_nil())
1144 myActor = SMESH::FindActorByObject(myGroup);
1145 else if(!myGroupOnGeom->_is_nil())
1146 myActor = SMESH::FindActorByObject(myGroupOnGeom);
1148 myActor = SMESH::FindActorByObject(myMesh);
1154 //=================================================================================
1155 // function : onSelectSubMesh()
1156 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1157 //=================================================================================
1158 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
1161 if (mySelectGroup->isChecked()) {
1162 mySelectGroup->setChecked(false);
1164 //VSR: else if (mySelectGeomGroup->isChecked()) {
1165 //VSR: mySelectGeomGroup->setChecked(false);
1167 myCurrentLineEdit = mySubMeshLine;
1168 setSelectionMode(4);
1171 mySubMeshLine->setText("");
1172 myCurrentLineEdit = 0;
1174 setSelectionMode(myTypeId);
1176 mySubMeshBtn->setEnabled(on);
1177 mySubMeshLine->setEnabled(on);
1181 //=================================================================================
1182 // function : (onSelectGroup)
1183 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1184 //=================================================================================
1185 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
1188 if (mySelectSubMesh->isChecked()) {
1189 mySelectSubMesh->setChecked(false);
1191 myCurrentLineEdit = myGroupLine;
1192 setSelectionMode(5);
1195 myGroupLine->setText("");
1196 myCurrentLineEdit = 0;
1198 setSelectionMode(myTypeId);
1200 myGroupBtn->setEnabled(on);
1201 myGroupLine->setEnabled(on);
1205 //=================================================================================
1206 // function : (onSelectGeomGroup)
1207 // purpose : Called when selection in 3D view or ObjectBrowser is changed
1208 //=================================================================================
1209 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
1212 if (mySelectSubMesh->isChecked()) {
1213 mySelectSubMesh->setChecked(false);
1215 else if (mySelectGroup->isChecked()) {
1216 mySelectGroup->setChecked(false);
1218 myCurrentLineEdit = myGeomGroupLine;
1220 setSelectionMode(8);
1223 myGeomGroupBtn->setOn(false);
1224 myGeomObjects->length(0);
1225 myGeomGroupLine->setText("");
1226 myCurrentLineEdit = 0;
1228 setSelectionMode(myTypeId);
1233 //=================================================================================
1234 // function : setCurrentSelection()
1236 //=================================================================================
1237 void SMESHGUI_GroupDlg::setCurrentSelection()
1239 QPushButton* send = (QPushButton*)sender();
1240 myCurrentLineEdit = 0;
1241 if (send == myMeshGroupBtn) {
1242 myCurrentLineEdit = myMeshGroupLine;
1244 setSelectionMode(6);
1246 setSelectionMode(5);
1247 onObjectSelectionChanged();
1249 else if (send == mySubMeshBtn) {
1250 myCurrentLineEdit = mySubMeshLine;
1251 onObjectSelectionChanged();
1253 else if (send == myGroupBtn) {
1254 myCurrentLineEdit = myGroupLine;
1255 onObjectSelectionChanged();
1260 //=================================================================================
1261 // function : setFilters()
1262 // purpose : SLOT. Called when "Filter" button pressed.
1263 //=================================================================================
1264 void SMESHGUI_GroupDlg::setFilters()
1266 SMESH::ElementType aType = SMESH::ALL;
1269 case 0 : aType = SMESH::NODE; break;
1270 case 1 : aType = SMESH::EDGE; break;
1271 case 2 : aType = SMESH::FACE; break;
1272 case 3 : aType = SMESH::VOLUME; break;
1276 if ( myFilterDlg == 0 )
1278 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
1279 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1282 myFilterDlg->Init( aType );
1284 myFilterDlg->SetSelection();
1285 myFilterDlg->SetMesh( myMesh );
1286 myFilterDlg->SetSourceWg( myElements );
1288 myFilterDlg->show();
1291 //=================================================================================
1292 // function : onFilterAccepted()
1293 // purpose : SLOT. Called when Filter dlg closed with OK button.
1294 // Uncheck "Select submesh" and "Select group" checkboxes
1295 //=================================================================================
1296 void SMESHGUI_GroupDlg::onFilterAccepted()
1298 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1300 mySelectionMode = myTypeId;
1301 mySelectSubMesh->setChecked( false );
1302 mySelectGroup->setChecked( false );
1306 //=================================================================================
1307 // function : onAdd()
1309 //=================================================================================
1310 void SMESHGUI_GroupDlg::onAdd()
1312 SALOME_ListIO aList;
1313 mySelectionMgr->selectedObjects( aList );
1315 int aNbSel = aList.Extent();
1317 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1321 SMESH::ElementType aType = SMESH::ALL;
1324 aType = SMESH::NODE;
1325 mySelector->SetSelectionMode(NodeSelection);
1328 aType = SMESH::EDGE;
1329 mySelector->SetSelectionMode(EdgeSelection);
1332 aType = SMESH::FACE;
1333 mySelector->SetSelectionMode(FaceSelection);
1336 aType = SMESH::VOLUME;
1337 mySelector->SetSelectionMode(VolumeSelection);
1340 mySelector->SetSelectionMode(ActorSelection);
1344 if (myCurrentLineEdit == 0) {
1345 //if (aNbSel != 1) { myIsBusy = false; return; }
1346 QString aListStr = "";
1348 if (myTypeId == 0) {
1349 aNbItems = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aListStr);
1352 aNbItems = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aListStr);
1355 QStringList anElements = QStringList::split(" ", aListStr);
1356 QListBoxItem* anItem = 0;
1357 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1358 anItem = myElements->findItem(*it, Qt::ExactMatch);
1360 anItem = new QListBoxText(*it);
1361 myElements->insertItem(anItem);
1363 myElements->setSelected(anItem, true);
1366 } else if (myCurrentLineEdit == mySubMeshLine) {
1367 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1369 SALOME_ListIO aList;
1370 mySelectionMgr->selectedObjects( aList );
1372 SALOME_ListIteratorOfListIO anIt (aList);
1373 for (; anIt.More(); anIt.Next()) {
1374 SMESH::SMESH_subMesh_var aSubMesh =
1375 SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1376 if (!aSubMesh->_is_nil()) {
1377 // check if mesh is the same
1378 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1380 SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
1381 int k = anElements->length();
1382 QListBoxItem* anItem = 0;
1383 for (int i = 0; i < k; i++) {
1384 QString aText = QString::number(anElements[i]);
1385 anItem = myElements->findItem(aText, Qt::ExactMatch);
1387 anItem = new QListBoxText(aText);
1388 myElements->insertItem(anItem);
1390 myElements->setSelected(anItem, true);
1393 catch (const SALOME::SALOME_Exception& ex) {
1394 SalomeApp_Tools::QtCatchCorbaException(ex);
1399 mySelectSubMesh->setChecked(false);
1401 onListSelectionChanged();
1403 } else if (myCurrentLineEdit == myGroupLine) {
1404 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1405 SALOME_ListIO aList;
1406 mySelectionMgr->selectedObjects( aList );
1408 SALOME_ListIteratorOfListIO anIt (aList);
1409 for (; anIt.More(); anIt.Next()) {
1410 SMESH::SMESH_Group_var aGroup =
1411 SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1412 if (!aGroup->_is_nil()) {
1413 // check if mesh is the same
1414 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1415 SMESH::long_array_var anElements = aGroup->GetListOfID();
1416 int k = anElements->length();
1417 QListBoxItem* anItem = 0;
1418 for (int i = 0; i < k; i++) {
1419 QString aText = QString::number(anElements[i]);
1420 anItem = myElements->findItem(aText, Qt::ExactMatch);
1422 anItem = new QListBoxText(aText);
1423 myElements->insertItem(anItem);
1425 myElements->setSelected(anItem, true);
1430 mySelectGroup->setChecked(false);
1432 onListSelectionChanged();
1434 } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
1435 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1436 GEOM::GEOM_IGroupOperations_var aGroupOp =
1437 SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1439 SMESH::ElementType aGroupType = SMESH::ALL;
1440 switch(aGroupOp->GetType(myGeomObjects[0])) {
1441 case 7: aGroupType = SMESH::NODE; break;
1442 case 6: aGroupType = SMESH::EDGE; break;
1443 case 4: aGroupType = SMESH::FACE; break;
1444 case 2: aGroupType = SMESH::VOLUME; break;
1445 default: myIsBusy = false; return;
1448 if (aGroupType == aType) {
1449 _PTR(SObject) aGroupSO =
1450 //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
1451 aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
1453 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1454 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1455 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1456 aBelongToGeom->SetGeom(myGeomObjects[0]);
1457 aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
1458 aBelongToGeom->SetElementType(aType);
1459 aFilter->SetPredicate(aBelongToGeom);
1461 SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
1463 int k = anElements->length();
1464 QListBoxItem* anItem = 0;
1465 for (int i = 0; i < k; i++) {
1466 QString aText = QString::number(anElements[i]);
1467 anItem = myElements->findItem(aText, Qt::ExactMatch);
1469 anItem = new QListBoxText(aText);
1470 myElements->insertItem(anItem);
1472 myElements->setSelected(anItem, true);
1476 //VSR: mySelectGeomGroup->setChecked(false);
1478 onListSelectionChanged();
1481 // mySelectionMgr->clearSelected();
1485 //=================================================================================
1486 // function : onRemove()
1488 //=================================================================================
1489 void SMESHGUI_GroupDlg::onRemove()
1492 if (myCurrentLineEdit == 0) {
1493 for (int i = myElements->count(); i > 0; i--) {
1494 if (myElements->isSelected(i-1)) {
1495 myElements->removeItem(i-1);
1499 SALOME_ListIO aList;
1500 mySelectionMgr->selectedObjects( aList );
1502 int aNbSel = aList.Extent();
1504 if (aNbSel == 0) { myIsBusy = false; return; }
1506 SMESH::ElementType aType = SMESH::ALL;
1508 case 0: aType = SMESH::NODE; break;
1509 case 1: aType = SMESH::EDGE; break;
1510 case 2: aType = SMESH::FACE; break;
1511 case 3: aType = SMESH::VOLUME; break;
1514 if (myCurrentLineEdit == mySubMeshLine) {
1515 //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
1516 SALOME_ListIO aList;
1517 mySelectionMgr->selectedObjects( aList );
1519 SALOME_ListIteratorOfListIO anIt (aList);
1520 for (; anIt.More(); anIt.Next()) {
1521 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1522 if (!aSubMesh->_is_nil()) {
1523 // check if mesh is the same
1524 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1525 if (aType == SMESH::NODE) {
1527 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1528 int k = anElements->length();
1529 QListBoxItem* anItem = 0;
1530 for (int i = 0; i < k; i++) {
1531 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1532 if (anItem) delete anItem;
1535 catch (const SALOME::SALOME_Exception& ex) {
1536 SalomeApp_Tools::QtCatchCorbaException(ex);
1541 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1542 int k = anElements->length();
1543 QListBoxItem* anItem = 0;
1544 for (int i = 0; i < k; i++) {
1545 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1546 if (anItem) delete anItem;
1549 catch (const SALOME::SALOME_Exception& ex) {
1550 SalomeApp_Tools::QtCatchCorbaException(ex);
1557 else if (myCurrentLineEdit == myGroupLine) {
1558 Standard_Boolean aRes;
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_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1566 if (aRes && !aGroup->_is_nil()) {
1567 // check if mesh is the same
1568 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1569 SMESH::long_array_var anElements = aGroup->GetListOfID();
1570 int k = anElements->length();
1571 QListBoxItem* anItem = 0;
1572 for (int i = 0; i < k; i++) {
1573 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1574 if (anItem) delete anItem;
1585 //=================================================================================
1586 // function : onSort()
1588 //=================================================================================
1589 void SMESHGUI_GroupDlg::onSort()
1591 // PAL5412: sorts items in ascending by "string" value
1592 // myElements->sort(true);
1593 // myElements->update();
1594 int i, k = myElements->count();
1597 QStringList aSelected;
1598 std::vector<int> anArray(k);
1599 // QMemArray<int> anArray(k);
1600 QListBoxItem* anItem;
1602 for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1603 anArray[i] = anItem->text().toInt();
1604 if (anItem->isSelected())
1605 aSelected.append(anItem->text());
1607 // sort & update list
1608 std::sort(anArray.begin(), anArray.end());
1610 myElements->clear();
1611 for (i = 0; i < k; i++) {
1612 myElements->insertItem(QString::number(anArray[i]));
1614 for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1615 anItem = myElements->findItem(*it, Qt::ExactMatch);
1616 if (anItem) myElements->setSelected(anItem, true);
1622 //=================================================================================
1623 // function : closeEvent()
1625 //=================================================================================
1626 void SMESHGUI_GroupDlg::closeEvent (QCloseEvent*)
1631 //=================================================================================
1632 // function : SMESHGUI_GroupDlg::onClose
1633 // purpose : SLOT called when "Close" button pressed. Close dialog
1634 //=================================================================================
1635 void SMESHGUI_GroupDlg::onClose()
1637 if (SMESH::GetCurrentVtkView()) {
1638 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1639 SMESH::SetPointRepresentation(false);
1640 SMESH::SetPickable();
1643 mySelectionMgr->clearSelected();
1644 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1645 aViewWindow->SetSelectionMode(ActorSelection);
1646 mySelectionMgr->clearFilters();
1647 mySMESHGUI->ResetState();
1652 //=================================================================================
1653 // function : onHelp()
1655 //=================================================================================
1656 void SMESHGUI_GroupDlg::onHelp()
1658 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1660 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1664 platform = "winapplication";
1666 platform = "application";
1668 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1669 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1670 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
1671 QObject::tr("BUT_OK"));
1675 //=================================================================================
1676 // function : SMESHGUI_GroupDlg::onDeactivate
1677 // purpose : SLOT called when dialog must be deativated
1678 //=================================================================================
1679 void SMESHGUI_GroupDlg::onDeactivate()
1681 mySMESHGUI->ResetState();
1685 //=================================================================================
1686 // function : SMESHGUI_GroupDlg::enterEvent
1687 // purpose : Event filter
1688 //=================================================================================
1689 void SMESHGUI_GroupDlg::enterEvent (QEvent*)
1692 mySMESHGUI->EmitSignalDeactivateDialog();
1694 mySelectionMode = -1;
1695 setSelectionMode(myTypeId);
1696 //mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1697 mySMESHGUI->SetActiveDialogBox(this);
1698 mySMESHGUI->SetState(800);
1702 //=================================================================================
1703 // function : hideEvent
1704 // purpose : caused by ESC key
1705 //=================================================================================
1706 void SMESHGUI_GroupDlg::hideEvent (QHideEvent*)
1708 if (!isMinimized() && !myIsBusy)
1712 //=================================================================================
1713 // function : keyPressEvent()
1715 //=================================================================================
1716 void SMESHGUI_GroupDlg::keyPressEvent( QKeyEvent* e )
1718 QDialog::keyPressEvent( e );
1719 if ( e->isAccepted() )
1722 if ( e->key() == Key_F1 )
1729 //================================================================================
1731 * \brief Enable showing of the popup when Geometry selection btn is clicked
1732 * \param enable - true to enable
1734 //================================================================================
1736 enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
1738 void SMESHGUI_GroupDlg::updateGeomPopup()
1740 bool enable = false;
1742 if ( !myMesh->_is_nil() )
1743 enable = myMesh->NbEdges() > 0;
1745 if ( myGeomGroupBtn )
1747 disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1749 if ( !myGeomPopup ) {
1750 myGeomPopup = new QPopupMenu();
1751 myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
1752 myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
1753 connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
1755 connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
1761 //=================================================================================
1762 // function : onGeomSelectionButton()
1764 //=================================================================================
1765 void SMESHGUI_GroupDlg::onGeomSelectionButton(bool isBtnOn)
1767 if ( myGeomPopup && isBtnOn )
1769 myCurrentLineEdit = myGeomGroupLine;
1770 int id = myGeomPopup->exec( QCursor::pos() );
1771 if (id == DIRECT_GEOM_INDEX || id == -1)
1772 setSelectionMode(7);
1776 myCurrentLineEdit = 0;
1777 setSelectionMode(8);
1781 //=================================================================================
1782 // function : onGeomPopup()
1784 //=================================================================================
1785 void SMESHGUI_GroupDlg::onGeomPopup( int index )
1787 if ( index == GEOM_BY_MESH_INDEX )
1789 mySelectionMode = -1;
1790 if ( !myShapeByMeshOp ) {
1791 myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
1792 connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
1793 SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
1794 connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
1795 SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
1797 // set mesh object to SMESHGUI_ShapeByMeshOp and start it
1798 if ( !myMesh->_is_nil() ) {
1800 hide(); // stop processing selection
1802 myShapeByMeshOp->setModule( mySMESHGUI );
1803 myShapeByMeshOp->setStudy( 0 ); // it's really necessary
1804 myShapeByMeshOp->SetMesh( myMesh );
1805 myShapeByMeshOp->start();
1810 //================================================================================
1812 * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
1814 //================================================================================
1816 void SMESHGUI_GroupDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
1818 if ( myShapeByMeshOp == op ) {
1819 mySMESHGUI->getApp()->updateObjectBrowser();
1821 // Select a found geometry object
1822 GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
1823 if ( !aGeomVar->_is_nil() )
1825 QString ID = aGeomVar->GetStudyEntry();
1826 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
1827 if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.latin1() )) {
1828 SALOME_ListIO anIOList;
1829 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1830 ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
1831 anIOList.Append( anIO );
1832 mySelectionMgr->setSelectedObjects( anIOList, false );
1833 onObjectSelectionChanged();
1839 //================================================================================
1841 * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
1843 //================================================================================
1845 void SMESHGUI_GroupDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
1847 if ( myShapeByMeshOp == op )
1850 setSelectionMode(7);
1854 //=================================================================================
1855 // function : setGroupColor()
1857 //=================================================================================
1858 void SMESHGUI_GroupDlg::setGroupColor( const SALOMEDS::Color& theColor )
1860 QColor aQColor( (int)( theColor.R * 255.0 ),
1861 (int)( theColor.G * 255.0 ),
1862 (int)( theColor.B * 255.0 ) );
1863 setGroupQColor( aQColor );
1866 //=================================================================================
1867 // function : getGroupColor()
1869 //=================================================================================
1870 SALOMEDS::Color SMESHGUI_GroupDlg::getGroupColor() const
1872 QColor aQColor = getGroupQColor();
1874 SALOMEDS::Color aColor;
1875 aColor.R = (float)aQColor.red() / 255.0;
1876 aColor.G = (float)aQColor.green() / 255.0;
1877 aColor.B = (float)aQColor.blue() / 255.0;
1882 //=================================================================================
1883 // function : setGroupQColor()
1885 //=================================================================================
1886 void SMESHGUI_GroupDlg::setGroupQColor( const QColor& theColor )
1888 if( theColor.isValid() )
1890 QPalette pal = myColorBtn->palette();
1891 pal.setColor(QColorGroup::Button, theColor);
1892 myColorBtn->setPalette(pal);
1896 //=================================================================================
1897 // function : getGroupQColor()
1899 //=================================================================================
1900 QColor SMESHGUI_GroupDlg::getGroupQColor() const
1902 QColor aColor = myColorBtn->palette().active().button();
1906 //=================================================================================
1907 // function : setDefaultGroupColor()
1909 //=================================================================================
1910 void SMESHGUI_GroupDlg::setDefaultGroupColor()
1912 if( myMesh->_is_nil() )
1915 bool isAutoColor = myMesh->GetAutoColor();
1920 int r = 0, g = 0, b = 0;
1921 SMESH::GetColor( "SMESH", "fill_color", r, g, b, QColor( 0, 170, 255 ) );
1922 aQColor.setRgb( r, g, b );
1926 SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
1928 QValueList<SALOMEDS::Color> aReservedColors;
1929 for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
1931 SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
1932 SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
1933 aReservedColors.append( aReservedColor );
1936 SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
1937 aQColor.setRgb( (int)( aColor.R * 255.0 ),
1938 (int)( aColor.G * 255.0 ),
1939 (int)( aColor.B * 255.0 ) );
1943 setGroupQColor( aQColor );