Salome HOME
265fb9029145f05e8a63370042d921408ef64bff
[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 XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop)
18     : myWorkshop(theWorkshop)
19 {
20 }
21
22 QList<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
23 {
24   //std::set<ObjectPtr> aPrsFeatures;
25   QList<ModuleBase_ViewerPrs> aPresentations;
26   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
27
28   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
29   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
30     ModuleBase_ViewerPrs aPrs;
31
32     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
33     aPrs.setInteractive(anIO);
34
35     ObjectPtr aFeature = aDisplayer->getObject(anIO);
36     // we should not check the appearance of this feature because there can be some selected shapes
37     // for one feature
38     //if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) {
39       aPrs.setFeature(aFeature);
40       //aPrsFeatures.insert(aFeature);
41     //}
42     if (aContext->HasOpenedContext()) {
43       TopoDS_Shape aShape = aContext->SelectedShape();
44       if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
45         aPrs.setShape(aShape);
46     }
47     Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
48     aPrs.setOwner(anOwner);
49     aPresentations.append(aPrs);
50   }
51   return aPresentations;
52 }
53
54 QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
55 {
56   //std::set<ObjectPtr> aPrsFeatures;
57   QList<ModuleBase_ViewerPrs> aPresentations;
58   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
59
60   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
61   for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
62     ModuleBase_ViewerPrs aPrs;
63     Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
64     aPrs.setInteractive(anIO);
65
66     ObjectPtr aResult = aDisplayer->getObject(anIO);
67     // we should not check the appearance of this feature because there can be some selected shapes
68     // for one feature
69     //if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) {
70       aPrs.setFeature(aResult);
71       //aPrsFeatures.insert(aResult);
72     //}
73     if (aContext->HasOpenedContext()) {
74       TopoDS_Shape aShape = aContext->DetectedShape();
75       if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
76         aPrs.setShape(aShape);
77     }
78     aPresentations.push_back(aPrs);
79   }
80   return aPresentations;
81 }
82
83 QList<ObjectPtr> XGUI_Selection::selectedObjects() const
84 {
85   return myWorkshop->objectBrowser()->selectedObjects();
86 }
87
88 QList<ObjectPtr> XGUI_Selection::selectedPresentations() const
89 {
90   QList<ObjectPtr> aSelectedList;
91
92   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
93   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
94     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
95     ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
96     if (aResult)
97       aSelectedList.append(aResult);
98   }
99   return aSelectedList;
100 }
101
102 //**************************************************************
103 QModelIndexList XGUI_Selection::selectedIndexes() const
104 {
105   return myWorkshop->objectBrowser()->selectedIndexes();
106 }
107
108 //**************************************************************
109 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
110 {
111   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
112   theList.Clear();
113   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
114     theList.Append(aContext->SelectedInteractive());
115 }
116
117 //**************************************************************
118 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList, 
119                                     std::list<ObjectPtr>& theOwners) const
120 {
121   theList.Clear();
122   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
123   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
124     TopoDS_Shape aShape = aContext->SelectedShape();
125     if (!aShape.IsNull()) {
126       theList.Append(aShape);
127       Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
128       if (!aEO.IsNull()) {
129         Handle(AIS_InteractiveObject) anObj = 
130           Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
131         ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
132         theOwners.push_back(anObject);
133       }
134     }
135   }
136 }