]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/construction/axis.py
Salome HOME
Add construction plugin without tests.
[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         if not args:
43             return
44
45         assert(len(args) == 2 or len(args) == 1)
46         if len(args) == 2:
47             self.setPoints(*args)
48         elif len(args) == 1:
49             self.setCylindricalFace(*args)
50         pass
51
52     def __clear(self):
53         self._fill_attribute(self._CreationMethod, "AxisByPointsCase")
54         self._fill_attribute(self._FirstPoint, None)
55         self._fill_attribute(self._SecondPoint, None)
56         self._fill_attribute(self._CylindricalFace, None)
57
58     def setPoints(self, p1, p2):
59         """Modify points attribute of the feature.
60
61         See __init__.
62         """
63         self.__clear()
64         self._fill_attribute(self._CreationMethod, "AxisByPointsCase")
65         self._fill_attribute(self._FirstPoint, p1)
66         self._fill_attribute(self._SecondPoint, p2)
67         pass
68
69     def setCylindricalFace(self, face):
70         """Modify CylindricalFace attribute of the feature.
71
72         See __init__.
73         """
74         self.__clear()
75         self._fill_attribute(self._CreationMethod, "AxisByCylindricalFaceCase")
76         self._fill_attribute(self._CylindricalFace, face)
77         pass