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 boost::shared_ptr<ModelAPI_Feature> XGUI_Displayer::GetFeature(const TopoDS_Shape& theShape)
58 boost::shared_ptr<ModelAPI_Feature> aFeature;
60 FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
61 aFLast = myFeature2AISObjectMap.end();
62 for (; aFIt != aFLast && !aFeature; aFIt++)
64 std::vector<Handle(AIS_InteractiveObject)> aDispAIS = (*aFIt).second;
65 std::vector<Handle(AIS_InteractiveObject)>::const_iterator anIt = aDispAIS.begin(),
66 aLast = aDispAIS.end();
67 Handle(AIS_InteractiveContext) aContext = AISContext();
68 for (; anIt != aLast && !aFeature; anIt++) {
69 Handle(AIS_InteractiveObject) anAIS = *anIt;
70 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
71 if (!anAISShape.IsNull() && anAISShape->Shape() == theShape) {
72 aFeature = (*aFIt).first;
80 void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
81 const bool isUpdateViewer)
83 if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
86 std::vector<Handle(AIS_InteractiveObject)> aDispAIS = myFeature2AISObjectMap[theFeature];
87 std::vector<Handle(AIS_InteractiveObject)>::const_iterator anIt = aDispAIS.begin(),
88 aLast = aDispAIS.end();
89 Handle(AIS_InteractiveContext) aContext = AISContext();
90 for (; anIt != aLast; anIt++) {
91 Handle(AIS_InteractiveObject) anAIS = *anIt;
92 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
93 if (anAISShape.IsNull())
95 aContext->Erase(anAISShape);
97 myFeature2AISObjectMap.erase(theFeature);
100 aContext->UpdateCurrentViewer();
103 void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
104 const TopoDS_Shape& theShape,
105 const std::list<int>& theModes, const bool isUpdateViewer)
107 Handle(AIS_InteractiveContext) aContext = AISContext();
109 if (IsVisible(theFeature)) {
110 Erase(theFeature, false);
113 Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
114 std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
115 if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
116 aDispAIS = myFeature2AISObjectMap[theFeature];
118 aDispAIS.push_back(anAIS);
119 myFeature2AISObjectMap[theFeature] = aDispAIS;
121 Handle(AIS_InteractiveContext) ic = AISContext();
123 // Open local context if there is no one
124 if (!ic->HasOpenedContext()) {
125 ic->ClearCurrents(false);
126 ic->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/,
127 true/*allow shape decomposition*/);
129 // Activate selection of objects from prs
130 if (!anAIS.IsNull()) {
131 if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) {
132 ic->Display(anAIS, false);
133 ic->Load(anAIS, -1, true/*allow decomposition*/);
134 std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
135 for (; anIt != aLast; anIt++)
136 ic->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt));
140 ic->UpdateCurrentViewer();
143 void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer)
145 closeAllContexts(true);
148 void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer)
150 Handle(AIS_InteractiveContext) ic = AISContext();
152 ic->CloseAllContexts(false);
154 ic->UpdateCurrentViewer();
158 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
160 return myWorkshop->viewer()->AISContext();