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 sub-shapes 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 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
624 SALOME_View* view = GEOM_Displayer::GetActiveView();
626 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
627 Handle(SALOME_InteractiveObject) io =
628 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
629 if (view->isVisible(io)) myIsHiddenMain = true;
632 aDisplayer->EraseAll(/*forced = false, updateViewer = true*/);
633 aDisplayer->Display(aSelList, true);
635 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
636 if (getShapeType() == TopAbs_VERTEX && myIsHiddenMain) {
637 aDisplayer->Display(myMainObj);
640 // for the case when selected ids were not displayed in the viewer: Mantis issue 0021367
641 highlightSubShapes();
645 //=================================================================================
646 // function : getSelectedSubshapes
648 //=================================================================================
649 int GroupGUI_GroupDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
653 SalomeApp_Application* app = myGeomGUI->getApp();
654 if (!app || myMainObj->_is_nil())
657 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
658 SALOME_ListIO aSelList;
659 aSelMgr->selectedObjects(aSelList);
661 // try to find out and process the global selection
662 // (of not published objects and of published sub-shapes)
664 SALOME_ListIteratorOfListIO anIter (aSelList);
665 for (int i = 0; anIter.More(); anIter.Next(), i++)
667 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
668 QString anEntry = anIObj->getEntry();
670 int index = anEntry.lastIndexOf(str);
671 if (index > 0) // selection among special preview
673 anEntry.remove(0, index+1);
674 int anIndex = anEntry.toInt();
676 theMapIndex.Add(anIndex);
678 else // selection among published shapes
680 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
681 if (!appStudy) return 0;
682 _PTR(Study) aStudy = appStudy->studyDS();
684 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
685 GEOM::GEOM_Object_var aGeomObj =
686 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
688 if (GEOMBase::GetShape(aGeomObj, aShape)) {
689 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType()) {
690 TopTools_IndexedMapOfShape aMainMap;
691 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
692 TopExp::MapShapes(aMainShape, aMainMap);
694 TopExp_Explorer anExp (aShape, getShapeType());
695 for (; anExp.More(); anExp.Next()) {
696 TopoDS_Shape aSubShape = anExp.Current();
697 int anIndex = aMainMap.FindIndex(aSubShape);
699 if (subSelectionWay() != ALL_SUBSHAPES &&
700 !myMain2InPlaceIndices.IsBound(anIndex))
702 theMapIndex.Add(anIndex);
711 return theMapIndex.Extent();
714 //=================================================================================
717 //=================================================================================
718 void GroupGUI_GroupDlg::add()
720 TColStd_IndexedMapOfInteger aMapIndex;
721 int nbSel = getSelectedSubshapes(aMapIndex);
723 TColStd_MapOfInteger aMap;
724 for (int i = 0, n = myIdList->count(); i < n; i++)
725 aMap.Add(myIdList->item(i)->text().toInt());
728 bool isBlocked = myIdList->signalsBlocked();
729 myIdList->blockSignals(true);
731 for (int i = 1, n = aMapIndex.Extent(); i <= n; i++) {
732 if (aMap.Contains(aMapIndex(i)))
735 QListWidgetItem* anItem = new QListWidgetItem(QString("%1").arg(aMapIndex(i)));
736 myIdList->addItem(anItem);
737 anItem->setSelected(true);
740 myIdList->blockSignals(isBlocked);
746 //=================================================================================
749 //=================================================================================
750 void GroupGUI_GroupDlg::remove()
752 bool isBlocked = myIdList->signalsBlocked();
753 myIdList->blockSignals(true);
755 QListIterator<QListWidgetItem*> it (myIdList->selectedItems());
759 myIdList->blockSignals(isBlocked);
761 highlightSubShapes();
764 //=================================================================================
765 //function : subSelectionWay
767 //=================================================================================
768 int GroupGUI_GroupDlg::subSelectionWay() const
770 return myRestrictGroup->checkedId();
773 //=================================================================================
774 // function : getShapeType()
776 //=================================================================================
777 TopAbs_ShapeEnum GroupGUI_GroupDlg::getShapeType() const
779 switch (getConstructorId()) {
780 case 0: return TopAbs_VERTEX;
781 case 1: return TopAbs_EDGE;
782 case 2: return TopAbs_FACE;
783 case 3: return TopAbs_SOLID;
784 default: return TopAbs_SHAPE;
788 //=================================================================================
789 // function : setShapeType()
791 //=================================================================================
792 void GroupGUI_GroupDlg::setShapeType(const TopAbs_ShapeEnum theType)
796 case TopAbs_VERTEX: anId = 0; break;
797 case TopAbs_EDGE: anId = 1; break;
798 case TopAbs_FACE: anId = 2; break;
799 case TopAbs_SOLID: anId = 3; break;
801 setConstructorId(anId);
804 myIsShapeType = true;
805 // workaround to avoid set checked button 0
806 setConstructorId(anId);
810 //=================================================================================
811 // function : activateSelection
812 // purpose : Activate selection in accordance with myEditCurrentArgument
813 //=================================================================================
814 void GroupGUI_GroupDlg::activateSelection()
819 if (!myMainObj->_is_nil() &&
820 !myEditCurrentArgument &&
821 myIsShapeType) // check if shape type is already choosen by user
823 GEOM_Displayer* aDisplayer = getDisplayer();
825 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
826 if (getShapeType() == TopAbs_VERTEX) {
828 aDisplayer->Display(myMainObj);
831 SALOME_View* view = GEOM_Displayer::GetActiveView();
833 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
834 Handle(SALOME_InteractiveObject) io =
835 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
836 if (view->isVisible(io)) {
837 aDisplayer->Erase(myMainObj, false, false);
838 myIsHiddenMain = true;
843 int prevDisplayMode = aDisplayer->SetDisplayMode(0);
845 SUIT_ViewWindow* aViewWindow = 0;
846 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
848 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
849 if (aViewWindow == 0) return;
851 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
852 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
853 aViewManager->getType() != SVTK_Viewer::Type())
856 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
857 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
858 if (aView == 0) return;
860 TopoDS_Shape aMainShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myMainObj);
861 TopoDS_Shape aRestrictionShape;
863 if (subSelectionWay() == ALL_SUBSHAPES) {
864 aRestrictionShape = aMainShape;
866 TopTools_IndexedMapOfShape aSubShapesMap;
867 TopExp::MapShapes(aMainShape, aSubShapesMap);
868 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
869 QString anEntryBase = aMainEntry.in();
871 TopExp_Explorer anExp (aRestrictionShape, getShapeType());
872 for (; anExp.More(); anExp.Next()) {
873 TopoDS_Shape aSubShape = anExp.Current();
874 int index = aSubShapesMap.FindIndex(aSubShape);
875 QString anEntry = anEntryBase + QString("_%1").arg(index);
877 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
879 displayPreview(aPrs, true, false); // append, do not update
880 // TODO: map or delete Prs
884 else if (!myInPlaceObj->_is_nil()) {
885 TopTools_IndexedMapOfShape aSubShapesMap;
886 TopExp::MapShapes(aMainShape, aSubShapesMap);
887 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
888 QString anEntryBase = aMainEntry.in();
890 TColStd_DataMapIteratorOfDataMapOfIntegerInteger aM2IPit (myMain2InPlaceIndices);
891 for (; aM2IPit.More(); aM2IPit.Next()) {
892 int index = aM2IPit.Key();
893 TopoDS_Shape aSubShape = aSubShapesMap.FindKey(index);
894 QString anEntry = anEntryBase + QString("_%1").arg(index);
896 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
898 displayPreview(aPrs, true, false); // append, do not update
904 aDisplayer->UpdateViewer();
905 aDisplayer->SetDisplayMode(prevDisplayMode);
908 globalSelection(GEOM_ALLSHAPES);
910 SelectionIntoArgument();
913 //=================================================================================
914 // function : updateState
916 //=================================================================================
917 void GroupGUI_GroupDlg::updateState (bool isAdd)
919 myAddBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
920 //myShowOnlyBtn->setEnabled(!myEditCurrentArgument && !CORBA::is_nil(myMainObj) && isAdd);
922 bool hasSel = myIdList->selectedItems().count() > 0;
924 myRemBtn->setEnabled(hasSel);
925 myRestrictGroupBox->setEnabled(!CORBA::is_nil(myMainObj));
926 mySelAllBtn->setEnabled(!CORBA::is_nil(myMainObj));
928 mySelBtn2->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
929 myShape2Name->setEnabled(subSelectionWay() != ALL_SUBSHAPES);
930 if (subSelectionWay() == ALL_SUBSHAPES)
931 setInPlaceObj(GEOM::GEOM_Object::_nil());
934 //=================================================================================
935 // function : selectionChanged
937 //=================================================================================
938 void GroupGUI_GroupDlg::selectionChanged()
940 highlightSubShapes();
943 //=================================================================================
944 // function : highlightSubShapes
946 //=================================================================================
947 void GroupGUI_GroupDlg::highlightSubShapes()
949 if (CORBA::is_nil(myMainObj))
952 TColStd_MapOfInteger anIds;
956 int ii = 0, nn = myIdList->count();
957 for (; ii < nn; ii++)
959 if (myIdList->item(ii)->isSelected()) {
960 int id = myIdList->item(ii)->text().toInt();
961 if (subSelectionWay() != ALL_SUBSHAPES &&
962 !myMain2InPlaceIndices.IsBound(id)) {
963 //myIdList->item(ii)->setSelected(false);
970 SalomeApp_Application* app = myGeomGUI->getApp();
971 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
972 aSelMgr->clearSelected();
974 SUIT_ViewWindow* aViewWindow = 0;
975 SUIT_Study* activeStudy = app->activeStudy();
977 aViewWindow = app->desktop()->activeWindow();
978 if (aViewWindow == 0) return;
980 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
981 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
982 aViewManager->getType() != SVTK_Viewer::Type())
985 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
986 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
987 if (aView == 0) return;
989 // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
991 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
992 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
993 AIS_ListOfInteractive List;
994 //ic->DisplayedObjects(List);
995 ic->ObjectsInside(List); // Mantis issue 0021367
997 SALOME_ListIO aSelList;
999 // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape
1000 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
1001 QMap<int, QString> childsMap;
1002 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1004 _PTR(Study) aStudy = appStudy->studyDS();
1005 CORBA::String_var aMainEntry = myMainObj->GetStudyEntry();
1006 QString anEntry = aMainEntry.in();
1007 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
1008 _PTR(ChildIterator) anIt (aStudy->NewChildIterator(aSObj));
1009 for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
1010 GEOM::GEOM_Object_var aChild = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
1011 if (!CORBA::is_nil(aChild)) {
1012 int index = aLocOp->GetSubShapeIndex(myMainObj, aChild);
1013 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
1014 QString anEntry = aChildEntry.in();
1015 childsMap.insert(index, anEntry);
1020 AIS_ListIteratorOfListOfInteractive ite (List);
1021 for (; ite.More(); ite.Next()) {
1022 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1023 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1025 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
1026 QString anEntry = anIO->getEntry();
1027 int index = anEntry.lastIndexOf("_");
1028 anEntry.remove(0, index+1);
1029 int anIndex = anEntry.toInt();
1030 if (anIds.Contains(anIndex)) {
1031 aSelList.Append(anIO);
1032 if (childsMap.contains (anIndex)) {
1033 Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
1034 aSelList.Append(tmpIO);
1040 aSelMgr->setSelectedObjects(aSelList);
1045 updateState(aSelList.Extent() > 0);
1047 myAddBtn->setEnabled(true);
1048 myAddBtn->setEnabled(true);
1049 myRemBtn->setEnabled(true);
1053 //=================================================================================
1054 // function : createOperation
1056 //=================================================================================
1057 GEOM::GEOM_IOperations_ptr GroupGUI_GroupDlg::createOperation()
1059 return getGeomEngine()->GetIGroupOperations(getStudyId());
1062 #define RETURN_WITH_MSG(a, b) \
1064 theMessage += (b); \
1068 //=================================================================================
1069 // function : isValid()
1070 // purpose : Verify validity of input data
1071 //=================================================================================
1072 bool GroupGUI_GroupDlg::isValid(QString& theMessage)
1074 SalomeApp_Study* study = getStudy();
1076 RETURN_WITH_MSG (!study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1078 if (myMode == CreateGroup) {
1079 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_MAIN_OBJ"))
1082 RETURN_WITH_MSG(!CORBA::is_nil(myMainObj), tr("NO_GROUP"))
1085 QString aName (getNewObjectName());
1086 RETURN_WITH_MSG (!aName.trimmed().isEmpty(), tr("EMPTY_NAME"))
1088 RETURN_WITH_MSG (myIdList->count(), tr("EMPTY_LIST"))
1092 //=================================================================================
1093 // function : execute
1095 //=================================================================================
1096 bool GroupGUI_GroupDlg::execute(ObjectList& objects)
1098 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1100 GEOM::GEOM_Object_var aGroup;
1101 if (myMode == CreateGroup)
1102 aGroup = anOper->CreateGroup(myMainObj, getShapeType());
1103 else if (myMode == EditGroup)
1106 if (CORBA::is_nil(aGroup) || (myMode == CreateGroup && !anOper->IsDone()))
1109 GEOM::ListOfLong_var aCurrList = anOper->GetObjects(aGroup);
1110 if (!anOper->IsDone())
1113 if (aCurrList->length() > 0)
1115 anOper->DifferenceIDs(aGroup, aCurrList);
1116 if (!anOper->IsDone())
1120 int ii, nn = myIdList->count();
1123 GEOM::ListOfLong_var aNewList = new GEOM::ListOfLong;
1124 aNewList->length(nn);
1125 for (ii = 0; ii < nn; ii++) {
1126 aNewList[ii] = myIdList->item(ii)->text().toInt();
1128 anOper->UnionIDs(aGroup, aNewList);
1129 if (!anOper->IsDone())
1133 SalomeApp_Study* study = getStudy();
1135 QString objIOR = GEOMBase::GetIORFromObject(aGroup);
1137 _PTR(SObject) SO (study->studyDS()->FindObjectIOR(objIOR.toLatin1().constData()));
1139 _PTR(StudyBuilder) aBuilder (study->studyDS()->NewBuilder());
1140 aBuilder->SetName(SO, getNewObjectName().toLatin1().constData());
1145 objects.push_back(aGroup._retn());
1150 //================================================================
1151 // Function : getFather
1152 // Purpose : Get father object for object to be added in study
1153 // (called with addInStudy method)
1154 //================================================================
1155 GEOM::GEOM_Object_ptr GroupGUI_GroupDlg::getFather(GEOM::GEOM_Object_ptr theObj)
1157 GEOM::GEOM_Object_var aFatherObj;
1158 if (theObj->GetType() == GEOM_GROUP) {
1159 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
1160 aFatherObj = anOper->GetMainShape(theObj);
1162 return aFatherObj._retn();