1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: XGUI_Selection.cpp
4 // Created: 8 July 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "XGUI_Selection.h"
8 #include "XGUI_Workshop.h"
9 #include "XGUI_Displayer.h"
10 #include "XGUI_ViewerProxy.h"
11 #include "XGUI_ObjectsBrowser.h"
13 #include <ModelAPI_Feature.h>
15 #include <AIS_InteractiveContext.hxx>
17 #include <SelectMgr_Selection.hxx>
18 #include <SelectBasics_SensitiveEntity.hxx>
19 #include <TColStd_ListIteratorOfListOfInteger.hxx>
23 XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop)
24 : myWorkshop(theWorkshop)
28 QList<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
30 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
32 QList<ModuleBase_ViewerPrs> aPresentations;
33 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
35 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
36 if (aContext->HasOpenedContext()) {
37 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
38 ModuleBase_ViewerPrs aPrs;
39 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
40 if (aSelectedIds.contains((long)anIO.Access()))
43 aSelectedIds.append((long)anIO.Access());
44 aPrs.setInteractive(anIO);
46 ObjectPtr aFeature = aDisplayer->getObject(anIO);
47 // we should not check the appearance of this feature because there can be some selected shapes
49 TopoDS_Shape aShape = aContext->SelectedShape();
50 if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
51 aPrs.setShape(aShape);
52 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
53 aPrs.setOwner(anOwner);
54 aPrs.setFeature(aFeature);
55 aPresentations.append(aPrs);
58 for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) {
59 ModuleBase_ViewerPrs aPrs;
60 Handle(AIS_InteractiveObject) anIO = aContext->Current();
61 if (aSelectedIds.contains((long)anIO.Access()))
64 aSelectedIds.append((long)anIO.Access());
65 aPrs.setInteractive(anIO);
67 ObjectPtr aFeature = aDisplayer->getObject(anIO);
68 aPrs.setFeature(aFeature);
69 aPresentations.append(aPrs);
72 return aPresentations;
75 QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
77 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
78 QList<ModuleBase_ViewerPrs> aPresentations;
79 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
81 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
82 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
83 ModuleBase_ViewerPrs aPrs;
84 Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
85 if (aSelectedIds.contains((long)anIO.Access()))
88 aSelectedIds.append((long)anIO.Access());
89 aPrs.setInteractive(anIO);
91 ObjectPtr aResult = aDisplayer->getObject(anIO);
92 // we should not check the appearance of this feature because there can be some selected shapes
94 aPrs.setFeature(aResult);
95 if (aContext->HasOpenedContext()) {
96 TopoDS_Shape aShape = aContext->DetectedShape();
97 if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
98 aPrs.setShape(aShape);
100 aPresentations.push_back(aPrs);
102 return aPresentations;
105 QObjectPtrList XGUI_Selection::selectedObjects() const
107 return myWorkshop->objectBrowser()->selectedObjects();
110 QObjectPtrList XGUI_Selection::selectedPresentations() const
112 QObjectPtrList aSelectedList;
114 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
115 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
116 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
117 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
119 aSelectedList.append(aResult);
121 return aSelectedList;
124 //**************************************************************
125 QModelIndexList XGUI_Selection::selectedIndexes() const
127 return myWorkshop->objectBrowser()->selectedIndexes();
130 //**************************************************************
131 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
133 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
135 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
136 theList.Append(aContext->SelectedInteractive());
139 //**************************************************************
140 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList,
141 std::list<ObjectPtr>& theOwners) const
144 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
145 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
146 TopoDS_Shape aShape = aContext->SelectedShape();
147 if (!aShape.IsNull()) {
148 theList.Append(aShape);
149 Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
151 Handle(AIS_InteractiveObject) anObj =
152 Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
153 ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
154 theOwners.push_back(anObject);
160 //**************************************************************
161 void XGUI_Selection::selectedOwners(SelectMgr_IndexedMapOfOwner& theSelectedOwners) const
163 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
165 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
166 theSelectedOwners.Add(aContext->SelectedOwner());
170 //**************************************************************
171 void XGUI_Selection::entityOwners(const Handle(AIS_InteractiveObject)& theObject,
172 SelectMgr_IndexedMapOfOwner& theOwners) const
174 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
176 if (theObject.IsNull() || aContext.IsNull())
179 TColStd_ListOfInteger aModes;
180 aContext->ActivatedModes(theObject, aModes);
182 TColStd_ListIteratorOfListOfInteger anIt(aModes);
183 for (; anIt.More(); anIt.Next()) {
184 int aMode = anIt.Value();
185 if (!theObject->HasSelection(aMode))
188 Handle(SelectMgr_Selection) aSelection = theObject->Selection(aMode);
189 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
190 Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive();
191 if (anEntity.IsNull())
193 Handle(SelectMgr_EntityOwner) anOwner =
194 Handle(SelectMgr_EntityOwner)::DownCast(anEntity->OwnerId());
195 if (!anOwner.IsNull())
196 theOwners.Add(anOwner);