]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/sketcher/tools.py
Salome HOME
Implement Collinear constraint
[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 import ModelHighAPI
5
6 def addPolyline(sketch, *coords):
7     """Add a poly-line to sketch.
8
9     The end of consecutive segments are defined as coincident.
10     """
11     c0 = coords[0]
12     c1 = coords[1]
13     polyline = []
14     line_1 = sketch.addLine(c0, c1)
15     polyline.append(line_1)
16     # Adding and connecting next lines
17     for c2 in coords[2:]:
18         line_2 = sketch.addLine(c1, c2)
19         sketch.setCoincident(line_1.endPoint(), line_2.startPoint())
20         polyline.append(line_2)
21         c1 = c2
22         line_1 = line_2
23     return polyline
24
25
26 def addPolygon(sketch, *coords):
27     """Add a polygon to sketch.
28
29     The end of consecutive segments are defined as coincident.
30     """
31     pg = addPolyline(sketch, *coords)
32     # Closing the poly-line supposed being defined by at least 3 points
33     c0 = coords[0]
34     cn = coords[len(coords) - 1]
35     ln = sketch.addLine(cn, c0)
36     sketch.setCoincident(
37         pg[len(coords) - 2].endPoint(), ln.startPoint()
38         )
39     sketch.setCoincident(
40         ln.endPoint(), pg[0].startPoint()
41         )
42     pg.append(ln)
43     return pg
44
45 def dof(sketch):
46     """ Extract degrees of freedom for the given sketch
47     """
48     aSketch = sketch
49     if issubclass(type(aSketch), ModelHighAPI.ModelHighAPI_Interface):
50         aSketch = sketch.feature()
51     return int(filter(str.isdigit, aSketch.string("SolverDOF").value()))