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 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.append(aPrs);
49 return aPresentations;
52 QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
54 //std::set<ObjectPtr> aPrsFeatures;
55 QList<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 // we should not check the appearance of this feature because there can be some selected shapes
67 //if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) {
68 aPrs.setFeature(aResult);
69 //aPrsFeatures.insert(aResult);
71 if (aContext->HasOpenedContext()) {
72 TopoDS_Shape aShape = aContext->DetectedShape();
73 if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
74 aPrs.setShape(aShape);
76 aPresentations.push_back(aPrs);
78 return aPresentations;
81 QList<ObjectPtr> XGUI_Selection::selectedObjects() const
83 return myWorkshop->objectBrowser()->selectedObjects();
86 QList<ObjectPtr> XGUI_Selection::selectedPresentations() const
88 QList<ObjectPtr> aSelectedList;
90 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
91 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
92 Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
93 ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
95 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,
117 std::list<ObjectPtr>& theOwners) const
120 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
121 for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
122 TopoDS_Shape aShape = aContext->SelectedShape();
123 if (!aShape.IsNull()) {
124 theList.Append(aShape);
125 Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
126 Handle(AIS_InteractiveObject) anObj =
127 Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
128 ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
129 theOwners.push_back(anObject);