1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ModuleBase_ArrowPrs.h"
22 #include <Prs3d_ArrowAspect.hxx>
24 #include <Events_Loop.h>
25 #include <ModelAPI_Events.h>
27 #include <BRep_Builder.hxx>
28 #include <BRep_Tool.hxx>
29 #include <GCPnts_AbscissaPoint.hxx>
30 #include <GeomAdaptor_Curve.hxx>
31 #include <Prs3d_Arrow.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Vertex.hxx>
37 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ArrowPrs, AIS_InteractiveContext)
40 ModuleBase_ArrowPrs::ModuleBase_ArrowPrs(const Handle(V3d_Viewer)& theViewer,
41 const GeomEdgePtr& theEdge)
42 : AIS_InteractiveContext(theViewer),
47 //********************************************************************
48 void ModuleBase_ArrowPrs::DrawArrow(const Handle(Prs3d_Presentation)& thePrs,
49 Quantity_Color theColor)
51 Handle(Prs3d_Drawer) aDrawer = myDefaultDrawer;
52 Handle(Prs3d_ArrowAspect) anArrowAspect = aDrawer->ArrowAspect();
54 Handle(Graphic3d_AspectLine3d) PtA = anArrowAspect->Aspect();
55 PtA->SetColor(theColor);
57 Handle(Graphic3d_Group) TheGroup = thePrs->CurrentGroup();
58 TheGroup->SetPrimitivesAspect(PtA);
60 TopoDS_Vertex aV1, aV2;
61 TopoDS_Edge anEdgeE = myEdge->impl<TopoDS_Edge>();
62 anEdgeE.Orientation(TopAbs_FORWARD);
63 if (anEdgeE.IsNull()) return;
65 TopExp::Vertices(anEdgeE, aV1, aV2);
66 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
67 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
71 Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE, fp, lp);
73 if (C.IsNull()) return;
75 if (anEdgeE.Orientation() == TopAbs_FORWARD)
76 C->D1(lp, aP2, aDirVec);
78 C->D1(fp, aP1, aDirVec);
82 GeomAdaptor_Curve aAdC;
84 Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp);
86 if (aDist > gp::Resolution()) {
88 if (anEdgeE.Orientation() == TopAbs_FORWARD)
93 TopoDS_Vertex aVertex;
95 aB.MakeVertex(aVertex, aP2, Precision::Confusion());
96 Prs3d_Arrow::Draw(TheGroup, aP2, aDir, M_PI / 180. * 5., aDist / 10.);
100 //********************************************************************
101 bool ModuleBase_ArrowPrs::Comparator::operator()(const std::shared_ptr<GeomAPI_Edge>& theEdge1,
102 const std::shared_ptr<GeomAPI_Edge>& theEdge2) const
104 const TopoDS_Edge& aShape1 = theEdge1->impl<TopoDS_Edge>();
105 const TopoDS_Edge& aShape2 = theEdge2->impl<TopoDS_Edge>();
106 bool isLess = aShape1.TShape() < aShape2.TShape();
107 if (aShape1.TShape() == aShape2.TShape()) {
108 Standard_Integer aHash1 = aShape1.Location().HashCode(IntegerLast());
109 Standard_Integer aHash2 = aShape2.Location().HashCode(IntegerLast());
110 isLess = aHash1 < aHash2;