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 std::list<XGUI_ViewerPrs> XGUI_Displayer::GetViewerPrs
68 (const NCollection_List<TopoDS_Shape>& theShapes)
70 std::list<XGUI_ViewerPrs> aPresentations;
71 if (theShapes.IsEmpty())
72 return aPresentations;
74 NCollection_List<TopoDS_Shape>::Iterator anIt(theShapes);
75 for (; anIt.More(); anIt.Next()) {
76 const TopoDS_Shape& aShape = anIt.Value();
79 boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(aShape);
80 aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
83 return aPresentations;
86 void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
87 const bool isUpdateViewer)
89 if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
92 Handle(AIS_InteractiveContext) aContext = AISContext();
93 Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[theFeature];
94 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
95 if (!anAISShape.IsNull())
97 aContext->Erase(anAISShape);
99 myFeature2AISObjectMap.erase(theFeature);
102 aContext->UpdateCurrentViewer();
105 void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
106 const TopoDS_Shape& theShape,
107 const std::list<int>& theModes, const bool isUpdateViewer)
109 Handle(AIS_InteractiveContext) aContext = AISContext();
110 // Open local context if there is no one
111 if (!aContext->HasOpenedContext()) {
112 aContext->ClearCurrents(false);
113 aContext->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/,
114 true/*allow shape decomposition*/);
116 // display or redisplay presentation
117 Handle(AIS_Shape) anAIS;
118 if (IsVisible(theFeature)) {
119 anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]);
120 if (!anAIS.IsNull()) {
121 anAIS->Set(theShape);
126 anAIS = new AIS_Shape(theShape);
127 myFeature2AISObjectMap[theFeature] = anAIS;
128 aContext->Display(anAIS, false);
130 // Activate selection of objects from prs
131 if (!anAIS.IsNull()) {
132 aContext->Load(anAIS, -1, true/*allow decomposition*/);
133 std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
134 for (; anIt != aLast; anIt++)
136 aContext->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt));
141 aContext->UpdateCurrentViewer();
144 void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer)
146 closeAllContexts(true);
149 void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer)
151 Handle(AIS_InteractiveContext) ic = AISContext();
153 ic->CloseAllContexts(false);
155 ic->UpdateCurrentViewer();
159 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
161 return myWorkshop->viewer()->AISContext();