]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Displayer.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[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
74   if (isUpdateViewer)
75     aContext->UpdateCurrentViewer();
76 }
77
78 void XGUI_Displayer::DisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
79                                            const TopoDS_Shape& theShape,
80                                            const int theMode, const bool isUpdateViewer)
81 {
82   Handle(AIS_InteractiveContext) aContext = AISContext();
83   
84   if (IsVisible(theFeature)) {
85     Erase(theFeature, false);
86   }
87
88   Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
89   std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
90   if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
91     aDispAIS = myFeature2AISObjectMap[theFeature];
92   }
93   aDispAIS.push_back(anAIS);
94   myFeature2AISObjectMap[theFeature] = aDispAIS;
95   aContext->Display(anAIS, Standard_False);
96
97   AIS_ListOfInteractive anAISList;
98   anAISList.Append(anAIS);
99   activateInLocalContext(anAISList, theMode, true);
100 }
101
102 void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer)
103 {
104   closeAllContexts(true);
105 }
106
107 void XGUI_Displayer::activateInLocalContext(const AIS_ListOfInteractive& theAISObjects, const int theMode,
108                                             const bool isUpdateViewer)
109 {
110   Handle(AIS_InteractiveContext) ic = AISContext();
111
112   // Open local context if there is no one
113   bool allObjects = false; // calculate by AIS shape
114   if (!ic->HasOpenedContext()) {
115     ic->ClearCurrents(false);
116     ic->OpenLocalContext(allObjects, true, true);
117   }
118
119   // Activate selection of objects from prs
120   AIS_ListIteratorOfListOfInteractive aIter(theAISObjects);
121   for (; aIter.More(); aIter.Next()) {
122     Handle(AIS_InteractiveObject) anAIS = aIter.Value();
123     if (!anAIS.IsNull()) {
124       if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) {
125         ic->Load(anAIS, -1, false);
126         ic->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theMode));
127       }
128       else if (anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron)) {
129         ic->Load(anAIS, -1, false);
130         ic->Activate(anAIS, theMode);
131       }
132     }
133   }
134   if (isUpdateViewer)
135     ic->UpdateCurrentViewer();
136 }
137
138 void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer)
139 {
140   Handle(AIS_InteractiveContext) ic = AISContext();
141   if (!ic.IsNull()) {
142     ic->CloseAllContexts(false);
143     if (isUpdateViewer)
144       ic->UpdateCurrentViewer();
145   }
146 }
147
148 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const 
149
150   return myWorkshop->viewer()->AISContext(); 
151 }