2 #include <HYDROData_BSplineOperation.h>
4 #include <TColgp_HArray1OfPnt.hxx>
6 #include <GeomAPI_Interpolate.hxx>
7 #include <GeomConvert_BSplineCurveToBezierCurve.hxx>
8 #include <Geom_BezierCurve.hxx>
10 #include <QPainterPath>
12 HYDROData_BSplineOperation::HYDROData_BSplineOperation(
13 const NCollection_Sequence<gp_XYZ>& thePoints,
14 const bool theIsClosed )
16 // fill array for algorithm by the received coordinates
17 int aNbPoints = thePoints.Size();
19 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt( 1, aNbPoints );
20 for ( int i = 1; i <= aNbPoints; i++ )
22 gp_Pnt aPnt( thePoints.Value( i ) );
23 aHCurvePoints->SetValue( i, aPnt );
27 GeomAPI_Interpolate aGBC( aHCurvePoints, theIsClosed, gp::Resolution() );
30 myCurve = aGBC.Curve();
33 void HYDROData_BSplineOperation::ComputePath( QPainterPath& thePath ) const
35 if ( myCurve.IsNull() ) // returns an empty Path if original curve is invalid
38 GeomConvert_BSplineCurveToBezierCurve aConverter(myCurve);
39 int a, aNumArcs = aConverter.NbArcs();
40 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 thePath.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 thePath.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