Salome HOME
Update copyrights
[modules/shaper.git] / src / GeomAPI / GeomAPI_Curve.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
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<GeomAPI_Curve.h>
21 #include<GeomAPI_Pnt.h>
22
23 #include <TopoDS_Shape.hxx>
24 #include <Geom_Curve.hxx>
25 #include <Geom_Line.hxx>
26 #include <Geom_Circle.hxx>
27 #include <BRep_Tool.hxx>
28 #include <TopoDS_Edge.hxx>
29 #include <TopoDS.hxx>
30 #include <GeomAdaptor_Curve.hxx>
31
32 #define MY_CURVE (*(implPtr<Handle_Geom_Curve>()))
33
34 GeomAPI_Curve::GeomAPI_Curve()
35     : GeomAPI_Interface(new Handle_Geom_Curve()), myStart(0), myEnd(1)
36 {
37 }
38
39 GeomAPI_Curve::GeomAPI_Curve(const std::shared_ptr<GeomAPI_Shape>& theShape)
40   : GeomAPI_Interface(new Handle_Geom_Curve()) // initially it is null
41 {
42   const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
43   TopoDS_Edge anEdge = TopoDS::Edge(aShape);
44   if (!anEdge.IsNull()) {
45     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, myStart, myEnd);
46     if (!aCurve.IsNull()) {
47       setImpl(new Handle(Geom_Curve)(aCurve));
48     }
49   }
50 }
51
52 bool GeomAPI_Curve::isNull() const
53 {
54   return MY_CURVE.IsNull() == Standard_True;
55 }
56
57 bool GeomAPI_Curve::isLine() const
58 {
59   return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Line);
60 }
61
62 bool GeomAPI_Curve::isCircle() const
63 {
64   return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle);
65 }
66
67 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Curve::getPoint(double theParam)
68 {
69   GeomAdaptor_Curve aAdaptor(MY_CURVE, myStart, myEnd);
70   gp_Pnt aPnt = aAdaptor.Value(theParam);
71   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
72 }