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_Error.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>
24 #include <SelectMgr_SequenceOfOwner.hxx>
25 #include <SelectMgr_EntityOwner.hxx>
26 #include <SelectMgr_SelectionManager.hxx>
27 #include <StdPrs_WFDeflectionShape.hxx>
28 #include <StdSelect_BRepSelectionTool.hxx>
29 #include <AIS_InteractiveContext.hxx>
30 #include <AIS_Selection.hxx>
31 #include <TColStd_ListIteratorOfListOfInteger.hxx>
33 IMPLEMENT_STANDARD_HANDLE(ModuleBase_BRepOwner, StdSelect_BRepOwner);
34 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner);
36 //*******************************************************************************************
38 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape);
39 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
45 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
46 : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult)
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);
62 bool ModuleBase_ResultPrs::isValidShapeType(const TopAbs_ShapeEnum& theBaseType,
63 const TopAbs_ShapeEnum& theCheckedType)
65 bool aValid = theBaseType == theCheckedType;
67 // currently this functionality is for all, as we have no separate wire selection mode
68 // lately it should be corrected to have the following check only for sketch presentations
69 aValid = theBaseType == TopAbs_FACE && theCheckedType == TopAbs_WIRE;
74 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
75 const Handle(Prs3d_Presentation)& thePresentation,
76 const Standard_Integer theMode)
78 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
79 bool aReadyToDisplay = aShapePtr.get();
80 if (aReadyToDisplay) {
81 myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
82 if (!myOriginalShape.IsNull())
85 // change deviation coefficient to provide more precise circle
86 ModuleBase_Tools::setDefaultDeviationCoefficient(Shape(), Attributes());
87 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
89 if (!aReadyToDisplay) {
90 Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs");
91 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
92 ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
96 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
97 const Standard_Integer aMode)
100 // In order to avoid using custom selection modes
103 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
104 // Limit selection area only by actual object (Shape)
105 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
106 if (aCompSolid.get()) {
107 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
108 if (aShapePtr.get()) {
109 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
110 int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_SHAPE);
111 double aDeflection = Prs3d::GetDeflection(aShape, myDrawer);
113 Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority);
114 StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection,
115 aDeflection, myDrawer->HLRAngle(), 9, 500);
117 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
118 Handle(SelectMgr_EntityOwner) anOwner =
119 Handle(SelectMgr_EntityOwner)::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId());
125 //AIS_Shape::ComputeSelection(aSelection, 0);
127 AIS_Shape::ComputeSelection(aSelection, aMode);
130 void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection,
131 const TopoDS_Shape& theShape)
133 static TopAbs_ShapeEnum TypOfSel
134 = AIS_Shape::SelectionType(AIS_Shape::SelectionMode(TopAbs_WIRE));
135 // POP protection against crash in low layers
136 Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer);
138 StdSelect_BRepSelectionTool::Load(theSelection,
143 myDrawer->HLRAngle(),
144 myDrawer->IsAutoTriangulation());
145 } catch ( Standard_Failure ) {
149 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
150 const SelectMgr_SequenceOfOwner& theOwners)
152 Handle(SelectMgr_EntityOwner) anOwner;
153 Handle(ModuleBase_BRepOwner) aCompOwner;
154 for (int i = 1; i <= theOwners.Length(); i++) {
155 anOwner = theOwners.Value(i);
156 aCompOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
157 if (aCompOwner.IsNull())
158 anOwner->Hilight(thePM);
160 TopoDS_Shape aShape = aCompOwner->Shape();
161 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
162 aSelectionPrs->Clear();
164 StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer);
166 aSelectionPrs->SetDisplayPriority(9);
167 aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor());
168 aSelectionPrs->Display();
169 thePM->Highlight(this);
174 void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
175 const Quantity_NameOfColor theColor,
176 const Handle(SelectMgr_EntityOwner)& theOwner)
178 Handle(StdSelect_BRepOwner) aOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
182 TopoDS_Shape aShape = aOwner->Shape();
183 if (!aShape.IsNull()) {
184 thePM->Color(this, theColor);
186 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
187 aHilightPrs->Clear();
189 StdPrs_WFDeflectionShape::Add(aHilightPrs, aShape, myDrawer);
190 aHilightPrs->Highlight(Aspect_TOHM_COLOR, theColor);
192 if (thePM->IsImmediateModeOn())
193 thePM->AddToImmediateList(aHilightPrs);