Salome HOME
bca8d2d24c37de2107155910d1d9fc51cca2d3a4
[modules/shaper.git] / src / XGUI / XGUI_Displayer.cpp
1 // File:        XGUI_Displayer.cpp
2 // Created:     20 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include "XGUI_Displayer.h"
6 #include "XGUI_Viewer.h"
7
8 #include <ModelAPI_Document.h>
9
10 #include <AIS_InteractiveContext.hxx>
11 #include <AIS_ListOfInteractive.hxx>
12 #include <AIS_ListIteratorOfListOfInteractive.hxx>
13
14 #include <AIS_Shape.hxx>
15
16 XGUI_Displayer::XGUI_Displayer(XGUI_Viewer* theViewer)
17 : myViewer(theViewer)
18 {
19 }
20
21 XGUI_Displayer::~XGUI_Displayer()
22 {
23 }
24
25 void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
26                              const bool isUpdateViewer)
27 {
28 }
29
30 void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
31                              const TopoDS_Shape& theShape, const bool isUpdateViewer)
32 {
33   Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
34
35   Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
36   std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
37   if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
38     aDispAIS = myFeature2AISObjectMap[theFeature];
39   }
40   aDispAIS.push_back(anAIS);
41   myFeature2AISObjectMap[theFeature] = aDispAIS;
42
43   aContext->Display(anAIS, Standard_False);
44
45   if (isUpdateViewer)
46     aContext->UpdateCurrentViewer();
47 }
48
49 void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
50                            const bool isUpdateViewer)
51 {
52   if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
53     return;
54
55   std::vector<Handle(AIS_InteractiveObject)> aDispAIS = myFeature2AISObjectMap[theFeature];
56   std::vector<Handle(AIS_InteractiveObject)>::const_iterator anIt = aDispAIS.begin(),
57                                                              aLast = aDispAIS.end();
58   Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
59   for (; anIt != aLast; anIt++) {
60     Handle(AIS_InteractiveObject) anAIS = *anIt;
61     Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
62     if (anAISShape.IsNull())
63       continue;
64       aContext->Erase(anAISShape);
65   }
66
67   if (isUpdateViewer)
68     aContext->UpdateCurrentViewer();
69 }
70
71 void XGUI_Displayer::LocalSelection(boost::shared_ptr<ModelAPI_Feature> theFeature,
72                                     const TopoDS_Shape& theShape,
73                                     const int theMode, const bool isUpdateViewer)
74 {
75   Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
76
77   Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
78   std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
79   if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
80     aDispAIS = myFeature2AISObjectMap[theFeature];
81   }
82   aDispAIS.push_back(anAIS);
83   myFeature2AISObjectMap[theFeature] = aDispAIS;
84   aContext->Display(anAIS, Standard_False);
85
86   AIS_ListOfInteractive anAISList;
87   anAISList.Append(anAIS);
88   myViewer->setLocalSelection(anAISList, theMode, true);
89 }
90
91 void XGUI_Displayer::GlobalSelection(const bool isUpdateViewer)
92 {
93   myViewer->setGlobalSelection(true);
94 }
95