]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Selection.cpp
Salome HOME
Create selection validator and selection object
[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<FeaturePtr> 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     FeaturePtr aFeature = myWorkshop->displayer()->getFeature(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<FeaturePtr > 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     FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO);
59     if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
60       continue;
61     aPresentations.push_back(ModuleBase_ViewerPrs(aFeature, aShape, NULL));
62     aPrsFeatures.insert(aFeature);
63   }
64
65   return aPresentations;
66 }
67
68 QFeatureList XGUI_Selection::selectedFeatures() const
69 {
70   return myWorkshop->objectBrowser()->selectedFeatures();
71   //QFeatureList aSelectedList;
72
73   //Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
74   //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
75   //  Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
76   //  FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO);
77   //  if (aFeature)
78   //    aSelectedList.append(aFeature);
79   //}
80   //return aSelectedList;
81 }
82
83
84 //**************************************************************
85 QModelIndexList XGUI_Selection::selectedIndexes() const 
86
87   return myWorkshop->objectBrowser()->selectedIndexes();
88 }
89
90 //**************************************************************
91 void XGUI_Selection::selectedAISObjects(AIS_ListOfInteractive& theList) const
92 {
93   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
94   theList.Clear();
95   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
96     theList.Append(aContext->SelectedInteractive());
97 }
98
99 //**************************************************************
100 void XGUI_Selection::selectedShapes(NCollection_List<TopoDS_Shape>& theList) const
101 {
102   theList.Clear();
103   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
104   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
105     TopoDS_Shape aShape = aContext->SelectedShape();
106     if (!aShape.IsNull())
107       theList.Append(aShape);
108   }
109 }