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
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),
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");
186 GroupGUI_GroupDlg::~GroupGUI_GroupDlg()
188 if (myIsHiddenMain) {
189 GEOM_Displayer* aDisplayer = getDisplayer();
190 aDisplayer->Display(myMainObj);
191 myIsHiddenMain = false;
195 //=================================================================================
198 //=================================================================================
199 void GroupGUI_GroupDlg::Init()
201 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
203 //unset shape type to avoid preparation of selection before exact user shape type selection
204 unsetConstructorId();
205 myIsShapeType = false;
207 if (myMode == CreateGroup) {
208 initName(tr("GROUP_PREFIX"));
210 // Get ready for main shape selection
211 myEditCurrentArgument = myMainName;
213 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
214 connect(mySelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
215 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
217 else if (myMode == EditGroup) {
218 SALOME_ListIO aSelList;
219 aSelMgr->selectedObjects(aSelList);
221 if (aSelList.Extent()) {
222 GEOM::GEOM_Object_var anObj =
223 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
225 if (!CORBA::is_nil(anObj) && anObj->GetType() == GEOM_GROUP) {
228 mainFrame()->ResultName->setText(GEOMBase::GetName(myGroup));
230 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
231 myMainObj = anOper->GetMainShape(myGroup);
232 if (!CORBA::is_nil(myMainObj))
233 myMainName->setText(GEOMBase::GetName(myMainObj));
235 setShapeType((TopAbs_ShapeEnum)anOper->GetType(myGroup));
237 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(myGroup);
238 for (int i = 0, n = aCurrList->length(); i < n; i++)
239 myIdList->addItem(new QListWidgetItem(QString("%1").arg(aCurrList[i])));
241 myEditCurrentArgument = 0;
243 connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
247 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
249 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
250 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
252 connect(myRestrictGroup, SIGNAL(buttonClicked(int)), this, SLOT(SetEditCurrentArgument()));
253 connect(mySelAllBtn, SIGNAL(clicked()), this, SLOT(selectAllSubShapes()));
254 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(add()));
255 connect(myRemBtn, SIGNAL(clicked()), this, SLOT(remove()));
256 connect(myShowOnlyBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
257 connect(myHideSelBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
258 connect(myShowAllBtn, SIGNAL(clicked()), this, SLOT(showOnlySelected()));
259 connect(myIdList, SIGNAL(itemSelectionChanged()), this, SLOT(selectionChanged()));
261 setInPlaceObj(GEOM::GEOM_Object::_nil());
263 myBusy = true; // just activate but do not select in the list
268 //=================================================================================
269 // function : enterEvent()
271 //=================================================================================
272 void GroupGUI_GroupDlg::enterEvent(QEvent* e)
274 if (!buttonCancel()->isEnabled())
275 ActivateThisDialog();
278 //=================================================================================
279 //function : closeEvent
280 //purpose : remove temporary geom object
281 //=================================================================================
282 void GroupGUI_GroupDlg::closeEvent(QCloseEvent* e)
284 setInPlaceObj(GEOM::GEOM_Object::_nil());
287 GEOMBase_Skeleton::closeEvent(e);
290 //=================================================================================
291 // function : ClickOnOk()
293 //=================================================================================
294 void GroupGUI_GroupDlg::ClickOnOk()
296 setIsApplyAndClose(true);
301 //=================================================================================
302 // function : ClickOnApply()
304 //=================================================================================
305 bool GroupGUI_GroupDlg::ClickOnApply()
307 if (!onAccept(myMode == CreateGroup, true))
310 if (myMode == CreateGroup)
314 ConstructorsClicked(getConstructorId());
322 //=================================================================================
323 // function : ActivateThisDialog()
325 //=================================================================================
326 void GroupGUI_GroupDlg::ActivateThisDialog()
328 GEOMBase_Skeleton::ActivateThisDialog();
330 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
331 this, SLOT(SelectionIntoArgument()));
336 //=================================================================================
337 // function : SetEditCurrentArgument()
339 //=================================================================================
340 void GroupGUI_GroupDlg::SetEditCurrentArgument()
342 QPushButton* send = (QPushButton*)sender();
344 if (send == mySelBtn) {
345 myEditCurrentArgument = myMainName;
346 myShape2Name->setText("");
348 else if (send == mySelBtn2 || sender() == myRestrictGroup) {
349 setInPlaceObj(GEOM::GEOM_Object::_nil());
350 myShape2Name->setText("");
351 if (subSelectionWay() != ALL_SUBSHAPES) {
352 myEditCurrentArgument = myShape2Name;
355 myEditCurrentArgument = 0;
364 //=================================================================================
365 // function : onGetInPlace()
367 //=================================================================================
368 void GroupGUI_GroupDlg::onGetInPlace()
370 setInPlaceObj(GEOM::GEOM_Object::_nil());
371 myEditCurrentArgument->setText("");
373 bool isBlocked = myIdList->signalsBlocked();
374 myIdList->blockSignals(true);
375 myIdList->clearSelection();
376 myIdList->blockSignals(isBlocked);
378 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
379 SALOME_ListIO aSelList;
380 aSelMgr->selectedObjects(aSelList);
382 if (aSelList.Extent() != 1)
385 GEOM::GEOM_Object_var anObj =
386 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
387 if (GEOMBase::IsShape(anObj)) {
388 if (!anObj->_is_equivalent(myMainObj) && !anObj->_is_equivalent(myGroup)) {
389 SUIT_OverrideCursor wc;
390 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
391 GEOM::GEOM_IShapesOperations_var aShapesOp =
392 getGeomEngine()->GetIShapesOperations(getStudyId());
393 if (subSelectionWay() == GET_IN_PLACE) {
394 GEOM::GEOM_Object_var aGetInPlaceObj = aShapesOp->GetInPlace(myMainObj, anObj);
395 setInPlaceObj(aGetInPlaceObj);
398 bool isVisible = true;
399 if (SALOME_View* view = GEOM_Displayer::GetActiveView())
400 isVisible = view->isVisible(aSelList.First());
401 setInPlaceObj(anObj, isVisible);
403 myEditCurrentArgument = 0;
404 //myBusy = true; // just activate but do not select in the list
411 //=================================================================================
412 //function : setInPlaceObj
413 //purpose : temporarily add an object to study and remove old InPlaceObj
414 //=================================================================================
415 void GroupGUI_GroupDlg::setInPlaceObj(GEOM::GEOM_Object_var theObj, const bool isVisible)
417 if (!myInPlaceObj->_is_equivalent(theObj))
419 myInPlaceObj = theObj;
422 // build map of indices
423 myMain2InPlaceIndices.Clear();
424 if (!myInPlaceObj->_is_nil()) {
425 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
426 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
428 GEOM::ListOfGO_var aSubObjects = aShapesOp->MakeExplode(myInPlaceObj, getShapeType(), false);
429 for (int i = 0; i < aSubObjects->length(); i++)
431 GEOM::GEOM_Object_var aSS = aShapesOp->GetSame(myMainObj, aSubObjects[i]);
432 if (!CORBA::is_nil(aSS)) {
433 CORBA::Long aMainIndex = aLocOp->GetSubShapeIndex(myMainObj, aSS);
434 CORBA::Long aPlaceIndex = aLocOp->GetSubShapeIndex(myInPlaceObj, aSubObjects[i]);
435 if (aMainIndex >= 0 && aPlaceIndex > 0)
436 myMain2InPlaceIndices.Bind(aMainIndex, aPlaceIndex);
440 myInPlaceObjSelectState = subSelectionWay();
441 if (myInPlaceObjSelectState == SUBSHAPES_OF_SHAPE2 && !isVisible)
442 myInPlaceObjSelectState = SUBSHAPES_OF_INVISIBLE_SHAPE2;
445 //=================================================================================
446 // function : SelectionIntoArgument()
447 // purpose : Called when selection has changed
448 //=================================================================================
449 void GroupGUI_GroupDlg::SelectionIntoArgument()
451 if (subSelectionWay() != ALL_SUBSHAPES && myEditCurrentArgument == myShape2Name) {
456 if (myEditCurrentArgument == myMainName) { // Selection of a main shape is active
457 myEditCurrentArgument->setText("");
460 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
461 SALOME_ListIO aSelList;
462 aSelMgr->selectedObjects(aSelList);
463 int nbSel = aSelList.Extent();
466 GEOM::GEOM_Object_var anObj =
467 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
469 if (GEOMBase::IsShape(anObj)) {
470 if (myIsHiddenMain) {
471 GEOM_Displayer* aDisplayer = getDisplayer();
472 aDisplayer->Display(myMainObj);
473 myIsHiddenMain = false;
476 myEditCurrentArgument->setText(GEOMBase::GetName(anObj));
477 // activate subshapes selection by default
478 myEditCurrentArgument = 0;
484 if (myIsHiddenMain) {
485 GEOM_Displayer* aDisplayer = getDisplayer();
486 aDisplayer->Display(myMainObj);
487 myIsHiddenMain = false;
489 myMainObj = GEOM::GEOM_Object::_nil();
492 else { // an attempt to synchronize list box selection with 3d viewer
493 if (myBusy || myMainObj->_is_nil()) {
497 bool isBlocked = myIdList->signalsBlocked();
498 myIdList->blockSignals(true);
499 myIdList->clearSelection();
501 TColStd_IndexedMapOfInteger aMapIndex;
502 int nbSel = getSelectedSubshapes(aMapIndex);
506 for (int i = 0, n = myIdList->count(); i < n; i++)
507 aMap.insert(myIdList->item(i)->text().toInt(), i);
509 bool highlight = false;
510 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
511 if (aMap.contains(aMapIndex(ii))) {
512 myIdList->item(aMap[aMapIndex(ii)])->setSelected(true);
517 highlightSubShapes();
519 myIdList->blockSignals(isBlocked);
525 //=================================================================================
526 // function : ConstructorsClicked()
527 // purpose : Radio button management
528 //=================================================================================
529 void GroupGUI_GroupDlg::ConstructorsClicked(int constructorId)
531 if (getConstructorId() != constructorId)
532 setConstructorId(constructorId);
534 myIsShapeType = true;
536 myEditCurrentArgument = 0;
538 setInPlaceObj(myInPlaceObj); // to rebuild myMain2InPlaceIndices
543 //=================================================================================
544 // function : selectAllSubShapes
546 //=================================================================================
547 void GroupGUI_GroupDlg::selectAllSubShapes()
549 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
552 GEOM::ListOfLong_var aSubShapes;
553 GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
554 aSubShapes = aShOp->SubShapeAllIDs(myMainObj, getShapeType(), false);
555 if (aSubShapes->length() > 0) {
556 if (subSelectionWay() == ALL_SUBSHAPES)
558 myIdList->clear(); // for sorted final list?
560 if (!aShOp->IsDone())
565 aSubShapes = new GEOM::ListOfLong();
566 aSubShapes->length(myMain2InPlaceIndices.Extent());
567 TColStd_DataMapIteratorOfDataMapOfIntegerInteger m2ip (myMain2InPlaceIndices);
568 for (int i = 0; m2ip.More(); i++, m2ip.Next())
569 aSubShapes[i] = m2ip.Key();
572 bool isBlocked = myIdList->signalsBlocked();
573 myIdList->blockSignals(true);
575 for (int i = 0, n = aSubShapes->length(); i < n; i++) {
576 CORBA::Long anIndex = aSubShapes[i];
580 QListWidgetItem* anItem = 0;
581 QString text = QString("%1").arg(anIndex);
582 if (!myInPlaceObj->_is_nil()) {
583 QList<QListWidgetItem*> found = myIdList->findItems(text, Qt::MatchExactly);
584 if (found.count()) anItem = found[0];
587 anItem = new QListWidgetItem(text);
588 myIdList->addItem(anItem);
590 anItem->setSelected(true);
593 myIdList->blockSignals(isBlocked);
594 highlightSubShapes();
598 //=================================================================================
599 // function : showOnlySelected
601 //=================================================================================
602 void GroupGUI_GroupDlg::showOnlySelected()
604 if (CORBA::is_nil(myMainObj) || !myIsShapeType)
607 QPushButton* send = (QPushButton*)sender();
608 if (send == myShowAllBtn) {
613 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
614 SALOME_ListIO aSelList;
615 aSelMgr->selectedObjects(aSelList);
617 GEOM_Displayer* aDisplayer = getDisplayer();
619 if (send == myHideSelBtn) {
620 aDisplayer->Erase(aSelList, /*forced=*/false, /*updateViewer=*/true);
623 aDisplayer->EraseAll(/*forced = false, updateViewer = true*/);
624 aDisplayer->Display(aSelList, true);
626 // for the case when selected ids were not displayed in the viewer: Mantis issue 0021367
627 highlightSubShapes();
631 //=================================================================================
632 // function : getSelectedSubshapes
634 //=================================================================================
635 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
639 SalomeApp_Application* app = myGeomGUI->getApp();
640 if (!app || myMainObj->_is_nil())
643 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
644 SALOME_ListIO aSelList;
645 aSelMgr->selectedObjects(aSelList);
647 // try to find out and process the global selection
648 // (of not published objects and of published sub-shapes)
650 SALOME_ListIteratorOfListIO anIter (aSelList);
651 for (int i = 0; anIter.More(); anIter.Next(), i++)
653 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
654 QString anEntry = anIObj->getEntry();
656 int index = anEntry.lastIndexOf(str);
657 if (index > 0) // selection among special preview
659 anEntry.remove(0, index+1);
660 int anIndex = anEntry.toInt();
662 theMapIndex.Add(anIndex);
664 else // selection among published shapes
666 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
667 if (!appStudy) return 0;
668 _PTR(Study) aStudy = appStudy->studyDS();
670 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
671 GEOM::GEOM_Object_var aGeomObj =
672 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
674 if (GEOMBase::GetShape(aGeomObj, aShape)) {
675 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
676 TopTools_IndexedMapOfShape aMainMap;
677 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
678 TopExp::MapShapes(aMainShape, aMainMap);
680 TopExp_Explorer anExp (aShape, getShapeType());
681 for (; anExp.More(); anExp.Next()) {
682 TopoDS_Shape aSubShape = anExp.Current();
683 int anIndex = aMainMap.FindIndex(aSubShape);
685 if (subSelectionWay() != ALL_SUBSHAPES &&
686 !myMain2InPlaceIndices.IsBound(anIndex))
688 theMapIndex.Add(anIndex);
697 return theMapIndex.Extent();
700 //=================================================================================
703 //=================================================================================
704 void GroupGUI_GroupDlg::add()
706 TColStd_IndexedMapOfInteger aMapIndex;
707 int nbSel = getSelectedSubshapes(aMapIndex);
709 TColStd_MapOfInteger aMap;
710 for (int i = 0, n = myIdList->count(); i < n; i++)
711 aMap.Add(myIdList->item(i)->text().toInt());
714 bool isBlocked = myIdList->signalsBlocked();
715 myIdList->blockSignals(true);
717 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
718 if (aMap.Contains(aMapIndex(i)))
721 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
722 myIdList->addItem(anItem);
723 anItem->setSelected(true);
726 myIdList->blockSignals(isBlocked);
732 //=================================================================================
735 //=================================================================================
736 void GroupGUI_GroupDlg::remove()
738 bool isBlocked = myIdList->signalsBlocked();
739 myIdList->blockSignals(true);
741 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
745 myIdList->blockSignals(isBlocked);
747 highlightSubShapes();
750 //=================================================================================
751 //function : subSelectionWay
753 //=================================================================================
754 int GroupGUI_GroupDlg::subSelectionWay() const
756 return myRestrictGroup->checkedId();
759 //=================================================================================
760 // function : getShapeType()
762 //=================================================================================
763 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
765 switch (getConstructorId()) {
766 case 0: return TopAbs_VERTEX;
767 case 1: return TopAbs_EDGE;
768 case 2: return TopAbs_FACE;
769 case 3: return TopAbs_SOLID;
770 default: return TopAbs_SHAPE;
774 //=================================================================================
775 // function : setShapeType()
777 //=================================================================================
778 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
782 case TopAbs_VERTEX: anId = 0; break;
783 case TopAbs_EDGE: anId = 1; break;
784 case TopAbs_FACE: anId = 2; break;
785 case TopAbs_SOLID: anId = 3; break;
787 setConstructorId(anId);
790 myIsShapeType = true;
791 // workaround to avoid set checked button 0
792 setConstructorId(anId);
796 //=================================================================================
797 // function : activateSelection
798 // purpose : Activate selection in accordance with myEditCurrentArgument
799 //=================================================================================
800 void GroupGUI_GroupDlg::activateSelection()
805 if (!myMainObj->_is_nil() &&
806 !myEditCurrentArgument &&
807 myIsShapeType) // check if shape type is already choosen by user
809 GEOM_Displayer* aDisplayer = getDisplayer();
810 SALOME_View* view = GEOM_Displayer::GetActiveView();
812 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
813 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
814 if (view->isVisible(io)) {
815 aDisplayer->Erase(myMainObj, false, false);
816 myIsHiddenMain = true;
820 int prevDisplayMode = aDisplayer->SetDisplayMode(0);
822 SUIT_ViewWindow* aViewWindow = 0;
823 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
825 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
826 if (aViewWindow == 0) return;
828 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
829 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
830 aViewManager->getType() != SVTK_Viewer::Type())
833 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
834 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
835 if (aView == 0) return;
837 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
838 TopoDS_Shape aRestrictionShape;
840 if (subSelectionWay() == ALL_SUBSHAPES) {
841 aRestrictionShape = aMainShape;
843 TopTools_IndexedMapOfShape aSubShapesMap;
844 TopExp::MapShapes(aMainShape, aSubShapesMap);
845 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
846 QString anEntryBase = aMainEntry.in();
848 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
849 for (; anExp.More(); anExp.Next()) {
850 TopoDS_Shape aSubShape = anExp.Current();
851 int index = aSubShapesMap.FindIndex(aSubShape);
852 QString anEntry = anEntryBase + QString("_%1").arg(index);
854 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
856 displayPreview(aPrs, true, false); // append, do not update
857 // TODO: map or delete Prs
861 else if (!myInPlaceObj->_is_nil()) {
862 TopTools_IndexedMapOfShape aSubShapesMap;
863 TopExp::MapShapes(aMainShape, aSubShapesMap);
864 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
865 QString anEntryBase = aMainEntry.in();
867 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
868 for (; aM2IPit.More(); aM2IPit.Next()) {
869 int index = aM2IPit.Key();
870 TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
871 QString anEntry = anEntryBase + QString("_%1").arg(index);
873 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
875 displayPreview(aPrs, true, false); // append, do not update
881 aDisplayer->UpdateViewer();
882 aDisplayer->SetDisplayMode(prevDisplayMode);
885 globalSelection(GEOM_ALLSHAPES);
887 SelectionIntoArgument();
890 //=================================================================================
891 // function : updateState
893 //=================================================================================
894 void GroupGUI_GroupDlg::updateState (bool isAdd)
896 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
897 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
899 bool hasSel = myIdList->selectedItems().count() > 0;
901 myRemBtn->setEnabled(hasSel);
902 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
903 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
905 mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
906 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
907 if (subSelectionWay() == ALL_SUBSHAPES)
908 setInPlaceObj(GEOM::GEOM_Object::_nil());
911 //=================================================================================
912 // function : selectionChanged
914 //=================================================================================
915 void GroupGUI_GroupDlg::selectionChanged()
917 highlightSubShapes();
920 //=================================================================================
921 // function : highlightSubShapes
923 //=================================================================================
924 void GroupGUI_GroupDlg::highlightSubShapes()
926 if (CORBA::is_nil(myMainObj))
929 TColStd_MapOfInteger anIds;
933 int ii = 0, nn = myIdList->count();
934 for (; ii < nn; ii++)
936 if (myIdList->item(ii)->isSelected()) {
937 int id = myIdList->item(ii)->text().toInt();
938 if (subSelectionWay() != ALL_SUBSHAPES &&
939 !myMain2InPlaceIndices.IsBound(id)) {
940 //myIdList->item(ii)->setSelected(false);
947 SalomeApp_Application* app = myGeomGUI->getApp();
948 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
949 aSelMgr->clearSelected();
951 SUIT_ViewWindow* aViewWindow = 0;
952 SUIT_Study* activeStudy = app->activeStudy();
954 aViewWindow = app->desktop()->activeWindow();
955 if (aViewWindow == 0) return;
957 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
958 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
959 aViewManager->getType() != SVTK_Viewer::Type())
962 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
963 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
964 if (aView == 0) return;
966 // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
968 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
969 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
970 AIS_ListOfInteractive List;
971 //ic->DisplayedObjects(List);
972 ic->ObjectsInside(List); // Mantis issue 0021367
974 SALOME_ListIO aSelList;
976 // To highlight the selected subshape in Object Browser, if it's already published under the main shape
977 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
978 QMap<int, QString> childsMap;
979 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
981 _PTR(Study) aStudy = appStudy->studyDS();
982 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
983 QString anEntry = aMainEntry.in();
984 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
985 _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
986 for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
987 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
988 if (!CORBA::is_nil(aChild)) {
989 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
990 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
991 QString anEntry = aChildEntry.in();
992 childsMap.insert(index, anEntry);
997 AIS_ListIteratorOfListOfInteractive ite (List);
998 for (; ite.More(); ite.Next()) {
999 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1000 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1002 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
1003 QString anEntry = anIO->getEntry();
1004 int index = anEntry.lastIndexOf("_");
1005 anEntry.remove(0, index+1);
1006 int anIndex = anEntry.toInt();
1007 if (anIds.Contains(anIndex)) {
1008 aSelList.Append(anIO);
1009 if (childsMap.contains (anIndex)) {
1010 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
1011 aSelList.Append(tmpIO);
1017 aSelMgr->setSelectedObjects(aSelList);
1022 updateState(aSelList.Extent() > 0);
1024 myAddBtn->setEnabled(true);
1025 myAddBtn->setEnabled(true);
1026 myRemBtn->setEnabled(true);
1030 //=================================================================================
1031 // function : createOperation
1033 //=================================================================================
1034 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1036 return getGeomEngine()->GetIGroupOperations(getStudyId());
1039 #define RETURN_WITH_MSG(a, b) \
1041 theMessage += (b); \
1045 //=================================================================================
1046 // function : isValid()
1047 // purpose : Verify validity of input data
1048 //=================================================================================
1049 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1051 SalomeApp_Study* study = getStudy();
1053 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1055 if (myMode == CreateGroup) {
1056 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1059 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1062 QString aName (getNewObjectName());
1063 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1065 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1069 //=================================================================================
1070 // function : execute
1072 //=================================================================================
1073 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1075 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1077 GEOM::GEOM_Object_var aGroup;
1078 if (myMode == CreateGroup)
1079 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1080 else if (myMode == EditGroup)
1083 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1086 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1087 if (!anOper->IsDone())
1090 if (aCurrList->length() > 0)
1092 anOper->DifferenceIDs(aGroup, aCurrList);
1093 if (!anOper->IsDone())
1097 int ii, nn = myIdList->count();
1100 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1101 aNewList->length(nn);
1102 for (ii = 0; ii < nn; ii++) {
1103 aNewList[ii] = myIdList->item(ii)->text().toInt();
1105 anOper->UnionIDs(aGroup, aNewList);
1106 if (!anOper->IsDone())
1110 SalomeApp_Study* study = getStudy();
1112 QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1114 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1116 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1117 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1122 objects.push_back(aGroup._retn());
1127 //================================================================
1128 // Function : getFather
1129 // Purpose : Get father object for object to be added in study
1130 // (called with addInStudy method)
1131 //================================================================
1132 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1134 GEOM::GEOM_Object_var aFatherObj;
1135 if (theObj->GetType() == GEOM_GROUP) {
1136 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1137 aFatherObj = anOper->GetMainShape(theObj);
1139 return aFatherObj._retn();