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 myFeature2AISObjectMap[theFeature] = anAIS;
45 aContext->Display(anAIS, Standard_False);
47 aContext->UpdateCurrentViewer();
50 boost::shared_ptr<ModelAPI_Feature> XGUI_Displayer::GetFeature(const TopoDS_Shape& theShape)
52 boost::shared_ptr<ModelAPI_Feature> aFeature;
54 FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
55 aFLast = myFeature2AISObjectMap.end();
56 for (; aFIt != aFLast && !aFeature; aFIt++)
58 Handle(AIS_InteractiveObject) anAIS = (*aFIt).second;
59 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
60 if (!anAISShape.IsNull() && anAISShape->Shape() == theShape) {
61 aFeature = (*aFIt).first;
67 void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
68 const bool isUpdateViewer)
70 if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
73 Handle(AIS_InteractiveContext) aContext = AISContext();
74 Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[theFeature];
75 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
76 if (!anAISShape.IsNull())
78 aContext->Erase(anAISShape);
80 myFeature2AISObjectMap.erase(theFeature);
83 aContext->UpdateCurrentViewer();
86 void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
87 const TopoDS_Shape& theShape,
88 const std::list<int>& theModes, const bool isUpdateViewer)
90 Handle(AIS_InteractiveContext) aContext = AISContext();
91 // Open local context if there is no one
92 if (!aContext->HasOpenedContext()) {
93 aContext->ClearCurrents(false);
94 aContext->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/,
95 true/*allow shape decomposition*/);
97 // display or redisplay presentation
98 Handle(AIS_Shape) anAIS;
99 if (IsVisible(theFeature)) {
100 anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]);
101 if (!anAIS.IsNull()) {
102 anAIS->Set(theShape);
107 anAIS = new AIS_Shape(theShape);
108 myFeature2AISObjectMap[theFeature] = anAIS;
109 aContext->Display(anAIS, false);
111 // Activate selection of objects from prs
112 if (!anAIS.IsNull()) {
113 aContext->Load(anAIS, -1, true/*allow decomposition*/);
114 std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
115 for (; anIt != aLast; anIt++)
117 aContext->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt));
122 aContext->UpdateCurrentViewer();
125 void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer)
127 closeAllContexts(true);
130 void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer)
132 Handle(AIS_InteractiveContext) ic = AISContext();
134 ic->CloseAllContexts(false);
136 ic->UpdateCurrentViewer();
140 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
142 return myWorkshop->viewer()->AISContext();