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 <GeomAPI_PlanarEdges.h>
15 #include <Events_InfoMessage.h>
16 #include <Events_Loop.h>
18 #include <BRep_Builder.hxx>
19 #include <Prs3d_Drawer.hxx>
21 #include <Prs3d_PointAspect.hxx>
22 #include <Prs3d_IsoAspect.hxx>
23 #include <TopoDS_Builder.hxx>
25 #include <SelectMgr_SequenceOfOwner.hxx>
26 #include <SelectMgr_EntityOwner.hxx>
27 #include <SelectMgr_SelectionManager.hxx>
28 #include <StdPrs_WFDeflectionShape.hxx>
29 #include <StdSelect_BRepSelectionTool.hxx>
30 #include <AIS_InteractiveContext.hxx>
31 #include <AIS_Selection.hxx>
32 #include <TColStd_ListIteratorOfListOfInteger.hxx>
33 #include <Graphic3d_AspectMarker3d.hxx>
35 IMPLEMENT_STANDARD_HANDLE(ModuleBase_BRepOwner, StdSelect_BRepOwner);
36 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner);
38 //*******************************************************************************************
40 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape);
41 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
47 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
48 : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult)
50 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
51 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
53 Handle(Prs3d_Drawer) aDrawer = Attributes();
54 if (aDrawer->HasOwnPointAspect())
55 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
57 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
59 // Activate individual repaintng if this is a part of compsolid
60 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
61 SetAutoHilight(aCompSolid.get() == NULL);
63 ModuleBase_Tools::setPointBallHighlighting(this);
66 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
67 const Handle(Prs3d_Presentation)& thePresentation,
68 const Standard_Integer theMode)
70 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
71 bool aReadyToDisplay = aShapePtr.get();
72 if (aReadyToDisplay) {
73 myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
74 if (!myOriginalShape.IsNull())
77 // change deviation coefficient to provide more precise circle
78 ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
79 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
81 if (!aReadyToDisplay) {
82 Events_InfoMessage("ModuleBase_ResultPrs", "An empty AIS presentation: ModuleBase_ResultPrs").send();
83 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
84 ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
88 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
89 const Standard_Integer aMode)
92 // In order to avoid using custom selection modes
95 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
96 // Limit selection area only by actual object (Shape)
97 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
98 if (aCompSolid.get()) {
99 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
100 if (aShapePtr.get()) {
101 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
102 int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_SHAPE);
103 double aDeflection = Prs3d::GetDeflection(aShape, myDrawer);
105 Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority);
106 StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection,
107 aDeflection, myDrawer->HLRAngle(), 9, 500);
109 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
110 Handle(SelectMgr_EntityOwner) anOwner =
111 Handle(SelectMgr_EntityOwner)::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId());
117 //AIS_Shape::ComputeSelection(aSelection, 0);
119 AIS_Shape::ComputeSelection(aSelection, aMode);
122 void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection,
123 const TopoDS_Shape& theShape)
125 static TopAbs_ShapeEnum TypOfSel
126 = AIS_Shape::SelectionType(AIS_Shape::SelectionMode(TopAbs_WIRE));
127 // POP protection against crash in low layers
128 Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer);
130 StdSelect_BRepSelectionTool::Load(theSelection,
135 myDrawer->HLRAngle(),
136 myDrawer->IsAutoTriangulation());
137 } catch ( Standard_Failure ) {
141 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
142 const SelectMgr_SequenceOfOwner& theOwners)
144 Handle(SelectMgr_EntityOwner) anOwner;
145 Handle(ModuleBase_BRepOwner) aCompOwner;
146 for (int i = 1; i <= theOwners.Length(); i++) {
147 anOwner = theOwners.Value(i);
148 aCompOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
149 if (aCompOwner.IsNull())
150 anOwner->Hilight(thePM);
152 TopoDS_Shape aShape = aCompOwner->Shape();
153 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
154 aSelectionPrs->Clear();
156 StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer);
158 aSelectionPrs->SetDisplayPriority(9);
159 aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor());
160 aSelectionPrs->Display();
161 thePM->Highlight(this);
166 void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
167 const Quantity_NameOfColor theColor,
168 const Handle(SelectMgr_EntityOwner)& theOwner)
170 Handle(StdSelect_BRepOwner) aOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
174 TopoDS_Shape aShape = aOwner->Shape();
175 if (!aShape.IsNull()) {
176 thePM->Color(this, theColor);
178 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
179 aHilightPrs->Clear();
181 StdPrs_WFDeflectionShape::Add(aHilightPrs, aShape, myDrawer);
182 aHilightPrs->Highlight(Aspect_TOHM_COLOR, theColor);
184 if (thePM->IsImmediateModeOn())
185 thePM->AddToImmediateList(aHilightPrs);