Salome HOME
acb5c6b4e6166b76051dba0290ce6c3f5685a0d0
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Projection.cpp
1 // Copyright (C) 2019-2023  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <GeomAlgoAPI_Projection.h>
21
22 #include <GeomAPI_Curve.h>
23 #include <GeomAPI_Edge.h>
24 #include <GeomAPI_Pln.h>
25
26 #include <Geom_Curve.hxx>
27 #include <Geom_Plane.hxx>
28 #include <GeomProjLib.hxx>
29
30 #include <BRep_Tool.hxx>
31 #include <Geom_TrimmedCurve.hxx>
32 #include <TopoDS.hxx>
33 #include <TopoDS_Edge.hxx>
34
35 GeomAlgoAPI_Projection::GeomAlgoAPI_Projection(const GeomPlanePtr& thePlane)
36   : myPlane(thePlane)
37 {
38 }
39
40 GeomCurvePtr GeomAlgoAPI_Projection::project(const GeomCurvePtr& theCurve)
41 {
42   Handle(Geom_Curve) aCurve = theCurve->impl<Handle_Geom_Curve>();
43   Handle(Geom_Plane) aPlane = new Geom_Plane(myPlane->impl<gp_Ax3>());
44
45   Handle(Geom_Curve) aProj =
46       GeomProjLib::ProjectOnPlane(aCurve, aPlane, aPlane->Axis().Direction(), false);
47
48   GeomCurvePtr aProjCurve(new GeomAPI_Curve);
49   aProjCurve->setImpl(new Handle_Geom_Curve(aProj));
50   return aProjCurve;
51 }
52
53 GeomCurvePtr GeomAlgoAPI_Projection::project(const GeomEdgePtr& theEdge)
54 {
55   GeomCurvePtr aCurve(new GeomAPI_Curve);
56
57   const TopoDS_Shape& aShape = theEdge->impl<TopoDS_Shape>();
58   TopoDS_Edge anEdge = TopoDS::Edge(aShape);
59   if (!anEdge.IsNull()) {
60     double aStart, aEnd;
61     Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, aStart, aEnd);
62     if (!anEdgeCurve.IsNull() && !BRep_Tool::IsClosed(anEdge))
63       anEdgeCurve = new Geom_TrimmedCurve(anEdgeCurve, aStart, aEnd);
64     aCurve->setImpl(new Handle_Geom_Curve(anEdgeCurve));
65   }
66
67   return project(aCurve);
68 }