Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_Selection.cpp
1 // File:        XGUI_Selection.cpp
2 // Created:     8 July 2014
3 // Author:      Vitaly SMETANNIKOV
4
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"
10
11 #include <ModelAPI_Feature.h>
12
13 #include <AIS_InteractiveContext.hxx>
14
15 #include <set>
16
17
18 XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop)
19 : myWorkshop(theWorkshop)
20 {
21 }
22
23 std::list<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
24 {
25   std::set<ResultPtr> aPrsFeatures;
26   std::list<ModuleBase_ViewerPrs> aPresentations;
27
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();
32
33     if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip)
34       continue;
35
36     ResultPtr aFeature = myWorkshop->displayer()->getResult(anIO);
37     if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
38       continue;
39     Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
40     aPresentations.push_back(ModuleBase_ViewerPrs(aFeature, aShape, anOwner));
41     aPrsFeatures.insert(aFeature);
42   }
43   return aPresentations;
44 }
45
46 std::list<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
47 {
48   std::set<ResultPtr> aPrsFeatures;
49   std::list<ModuleBase_ViewerPrs> aPresentations;
50
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)
56       continue;
57
58     ResultPtr aResult = myWorkshop->displayer()->getResult(anIO);
59     if (aPrsFeatures.find(aResult) != aPrsFeatures.end())
60       continue;
61     aPresentations.push_back(ModuleBase_ViewerPrs(aResult, aShape, NULL));
62     aPrsFeatures.insert(aResult);
63   }
64
65   return aPresentations;
66 }
67
68 QList<ObjectPtr> XGUI_Selection::selectedObjects() const
69 {
70   return myWorkshop->objectBrowser()->selectedObjects();
71 }
72   
73 QResultList XGUI_Selection::selectedResults() const
74 {
75   QResultList aSelectedList;
76
77   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
78   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
79     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
80     ResultPtr aResult = myWorkshop->displayer()->getResult(anIO);
81     if (aResult)
82       aSelectedList.append(aResult);
83   }
84   return aSelectedList;
85 }
86
87
88 //**************************************************************
89 QModelIndexList XGUI_Selection::selectedIndexes() const 
90
91   return myWorkshop->objectBrowser()->selectedIndexes();
92 }
93
94 //**************************************************************
95 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
96 {
97   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
98   theList.Clear();
99   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
100     theList.Append(aContext->SelectedInteractive());
101 }
102
103 //**************************************************************
104 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
105 {
106   theList.Clear();
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);
112   }
113 }