Salome HOME
Merge branch 'BR_MULTI_BATHS' into HEAD
[modules/hydro.git] / src / HYDRO_tests / TestShape.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
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>
29
30 TopoDS_Edge Edge( const QList<double>& theXYList, bool isClosed )
31 {
32   int n = theXYList.size()/2;
33   Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n );
34   for( int i=1; i<=n; i++ )
35   {
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 );
40   }
41   GeomAPI_Interpolate anInterpolator( aPointsArray, isClosed, 1E-3 );
42   anInterpolator.Perform();
43   bool aResult = anInterpolator.IsDone() == Standard_True;
44   if( aResult )
45   {
46     Handle( Geom_BSplineCurve ) aCurve = anInterpolator.Curve();
47     return BRepBuilderAPI_MakeEdge( aCurve ).Edge();
48   }
49   else
50     return TopoDS_Edge();
51 }
52
53 TopoDS_Wire Wire( const QList<double>& theXYList, bool isClosed )
54 {
55   return BRepBuilderAPI_MakeWire( Edge( theXYList, isClosed ) ).Wire();
56 }
57
58 TopoDS_Face Face( const QList<double>& theXYList )
59 {
60   return BRepBuilderAPI_MakeFace( Wire( theXYList, true ), Standard_True ).Face();
61 }
62
63 TopoDS_Wire WireCirc( const gp_Pnt& theCenter, double theRadius )
64 {
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();
68 }