1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_ResultPrs.cpp
4 // Created: 21 October 2014
5 // Author: Vitaly SMETANNIKOV
7 #include "ModuleBase_ResultPrs.h"
8 #include "ModuleBase_Tools.h"
10 #include <ModelAPI_Events.h>
11 #include <ModelAPI_Tools.h>
12 #include <ModelAPI_ResultConstruction.h>
13 #include <ModelAPI_ResultCompSolid.h>
14 #include <GeomAPI_PlanarEdges.h>
16 #include <Events_InfoMessage.h>
17 #include <Events_Loop.h>
19 #include <BRep_Builder.hxx>
20 #include <Prs3d_Drawer.hxx>
22 #include <Prs3d_PointAspect.hxx>
23 #include <Prs3d_IsoAspect.hxx>
24 #include <TopoDS_Builder.hxx>
26 #include <SelectMgr_SequenceOfOwner.hxx>
27 #include <SelectMgr_EntityOwner.hxx>
28 #include <SelectMgr_SelectionManager.hxx>
29 #include <StdPrs_WFShape.hxx>
30 #include <StdSelect_BRepSelectionTool.hxx>
31 #include <AIS_InteractiveContext.hxx>
32 #include <AIS_Selection.hxx>
33 #include <TColStd_ListIteratorOfListOfInteger.hxx>
34 #include <Graphic3d_AspectMarker3d.hxx>
35 #include <TopExp_Explorer.hxx>
37 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner);
39 //*******************************************************************************************
41 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
45 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
46 : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myAdditionalSelectionPriority(0)
48 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
49 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
51 Handle(Prs3d_Drawer) aDrawer = Attributes();
52 if (aDrawer->HasOwnPointAspect())
53 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
55 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
57 // Activate individual repaintng if this is a part of compsolid
58 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
59 SetAutoHilight(aCompSolid.get() == NULL);
61 ModuleBase_Tools::setPointBallHighlighting(this);
64 void ModuleBase_ResultPrs::setAdditionalSelectionPriority(const int thePriority)
66 myAdditionalSelectionPriority = thePriority;
69 void ModuleBase_ResultPrs::Compute(
70 const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
71 const Handle(Prs3d_Presentation)& thePresentation,
72 const Standard_Integer theMode)
74 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
75 bool aReadyToDisplay = aShapePtr.get();
76 if (aReadyToDisplay) {
77 myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
78 if (!myOriginalShape.IsNull())
81 // change deviation coefficient to provide more precise circle
82 //ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
83 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
85 if (!aReadyToDisplay) {
86 Events_InfoMessage("ModuleBase_ResultPrs",
87 "An empty AIS presentation: ModuleBase_ResultPrs").send();
88 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
89 ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
93 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
94 const Standard_Integer aMode)
96 if (aMode > TopAbs_SHAPE) {
97 // In order to avoid using custom selection modes
98 if (aMode == ModuleBase_ResultPrs::Sel_Result) {
99 AIS_Shape::ComputeSelection(aSelection, TopAbs_COMPOUND);
104 // TODO: OCCT issue should be created for the COMPOUND processing
105 // before it is fixed, the next workaround in necessary
106 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPOUND)) {
107 const TopoDS_Shape& aShape = Shape();
108 TopExp_Explorer aCompExp(aShape, TopAbs_COMPOUND);
109 // do not activate in compound mode shapes which do not contain compounds
110 if (!aCompExp.More())
114 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
115 // Limit selection area only by actual object (Shape)
116 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
117 if (aCompSolid.get()) {
118 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
119 if (aShapePtr.get()) {
120 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
121 int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_COMPSOLID);
122 /// It is important to have priority for the shape of comp solid result less than priority
123 /// for the presentation shape which is a sub-result.
124 /// Reason is to select the sub-objects before: #1592
125 aPriority = aPriority - 1;
126 double aDeflection = Prs3d::GetDeflection(aShape, myDrawer);
128 Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority);
129 StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection,
130 aDeflection, myDrawer->HLRAngle(), 9, 500);
132 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
133 Handle(SelectMgr_EntityOwner) anOwner =
134 Handle(SelectMgr_EntityOwner)
135 ::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId());
141 //AIS_Shape::ComputeSelection(aSelection, 0);
143 AIS_Shape::ComputeSelection(aSelection, aMode);
145 if (myAdditionalSelectionPriority > 0) {
146 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
147 Handle(SelectBasics_EntityOwner) aBasicsOwner =
148 aSelection->Sensitive()->BaseSensitive()->OwnerId();
149 if (!aBasicsOwner.IsNull())
150 aBasicsOwner->Set(aBasicsOwner->Priority() + myAdditionalSelectionPriority);
155 void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection,
156 const TopoDS_Shape& theShape)
158 static TopAbs_ShapeEnum TypOfSel
159 = AIS_Shape::SelectionType(AIS_Shape::SelectionMode(TopAbs_WIRE));
160 // POP protection against crash in low layers
161 Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer);
163 StdSelect_BRepSelectionTool::Load(theSelection,
168 myDrawer->HLRAngle(),
169 myDrawer->IsAutoTriangulation());
170 } catch ( Standard_Failure ) {
174 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
175 const SelectMgr_SequenceOfOwner& theOwners)
177 Handle(SelectMgr_EntityOwner) anOwner;
178 Handle(ModuleBase_BRepOwner) aCompOwner;
179 for (int i = 1; i <= theOwners.Length(); i++) {
180 anOwner = theOwners.Value(i);
181 aCompOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
182 if (aCompOwner.IsNull()) {
183 thePM->Color(anOwner->Selectable(), GetContext()->SelectionStyle());
186 TopoDS_Shape aShape = aCompOwner->Shape();
187 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
188 aSelectionPrs->Clear();
190 StdPrs_WFShape::Add(aSelectionPrs, aShape, myDrawer);
192 aSelectionPrs->SetDisplayPriority(9);
193 aSelectionPrs->Highlight(GetContext()->SelectionStyle());
194 aSelectionPrs->Display();
195 thePM->Color(this, GetContext()->SelectionStyle());
200 void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
201 const Handle(Graphic3d_HighlightStyle)& theStyle,
202 const Handle(SelectMgr_EntityOwner)& theOwner)
204 Handle(StdSelect_BRepOwner) aOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
208 TopoDS_Shape aShape = aOwner->Shape();
209 if (!aShape.IsNull()) {
210 thePM->Color(this, theStyle);
212 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
213 aHilightPrs->Clear();
215 StdPrs_WFShape::Add(aHilightPrs, aShape, myDrawer);
216 aHilightPrs->Highlight(theStyle);
218 if (thePM->IsImmediateModeOn())
219 thePM->AddToImmediateList(aHilightPrs);