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 if (aShapePtr.get()) {
80 myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
81 if (!myOriginalShape.IsNull())
85 Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs");
86 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
87 ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
89 // change deviation coefficient to provide more precise circle
90 ModuleBase_Tools::setDefaultDeviationCoefficient(Shape(), Attributes());
91 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
94 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
95 const Standard_Integer aMode)
98 // In order to avoid using custom selection modes
101 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
102 // Limit selection area only by actual object (Shape)
103 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
104 if (aCompSolid.get()) {
105 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
106 if (aShapePtr.get()) {
107 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
108 int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_SHAPE);
109 double aDeflection = Prs3d::GetDeflection(aShape, myDrawer);
111 Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority);
112 StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection,
113 aDeflection, myDrawer->HLRAngle(), 9, 500);
115 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
116 Handle(SelectMgr_EntityOwner) anOwner =
117 Handle(SelectMgr_EntityOwner)::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId());
123 //AIS_Shape::ComputeSelection(aSelection, 0);
125 AIS_Shape::ComputeSelection(aSelection, aMode);
128 void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection,
129 const TopoDS_Shape& theShape)
131 static TopAbs_ShapeEnum TypOfSel
132 = AIS_Shape::SelectionType(AIS_Shape::SelectionMode(TopAbs_WIRE));
133 // POP protection against crash in low layers
134 Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer);
136 StdSelect_BRepSelectionTool::Load(theSelection,
141 myDrawer->HLRAngle(),
142 myDrawer->IsAutoTriangulation());
143 } catch ( Standard_Failure ) {
147 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
148 const SelectMgr_SequenceOfOwner& theOwners)
150 Handle(SelectMgr_EntityOwner) anOwner;
151 Handle(ModuleBase_BRepOwner) aCompOwner;
152 for (int i = 1; i <= theOwners.Length(); i++) {
153 anOwner = theOwners.Value(i);
154 aCompOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
155 if (aCompOwner.IsNull())
156 anOwner->Hilight(thePM);
158 TopoDS_Shape aShape = aCompOwner->Shape();
159 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
160 aSelectionPrs->Clear();
162 StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer);
164 aSelectionPrs->SetDisplayPriority(9);
165 aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor());
166 aSelectionPrs->Display();
167 thePM->Highlight(this);
172 void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
173 const Quantity_NameOfColor theColor,
174 const Handle(SelectMgr_EntityOwner)& theOwner)
176 Handle(StdSelect_BRepOwner) aOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
180 TopoDS_Shape aShape = aOwner->Shape();
181 if (!aShape.IsNull()) {
182 thePM->Color(this, theColor);
184 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
185 aHilightPrs->Clear();
187 StdPrs_WFDeflectionShape::Add(aHilightPrs, aShape, myDrawer);
188 aHilightPrs->Highlight(Aspect_TOHM_COLOR, theColor);
190 if (thePM->IsImmediateModeOn())
191 thePM->AddToImmediateList(aHilightPrs);