1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GroupGUI_GroupDlg.cxx
24 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26 #include "GroupGUI_GroupDlg.h"
30 #include <GeometryGUI.h>
31 #include <GEOM_Displayer.h>
33 #include <SalomeApp_Application.h>
34 #include <SalomeApp_Study.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <OCCViewer_ViewModel.h>
39 #include <OCCViewer_ViewManager.h>
40 #include <SVTK_ViewModel.h>
41 #include <SALOME_Prs.h>
42 #include <SALOME_ListIteratorOfListIO.hxx>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_OverrideCursor.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_ViewWindow.h>
49 #include <SUIT_ViewManager.h>
52 #include <QListWidget>
56 #include <AIS_ListOfInteractive.hxx>
57 #include <AIS_ListIteratorOfListOfInteractive.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <TopTools_IndexedMapOfShape.hxx>
62 #include <TColStd_IndexedMapOfInteger.hxx>
63 #include <TColStd_MapOfInteger.hxx>
64 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
66 #include <GEOMImpl_Types.hxx>
68 enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2, SUBSHAPES_OF_INVISIBLE_SHAPE2 };
70 GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
71 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
76 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
78 QPixmap image0 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
79 QPixmap image1 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
80 QPixmap image2 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
81 QPixmap image3 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
82 QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
84 setWindowTitle(myMode == CreateGroup ? tr("CREATE_GROUP_TITLE") : tr("EDIT_GROUP_TITLE"));
86 // Shape type button group
87 mainFrame()->GroupConstructors->setEnabled(myMode == CreateGroup);
88 mainFrame()->GroupConstructors->setTitle(tr("SHAPE_TYPE"));
89 mainFrame()->RadioButton1->setIcon(image0);
90 mainFrame()->RadioButton2->setIcon(image1);
91 mainFrame()->RadioButton3->setIcon(image2);
92 mainFrame()->RadioButton4->setIcon(image3);
93 mainFrame()->RadioButton4->show();
96 mainFrame()->GroupBoxName->setTitle(tr("GROUP_NAME"));
98 // Main shape and sub-shapes
99 QGroupBox* GroupMedium = new QGroupBox(tr("MAIN_SUB_SHAPES"), centralWidget());
100 QGridLayout* aMedLayout = new QGridLayout(GroupMedium);
101 aMedLayout->setMargin(9);
102 aMedLayout->setSpacing(6);
104 QLabel* aMainLabel = new QLabel(tr("MAIN_SHAPE"), GroupMedium);
106 mySelBtn = new QPushButton(GroupMedium);
107 mySelBtn->setIcon(iconSelect);
108 mySelBtn->setEnabled(myMode == CreateGroup);
110 myMainName = new QLineEdit(GroupMedium);
111 myMainName->setReadOnly(true);
112 myMainName->setEnabled(myMode == CreateGroup);
114 QLabel* aSecondLabel = new QLabel(tr("SECOND_SHAPE"), GroupMedium);
116 mySelBtn2 = new QPushButton(GroupMedium);
117 mySelBtn2->setIcon(iconSelect);
118 mySelBtn2->setEnabled(false);
120 myShape2Name = new QLineEdit(GroupMedium);
121 myShape2Name->setReadOnly(true);
122 myShape2Name->setEnabled(false);
124 myRestrictGroupBox = new QGroupBox(tr("SHAPE_SEL_RESTR"), GroupMedium);
125 myRestrictGroup = new QButtonGroup(myRestrictGroupBox);
126 QRadioButton* allSubs = new QRadioButton(tr("NO_RESTR") , myRestrictGroupBox);
127 QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"), myRestrictGroupBox);
128 QRadioButton* shape2Subs = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") , myRestrictGroupBox);
129 QVBoxLayout* aRestrictLayout = new QVBoxLayout(myRestrictGroupBox);
130 aRestrictLayout->setMargin(9);
131 aRestrictLayout->setSpacing(6);
132 aRestrictLayout->addWidget(allSubs);
133 aRestrictLayout->addWidget(inPlaceSubs);
134 aRestrictLayout->addWidget(shape2Subs);
135 myRestrictGroup->addButton(allSubs, ALL_SUBSHAPES);
136 myRestrictGroup->addButton(inPlaceSubs, GET_IN_PLACE);
137 myRestrictGroup->addButton(shape2Subs, SUBSHAPES_OF_SHAPE2);
138 allSubs->setChecked(true);
140 myShowOnlyBtn = new QPushButton(tr("Show only selected"), GroupMedium);
141 myHideSelBtn = new QPushButton(tr("Hide selected"), GroupMedium);
142 myShowAllBtn = new QPushButton(tr("Show all sub-shapes"), GroupMedium);
144 mySelAllBtn = new QPushButton(tr("SELECT_ALL"), GroupMedium);
145 myAddBtn = new QPushButton(tr("ADD"), GroupMedium);
146 myRemBtn = new QPushButton(tr("REMOVE"), GroupMedium);
148 myIdList = new QListWidget(GroupMedium);
150 myIdList->setSelectionMode(QAbstractItemView::ExtendedSelection);
151 myIdList->setFlow(QListView::TopToBottom);
152 myIdList->setWrapping(true);
154 aMedLayout->addWidget(aMainLabel, 0, 0);
155 aMedLayout->addWidget(mySelBtn, 0, 1);
156 aMedLayout->addWidget(myMainName, 0, 2, 1, 2);
157 aMedLayout->addWidget(aSecondLabel, 1, 0);
158 aMedLayout->addWidget(mySelBtn2, 1, 1);
159 aMedLayout->addWidget(myShape2Name, 1, 2, 1, 2);
160 aMedLayout->addWidget(myRestrictGroupBox, 2, 0, 3, 3);
162 aMedLayout->addWidget(myShowOnlyBtn, 2, 3);
163 aMedLayout->addWidget(myHideSelBtn, 3, 3);
164 aMedLayout->addWidget(myShowAllBtn, 4, 3);
166 aMedLayout->addWidget(mySelAllBtn, 5, 3);
167 aMedLayout->addWidget(myAddBtn, 6, 3);
168 aMedLayout->addWidget(myRemBtn, 7, 3);
170 aMedLayout->addWidget(myIdList, 5, 0, 3, 3);
171 aMedLayout->setRowStretch(5, 1);
173 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
174 layout->setMargin(0); layout->setSpacing(6);
175 layout->addWidget(GroupMedium);
177 setHelpFileName("work_with_groups_page.html");
182 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
186 //=================================================================================
189 //=================================================================================
190 void GroupGUI_GroupDlg::Init()
192 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
194 //unset shape type to avoid preparation of selection before exact user shape type selection
195 unsetConstructorId();
196 myIsShapeType = false;
198 if (myMode == CreateGroup) {
199 initName(tr("GROUP_PREFIX"));
201 // Get ready for main shape selection
202 myEditCurrentArgument = myMainName;
204 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
205 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
206 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
208 else if (myMode == EditGroup) {
209 SALOME_ListIO aSelList;
210 aSelMgr->selectedObjects(aSelList);
212 if (aSelList.Extent()) {
213 Standard_Boolean aResult = Standard_False;
214 GEOM::GEOM_Object_var anObj =
215 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
217 if (aResult && !CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
220 mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
222 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
223 myMainObj = anOper->GetMainShape(myGroup);
224 if (!CORBA::is_nil(myMainObj))
225 myMainName->setText(GEOMBase::GetName(myMainObj));
227 setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
229 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
230 for (int i = 0, n = aCurrList->length(); i < n; i++)
231 myIdList->addItem(new QListWidgetItem(QString("%1").arg(aCurrList[i])));
233 myEditCurrentArgument = 0;
235 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
239 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
241 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
242 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
244 connect(myRestrictGroup, SIGNAL(buttonClicked(int)), this, SLOT(SetEditCurrentArgument()));
245 connect(mySelAllBtn, SIGNAL(clicked()), this, SLOT(selectAllSubShapes()));
246 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(add()));
247 connect(myRemBtn, SIGNAL(clicked()), this, SLOT(remove()));
248 connect(myShowOnlyBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
249 connect(myHideSelBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
250 connect(myShowAllBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
251 connect(myIdList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
253 setInPlaceObj(GEOM::GEOM_Object::_nil());
255 myBusy = true; // just activate but do not select in the list
260 //=================================================================================
261 // function : enterEvent()
263 //=================================================================================
264 void GroupGUI_GroupDlg::enterEvent(QEvent* e)
266 if (!buttonCancel()->isEnabled())
267 ActivateThisDialog();
270 //=================================================================================
271 //function : closeEvent
272 //purpose : remove temporary geom object
273 //=================================================================================
274 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
276 setInPlaceObj(GEOM::GEOM_Object::_nil());
279 GEOMBase_Skeleton::closeEvent(e);
282 //=================================================================================
283 // function : ClickOnOk()
285 //=================================================================================
286 void GroupGUI_GroupDlg::ClickOnOk()
292 //=================================================================================
293 // function : ClickOnApply()
295 //=================================================================================
296 bool GroupGUI_GroupDlg::ClickOnApply()
298 if (!onAccept(myMode == CreateGroup, true))
301 if (myMode == CreateGroup)
305 ConstructorsClicked(getConstructorId());
313 //=================================================================================
314 // function : ActivateThisDialog()
316 //=================================================================================
317 void GroupGUI_GroupDlg::ActivateThisDialog()
319 GEOMBase_Skeleton::ActivateThisDialog();
321 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
322 this, SLOT(SelectionIntoArgument()));
327 //=================================================================================
328 // function : SetEditCurrentArgument()
330 //=================================================================================
331 void GroupGUI_GroupDlg::SetEditCurrentArgument()
333 QPushButton* send = (QPushButton*)sender();
335 if (send == mySelBtn) {
336 myEditCurrentArgument = myMainName;
337 myShape2Name->setText("");
339 else if (send == mySelBtn2 || sender() == myRestrictGroup) {
340 setInPlaceObj(GEOM::GEOM_Object::_nil());
341 myShape2Name->setText("");
342 if (subSelectionWay() != ALL_SUBSHAPES) {
343 myEditCurrentArgument = myShape2Name;
346 myEditCurrentArgument = 0;
355 //=================================================================================
356 // function : onGetInPlace()
358 //=================================================================================
359 void GroupGUI_GroupDlg::onGetInPlace()
361 setInPlaceObj(GEOM::GEOM_Object::_nil());
362 myEditCurrentArgument->setText("");
364 bool isBlocked = myIdList->signalsBlocked();
365 myIdList->blockSignals(true);
366 myIdList->clearSelection();
367 myIdList->blockSignals(isBlocked);
369 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
370 SALOME_ListIO aSelList;
371 aSelMgr->selectedObjects(aSelList);
373 if (aSelList.Extent() != 1)
376 Standard_Boolean aResult = Standard_False;
377 GEOM::GEOM_Object_var anObj =
378 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
379 if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
380 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
381 SUIT_OverrideCursor wc;
382 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
383 GEOM::GEOM_IShapesOperations_var aShapesOp =
384 getGeomEngine()->GetIShapesOperations(getStudyId());
385 if (subSelectionWay() == GET_IN_PLACE) {
386 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
387 setInPlaceObj(aGetInPlaceObj);
390 bool isVisible = true;
391 if (SALOME_View* view = GEOM_Displayer::GetActiveView())
392 isVisible = view->isVisible(aSelList.First());
393 setInPlaceObj(anObj, isVisible);
395 myEditCurrentArgument = 0;
396 //myBusy = true; // just activate but do not select in the list
403 //=================================================================================
404 //function : setInPlaceObj
405 //purpose : temporarily add an object to study and remove old InPlaceObj
406 //=================================================================================
407 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
409 if (!myInPlaceObj->_is_equivalent(theObj))
411 myInPlaceObj = theObj;
414 // build map of indices
415 myMain2InPlaceIndices.Clear();
416 if (!myInPlaceObj->_is_nil()) {
417 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
418 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
420 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
421 for (int i = 0; i < aSubObjects->length(); i++)
423 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSubObjects[i]);
424 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
425 if (aMainIndex >= 0 && aPlaceIndex > 0)
426 myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
429 myInPlaceObjSelectState = subSelectionWay();
430 if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
431 myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
434 //=================================================================================
435 // function : SelectionIntoArgument()
436 // purpose : Called when selection has changed
437 //=================================================================================
438 void GroupGUI_GroupDlg::SelectionIntoArgument()
440 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
445 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
446 myEditCurrentArgument->setText("");
449 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
450 SALOME_ListIO aSelList;
451 aSelMgr->selectedObjects(aSelList);
452 int nbSel = aSelList.Extent();
455 Standard_Boolean aResult = Standard_False;
456 GEOM::GEOM_Object_var anObj =
457 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
459 if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
461 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
462 // activate subshapes selection by default
463 myEditCurrentArgument = 0;
469 myMainObj = GEOM::GEOM_Object::_nil();
472 else { // an attempt to synchronize list box selection with 3d viewer
477 bool isBlocked = myIdList->signalsBlocked();
478 myIdList->blockSignals(true);
479 myIdList->clearSelection();
481 TColStd_IndexedMapOfInteger aMapIndex;
482 int nbSel = getSelectedSubshapes(aMapIndex);
486 for (int i = 0, n = myIdList->count(); i < n; i++)
487 aMap.insert(myIdList->item(i)->text().toInt(), i);
489 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
490 if (aMap.contains(aMapIndex(ii)))
491 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
494 myIdList->blockSignals(isBlocked);
500 //=================================================================================
501 // function : ConstructorsClicked()
502 // purpose : Radio button management
503 //=================================================================================
504 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
506 if (getConstructorId() != constructorId)
507 setConstructorId(constructorId);
509 myIsShapeType = true;
511 myEditCurrentArgument = 0;
513 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
518 //=================================================================================
519 // function : selectAllSubShapes
521 //=================================================================================
522 void GroupGUI_GroupDlg::selectAllSubShapes()
524 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
527 GEOM::ListOfLong_var aSubShapes;
528 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
529 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
530 if (aSubShapes->length() > 0) {
531 if (subSelectionWay() == ALL_SUBSHAPES)
533 myIdList->clear(); // for sorted final list?
535 if (!aShOp->IsDone())
540 aSubShapes = new GEOM::ListOfLong();
541 aSubShapes->length(myMain2InPlaceIndices.Extent());
542 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
543 for (int i = 0; m2ip.More(); i++, m2ip.Next())
544 aSubShapes[i] = m2ip.Key();
547 bool isBlocked = myIdList->signalsBlocked();
548 myIdList->blockSignals(true);
550 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
551 CORBA::Long anIndex = aSubShapes[i];
555 QListWidgetItem* anItem = 0;
556 QString text = QString("%1").arg(anIndex);
557 if (!myInPlaceObj->_is_nil()) {
558 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
559 if (found.count()) anItem = found[0];
562 anItem = new QListWidgetItem(text);
563 myIdList->addItem(anItem);
565 anItem->setSelected(true);
568 myIdList->blockSignals(isBlocked);
569 highlightSubShapes();
573 //=================================================================================
574 // function : showOnlySelected
576 //=================================================================================
577 void GroupGUI_GroupDlg::showOnlySelected()
579 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
582 QPushButton* send = (QPushButton*)sender();
583 if (send == myShowAllBtn) {
588 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
589 SALOME_ListIO aSelList;
590 aSelMgr->selectedObjects(aSelList);
592 GEOM_Displayer* aDisplayer = getDisplayer();
594 if (send == myHideSelBtn) {
595 aDisplayer->Erase(aSelList, false, true);
598 aDisplayer->EraseAll();
599 aDisplayer->Display(aSelList, true);
603 //=================================================================================
604 // function : getSelectedSubshapes
606 //=================================================================================
607 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
611 SalomeApp_Application* app = myGeomGUI->getApp();
614 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
615 SALOME_ListIO aSelList;
616 aSelMgr->selectedObjects(aSelList);
618 // try to find out and process the global selection
619 // (of not published objects and of published sub-shapes)
621 SALOME_ListIteratorOfListIO anIter (aSelList);
622 for (int i = 0; anIter.More(); anIter.Next(), i++)
624 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
625 QString anEntry = anIObj->getEntry();
627 int index = anEntry.lastIndexOf(str);
628 if (index > 0) // selection among special preview
630 anEntry.remove(0, index+1);
631 int anIndex = anEntry.toInt();
633 theMapIndex.Add(anIndex);
635 else // selection among published shapes
637 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
638 if (!appStudy) return 0;
639 _PTR(Study) aStudy = appStudy->studyDS();
641 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
642 GEOM::GEOM_Object_var aGeomObj =
643 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
645 if (GEOMBase::GetShape(aGeomObj, aShape)) {
646 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
647 TopTools_IndexedMapOfShape aMainMap;
648 TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
649 TopExp::MapShapes(aMainShape, aMainMap);
651 TopExp_Explorer anExp (aShape, getShapeType());
652 for (; anExp.More(); anExp.Next()) {
653 TopoDS_Shape aSubShape = anExp.Current();
654 int anIndex = aMainMap.FindIndex(aSubShape);
656 if (subSelectionWay() != ALL_SUBSHAPES &&
657 !myMain2InPlaceIndices.IsBound(anIndex))
659 theMapIndex.Add(anIndex);
668 return theMapIndex.Extent();
671 //=================================================================================
674 //=================================================================================
675 void GroupGUI_GroupDlg::add()
677 TColStd_IndexedMapOfInteger aMapIndex;
678 int nbSel = getSelectedSubshapes(aMapIndex);
680 TColStd_MapOfInteger aMap;
681 for (int i = 0, n = myIdList->count(); i < n; i++)
682 aMap.Add(myIdList->item(i)->text().toInt());
685 bool isBlocked = myIdList->signalsBlocked();
686 myIdList->blockSignals(true);
688 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
689 if (aMap.Contains(aMapIndex(i)))
692 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
693 myIdList->addItem(anItem);
694 anItem->setSelected(true);
697 myIdList->blockSignals(isBlocked);
703 //=================================================================================
706 //=================================================================================
707 void GroupGUI_GroupDlg::remove()
709 bool isBlocked = myIdList->signalsBlocked();
710 myIdList->blockSignals(true);
712 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
716 myIdList->blockSignals(isBlocked);
718 highlightSubShapes();
721 //=================================================================================
722 //function : subSelectionWay
724 //=================================================================================
725 int GroupGUI_GroupDlg::subSelectionWay() const
727 return myRestrictGroup->checkedId();
730 //=================================================================================
731 // function : getShapeType()
733 //=================================================================================
734 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
736 switch (getConstructorId()) {
737 case 0: return TopAbs_VERTEX;
738 case 1: return TopAbs_EDGE;
739 case 2: return TopAbs_FACE;
740 case 3: return TopAbs_SOLID;
741 default: return TopAbs_SHAPE;
745 //=================================================================================
746 // function : setShapeType()
748 //=================================================================================
749 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
753 case TopAbs_VERTEX: anId = 0; break;
754 case TopAbs_EDGE: anId = 1; break;
755 case TopAbs_FACE: anId = 2; break;
756 case TopAbs_SOLID: anId = 3; break;
758 setConstructorId(anId);
761 myIsShapeType = true;
762 // workaround to avoid set checked button 0
763 setConstructorId(anId);
767 //=================================================================================
768 // function : activateSelection
769 // purpose : Activate selection in accordance with myEditCurrentArgument
770 //=================================================================================
771 void GroupGUI_GroupDlg::activateSelection()
776 if (!myMainObj->_is_nil() &&
777 !myEditCurrentArgument &&
778 myIsShapeType) // check if shape type is already choosen by user
780 GEOM_Displayer* aDisplayer = getDisplayer();
782 SUIT_ViewWindow* aViewWindow = 0;
783 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
785 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
786 if (aViewWindow == 0) return;
788 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
789 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
790 aViewManager->getType() != SVTK_Viewer::Type())
793 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
794 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
795 if (aView == 0) return;
797 TopoDS_Shape aMainShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
798 TopoDS_Shape aRestrictionShape;
799 if (subSelectionWay() == ALL_SUBSHAPES)
800 aRestrictionShape = aMainShape;
801 else if (!myInPlaceObj->_is_nil())
802 aRestrictionShape = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), myInPlaceObj);
805 TopTools_IndexedMapOfShape aSubShapesMap;
806 TopExp::MapShapes(aMainShape, aSubShapesMap);
807 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
808 QString anEntryBase = aMainEntry.in();
810 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
811 for (; anExp.More(); anExp.Next())
813 TopoDS_Shape aSubShape = anExp.Current();
814 int index = aSubShapesMap.FindIndex(aSubShape);
815 QString anEntry = anEntryBase + QString("_%1").arg(index);
817 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
819 displayPreview(aPrs, true, false); // append, do not update
822 aDisplayer->UpdateViewer();
825 globalSelection(GEOM_ALLSHAPES);
827 SelectionIntoArgument();
830 //=================================================================================
831 // function : updateState
833 //=================================================================================
834 void GroupGUI_GroupDlg::updateState (bool isAdd)
836 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
837 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
839 bool hasSel = myIdList->selectedItems().count() > 0;
841 myRemBtn->setEnabled(hasSel);
842 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
843 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
845 mySelBtn2->setEnabled( subSelectionWay() != ALL_SUBSHAPES);
846 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
847 if (subSelectionWay() == ALL_SUBSHAPES)
848 setInPlaceObj(GEOM::GEOM_Object::_nil());
851 //=================================================================================
852 // function : selectionChanged
854 //=================================================================================
855 void GroupGUI_GroupDlg::selectionChanged()
857 highlightSubShapes();
860 //=================================================================================
861 // function : highlightSubShapes
863 //=================================================================================
864 void GroupGUI_GroupDlg::highlightSubShapes()
866 if (CORBA::is_nil(myMainObj))
869 TColStd_MapOfInteger anIds;
873 int ii = 0, nn = myIdList->count();
874 for (; ii < nn; ii++)
876 if (myIdList->item(ii)->isSelected()) {
877 int id = myIdList->item(ii)->text().toInt();
878 if (subSelectionWay() != ALL_SUBSHAPES &&
879 !myMain2InPlaceIndices.IsBound(id)) {
880 myIdList->item(ii)->setSelected(false);
887 SalomeApp_Application* app = myGeomGUI->getApp();
888 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
889 aSelMgr->clearSelected();
891 SUIT_ViewWindow* aViewWindow = 0;
892 SUIT_Study* activeStudy = app->activeStudy();
894 aViewWindow = app->desktop()->activeWindow();
895 if (aViewWindow == 0) return;
897 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
898 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
899 aViewManager->getType() != SVTK_Viewer::Type())
902 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
903 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
904 if (aView == 0) return;
906 // TODO: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
908 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
909 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
910 AIS_ListOfInteractive List;
911 ic->DisplayedObjects(List);
913 SALOME_ListIO aSelList;
915 AIS_ListIteratorOfListOfInteractive ite (List);
916 for (; ite.More(); ite.Next()) {
917 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
918 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
920 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
921 QString anEntry = anIO->getEntry();
922 int index = anEntry.lastIndexOf("_");
923 anEntry.remove(0, index+1);
924 int anIndex = anEntry.toInt();
925 if (anIds.Contains(anIndex))
926 aSelList.Append(anIO);
930 aSelMgr->setSelectedObjects(aSelList);
935 updateState(aSelList.Extent() > 0);
937 myAddBtn->setEnabled(true);
938 myAddBtn->setEnabled(true);
939 myRemBtn->setEnabled(true);
943 //=================================================================================
944 // function : createOperation
946 //=================================================================================
947 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
949 return getGeomEngine()->GetIGroupOperations(getStudyId());
952 #define RETURN_WITH_MSG(a, b) \
958 //=================================================================================
959 // function : isValid()
960 // purpose : Verify validity of input data
961 //=================================================================================
962 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
964 SalomeApp_Study* study = getStudy();
966 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
968 if (myMode == CreateGroup) {
969 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
972 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
975 QString aName (getNewObjectName());
976 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
978 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
982 //=================================================================================
983 // function : execute
985 //=================================================================================
986 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
988 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
990 GEOM::GEOM_Object_var aGroup;
991 if (myMode == CreateGroup)
992 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
993 else if (myMode == EditGroup)
996 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
999 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1000 if (!anOper->IsDone())
1003 if (aCurrList->length() > 0)
1005 anOper->DifferenceIDs(aGroup, aCurrList);
1006 if (!anOper->IsDone())
1010 int ii, nn = myIdList->count();
1013 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1014 aNewList->length(nn);
1015 for (ii = 0; ii < nn; ii++) {
1016 aNewList[ii] = myIdList->item(ii)->text().toInt();
1018 anOper->UnionIDs(aGroup, aNewList);
1019 if (!anOper->IsDone())
1023 SalomeApp_Study* study = getStudy();
1025 char* objIOR = GEOMBase::GetIORFromObject(aGroup);
1026 std::string IOR(objIOR);
1029 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(IOR));
1031 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1032 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1037 objects.push_back(aGroup._retn());
1042 //================================================================
1043 // Function : getFather
1044 // Purpose : Get father object for object to be added in study
1045 // ( called with addInStudy method )
1046 //================================================================
1047 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1049 GEOM::GEOM_Object_var aFatherObj;
1050 if (theObj->GetType() == GEOM_GROUP) {
1051 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1052 aFatherObj = anOper->GetMainShape(theObj);
1054 return aFatherObj._retn();