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);
73 myFeature2AISObjectMap.erase(theFeature);
76 aContext->UpdateCurrentViewer();
79 void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
80 const TopoDS_Shape& theShape,
81 const int theMode, const bool isUpdateViewer)
83 Handle(AIS_InteractiveContext) aContext = AISContext();
85 if (IsVisible(theFeature)) {
86 Erase(theFeature, false);
89 Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
90 std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
91 if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
92 aDispAIS = myFeature2AISObjectMap[theFeature];
94 aDispAIS.push_back(anAIS);
95 myFeature2AISObjectMap[theFeature] = aDispAIS;
97 Handle(AIS_InteractiveContext) ic = AISContext();
99 // Open local context if there is no one
100 if (!ic->HasOpenedContext()) {
101 ic->ClearCurrents(false);
102 ic->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/,
103 true/*allow shape decomposition*/);
105 // Activate selection of objects from prs
106 if (!anAIS.IsNull()) {
107 if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) {
108 ic->Display(anAIS, 0/*display mode*/, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theMode),
109 false/*update viewer*/, true/*allow decomposition*/);
110 /*if (theMode == TopAbs_VERTEX) {
111 ic->ActivateStandardMode(TopAbs_EDGE);
112 ic->ActivateStandardMode(TopAbs_VERTEX);
117 ic->UpdateCurrentViewer();
120 void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer)
122 closeAllContexts(true);
125 void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer)
127 Handle(AIS_InteractiveContext) ic = AISContext();
129 ic->CloseAllContexts(false);
131 ic->UpdateCurrentViewer();
135 Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const
137 return myWorkshop->viewer()->AISContext();