1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <TestShape.h>
20 #include <BRepBuilderAPI_MakeEdge.hxx>
21 #include <BRepBuilderAPI_MakeFace.hxx>
22 #include <BRepBuilderAPI_MakeWire.hxx>
23 #include <TopoDS_Edge.hxx>
24 #include <TopoDS_Wire.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <TColgp_HArray1OfPnt.hxx>
27 #include <GeomAPI_Interpolate.hxx>
28 #include <gp_Circ.hxx>
30 TopoDS_Edge Edge( const QList<double>& theXYList, bool isClosed )
32 int n = theXYList.size()/2;
33 Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n );
34 for( int i=1; i<=n; i++ )
36 double x = theXYList[2*i-2];
37 double y = theXYList[2*i-1];
38 gp_Pnt aPnt( x, y, 0 );
39 aPointsArray->SetValue( i, aPnt );
41 GeomAPI_Interpolate anInterpolator( aPointsArray, isClosed, 1E-3 );
42 anInterpolator.Perform();
43 bool aResult = anInterpolator.IsDone() == Standard_True;
46 Handle( Geom_BSplineCurve ) aCurve = anInterpolator.Curve();
47 return BRepBuilderAPI_MakeEdge( aCurve ).Edge();
53 TopoDS_Wire Wire( const QList<double>& theXYList, bool isClosed )
55 return BRepBuilderAPI_MakeWire( Edge( theXYList, isClosed ) ).Wire();
58 TopoDS_Face Face( const QList<double>& theXYList )
60 return BRepBuilderAPI_MakeFace( Wire( theXYList, true ), Standard_True ).Face();
63 TopoDS_Wire WireCirc( const gp_Pnt& theCenter, double theRadius )
65 gp_Circ aCircle( gp_Ax2( theCenter, gp_Dir( 0, 0, 1 ) ), theRadius );
66 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aCircle ).Edge();
67 return BRepBuilderAPI_MakeWire( anEdge ).Wire();