]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/sketcher/line.py
Salome HOME
93f354ba063a45c76f4e7ba7ed71e747d725e5c6
[modules/shaper.git] / src / PythonAPI / model / sketcher / line.py
1 from GeomDataAPI import geomDataAPI_Point2D
2 from model.roots import Interface
3 from model.errors import WrongNumberOfArguments
4
5 from .entity import Entity
6
7 class Line(Entity):
8     """Interface for editing of a sketch line feature."""
9     def __init__(self, feature, *args):
10         Entity.__init__(self, feature)
11         assert(self._feature.getKind() == "SketchLine")
12
13         # Initialize attributes
14         self._start_point = geomDataAPI_Point2D(
15             self._feature.data().attribute("StartPoint")
16             )
17         self._end_point = geomDataAPI_Point2D(
18             self._feature.data().attribute("EndPoint")
19             )
20
21         # If no arguments are given the attributes of the feature
22         # are'nt initialized
23         if args is None:
24             return
25
26         # Set attribute values and execute
27         if len(args) == 4:
28             self.__createByCoordinates(*args)
29         elif len(args) == 2:
30             self.__createByPoints(*args)
31         elif len(args) == 1:
32             self.__createByName(*args)
33         else:
34             raise WrongNumberOfArguments(
35                 "Arc takes 1, 2 or 4 arguments (%s given)" % len(args)
36                 )
37         self.execute()
38
39     def __createByCoordinates(self, x1, y1, x2, y2):
40         self.setStartPoint(x1, y1)
41         self.setEndPoint(x2, y2)
42
43     def __createByPoints(self, p1, p2):
44         self.setStartPoint(p1.x(), p1.y())
45         self.setEndPoint(p2.x(), p2.y())
46
47     def __createByName(self, name):
48         self._feature.data().selection("External").selectSubShape("EDGE", name)
49
50     #######
51     #
52     # Set methods
53     #
54     #######
55
56     def setStartPoint(self, x, y):
57         """Set the start point of the line."""
58         self._start_point.setValue(x, y)
59
60     def setEndPoint(self, x, y):
61         """Set the end point of the line."""
62         self._end_point.setValue(x, y)
63
64     # TODO : methods below will be removed.
65     # Kept until all tests have been updated
66     def startPointData(self):
67         return self._start_point
68
69     def endPointData(self):
70         return self._end_point
71
72     def result(self):
73         return self._feature.firstResult()