1 // File: XGUI_Displayer.cpp
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include "XGUI_Displayer.h"
6 #include "XGUI_Viewer.h"
7 #include "XGUI_Workshop.h"
8 #include "XGUI_ViewerProxy.h"
10 #include <ModelAPI_Document.h>
12 #include <AIS_InteractiveContext.hxx>
13 #include <AIS_ListOfInteractive.hxx>
14 #include <AIS_ListIteratorOfListOfInteractive.hxx>
16 #include <AIS_Shape.hxx>
18 XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop)
20 myWorkshop = theWorkshop;
23 XGUI_Displayer::~XGUI_Displayer()
27 bool XGUI_Displayer::IsVisible(boost::shared_ptr<ModelAPI_Feature> theFeature)
29 return myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end();
32 void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
33 const bool isUpdateViewer)
37 void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
38 const TopoDS_Shape& theShape, const bool isUpdateViewer)
40 Handle(AIS_InteractiveContext) aContext = AISContext();
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];
47 aDispAIS.push_back(anAIS);
48 myFeature2AISObjectMap[theFeature] = aDispAIS;
50 aContext->Display(anAIS, Standard_False);
53 aContext->UpdateCurrentViewer();
56 void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
57 const bool isUpdateViewer)
59 if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
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())
71 aContext->Erase(anAISShape);
75 aContext->UpdateCurrentViewer();
78 void XGUI_Displayer::DisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
79 const TopoDS_Shape& theShape,
80 const int theMode, const bool isUpdateViewer)
82 Handle(AIS_InteractiveContext) aContext = AISContext();
84 if (IsVisible(theFeature)) {
85 Erase(theFeature, false);
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];
93 aDispAIS.push_back(anAIS);
94 myFeature2AISObjectMap[theFeature] = aDispAIS;
95 aContext->Display(anAIS, Standard_False);
97 AIS_ListOfInteractive anAISList;
98 anAISList.Append(anAIS);
99 activateInLocalContext(anAISList, theMode, true);
102 void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer)
104 closeAllContexts(true);
107 void XGUI_Displayer::activateInLocalContext(const AIS_ListOfInteractive& theAISObjects, const int theMode,
108 const bool isUpdateViewer)
110 Handle(AIS_InteractiveContext) ic = AISContext();
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);
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));
128 else if (anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron)) {
129 ic->Load(anAIS, -1, false);
130 ic->Activate(anAIS, theMode);
135 ic->UpdateCurrentViewer();
138 void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer)
140 Handle(AIS_InteractiveContext) ic = AISContext();
142 ic->CloseAllContexts(false);
144 ic->UpdateCurrentViewer();
148 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
150 return myWorkshop->viewer()->AISContext();