1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ## Lesser General Public License for more details.
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
24 def addPolyline(sketch, *coords):
25 """Add a poly-line to sketch.
27 The end of consecutive segments are defined as coincident.
32 line_1 = sketch.addLine(c0, c1)
33 polyline.append(line_1)
34 # Adding and connecting next lines
36 line_2 = sketch.addLine(c1, c2)
37 sketch.setCoincident(line_1.endPoint(), line_2.startPoint())
38 polyline.append(line_2)
44 def addPolygon(sketch, *coords):
45 """Add a polygon to sketch.
47 The end of consecutive segments are defined as coincident.
49 pg = addPolyline(sketch, *coords)
50 # Closing the poly-line supposed being defined by at least 3 points
52 cn = coords[len(coords) - 1]
53 ln = sketch.addLine(cn, c0)
55 pg[len(coords) - 2].endPoint(), ln.startPoint()
58 ln.endPoint(), pg[0].startPoint()
64 """ Extract degrees of freedom for the given sketch
67 if issubclass(type(aSketch), ModelHighAPI.ModelHighAPI_Interface):
68 aSketch = sketch.feature()
69 return int(filter(str.isdigit, aSketch.string("SolverDOF").value()))
71 def distancePointPoint(thePoint1, thePoint2):
74 if issubclass(type(thePoint1), GeomDataAPI.GeomDataAPI_Point2D):
75 aGeomPnt1 = thePoint1.pnt()
76 if issubclass(type(thePoint2), GeomDataAPI.GeomDataAPI_Point2D):
77 aGeomPnt2 = thePoint2.pnt()
78 return aGeomPnt1.distance(aGeomPnt2)
80 def lastSubFeature(theSketch, theKind):
82 obtains last feature of given kind from the sketch
84 for anIndex in range(theSketch.numberOfSubs() - 1, -1, -1):
85 aSub = theSketch.subFeature(anIndex)
86 if (aSub.getKind() == theKind):