1 #include<HYDROOperations_BSpline.h>
3 #include<TColgp_HArray1OfPnt.hxx>
4 #include<GeomAPI_Interpolate.hxx>
5 #include<GeomConvert_BSplineCurveToBezierCurve.hxx>
6 #include<Geom_BezierCurve.hxx>
8 HYDROOperations_BSpline::HYDROOperations_BSpline(
9 const QList<double>& thePoints,
10 const bool theIsClosed)
12 // fill array for algorithm by the received coordinates
13 int aLen = thePoints.size() / 2;
14 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
15 QList<double>::const_iterator aListIter = thePoints.begin();
16 for (int ind = 1; ind <= aLen; ind++) {
17 gp_Pnt aPnt(gp::Origin());
18 aPnt.SetX(*aListIter);
20 aPnt.SetY(*aListIter);
22 aHCurvePoints->SetValue(ind, aPnt);
25 GeomAPI_Interpolate aGBC(aHCurvePoints, theIsClosed, gp::Resolution());
28 myCurve = aGBC.Curve();
32 QPainterPath HYDROOperations_BSpline::ComputePath() const
35 if (myCurve.IsNull()) // returns an empty Path if original curve is invalid
37 GeomConvert_BSplineCurveToBezierCurve aConverter(myCurve);
38 int a, aNumArcs = aConverter.NbArcs();
39 for(a = 1; a <= aNumArcs; a++) {
40 Handle(Geom_BezierCurve) anArc = aConverter.Arc(a);
41 if (a == 1) { // set a start point
42 gp_Pnt aStart = anArc->StartPoint();
43 aResult.moveTo(aStart.X(), aStart.Y());
45 gp_Pnt anEnd = anArc->EndPoint();
46 if (anArc->NbPoles() == 3) { // quadric segment in the path (pole 1 is start, pole 3 is end)
47 gp_Pnt aPole = anArc->Pole(2);
48 aResult.quadTo(aPole.X(), aPole.Y(), anEnd.X(), anEnd.Y());
49 } else if (anArc->NbPoles() == 4) { // cubic segment (usually this is used)
50 gp_Pnt aPole1 = anArc->Pole(2);
51 gp_Pnt aPole2 = anArc->Pole(3);
53 aPole1.X(), aPole1.Y(), aPole2.X(), aPole2.Y(), anEnd.X(), anEnd.Y());
54 } else { // error, another number of poles is not supported
55 return QPainterPath();