1 // File: XGUI_Selection.cpp
2 // Created: 8 July 2014
3 // Author: Vitaly SMETANNIKOV
5 #include "XGUI_Selection.h"
6 #include "XGUI_Workshop.h"
7 #include "XGUI_Displayer.h"
8 #include "XGUI_ViewerProxy.h"
9 #include "XGUI_ObjectsBrowser.h"
11 #include <ModelAPI_Feature.h>
13 #include <AIS_InteractiveContext.hxx>
17 XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop)
18 : myWorkshop(theWorkshop)
22 QList<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
24 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
26 QList<ModuleBase_ViewerPrs> aPresentations;
27 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
29 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
30 if (aContext->HasOpenedContext()) {
31 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
32 ModuleBase_ViewerPrs aPrs;
33 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
34 if (aSelectedIds.contains((long)anIO.Access()))
37 aSelectedIds.append((long)anIO.Access());
38 aPrs.setInteractive(anIO);
40 ObjectPtr aFeature = aDisplayer->getObject(anIO);
41 // we should not check the appearance of this feature because there can be some selected shapes
43 TopoDS_Shape aShape = aContext->SelectedShape();
44 if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
45 aPrs.setShape(aShape);
46 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
47 aPrs.setOwner(anOwner);
48 aPresentations.append(aPrs);
51 for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) {
52 ModuleBase_ViewerPrs aPrs;
53 Handle(AIS_InteractiveObject) anIO = aContext->Current();
54 if (aSelectedIds.contains((long)anIO.Access()))
57 aSelectedIds.append((long)anIO.Access());
58 aPrs.setInteractive(anIO);
60 ObjectPtr aFeature = aDisplayer->getObject(anIO);
61 aPrs.setFeature(aFeature);
62 aPresentations.append(aPrs);
65 return aPresentations;
68 QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
70 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
71 QList<ModuleBase_ViewerPrs> aPresentations;
72 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
74 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
75 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
76 ModuleBase_ViewerPrs aPrs;
77 Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
78 if (aSelectedIds.contains((long)anIO.Access()))
81 aSelectedIds.append((long)anIO.Access());
82 aPrs.setInteractive(anIO);
84 ObjectPtr aResult = aDisplayer->getObject(anIO);
85 // we should not check the appearance of this feature because there can be some selected shapes
87 aPrs.setFeature(aResult);
88 if (aContext->HasOpenedContext()) {
89 TopoDS_Shape aShape = aContext->DetectedShape();
90 if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
91 aPrs.setShape(aShape);
93 aPresentations.push_back(aPrs);
95 return aPresentations;
98 QObjectPtrList XGUI_Selection::selectedObjects() const
100 return myWorkshop->objectBrowser()->selectedObjects();
103 QObjectPtrList XGUI_Selection::selectedPresentations() const
105 QObjectPtrList aSelectedList;
107 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
108 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
109 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
110 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
112 aSelectedList.append(aResult);
114 return aSelectedList;
117 //**************************************************************
118 QModelIndexList XGUI_Selection::selectedIndexes() const
120 return myWorkshop->objectBrowser()->selectedIndexes();
123 //**************************************************************
124 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
126 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
128 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
129 theList.Append(aContext->SelectedInteractive());
132 //**************************************************************
133 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList,
134 std::list<ObjectPtr>& theOwners) const
137 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
138 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
139 TopoDS_Shape aShape = aContext->SelectedShape();
140 if (!aShape.IsNull()) {
141 theList.Append(aShape);
142 Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
144 Handle(AIS_InteractiveObject) anObj =
145 Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
146 ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
147 theOwners.push_back(anObject);