]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Displayer.cpp
Salome HOME
c0a57d545ccabd3b0a81eb15c4f231667ffd3fe1
[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 #include "XGUI_Workshop.h"
8 #include "XGUI_ViewerProxy.h"
9
10 #include <ModelAPI_Document.h>
11
12 #include <AIS_InteractiveContext.hxx>
13 #include <AIS_ListOfInteractive.hxx>
14 #include <AIS_ListIteratorOfListOfInteractive.hxx>
15
16 #include <AIS_Shape.hxx>
17
18 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
19 {
20   myWorkshop = theWorkshop;
21 }
22
23 XGUI_Displayer::~XGUI_Displayer()
24 {
25 }
26
27 bool XGUI_Displayer::IsVisible(boost::shared_ptr<ModelAPI_Feature> theFeature)
28 {
29   return myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end();
30 }
31
32 void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
33                              const bool isUpdateViewer)
34 {
35 }
36
37 void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
38                              const TopoDS_Shape& theShape, const bool isUpdateViewer)
39 {
40   Handle(AIS_InteractiveContext) aContext = AISContext();
41
42   Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
43   std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
44   if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
45     aDispAIS = myFeature2AISObjectMap[theFeature];
46   }
47   aDispAIS.push_back(anAIS);
48   myFeature2AISObjectMap[theFeature] = aDispAIS;
49
50   aContext->Display(anAIS, Standard_False);
51
52   if (isUpdateViewer)
53     aContext->UpdateCurrentViewer();
54 }
55
56 void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
57                            const bool isUpdateViewer)
58 {
59   if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
60     return;
61
62   std::vector<Handle(AIS_InteractiveObject)> aDispAIS = myFeature2AISObjectMap[theFeature];
63   std::vector<Handle(AIS_InteractiveObject)>::const_iterator anIt = aDispAIS.begin(),
64                                                              aLast = aDispAIS.end();
65   Handle(AIS_InteractiveContext) aContext = AISContext();
66   for (; anIt != aLast; anIt++) {
67     Handle(AIS_InteractiveObject) anAIS = *anIt;
68     Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
69     if (anAISShape.IsNull())
70       continue;
71       aContext->Erase(anAISShape);
72   }
73   myFeature2AISObjectMap.erase(theFeature);
74
75   if (isUpdateViewer)
76     aContext->UpdateCurrentViewer();
77 }
78
79 void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
80                                              const TopoDS_Shape& theShape,
81                                              const std::list<int>& theModes, const bool isUpdateViewer)
82 {
83   Handle(AIS_InteractiveContext) aContext = AISContext();
84   
85   if (IsVisible(theFeature)) {
86     Erase(theFeature, false);
87   }
88
89   Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
90   std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
91   if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
92     aDispAIS = myFeature2AISObjectMap[theFeature];
93   }
94   aDispAIS.push_back(anAIS);
95   myFeature2AISObjectMap[theFeature] = aDispAIS;
96
97   Handle(AIS_InteractiveContext) ic = AISContext();
98
99   // Open local context if there is no one
100   if (!ic->HasOpenedContext()) {
101     ic->ClearCurrents(false);
102     ic->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/,
103                          true/*allow shape decomposition*/);
104   }
105   // Activate selection of objects from prs
106   if (!anAIS.IsNull()) {
107     if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) {
108       ic->Display(anAIS, false);
109       ic->Load(anAIS, -1, true/*allow decomposition*/);
110       std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
111       for (; anIt != aLast; anIt++) 
112         ic->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt));
113     }
114   }
115   if (isUpdateViewer)
116     ic->UpdateCurrentViewer();
117 }
118
119 void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer)
120 {
121   closeAllContexts(true);
122 }
123
124 void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer)
125 {
126   Handle(AIS_InteractiveContext) ic = AISContext();
127   if (!ic.IsNull()) {
128     ic->CloseAllContexts(false);
129     if (isUpdateViewer)
130       ic->UpdateCurrentViewer();
131   }
132 }
133
134 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const 
135
136   return myWorkshop->viewer()->AISContext(); 
137 }