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 Edge2d( 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 Wire2d( const QList<double>& theXYList, bool isClosed )
55 return BRepBuilderAPI_MakeWire( Edge2d( theXYList, isClosed ) ).Wire();
58 TopoDS_Edge Edge3d( const QList<double>& theXYZList, bool isClosed )
60 int n = theXYZList.size()/3;
61 Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n );
62 for( int i=1; i<=n; i++ )
64 double x = theXYZList[3*i-3];
65 double y = theXYZList[3*i-2];
66 double z = theXYZList[3*i-1];
67 gp_Pnt aPnt( x, y, z );
68 aPointsArray->SetValue( i, aPnt );
70 GeomAPI_Interpolate anInterpolator( aPointsArray, isClosed, 1E-3 );
71 anInterpolator.Perform();
72 bool aResult = anInterpolator.IsDone() == Standard_True;
75 Handle( Geom_BSplineCurve ) aCurve = anInterpolator.Curve();
76 return BRepBuilderAPI_MakeEdge( aCurve ).Edge();
82 TopoDS_Wire Wire3d( const QList<double>& theXYZList, bool isClosed )
84 return BRepBuilderAPI_MakeWire( Edge3d( theXYZList, isClosed ) ).Wire();
87 TopoDS_Face Face2d( const QList<double>& theXYList )
89 return BRepBuilderAPI_MakeFace( Wire2d( theXYList, true ), Standard_True ).Face();
92 TopoDS_Face Face3d( const QList<double>& theXYZList )
94 return BRepBuilderAPI_MakeFace( Wire3d( theXYZList, true ), Standard_True ).Face();
97 TopoDS_Wire WireCirc( const gp_Pnt& theCenter, double theRadius )
99 gp_Circ aCircle( gp_Ax2( theCenter, gp_Dir( 0, 0, 1 ) ), theRadius );
100 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aCircle ).Edge();
101 return BRepBuilderAPI_MakeWire( anEdge ).Wire();