1 // File: XGUI_Displayer.cpp
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #include "XGUI_Displayer.h"
6 #include "XGUI_Viewer.h"
8 #include <ModelAPI_Document.h>
10 #include <AIS_InteractiveContext.hxx>
11 #include <AIS_ListOfInteractive.hxx>
12 #include <AIS_ListIteratorOfListOfInteractive.hxx>
14 #include <AIS_Shape.hxx>
16 XGUI_Displayer::XGUI_Displayer(const Handle(AIS_InteractiveContext)& theAIS)
18 myAISContext = theAIS;
21 XGUI_Displayer::~XGUI_Displayer()
25 bool XGUI_Displayer::IsVisible(boost::shared_ptr<ModelAPI_Feature> theFeature)
27 return myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end();
30 void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
31 const bool isUpdateViewer)
35 void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
36 const TopoDS_Shape& theShape, const bool isUpdateViewer)
38 Handle(AIS_InteractiveContext) aContext = AISContext();
40 Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
41 std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
42 if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
43 aDispAIS = myFeature2AISObjectMap[theFeature];
45 aDispAIS.push_back(anAIS);
46 myFeature2AISObjectMap[theFeature] = aDispAIS;
48 aContext->Display(anAIS, Standard_False);
51 aContext->UpdateCurrentViewer();
54 void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
55 const bool isUpdateViewer)
57 if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
60 std::vector<Handle(AIS_InteractiveObject)> aDispAIS = myFeature2AISObjectMap[theFeature];
61 std::vector<Handle(AIS_InteractiveObject)>::const_iterator anIt = aDispAIS.begin(),
62 aLast = aDispAIS.end();
63 Handle(AIS_InteractiveContext) aContext = AISContext();
64 for (; anIt != aLast; anIt++) {
65 Handle(AIS_InteractiveObject) anAIS = *anIt;
66 Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
67 if (anAISShape.IsNull())
69 aContext->Erase(anAISShape);
73 aContext->UpdateCurrentViewer();
76 void XGUI_Displayer::LocalSelection(boost::shared_ptr<ModelAPI_Feature> theFeature,
77 const TopoDS_Shape& theShape,
78 const int theMode, const bool isUpdateViewer)
80 Handle(AIS_InteractiveContext) aContext = AISContext();
82 if (IsVisible(theFeature)) {
83 Erase(theFeature, false);
86 Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
87 std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
88 if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
89 aDispAIS = myFeature2AISObjectMap[theFeature];
91 aDispAIS.push_back(anAIS);
92 myFeature2AISObjectMap[theFeature] = aDispAIS;
93 aContext->Display(anAIS, Standard_False);
95 AIS_ListOfInteractive anAISList;
96 anAISList.Append(anAIS);
97 setLocalSelection(anAISList, theMode, true);
100 void XGUI_Displayer::GlobalSelection(const bool isUpdateViewer)
102 setGlobalSelection(true);
105 void XGUI_Displayer::setLocalSelection(const AIS_ListOfInteractive& theAISObjects, const int theMode,
106 const bool isUpdateViewer)
108 Handle(AIS_InteractiveContext) ic = AISContext();
110 // Open local context if there is no one
111 bool allObjects = false; // calculate by AIS shape
112 if (!ic->HasOpenedContext()) {
113 ic->ClearCurrents(false);
114 ic->OpenLocalContext(allObjects, true, true);
117 // Activate selection of objects from prs
118 AIS_ListIteratorOfListOfInteractive aIter(theAISObjects);
119 for (; aIter.More(); aIter.Next()) {
120 Handle(AIS_InteractiveObject) anAIS = aIter.Value();
121 if (!anAIS.IsNull()) {
122 if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) {
123 ic->Load(anAIS, -1, false);
124 ic->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theMode));
126 else if (anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron)) {
127 ic->Load(anAIS, -1, false);
128 ic->Activate(anAIS, theMode);
133 ic->UpdateCurrentViewer();
136 void XGUI_Displayer::setGlobalSelection(const bool isUpdateViewer)
138 Handle(AIS_InteractiveContext) ic = AISContext();
140 ic->CloseAllContexts(false);
142 ic->UpdateCurrentViewer();