Salome HOME
Regression during edit operation. Edit sketch, select a line, as a result the propert...
[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     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.append(aPrs);
48   }
49   return aPresentations;
50 }
51
52 QList<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
53 {
54   //std::set<ObjectPtr> aPrsFeatures;
55   QList<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     // we should not check the appearance of this feature because there can be some selected shapes
66     // for one feature
67     //if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) {
68       aPrs.setFeature(aResult);
69       //aPrsFeatures.insert(aResult);
70     //}
71     if (aContext->HasOpenedContext()) {
72       TopoDS_Shape aShape = aContext->DetectedShape();
73       if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
74         aPrs.setShape(aShape);
75     }
76     aPresentations.push_back(aPrs);
77   }
78   return aPresentations;
79 }
80
81 QList<ObjectPtr> XGUI_Selection::selectedObjects() const
82 {
83   return myWorkshop->objectBrowser()->selectedObjects();
84 }
85
86 QList<ObjectPtr> XGUI_Selection::selectedPresentations() const
87 {
88   QList<ObjectPtr> aSelectedList;
89
90   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
91   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
92     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
93     ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
94     if (aResult)
95       aSelectedList.append(aResult);
96   }
97   return aSelectedList;
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, 
117                                     std::list<ObjectPtr>& theOwners) const
118 {
119   theList.Clear();
120   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
121   for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
122     TopoDS_Shape aShape = aContext->SelectedShape();
123     if (!aShape.IsNull()) {
124       theList.Append(aShape);
125       Handle(SelectMgr_EntityOwner) aEO = aContext->SelectedOwner();
126       Handle(AIS_InteractiveObject) anObj = 
127         Handle(AIS_InteractiveObject)::DownCast(aEO->Selectable());
128       ObjectPtr anObject = myWorkshop->displayer()->getObject(anObj);
129       theOwners.push_back(anObject);
130     }
131   }
132 }