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>
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), myIsSketchMode(false)
48 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
49 std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
50 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapePtr);
52 if (aWirePtr->hasPlane() ) {
53 // If this is a wire with plane defined thin it is a sketch-like object
54 // It must have invisible faces
55 myIsSketchMode = true;
58 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
60 Handle(Prs3d_Drawer) aDrawer = Attributes();
61 if (aDrawer->HasOwnPointAspect())
62 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
64 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
66 // Activate individual repaintng if this is a part of compsolid
67 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
68 SetAutoHilight(aCompSolid.get() == NULL);
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);
78 Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs");
84 ResultConstructionPtr aConstruction =
85 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myResult);
86 if (aConstruction.get()) {
87 int aFacesNum = aConstruction->facesNum();
88 for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
89 myFacesList.push_back(aConstruction->face(aFaceIndex));
93 myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
94 if (!myOriginalShape.IsNull()) {
97 // change deviation coefficient to provide more precise circle
98 ModuleBase_Tools::setDefaultDeviationCoefficient(myOriginalShape, Attributes());
99 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
102 Events_Error::throwException("An empty AIS presentation: ModuleBase_ResultPrs");
106 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
107 const Standard_Integer aMode)
110 // In order to avoid using custom selection modes
114 if (myIsSketchMode) {
115 if (aMode == AIS_Shape::SelectionMode(TopAbs_FACE)) {
116 BRep_Builder aBuilder;
117 TopoDS_Compound aComp;
118 aBuilder.MakeCompound(aComp);
119 aBuilder.Add(aComp, myOriginalShape);
120 std::list<std::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
121 for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
122 TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
123 aBuilder.Add(aComp, aFace);
127 Set(myOriginalShape);
129 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
130 // Limit selection area only by actual object (Shape)
131 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
132 if (aCompSolid.get()) {
133 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
134 if (aShapePtr.get()) {
135 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
136 int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_SHAPE);
137 double aDeflection = Prs3d::GetDeflection(aShape, myDrawer);
139 Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority);
140 StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection,
141 aDeflection, myDrawer->HLRAngle(), 9, 500);
143 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
144 Handle(SelectMgr_EntityOwner) anOwner =
145 Handle(SelectMgr_EntityOwner)::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId());
151 //AIS_Shape::ComputeSelection(aSelection, 0);
153 AIS_Shape::ComputeSelection(aSelection, aMode);
157 bool ModuleBase_ResultPrs::hasCompSolidSelectionMode() const
159 if (!HasInteractiveContext())
162 Handle(AIS_InteractiveContext) aContext = GetContext();
163 TColStd_ListOfInteger aModes;
164 aContext->ActivatedModes(this, aModes);
166 TColStd_ListIteratorOfListOfInteger aIt(aModes);
167 for (; aIt.More(); aIt.Next()) {
168 if (aIt.Value() == AIS_Shape::SelectionMode(TopAbs_COMPSOLID))
175 TopoDS_Shape ModuleBase_ResultPrs::getSelectionShape() const
177 if (hasCompSolidSelectionMode()) {
178 // In case of CompSolid mode use shape from Parent for highlighting
179 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
180 if (aCompSolid.get()) {
181 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
183 return aShapePtr->impl<TopoDS_Shape>();
186 return myOriginalShape;
190 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
191 const SelectMgr_SequenceOfOwner& theOwners)
193 Handle(SelectMgr_EntityOwner) anOwner;
194 Handle(ModuleBase_BRepOwner) aCompOwner;
195 for (int i = 1; i <= theOwners.Length(); i++) {
196 anOwner = theOwners.Value(i);
197 aCompOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
198 if (aCompOwner.IsNull())
199 anOwner->Hilight(thePM);
201 TopoDS_Shape aShape = aCompOwner->Shape();
202 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
203 aSelectionPrs->Clear();
205 StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer);
207 aSelectionPrs->SetDisplayPriority(9);
208 aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor());
209 aSelectionPrs->Display();
210 thePM->Highlight(this);
215 void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
216 const Quantity_NameOfColor theColor,
217 const Handle(SelectMgr_EntityOwner)& theOwner)
219 Handle(StdSelect_BRepOwner) aOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
223 TopoDS_Shape aShape = aOwner->Shape();
224 if (!aShape.IsNull()) {
225 thePM->Color(this, theColor);
227 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
228 aHilightPrs->Clear();
230 StdPrs_WFDeflectionShape::Add(aHilightPrs, aShape, myDrawer);
231 aHilightPrs->Highlight(Aspect_TOHM_COLOR, theColor);
233 if (thePM->IsImmediateModeOn())
234 thePM->AddToImmediateList(aHilightPrs);