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<ObjectPtr> aPrsFeatures;
26   std::list<ModuleBase_ViewerPrs> aPresentations;
27   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
28
29   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
30   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
31     ModuleBase_ViewerPrs aPrs;
32
33     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
34     aPrs.setInteractive(anIO);
35
36     ObjectPtr aFeature = aDisplayer->getObject(anIO);
37     if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) {
38       aPrs.setFeature(aFeature);
39       aPrsFeatures.insert(aFeature);
40     }
41     if (aContext->HasOpenedContext()) {
42       TopoDS_Shape aShape = aContext->SelectedShape();
43       if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
44         aPrs.setShape(aShape);
45     }
46     Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
47     aPrs.setOwner(anOwner);
48     aPresentations.push_back(aPrs);
49   }
50   return aPresentations;
51 }
52
53 std::list<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
54 {
55   std::set<ObjectPtr> aPrsFeatures;
56   std::list<ModuleBase_ViewerPrs> aPresentations;
57   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
58
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);
64
65     ObjectPtr aResult = aDisplayer->getObject(anIO);
66     if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) {
67       aPrs.setFeature(aResult);
68       aPrsFeatures.insert(aResult);
69     }
70     if (aContext->HasOpenedContext()) {
71       TopoDS_Shape aShape = aContext->DetectedShape();
72       if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
73         aPrs.setShape(aShape);
74     }
75     aPresentations.push_back(aPrs);
76   }
77   return aPresentations;
78 }
79
80 QList<ObjectPtr> XGUI_Selection::selectedObjects() const
81 {
82   return myWorkshop->objectBrowser()->selectedObjects();
83 }
84   
85 QList<ObjectPtr> XGUI_Selection::selectedPresentations() const
86 {
87   QList<ObjectPtr> aSelectedList;
88
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);
93     if (aResult)
94       aSelectedList.append(aResult);
95   }
96   return aSelectedList;
97 }
98
99
100 //**************************************************************
101 QModelIndexList XGUI_Selection::selectedIndexes() const 
102
103   return myWorkshop->objectBrowser()->selectedIndexes();
104 }
105
106 //**************************************************************
107 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
108 {
109   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
110   theList.Clear();
111   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
112     theList.Append(aContext->SelectedInteractive());
113 }
114
115 //**************************************************************
116 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
117 {
118   theList.Clear();
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);
124   }
125 }