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 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
30 ModuleBase_ViewerPrs aPrs;
32 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
33 aPrs.setInteractive(anIO);
35 ObjectPtr aFeature = aDisplayer->getObject(anIO);
36 // we should not check the appearance of this feature because there can be some selected shapes
38 //if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) {
39 aPrs.setFeature(aFeature);
40 //aPrsFeatures.insert(aFeature);
42 if (aContext->HasOpenedContext()) {
43 TopoDS_Shape aShape = aContext->SelectedShape();
44 if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
45 aPrs.setShape(aShape);
47 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
48 aPrs.setOwner(anOwner);
49 aPresentations.append(aPrs);
51 return aPresentations;
54 QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
56 //std::set<ObjectPtr> aPrsFeatures;
57 QList<ModuleBase_ViewerPrs> aPresentations;
58 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
60 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
61 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
62 ModuleBase_ViewerPrs aPrs;
63 Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
64 aPrs.setInteractive(anIO);
66 ObjectPtr aResult = aDisplayer->getObject(anIO);
67 // we should not check the appearance of this feature because there can be some selected shapes
69 //if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) {
70 aPrs.setFeature(aResult);
71 //aPrsFeatures.insert(aResult);
73 if (aContext->HasOpenedContext()) {
74 TopoDS_Shape aShape = aContext->DetectedShape();
75 if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
76 aPrs.setShape(aShape);
78 aPresentations.push_back(aPrs);
80 return aPresentations;
83 QList<ObjectPtr> XGUI_Selection::selectedObjects() const
85 return myWorkshop->objectBrowser()->selectedObjects();
88 QList<ObjectPtr> XGUI_Selection::selectedPresentations() const
90 QList<ObjectPtr> aSelectedList;
92 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
93 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
94 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
95 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
97 aSelectedList.append(aResult);
102 //**************************************************************
103 QModelIndexList XGUI_Selection::selectedIndexes() const
105 return myWorkshop->objectBrowser()->selectedIndexes();
108 //**************************************************************
109 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
111 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
113 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
114 theList.Append(aContext->SelectedInteractive());
117 //**************************************************************
118 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList,
119 std::list<ObjectPtr>& theOwners) const
122 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
123 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
124 TopoDS_Shape aShape = aContext->SelectedShape();
125 if (!aShape.IsNull()) {
126 theList.Append(aShape);
127 Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
128 Handle(AIS_InteractiveObject) anObj =
129 Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
130 ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
131 theOwners.push_back(anObject);