1 // Copyright (C) 2007-2011 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GroupGUI_GroupDlg.cxx
25 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
27 #include "GroupGUI_GroupDlg.h"
31 #include <GeometryGUI.h>
32 #include <GEOM_Displayer.h>
34 #include <SalomeApp_Application.h>
35 #include <SalomeApp_Study.h>
37 #include <LightApp_SelectionMgr.h>
39 #include <OCCViewer_ViewModel.h>
40 #include <OCCViewer_ViewManager.h>
41 #include <SVTK_ViewModel.h>
42 #include <SALOME_Prs.h>
43 #include <SALOME_ListIteratorOfListIO.hxx>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_OverrideCursor.h>
48 #include <SUIT_Session.h>
49 #include <SUIT_ViewWindow.h>
50 #include <SUIT_ViewManager.h>
53 #include <QListWidget>
57 #include <AIS_ListOfInteractive.hxx>
58 #include <AIS_ListIteratorOfListOfInteractive.hxx>
61 #include <TopExp_Explorer.hxx>
62 #include <TopTools_IndexedMapOfShape.hxx>
63 #include <TColStd_IndexedMapOfInteger.hxx>
64 #include <TColStd_MapOfInteger.hxx>
65 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
67 #include <GEOMImpl_Types.hxx>
69 enum { ALL_SUBSHAPES = 0, GET_IN_PLACE, SUBSHAPES_OF_SHAPE2, SUBSHAPES_OF_INVISIBLE_SHAPE2 };
71 GroupGUI_GroupDlg::GroupGUI_GroupDlg (Mode mode, GeometryGUI* theGeometryGUI, QWidget* parent)
72 : GEOMBase_Skeleton(theGeometryGUI, parent, false),
77 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
79 QPixmap image0 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX")));
80 QPixmap image1 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_EDGE")));
81 QPixmap image2 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_FACE")));
82 QPixmap image3 (resMgr->loadPixmap("GEOM", tr("ICON_OBJBROWSER_SOLID")));
83 QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
85 setWindowTitle(myMode == CreateGroup ? tr("CREATE_GROUP_TITLE") : tr("EDIT_GROUP_TITLE"));
87 // Shape type button group
88 mainFrame()->GroupConstructors->setEnabled(myMode == CreateGroup);
89 mainFrame()->GroupConstructors->setTitle(tr("SHAPE_TYPE"));
90 mainFrame()->RadioButton1->setIcon(image0);
91 mainFrame()->RadioButton2->setIcon(image1);
92 mainFrame()->RadioButton3->setIcon(image2);
93 mainFrame()->RadioButton4->setIcon(image3);
94 mainFrame()->RadioButton4->show();
97 mainFrame()->GroupBoxName->setTitle(tr("GROUP_NAME"));
99 // Main shape and sub-shapes
100 QGroupBox* GroupMedium = new QGroupBox(tr("MAIN_SUB_SHAPES"), centralWidget());
101 QGridLayout* aMedLayout = new QGridLayout(GroupMedium);
102 aMedLayout->setMargin(9);
103 aMedLayout->setSpacing(6);
105 QLabel* aMainLabel = new QLabel(tr("MAIN_SHAPE"), GroupMedium);
107 mySelBtn = new QPushButton(GroupMedium);
108 mySelBtn->setIcon(iconSelect);
109 mySelBtn->setEnabled(myMode == CreateGroup);
111 myMainName = new QLineEdit(GroupMedium);
112 myMainName->setReadOnly(true);
113 myMainName->setEnabled(myMode == CreateGroup);
115 myRestrictGroupBox = new QGroupBox(tr("SHAPE_SEL_RESTR"), GroupMedium);
116 myRestrictGroup = new QButtonGroup(myRestrictGroupBox);
117 QRadioButton* allSubs = new QRadioButton(tr("NO_RESTR") , myRestrictGroupBox);
118 QRadioButton* inPlaceSubs = new QRadioButton(tr("GEOM_PARTS_OF_SHAPE2"), myRestrictGroupBox);
119 QRadioButton* shape2Subs = new QRadioButton(tr("SUBSHAPES_OF_SHAPE2") , myRestrictGroupBox);
120 QGridLayout* aRestrictLayout = new QGridLayout(myRestrictGroupBox);
122 QLabel* aSecondLabel = new QLabel(tr("SECOND_SHAPE"), myRestrictGroupBox);
123 mySelBtn2 = new QPushButton(myRestrictGroupBox);
124 mySelBtn2->setIcon(iconSelect);
125 mySelBtn2->setEnabled(false);
126 myShape2Name = new QLineEdit(myRestrictGroupBox);
127 myShape2Name->setReadOnly(true);
128 myShape2Name->setEnabled(false);
130 aRestrictLayout->setMargin(9);
131 aRestrictLayout->setSpacing(6);
132 aRestrictLayout->addWidget(allSubs, 0, 0, 1, 3);
133 aRestrictLayout->addWidget(inPlaceSubs, 1, 0, 1, 3);
134 aRestrictLayout->addWidget(shape2Subs, 2, 0, 1, 3);
135 aRestrictLayout->addWidget(aSecondLabel, 3, 0);
136 aRestrictLayout->addWidget(mySelBtn2, 3, 1);
137 aRestrictLayout->addWidget(myShape2Name, 3, 2);
138 myRestrictGroup->addButton(allSubs, ALL_SUBSHAPES);
139 myRestrictGroup->addButton(inPlaceSubs, GET_IN_PLACE);
140 myRestrictGroup->addButton(shape2Subs, SUBSHAPES_OF_SHAPE2);
141 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
142 allSubs->setChecked(true);
144 myShowOnlyBtn = new QPushButton(tr("SHOW_ONLY_SELECTED"), GroupMedium);
145 myHideSelBtn = new QPushButton(tr("HIDE_SELECTED"), GroupMedium);
146 myShowAllBtn = new QPushButton(tr("SHOW_ALL_SUB_SHAPES"), GroupMedium);
148 mySelAllBtn = new QPushButton(tr("SELECT_ALL"), GroupMedium);
149 myAddBtn = new QPushButton(tr("ADD"), GroupMedium);
150 myRemBtn = new QPushButton(tr("REMOVE"), GroupMedium);
152 myIdList = new QListWidget(GroupMedium);
154 myIdList->setSelectionMode(QAbstractItemView::ExtendedSelection);
155 myIdList->setFlow(QListView::TopToBottom);
156 myIdList->setWrapping(true);
158 aMedLayout->addWidget(aMainLabel, 0, 0);
159 aMedLayout->addWidget(mySelBtn, 0, 1);
160 aMedLayout->addWidget(myMainName, 0, 2, 1, 2);
161 aMedLayout->addWidget(myRestrictGroupBox, 1, 0, 4, 3);
163 aMedLayout->addWidget(myShowOnlyBtn, 1, 3);
164 aMedLayout->addWidget(myHideSelBtn, 2, 3);
165 aMedLayout->addWidget(myShowAllBtn, 3, 3);
167 aMedLayout->addWidget(myIdList, 5, 0, 4, 3);
168 aMedLayout->addWidget(mySelAllBtn, 5, 3);
169 aMedLayout->addWidget(myAddBtn, 6, 3);
170 aMedLayout->addWidget(myRemBtn, 7, 3);
172 aMedLayout->setColumnStretch(2, 5);
173 aMedLayout->setRowStretch(5, 5);
174 aMedLayout->setRowStretch(8, 5);
176 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
177 layout->setMargin(0); layout->setSpacing(6);
178 layout->addWidget(GroupMedium);
180 setHelpFileName("work_with_groups_page.html");
185 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
189 //=================================================================================
192 //=================================================================================
193 void GroupGUI_GroupDlg::Init()
195 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
197 //unset shape type to avoid preparation of selection before exact user shape type selection
198 unsetConstructorId();
199 myIsShapeType = false;
201 if (myMode == CreateGroup) {
202 initName(tr("GROUP_PREFIX"));
204 // Get ready for main shape selection
205 myEditCurrentArgument = myMainName;
207 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
208 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
209 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
211 else if (myMode == EditGroup) {
212 SALOME_ListIO aSelList;
213 aSelMgr->selectedObjects(aSelList);
215 if (aSelList.Extent()) {
216 GEOM::GEOM_Object_var anObj =
217 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
219 if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
222 mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
224 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
225 myMainObj = anOper->GetMainShape(myGroup);
226 if (!CORBA::is_nil(myMainObj))
227 myMainName->setText(GEOMBase::GetName(myMainObj));
229 setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
231 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
232 for (int i = 0, n = aCurrList->length(); i < n; i++)
233 myIdList->addItem(new QListWidgetItem(QString("%1").arg(aCurrList[i])));
235 myEditCurrentArgument = 0;
237 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
241 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
243 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
244 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
246 connect(myRestrictGroup, SIGNAL(buttonClicked(int)), this, SLOT(SetEditCurrentArgument()));
247 connect(mySelAllBtn, SIGNAL(clicked()), this, SLOT(selectAllSubShapes()));
248 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(add()));
249 connect(myRemBtn, SIGNAL(clicked()), this, SLOT(remove()));
250 connect(myShowOnlyBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
251 connect(myHideSelBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
252 connect(myShowAllBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
253 connect(myIdList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
255 setInPlaceObj(GEOM::GEOM_Object::_nil());
257 myBusy = true; // just activate but do not select in the list
262 //=================================================================================
263 // function : enterEvent()
265 //=================================================================================
266 void GroupGUI_GroupDlg::enterEvent(QEvent* e)
268 if (!buttonCancel()->isEnabled())
269 ActivateThisDialog();
272 //=================================================================================
273 //function : closeEvent
274 //purpose : remove temporary geom object
275 //=================================================================================
276 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
278 setInPlaceObj(GEOM::GEOM_Object::_nil());
281 GEOMBase_Skeleton::closeEvent(e);
284 //=================================================================================
285 // function : ClickOnOk()
287 //=================================================================================
288 void GroupGUI_GroupDlg::ClickOnOk()
290 setIsApplyAndClose(true);
295 //=================================================================================
296 // function : ClickOnApply()
298 //=================================================================================
299 bool GroupGUI_GroupDlg::ClickOnApply()
301 if (!onAccept(myMode == CreateGroup, true))
304 if (myMode == CreateGroup)
308 ConstructorsClicked(getConstructorId());
316 //=================================================================================
317 // function : ActivateThisDialog()
319 //=================================================================================
320 void GroupGUI_GroupDlg::ActivateThisDialog()
322 GEOMBase_Skeleton::ActivateThisDialog();
324 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
325 this, SLOT(SelectionIntoArgument()));
330 //=================================================================================
331 // function : SetEditCurrentArgument()
333 //=================================================================================
334 void GroupGUI_GroupDlg::SetEditCurrentArgument()
336 QPushButton* send = (QPushButton*)sender();
338 if (send == mySelBtn) {
339 myEditCurrentArgument = myMainName;
340 myShape2Name->setText("");
342 else if (send == mySelBtn2 || sender() == myRestrictGroup) {
343 setInPlaceObj(GEOM::GEOM_Object::_nil());
344 myShape2Name->setText("");
345 if (subSelectionWay() != ALL_SUBSHAPES) {
346 myEditCurrentArgument = myShape2Name;
349 myEditCurrentArgument = 0;
358 //=================================================================================
359 // function : onGetInPlace()
361 //=================================================================================
362 void GroupGUI_GroupDlg::onGetInPlace()
364 setInPlaceObj(GEOM::GEOM_Object::_nil());
365 myEditCurrentArgument->setText("");
367 bool isBlocked = myIdList->signalsBlocked();
368 myIdList->blockSignals(true);
369 myIdList->clearSelection();
370 myIdList->blockSignals(isBlocked);
372 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
373 SALOME_ListIO aSelList;
374 aSelMgr->selectedObjects(aSelList);
376 if (aSelList.Extent() != 1)
379 GEOM::GEOM_Object_var anObj =
380 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
381 if (GEOMBase::IsShape(anObj)) {
382 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
383 SUIT_OverrideCursor wc;
384 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
385 GEOM::GEOM_IShapesOperations_var aShapesOp =
386 getGeomEngine()->GetIShapesOperations(getStudyId());
387 if (subSelectionWay() == GET_IN_PLACE) {
388 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
389 setInPlaceObj(aGetInPlaceObj);
392 bool isVisible = true;
393 if (SALOME_View* view = GEOM_Displayer::GetActiveView())
394 isVisible = view->isVisible(aSelList.First());
395 setInPlaceObj(anObj, isVisible);
397 myEditCurrentArgument = 0;
398 //myBusy = true; // just activate but do not select in the list
405 //=================================================================================
406 //function : setInPlaceObj
407 //purpose : temporarily add an object to study and remove old InPlaceObj
408 //=================================================================================
409 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
411 if (!myInPlaceObj->_is_equivalent(theObj))
413 myInPlaceObj = theObj;
416 // build map of indices
417 myMain2InPlaceIndices.Clear();
418 if (!myInPlaceObj->_is_nil()) {
419 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
420 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
422 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
423 for (int i = 0; i < aSubObjects->length(); i++)
425 GEOM::GEOM_Object_var aSS = aShapesOp->GetSame(myMainObj, aSubObjects[i]);
426 if (!CORBA::is_nil(aSS)) {
427 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSS);
428 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
429 if (aMainIndex >= 0 && aPlaceIndex > 0)
430 myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
434 myInPlaceObjSelectState = subSelectionWay();
435 if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
436 myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
439 //=================================================================================
440 // function : SelectionIntoArgument()
441 // purpose : Called when selection has changed
442 //=================================================================================
443 void GroupGUI_GroupDlg::SelectionIntoArgument()
445 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
450 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
451 myEditCurrentArgument->setText("");
454 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
455 SALOME_ListIO aSelList;
456 aSelMgr->selectedObjects(aSelList);
457 int nbSel = aSelList.Extent();
460 GEOM::GEOM_Object_var anObj =
461 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
463 if (GEOMBase::IsShape(anObj)) {
465 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
466 // activate subshapes selection by default
467 myEditCurrentArgument = 0;
473 myMainObj = GEOM::GEOM_Object::_nil();
476 else { // an attempt to synchronize list box selection with 3d viewer
477 if (myBusy || myMainObj->_is_nil()) {
481 bool isBlocked = myIdList->signalsBlocked();
482 myIdList->blockSignals(true);
483 myIdList->clearSelection();
485 TColStd_IndexedMapOfInteger aMapIndex;
486 int nbSel = getSelectedSubshapes(aMapIndex);
490 for (int i = 0, n = myIdList->count(); i < n; i++)
491 aMap.insert(myIdList->item(i)->text().toInt(), i);
493 bool highlight = false;
494 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
495 if (aMap.contains(aMapIndex(ii))) {
496 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
501 highlightSubShapes();
503 myIdList->blockSignals(isBlocked);
509 //=================================================================================
510 // function : ConstructorsClicked()
511 // purpose : Radio button management
512 //=================================================================================
513 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
515 if (getConstructorId() != constructorId)
516 setConstructorId(constructorId);
518 myIsShapeType = true;
520 myEditCurrentArgument = 0;
522 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
527 //=================================================================================
528 // function : selectAllSubShapes
530 //=================================================================================
531 void GroupGUI_GroupDlg::selectAllSubShapes()
533 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
536 GEOM::ListOfLong_var aSubShapes;
537 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
538 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
539 if (aSubShapes->length() > 0) {
540 if (subSelectionWay() == ALL_SUBSHAPES)
542 myIdList->clear(); // for sorted final list?
544 if (!aShOp->IsDone())
549 aSubShapes = new GEOM::ListOfLong();
550 aSubShapes->length(myMain2InPlaceIndices.Extent());
551 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
552 for (int i = 0; m2ip.More(); i++, m2ip.Next())
553 aSubShapes[i] = m2ip.Key();
556 bool isBlocked = myIdList->signalsBlocked();
557 myIdList->blockSignals(true);
559 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
560 CORBA::Long anIndex = aSubShapes[i];
564 QListWidgetItem* anItem = 0;
565 QString text = QString("%1").arg(anIndex);
566 if (!myInPlaceObj->_is_nil()) {
567 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
568 if (found.count()) anItem = found[0];
571 anItem = new QListWidgetItem(text);
572 myIdList->addItem(anItem);
574 anItem->setSelected(true);
577 myIdList->blockSignals(isBlocked);
578 highlightSubShapes();
582 //=================================================================================
583 // function : showOnlySelected
585 //=================================================================================
586 void GroupGUI_GroupDlg::showOnlySelected()
588 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
591 QPushButton* send = (QPushButton*)sender();
592 if (send == myShowAllBtn) {
597 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
598 SALOME_ListIO aSelList;
599 aSelMgr->selectedObjects(aSelList);
601 GEOM_Displayer* aDisplayer = getDisplayer();
603 if (send == myHideSelBtn) {
604 aDisplayer->Erase(aSelList, false, true);
607 aDisplayer->EraseAll();
608 aDisplayer->Display(aSelList, true);
612 //=================================================================================
613 // function : getSelectedSubshapes
615 //=================================================================================
616 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
620 SalomeApp_Application* app = myGeomGUI->getApp();
621 if (!app || myMainObj->_is_nil())
624 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
625 SALOME_ListIO aSelList;
626 aSelMgr->selectedObjects(aSelList);
628 // try to find out and process the global selection
629 // (of not published objects and of published sub-shapes)
631 SALOME_ListIteratorOfListIO anIter (aSelList);
632 for (int i = 0; anIter.More(); anIter.Next(), i++)
634 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
635 QString anEntry = anIObj->getEntry();
637 int index = anEntry.lastIndexOf(str);
638 if (index > 0) // selection among special preview
640 anEntry.remove(0, index+1);
641 int anIndex = anEntry.toInt();
643 theMapIndex.Add(anIndex);
645 else // selection among published shapes
647 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
648 if (!appStudy) return 0;
649 _PTR(Study) aStudy = appStudy->studyDS();
651 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
652 GEOM::GEOM_Object_var aGeomObj =
653 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
655 if (GEOMBase::GetShape(aGeomObj, aShape)) {
656 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
657 TopTools_IndexedMapOfShape aMainMap;
658 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
659 TopExp::MapShapes(aMainShape, aMainMap);
661 TopExp_Explorer anExp (aShape, getShapeType());
662 for (; anExp.More(); anExp.Next()) {
663 TopoDS_Shape aSubShape = anExp.Current();
664 int anIndex = aMainMap.FindIndex(aSubShape);
666 if (subSelectionWay() != ALL_SUBSHAPES &&
667 !myMain2InPlaceIndices.IsBound(anIndex))
669 theMapIndex.Add(anIndex);
678 return theMapIndex.Extent();
681 //=================================================================================
684 //=================================================================================
685 void GroupGUI_GroupDlg::add()
687 TColStd_IndexedMapOfInteger aMapIndex;
688 int nbSel = getSelectedSubshapes(aMapIndex);
690 TColStd_MapOfInteger aMap;
691 for (int i = 0, n = myIdList->count(); i < n; i++)
692 aMap.Add(myIdList->item(i)->text().toInt());
695 bool isBlocked = myIdList->signalsBlocked();
696 myIdList->blockSignals(true);
698 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
699 if (aMap.Contains(aMapIndex(i)))
702 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
703 myIdList->addItem(anItem);
704 anItem->setSelected(true);
707 myIdList->blockSignals(isBlocked);
713 //=================================================================================
716 //=================================================================================
717 void GroupGUI_GroupDlg::remove()
719 bool isBlocked = myIdList->signalsBlocked();
720 myIdList->blockSignals(true);
722 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
726 myIdList->blockSignals(isBlocked);
728 highlightSubShapes();
731 //=================================================================================
732 //function : subSelectionWay
734 //=================================================================================
735 int GroupGUI_GroupDlg::subSelectionWay() const
737 return myRestrictGroup->checkedId();
740 //=================================================================================
741 // function : getShapeType()
743 //=================================================================================
744 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
746 switch (getConstructorId()) {
747 case 0: return TopAbs_VERTEX;
748 case 1: return TopAbs_EDGE;
749 case 2: return TopAbs_FACE;
750 case 3: return TopAbs_SOLID;
751 default: return TopAbs_SHAPE;
755 //=================================================================================
756 // function : setShapeType()
758 //=================================================================================
759 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
763 case TopAbs_VERTEX: anId = 0; break;
764 case TopAbs_EDGE: anId = 1; break;
765 case TopAbs_FACE: anId = 2; break;
766 case TopAbs_SOLID: anId = 3; break;
768 setConstructorId(anId);
771 myIsShapeType = true;
772 // workaround to avoid set checked button 0
773 setConstructorId(anId);
777 //=================================================================================
778 // function : activateSelection
779 // purpose : Activate selection in accordance with myEditCurrentArgument
780 //=================================================================================
781 void GroupGUI_GroupDlg::activateSelection()
786 if (!myMainObj->_is_nil() &&
787 !myEditCurrentArgument &&
788 myIsShapeType) // check if shape type is already choosen by user
790 GEOM_Displayer* aDisplayer = getDisplayer();
791 aDisplayer->Erase(myMainObj, false, false);
793 int prevDisplayMode = aDisplayer->SetDisplayMode(0);
795 SUIT_ViewWindow* aViewWindow = 0;
796 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
798 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
799 if (aViewWindow == 0) return;
801 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
802 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
803 aViewManager->getType() != SVTK_Viewer::Type())
806 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
807 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
808 if (aView == 0) return;
810 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
811 TopoDS_Shape aRestrictionShape;
813 if (subSelectionWay() == ALL_SUBSHAPES) {
814 aRestrictionShape = aMainShape;
816 TopTools_IndexedMapOfShape aSubShapesMap;
817 TopExp::MapShapes(aMainShape, aSubShapesMap);
818 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
819 QString anEntryBase = aMainEntry.in();
821 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
822 for (; anExp.More(); anExp.Next()) {
823 TopoDS_Shape aSubShape = anExp.Current();
824 int index = aSubShapesMap.FindIndex(aSubShape);
825 QString anEntry = anEntryBase + QString("_%1").arg(index);
827 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
829 displayPreview(aPrs, true, false); // append, do not update
833 else if (!myInPlaceObj->_is_nil()) {
834 TopTools_IndexedMapOfShape aSubShapesMap;
835 TopExp::MapShapes(aMainShape, aSubShapesMap);
836 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
837 QString anEntryBase = aMainEntry.in();
839 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
840 for (; aM2IPit.More(); aM2IPit.Next()) {
841 int index = aM2IPit.Key();
842 TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
843 QString anEntry = anEntryBase + QString("_%1").arg(index);
845 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
847 displayPreview(aPrs, true, false); // append, do not update
853 aDisplayer->UpdateViewer();
854 aDisplayer->SetDisplayMode(prevDisplayMode);
857 globalSelection(GEOM_ALLSHAPES);
859 SelectionIntoArgument();
862 //=================================================================================
863 // function : updateState
865 //=================================================================================
866 void GroupGUI_GroupDlg::updateState (bool isAdd)
868 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
869 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
871 bool hasSel = myIdList->selectedItems().count() > 0;
873 myRemBtn->setEnabled(hasSel);
874 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
875 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
877 mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
878 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
879 if (subSelectionWay() == ALL_SUBSHAPES)
880 setInPlaceObj(GEOM::GEOM_Object::_nil());
883 //=================================================================================
884 // function : selectionChanged
886 //=================================================================================
887 void GroupGUI_GroupDlg::selectionChanged()
889 highlightSubShapes();
892 //=================================================================================
893 // function : highlightSubShapes
895 //=================================================================================
896 void GroupGUI_GroupDlg::highlightSubShapes()
898 if (CORBA::is_nil(myMainObj))
901 TColStd_MapOfInteger anIds;
905 int ii = 0, nn = myIdList->count();
906 for (; ii < nn; ii++)
908 if (myIdList->item(ii)->isSelected()) {
909 int id = myIdList->item(ii)->text().toInt();
910 if (subSelectionWay() != ALL_SUBSHAPES &&
911 !myMain2InPlaceIndices.IsBound(id)) {
912 myIdList->item(ii)->setSelected(false);
919 SalomeApp_Application* app = myGeomGUI->getApp();
920 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
921 aSelMgr->clearSelected();
923 SUIT_ViewWindow* aViewWindow = 0;
924 SUIT_Study* activeStudy = app->activeStudy();
926 aViewWindow = app->desktop()->activeWindow();
927 if (aViewWindow == 0) return;
929 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
930 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
931 aViewManager->getType() != SVTK_Viewer::Type())
934 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
935 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
936 if (aView == 0) return;
938 // TODO: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
940 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
941 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
942 AIS_ListOfInteractive List;
943 ic->DisplayedObjects(List);
945 SALOME_ListIO aSelList;
947 // To highlight the selected subshape in Object Browser, if it's already pudlished under the main shape
948 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
949 QMap<int, QString> childsMap;
950 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
952 _PTR(Study) aStudy = appStudy->studyDS();
953 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
954 QString anEntry = aMainEntry.in();
955 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
956 _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
957 for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
958 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
959 if (!CORBA::is_nil(aChild)) {
960 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
961 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
962 QString anEntry = aChildEntry.in();
963 childsMap.insert(index, anEntry);
968 AIS_ListIteratorOfListOfInteractive ite (List);
969 for (; ite.More(); ite.Next()) {
970 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
971 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
973 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
974 QString anEntry = anIO->getEntry();
975 int index = anEntry.lastIndexOf("_");
976 anEntry.remove(0, index+1);
977 int anIndex = anEntry.toInt();
978 if (anIds.Contains(anIndex)) {
979 aSelList.Append(anIO);
980 if (childsMap.contains (anIndex)) {
981 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
982 aSelList.Append(tmpIO);
988 aSelMgr->setSelectedObjects(aSelList);
993 updateState(aSelList.Extent() > 0);
995 myAddBtn->setEnabled(true);
996 myAddBtn->setEnabled(true);
997 myRemBtn->setEnabled(true);
1001 //=================================================================================
1002 // function : createOperation
1004 //=================================================================================
1005 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1007 return getGeomEngine()->GetIGroupOperations(getStudyId());
1010 #define RETURN_WITH_MSG(a, b) \
1012 theMessage += (b); \
1016 //=================================================================================
1017 // function : isValid()
1018 // purpose : Verify validity of input data
1019 //=================================================================================
1020 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1022 SalomeApp_Study* study = getStudy();
1024 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1026 if (myMode == CreateGroup) {
1027 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1030 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1033 QString aName (getNewObjectName());
1034 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1036 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1040 //=================================================================================
1041 // function : execute
1043 //=================================================================================
1044 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1046 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1048 GEOM::GEOM_Object_var aGroup;
1049 if (myMode == CreateGroup)
1050 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1051 else if (myMode == EditGroup)
1054 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1057 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1058 if (!anOper->IsDone())
1061 if (aCurrList->length() > 0)
1063 anOper->DifferenceIDs(aGroup, aCurrList);
1064 if (!anOper->IsDone())
1068 int ii, nn = myIdList->count();
1071 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1072 aNewList->length(nn);
1073 for (ii = 0; ii < nn; ii++) {
1074 aNewList[ii] = myIdList->item(ii)->text().toInt();
1076 anOper->UnionIDs(aGroup, aNewList);
1077 if (!anOper->IsDone())
1081 SalomeApp_Study* study = getStudy();
1083 QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1085 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1087 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1088 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1093 objects.push_back(aGroup._retn());
1098 //================================================================
1099 // Function : getFather
1100 // Purpose : Get father object for object to be added in study
1101 // (called with addInStudy method)
1102 //================================================================
1103 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1105 GEOM::GEOM_Object_var aFatherObj;
1106 if (theObj->GetType() == GEOM_GROUP) {
1107 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1108 aFatherObj = anOper->GetMainShape(theObj);
1110 return aFatherObj._retn();