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