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 aPrs.setFeature(aFeature);
49 aPresentations.append(aPrs);
52 for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) {
53 ModuleBase_ViewerPrs aPrs;
54 Handle(AIS_InteractiveObject) anIO = aContext->Current();
55 if (aSelectedIds.contains((long)anIO.Access()))
58 aSelectedIds.append((long)anIO.Access());
59 aPrs.setInteractive(anIO);
61 ObjectPtr aFeature = aDisplayer->getObject(anIO);
62 aPrs.setFeature(aFeature);
63 aPresentations.append(aPrs);
66 return aPresentations;
69 QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
71 QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
72 QList<ModuleBase_ViewerPrs> aPresentations;
73 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
75 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
76 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
77 ModuleBase_ViewerPrs aPrs;
78 Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
79 if (aSelectedIds.contains((long)anIO.Access()))
82 aSelectedIds.append((long)anIO.Access());
83 aPrs.setInteractive(anIO);
85 ObjectPtr aResult = aDisplayer->getObject(anIO);
86 // we should not check the appearance of this feature because there can be some selected shapes
88 aPrs.setFeature(aResult);
89 if (aContext->HasOpenedContext()) {
90 TopoDS_Shape aShape = aContext->DetectedShape();
91 if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
92 aPrs.setShape(aShape);
94 aPresentations.push_back(aPrs);
96 return aPresentations;
99 QObjectPtrList XGUI_Selection::selectedObjects() const
101 return myWorkshop->objectBrowser()->selectedObjects();
104 QObjectPtrList XGUI_Selection::selectedPresentations() const
106 QObjectPtrList aSelectedList;
108 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
109 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
110 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
111 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
113 aSelectedList.append(aResult);
115 return aSelectedList;
118 //**************************************************************
119 QModelIndexList XGUI_Selection::selectedIndexes() const
121 return myWorkshop->objectBrowser()->selectedIndexes();
124 //**************************************************************
125 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
127 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
129 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
130 theList.Append(aContext->SelectedInteractive());
133 //**************************************************************
134 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList,
135 std::list<ObjectPtr>& theOwners) const
138 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
139 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
140 TopoDS_Shape aShape = aContext->SelectedShape();
141 if (!aShape.IsNull()) {
142 theList.Append(aShape);
143 Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
145 Handle(AIS_InteractiveObject) anObj =
146 Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
147 ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
148 theOwners.push_back(anObject);