1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include<GeomAPI_Curve.h>
22 #include<GeomAPI_Pnt.h>
24 #include <TopoDS_Shape.hxx>
25 #include <Geom_Curve.hxx>
26 #include <Geom_Line.hxx>
27 #include <Geom_Circle.hxx>
28 #include <BRep_Tool.hxx>
29 #include <TopoDS_Edge.hxx>
31 #include <GeomAdaptor_Curve.hxx>
33 #define MY_CURVE (*(implPtr<Handle_Geom_Curve>()))
35 GeomAPI_Curve::GeomAPI_Curve()
36 : GeomAPI_Interface(new Handle_Geom_Curve()), myStart(0), myEnd(1)
40 GeomAPI_Curve::GeomAPI_Curve(const std::shared_ptr<GeomAPI_Shape>& theShape)
41 : GeomAPI_Interface(new Handle_Geom_Curve()) // initially it is null
43 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
44 TopoDS_Edge anEdge = TopoDS::Edge(aShape);
45 if (!anEdge.IsNull()) {
46 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, myStart, myEnd);
47 if (!aCurve.IsNull()) {
48 setImpl(new Handle(Geom_Curve)(aCurve));
53 bool GeomAPI_Curve::isNull() const
55 return MY_CURVE.IsNull() == Standard_True;
58 bool GeomAPI_Curve::isLine() const
60 return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Line);
63 bool GeomAPI_Curve::isCircle() const
65 return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle);
68 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Curve::getPoint(double theParam)
70 GeomAdaptor_Curve aAdaptor(MY_CURVE, myStart, myEnd);
71 gp_Pnt aPnt = aAdaptor.Value(theParam);
72 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));