Salome HOME
Issue #3231: Convert Offset curves to b-splines. Order wires.
[modules/shaper.git] / src / GeomAPI / GeomAPI_BSpline.cpp
1 // Copyright (C) 2019-2020  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_BSpline.h>
21 #include <GeomAPI_Pnt.h>
22
23 #include <Geom_BSplineCurve.hxx>
24
25 #include <GeomConvert.hxx>
26
27 #define MY_BSPLINE (*(implPtr<Handle_Geom_BSplineCurve>()))
28
29 GeomAPI_BSpline::GeomAPI_BSpline (const GeomCurvePtr& theCurve,
30                                   const bool isForced)
31 {
32   GeomCurvePtr anUntrimmedCurve = theCurve->basisCurve();
33   Handle(Geom_Curve) aCurve = anUntrimmedCurve->impl<Handle(Geom_Curve)>();
34   Handle(Geom_BSplineCurve) aBSpl = Handle(Geom_BSplineCurve)::DownCast(aCurve);
35   if (aBSpl.IsNull() && isForced) {
36     // convert to b-spline
37     aBSpl = GeomConvert::CurveToBSplineCurve(aCurve);
38   }
39   if (aBSpl.IsNull())
40     throw Standard_ConstructionError("GeomAPI_BSpline: Curve is not a B-spline");
41   setImpl(new Handle_Geom_BSplineCurve(aBSpl));
42 }
43
44 int GeomAPI_BSpline::degree() const
45 {
46   return MY_BSPLINE->Degree();
47 }
48
49 std::list<GeomPointPtr> GeomAPI_BSpline::poles() const
50 {
51   const TColgp_Array1OfPnt& aBSplPoles = MY_BSPLINE->Poles();
52
53   std::list<GeomPointPtr> aPoles;
54   for (int anIndex = aBSplPoles.Lower(); anIndex <= aBSplPoles.Upper(); ++anIndex) {
55     const gp_Pnt& aPoint = aBSplPoles.Value(anIndex);
56     aPoles.push_back(GeomPointPtr(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z())));
57   }
58   return aPoles;
59 }
60
61 std::list<double> GeomAPI_BSpline::weights() const
62 {
63   std::list<double> aWeights;
64   const TColStd_Array1OfReal* aBSplWeights = MY_BSPLINE->Weights();
65   if (aBSplWeights)
66     aWeights.assign(aBSplWeights->begin(), aBSplWeights->end());
67   return aWeights;
68 }
69
70 std::list<double> GeomAPI_BSpline::knots() const
71 {
72   const TColStd_Array1OfReal& aBSplKnots = MY_BSPLINE->Knots();
73   return std::list<double>(aBSplKnots.begin(), aBSplKnots.end());
74 }
75
76 std::list<int> GeomAPI_BSpline::mults() const
77 {
78   const TColStd_Array1OfInteger& aBSplMults = MY_BSPLINE->Multiplicities();
79   return std::list<int>(aBSplMults.begin(), aBSplMults.end());
80 }
81
82 bool GeomAPI_BSpline::isPeriodic() const
83 {
84   return MY_BSPLINE->IsPeriodic();
85 }