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 <AIS_Selection.hxx>
27 #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), myIsSketchMode(false)
46 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
47 std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
48 std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapePtr);
50 if (aWirePtr->hasPlane() ) {
51 // If this is a wire with plane defined thin it is a sketch-like object
52 // It must have invisible faces
53 myIsSketchMode = true;
56 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
58 Handle(Prs3d_Drawer) aDrawer = Attributes();
59 if (aDrawer->HasOwnPointAspect())
60 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS);
62 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.));
64 // Activate individual repaintng if this is a part of compsolid
65 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
66 SetAutoHilight(aCompSolid.get() == NULL);
70 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
71 const Handle(Prs3d_Presentation)& thePresentation,
72 const Standard_Integer theMode)
74 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
80 ResultConstructionPtr aConstruction =
81 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myResult);
82 if (aConstruction.get()) {
83 int aFacesNum = aConstruction->facesNum();
84 for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
85 myFacesList.push_back(aConstruction->face(aFaceIndex));
89 myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
90 if (!myOriginalShape.IsNull()) {
93 // change deviation coefficient to provide more precise circle
94 ModuleBase_Tools::setDefaultDeviationCoefficient(myOriginalShape, Attributes());
95 AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
100 void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
101 const Standard_Integer aMode)
104 // In order to avoid using custom selection modes
108 if (myIsSketchMode) {
109 if (aMode == AIS_Shape::SelectionMode(TopAbs_FACE)) {
110 BRep_Builder aBuilder;
111 TopoDS_Compound aComp;
112 aBuilder.MakeCompound(aComp);
113 aBuilder.Add(aComp, myOriginalShape);
114 std::list<std::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
115 for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
116 TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
117 aBuilder.Add(aComp, aFace);
121 Set(myOriginalShape);
123 if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) {
124 // Limit selection area only by actual object (Shape)
125 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
126 if (aCompSolid.get()) {
127 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
128 if (aShapePtr.get()) {
129 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
130 int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_SHAPE);
131 double aDeflection = Prs3d::GetDeflection(aShape, myDrawer);
133 Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority);
134 StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection,
135 aDeflection, myDrawer->HLRAngle(), 9, 500);
137 for (aSelection->Init(); aSelection->More(); aSelection->Next()) {
138 Handle(SelectMgr_EntityOwner) anOwner =
139 Handle(SelectMgr_EntityOwner)::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId());
145 //AIS_Shape::ComputeSelection(aSelection, 0);
147 AIS_Shape::ComputeSelection(aSelection, aMode);
151 bool ModuleBase_ResultPrs::hasCompSolidSelectionMode() const
153 if (!HasInteractiveContext())
156 Handle(AIS_InteractiveContext) aContext = GetContext();
157 TColStd_ListOfInteger aModes;
158 aContext->ActivatedModes(this, aModes);
160 TColStd_ListIteratorOfListOfInteger aIt(aModes);
161 for (; aIt.More(); aIt.Next()) {
162 if (aIt.Value() == AIS_Shape::SelectionMode(TopAbs_COMPSOLID))
169 TopoDS_Shape ModuleBase_ResultPrs::getSelectionShape() const
171 if (hasCompSolidSelectionMode()) {
172 // In case of CompSolid mode use shape from Parent for highlighting
173 ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult);
174 if (aCompSolid.get()) {
175 std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aCompSolid);
177 return aShapePtr->impl<TopoDS_Shape>();
180 return myOriginalShape;
184 void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
185 const SelectMgr_SequenceOfOwner& theOwners)
187 Handle(SelectMgr_EntityOwner) anOwner;
188 Handle(ModuleBase_BRepOwner) aCompOwner;
189 for (int i = 1; i <= theOwners.Length(); i++) {
190 anOwner = theOwners.Value(i);
191 aCompOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner);
192 if (aCompOwner.IsNull())
193 anOwner->Hilight(thePM);
195 TopoDS_Shape aShape = aCompOwner->Shape();
196 Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
197 aSelectionPrs->Clear();
199 StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer);
201 aSelectionPrs->SetDisplayPriority(9);
202 aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor());
203 aSelectionPrs->Display();
204 thePM->Highlight(this);
209 void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
210 const Quantity_NameOfColor theColor,
211 const Handle(SelectMgr_EntityOwner)& theOwner)
213 Handle(StdSelect_BRepOwner) aOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
217 TopoDS_Shape aShape = aOwner->Shape();
218 if (!aShape.IsNull()) {
219 thePM->Color(this, theColor);
221 Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
222 aHilightPrs->Clear();
224 StdPrs_WFDeflectionShape::Add(aHilightPrs, aShape, myDrawer);
225 aHilightPrs->Highlight(Aspect_TOHM_COLOR, theColor);
227 if (thePM->IsImmediateModeOn())
228 thePM->AddToImmediateList(aHilightPrs);