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.IsNull())
37 return aPresentations;
39 if (aContext->HasOpenedContext()) {
40 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
41 ModuleBase_ViewerPrs aPrs;
42 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
43 if (aSelectedIds.contains((long)anIO.Access()))
46 aSelectedIds.append((long)anIO.Access());
47 aPrs.setInteractive(anIO);
49 ObjectPtr aFeature = aDisplayer->getObject(anIO);
50 // we should not check the appearance of this feature because there can be some selected shapes
52 TopoDS_Shape aShape = aContext->SelectedShape();
53 if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
54 aPrs.setShape(aShape);
55 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
56 aPrs.setOwner(anOwner);
57 aPrs.setFeature(aFeature);
58 aPresentations.append(aPrs);
61 for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) {
62 ModuleBase_ViewerPrs aPrs;
63 Handle(AIS_InteractiveObject) anIO = aContext->Current();
64 if (aSelectedIds.contains((long)anIO.Access()))
67 aSelectedIds.append((long)anIO.Access());
68 aPrs.setInteractive(anIO);
70 ObjectPtr aFeature = aDisplayer->getObject(anIO);
71 aPrs.setFeature(aFeature);
72 aPresentations.append(aPrs);
75 return aPresentations;
78 QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
80 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
81 QList<ModuleBase_ViewerPrs> aPresentations;
82 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
84 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
85 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
86 ModuleBase_ViewerPrs aPrs;
87 Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
88 if (aSelectedIds.contains((long)anIO.Access()))
91 aSelectedIds.append((long)anIO.Access());
92 aPrs.setInteractive(anIO);
94 ObjectPtr aResult = aDisplayer->getObject(anIO);
95 // we should not check the appearance of this feature because there can be some selected shapes
97 aPrs.setFeature(aResult);
98 if (aContext->HasOpenedContext()) {
99 TopoDS_Shape aShape = aContext->DetectedShape();
100 if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
101 aPrs.setShape(aShape);
103 aPresentations.push_back(aPrs);
105 return aPresentations;
108 QObjectPtrList XGUI_Selection::selectedObjects() const
110 return myWorkshop->objectBrowser()->selectedObjects();
113 QObjectPtrList XGUI_Selection::selectedPresentations() const
115 QObjectPtrList aSelectedList;
117 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
118 if (!aContext.IsNull()) {
119 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
120 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
121 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
123 aSelectedList.append(aResult);
126 return aSelectedList;
129 //**************************************************************
130 QModelIndexList XGUI_Selection::selectedIndexes() const
132 return myWorkshop->objectBrowser()->selectedIndexes();
135 //**************************************************************
136 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
138 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
140 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
141 theList.Append(aContext->SelectedInteractive());
144 //**************************************************************
145 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList,
146 std::list<ObjectPtr>& theOwners) const
149 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
150 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
151 TopoDS_Shape aShape = aContext->SelectedShape();
152 if (!aShape.IsNull()) {
153 theList.Append(aShape);
154 Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
156 Handle(AIS_InteractiveObject) anObj =
157 Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
158 ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
159 theOwners.push_back(anObject);
165 //**************************************************************
166 void XGUI_Selection::selectedOwners(SelectMgr_IndexedMapOfOwner& theSelectedOwners) const
168 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
170 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
171 theSelectedOwners.Add(aContext->SelectedOwner());
175 //**************************************************************
176 void XGUI_Selection::entityOwners(const Handle(AIS_InteractiveObject)& theObject,
177 SelectMgr_IndexedMapOfOwner& theOwners) const
179 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
181 if (theObject.IsNull() || aContext.IsNull())
184 TColStd_ListOfInteger aModes;
185 aContext->ActivatedModes(theObject, aModes);
187 TColStd_ListIteratorOfListOfInteger anIt(aModes);
188 for (; anIt.More(); anIt.Next()) {
189 int aMode = anIt.Value();
190 if (!theObject->HasSelection(aMode))
193 Handle(SelectMgr_Selection) aSelection = theObject->Selection(aMode);
194 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
195 Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive();
196 if (anEntity.IsNull())
198 Handle(SelectMgr_EntityOwner) anOwner =
199 Handle(SelectMgr_EntityOwner)::DownCast(anEntity->OwnerId());
200 if (!anOwner.IsNull())
201 theOwners.Add(anOwner);