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
30 #include "SMESHGUI_GroupDlg.h"
31 #include "SMESHGUI_FilterDlg.h"
34 #include "SALOMEGUI_QtCatchCorbaException.hxx"
35 #include "SALOME_ListIteratorOfListIO.hxx"
36 #include "VTKViewer_InteractorStyleSALOME.h"
37 #include "VTKViewer_ViewFrame.h"
38 #include "QAD_Application.h"
39 #include "QAD_Desktop.h"
40 #include "QAD_MessageBox.h"
41 #include "QAD_RightFrame.h"
42 #include "utilities.h"
44 #include "SMESH_Actor.h"
47 #include <qbuttongroup.h>
48 #include <qgroupbox.h>
51 #include <qlineedit.h>
52 #include <qpushbutton.h>
53 #include <qradiobutton.h>
54 #include <qcheckbox.h>
59 #include <qmemarray.h>
65 //=================================================================================
66 // class : SMESHGUI_GroupDlg()
68 //=================================================================================
69 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( QWidget* parent, const char* name, SALOME_Selection* theSel,
70 SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl )
71 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
73 if ( !name ) setName( "SMESHGUI_GroupDlg" );
74 initDialog(theSel, true);
77 /* Move widget on the botton right corner of main widget */
79 mySMESHGUI->DefineDlgPosition(this, x, y);
83 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( QWidget* parent, const char* name, SALOME_Selection* theSel,
84 SMESH::SMESH_Group_ptr theGroup, bool modal, WFlags fl )
85 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
87 if ( !name ) setName( "SMESHGUI_GroupDlg" );
88 initDialog(theSel, false);
91 /* Move widget on the botton right corner of main widget */
93 mySMESHGUI->DefineDlgPosition(this, x, y);
97 void SMESHGUI_GroupDlg::initDialog(SALOME_Selection* theSel, bool create)
101 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
104 setCaption( tr( "SMESH_CREATE_GROUP_TITLE" ) );
106 setCaption( tr( "SMESH_EDIT_GROUP_TITLE" ) );
107 setSizeGripEnabled( TRUE );
109 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 11, 6);
111 /***************************************************************/
112 myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
113 myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
114 myTypeGroup->setExclusive(true);
117 types.append(tr("MESH_NODE"));
118 types.append(tr("SMESH_EDGE"));
119 types.append(tr("SMESH_FACE"));
120 types.append(tr("SMESH_VOLUME"));
122 for (int i = 0; i < types.count(); i++) {
123 rb = new QRadioButton(types[i], myTypeGroup);
125 myTypeGroup->setEnabled(create);
128 /***************************************************************/
129 QHBox* aNameBox = new QHBox(this, "name box");
130 QLabel* aName = new QLabel(aNameBox, "name label");
131 aName->setText(tr("SMESH_NAME"));
132 aName->setMinimumSize(50,0);
133 myName = new QLineEdit(aNameBox, "name");
135 /***************************************************************/
136 QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, this, "content box");
137 aContentBox->setTitle(tr("SMESH_CONTENT"));
138 QFrame* aContent = new QFrame(aContentBox, "content");
139 QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
140 aLayout->setSpacing(6);
141 aLayout->setAutoAdd(false);
143 QLabel* aLabel = new QLabel(aContent, "elements label");
144 aLabel->setText(tr("SMESH_ID_ELEMENTS"));
145 myElements = new QListBox(aContent, "elements list");
146 myElements->setSelectionMode(QListBox::Extended);
147 // myElements->setMinimumHeight(150);
149 myFilter = new QPushButton(aContent, "filter");
150 myFilter->setText(tr("SMESH_BUT_FILTER"));
151 QPushButton* aAddBtn = new QPushButton(aContent, "add");
152 aAddBtn->setText(tr("SMESH_BUT_ADD"));
153 QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
154 aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
155 QPushButton* aSortBtn = new QPushButton(aContent, "sort");
156 aSortBtn->setText(tr("SMESH_BUT_SORT"));
158 aLayout->addWidget(aLabel, 0, 0);
159 aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
160 aLayout->addWidget(myFilter, 1, 2);
161 aLayout->addWidget(aAddBtn, 3, 2);
162 aLayout->addWidget(aRemoveBtn, 4, 2);
163 aLayout->addWidget(aSortBtn, 6, 2);
165 aLayout->setColStretch(0, 1);
166 aLayout->addColSpacing(1, 20);
167 aLayout->addColSpacing(3, 20);
168 aLayout->setRowStretch(2, 1);
169 aLayout->setRowStretch(5, 1);
171 aContentBox->setMinimumHeight(aContent->sizeHint().height() +
172 aContentBox->sizeHint().height());
174 /***************************************************************/
175 QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, this, "select box");
176 aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
178 mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
179 mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
180 mySelectSubMesh->setMinimumSize(50, 0);
181 mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
182 mySubMeshBtn->setText("");
183 mySubMeshBtn->setPixmap(image0);
184 mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
185 mySubMeshLine->setReadOnly(true);
186 onSelectSubMesh(false);
188 mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
189 mySelectGroup->setText(tr("SMESH_GROUP"));
190 mySelectGroup->setMinimumSize(50, 0);
191 myGroupBtn = new QPushButton(aSelectBox, "group button");
192 myGroupBtn->setText("");
193 myGroupBtn->setPixmap(image0);
194 myGroupLine = new QLineEdit(aSelectBox, "group line");
195 myGroupLine->setReadOnly(true);
196 onSelectGroup(false);
198 aSelectBox->setMinimumHeight(mySubMeshBtn->sizeHint().height() +
199 myGroupBtn->sizeHint().height() +
200 aSelectBox->sizeHint().height());
202 /***************************************************************/
203 QFrame* aButtons = new QFrame(this, "button box");
204 aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
205 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
206 aBtnLayout->setAutoAdd(false);
208 QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
209 aOKBtn->setText(tr("SMESH_BUT_OK"));
210 aOKBtn->setAutoDefault(true);
211 aOKBtn->setDefault(true);
212 QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
213 aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
214 aApplyBtn->setAutoDefault(true);
215 QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
216 aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
217 aCloseBtn->setAutoDefault(true);
219 aBtnLayout->addWidget(aOKBtn);
220 aBtnLayout->addWidget(aApplyBtn);
221 aBtnLayout->addStretch();
222 aBtnLayout->addWidget(aCloseBtn);
224 /***************************************************************/
225 aMainLayout->addWidget(myTypeGroup);
226 aMainLayout->addWidget(aNameBox);
227 aMainLayout->addWidget(aContentBox);
228 aMainLayout->addWidget(aSelectBox);
229 aMainLayout->addWidget(aButtons);
231 /* signals and slots connections */
232 connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
234 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
235 connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
237 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
238 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
239 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
240 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
242 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
243 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
244 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
245 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
247 connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
248 connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
249 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
252 mySelection = theSel;
253 mySMESHGUI = SMESHGUI::GetSMESHGUI();
254 mySMESHGUI->SetActiveDialogBox(this);
255 mySMESHGUI->SetState(800);
257 mySelectionMode = -1;
258 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
259 myGroupFilter = new SMESH_TypeFilter(GROUP);
261 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onClose()));
262 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
263 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
268 //=================================================================================
269 // function : ~SMESHGUI_GroupDlg()
270 // purpose : Destroys the object and frees any allocated resources
271 //=================================================================================
272 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
274 // no need to delete child widgets, Qt does it all for us
278 //=================================================================================
281 //=================================================================================
282 void SMESHGUI_GroupDlg::init(SMESH::SMESH_Mesh_ptr theMesh)
284 /* init data from current selection */
285 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
286 myGroup = SMESH::SMESH_Group::_nil();
288 Standard_Boolean aResult;
289 myActor = mySMESHGUI->FindActor(myMesh, aResult, true);
290 mySMESHGUI->SetPickable(myActor);
292 myTypeGroup->setButton(0);
296 //=================================================================================
299 //=================================================================================
300 void SMESHGUI_GroupDlg::init(SMESH::SMESH_Group_ptr theGroup)
303 myMesh = theGroup->GetMesh();
304 myGroup = SMESH::SMESH_Group::_duplicate(theGroup);
306 Standard_Boolean aResult;
307 myActor = mySMESHGUI->FindActor(myMesh, aResult, true);
309 myActor = mySMESHGUI->FindActor(myGroup, aResult, true);
310 mySMESHGUI->SetPickable(myActor);
313 switch(theGroup->GetType()) {
314 case SMESH::NODE: aType= 0; break;
315 case SMESH::EDGE: aType = 1; break;
316 case SMESH::FACE: aType = 2; break;
317 case SMESH::VOLUME: aType = 3; break;
319 myTypeGroup->setButton(aType);
320 onTypeChanged(aType);
322 myName->setText(myGroup->GetName());
325 if (!theGroup->IsEmpty()) {
326 SMESH::long_array_var anElements = myGroup->GetListOfID();
327 int k = anElements->length();
328 for (int i = 0; i < k; i++) {
329 myIdList.append(anElements[i]);
330 myElements->insertItem(QString::number(anElements[i]));
332 myElements->selectAll(true);
337 //=================================================================================
338 // function : updateButtons()
340 //=================================================================================
341 void SMESHGUI_GroupDlg::updateButtons()
343 bool enable = !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0;
345 aBtn = (QPushButton*) child("ok", "QPushButton");
346 if (aBtn) aBtn->setEnabled(enable);
347 aBtn = (QPushButton*) child("apply", "QPushButton");
348 if (aBtn) aBtn->setEnabled(enable);
351 //=================================================================================
352 // function : onNameChanged()
354 //=================================================================================
355 void SMESHGUI_GroupDlg::onNameChanged(const QString& text)
360 //=================================================================================
361 // function : onTypeChanged()
362 // purpose : Radio button management
363 //=================================================================================
364 void SMESHGUI_GroupDlg::onTypeChanged(int id)
366 if (myTypeId != id) {
368 if (myCurrentLineEdit == 0)
369 setSelectionMode(id);
370 myFilter->setEnabled(id == 1 || id == 2);
375 //=================================================================================
376 // function : setSelectionMode()
377 // purpose : Radio button management
378 //=================================================================================
379 void SMESHGUI_GroupDlg::setSelectionMode(int theMode)
381 if (mySelectionMode != theMode) {
382 mySelection->ClearIObjects();
383 mySelection->ClearFilters();
384 if (mySelectionMode == 0)
385 mySMESHGUI->EraseSimulationActors();
388 mySMESHGUI->ViewNodes();
389 QAD_Application::getDesktop()->SetSelectionMode(NodeSelection, true);
391 else if (theMode == 1) {
392 QAD_Application::getDesktop()->SetSelectionMode(EdgeSelection, true);
394 else if (theMode == 2) {
395 QAD_Application::getDesktop()->SetSelectionMode(FaceSelection, true);
398 QAD_Application::getDesktop()->SetSelectionMode(VolumeSelection, true);
402 QAD_Application::getDesktop()->SetSelectionMode(ActorSelection, true);
404 mySelection->AddFilter(mySubMeshFilter);
405 else if (theMode == 5)
406 mySelection->AddFilter(myGroupFilter);
408 mySelectionMode = theMode;
412 //=================================================================================
413 // function : onApply()
415 //=================================================================================
416 bool SMESHGUI_GroupDlg::onApply()
418 if (!myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0) {
419 mySelection->ClearIObjects();
420 if (myGroup->_is_nil()) {
421 SMESH::ElementType aType = SMESH::ALL;
423 case 0: aType = SMESH::NODE; break;
424 case 1: aType = SMESH::EDGE; break;
425 case 2: aType = SMESH::FACE; break;
426 case 3: aType = SMESH::VOLUME; break;
428 SMESH::long_array_var anIdList = new SMESH::long_array;
429 int i, k = myElements->count();
431 QListBoxItem* anItem;
432 for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
433 anIdList[i] = anItem->text().toInt();
436 myGroup = mySMESHGUI->AddGroup(myMesh, aType, myName->text());
437 myGroup->Add(anIdList);
439 /* init for next operation */
442 myGroup = SMESH::SMESH_Group::_nil();
445 myGroup->SetName(myName->text());
447 QValueList<int> aAddList;
448 QValueList<int>::iterator anIt;
449 QListBoxItem* anItem;
450 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
451 int anId = anItem->text().toInt();
452 if ((anIt = myIdList.find(anId)) == myIdList.end())
453 aAddList.append(anId);
455 myIdList.remove(anIt);
457 if (!aAddList.empty()) {
458 SMESH::long_array_var anIdList = new SMESH::long_array;
459 anIdList->length(aAddList.count());
461 for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
463 myGroup->Add(anIdList);
465 if (!myIdList.empty()) {
466 SMESH::long_array_var anIdList = new SMESH::long_array;
467 anIdList->length(myIdList.count());
469 for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
471 myGroup->Remove(anIdList);
473 /* init for next operation */
475 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
476 myIdList.append(anItem->text().toInt());
479 mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
480 mySelection->ClearIObjects();
486 //=================================================================================
489 //=================================================================================
490 void SMESHGUI_GroupDlg::onOK()
496 //=================================================================================
497 // function : onClose()
499 //=================================================================================
500 void SMESHGUI_GroupDlg::onClose()
506 static bool busy = false;
507 //=================================================================================
508 // function : onListSelectionChanged()
509 // purpose : Called when selection in element list is changed
510 //=================================================================================
511 void SMESHGUI_GroupDlg::onListSelectionChanged()
513 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
514 if (busy || !myActor) return;
517 if (myCurrentLineEdit == 0) {
518 mySelection->ClearIObjects();
519 TColStd_MapOfInteger aIndexes;
520 QListBoxItem* anItem;
521 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
522 if (anItem->isSelected()) {
523 std::vector<int> aVtkList;
525 aVtkList = myActor->GetNodeVtkId(anItem->text().toInt());
527 aVtkList = myActor->GetElemVtkId(anItem->text().toInt());
529 if (aVtkList.size() > 0) {
530 std::vector<int>::iterator it;
531 for (it = aVtkList.begin(); it != aVtkList.end(); ++it) {
537 mySelection->AddOrRemoveIndex(myActor->getIO(), aIndexes, false, false);
538 mySelection->AddIObject(myActor->getIO());
543 //=================================================================================
544 // function : onObjectSelectionChanged()
545 // purpose : Called when selection in 3D view or ObjectBrowser is changed
546 //=================================================================================
547 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
552 int aNbSel = mySelection->IObjectCount();
553 myElements->clearSelection();
555 if (myCurrentLineEdit) {
556 myCurrentLineEdit->setText("") ;
557 QString aString = "";
560 if (myCurrentLineEdit = mySubMeshLine)
561 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
562 else if (myCurrentLineEdit = myGroupLine)
563 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
566 aString = mySelection->firstIObject()->getName();
570 myCurrentLineEdit->setText(aString) ;
571 myCurrentLineEdit->home( false );
575 QString aListStr = "";
578 aNbItems = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aListStr);
581 aNbItems = mySMESHGUI->GetNameOfSelectedElements(mySelection, aListStr);
584 QStringList anElements = QStringList::split(" ", aListStr);
585 QListBoxItem* anItem = 0;
586 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
587 anItem = myElements->findItem(*it, Qt::ExactMatch);
588 if (anItem) myElements->setSelected(anItem, true);
597 //=================================================================================
598 // function : onSelectSubMesh()
599 // purpose : Called when selection in 3D view or ObjectBrowser is changed
600 //=================================================================================
601 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
604 if (mySelectGroup->isChecked()) {
605 mySelectGroup->setChecked(false);
607 myCurrentLineEdit = mySubMeshLine;
611 mySubMeshLine->setText("");
612 myCurrentLineEdit = 0;
614 setSelectionMode(myTypeId);
616 mySubMeshBtn->setEnabled(on);
617 mySubMeshLine->setEnabled(on);
620 //=================================================================================
621 // function : (onSelectGroup)
622 // purpose : Called when selection in 3D view or ObjectBrowser is changed
623 //=================================================================================
624 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
627 if (mySelectSubMesh->isChecked()) {
628 mySelectSubMesh->setChecked(false);
630 myCurrentLineEdit = myGroupLine;
634 myGroupLine->setText("");
635 myCurrentLineEdit = 0;
637 setSelectionMode(myTypeId);
639 myGroupBtn->setEnabled(on);
640 myGroupLine->setEnabled(on);
643 //=================================================================================
644 // function : setCurrentSelection()
646 //=================================================================================
647 void SMESHGUI_GroupDlg::setCurrentSelection()
649 QPushButton* send = (QPushButton*)sender();
650 myCurrentLineEdit = 0;
651 if (send == mySubMeshBtn) {
652 myCurrentLineEdit = mySubMeshLine;
653 onObjectSelectionChanged();
655 else if (send == myGroupBtn) {
656 myCurrentLineEdit = myGroupLine;
657 onObjectSelectionChanged();
662 //=================================================================================
663 // function : setFilters()
664 // purpose : SLOT. Called when "Filter" button pressed.
665 //=================================================================================
666 void SMESHGUI_GroupDlg::setFilters()
668 SMESH::ElementType aType = SMESH::ALL;
671 case 0 : aType = SMESH::NODE; break;
672 case 1 : aType = SMESH::EDGE; break;
673 case 2 : aType = SMESH::FACE; break;
674 case 3 : aType = SMESH::VOLUME; break;
678 if ( myFilterDlg == 0 )
679 myFilterDlg = new SMESHGUI_FilterDlg( this, aType, true );
681 myFilterDlg->Init( aType );
683 myFilterDlg->SetSelection( mySelection );
684 myFilterDlg->SetMesh( myMesh );
685 myFilterDlg->SetSourceWg( myElements );
687 if ( myFilterDlg->exec() != QDialog::Accepted )
690 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
692 mySelectionMode = myTypeId;
693 mySelectSubMesh->setChecked( false );
694 mySelectGroup->setChecked( false );
698 //=================================================================================
699 // function : onAdd()
701 //=================================================================================
702 void SMESHGUI_GroupDlg::onAdd()
704 int aNbSel = mySelection->IObjectCount();
705 if (aNbSel == 0) return;
709 SMESH::ElementType aType = SMESH::ALL;
711 case 0: aType = SMESH::NODE; break;
712 case 1: aType = SMESH::EDGE; break;
713 case 2: aType = SMESH::FACE; break;
714 case 3: aType = SMESH::VOLUME; break;
717 if (myCurrentLineEdit == 0) {
718 if (aNbSel != 1) { busy = false; return; }
719 QString aListStr = "";
722 aNbItems = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aListStr);
725 aNbItems = mySMESHGUI->GetNameOfSelectedElements(mySelection, aListStr);
728 QStringList anElements = QStringList::split(" ", aListStr);
729 QListBoxItem* anItem = 0;
730 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
731 anItem = myElements->findItem(*it, Qt::ExactMatch);
733 anItem = new QListBoxText(*it);
734 myElements->insertItem(anItem);
736 myElements->setSelected(anItem, true);
740 else if (myCurrentLineEdit == mySubMeshLine) {
741 Standard_Boolean aRes;
742 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
743 for (; anIt.More(); anIt.Next()) {
744 SMESH::SMESH_subMesh_var aSubMesh = mySMESHGUI->ConvertIOinSubMesh(anIt.Value(), aRes);
745 if (aRes && !aSubMesh->_is_nil()) {
746 // check if mesh is the same
747 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
748 if (aType == SMESH::NODE) {
750 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
751 int k = anElements->length();
752 QListBoxItem* anItem = 0;
753 for (int i = 0; i < k; i++) {
754 QString aText = QString::number(anElements[i]);
755 anItem = myElements->findItem(aText, Qt::ExactMatch);
757 anItem = new QListBoxText(aText);
758 myElements->insertItem(anItem);
760 myElements->setSelected(anItem, true);
763 catch (const SALOME::SALOME_Exception& ex) {
764 QtCatchCorbaException(ex);
769 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
770 int k = anElements->length();
771 QListBoxItem* anItem = 0;
772 for (int i = 0; i < k; i++) {
773 QString aText = QString::number(anElements[i]);
774 anItem = myElements->findItem(aText, Qt::ExactMatch);
776 anItem = new QListBoxText(aText);
777 myElements->insertItem(anItem);
779 myElements->setSelected(anItem, true);
782 catch (const SALOME::SALOME_Exception& ex) {
783 QtCatchCorbaException(ex);
789 mySelectSubMesh->setChecked(false);
791 onListSelectionChanged();
793 else if (myCurrentLineEdit == myGroupLine) {
794 Standard_Boolean aRes;
795 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
796 for (; anIt.More(); anIt.Next()) {
797 SMESH::SMESH_Group_var aGroup = mySMESHGUI->ConvertIOinSMESHGroup(anIt.Value(), aRes);
798 if (aRes && !aGroup->_is_nil()) {
799 // check if mesh is the same
800 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
801 SMESH::long_array_var anElements = aGroup->GetListOfID();
802 int k = anElements->length();
803 QListBoxItem* anItem = 0;
804 for (int i = 0; i < k; i++) {
805 QString aText = QString::number(anElements[i]);
806 anItem = myElements->findItem(aText, Qt::ExactMatch);
808 anItem = new QListBoxText(aText);
809 myElements->insertItem(anItem);
811 myElements->setSelected(anItem, true);
816 mySelectGroup->setChecked(false);
818 onListSelectionChanged();
821 // mySelection->ClearIObjects();
825 //=================================================================================
826 // function : onRemove()
828 //=================================================================================
829 void SMESHGUI_GroupDlg::onRemove()
832 if (myCurrentLineEdit == 0) {
833 for (int i = myElements->count(); i > 0; i--) {
834 if (myElements->isSelected(i-1)) {
835 myElements->removeItem(i-1);
840 int aNbSel = mySelection->IObjectCount();
841 if (aNbSel == 0) { busy = false; return; }
843 SMESH::ElementType aType = SMESH::ALL;
845 case 0: aType = SMESH::NODE; break;
846 case 1: aType = SMESH::EDGE; break;
847 case 2: aType = SMESH::FACE; break;
848 case 3: aType = SMESH::VOLUME; break;
851 if (myCurrentLineEdit == mySubMeshLine) {
852 Standard_Boolean aRes;
853 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
854 for (; anIt.More(); anIt.Next()) {
855 SMESH::SMESH_subMesh_var aSubMesh = mySMESHGUI->ConvertIOinSubMesh(anIt.Value(), aRes);
856 if (aRes && !aSubMesh->_is_nil()) {
857 // check if mesh is the same
858 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
859 if (aType == SMESH::NODE) {
861 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
862 int k = anElements->length();
863 QListBoxItem* anItem = 0;
864 for (int i = 0; i < k; i++) {
865 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
866 if (anItem) delete anItem;
869 catch (const SALOME::SALOME_Exception& ex) {
870 QtCatchCorbaException(ex);
875 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
876 int k = anElements->length();
877 QListBoxItem* anItem = 0;
878 for (int i = 0; i < k; i++) {
879 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
880 if (anItem) delete anItem;
883 catch (const SALOME::SALOME_Exception& ex) {
884 QtCatchCorbaException(ex);
891 else if (myCurrentLineEdit == myGroupLine) {
892 Standard_Boolean aRes;
893 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
894 for (; anIt.More(); anIt.Next()) {
895 SMESH::SMESH_Group_var aGroup = mySMESHGUI->ConvertIOinSMESHGroup(anIt.Value(), aRes);
896 if (aRes && !aGroup->_is_nil()) {
897 // check if mesh is the same
898 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
899 SMESH::long_array_var anElements = aGroup->GetListOfID();
900 int k = anElements->length();
901 QListBoxItem* anItem = 0;
902 for (int i = 0; i < k; i++) {
903 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
904 if (anItem) delete anItem;
915 //=================================================================================
916 // function : onSort()
918 //=================================================================================
919 void SMESHGUI_GroupDlg::onSort()
921 // PAL5412: sorts items in ascending by "string" value
922 // myElements->sort(true);
923 // myElements->update();
924 int i, k = myElements->count();
927 QStringList aSelected;
928 std::vector<int> anArray(k);
929 // QMemArray<int> anArray(k);
930 QListBoxItem* anItem;
932 for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
933 anArray[i] = anItem->text().toInt();
934 if (anItem->isSelected())
935 aSelected.append(anItem->text());
937 // sort & update list
938 std::sort(anArray.begin(), anArray.end());
941 for (i = 0; i < k; i++) {
942 myElements->insertItem(QString::number(anArray[i]));
944 for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
945 anItem = myElements->findItem(*it, Qt::ExactMatch);
946 if (anItem) myElements->setSelected(anItem, true);
952 //=================================================================================
953 // function : closeEvent()
955 //=================================================================================
956 void SMESHGUI_GroupDlg::closeEvent( QCloseEvent* e )
958 QAD_StudyFrame* aStudyFrame = mySMESHGUI->GetActiveStudy()->getActiveStudyFrame();
959 if (aStudyFrame->getTypeView() == VIEW_VTK) {
960 mySMESHGUI->SetPickable();
961 if (mySelectionMode == 0)
962 mySMESHGUI->EraseSimulationActors();
964 // remove filters from viewer
965 VTKViewer_InteractorStyleSALOME* aStyle = ((VTKViewer_ViewFrame*)aStudyFrame->getRightFrame()->getViewFrame())->getRWInteractor()->GetInteractorStyleSALOME();
966 aStyle->RemoveEdgeFilter();
967 aStyle->RemoveFaceFilter();
971 mySelection->ClearIObjects();
972 QAD_Application::getDesktop()->SetSelectionMode(ActorSelection);
973 mySelection->ClearFilters();
974 mySMESHGUI->ResetState();
976 QDialog::closeEvent( e );