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<FeaturePtr> 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 FeaturePtr aFeature = myWorkshop->displayer()->getFeature(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<FeaturePtr > 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 FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO);
59 if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
61 aPresentations.push_back(ModuleBase_ViewerPrs(aFeature, aShape, NULL));
62 aPrsFeatures.insert(aFeature);
65 return aPresentations;
68 QFeatureList XGUI_Selection::selectedFeatures() const
70 return myWorkshop->objectBrowser()->selectedFeatures();
71 //QFeatureList aSelectedList;
73 //Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
74 //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
75 // Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
76 // FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO);
78 // aSelectedList.append(aFeature);
80 //return aSelectedList;
84 //**************************************************************
85 QModelIndexList XGUI_Selection::selectedIndexes() const
87 return myWorkshop->objectBrowser()->selectedIndexes();
90 //**************************************************************
91 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
93 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
95 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
96 theList.Append(aContext->SelectedInteractive());
99 //**************************************************************
100 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
103 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
104 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
105 TopoDS_Shape aShape = aContext->SelectedShape();
106 if (!aShape.IsNull())
107 theList.Append(aShape);