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_GroupUtils.h"
37 #include "SMESHGUI_FilterUtils.h"
38 #include "SMESHGUI_GEOMGenUtils.h"
40 #include "SALOMEGUI_QtCatchCorbaException.hxx"
41 #include "SALOME_ListIteratorOfListIO.hxx"
42 #include "VTKViewer_ViewFrame.h"
43 #include "QAD_Application.h"
44 #include "QAD_Desktop.h"
45 #include "QAD_MessageBox.h"
46 #include "QAD_RightFrame.h"
47 #include "utilities.h"
49 #include "SMESH_Actor.h"
54 #include <qbuttongroup.h>
55 #include <qgroupbox.h>
58 #include <qlineedit.h>
59 #include <qpushbutton.h>
60 #include <qradiobutton.h>
61 #include <qcheckbox.h>
66 #include <qmemarray.h>
74 //=================================================================================
75 // class : SMESHGUI_GroupDlg()
77 //=================================================================================
78 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( QWidget* parent, const char* name, SALOME_Selection* theSel,
79 SMESH::SMESH_Mesh_ptr theMesh, bool modal, WFlags fl )
80 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
82 if ( !name ) setName( "SMESHGUI_GroupDlg" );
83 initDialog(theSel, true);
86 /* Move widget on the botton right corner of main widget */
88 mySMESHGUI->DefineDlgPosition(this, x, y);
92 SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( QWidget* parent, const char* name, SALOME_Selection* theSel,
93 SMESH::SMESH_Group_ptr theGroup, bool modal, WFlags fl )
94 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
96 if ( !name ) setName( "SMESHGUI_GroupDlg" );
97 initDialog(theSel, false);
100 /* Move widget on the botton right corner of main widget */
102 mySMESHGUI->DefineDlgPosition(this, x, y);
106 void SMESHGUI_GroupDlg::initDialog(SALOME_Selection* theSel, bool create)
110 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
113 setCaption( tr( "SMESH_CREATE_GROUP_TITLE" ) );
115 setCaption( tr( "SMESH_EDIT_GROUP_TITLE" ) );
116 setSizeGripEnabled( TRUE );
118 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 11, 6);
120 /***************************************************************/
121 myTypeGroup = new QButtonGroup(1, Qt::Vertical, this, "Group types");
122 myTypeGroup->setTitle(tr("SMESH_ELEMENTS_TYPE"));
123 myTypeGroup->setExclusive(true);
126 types.append(tr("MESH_NODE"));
127 types.append(tr("SMESH_EDGE"));
128 types.append(tr("SMESH_FACE"));
129 types.append(tr("SMESH_VOLUME"));
131 for (int i = 0; i < types.count(); i++) {
132 rb = new QRadioButton(types[i], myTypeGroup);
134 myTypeGroup->setEnabled(create);
137 /***************************************************************/
138 QHBox* aNameBox = new QHBox(this, "name box");
139 QLabel* aName = new QLabel(aNameBox, "name label");
140 aName->setText(tr("SMESH_NAME"));
141 aName->setMinimumSize(50,0);
142 myName = new QLineEdit(aNameBox, "name");
144 /***************************************************************/
145 QGroupBox* aContentBox = new QGroupBox(1, Qt::Horizontal, this, "content box");
146 aContentBox->setTitle(tr("SMESH_CONTENT"));
147 QFrame* aContent = new QFrame(aContentBox, "content");
148 QGridLayout* aLayout = new QGridLayout(aContent, 7, 4);
149 aLayout->setSpacing(6);
150 aLayout->setAutoAdd(false);
152 QLabel* aLabel = new QLabel(aContent, "elements label");
153 aLabel->setText(tr("SMESH_ID_ELEMENTS"));
154 myElements = new QListBox(aContent, "elements list");
155 myElements->setSelectionMode(QListBox::Extended);
156 // myElements->setMinimumHeight(150);
158 myFilter = new QPushButton(aContent, "filter");
159 myFilter->setText(tr("SMESH_BUT_FILTER"));
160 QPushButton* aAddBtn = new QPushButton(aContent, "add");
161 aAddBtn->setText(tr("SMESH_BUT_ADD"));
162 QPushButton* aRemoveBtn = new QPushButton(aContent, "remove");
163 aRemoveBtn->setText(tr("SMESH_BUT_REMOVE"));
164 QPushButton* aSortBtn = new QPushButton(aContent, "sort");
165 aSortBtn->setText(tr("SMESH_BUT_SORT"));
167 aLayout->addWidget(aLabel, 0, 0);
168 aLayout->addMultiCellWidget(myElements, 1, 6, 0, 0);
169 aLayout->addWidget(myFilter, 1, 2);
170 aLayout->addWidget(aAddBtn, 3, 2);
171 aLayout->addWidget(aRemoveBtn, 4, 2);
172 aLayout->addWidget(aSortBtn, 6, 2);
174 aLayout->setColStretch(0, 1);
175 aLayout->addColSpacing(1, 20);
176 aLayout->addColSpacing(3, 20);
177 aLayout->setRowStretch(2, 1);
178 aLayout->setRowStretch(5, 1);
180 aContentBox->setMinimumHeight(aContent->sizeHint().height() +
181 aContentBox->sizeHint().height());
183 /***************************************************************/
184 QGroupBox* aSelectBox = new QGroupBox(3, Qt::Horizontal, this, "select box");
185 aSelectBox->setTitle(tr("SMESH_SELECT_FROM"));
187 mySelectSubMesh = new QCheckBox(aSelectBox, "submesh checkbox");
188 mySelectSubMesh->setText(tr("SMESH_SUBMESH"));
189 mySelectSubMesh->setMinimumSize(50, 0);
190 mySubMeshBtn = new QPushButton(aSelectBox, "submesh button");
191 mySubMeshBtn->setText("");
192 mySubMeshBtn->setPixmap(image0);
193 mySubMeshLine = new QLineEdit(aSelectBox, "submesh line");
194 mySubMeshLine->setReadOnly(true);
195 onSelectSubMesh(false);
197 mySelectGroup = new QCheckBox(aSelectBox, "group checkbox");
198 mySelectGroup->setText(tr("SMESH_GROUP"));
199 mySelectGroup->setMinimumSize(50, 0);
200 myGroupBtn = new QPushButton(aSelectBox, "group button");
201 myGroupBtn->setText("");
202 myGroupBtn->setPixmap(image0);
203 myGroupLine = new QLineEdit(aSelectBox, "group line");
204 myGroupLine->setReadOnly(true);
205 onSelectGroup(false);
207 mySelectGeomGroup = new QCheckBox(aSelectBox, "geometry group checkbox");
208 mySelectGeomGroup->setText(tr("SMESH_GEOM_GROUP"));
209 mySelectGeomGroup->setMinimumSize(50, 0);
210 mySelectGeomGroup->setEnabled(create);
211 myGeomGroupBtn = new QPushButton(aSelectBox, "geometry group button");
212 myGeomGroupBtn->setText("");
213 myGeomGroupBtn->setPixmap(image0);
214 myGeomGroupLine = new QLineEdit(aSelectBox, "geometry group line");
215 myGeomGroupLine->setReadOnly(true);
216 onSelectGeomGroup(false);
218 aSelectBox->setMinimumHeight(137);
219 aSelectBox->setMinimumWidth(305);
221 /***************************************************************/
222 QFrame* aButtons = new QFrame(this, "button box");
223 aButtons->setFrameStyle(QFrame::Box | QFrame::Sunken);
224 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtons, 11, 6);
225 aBtnLayout->setAutoAdd(false);
227 QPushButton* aOKBtn = new QPushButton(aButtons, "ok");
228 aOKBtn->setText(tr("SMESH_BUT_OK"));
229 aOKBtn->setAutoDefault(true);
230 aOKBtn->setDefault(true);
231 QPushButton* aApplyBtn = new QPushButton(aButtons, "apply");
232 aApplyBtn->setText(tr("SMESH_BUT_APPLY"));
233 aApplyBtn->setAutoDefault(true);
234 QPushButton* aCloseBtn = new QPushButton(aButtons, "close");
235 aCloseBtn->setText(tr("SMESH_BUT_CLOSE"));
236 aCloseBtn->setAutoDefault(true);
238 aBtnLayout->addWidget(aOKBtn);
239 aBtnLayout->addWidget(aApplyBtn);
240 aBtnLayout->addStretch();
241 aBtnLayout->addWidget(aCloseBtn);
243 /***************************************************************/
244 aMainLayout->addWidget(myTypeGroup);
245 aMainLayout->addWidget(aNameBox);
246 aMainLayout->addWidget(aContentBox);
247 aMainLayout->addWidget(aSelectBox);
248 aMainLayout->addWidget(aButtons);
250 /* signals and slots connections */
251 connect(myTypeGroup, SIGNAL(clicked(int)), this, SLOT(onTypeChanged(int)));
253 connect(myName, SIGNAL(textChanged(const QString&)), this, SLOT(onNameChanged(const QString&)));
254 connect(myElements, SIGNAL(selectionChanged()), this, SLOT(onListSelectionChanged()));
256 connect(myFilter, SIGNAL(clicked()), this, SLOT(setFilters()));
257 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(onAdd()));
258 connect(aRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemove()));
259 connect(aSortBtn, SIGNAL(clicked()), this, SLOT(onSort()));
261 connect(mySelectSubMesh, SIGNAL(toggled(bool)), this, SLOT(onSelectSubMesh(bool)));
262 connect(mySelectGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGroup(bool)));
263 connect(mySelectGeomGroup, SIGNAL(toggled(bool)), this, SLOT(onSelectGeomGroup(bool)));
264 connect(mySubMeshBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
265 connect(myGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
266 connect(myGeomGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
269 connect(aOKBtn, SIGNAL(clicked()), this, SLOT(onOK()));
270 connect(aApplyBtn, SIGNAL(clicked()), this, SLOT(onApply()));
271 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(onClose()));
274 mySelection = theSel;
275 mySMESHGUI = SMESHGUI::GetSMESHGUI();
276 mySMESHGUI->SetActiveDialogBox(this);
277 mySMESHGUI->SetState(800);
279 mySelectionMode = -1;
280 mySubMeshFilter = new SMESH_TypeFilter(SUBMESH);
281 myGroupFilter = new SMESH_TypeFilter(GROUP);
283 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
284 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(onClose()));
285 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(onObjectSelectionChanged()));
290 //=================================================================================
291 // function : ~SMESHGUI_GroupDlg()
292 // purpose : Destroys the object and frees any allocated resources
293 //=================================================================================
294 SMESHGUI_GroupDlg::~SMESHGUI_GroupDlg()
296 // no need to delete child widgets, Qt does it all for us
297 if ( myFilterDlg != 0 )
299 myFilterDlg->reparent( 0, QPoint() );
305 //=================================================================================
308 //=================================================================================
309 void SMESHGUI_GroupDlg::init(SMESH::SMESH_Mesh_ptr theMesh)
311 /* init data from current selection */
312 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
313 myGroup = SMESH::SMESH_Group::_nil();
315 myActor = SMESH::FindActorByObject(myMesh);
316 SMESH::SetPickable(myActor);
318 myTypeGroup->setButton(0);
322 //=================================================================================
325 //=================================================================================
326 void SMESHGUI_GroupDlg::init(SMESH::SMESH_Group_ptr theGroup)
328 myMesh = theGroup->GetMesh();
329 myGroup = SMESH::SMESH_Group::_duplicate(theGroup);
331 myActor = SMESH::FindActorByObject(myMesh);
333 myActor = SMESH::FindActorByObject(myGroup);
334 SMESH::SetPickable(myActor);
337 switch(theGroup->GetType()) {
338 case SMESH::NODE: aType= 0; break;
339 case SMESH::EDGE: aType = 1; break;
340 case SMESH::FACE: aType = 2; break;
341 case SMESH::VOLUME: aType = 3; break;
343 myTypeGroup->setButton(aType);
344 onTypeChanged(aType);
346 myName->setText(myGroup->GetName());
349 if (!theGroup->IsEmpty()) {
350 SMESH::long_array_var anElements = myGroup->GetListOfID();
351 int k = anElements->length();
352 for (int i = 0; i < k; i++) {
353 myIdList.append(anElements[i]);
354 myElements->insertItem(QString::number(anElements[i]));
356 myElements->selectAll(true);
361 //=================================================================================
362 // function : updateButtons()
364 //=================================================================================
365 void SMESHGUI_GroupDlg::updateButtons()
367 bool enable = !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0;
369 aBtn = (QPushButton*) child("ok", "QPushButton");
370 if (aBtn) aBtn->setEnabled(enable);
371 aBtn = (QPushButton*) child("apply", "QPushButton");
372 if (aBtn) aBtn->setEnabled(enable);
375 //=================================================================================
376 // function : onNameChanged()
378 //=================================================================================
379 void SMESHGUI_GroupDlg::onNameChanged(const QString& text)
384 //=================================================================================
385 // function : onTypeChanged()
386 // purpose : Radio button management
387 //=================================================================================
388 void SMESHGUI_GroupDlg::onTypeChanged(int id)
390 if (myTypeId != id) {
392 if (myCurrentLineEdit == 0)
393 setSelectionMode(id);
398 //=================================================================================
399 // function : setSelectionMode()
400 // purpose : Radio button management
401 //=================================================================================
402 void SMESHGUI_GroupDlg::setSelectionMode(int theMode)
404 if (mySelectionMode != theMode) {
405 mySelection->ClearIObjects();
406 mySelection->ClearFilters();
407 SMESH::SetPointRepresentation(false);
412 myActor->SetPointRepresentation(true);
414 SMESH::SetPointRepresentation(true);
415 QAD_Application::getDesktop()->SetSelectionMode(NodeSelection, true);
418 QAD_Application::getDesktop()->SetSelectionMode(EdgeSelection, true);
421 QAD_Application::getDesktop()->SetSelectionMode(FaceSelection, true);
424 QAD_Application::getDesktop()->SetSelectionMode(VolumeSelection, true);
428 QAD_Application::getDesktop()->SetSelectionMode(ActorSelection, true);
430 mySelection->AddFilter(mySubMeshFilter);
431 else if (theMode == 5)
432 mySelection->AddFilter(myGroupFilter);
434 mySelectionMode = theMode;
438 //=================================================================================
439 // function : onApply()
441 //=================================================================================
442 bool SMESHGUI_GroupDlg::onApply()
444 if (mySMESHGUI->ActiveStudyLocked())
446 if (!myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0) {
447 mySelection->ClearIObjects();
448 if (myGroup->_is_nil()) {
449 SMESH::ElementType aType = SMESH::ALL;
451 case 0: aType = SMESH::NODE; break;
452 case 1: aType = SMESH::EDGE; break;
453 case 2: aType = SMESH::FACE; break;
454 case 3: aType = SMESH::VOLUME; break;
456 SMESH::long_array_var anIdList = new SMESH::long_array;
457 int i, k = myElements->count();
459 QListBoxItem* anItem;
460 for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
461 anIdList[i] = anItem->text().toInt();
464 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
465 myGroup->Add(anIdList.inout());
467 //Add reference to geometry group if it is neccessary
468 if (!CORBA::is_nil( myGeomGroup ))
470 SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
471 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
472 SALOMEDS::SObject_var aGeomGroupSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myGeomGroup) );
473 SALOMEDS::SObject_var aMeshGroupSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myGroup) );
474 SALOMEDS::SObject_var aReference = aStudyBuilder->NewObject(aMeshGroupSO);
475 aStudyBuilder->Addreference(aReference, aGeomGroupSO);
478 /* init for next operation */
481 myGroup = SMESH::SMESH_Group::_nil();
484 myGroup->SetName(myName->text());
486 QValueList<int> aAddList;
487 QValueList<int>::iterator anIt;
488 QListBoxItem* anItem;
489 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
490 int anId = anItem->text().toInt();
491 if ((anIt = myIdList.find(anId)) == myIdList.end())
492 aAddList.append(anId);
494 myIdList.remove(anIt);
496 if (!aAddList.empty()) {
497 SMESH::long_array_var anIdList = new SMESH::long_array;
498 anIdList->length(aAddList.count());
500 for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
502 myGroup->Add(anIdList.inout());
504 if (!myIdList.empty()) {
505 SMESH::long_array_var anIdList = new SMESH::long_array;
506 anIdList->length(myIdList.count());
508 for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
510 myGroup->Remove(anIdList.inout());
512 /* init for next operation */
514 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
515 myIdList.append(anItem->text().toInt());
518 mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
519 SMESH::UpdateView(); // asv: fix of BUG PAL5515
520 mySelection->ClearIObjects();
526 //=================================================================================
529 //=================================================================================
530 void SMESHGUI_GroupDlg::onOK()
536 static bool busy = false;
537 //=================================================================================
538 // function : onListSelectionChanged()
539 // purpose : Called when selection in element list is changed
540 //=================================================================================
541 void SMESHGUI_GroupDlg::onListSelectionChanged()
543 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
544 if (busy || !myActor) return;
547 if (myCurrentLineEdit == 0) {
548 mySelection->ClearIObjects();
549 TColStd_MapOfInteger aIndexes;
550 QListBoxItem* anItem;
551 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
552 if (anItem->isSelected()) {
553 int anId = anItem->text().toInt();
557 mySelection->AddOrRemoveIndex(myActor->getIO(), aIndexes, false, false);
558 mySelection->AddIObject(myActor->getIO());
563 //=================================================================================
564 // function : onObjectSelectionChanged()
565 // purpose : Called when selection in 3D view or ObjectBrowser is changed
566 //=================================================================================
567 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
569 if (busy || !isEnabled()) return;
572 int aNbSel = mySelection->IObjectCount();
573 myElements->clearSelection();
575 if (myCurrentLineEdit) {
576 myCurrentLineEdit->setText("") ;
577 QString aString = "";
579 if (myCurrentLineEdit == myGeomGroupLine)
583 myGeomGroup = GEOM::GEOM_Object::_nil();
587 Standard_Boolean testResult = Standard_False;
588 myGeomGroup = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
590 // Check if the object is a geometry group
591 if(!testResult || CORBA::is_nil( myGeomGroup ) || myGeomGroup->GetType() != 37)
593 myGeomGroup = GEOM::GEOM_Object::_nil();
597 // Check if group constructed on the same shape as a mesh or on its child
598 SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
599 GEOM::GEOM_IGroupOperations_var anOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
600 // The main shape of the group
601 GEOM::GEOM_Object_var aGroupMainShape = anOp->GetMainShape( myGeomGroup );
602 SALOMEDS::SObject_var aGroupMainShapeSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(aGroupMainShape) );
604 SALOMEDS::SObject_var aMeshSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myMesh) );
606 SALOMEDS::SObject_var anObj, aRef;
607 bool isRefOrSubShape = false;
609 if ( aMeshSO->FindSubObject( 1, anObj ) && anObj->ReferencedObject( aRef )) {
610 if ( strcmp( aRef->GetID(), aGroupMainShapeSO->GetID() ) == 0 )
611 isRefOrSubShape = true;
614 SALOMEDS::SObject_var aFather = aGroupMainShapeSO->GetFather();
615 SALOMEDS::SComponent_var aComponent = aGroupMainShapeSO->GetFatherComponent();
616 while ( !isRefOrSubShape && strcmp( aFather->GetID(), aComponent->GetID() ) != 0 )
618 if (strcmp( aRef->GetID(), aFather->GetID() ) == 0)
619 isRefOrSubShape = true;
621 aFather = aFather->GetFather();
624 if ( !isRefOrSubShape )
626 myGeomGroup = GEOM::GEOM_Object::_nil();
635 if (myCurrentLineEdit == mySubMeshLine)
636 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
637 else if (myCurrentLineEdit == myGroupLine || myCurrentLineEdit == myGeomGroupLine)
638 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
641 aString = mySelection->firstIObject()->getName();
645 myCurrentLineEdit->setText(aString) ;
646 myCurrentLineEdit->home( false );
650 QString aListStr = "";
653 aNbItems = SMESH::GetNameOfSelectedNodes(mySelection, aListStr);
656 aNbItems = SMESH::GetNameOfSelectedElements(mySelection, aListStr);
659 QStringList anElements = QStringList::split(" ", aListStr);
660 QListBoxItem* anItem = 0;
661 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
662 anItem = myElements->findItem(*it, Qt::ExactMatch);
663 if (anItem) myElements->setSelected(anItem, true);
670 if ( !myGroup->_is_nil() )
671 myActor = SMESH::FindActorByObject(myGroup);
673 myActor = SMESH::FindActorByObject(myMesh);
680 //=================================================================================
681 // function : onSelectSubMesh()
682 // purpose : Called when selection in 3D view or ObjectBrowser is changed
683 //=================================================================================
684 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
687 if (mySelectGroup->isChecked()) {
688 mySelectGroup->setChecked(false);
690 else if (mySelectGeomGroup->isChecked()) {
691 mySelectGeomGroup->setChecked(false);
693 myCurrentLineEdit = mySubMeshLine;
697 mySubMeshLine->setText("");
698 myCurrentLineEdit = 0;
700 setSelectionMode(myTypeId);
702 mySubMeshBtn->setEnabled(on);
703 mySubMeshLine->setEnabled(on);
707 //=================================================================================
708 // function : (onSelectGroup)
709 // purpose : Called when selection in 3D view or ObjectBrowser is changed
710 //=================================================================================
711 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
714 if (mySelectSubMesh->isChecked()) {
715 mySelectSubMesh->setChecked(false);
717 else if (mySelectGeomGroup->isChecked()) {
718 mySelectGeomGroup->setChecked(false);
720 myCurrentLineEdit = myGroupLine;
724 myGroupLine->setText("");
725 myCurrentLineEdit = 0;
727 setSelectionMode(myTypeId);
729 myGroupBtn->setEnabled(on);
730 myGroupLine->setEnabled(on);
734 //=================================================================================
735 // function : (onSelectGeomGroup)
736 // purpose : Called when selection in 3D view or ObjectBrowser is changed
737 //=================================================================================
738 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
741 if (mySelectSubMesh->isChecked()) {
742 mySelectSubMesh->setChecked(false);
744 else if (mySelectGroup->isChecked()) {
745 mySelectGroup->setChecked(false);
747 myCurrentLineEdit = myGeomGroupLine;
751 myGeomGroupLine->setText("");
752 myCurrentLineEdit = 0;
754 setSelectionMode(myTypeId);
756 myGeomGroupBtn->setEnabled(on);
757 myGeomGroupLine->setEnabled(on);
761 //=================================================================================
762 // function : setCurrentSelection()
764 //=================================================================================
765 void SMESHGUI_GroupDlg::setCurrentSelection()
767 QPushButton* send = (QPushButton*)sender();
768 myCurrentLineEdit = 0;
769 if (send == mySubMeshBtn) {
770 myCurrentLineEdit = mySubMeshLine;
771 onObjectSelectionChanged();
773 else if (send == myGroupBtn) {
774 myCurrentLineEdit = myGroupLine;
775 onObjectSelectionChanged();
777 else if (send == myGeomGroupBtn) {
778 myCurrentLineEdit = myGeomGroupLine;
779 onObjectSelectionChanged();
784 //=================================================================================
785 // function : setFilters()
786 // purpose : SLOT. Called when "Filter" button pressed.
787 //=================================================================================
788 void SMESHGUI_GroupDlg::setFilters()
790 SMESH::ElementType aType = SMESH::ALL;
793 case 0 : aType = SMESH::NODE; break;
794 case 1 : aType = SMESH::EDGE; break;
795 case 2 : aType = SMESH::FACE; break;
796 case 3 : aType = SMESH::VOLUME; break;
800 if ( myFilterDlg == 0 )
802 myFilterDlg = new SMESHGUI_FilterDlg( (QWidget*)parent(), aType );
803 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
806 myFilterDlg->Init( aType );
808 myFilterDlg->SetSelection( mySelection );
809 myFilterDlg->SetMesh( myMesh );
810 myFilterDlg->SetSourceWg( myElements );
815 //=================================================================================
816 // function : onFilterAccepted()
817 // purpose : SLOT. Called when Filter dlg closed with OK button.
818 // Uncheck "Select submesh" and "Select group" checkboxes
819 //=================================================================================
820 void SMESHGUI_GroupDlg::onFilterAccepted()
822 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
824 mySelectionMode = myTypeId;
825 mySelectSubMesh->setChecked( false );
826 mySelectGroup->setChecked( false );
830 //=================================================================================
831 // function : onAdd()
833 //=================================================================================
834 void SMESHGUI_GroupDlg::onAdd()
836 int aNbSel = mySelection->IObjectCount();
837 if (aNbSel == 0 || !myActor) return;
841 SMESH::ElementType aType = SMESH::ALL;
843 case 0: aType = SMESH::NODE; break;
844 case 1: aType = SMESH::EDGE; break;
845 case 2: aType = SMESH::FACE; break;
846 case 3: aType = SMESH::VOLUME; break;
849 if (myCurrentLineEdit == 0) {
850 //if (aNbSel != 1) { busy = false; return; }
851 QString aListStr = "";
854 aNbItems = SMESH::GetNameOfSelectedNodes(mySelection, myActor->getIO(), aListStr);
857 aNbItems = SMESH::GetNameOfSelectedElements(mySelection, myActor->getIO(), aListStr);
860 QStringList anElements = QStringList::split(" ", aListStr);
861 QListBoxItem* anItem = 0;
862 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
863 anItem = myElements->findItem(*it, Qt::ExactMatch);
865 anItem = new QListBoxText(*it);
866 myElements->insertItem(anItem);
868 myElements->setSelected(anItem, true);
872 else if (myCurrentLineEdit == mySubMeshLine) {
873 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
874 for (; anIt.More(); anIt.Next()) {
875 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
876 if (!aSubMesh->_is_nil()) {
877 // check if mesh is the same
878 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
880 SMESH::long_array_var anElements = aSubMesh->GetElementsByType ( aType );
881 int k = anElements->length();
882 QListBoxItem* anItem = 0;
883 for (int i = 0; i < k; i++) {
884 QString aText = QString::number(anElements[i]);
885 anItem = myElements->findItem(aText, Qt::ExactMatch);
887 anItem = new QListBoxText(aText);
888 myElements->insertItem(anItem);
890 myElements->setSelected(anItem, true);
893 catch (const SALOME::SALOME_Exception& ex) {
894 QtCatchCorbaException(ex);
899 mySelectSubMesh->setChecked(false);
901 onListSelectionChanged();
903 else if (myCurrentLineEdit == myGroupLine) {
904 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
905 for (; anIt.More(); anIt.Next()) {
906 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
907 if (!aGroup->_is_nil()) {
908 // check if mesh is the same
909 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
910 SMESH::long_array_var anElements = aGroup->GetListOfID();
911 int k = anElements->length();
912 QListBoxItem* anItem = 0;
913 for (int i = 0; i < k; i++) {
914 QString aText = QString::number(anElements[i]);
915 anItem = myElements->findItem(aText, Qt::ExactMatch);
917 anItem = new QListBoxText(aText);
918 myElements->insertItem(anItem);
920 myElements->setSelected(anItem, true);
925 mySelectGroup->setChecked(false);
927 onListSelectionChanged();
929 else if (myCurrentLineEdit == myGeomGroupLine && !CORBA::is_nil(myGeomGroup)) {
931 SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
932 GEOM::GEOM_IGroupOperations_var aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
934 SMESH::ElementType aGroupType = SMESH::ALL;
935 switch(aGroupOp->GetType(myGeomGroup)) {
936 case 7: aGroupType = SMESH::NODE; break;
937 case 6: aGroupType = SMESH::EDGE; break;
938 case 4: aGroupType = SMESH::FACE; break;
939 case 2: aGroupType = SMESH::VOLUME; break;
943 if (aGroupType == aType) {
944 SALOMEDS::SObject_var aGroupSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myGeomGroup) );
946 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
947 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
948 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
949 aBelongToGeom->SetGeom(myGeomGroup);
950 aBelongToGeom->SetShapeName(aGroupSO->GetName());
951 aBelongToGeom->SetElementType(aType);
952 aFilter->SetPredicate( aBelongToGeom );
954 SMESH::long_array_var anElements = aFilter->GetElementsId( myMesh );
956 int k = anElements->length();
957 QListBoxItem* anItem = 0;
958 for (int i = 0; i < k; i++) {
959 QString aText = QString::number(anElements[i]);
960 anItem = myElements->findItem(aText, Qt::ExactMatch);
962 anItem = new QListBoxText(aText);
963 myElements->insertItem(anItem);
965 myElements->setSelected(anItem, true);
969 mySelectGeomGroup->setChecked(false);
971 onListSelectionChanged();
974 // mySelection->ClearIObjects();
978 //=================================================================================
979 // function : onRemove()
981 //=================================================================================
982 void SMESHGUI_GroupDlg::onRemove()
985 if (myCurrentLineEdit == 0) {
986 for (int i = myElements->count(); i > 0; i--) {
987 if (myElements->isSelected(i-1)) {
988 myElements->removeItem(i-1);
993 int aNbSel = mySelection->IObjectCount();
994 if (aNbSel == 0) { busy = false; return; }
996 SMESH::ElementType aType = SMESH::ALL;
998 case 0: aType = SMESH::NODE; break;
999 case 1: aType = SMESH::EDGE; break;
1000 case 2: aType = SMESH::FACE; break;
1001 case 3: aType = SMESH::VOLUME; break;
1004 if (myCurrentLineEdit == mySubMeshLine) {
1005 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1006 for (; anIt.More(); anIt.Next()) {
1007 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1008 if (!aSubMesh->_is_nil()) {
1009 // check if mesh is the same
1010 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1011 if (aType == SMESH::NODE) {
1013 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1014 int k = anElements->length();
1015 QListBoxItem* anItem = 0;
1016 for (int i = 0; i < k; i++) {
1017 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1018 if (anItem) delete anItem;
1021 catch (const SALOME::SALOME_Exception& ex) {
1022 QtCatchCorbaException(ex);
1027 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1028 int k = anElements->length();
1029 QListBoxItem* anItem = 0;
1030 for (int i = 0; i < k; i++) {
1031 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1032 if (anItem) delete anItem;
1035 catch (const SALOME::SALOME_Exception& ex) {
1036 QtCatchCorbaException(ex);
1043 else if (myCurrentLineEdit == myGroupLine) {
1044 Standard_Boolean aRes;
1045 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1046 for (; anIt.More(); anIt.Next()) {
1047 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1048 if (aRes && !aGroup->_is_nil()) {
1049 // check if mesh is the same
1050 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1051 SMESH::long_array_var anElements = aGroup->GetListOfID();
1052 int k = anElements->length();
1053 QListBoxItem* anItem = 0;
1054 for (int i = 0; i < k; i++) {
1055 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1056 if (anItem) delete anItem;
1067 //=================================================================================
1068 // function : onSort()
1070 //=================================================================================
1071 void SMESHGUI_GroupDlg::onSort()
1073 // PAL5412: sorts items in ascending by "string" value
1074 // myElements->sort(true);
1075 // myElements->update();
1076 int i, k = myElements->count();
1079 QStringList aSelected;
1080 std::vector<int> anArray(k);
1081 // QMemArray<int> anArray(k);
1082 QListBoxItem* anItem;
1084 for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1085 anArray[i] = anItem->text().toInt();
1086 if (anItem->isSelected())
1087 aSelected.append(anItem->text());
1089 // sort & update list
1090 std::sort(anArray.begin(), anArray.end());
1092 myElements->clear();
1093 for (i = 0; i < k; i++) {
1094 myElements->insertItem(QString::number(anArray[i]));
1096 for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1097 anItem = myElements->findItem(*it, Qt::ExactMatch);
1098 if (anItem) myElements->setSelected(anItem, true);
1104 //=================================================================================
1105 // function : closeEvent()
1107 //=================================================================================
1108 void SMESHGUI_GroupDlg::closeEvent( QCloseEvent* e )
1113 //=======================================================================
1114 // name : SMESHGUI_GroupDlg::onClose
1115 // Purpose : SLOT called when "Close" button pressed. Close dialog
1116 //=======================================================================
1117 void SMESHGUI_GroupDlg::onClose()
1119 QAD_StudyFrame* aStudyFrame = mySMESHGUI->GetActiveStudy()->getActiveStudyFrame();
1120 if (aStudyFrame->getTypeView() == VIEW_VTK) {
1121 SMESH::SetPointRepresentation(false);
1122 SMESH::SetPickable();
1124 // remove filters from viewer
1125 if(VTKViewer_InteractorStyleSALOME* aStyle = SMESH::GetInteractorStyle()){
1126 SMESH::RemoveFilter(SMESHGUI_EdgeFilter,aStyle);
1127 SMESH::RemoveFilter(SMESHGUI_FaceFilter,aStyle);
1131 mySelection->ClearIObjects();
1132 QAD_Application::getDesktop()->SetSelectionMode(ActorSelection);
1133 mySelection->ClearFilters();
1134 mySMESHGUI->ResetState();
1139 //=======================================================================
1140 // name : SMESHGUI_GroupDlg::onDeactivate
1141 // Purpose : SLOT called when dialog must be deativated
1142 //=======================================================================
1143 void SMESHGUI_GroupDlg::onDeactivate()
1145 setEnabled( false );
1148 //=======================================================================
1149 // name : SMESHGUI_GroupDlg::enterEvent
1150 // Purpose : Event filter
1151 //=======================================================================
1152 void SMESHGUI_GroupDlg::enterEvent( QEvent* )
1154 if ( !isEnabled() ) {
1155 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1157 mySelectionMode = -1;
1158 setSelectionMode( myTypeId );
1162 //=======================================================================
1163 //function : hideEvent
1164 //purpose : caused by ESC key
1165 //=======================================================================
1167 void SMESHGUI_GroupDlg::hideEvent ( QHideEvent * e )
1169 if ( !isMinimized() )