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)
501 if (mySelectionMode != theMode) {
502 mySelection->ClearIObjects();
503 mySelection->ClearFilters();
504 SMESH::SetPointRepresentation(false);
509 myActor->SetPointRepresentation(true);
511 SMESH::SetPointRepresentation(true);
512 QAD_Application::getDesktop()->SetSelectionMode(NodeSelection, true);
515 QAD_Application::getDesktop()->SetSelectionMode(EdgeSelection, true);
518 QAD_Application::getDesktop()->SetSelectionMode(FaceSelection, true);
521 QAD_Application::getDesktop()->SetSelectionMode(VolumeSelection, true);
525 QAD_Application::getDesktop()->SetSelectionMode(ActorSelection, true);
527 mySelection->AddFilter(mySubMeshFilter);
528 else if (theMode == 5)
529 mySelection->AddFilter(myGroupFilter);
530 else if (theMode == 6)
531 mySelection->AddFilter(myMeshFilter);
533 mySelectionMode = theMode;
537 //=================================================================================
538 // function : onApply()
540 //=================================================================================
541 bool SMESHGUI_GroupDlg::onApply()
543 if (mySMESHGUI->ActiveStudyLocked())
546 if ( myGrpTypeId == 0 && !myName->text().stripWhiteSpace().isEmpty() && myElements->count() > 0) {
547 mySelection->ClearIObjects();
548 if (myGroup->_is_nil()) {
549 SMESH::ElementType aType = SMESH::ALL;
551 case 0: aType = SMESH::NODE; break;
552 case 1: aType = SMESH::EDGE; break;
553 case 2: aType = SMESH::FACE; break;
554 case 3: aType = SMESH::VOLUME; break;
556 SMESH::long_array_var anIdList = new SMESH::long_array;
557 int i, k = myElements->count();
559 QListBoxItem* anItem;
560 for (i = 0, anItem = myElements->firstItem(); anItem != 0; i++, anItem = anItem->next()) {
561 anIdList[i] = anItem->text().toInt();
564 myGroup = SMESH::AddGroup(myMesh, aType, myName->text());
565 myGroup->Add(anIdList.inout());
567 /* init for next operation */
570 myGroup = SMESH::SMESH_Group::_nil();
573 myGroup->SetName(myName->text());
575 QValueList<int> aAddList;
576 QValueList<int>::iterator anIt;
577 QListBoxItem* anItem;
579 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
580 int anId = anItem->text().toInt();
581 if ((anIt = myIdList.find(anId)) == myIdList.end())
582 aAddList.append(anId);
584 myIdList.remove(anIt);
586 if (!aAddList.empty()) {
587 SMESH::long_array_var anIdList = new SMESH::long_array;
588 anIdList->length(aAddList.count());
590 for (i = 0, anIt = aAddList.begin(); anIt != aAddList.end(); anIt++, i++)
592 myGroup->Add(anIdList.inout());
594 if (!myIdList.empty()) {
595 SMESH::long_array_var anIdList = new SMESH::long_array;
596 anIdList->length(myIdList.count());
598 for (i = 0, anIt = myIdList.begin(); anIt != myIdList.end(); anIt++, i++)
600 myGroup->Remove(anIdList.inout());
602 /* init for next operation */
604 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next())
605 myIdList.append(anItem->text().toInt());
608 mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
609 SMESH::UpdateView(); // asv: fix of BUG PAL5515
610 mySelection->ClearIObjects();
613 else if (myGrpTypeId == 1 && !myName->text().stripWhiteSpace().isEmpty() && !CORBA::is_nil( myGeomGroup ))
615 SMESH::ElementType aType = SMESH::ALL;
617 case 0: aType = SMESH::NODE; break;
618 case 1: aType = SMESH::EDGE; break;
619 case 2: aType = SMESH::FACE; break;
620 case 3: aType = SMESH::VOLUME; break;
623 SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
624 GEOM::GEOM_IGroupOperations_var aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
626 SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = myMesh->CreateGroupFromGEOM(aType, myName->text(),myGeomGroup);
628 mySMESHGUI->GetActiveStudy()->updateObjBrowser(true);
629 mySelection->ClearIObjects();
630 /* init for next operation */
638 //=================================================================================
641 //=================================================================================
642 void SMESHGUI_GroupDlg::onOK()
648 static bool busy = false;
649 //=================================================================================
650 // function : onListSelectionChanged()
651 // purpose : Called when selection in element list is changed
652 //=================================================================================
653 void SMESHGUI_GroupDlg::onListSelectionChanged()
655 // MESSAGE("SMESHGUI_GroupDlg::onListSelectionChanged(); myActor = " << myActor);
656 if (busy || !myActor) return;
659 if (myCurrentLineEdit == 0) {
660 mySelection->ClearIObjects();
661 TColStd_MapOfInteger aIndexes;
662 QListBoxItem* anItem;
663 for (anItem = myElements->firstItem(); anItem != 0; anItem = anItem->next()) {
664 if (anItem->isSelected()) {
665 int anId = anItem->text().toInt();
669 mySelection->AddOrRemoveIndex(myActor->getIO(), aIndexes, false, false);
670 mySelection->AddIObject(myActor->getIO());
675 //=================================================================================
676 // function : onObjectSelectionChanged()
677 // purpose : Called when selection in 3D view or ObjectBrowser is changed
678 //=================================================================================
679 void SMESHGUI_GroupDlg::onObjectSelectionChanged()
681 if (busy || !isEnabled()) return;
684 int aNbSel = mySelection->IObjectCount();
685 myElements->clearSelection();
687 if (myCurrentLineEdit) {
688 myCurrentLineEdit->setText("") ;
689 QString aString = "";
691 if (myCurrentLineEdit == myMeshGroupLine)
693 mySelectSubMesh->setEnabled(false);
694 mySelectGroup->setEnabled(false);
695 myGroupLine->setText("");
696 mySubMeshLine->setText("");
698 myGeomGroupBtn->setEnabled(false);
699 myGeomGroupLine->setEnabled(false);
700 myGeomGroupLine->setText("");
708 myGroup = SMESH::SMESH_Group::_nil();
709 myMesh = SMESH::SMESH_Mesh::_nil();
713 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
717 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
718 if(myMesh->_is_nil())
720 myGroup = SMESH::SMESH_Group::_nil();
722 myActor = SMESH::FindActorByObject(myMesh);
723 SMESH::SetPickable(myActor);
725 aString = mySelection->firstIObject()->getName();
726 myMeshGroupLine->setText(aString) ;
727 myMeshGroupLine->home( false );
729 mySelectSubMesh->setEnabled(true);
730 mySelectGroup->setEnabled(true);
731 myGeomGroupBtn->setEnabled(true);
732 myGeomGroupLine->setEnabled(true);
737 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(IO);
738 if(aGroup->_is_nil())
741 myCurrentLineEdit = 0;
744 mySelectSubMesh->setEnabled(true);
745 mySelectGroup->setEnabled(true);
746 myGeomGroupBtn->setEnabled(true);
747 myGeomGroupLine->setEnabled(true);
749 myCurrentLineEdit = 0;
759 setSelectionMode(myTypeId);
764 else if (myCurrentLineEdit == myGeomGroupLine)
769 myGeomGroup = GEOM::GEOM_Object::_nil();
774 Standard_Boolean testResult = Standard_False;
775 myGeomGroup = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
777 // Check if the object is a geometry group
778 if(!testResult || CORBA::is_nil( myGeomGroup ))
780 myGeomGroup = GEOM::GEOM_Object::_nil();
784 // Check if group constructed on the same shape as a mesh or on its child
785 SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
786 GEOM::GEOM_IGroupOperations_var anOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
787 // The main shape of the group
788 GEOM::GEOM_Object_var aGroupMainShape;
789 if( myGeomGroup->GetType() == 37 )
790 aGroupMainShape = anOp->GetMainShape( myGeomGroup );
792 aGroupMainShape = GEOM::GEOM_Object::_duplicate(myGeomGroup);
793 SALOMEDS::SObject_var aGroupMainShapeSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(aGroupMainShape) );
795 SALOMEDS::SObject_var aMeshSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myMesh) );
797 SALOMEDS::SObject_var anObj, aRef;
798 bool isRefOrSubShape = false;
799 if ( aMeshSO->FindSubObject( 1, anObj ) && anObj->ReferencedObject( aRef )) {
800 if ( strcmp( aRef->GetID(), aGroupMainShapeSO->GetID() ) == 0 )
801 isRefOrSubShape = true;
804 SALOMEDS::SObject_var aFather = aGroupMainShapeSO->GetFather();
805 SALOMEDS::SComponent_var aComponent = aGroupMainShapeSO->GetFatherComponent();
806 while ( !isRefOrSubShape && strcmp( aFather->GetID(), aComponent->GetID() ) != 0 )
808 if (strcmp( aRef->GetID(), aFather->GetID() ) == 0)
809 isRefOrSubShape = true;
811 aFather = aFather->GetFather();
815 if ( !isRefOrSubShape )
817 myGeomGroup = GEOM::GEOM_Object::_nil();
825 if (myCurrentLineEdit == mySubMeshLine)
826 aString = tr("SMESH_SUBMESH_SELECTED").arg(aNbSel);
827 else if (myCurrentLineEdit == myGroupLine || myCurrentLineEdit == myGeomGroupLine)
828 aString = tr("SMESH_GROUP_SELECTED").arg(aNbSel);
831 aString = mySelection->firstIObject()->getName();
835 myCurrentLineEdit->setText(aString) ;
836 myCurrentLineEdit->home( false );
842 QString aListStr = "";
845 aNbItems = SMESH::GetNameOfSelectedNodes(mySelection, aListStr);
848 aNbItems = SMESH::GetNameOfSelectedElements(mySelection, aListStr);
851 QStringList anElements = QStringList::split(" ", aListStr);
852 QListBoxItem* anItem = 0;
853 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
854 anItem = myElements->findItem(*it, Qt::ExactMatch);
855 if (anItem) myElements->setSelected(anItem, true);
862 if ( !myGroup->_is_nil() )
863 myActor = SMESH::FindActorByObject(myGroup);
865 myActor = SMESH::FindActorByObject(myMesh);
872 //=================================================================================
873 // function : onSelectSubMesh()
874 // purpose : Called when selection in 3D view or ObjectBrowser is changed
875 //=================================================================================
876 void SMESHGUI_GroupDlg::onSelectSubMesh(bool on)
879 if (mySelectGroup->isChecked()) {
880 mySelectGroup->setChecked(false);
882 //VSR: else if (mySelectGeomGroup->isChecked()) {
883 //VSR: mySelectGeomGroup->setChecked(false);
885 myCurrentLineEdit = mySubMeshLine;
889 mySubMeshLine->setText("");
890 myCurrentLineEdit = 0;
892 setSelectionMode(myTypeId);
894 mySubMeshBtn->setEnabled(on);
895 mySubMeshLine->setEnabled(on);
899 //=================================================================================
900 // function : (onSelectGroup)
901 // purpose : Called when selection in 3D view or ObjectBrowser is changed
902 //=================================================================================
903 void SMESHGUI_GroupDlg::onSelectGroup(bool on)
906 if (mySelectSubMesh->isChecked()) {
907 mySelectSubMesh->setChecked(false);
909 myCurrentLineEdit = myGroupLine;
913 myGroupLine->setText("");
914 myCurrentLineEdit = 0;
916 setSelectionMode(myTypeId);
918 myGroupBtn->setEnabled(on);
919 myGroupLine->setEnabled(on);
923 //=================================================================================
924 // function : (onSelectGeomGroup)
925 // purpose : Called when selection in 3D view or ObjectBrowser is changed
926 //=================================================================================
927 void SMESHGUI_GroupDlg::onSelectGeomGroup(bool on)
930 if (mySelectSubMesh->isChecked()) {
931 mySelectSubMesh->setChecked(false);
933 else if (mySelectGroup->isChecked()) {
934 mySelectGroup->setChecked(false);
936 myCurrentLineEdit = myGeomGroupLine;
940 myGeomGroupLine->setText("");
941 myCurrentLineEdit = 0;
943 setSelectionMode(myTypeId);
948 //=================================================================================
949 // function : setCurrentSelection()
951 //=================================================================================
952 void SMESHGUI_GroupDlg::setCurrentSelection()
954 QPushButton* send = (QPushButton*)sender();
955 myCurrentLineEdit = 0;
956 if (send == myMeshGroupBtn) {
957 myCurrentLineEdit = myMeshGroupLine;
962 onObjectSelectionChanged();
964 else if (send == mySubMeshBtn) {
965 myCurrentLineEdit = mySubMeshLine;
966 onObjectSelectionChanged();
968 else if (send == myGroupBtn) {
969 myCurrentLineEdit = myGroupLine;
970 onObjectSelectionChanged();
972 else if (send == myGeomGroupBtn) {
973 myCurrentLineEdit = myGeomGroupLine;
975 onObjectSelectionChanged();
980 //=================================================================================
981 // function : setFilters()
982 // purpose : SLOT. Called when "Filter" button pressed.
983 //=================================================================================
984 void SMESHGUI_GroupDlg::setFilters()
986 SMESH::ElementType aType = SMESH::ALL;
989 case 0 : aType = SMESH::NODE; break;
990 case 1 : aType = SMESH::EDGE; break;
991 case 2 : aType = SMESH::FACE; break;
992 case 3 : aType = SMESH::VOLUME; break;
996 if ( myFilterDlg == 0 )
998 myFilterDlg = new SMESHGUI_FilterDlg( (QWidget*)parent(), aType );
999 connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
1002 myFilterDlg->Init( aType );
1004 myFilterDlg->SetSelection( mySelection );
1005 myFilterDlg->SetMesh( myMesh );
1006 myFilterDlg->SetSourceWg( myElements );
1008 myFilterDlg->show();
1011 //=================================================================================
1012 // function : onFilterAccepted()
1013 // purpose : SLOT. Called when Filter dlg closed with OK button.
1014 // Uncheck "Select submesh" and "Select group" checkboxes
1015 //=================================================================================
1016 void SMESHGUI_GroupDlg::onFilterAccepted()
1018 if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
1020 mySelectionMode = myTypeId;
1021 mySelectSubMesh->setChecked( false );
1022 mySelectGroup->setChecked( false );
1026 //=================================================================================
1027 // function : onAdd()
1029 //=================================================================================
1030 void SMESHGUI_GroupDlg::onAdd()
1032 int aNbSel = mySelection->IObjectCount();
1033 if (aNbSel == 0 || !myActor || myMesh->_is_nil()) return;
1037 SMESH::ElementType aType = SMESH::ALL;
1039 case 0: aType = SMESH::NODE; break;
1040 case 1: aType = SMESH::EDGE; break;
1041 case 2: aType = SMESH::FACE; break;
1042 case 3: aType = SMESH::VOLUME; break;
1045 if (myCurrentLineEdit == 0) {
1046 //if (aNbSel != 1) { busy = false; return; }
1047 QString aListStr = "";
1049 if (myTypeId == 0) {
1050 aNbItems = SMESH::GetNameOfSelectedNodes(mySelection, myActor->getIO(), aListStr);
1053 aNbItems = SMESH::GetNameOfSelectedElements(mySelection, myActor->getIO(), aListStr);
1056 QStringList anElements = QStringList::split(" ", aListStr);
1057 QListBoxItem* anItem = 0;
1058 for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
1059 anItem = myElements->findItem(*it, Qt::ExactMatch);
1061 anItem = new QListBoxText(*it);
1062 myElements->insertItem(anItem);
1064 myElements->setSelected(anItem, true);
1068 else if (myCurrentLineEdit == mySubMeshLine) {
1069 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1070 for (; anIt.More(); anIt.Next()) {
1071 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1072 if (!aSubMesh->_is_nil()) {
1073 // check if mesh is the same
1074 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1076 SMESH::long_array_var anElements = aSubMesh->GetElementsByType ( aType );
1077 int k = anElements->length();
1078 QListBoxItem* anItem = 0;
1079 for (int i = 0; i < k; i++) {
1080 QString aText = QString::number(anElements[i]);
1081 anItem = myElements->findItem(aText, Qt::ExactMatch);
1083 anItem = new QListBoxText(aText);
1084 myElements->insertItem(anItem);
1086 myElements->setSelected(anItem, true);
1089 catch (const SALOME::SALOME_Exception& ex) {
1090 QtCatchCorbaException(ex);
1095 mySelectSubMesh->setChecked(false);
1097 onListSelectionChanged();
1099 else if (myCurrentLineEdit == myGroupLine) {
1100 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1101 for (; anIt.More(); anIt.Next()) {
1102 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1103 if (!aGroup->_is_nil()) {
1104 // check if mesh is the same
1105 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1106 SMESH::long_array_var anElements = aGroup->GetListOfID();
1107 int k = anElements->length();
1108 QListBoxItem* anItem = 0;
1109 for (int i = 0; i < k; i++) {
1110 QString aText = QString::number(anElements[i]);
1111 anItem = myElements->findItem(aText, Qt::ExactMatch);
1113 anItem = new QListBoxText(aText);
1114 myElements->insertItem(anItem);
1116 myElements->setSelected(anItem, true);
1121 mySelectGroup->setChecked(false);
1123 onListSelectionChanged();
1125 else if (myCurrentLineEdit == myGeomGroupLine && !CORBA::is_nil(myGeomGroup)) {
1127 SALOMEDS::Study_var aStudy = SMESH::GetActiveStudyDocument();
1128 GEOM::GEOM_IGroupOperations_var aGroupOp = SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
1130 SMESH::ElementType aGroupType = SMESH::ALL;
1131 switch(aGroupOp->GetType(myGeomGroup)) {
1132 case 7: aGroupType = SMESH::NODE; break;
1133 case 6: aGroupType = SMESH::EDGE; break;
1134 case 4: aGroupType = SMESH::FACE; break;
1135 case 2: aGroupType = SMESH::VOLUME; break;
1139 if (aGroupType == aType) {
1140 SALOMEDS::SObject_var aGroupSO = aStudy->FindObjectIOR( aStudy->ConvertObjectToIOR(myGeomGroup) );
1142 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
1143 SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
1144 SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();;
1145 aBelongToGeom->SetGeom(myGeomGroup);
1146 aBelongToGeom->SetShapeName(aGroupSO->GetName());
1147 aBelongToGeom->SetElementType(aType);
1148 aFilter->SetPredicate( aBelongToGeom );
1150 SMESH::long_array_var anElements = aFilter->GetElementsId( myMesh );
1152 int k = anElements->length();
1153 QListBoxItem* anItem = 0;
1154 for (int i = 0; i < k; i++) {
1155 QString aText = QString::number(anElements[i]);
1156 anItem = myElements->findItem(aText, Qt::ExactMatch);
1158 anItem = new QListBoxText(aText);
1159 myElements->insertItem(anItem);
1161 myElements->setSelected(anItem, true);
1165 //VSR: mySelectGeomGroup->setChecked(false);
1167 onListSelectionChanged();
1170 // mySelection->ClearIObjects();
1174 //=================================================================================
1175 // function : onRemove()
1177 //=================================================================================
1178 void SMESHGUI_GroupDlg::onRemove()
1181 if (myCurrentLineEdit == 0) {
1182 for (int i = myElements->count(); i > 0; i--) {
1183 if (myElements->isSelected(i-1)) {
1184 myElements->removeItem(i-1);
1189 int aNbSel = mySelection->IObjectCount();
1190 if (aNbSel == 0) { busy = false; return; }
1192 SMESH::ElementType aType = SMESH::ALL;
1194 case 0: aType = SMESH::NODE; break;
1195 case 1: aType = SMESH::EDGE; break;
1196 case 2: aType = SMESH::FACE; break;
1197 case 3: aType = SMESH::VOLUME; break;
1200 if (myCurrentLineEdit == mySubMeshLine) {
1201 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1202 for (; anIt.More(); anIt.Next()) {
1203 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
1204 if (!aSubMesh->_is_nil()) {
1205 // check if mesh is the same
1206 if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
1207 if (aType == SMESH::NODE) {
1209 SMESH::long_array_var anElements = aSubMesh->GetNodesId();
1210 int k = anElements->length();
1211 QListBoxItem* anItem = 0;
1212 for (int i = 0; i < k; i++) {
1213 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1214 if (anItem) delete anItem;
1217 catch (const SALOME::SALOME_Exception& ex) {
1218 QtCatchCorbaException(ex);
1223 SMESH::long_array_var anElements = aSubMesh->GetElementsId();
1224 int k = anElements->length();
1225 QListBoxItem* anItem = 0;
1226 for (int i = 0; i < k; i++) {
1227 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1228 if (anItem) delete anItem;
1231 catch (const SALOME::SALOME_Exception& ex) {
1232 QtCatchCorbaException(ex);
1239 else if (myCurrentLineEdit == myGroupLine) {
1240 Standard_Boolean aRes;
1241 SALOME_ListIteratorOfListIO anIt(mySelection->StoredIObjects());
1242 for (; anIt.More(); anIt.Next()) {
1243 SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
1244 if (aRes && !aGroup->_is_nil()) {
1245 // check if mesh is the same
1246 if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
1247 SMESH::long_array_var anElements = aGroup->GetListOfID();
1248 int k = anElements->length();
1249 QListBoxItem* anItem = 0;
1250 for (int i = 0; i < k; i++) {
1251 anItem = myElements->findItem(QString::number(anElements[i]), Qt::ExactMatch);
1252 if (anItem) delete anItem;
1263 //=================================================================================
1264 // function : onSort()
1266 //=================================================================================
1267 void SMESHGUI_GroupDlg::onSort()
1269 // PAL5412: sorts items in ascending by "string" value
1270 // myElements->sort(true);
1271 // myElements->update();
1272 int i, k = myElements->count();
1275 QStringList aSelected;
1276 std::vector<int> anArray(k);
1277 // QMemArray<int> anArray(k);
1278 QListBoxItem* anItem;
1280 for (anItem = myElements->firstItem(), i = 0; anItem != 0; anItem = anItem->next(), i++) {
1281 anArray[i] = anItem->text().toInt();
1282 if (anItem->isSelected())
1283 aSelected.append(anItem->text());
1285 // sort & update list
1286 std::sort(anArray.begin(), anArray.end());
1288 myElements->clear();
1289 for (i = 0; i < k; i++) {
1290 myElements->insertItem(QString::number(anArray[i]));
1292 for (QStringList::iterator it = aSelected.begin(); it != aSelected.end(); ++it) {
1293 anItem = myElements->findItem(*it, Qt::ExactMatch);
1294 if (anItem) myElements->setSelected(anItem, true);
1300 //=================================================================================
1301 // function : closeEvent()
1303 //=================================================================================
1304 void SMESHGUI_GroupDlg::closeEvent( QCloseEvent* e )
1309 //=======================================================================
1310 // name : SMESHGUI_GroupDlg::onClose
1311 // Purpose : SLOT called when "Close" button pressed. Close dialog
1312 //=======================================================================
1313 void SMESHGUI_GroupDlg::onClose()
1315 QAD_StudyFrame* aStudyFrame = mySMESHGUI->GetActiveStudy()->getActiveStudyFrame();
1316 if (aStudyFrame->getTypeView() == VIEW_VTK) {
1317 SMESH::SetPointRepresentation(false);
1318 SMESH::SetPickable();
1320 // remove filters from viewer
1321 if(VTKViewer_InteractorStyleSALOME* aStyle = SMESH::GetInteractorStyle()){
1322 SMESH::RemoveFilter(SMESHGUI_EdgeFilter,aStyle);
1323 SMESH::RemoveFilter(SMESHGUI_FaceFilter,aStyle);
1327 mySelection->ClearIObjects();
1328 QAD_Application::getDesktop()->SetSelectionMode(ActorSelection);
1329 mySelection->ClearFilters();
1330 mySMESHGUI->ResetState();
1335 //=======================================================================
1336 // name : SMESHGUI_GroupDlg::onDeactivate
1337 // Purpose : SLOT called when dialog must be deativated
1338 //=======================================================================
1339 void SMESHGUI_GroupDlg::onDeactivate()
1341 setEnabled( false );
1344 //=======================================================================
1345 // name : SMESHGUI_GroupDlg::enterEvent
1346 // Purpose : Event filter
1347 //=======================================================================
1348 void SMESHGUI_GroupDlg::enterEvent( QEvent* )
1350 if ( !isEnabled() ) {
1351 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
1353 mySelectionMode = -1;
1354 setSelectionMode( myTypeId );
1358 //=======================================================================
1359 //function : hideEvent
1360 //purpose : caused by ESC key
1361 //=======================================================================
1363 void SMESHGUI_GroupDlg::hideEvent ( QHideEvent * e )
1365 if ( !isMinimized() )