]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Selection.cpp
Salome HOME
a2db13b1e69f334164a1c59e59120e66fcd105ee
[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   QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
25
26   QList<ModuleBase_ViewerPrs> aPresentations;
27   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
28
29   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
30   if (aContext->HasOpenedContext()) {
31     for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
32       ModuleBase_ViewerPrs aPrs;
33       Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
34       if (aSelectedIds.contains((long)anIO.Access()))
35         continue;
36     
37       aSelectedIds.append((long)anIO.Access());
38       aPrs.setInteractive(anIO);
39
40       ObjectPtr aFeature = aDisplayer->getObject(anIO);
41       // we should not check the appearance of this feature because there can be some selected shapes
42       // for one feature
43       TopoDS_Shape aShape = aContext->SelectedShape();
44       if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
45         aPrs.setShape(aShape);
46       Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
47       aPrs.setOwner(anOwner);
48       aPresentations.append(aPrs);
49     }
50   } else {
51     for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) {
52       ModuleBase_ViewerPrs aPrs;
53       Handle(AIS_InteractiveObject) anIO = aContext->Current();
54       if (aSelectedIds.contains((long)anIO.Access()))
55         continue;
56     
57       aSelectedIds.append((long)anIO.Access());
58       aPrs.setInteractive(anIO);
59
60       ObjectPtr aFeature = aDisplayer->getObject(anIO);
61       aPrs.setFeature(aFeature);
62       aPresentations.append(aPrs);
63     }
64   }
65   return aPresentations;
66 }
67
68 QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
69 {
70   QList<long> aSelectedIds; // Remember of selected address in order to avoid duplicates
71   QList<ModuleBase_ViewerPrs> aPresentations;
72   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
73
74   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
75   for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
76     ModuleBase_ViewerPrs aPrs;
77     Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
78     if (aSelectedIds.contains((long)anIO.Access()))
79       continue;
80     
81     aSelectedIds.append((long)anIO.Access());
82     aPrs.setInteractive(anIO);
83
84     ObjectPtr aResult = aDisplayer->getObject(anIO);
85     // we should not check the appearance of this feature because there can be some selected shapes
86     // for one feature
87     aPrs.setFeature(aResult);
88     if (aContext->HasOpenedContext()) {
89       TopoDS_Shape aShape = aContext->DetectedShape();
90       if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
91         aPrs.setShape(aShape);
92     }
93     aPresentations.push_back(aPrs);
94   }
95   return aPresentations;
96 }
97
98 QObjectPtrList XGUI_Selection::selectedObjects() const
99 {
100   return myWorkshop->objectBrowser()->selectedObjects();
101 }
102
103 QObjectPtrList XGUI_Selection::selectedPresentations() const
104 {
105   QObjectPtrList aSelectedList;
106
107   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
108   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
109     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
110     ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
111     if (aResult)
112       aSelectedList.append(aResult);
113   }
114   return aSelectedList;
115 }
116
117 //**************************************************************
118 QModelIndexList XGUI_Selection::selectedIndexes() const
119 {
120   return myWorkshop->objectBrowser()->selectedIndexes();
121 }
122
123 //**************************************************************
124 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
125 {
126   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
127   theList.Clear();
128   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
129     theList.Append(aContext->SelectedInteractive());
130 }
131
132 //**************************************************************
133 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList, 
134                                     std::list<ObjectPtr>& theOwners) const
135 {
136   theList.Clear();
137   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
138   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
139     TopoDS_Shape aShape = aContext->SelectedShape();
140     if (!aShape.IsNull()) {
141       theList.Append(aShape);
142       Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
143       if (!aEO.IsNull()) {
144         Handle(AIS_InteractiveObject) anObj = 
145           Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
146         ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
147         theOwners.push_back(anObject);
148       }
149     }
150   }
151 }