]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Selection.cpp
Salome HOME
Make property panel as a GUI of an operation
[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 std::list<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
23 {
24   std::set<ObjectPtr> aPrsFeatures;
25   std::list<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     if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) {
37       aPrs.setFeature(aFeature);
38       aPrsFeatures.insert(aFeature);
39     }
40     if (aContext->HasOpenedContext()) {
41       TopoDS_Shape aShape = aContext->SelectedShape();
42       if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
43         aPrs.setShape(aShape);
44     }
45     Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
46     aPrs.setOwner(anOwner);
47     aPresentations.push_back(aPrs);
48   }
49   return aPresentations;
50 }
51
52 std::list<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
53 {
54   std::set<ObjectPtr> aPrsFeatures;
55   std::list<ModuleBase_ViewerPrs> aPresentations;
56   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
57
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);
63
64     ObjectPtr aResult = aDisplayer->getObject(anIO);
65     if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) {
66       aPrs.setFeature(aResult);
67       aPrsFeatures.insert(aResult);
68     }
69     if (aContext->HasOpenedContext()) {
70       TopoDS_Shape aShape = aContext->DetectedShape();
71       if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
72         aPrs.setShape(aShape);
73     }
74     aPresentations.push_back(aPrs);
75   }
76   return aPresentations;
77 }
78
79 QList<ObjectPtr> XGUI_Selection::selectedObjects() const
80 {
81   return myWorkshop->objectBrowser()->selectedObjects();
82 }
83
84 QList<ObjectPtr> XGUI_Selection::selectedPresentations() const
85 {
86   QList<ObjectPtr> aSelectedList;
87
88   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
89   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
90     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
91     ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
92     if (aResult)
93       aSelectedList.append(aResult);
94   }
95   return aSelectedList;
96 }
97
98 //**************************************************************
99 QModelIndexList XGUI_Selection::selectedIndexes() const
100 {
101   return myWorkshop->objectBrowser()->selectedIndexes();
102 }
103
104 //**************************************************************
105 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
106 {
107   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
108   theList.Clear();
109   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
110     theList.Append(aContext->SelectedInteractive());
111 }
112
113 //**************************************************************
114 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
115 {
116   theList.Clear();
117   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
118   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
119     TopoDS_Shape aShape = aContext->SelectedShape();
120     if (!aShape.IsNull())
121       theList.Append(aShape);
122   }
123 }