]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/construction/plane.py
Salome HOME
0da5060062117d000ded87528d8096a2ff2097e9
[modules/shaper.git] / src / PythonAPI / model / construction / plane.py
1 """Plane 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 addPlane(part, *args):
10     """Add a Plane feature to the Part and return Plane.
11
12     Pass all args to Plane __init__ function.
13     """
14     feature = part.addFeature("Plane")
15     return Plane(feature, *args)
16
17
18 class Plane(Interface):
19     """Interface on a Plane feature."""
20
21     def __init__(self, feature, *args):
22         """Initialize a Plane feature with given parameters.
23
24         Expected arguments for all modes:
25         feature -- a Plane feature
26
27         For PlaneByFaceAndDistance mode (expect 2 arguments):
28         face -- planeFace
29         distance -- distance
30
31         For PlaneByGeneralEquation mode (expect 4 arguments):
32         A, B, C, D -- GeneralEquation parameters
33         """
34         Interface.__init__(self, feature)
35         assert(self._feature.getKind() == "Plane")
36
37         self._CreationMethod = self._feature.data().string("CreationMethod")
38         self._plane_face = self._feature.data().selection("planeFace")
39         self._distance = self._feature.data().real("distance")
40         self._a = self._feature.data().real("A")
41         self._b = self._feature.data().real("B")
42         self._c = self._feature.data().real("C")
43         self._d = self._feature.data().real("D")
44
45         assert(self._CreationMethod)
46         assert(self._plane_face)
47         assert(self._distance)
48         assert(self._a)
49         assert(self._b)
50         assert(self._c)
51         assert(self._d)
52
53         if not args:
54             return
55
56         assert(len(args) in (2, 4))
57         if len(args) == 2:
58             self.setFaceAndDistance(*args)
59         elif len(args) == 4:
60             self.setGeneralEquation(*args)
61
62         self._execute()
63         pass
64
65     def __clear(self):
66         self._fill_attribute(self._CreationMethod, "PlaneByFaceAndDistance")
67         self._fill_attribute(self._plane_face, None)
68         self._fill_attribute(self._distance, 0)
69         self._fill_attribute(self._a, 0)
70         self._fill_attribute(self._b, 0)
71         self._fill_attribute(self._c, 0)
72         self._fill_attribute(self._d, 0)
73
74     def setFaceAndDistance(self, face, distance):
75         """Modify face and distance attribute of the feature.
76
77         See __init__.
78         """
79         self.__clear()
80         self._fill_attribute(self._CreationMethod, "PlaneByFaceAndDistance")
81         self._fill_attribute(self._plane_face, face)
82         self._fill_attribute(self._distance, distance)
83         pass
84
85     def setGeneralEquation(self, a, b, c, d):
86         """Modify GeneralEquation parameters of the feature.
87
88         See __init__.
89         """
90         self.__clear()
91         self._fill_attribute(self._CreationMethod, "PlaneByGeneralEquation")
92         self._fill_attribute(self._a, a)
93         self._fill_attribute(self._b, b)
94         self._fill_attribute(self._c, c)
95         self._fill_attribute(self._d, d)
96         pass