Salome HOME
6bbaea87fcecf5577437fdccd01a172556aca822
[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     feature = part.addFeature("Axis")
15     return Axis(feature, *args)
16
17
18 class Axis(Interface):
19     """Interface on an Axis feature."""
20
21     def __init__(self, feature, *args):
22         """Initialize an Axis feature with given parameters.
23
24         Expected arguments for all modes:
25         feature -- a Axis feature
26
27         For AxisByPointsCase mode (expect 2 arguments):
28         p1 -- FirstPoint
29         p2 -- SecondPoint
30
31         For AxisByCylindricalFaceCase mode (expect 1 argument):
32         face -- CylindricalFace
33         """
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) == 2 or len(args) == 1)
51         if len(args) == 2:
52             self.setPoints(*args)
53         elif len(args) == 1:
54             self.setCylindricalFace(*args)
55         pass
56
57     def __clear(self):
58         self._fill_attribute(self._CreationMethod, "AxisByPointsCase")
59         self._fill_attribute(self._FirstPoint, None)
60         self._fill_attribute(self._SecondPoint, None)
61         self._fill_attribute(self._CylindricalFace, None)
62
63     def setPoints(self, p1, p2):
64         """Modify points attribute of the feature.
65
66         See __init__.
67         """
68         self.__clear()
69         self._fill_attribute(self._CreationMethod, "AxisByPointsCase")
70         self._fill_attribute(self._FirstPoint, p1)
71         self._fill_attribute(self._SecondPoint, p2)
72         pass
73
74     def setCylindricalFace(self, face):
75         """Modify CylindricalFace attribute of the feature.
76
77         See __init__.
78         """
79         self.__clear()
80         self._fill_attribute(self._CreationMethod, "AxisByCylindricalFaceCase")
81         self._fill_attribute(self._CylindricalFace, face)
82         pass