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>
18 XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop)
19 : myWorkshop(theWorkshop)
23 std::list<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
25 std::set<ObjectPtr> aPrsFeatures;
26 std::list<ModuleBase_ViewerPrs> aPresentations;
27 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
29 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
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 if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) {
38 aPrs.setFeature(aFeature);
39 aPrsFeatures.insert(aFeature);
41 if (aContext->HasOpenedContext()) {
42 TopoDS_Shape aShape = aContext->SelectedShape();
43 if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
44 aPrs.setShape(aShape);
46 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
47 aPrs.setOwner(anOwner);
48 aPresentations.push_back(aPrs);
50 return aPresentations;
53 std::list<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
55 std::set<ObjectPtr> aPrsFeatures;
56 std::list<ModuleBase_ViewerPrs> aPresentations;
57 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
59 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
60 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
61 ModuleBase_ViewerPrs aPrs;
62 Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
63 aPrs.setInteractive(anIO);
65 ObjectPtr aResult = aDisplayer->getObject(anIO);
66 if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) {
67 aPrs.setFeature(aResult);
68 aPrsFeatures.insert(aResult);
70 if (aContext->HasOpenedContext()) {
71 TopoDS_Shape aShape = aContext->DetectedShape();
72 if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
73 aPrs.setShape(aShape);
75 aPresentations.push_back(aPrs);
77 return aPresentations;
80 QList<ObjectPtr> XGUI_Selection::selectedObjects() const
82 return myWorkshop->objectBrowser()->selectedObjects();
85 QList<ObjectPtr> XGUI_Selection::selectedPresentations() const
87 QList<ObjectPtr> aSelectedList;
89 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
90 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
91 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
92 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
94 aSelectedList.append(aResult);
100 //**************************************************************
101 QModelIndexList XGUI_Selection::selectedIndexes() const
103 return myWorkshop->objectBrowser()->selectedIndexes();
106 //**************************************************************
107 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
109 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
111 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
112 theList.Append(aContext->SelectedInteractive());
115 //**************************************************************
116 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
119 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
120 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
121 TopoDS_Shape aShape = aContext->SelectedShape();
122 if (!aShape.IsNull())
123 theList.Append(aShape);