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>
19 XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop)
20 : myWorkshop(theWorkshop)
24 QList<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
26 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
28 QList<ModuleBase_ViewerPrs> aPresentations;
29 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
31 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
32 if (aContext->HasOpenedContext()) {
33 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
34 ModuleBase_ViewerPrs aPrs;
35 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
36 if (aSelectedIds.contains((long)anIO.Access()))
39 aSelectedIds.append((long)anIO.Access());
40 aPrs.setInteractive(anIO);
42 ObjectPtr aFeature = aDisplayer->getObject(anIO);
43 // we should not check the appearance of this feature because there can be some selected shapes
45 TopoDS_Shape aShape = aContext->SelectedShape();
46 if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
47 aPrs.setShape(aShape);
48 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
49 aPrs.setOwner(anOwner);
50 aPrs.setFeature(aFeature);
51 aPresentations.append(aPrs);
54 for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) {
55 ModuleBase_ViewerPrs aPrs;
56 Handle(AIS_InteractiveObject) anIO = aContext->Current();
57 if (aSelectedIds.contains((long)anIO.Access()))
60 aSelectedIds.append((long)anIO.Access());
61 aPrs.setInteractive(anIO);
63 ObjectPtr aFeature = aDisplayer->getObject(anIO);
64 aPrs.setFeature(aFeature);
65 aPresentations.append(aPrs);
68 return aPresentations;
71 QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
73 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
74 QList<ModuleBase_ViewerPrs> aPresentations;
75 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
77 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
78 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
79 ModuleBase_ViewerPrs aPrs;
80 Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
81 if (aSelectedIds.contains((long)anIO.Access()))
84 aSelectedIds.append((long)anIO.Access());
85 aPrs.setInteractive(anIO);
87 ObjectPtr aResult = aDisplayer->getObject(anIO);
88 // we should not check the appearance of this feature because there can be some selected shapes
90 aPrs.setFeature(aResult);
91 if (aContext->HasOpenedContext()) {
92 TopoDS_Shape aShape = aContext->DetectedShape();
93 if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
94 aPrs.setShape(aShape);
96 aPresentations.push_back(aPrs);
98 return aPresentations;
101 QObjectPtrList XGUI_Selection::selectedObjects() const
103 return myWorkshop->objectBrowser()->selectedObjects();
106 QObjectPtrList XGUI_Selection::selectedPresentations() const
108 QObjectPtrList aSelectedList;
110 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
111 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
112 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
113 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
115 aSelectedList.append(aResult);
117 return aSelectedList;
120 //**************************************************************
121 QModelIndexList XGUI_Selection::selectedIndexes() const
123 return myWorkshop->objectBrowser()->selectedIndexes();
126 //**************************************************************
127 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
129 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
131 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
132 theList.Append(aContext->SelectedInteractive());
135 //**************************************************************
136 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList,
137 std::list<ObjectPtr>& theOwners) const
140 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
141 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
142 TopoDS_Shape aShape = aContext->SelectedShape();
143 if (!aShape.IsNull()) {
144 theList.Append(aShape);
145 Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
147 Handle(AIS_InteractiveObject) anObj =
148 Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
149 ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
150 theOwners.push_back(anObject);