Salome HOME
Merge branch 'BR_LAND_COVER_MAP' of ssh://git.salome-platform.org/modules/hydro into...
[modules/hydro.git] / src / HYDRO_tests / TestShape.cxx
1
2 #include <TestShape.h>
3 #include <BRepBuilderAPI_MakeEdge.hxx>
4 #include <BRepBuilderAPI_MakeFace.hxx>
5 #include <BRepBuilderAPI_MakeWire.hxx>
6 #include <TopoDS_Edge.hxx>
7 #include <TopoDS_Wire.hxx>
8 #include <TopoDS_Face.hxx>
9 #include <TColgp_HArray1OfPnt.hxx>
10 #include <GeomAPI_Interpolate.hxx>
11 #include <gp_Circ.hxx>
12
13 TopoDS_Edge Edge( const QList<double>& theXYList, bool isClosed )
14 {
15   int n = theXYList.size()/2;
16   Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n );
17   for( int i=1; i<=n; i++ )
18   {
19     double x = theXYList[2*i-2];
20     double y = theXYList[2*i-1];
21     gp_Pnt aPnt( x, y, 0 );
22     aPointsArray->SetValue( i, aPnt );
23   }
24   GeomAPI_Interpolate anInterpolator( aPointsArray, isClosed, 1E-3 );
25   anInterpolator.Perform();
26   bool aResult = anInterpolator.IsDone() == Standard_True;
27   if( aResult )
28   {
29     Handle( Geom_BSplineCurve ) aCurve = anInterpolator.Curve();
30     return BRepBuilderAPI_MakeEdge( aCurve ).Edge();
31   }
32   else
33     return TopoDS_Edge();
34 }
35
36 TopoDS_Wire Wire( const QList<double>& theXYList, bool isClosed )
37 {
38   return BRepBuilderAPI_MakeWire( Edge( theXYList, isClosed ) ).Wire();
39 }
40
41 TopoDS_Face Face( const QList<double>& theXYList )
42 {
43   return BRepBuilderAPI_MakeFace( Wire( theXYList, true ), Standard_True ).Face();
44 }
45
46 TopoDS_Wire WireCirc( const gp_Pnt& theCenter, double theRadius )
47 {
48   gp_Circ aCircle( gp_Ax2( theCenter, gp_Dir( 0, 0, 1 ) ), theRadius );
49   TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aCircle ).Edge();
50   return BRepBuilderAPI_MakeWire( anEdge ).Wire();
51 }