Salome HOME
Issue #1440 Crash when edit box with parameter: correction for using parameter values...
[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         self._external = self._feature.selection("External")
21
22         # If no arguments are given the attributes of the feature
23         # are'nt initialized
24         if args is None:
25             return
26
27         # Set attribute values and execute
28         if len(args) == 4:
29             self.__createByCoordinates(*args)
30         elif len(args) == 2:
31             self.__createByPoints(*args)
32         elif len(args) == 1:
33             self.__createByName(*args)
34         else:
35             raise WrongNumberOfArguments(
36                 "Arc takes 1, 2 or 4 arguments (%s given)" % len(args)
37                 )
38         self.execute()
39
40     def __createByCoordinates(self, x1, y1, x2, y2):
41         self.setStartPoint(x1, y1)
42         self.setEndPoint(x2, y2)
43
44     def __createByPoints(self, p1, p2):
45         self.setStartPoint(p1.x(), p1.y())
46         self.setEndPoint(p2.x(), p2.y())
47
48     def __createByName(self, name):
49         self.setExternal(name)
50
51     #######
52     #
53     # Set methods
54     #
55     #######
56
57     def setStartPoint(self, x, y):
58         """Set the start point of the line."""
59         self._start_point.setValue(x, y)
60
61     def setEndPoint(self, x, y):
62         """Set the end point of the line."""
63         self._end_point.setValue(x, y)
64
65     # TODO : methods below will be removed.
66     # Kept until all tests have been updated
67     def startPoint(self):
68         return self._start_point
69
70     def endPoint(self):
71         return self._end_point
72
73     def setExternal(self, name):
74         """Set external edge"""
75         self._external.selectSubShape("EDGE", name)
76
77     def result(self):
78         return self._feature.firstResult()