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>
34 #include <TopExp_Explorer.hxx>
36 IMPLEMENT_STANDARD_HANDLE(ModuleBase_BRepOwner, StdSelect_BRepOwner);
37 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner);
39 //*******************************************************************************************
41 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape);
42 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
48 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
49 : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myAdditionalSelectionPriority(0)
51 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
52 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
54 Handle(Prs3d_Drawer) aDrawer = Attributes();
55 if (aDrawer->HasOwnPointAspect())
56 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
58 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
60 // Activate individual repaintng if this is a part of compsolid
61 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
62 SetAutoHilight(aCompSolid.get() == NULL);
64 ModuleBase_Tools::setPointBallHighlighting(this);
67 void ModuleBase_ResultPrs::setAdditionalSelectionPriority(const int thePriority)
69 myAdditionalSelectionPriority = thePriority;
72 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
73 const Handle(Prs3d_Presentation)& thePresentation,
74 const Standard_Integer theMode)
76 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
77 bool aReadyToDisplay = aShapePtr.get();
78 if (aReadyToDisplay) {
79 myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
80 if (!myOriginalShape.IsNull())
83 // change deviation coefficient to provide more precise circle
84 //ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes());
85 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
87 if (!aReadyToDisplay) {
88 Events_InfoMessage("ModuleBase_ResultPrs", "An empty AIS presentation: ModuleBase_ResultPrs").send();
89 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
90 ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent);
94 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
95 const Standard_Integer aMode)
97 if (aMode > TopAbs_SHAPE) {
98 // In order to avoid using custom selection modes
99 if (aMode == ModuleBase_ResultPrs::Sel_Result) {
100 AIS_Shape::ComputeSelection(aSelection, TopAbs_COMPOUND);
105 // TODO: OCCT issue should be created for the COMPOUND processing
106 // before it is fixed, the next workaround in necessary
107 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPOUND)) {
108 const TopoDS_Shape& aShape = Shape();
109 TopExp_Explorer aCompExp(aShape, TopAbs_COMPOUND);
110 // do not activate in compound mode shapes which do not contain compounds
111 if (!aCompExp.More())
115 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
116 // Limit selection area only by actual object (Shape)
117 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
118 if (aCompSolid.get()) {
119 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
120 if (aShapePtr.get()) {
121 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
122 int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_COMPSOLID);
123 /// It is important to have priority for the shape of comp solid result less than priority
124 /// for the presentation shape which is a sub-result. 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)::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId());
140 //AIS_Shape::ComputeSelection(aSelection, 0);
142 AIS_Shape::ComputeSelection(aSelection, aMode);
144 if (myAdditionalSelectionPriority > 0) {
145 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
146 Handle(SelectBasics_EntityOwner) aBasicsOwner = aSelection->Sensitive()->BaseSensitive()->OwnerId();
147 if (!aBasicsOwner.IsNull())
148 aBasicsOwner->Set(aBasicsOwner->Priority() + myAdditionalSelectionPriority);
153 void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection,
154 const TopoDS_Shape& theShape)
156 static TopAbs_ShapeEnum TypOfSel
157 = AIS_Shape::SelectionType(AIS_Shape::SelectionMode(TopAbs_WIRE));
158 // POP protection against crash in low layers
159 Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer);
161 StdSelect_BRepSelectionTool::Load(theSelection,
166 myDrawer->HLRAngle(),
167 myDrawer->IsAutoTriangulation());
168 } catch ( Standard_Failure ) {
172 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
173 const SelectMgr_SequenceOfOwner& theOwners)
175 Handle(SelectMgr_EntityOwner) anOwner;
176 Handle(ModuleBase_BRepOwner) aCompOwner;
177 for (int i = 1; i <= theOwners.Length(); i++) {
178 anOwner = theOwners.Value(i);
179 aCompOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
180 if (aCompOwner.IsNull())
181 anOwner->Hilight(thePM);
183 TopoDS_Shape aShape = aCompOwner->Shape();
184 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
185 aSelectionPrs->Clear();
187 StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer);
189 aSelectionPrs->SetDisplayPriority(9);
190 aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor());
191 aSelectionPrs->Display();
192 thePM->Highlight(this);
197 void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
198 const Quantity_NameOfColor theColor,
199 const Handle(SelectMgr_EntityOwner)& theOwner)
201 Handle(StdSelect_BRepOwner) aOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
205 TopoDS_Shape aShape = aOwner->Shape();
206 if (!aShape.IsNull()) {
207 thePM->Color(this, theColor);
209 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
210 aHilightPrs->Clear();
212 StdPrs_WFDeflectionShape::Add(aHilightPrs, aShape, myDrawer);
213 aHilightPrs->Highlight(Aspect_TOHM_COLOR, theColor);
215 if (thePM->IsImmediateModeOn())
216 thePM->AddToImmediateList(aHilightPrs);