1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <HYDROData_BSplineOperation.h>
25 #include <TColgp_HArray1OfPnt.hxx>
27 #include <GeomAPI_Interpolate.hxx>
28 #include <GeomConvert_BSplineCurveToBezierCurve.hxx>
29 #include <Geom_BezierCurve.hxx>
31 #include <QPainterPath>
33 HYDROData_BSplineOperation::HYDROData_BSplineOperation(
34 const NCollection_Sequence<gp_XYZ>& thePoints,
35 const bool theIsClosed,
36 const double theTolerance )
39 int aNbPoints = thePoints.Size();
40 NCollection_Sequence<gp_XYZ> aPoints;
41 if ( aNbPoints > 0 ) {
42 gp_XYZ aPrevPoint = thePoints.Value( 1 );
43 aPoints.Append( aPrevPoint );
44 for( int i = 2 ; i <= aNbPoints; ++i )
46 gp_XYZ aPoint( thePoints.Value( i ) );
47 if ( !aPoint.IsEqual( aPrevPoint, theTolerance ) )
48 aPoints.Append( aPoint );
53 // fill array for algorithm by the received coordinates
54 aNbPoints = aPoints.Size();
55 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt( 1, aNbPoints );
56 for ( int i = 1; i <= aNbPoints; i++ )
58 gp_Pnt aPnt( aPoints.Value( i ) );
59 aHCurvePoints->SetValue( i, aPnt );
63 GeomAPI_Interpolate aGBC( aHCurvePoints, theIsClosed, gp::Resolution() );
66 myCurve = aGBC.Curve();
69 void HYDROData_BSplineOperation::ComputePath( QPainterPath& thePath ) const
71 if ( myCurve.IsNull() ) // returns an empty Path if original curve is invalid
74 GeomConvert_BSplineCurveToBezierCurve aConverter(myCurve);
75 int a, aNumArcs = aConverter.NbArcs();
76 for(a = 1; a <= aNumArcs; a++)
78 Handle(Geom_BezierCurve) anArc = aConverter.Arc(a);
79 if (a == 1) { // set a start point
80 gp_Pnt aStart = anArc->StartPoint();
81 thePath.moveTo(aStart.X(), aStart.Y());
83 gp_Pnt anEnd = anArc->EndPoint();
84 if (anArc->NbPoles() == 3) { // quadric segment in the path (pole 1 is start, pole 3 is end)
85 gp_Pnt aPole = anArc->Pole(2);
86 thePath.quadTo(aPole.X(), aPole.Y(), anEnd.X(), anEnd.Y());
87 } else if (anArc->NbPoles() == 4) { // cubic segment (usually this is used)
88 gp_Pnt aPole1 = anArc->Pole(2);
89 gp_Pnt aPole2 = anArc->Pole(3);
91 aPole1.X(), aPole1.Y(), aPole2.X(), aPole2.Y(), anEnd.X(), anEnd.Y());
92 } else { // error, another number of poles is not supported