Salome HOME
Rename _fill_attribute to _fillAttribute. Make redirection using functions.
[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 and return Axis.
11
12     Pass all args to Axis __init__ function.
13     """
14     assert(args)
15     feature = part.addFeature("Axis")
16     return Axis(feature, *args)
17
18
19 class Axis(Interface):
20     """Interface class for Axis feature.
21
22     Axis(feature) -> feature interface without initialization
23     Axis(feature, p1, p2) ->
24         feature interface initialized from arguments:
25         - p1 -- FirstPoint
26         - p2 -- SecondPoint
27     Axis(feature, face) ->
28         feature interface initialized from arguments:
29         - face -- CylindricalFace
30     """
31
32     def __init__(self, feature, *args):
33         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
34         Interface.__init__(self, feature)
35         assert(self._feature.getKind() == "Axis")
36
37         self._CreationMethod = self._feature.data().string("CreationMethod")
38         self._FirstPoint = self._feature.data().selection("FirstPoint")
39         self._SecondPoint = self._feature.data().selection("SecondPoint")
40         self._CylindricalFace = self._feature.data().selection("CylindricalFace")
41
42         assert(self._CreationMethod)
43         assert(self._FirstPoint)
44         assert(self._SecondPoint)
45         assert(self._CylindricalFace)
46
47         if not args:
48             return
49
50         assert(len(args) in (1, 2))
51         if len(args) == 2:
52             self.setPoints(*args)
53         elif len(args) == 1:
54             self.setCylindricalFace(*args)
55
56         self._execute()
57         pass
58
59     def __clear(self):
60         self._fillAttribute(self._CreationMethod, "AxisByPointsCase")
61         self._fillAttribute(self._FirstPoint, None)
62         self._fillAttribute(self._SecondPoint, None)
63         self._fillAttribute(self._CylindricalFace, None)
64
65     def setPoints(self, p1, p2):
66         """Modify points attribute of the feature.
67
68         See __init__.
69         """
70         self.__clear()
71         self._fillAttribute(self._CreationMethod, "AxisByPointsCase")
72         self._fillAttribute(self._FirstPoint, p1)
73         self._fillAttribute(self._SecondPoint, p2)
74         pass
75
76     def setCylindricalFace(self, face):
77         """Modify CylindricalFace attribute of the feature.
78
79         See __init__.
80         """
81         self.__clear()
82         self._fillAttribute(self._CreationMethod, "AxisByCylindricalFaceCase")
83         self._fillAttribute(self._CylindricalFace, face)
84         pass