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;
28 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
29 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
30 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
31 TopoDS_Shape aShape = aContext->SelectedShape();
33 if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip)
36 ObjectPtr aFeature = myWorkshop->displayer()->getObject(anIO);
37 if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
39 Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
40 aPresentations.push_back(ModuleBase_ViewerPrs(aFeature, aShape, anOwner));
41 aPrsFeatures.insert(aFeature);
43 return aPresentations;
46 std::list<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
48 std::set<ObjectPtr> aPrsFeatures;
49 std::list<ModuleBase_ViewerPrs> aPresentations;
51 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
52 for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
53 Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
54 TopoDS_Shape aShape = aContext->DetectedShape();
55 if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip)
58 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
59 if (aPrsFeatures.find(aResult) != aPrsFeatures.end())
61 aPresentations.push_back(ModuleBase_ViewerPrs(aResult, aShape, NULL));
62 aPrsFeatures.insert(aResult);
65 return aPresentations;
68 QList<ObjectPtr> XGUI_Selection::selectedObjects() const
70 return myWorkshop->objectBrowser()->selectedObjects();
73 QList<ObjectPtr> XGUI_Selection::selectedPresentations() const
75 QList<ObjectPtr> aSelectedList;
77 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
78 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
79 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
80 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
82 aSelectedList.append(aResult);
88 //**************************************************************
89 QModelIndexList XGUI_Selection::selectedIndexes() const
91 return myWorkshop->objectBrowser()->selectedIndexes();
94 //**************************************************************
95 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
97 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
99 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
100 theList.Append(aContext->SelectedInteractive());
103 //**************************************************************
104 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
107 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
108 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
109 TopoDS_Shape aShape = aContext->SelectedShape();
110 if (!aShape.IsNull())
111 theList.Append(aShape);