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.org
24 // File : SMESHGUI_GroupDlg.cxx
25 // Author : Natalia KOPNOVA
29 #include "SMESHGUI_GroupDlg.h"
30 #include "SMESHGUI_FilterDlg.h"
31 #include "SMESHGUI_Filter.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 "SALOMEGUI_QtCatchCorbaException.hxx"
42 #include "SALOME_ListIteratorOfListIO.hxx"
43 #include "VTKViewer_ViewFrame.h"
44 #include "QAD_Application.h"
45 #include "QAD_Desktop.h"
46 #include "QAD_MessageBox.h"
47 #include "QAD_RightFrame.h"
48 #include "utilities.h"
50 #include "SMESH_Actor.h"
55 #include <qbuttongroup.h>
56 #include <qgroupbox.h>
59 #include <qlineedit.h>
60 #include <qpushbutton.h>
61 #include <qradiobutton.h>
62 #include <qcheckbox.h>
67 #include <qmemarray.h>
68 #include <qwidgetstack.h>
76 //=================================================================================
77 // class : SMESHGUI_GroupDlg()
79 //=================================================================================
80 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( QWidget* parent, const char* name, SALOME_Selection* theSel,
81 SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl )
82 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
84 if ( !name ) setName( "SMESHGUI_GroupDlg" );
85 initDialog(theSel, true);
86 if (!theMesh->_is_nil())
89 mySelectSubMesh->setEnabled(false);
90 mySelectGroup->setEnabled(false);
91 myGeomGroupBtn->setEnabled(false);
92 myGeomGroupLine->setEnabled(false);
95 /* Move widget on the botton right corner of main widget */
97 mySMESHGUI->DefineDlgPosition(this, x, y);
101 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( QWidget* parent, const char* name, SALOME_Selection* theSel,
102 SMESH::SMESH_Group_ptr theGroup, bool modal, WFlags fl )
103 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
105 if ( !name ) setName( "SMESHGUI_GroupDlg" );
106 initDialog(theSel, false);
107 if (!theGroup->_is_nil())
110 mySelectSubMesh->setEnabled(false);
111 mySelectGroup->setEnabled(false);
114 /* Move widget on the botton right corner of main widget */
116 mySMESHGUI->DefineDlgPosition(this, x, y);
120 void SMESHGUI_GroupDlg::initDialog(SALOME_Selection* theSel, bool create)
124 myCurrentLineEdit = 0;
126 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
129 setCaption( tr( "SMESH_CREATE_GROUP_TITLE" ) );
131 setCaption( tr( "SMESH_EDIT_GROUP_TITLE" ) );
133 setSizeGripEnabled( TRUE );
135 QGridLayout* aMainLayout = new QGridLayout(this, 7, 3, 11, 6);
137 /***************************************************************/
138 QLabel* meshGroupLab = new QLabel(this, "mesh/group label");
140 meshGroupLab->setText(tr("SMESH_MESH"));
142 meshGroupLab->setText(tr("SMESH_GROUP"));
143 myMeshGroupBtn = new QPushButton(this, "mesh/group button");
144 myMeshGroupBtn->setPixmap(image0);
145 myMeshGroupLine = new QLineEdit(this, "mesh/group line");
146 myMeshGroupLine->setReadOnly(true);
148 /***************************************************************/
149 myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
150 myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
151 myTypeGroup->setExclusive(true);
154 types.append(tr("MESH_NODE"));
155 types.append(tr("SMESH_EDGE"));
156 types.append(tr("SMESH_FACE"));
157 types.append(tr("SMESH_VOLUME"));
159 for (int i = 0; i < types.count(); i++) {
160 rb = new QRadioButton(types[i], myTypeGroup);
162 myTypeGroup->setEnabled(create);
165 /***************************************************************/
166 QLabel* aName = new QLabel(this, "name label");
167 aName->setText(tr("SMESH_NAME"));
168 aName->setMinimumSize(50,0);
169 myName = new QLineEdit(this, "name");
171 /***************************************************************/
172 myGrpTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Type of group");
173 myGrpTypeGroup->setTitle(tr("SMESH_GROUP_TYPE"));
174 myGrpTypeGroup->setExclusive(true);
175 QRadioButton* rb1 = new QRadioButton( tr("SMESH_GROUP_STANDALONE"), myGrpTypeGroup);
176 QRadioButton* rb2 = new QRadioButton( tr("SMESH_GROUP_GEOMETRY"), myGrpTypeGroup);
177 myGrpTypeGroup->setEnabled(create);
180 /***************************************************************/
181 myWGStack = new QWidgetStack( this, "widget stack");
182 QWidget* wg1 = new QFrame( myWGStack, "first widget" );
183 QWidget* wg2 = new QFrame( myWGStack, "second widget" );
185 /***************************************************************/
186 QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, wg1, "content box");
187 aContentBox->setTitle(tr("SMESH_CONTENT"));
188 QFrame* aContent = new QFrame(aContentBox, "content");
189 QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
190 aLayout->setSpacing(6);
191 aLayout->setAutoAdd(false);
193 QLabel* aLabel = new QLabel(aContent, "elements label");
194 aLabel->setText(tr("SMESH_ID_ELEMENTS"));
195 myElements = new QListBox(aContent, "elements list");
196 myElements->setSelectionMode(QListBox::Extended);
198 myFilter = new QPushButton(aContent, "filter");
199 myFilter->setText(tr("SMESH_BUT_FILTER"));
200 QPushButton* aAddBtn = new QPushButton(aContent, "add");
201 aAddBtn->setText(tr("SMESH_BUT_ADD"));
202 QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
203 aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
204 QPushButton* aSortBtn = new QPushButton(aContent, "sort");
205 aSortBtn->setText(tr("SMESH_BUT_SORT"));
207 aLayout->addWidget(aLabel, 0, 0);
208 aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
209 aLayout->addWidget(myFilter, 1, 2);
210 aLayout->addWidget(aAddBtn, 3, 2);
211 aLayout->addWidget(aRemoveBtn, 4, 2);
212 aLayout->addWidget(aSortBtn, 6, 2);
214 aLayout->setColStretch(0, 1);
215 aLayout->addColSpacing(1, 20);
216 aLayout->addColSpacing(3, 20);
217 aLayout->setRowStretch(2, 1);
218 aLayout->setRowStretch(5, 1);
220 /***************************************************************/
221 QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, wg1, "select box");
222 aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
224 mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
225 mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
226 mySelectSubMesh->setMinimumSize(50, 0);
227 mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
228 mySubMeshBtn->setText("");
229 mySubMeshBtn->setPixmap(image0);
230 mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
231 mySubMeshLine->setReadOnly(true);
232 onSelectSubMesh(false);
234 mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
235 mySelectGroup->setText(tr("SMESH_GROUP"));
236 mySelectGroup->setMinimumSize(50, 0);
237 myGroupBtn = new QPushButton(aSelectBox, "group button");
238 myGroupBtn->setText("");
239 myGroupBtn->setPixmap(image0);
240 myGroupLine = new QLineEdit(aSelectBox, "group line");
241 myGroupLine->setReadOnly(true);
242 onSelectGroup(false);
244 /***************************************************************/
245 QGridLayout* wg1Layout = new QGridLayout( wg1, 3, 1, 0, 6 );
246 wg1Layout->addWidget(aContentBox, 0, 0);
247 wg1Layout->addWidget(aSelectBox, 1, 0);
248 wg1Layout->setRowStretch(2, 5);
250 /***************************************************************/
251 QLabel* geomObject = new QLabel(wg2, "geometry object label");
252 geomObject->setText(tr("SMESH_OBJECT_GEOM"));
253 myGeomGroupBtn = new QPushButton(wg2, "geometry group button");
254 myGeomGroupBtn->setText("");
255 myGeomGroupBtn->setPixmap(image0);
256 myGeomGroupLine = new QLineEdit(wg2, "geometry group line");
257 myGeomGroupLine->setReadOnly(true); //VSR ???
258 onSelectGeomGroup(false);
260 /***************************************************************/
261 QGridLayout* wg2Layout = new QGridLayout( wg2, 2, 3, 0, 6 );
262 wg2Layout->addWidget(geomObject, 0, 0);
263 wg2Layout->addWidget(myGeomGroupBtn, 0, 1);
264 wg2Layout->addWidget(myGeomGroupLine,0, 2);
265 wg2Layout->setRowStretch(1, 5);
267 /***************************************************************/
268 QVBoxLayout* dumb = new QVBoxLayout(myWGStack);
269 dumb->addWidget(wg1);
270 dumb->addWidget(wg2);
271 myWGStack->addWidget( wg1, myGrpTypeGroup->id(rb1) );
272 myWGStack->addWidget( wg2, myGrpTypeGroup->id(rb2) );
274 /***************************************************************/
275 QFrame* aButtons = new QFrame(this, "button box");
276 aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
277 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
278 aBtnLayout->setAutoAdd(false);
280 QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
281 aOKBtn->setText(tr("SMESH_BUT_OK"));
282 aOKBtn->setAutoDefault(true);
283 aOKBtn->setDefault(true);
284 QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
285 aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
286 aApplyBtn->setAutoDefault(true);
287 QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
288 aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
289 aCloseBtn->setAutoDefault(true);
291 aBtnLayout->addWidget(aOKBtn);
292 aBtnLayout->addWidget(aApplyBtn);
293 aBtnLayout->addStretch();
294 aBtnLayout->addWidget(aCloseBtn);
296 /***************************************************************/
297 aMainLayout->addWidget(meshGroupLab, 0, 0);
298 aMainLayout->addWidget(myMeshGroupBtn, 0, 1);
299 aMainLayout->addWidget(myMeshGroupLine, 0, 2);
300 aMainLayout->addMultiCellWidget(myTypeGroup, 1, 1, 0, 2);
301 aMainLayout->addWidget(aName, 2, 0);
302 aMainLayout->addWidget(myName, 2, 2);
303 aMainLayout->addMultiCellWidget(myGrpTypeGroup, 3, 3, 0, 2);
304 aMainLayout->addMultiCellWidget(myWGStack, 4, 4, 0, 2);
305 aMainLayout->setRowStretch( 5, 5 );
306 aMainLayout->addMultiCellWidget(aButtons, 6, 6, 0, 2);
308 /* signals and slots connections */
309 connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
311 connect(myGrpTypeGroup, SIGNAL(clicked(int)), this, SLOT(onGrpTypeChanged(int)));
313 connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
315 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
316 connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
318 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
319 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
320 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
321 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
323 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
324 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
325 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
326 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
327 connect(myGeomGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
329 connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
330 connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
331 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
334 mySelection = theSel;
335 mySMESHGUI = SMESHGUI::GetSMESHGUI();
336 mySMESHGUI->SetActiveDialogBox(this);
337 mySMESHGUI->SetState(800);
339 mySelectionMode = -1;
340 myMeshFilter = new SMESH_TypeFilter(MESH);
341 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
342 myGroupFilter = new SMESH_TypeFilter(GROUP);
344 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
345 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
346 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
348 myGrpTypeGroup->setButton(myGrpTypeGroup->id(rb1)); // VSR !!!
349 onGrpTypeChanged(myGrpTypeGroup->id(rb1)); // VSR!!!
351 if (myMesh->_is_nil() )
352 myTypeGroup->setButton(0);
357 //=================================================================================
358 // function : ~SMESHGUI_GroupDlg()
359 // purpose : Destroys the object and frees any allocated resources
360 //=================================================================================
361 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
363 // no need to delete child widgets, Qt does it all for us
364 if ( myFilterDlg != 0 )
366 myFilterDlg->reparent( 0, QPoint() );
372 //=================================================================================
375 //=================================================================================
376 void SMESHGUI_GroupDlg::init(SMESH::SMESH_Mesh_ptr theMesh)
378 /* init data from current selection */
379 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
380 myGroup = SMESH::SMESH_Group::_nil();
382 myActor = SMESH::FindActorByObject(myMesh);
383 SMESH::SetPickable(myActor);
385 QString aName = mySelection->firstIObject()->getName();
386 myMeshGroupLine->setText(aName) ;
387 myMeshGroupLine->home( false );
389 myCurrentLineEdit = 0;
391 myTypeGroup->setButton(0);
395 //=================================================================================
398 //=================================================================================
399 void SMESHGUI_GroupDlg::init(SMESH::SMESH_Group_ptr theGroup)
401 myMesh = theGroup->GetMesh();
402 myGroup = SMESH::SMESH_Group::_duplicate(theGroup);
404 myActor = SMESH::FindActorByObject(myMesh);
406 myActor = SMESH::FindActorByObject(myGroup);
407 SMESH::SetPickable(myActor);
410 switch(theGroup->GetType()) {
411 case SMESH::NODE: aType= 0; break;
412 case SMESH::EDGE: aType = 1; break;
413 case SMESH::FACE: aType = 2; break;
414 case SMESH::VOLUME: aType = 3; break;
417 myName->setText(myGroup->GetName());
419 myMeshGroupLine->setText(myGroup->GetName());
421 myCurrentLineEdit = 0;
422 myTypeGroup->setButton(aType);
424 setSelectionMode(aType);
428 if (!theGroup->IsEmpty()) {
429 SMESH::long_array_var anElements = myGroup->GetListOfID();
430 int k = anElements->length();
431 for (int i = 0; i < k; i++) {
432 myIdList.append(anElements[i]);
433 myElements->insertItem(QString::number(anElements[i]));
435 myElements->selectAll(true);
440 //=================================================================================
441 // function : updateButtons()
443 //=================================================================================
444 void SMESHGUI_GroupDlg::updateButtons()
448 if (myGrpTypeId == 0)
449 enable = !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0;
450 else if (myGrpTypeId == 1)
451 enable = !myName->text().stripWhiteSpace().isEmpty() && !CORBA::is_nil( myGeomGroup );
453 aBtn = (QPushButton*) child("ok", "QPushButton");
454 if (aBtn) aBtn->setEnabled(enable);
455 aBtn = (QPushButton*) child("apply", "QPushButton");
456 if (aBtn) aBtn->setEnabled(enable);
459 //=================================================================================
460 // function : onNameChanged()
462 //=================================================================================
463 void SMESHGUI_GroupDlg::onNameChanged(const QString& text)
468 //=================================================================================
469 // function : onTypeChanged()
470 // purpose : Group elements type radio button management
471 //=================================================================================
472 void SMESHGUI_GroupDlg::onTypeChanged(int id)
474 if (myTypeId != id) {
476 if (myCurrentLineEdit == 0)
477 setSelectionMode(id);
482 //=================================================================================
483 // function : onGrpTypeChanged()
484 // purpose : Group type radio button management
485 //=================================================================================
486 void SMESHGUI_GroupDlg::onGrpTypeChanged(int id)
488 if (myGrpTypeId != id) {
489 myWGStack->raiseWidget( id );
490 onSelectGeomGroup(id == 1);
495 //=================================================================================
496 // function : setSelectionMode()
497 // purpose : Radio button management
498 //=================================================================================
499 void SMESHGUI_GroupDlg::setSelectionMode(int theMode)
502 if (myMesh->_is_nil())
505 if (mySelectionMode != theMode) {
506 mySelection->ClearIObjects();
507 mySelection->ClearFilters();
508 SMESH::SetPointRepresentation(false);
513 myActor->SetPointRepresentation(true);
515 SMESH::SetPointRepresentation(true);
516 QAD_Application::getDesktop()->SetSelectionMode(NodeSelection, true);
519 QAD_Application::getDesktop()->SetSelectionMode(EdgeSelection, true);
522 QAD_Application::getDesktop()->SetSelectionMode(FaceSelection, true);
525 QAD_Application::getDesktop()->SetSelectionMode(VolumeSelection, true);
529 QAD_Application::getDesktop()->SetSelectionMode(ActorSelection, true);
531 mySelection->AddFilter(mySubMeshFilter);
532 else if (theMode == 5)
533 mySelection->AddFilter(myGroupFilter);
534 else if (theMode == 6)
535 mySelection->AddFilter(myMeshFilter);
537 mySelectionMode = theMode;
541 //=================================================================================
542 // function : onApply()
544 //=================================================================================
545 bool SMESHGUI_GroupDlg::onApply()
547 if (mySMESHGUI->ActiveStudyLocked())
550 if ( myGrpTypeId == 0 && !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0) {
551 mySelection->ClearIObjects();
552 if (myGroup->_is_nil()) {
553 SMESH::ElementType aType = SMESH::ALL;
555 case 0: aType = SMESH::NODE; break;
556 case 1: aType = SMESH::EDGE; break;
557 case 2: aType = SMESH::FACE; break;
558 case 3: aType = SMESH::VOLUME; break;
560 SMESH::long_array_var anIdList = new SMESH::long_array;
561 int i, k = myElements->count();
563 QListBoxItem* anItem;
564 for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
565 anIdList[i] = anItem->text().toInt();
568 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
569 myGroup->Add(anIdList.inout());
571 /* init for next operation */
574 myGroup = SMESH::SMESH_Group::_nil();
577 myGroup->SetName(myName->text());
579 QValueList<int> aAddList;
580 QValueList<int>::iterator anIt;
581 QListBoxItem* anItem;
583 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
584 int anId = anItem->text().toInt();
585 if ((anIt = myIdList.find(anId)) == myIdList.end())
586 aAddList.append(anId);
588 myIdList.remove(anIt);
590 if (!aAddList.empty()) {
591 SMESH::long_array_var anIdList = new SMESH::long_array;
592 anIdList->length(aAddList.count());
594 for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
596 myGroup->Add(anIdList.inout());
598 if (!myIdList.empty()) {
599 SMESH::long_array_var anIdList = new SMESH::long_array;
600 anIdList->length(myIdList.count());
602 for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
604 myGroup->Remove(anIdList.inout());
606 /* init for next operation */
608 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
609 myIdList.append(anItem->text().toInt());
612 mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
613 SMESH::UpdateView(); // asv: fix of BUG PAL5515
614 mySelection->ClearIObjects();
617 else if (myGrpTypeId == 1 && !myName->text().stripWhiteSpace().isEmpty() && !CORBA::is_nil( myGeomGroup ))
619 SMESH::ElementType aType = SMESH::ALL;
621 case 0: aType = SMESH::NODE; break;
622 case 1: aType = SMESH::EDGE; break;
623 case 2: aType = SMESH::FACE; break;
624 case 3: aType = SMESH::VOLUME; break;
627 SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
628 GEOM::GEOM_IGroupOperations_var aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
630 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomGroup);
632 mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
633 mySelection->ClearIObjects();
634 /* init for next operation */
642 //=================================================================================
645 //=================================================================================
646 void SMESHGUI_GroupDlg::onOK()
652 static bool busy = false;
653 //=================================================================================
654 // function : onListSelectionChanged()
655 // purpose : Called when selection in element list is changed
656 //=================================================================================
657 void SMESHGUI_GroupDlg::onListSelectionChanged()
659 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
660 if (busy || !myActor) return;
663 if (myCurrentLineEdit == 0) {
664 mySelection->ClearIObjects();
665 TColStd_MapOfInteger aIndexes;
666 QListBoxItem* anItem;
667 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
668 if (anItem->isSelected()) {
669 int anId = anItem->text().toInt();
673 mySelection->AddOrRemoveIndex(myActor->getIO(), aIndexes, false, false);
674 mySelection->AddIObject(myActor->getIO());
679 //=================================================================================
680 // function : onObjectSelectionChanged()
681 // purpose : Called when selection in 3D view or ObjectBrowser is changed
682 //=================================================================================
683 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
685 if (busy || !isEnabled()) return;
688 int aNbSel = mySelection->IObjectCount();
689 myElements->clearSelection();
691 if (myCurrentLineEdit) {
692 myCurrentLineEdit->setText("") ;
693 QString aString = "";
695 if (myCurrentLineEdit == myMeshGroupLine)
697 mySelectSubMesh->setEnabled(false);
698 mySelectGroup->setEnabled(false);
699 myGroupLine->setText("");
700 mySubMeshLine->setText("");
702 myGeomGroupBtn->setEnabled(false);
703 myGeomGroupLine->setEnabled(false);
704 myGeomGroupLine->setText("");
712 myGroup = SMESH::SMESH_Group::_nil();
713 myMesh = SMESH::SMESH_Mesh::_nil();
717 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
721 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
722 if(myMesh->_is_nil())
724 myGroup = SMESH::SMESH_Group::_nil();
726 myActor = SMESH::FindActorByObject(myMesh);
727 SMESH::SetPickable(myActor);
729 aString = mySelection->firstIObject()->getName();
730 myMeshGroupLine->setText(aString) ;
731 myMeshGroupLine->home( false );
733 mySelectSubMesh->setEnabled(true);
734 mySelectGroup->setEnabled(true);
735 myGeomGroupBtn->setEnabled(true);
736 myGeomGroupLine->setEnabled(true);
741 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(IO);
742 if(aGroup->_is_nil())
745 myCurrentLineEdit = 0;
748 mySelectSubMesh->setEnabled(true);
749 mySelectGroup->setEnabled(true);
750 myGeomGroupBtn->setEnabled(true);
751 myGeomGroupLine->setEnabled(true);
753 myCurrentLineEdit = 0;
763 setSelectionMode(myTypeId);
768 else if (myCurrentLineEdit == myGeomGroupLine)
773 myGeomGroup = GEOM::GEOM_Object::_nil();
778 Standard_Boolean testResult = Standard_False;
779 myGeomGroup = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
781 // Check if the object is a geometry group
782 if(!testResult || CORBA::is_nil( myGeomGroup ))
784 myGeomGroup = GEOM::GEOM_Object::_nil();
788 // Check if group constructed on the same shape as a mesh or on its child
789 SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
790 GEOM::GEOM_IGroupOperations_var anOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
791 // The main shape of the group
792 GEOM::GEOM_Object_var aGroupMainShape;
793 if( myGeomGroup->GetType() == 37 )
794 aGroupMainShape = anOp->GetMainShape( myGeomGroup );
796 aGroupMainShape = GEOM::GEOM_Object::_duplicate(myGeomGroup);
797 SALOMEDS::SObject_var aGroupMainShapeSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(aGroupMainShape) );
799 SALOMEDS::SObject_var aMeshSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myMesh) );
800 if ( aMeshSO->_is_nil() ) {
801 myGeomGroup = GEOM::GEOM_Object::_nil();
805 SALOMEDS::SObject_var anObj, aRef;
806 bool isRefOrSubShape = false;
807 if ( aMeshSO->FindSubObject( 1, anObj ) && anObj->ReferencedObject( aRef )) {
808 if ( strcmp( aRef->GetID(), aGroupMainShapeSO->GetID() ) == 0 )
809 isRefOrSubShape = true;
812 SALOMEDS::SObject_var aFather = aGroupMainShapeSO->GetFather();
813 SALOMEDS::SComponent_var aComponent = aGroupMainShapeSO->GetFatherComponent();
814 while ( !isRefOrSubShape && strcmp( aFather->GetID(), aComponent->GetID() ) != 0 )
816 if (strcmp( aRef->GetID(), aFather->GetID() ) == 0)
817 isRefOrSubShape = true;
819 aFather = aFather->GetFather();
823 if ( !isRefOrSubShape )
825 myGeomGroup = GEOM::GEOM_Object::_nil();
833 if (myCurrentLineEdit == mySubMeshLine)
834 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
835 else if (myCurrentLineEdit == myGroupLine || myCurrentLineEdit == myGeomGroupLine)
836 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
839 aString = mySelection->firstIObject()->getName();
843 myCurrentLineEdit->setText(aString) ;
844 myCurrentLineEdit->home( false );
850 QString aListStr = "";
853 aNbItems = SMESH::GetNameOfSelectedNodes(mySelection, aListStr);
856 aNbItems = SMESH::GetNameOfSelectedElements(mySelection, aListStr);
859 QStringList anElements = QStringList::split(" ", aListStr);
860 QListBoxItem* anItem = 0;
861 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
862 anItem = myElements->findItem(*it, Qt::ExactMatch);
863 if (anItem) myElements->setSelected(anItem, true);
870 if ( !myGroup->_is_nil() )
871 myActor = SMESH::FindActorByObject(myGroup);
873 myActor = SMESH::FindActorByObject(myMesh);
880 //=================================================================================
881 // function : onSelectSubMesh()
882 // purpose : Called when selection in 3D view or ObjectBrowser is changed
883 //=================================================================================
884 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
887 if (mySelectGroup->isChecked()) {
888 mySelectGroup->setChecked(false);
890 //VSR: else if (mySelectGeomGroup->isChecked()) {
891 //VSR: mySelectGeomGroup->setChecked(false);
893 myCurrentLineEdit = mySubMeshLine;
897 mySubMeshLine->setText("");
898 myCurrentLineEdit = 0;
900 setSelectionMode(myTypeId);
902 mySubMeshBtn->setEnabled(on);
903 mySubMeshLine->setEnabled(on);
907 //=================================================================================
908 // function : (onSelectGroup)
909 // purpose : Called when selection in 3D view or ObjectBrowser is changed
910 //=================================================================================
911 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
914 if (mySelectSubMesh->isChecked()) {
915 mySelectSubMesh->setChecked(false);
917 myCurrentLineEdit = myGroupLine;
921 myGroupLine->setText("");
922 myCurrentLineEdit = 0;
924 setSelectionMode(myTypeId);
926 myGroupBtn->setEnabled(on);
927 myGroupLine->setEnabled(on);
931 //=================================================================================
932 // function : (onSelectGeomGroup)
933 // purpose : Called when selection in 3D view or ObjectBrowser is changed
934 //=================================================================================
935 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
938 if (mySelectSubMesh->isChecked()) {
939 mySelectSubMesh->setChecked(false);
941 else if (mySelectGroup->isChecked()) {
942 mySelectGroup->setChecked(false);
944 myCurrentLineEdit = myGeomGroupLine;
948 myGeomGroupLine->setText("");
949 myCurrentLineEdit = 0;
951 setSelectionMode(myTypeId);
956 //=================================================================================
957 // function : setCurrentSelection()
959 //=================================================================================
960 void SMESHGUI_GroupDlg::setCurrentSelection()
962 QPushButton* send = (QPushButton*)sender();
963 myCurrentLineEdit = 0;
964 if (send == myMeshGroupBtn) {
965 myCurrentLineEdit = myMeshGroupLine;
970 onObjectSelectionChanged();
972 else if (send == mySubMeshBtn) {
973 myCurrentLineEdit = mySubMeshLine;
974 onObjectSelectionChanged();
976 else if (send == myGroupBtn) {
977 myCurrentLineEdit = myGroupLine;
978 onObjectSelectionChanged();
980 else if (send == myGeomGroupBtn) {
981 myCurrentLineEdit = myGeomGroupLine;
983 onObjectSelectionChanged();
988 //=================================================================================
989 // function : setFilters()
990 // purpose : SLOT. Called when "Filter" button pressed.
991 //=================================================================================
992 void SMESHGUI_GroupDlg::setFilters()
994 SMESH::ElementType aType = SMESH::ALL;
997 case 0 : aType = SMESH::NODE; break;
998 case 1 : aType = SMESH::EDGE; break;
999 case 2 : aType = SMESH::FACE; break;
1000 case 3 : aType = SMESH::VOLUME; break;
1004 if ( myFilterDlg == 0 )
1006 myFilterDlg = new SMESHGUI_FilterDlg( (QWidget*)parent(), aType );
1007 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1010 myFilterDlg->Init( aType );
1012 myFilterDlg->SetSelection( mySelection );
1013 myFilterDlg->SetMesh( myMesh );
1014 myFilterDlg->SetSourceWg( myElements );
1016 myFilterDlg->show();
1019 //=================================================================================
1020 // function : onFilterAccepted()
1021 // purpose : SLOT. Called when Filter dlg closed with OK button.
1022 // Uncheck "Select submesh" and "Select group" checkboxes
1023 //=================================================================================
1024 void SMESHGUI_GroupDlg::onFilterAccepted()
1026 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1028 mySelectionMode = myTypeId;
1029 mySelectSubMesh->setChecked( false );
1030 mySelectGroup->setChecked( false );
1034 //=================================================================================
1035 // function : onAdd()
1037 //=================================================================================
1038 void SMESHGUI_GroupDlg::onAdd()
1040 int aNbSel = mySelection->IObjectCount();
1041 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1045 SMESH::ElementType aType = SMESH::ALL;
1047 case 0: aType = SMESH::NODE; break;
1048 case 1: aType = SMESH::EDGE; break;
1049 case 2: aType = SMESH::FACE; break;
1050 case 3: aType = SMESH::VOLUME; break;
1053 if (myCurrentLineEdit == 0) {
1054 //if (aNbSel != 1) { busy = false; return; }
1055 QString aListStr = "";
1057 if (myTypeId == 0) {
1058 aNbItems = SMESH::GetNameOfSelectedNodes(mySelection, myActor->getIO(), aListStr);
1061 aNbItems = SMESH::GetNameOfSelectedElements(mySelection, myActor->getIO(), aListStr);
1064 QStringList anElements = QStringList::split(" ", aListStr);
1065 QListBoxItem* anItem = 0;
1066 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1067 anItem = myElements->findItem(*it, Qt::ExactMatch);
1069 anItem = new QListBoxText(*it);
1070 myElements->insertItem(anItem);
1072 myElements->setSelected(anItem, true);
1076 else if (myCurrentLineEdit == mySubMeshLine) {
1077 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1078 for (; anIt.More(); anIt.Next()) {
1079 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1080 if (!aSubMesh->_is_nil()) {
1081 // check if mesh is the same
1082 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1084 SMESH::long_array_var anElements = aSubMesh->GetElementsByType ( aType );
1085 int k = anElements->length();
1086 QListBoxItem* anItem = 0;
1087 for (int i = 0; i < k; i++) {
1088 QString aText = QString::number(anElements[i]);
1089 anItem = myElements->findItem(aText, Qt::ExactMatch);
1091 anItem = new QListBoxText(aText);
1092 myElements->insertItem(anItem);
1094 myElements->setSelected(anItem, true);
1097 catch (const SALOME::SALOME_Exception& ex) {
1098 QtCatchCorbaException(ex);
1103 mySelectSubMesh->setChecked(false);
1105 onListSelectionChanged();
1107 else if (myCurrentLineEdit == myGroupLine) {
1108 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1109 for (; anIt.More(); anIt.Next()) {
1110 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1111 if (!aGroup->_is_nil()) {
1112 // check if mesh is the same
1113 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1114 SMESH::long_array_var anElements = aGroup->GetListOfID();
1115 int k = anElements->length();
1116 QListBoxItem* anItem = 0;
1117 for (int i = 0; i < k; i++) {
1118 QString aText = QString::number(anElements[i]);
1119 anItem = myElements->findItem(aText, Qt::ExactMatch);
1121 anItem = new QListBoxText(aText);
1122 myElements->insertItem(anItem);
1124 myElements->setSelected(anItem, true);
1129 mySelectGroup->setChecked(false);
1131 onListSelectionChanged();
1133 else if (myCurrentLineEdit == myGeomGroupLine && !CORBA::is_nil(myGeomGroup)) {
1135 SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
1136 GEOM::GEOM_IGroupOperations_var aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1138 SMESH::ElementType aGroupType = SMESH::ALL;
1139 switch(aGroupOp->GetType(myGeomGroup)) {
1140 case 7: aGroupType = SMESH::NODE; break;
1141 case 6: aGroupType = SMESH::EDGE; break;
1142 case 4: aGroupType = SMESH::FACE; break;
1143 case 2: aGroupType = SMESH::VOLUME; break;
1147 if (aGroupType == aType) {
1148 SALOMEDS::SObject_var aGroupSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myGeomGroup) );
1150 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1151 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1152 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1153 aBelongToGeom->SetGeom(myGeomGroup);
1154 aBelongToGeom->SetShapeName(aGroupSO->GetName());
1155 aBelongToGeom->SetElementType(aType);
1156 aFilter->SetPredicate( aBelongToGeom );
1158 SMESH::long_array_var anElements = aFilter->GetElementsId( myMesh );
1160 int k = anElements->length();
1161 QListBoxItem* anItem = 0;
1162 for (int i = 0; i < k; i++) {
1163 QString aText = QString::number(anElements[i]);
1164 anItem = myElements->findItem(aText, Qt::ExactMatch);
1166 anItem = new QListBoxText(aText);
1167 myElements->insertItem(anItem);
1169 myElements->setSelected(anItem, true);
1173 //VSR: mySelectGeomGroup->setChecked(false);
1175 onListSelectionChanged();
1178 // mySelection->ClearIObjects();
1182 //=================================================================================
1183 // function : onRemove()
1185 //=================================================================================
1186 void SMESHGUI_GroupDlg::onRemove()
1189 if (myCurrentLineEdit == 0) {
1190 for (int i = myElements->count(); i > 0; i--) {
1191 if (myElements->isSelected(i-1)) {
1192 myElements->removeItem(i-1);
1197 int aNbSel = mySelection->IObjectCount();
1198 if (aNbSel == 0) { busy = false; return; }
1200 SMESH::ElementType aType = SMESH::ALL;
1202 case 0: aType = SMESH::NODE; break;
1203 case 1: aType = SMESH::EDGE; break;
1204 case 2: aType = SMESH::FACE; break;
1205 case 3: aType = SMESH::VOLUME; break;
1208 if (myCurrentLineEdit == mySubMeshLine) {
1209 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1210 for (; anIt.More(); anIt.Next()) {
1211 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1212 if (!aSubMesh->_is_nil()) {
1213 // check if mesh is the same
1214 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1215 if (aType == SMESH::NODE) {
1217 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1218 int k = anElements->length();
1219 QListBoxItem* anItem = 0;
1220 for (int i = 0; i < k; i++) {
1221 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1222 if (anItem) delete anItem;
1225 catch (const SALOME::SALOME_Exception& ex) {
1226 QtCatchCorbaException(ex);
1231 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1232 int k = anElements->length();
1233 QListBoxItem* anItem = 0;
1234 for (int i = 0; i < k; i++) {
1235 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1236 if (anItem) delete anItem;
1239 catch (const SALOME::SALOME_Exception& ex) {
1240 QtCatchCorbaException(ex);
1247 else if (myCurrentLineEdit == myGroupLine) {
1248 Standard_Boolean aRes;
1249 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1250 for (; anIt.More(); anIt.Next()) {
1251 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1252 if (aRes && !aGroup->_is_nil()) {
1253 // check if mesh is the same
1254 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1255 SMESH::long_array_var anElements = aGroup->GetListOfID();
1256 int k = anElements->length();
1257 QListBoxItem* anItem = 0;
1258 for (int i = 0; i < k; i++) {
1259 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1260 if (anItem) delete anItem;
1271 //=================================================================================
1272 // function : onSort()
1274 //=================================================================================
1275 void SMESHGUI_GroupDlg::onSort()
1277 // PAL5412: sorts items in ascending by "string" value
1278 // myElements->sort(true);
1279 // myElements->update();
1280 int i, k = myElements->count();
1283 QStringList aSelected;
1284 std::vector<int> anArray(k);
1285 // QMemArray<int> anArray(k);
1286 QListBoxItem* anItem;
1288 for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1289 anArray[i] = anItem->text().toInt();
1290 if (anItem->isSelected())
1291 aSelected.append(anItem->text());
1293 // sort & update list
1294 std::sort(anArray.begin(), anArray.end());
1296 myElements->clear();
1297 for (i = 0; i < k; i++) {
1298 myElements->insertItem(QString::number(anArray[i]));
1300 for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1301 anItem = myElements->findItem(*it, Qt::ExactMatch);
1302 if (anItem) myElements->setSelected(anItem, true);
1308 //=================================================================================
1309 // function : closeEvent()
1311 //=================================================================================
1312 void SMESHGUI_GroupDlg::closeEvent( QCloseEvent* e )
1317 //=======================================================================
1318 // name : SMESHGUI_GroupDlg::onClose
1319 // Purpose : SLOT called when "Close" button pressed. Close dialog
1320 //=======================================================================
1321 void SMESHGUI_GroupDlg::onClose()
1323 QAD_StudyFrame* aStudyFrame = mySMESHGUI->GetActiveStudy()->getActiveStudyFrame();
1324 if (aStudyFrame->getTypeView() == VIEW_VTK) {
1325 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
1326 SMESH::SetPointRepresentation(false);
1327 SMESH::SetPickable();
1330 mySelection->ClearIObjects();
1331 QAD_Application::getDesktop()->SetSelectionMode(ActorSelection);
1332 mySelection->ClearFilters();
1333 mySMESHGUI->ResetState();
1338 //=======================================================================
1339 // name : SMESHGUI_GroupDlg::onDeactivate
1340 // Purpose : SLOT called when dialog must be deativated
1341 //=======================================================================
1342 void SMESHGUI_GroupDlg::onDeactivate()
1344 mySMESHGUI->ResetState();
1345 setEnabled( false );
1348 //=======================================================================
1349 // name : SMESHGUI_GroupDlg::enterEvent
1350 // Purpose : Event filter
1351 //=======================================================================
1352 void SMESHGUI_GroupDlg::enterEvent( QEvent* )
1354 if ( !isEnabled() ) {
1355 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1357 mySelectionMode = -1;
1358 setSelectionMode( myTypeId );
1359 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
1360 mySMESHGUI->SetState(800);
1364 //=======================================================================
1365 //function : hideEvent
1366 //purpose : caused by ESC key
1367 //=======================================================================
1369 void SMESHGUI_GroupDlg::hideEvent ( QHideEvent * e )
1371 if ( !isMinimized() )