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 //std::set<ObjectPtr> aPrsFeatures;
25 QList<ModuleBase_ViewerPrs> aPresentations;
26 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
28 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
29 if (aContext->HasOpenedContext()) {
30 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
31 ModuleBase_ViewerPrs aPrs;
33 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
34 aPrs.setInteractive(anIO);
36 ObjectPtr aFeature = aDisplayer->getObject(anIO);
37 // we should not check the appearance of this feature because there can be some selected shapes
39 //if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) {
40 aPrs.setFeature(aFeature);
41 //aPrsFeatures.insert(aFeature);
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;
54 Handle(AIS_InteractiveObject) anIO = aContext->Current();
55 aPrs.setInteractive(anIO);
57 ObjectPtr aFeature = aDisplayer->getObject(anIO);
58 // we should not check the appearance of this feature because there can be some selected shapes
60 //if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) {
61 aPrs.setFeature(aFeature);
62 //aPrsFeatures.insert(aFeature);
64 aPresentations.append(aPrs);
67 return aPresentations;
70 QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
72 //std::set<ObjectPtr> aPrsFeatures;
73 QList<ModuleBase_ViewerPrs> aPresentations;
74 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
76 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
77 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
78 ModuleBase_ViewerPrs aPrs;
79 Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
80 aPrs.setInteractive(anIO);
82 ObjectPtr aResult = aDisplayer->getObject(anIO);
83 // we should not check the appearance of this feature because there can be some selected shapes
85 //if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) {
86 aPrs.setFeature(aResult);
87 //aPrsFeatures.insert(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);