Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into azv/SketchSolver_Refactoring
[modules/shaper.git] / src / PythonAPI / model / sketcher / tools.py
1 # Author: Sergey Pokhodenko
2 # Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3
4
5 def addPolyline(sketch, *coords):
6     """Add a poly-line to sketch.
7
8     The end of consecutive segments are defined as coincident.
9     """
10     c0 = coords[0]
11     c1 = coords[1]
12     polyline = []
13     line_1 = sketch.addLine(c0, c1)
14     polyline.append(line_1)
15     # Adding and connecting next lines
16     for c2 in coords[2:]:
17         line_2 = sketch.addLine(c1, c2)
18         sketch.setCoincident(line_1.endPoint(), line_2.startPoint())
19         polyline.append(line_2)
20         c1 = c2
21         line_1 = line_2
22     return polyline
23
24
25 def addPolygon(sketch, *coords):
26     """Add a polygon to sketch.
27
28     The end of consecutive segments are defined as coincident.
29     """
30     pg = addPolyline(sketch, *coords)
31     # Closing the poly-line supposed being defined by at least 3 points
32     c0 = coords[0]
33     cn = coords[len(coords) - 1]
34     ln = sketch.addLine(cn, c0)
35     sketch.setCoincident(
36         pg[len(coords) - 2].endPoint(), ln.startPoint()
37         )
38     sketch.setCoincident(
39         ln.endPoint(), pg[0].startPoint()
40         )
41     pg.append(ln)
42     return pg
43
44 def dof(sketch):
45     """ Extract degrees of freedom for the given sketch
46     """
47     return int(filter(str.isdigit, sketch.string("SolverDOF").value()))