Salome HOME
Fix Platine test
[modules/shaper.git] / src / PythonAPI / model / construction / axis.py
1 """Axis Interface
2 Author: Sergey Pokhodenko
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 from model.roots import Interface
7
8
9 def addAxis(part, *args):
10     """Add an Axis feature to the Part.
11
12     .. function:: addAxis(part, p1, p2)
13
14     Args:
15         part (ModelAPI_Document): part document
16         p1 (Selection): first point
17         p2 (Selection): second point
18
19     .. function:: addAxis(part, face)
20
21     Args:
22         part (ModelAPI_Document): part document
23         face (Selection): cylindrical face
24
25     Returns:
26         Axis: axis object
27     """
28     assert(args)
29     feature = part.addFeature("Axis")
30     return Axis(feature, *args)
31
32
33 class Axis(Interface):
34     """Interface class for Axis feature.
35
36     .. function:: Axis(feature)
37
38         Create interface for the feature without initialization.
39
40     .. function:: Axis(feature, p1, p2)
41
42         Create interface for the feature and initialize the feature with arguments.
43
44     .. function:: Axis(feature, face)
45
46         Create interface for the feature and initialize the feature with arguments.
47     """
48
49     def __init__(self, feature, *args):
50         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
51         Interface.__init__(self, feature)
52         assert(self._feature.getKind() == "Axis")
53
54         self._CreationMethod = self._feature.data().string("CreationMethod")
55         self._FirstPoint = self._feature.data().selection("FirstPoint")
56         self._SecondPoint = self._feature.data().selection("SecondPoint")
57         self._CylindricalFace = self._feature.data().selection("CylindricalFace")
58
59         assert(self._CreationMethod)
60         assert(self._FirstPoint)
61         assert(self._SecondPoint)
62         assert(self._CylindricalFace)
63
64         if not args:
65             return
66
67         assert(len(args) in (1, 2))
68         if len(args) == 2:
69             self.setPoints(*args)
70         elif len(args) == 1:
71             self.setCylindricalFace(*args)
72
73         self.execute()
74         pass
75
76     def __clear(self):
77         self._fillAttribute(self._CreationMethod, "AxisByPointsCase")
78         self._fillAttribute(self._FirstPoint, None)
79         self._fillAttribute(self._SecondPoint, None)
80         self._fillAttribute(self._CylindricalFace, None)
81
82     def setPoints(self, p1, p2):
83         """Modify points attribute of the feature.
84
85         See __init__.
86         """
87         self.__clear()
88         self._fillAttribute(self._CreationMethod, "AxisByPointsCase")
89         self._fillAttribute(self._FirstPoint, p1)
90         self._fillAttribute(self._SecondPoint, p2)
91         pass
92
93     def setCylindricalFace(self, face):
94         """Modify CylindricalFace attribute of the feature.
95
96         See __init__.
97         """
98         self.__clear()
99         self._fillAttribute(self._CreationMethod, "AxisByCylindricalFaceCase")
100         self._fillAttribute(self._CylindricalFace, face)
101         pass