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 std::list<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
24 std::set<ObjectPtr> aPrsFeatures;
25 std::list<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 if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) {
37 aPrs.setFeature(aFeature);
38 aPrsFeatures.insert(aFeature);
40 if (aContext->HasOpenedContext()) {
41 TopoDS_Shape aShape = aContext->SelectedShape();
42 if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
43 aPrs.setShape(aShape);
45 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
46 aPrs.setOwner(anOwner);
47 aPresentations.push_back(aPrs);
49 return aPresentations;
52 std::list<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
54 std::set<ObjectPtr> aPrsFeatures;
55 std::list<ModuleBase_ViewerPrs> aPresentations;
56 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
58 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
59 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
60 ModuleBase_ViewerPrs aPrs;
61 Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
62 aPrs.setInteractive(anIO);
64 ObjectPtr aResult = aDisplayer->getObject(anIO);
65 if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) {
66 aPrs.setFeature(aResult);
67 aPrsFeatures.insert(aResult);
69 if (aContext->HasOpenedContext()) {
70 TopoDS_Shape aShape = aContext->DetectedShape();
71 if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
72 aPrs.setShape(aShape);
74 aPresentations.push_back(aPrs);
76 return aPresentations;
79 QList<ObjectPtr> XGUI_Selection::selectedObjects() const
81 return myWorkshop->objectBrowser()->selectedObjects();
84 QList<ObjectPtr> XGUI_Selection::selectedPresentations() const
86 QList<ObjectPtr> aSelectedList;
88 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
89 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
90 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
91 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
93 aSelectedList.append(aResult);
98 //**************************************************************
99 QModelIndexList XGUI_Selection::selectedIndexes() const
101 return myWorkshop->objectBrowser()->selectedIndexes();
104 //**************************************************************
105 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
107 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
109 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
110 theList.Append(aContext->SelectedInteractive());
113 //**************************************************************
114 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
117 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
118 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
119 TopoDS_Shape aShape = aContext->SelectedShape();
120 if (!aShape.IsNull())
121 theList.Append(aShape);