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 <BRep_Builder.hxx>
15 #include <Prs3d_Drawer.hxx>
17 #include <Prs3d_PointAspect.hxx>
18 #include <Prs3d_IsoAspect.hxx>
19 #include <TopoDS_Builder.hxx>
20 #include <SelectMgr_SequenceOfOwner.hxx>
21 #include <SelectMgr_EntityOwner.hxx>
22 #include <SelectMgr_SelectionManager.hxx>
23 #include <StdPrs_WFDeflectionShape.hxx>
24 #include <StdSelect_BRepSelectionTool.hxx>
25 #include <AIS_InteractiveContext.hxx>
26 #include <TColStd_ListIteratorOfListOfInteger.hxx>
30 IMPLEMENT_STANDARD_HANDLE(ModuleBase_BRepOwner, StdSelect_BRepOwner);
31 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner);
33 //*******************************************************************************************
35 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape);
36 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape);
42 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
43 : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false)
45 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
46 std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
47 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapePtr);
49 if (aWirePtr->hasPlane() ) {
50 // If this is a wire with plane defined thin it is a sketch-like object
51 // It must have invisible faces
52 myIsSketchMode = true;
55 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
57 Handle(Prs3d_Drawer) aDrawer = Attributes();
58 if (aDrawer->HasOwnPointAspect())
59 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
61 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
63 // Activate individual repaintng if this is a part of compsolid
64 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
65 SetAutoHilight(aCompSolid.get() == NULL);
69 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
70 const Handle(Prs3d_Presentation)& thePresentation,
71 const Standard_Integer theMode)
73 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
79 ResultConstructionPtr aConstruction =
80 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myResult);
81 if (aConstruction.get()) {
82 int aFacesNum = aConstruction->facesNum();
83 for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
84 myFacesList.push_back(aConstruction->face(aFaceIndex));
88 myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
89 if (!myOriginalShape.IsNull()) {
92 // change deviation coefficient to provide more precise circle
93 ModuleBase_Tools::setDefaultDeviationCoefficient(myOriginalShape, Attributes());
94 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
99 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
100 const Standard_Integer aMode)
103 // In order to avoid using custom selection modes
107 if (myIsSketchMode) {
108 if (aMode == AIS_Shape::SelectionMode(TopAbs_FACE)) {
109 BRep_Builder aBuilder;
110 TopoDS_Compound aComp;
111 aBuilder.MakeCompound(aComp);
112 aBuilder.Add(aComp, myOriginalShape);
113 std::list<std::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
114 for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
115 TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
116 aBuilder.Add(aComp, aFace);
120 Set(myOriginalShape);
122 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
123 // Limit selection area only by actual object (Shape)
124 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
125 if (aCompSolid.get()) {
126 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
127 if (aShapePtr.get()) {
128 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
129 int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_SHAPE);
130 double aDeflection = Prs3d::GetDeflection(aShape, myDrawer);
132 Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority);
133 StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection,
134 aDeflection, myDrawer->HLRAngle(), 9, 500);
136 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
137 Handle(SelectMgr_EntityOwner) anOwner
138 = Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Sensitive()->BaseSensitive()->OwnerId());
144 //AIS_Shape::ComputeSelection(aSelection, 0);
146 AIS_Shape::ComputeSelection(aSelection, aMode);
150 bool ModuleBase_ResultPrs::hasCompSolidSelectionMode() const
152 if (!HasInteractiveContext())
155 Handle(AIS_InteractiveContext) aContext = GetContext();
156 TColStd_ListOfInteger aModes;
157 aContext->ActivatedModes(this, aModes);
159 TColStd_ListIteratorOfListOfInteger aIt(aModes);
160 for (; aIt.More(); aIt.Next()) {
161 if (aIt.Value() == AIS_Shape::SelectionMode(TopAbs_COMPSOLID))
168 TopoDS_Shape ModuleBase_ResultPrs::getSelectionShape() const
170 if (hasCompSolidSelectionMode()) {
171 // In case of CompSolid mode use shape from Parent for highlighting
172 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
173 if (aCompSolid.get()) {
174 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
176 return aShapePtr->impl<TopoDS_Shape>();
179 return myOriginalShape;
183 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
184 const SelectMgr_SequenceOfOwner& theOwners)
186 TopoDS_Shape aShape = getSelectionShape();
187 if (!aShape.IsNull()) {
188 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
189 aSelectionPrs->Clear();
191 StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer);
193 aSelectionPrs->SetDisplayPriority(9);
194 aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor());
195 aSelectionPrs->Display();
196 thePM->Highlight(this);
200 void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
201 const Quantity_NameOfColor theColor,
202 const Handle(SelectMgr_EntityOwner)& theOwner)
204 TopoDS_Shape aShape = getSelectionShape();
205 if (!aShape.IsNull()) {
206 thePM->Color(this, theColor);
208 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
209 aHilightPrs->Clear();
211 StdPrs_WFDeflectionShape::Add(aHilightPrs, aShape, myDrawer);
212 aHilightPrs->Highlight(Aspect_TOHM_COLOR, theColor);
214 if (thePM->IsImmediateModeOn())
215 thePM->AddToImmediateList(aHilightPrs);