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_Tools.h>
11 #include <ModelAPI_ResultConstruction.h>
12 #include <GeomAPI_PlanarEdges.h>
14 #include <Events_Error.h>
16 #include <BRep_Builder.hxx>
17 #include <Prs3d_Drawer.hxx>
19 #include <Prs3d_PointAspect.hxx>
20 #include <Prs3d_IsoAspect.hxx>
21 #include <TopoDS_Builder.hxx>
22 #include <SelectMgr_SequenceOfOwner.hxx>
23 #include <SelectMgr_EntityOwner.hxx>
24 #include <SelectMgr_SelectionManager.hxx>
25 #include <StdPrs_WFDeflectionShape.hxx>
26 #include <StdSelect_BRepSelectionTool.hxx>
27 #include <AIS_InteractiveContext.hxx>
28 #include <AIS_Selection.hxx>
29 #include <TColStd_ListIteratorOfListOfInteger.hxx>
31 IMPLEMENT_STANDARD_HANDLE(ModuleBase_BRepOwner, StdSelect_BRepOwner);
32 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner);
34 //*******************************************************************************************
36 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape);
37 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
43 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
44 : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult)
46 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
47 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
49 Handle(Prs3d_Drawer) aDrawer = Attributes();
50 if (aDrawer->HasOwnPointAspect())
51 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
53 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
55 // Activate individual repaintng if this is a part of compsolid
56 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
57 SetAutoHilight(aCompSolid.get() == NULL);
60 bool ModuleBase_ResultPrs::isValidShapeType(const TopAbs_ShapeEnum& theBaseType,
61 const TopAbs_ShapeEnum& theCheckedType)
63 bool aValid = theBaseType == theCheckedType;
65 // currently this functionality is for all, as we have no separate wire selection mode
66 // lately it should be corrected to have the following check only for sketch presentations
67 aValid = theBaseType == TopAbs_FACE && theCheckedType == TopAbs_WIRE;
73 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
74 const Handle(Prs3d_Presentation)& thePresentation,
75 const Standard_Integer theMode)
77 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
79 Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs");
83 myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
84 if (!myOriginalShape.IsNull()) {
87 // change deviation coefficient to provide more precise circle
88 ModuleBase_Tools::setDefaultDeviationCoefficient(myOriginalShape, Attributes());
89 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
92 Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs");
95 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
96 const Standard_Integer aMode)
99 // In order to avoid using custom selection modes
102 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
103 // Limit selection area only by actual object (Shape)
104 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
105 if (aCompSolid.get()) {
106 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
107 if (aShapePtr.get()) {
108 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
109 int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_SHAPE);
110 double aDeflection = Prs3d::GetDeflection(aShape, myDrawer);
112 Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority);
113 StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection,
114 aDeflection, myDrawer->HLRAngle(), 9, 500);
116 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
117 Handle(SelectMgr_EntityOwner) anOwner =
118 Handle(SelectMgr_EntityOwner)::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId());
124 //AIS_Shape::ComputeSelection(aSelection, 0);
126 AIS_Shape::ComputeSelection(aSelection, aMode);
129 void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection,
130 const TopoDS_Shape& theShape)
132 static TopAbs_ShapeEnum TypOfSel
133 = AIS_Shape::SelectionType(AIS_Shape::SelectionMode(TopAbs_WIRE));
134 // POP protection against crash in low layers
135 Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer);
137 StdSelect_BRepSelectionTool::Load(theSelection,
142 myDrawer->HLRAngle(),
143 myDrawer->IsAutoTriangulation());
144 } catch ( Standard_Failure ) {
148 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
149 const SelectMgr_SequenceOfOwner& theOwners)
151 Handle(SelectMgr_EntityOwner) anOwner;
152 Handle(ModuleBase_BRepOwner) aCompOwner;
153 for (int i = 1; i <= theOwners.Length(); i++) {
154 anOwner = theOwners.Value(i);
155 aCompOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
156 if (aCompOwner.IsNull())
157 anOwner->Hilight(thePM);
159 TopoDS_Shape aShape = aCompOwner->Shape();
160 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
161 aSelectionPrs->Clear();
163 StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer);
165 aSelectionPrs->SetDisplayPriority(9);
166 aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor());
167 aSelectionPrs->Display();
168 thePM->Highlight(this);
173 void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
174 const Quantity_NameOfColor theColor,
175 const Handle(SelectMgr_EntityOwner)& theOwner)
177 Handle(StdSelect_BRepOwner) aOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
181 TopoDS_Shape aShape = aOwner->Shape();
182 if (!aShape.IsNull()) {
183 thePM->Color(this, theColor);
185 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
186 aHilightPrs->Clear();
188 StdPrs_WFDeflectionShape::Add(aHilightPrs, aShape, myDrawer);
189 aHilightPrs->Highlight(Aspect_TOHM_COLOR, theColor);
191 if (thePM->IsImmediateModeOn())
192 thePM->AddToImmediateList(aHilightPrs);