Salome HOME
c51e53032947ca7a22f47352403df6767bc544d3
[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     .. function:: addPartition(part, face, distance)
13
14     Args:
15         part (ModelAPI_Document): part document
16         face (Selection): plane face
17         distance (double): distance
18
19     .. function:: addPartition(part, a, b, c, d)
20
21     Args:
22         part (ModelAPI_Document): part document
23         a (double): general equation parameter
24         b (double): general equation parameter
25         c (double): general equation parameter
26         d (double): general equation parameter
27
28     Returns:
29         Plane: plane object
30     """
31     assert(args)
32     feature = part.addFeature("Plane")
33     return Plane(feature, *args)
34
35
36 class Plane(Interface):
37     """Interface class for Plane feature.
38
39     .. function:: Plane(feature)
40
41         Create interface for the feature without initialization.
42
43     .. function:: Plane(feature, face, distance)
44
45         Create interface for the feature and initialize the feature with arguments.
46
47     .. function:: Plane(feature, a, b, c, d)
48
49         Create interface for the feature and initialize the feature with arguments.
50     """
51
52     def __init__(self, feature, *args):
53         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
54         Interface.__init__(self, feature)
55         assert(self._feature.getKind() == "Plane")
56
57         self._CreationMethod = self._feature.data().string("CreationMethod")
58         self._plane_face = self._feature.data().selection("planeFace")
59         self._distance = self._feature.data().real("distance")
60         self._a = self._feature.data().real("A")
61         self._b = self._feature.data().real("B")
62         self._c = self._feature.data().real("C")
63         self._d = self._feature.data().real("D")
64
65         assert(self._CreationMethod)
66         assert(self._plane_face)
67         assert(self._distance)
68         assert(self._a)
69         assert(self._b)
70         assert(self._c)
71         assert(self._d)
72
73         if not args:
74             return
75
76         assert(len(args) in (2, 4))
77         if len(args) == 2:
78             self.setFaceAndDistance(*args)
79         elif len(args) == 4:
80             self.setGeneralEquation(*args)
81
82         self.execute()
83         pass
84
85     def __clear(self):
86         self._fillAttribute(self._CreationMethod, "PlaneByFaceAndDistance")
87         self._fillAttribute(self._plane_face, None)
88         self._fillAttribute(self._distance, 0)
89         self._fillAttribute(self._a, 0)
90         self._fillAttribute(self._b, 0)
91         self._fillAttribute(self._c, 0)
92         self._fillAttribute(self._d, 0)
93
94     def setFaceAndDistance(self, face, distance):
95         """Modify face and distance attribute of the feature.
96
97         See __init__.
98         """
99         self.__clear()
100         self._fillAttribute(self._CreationMethod, "PlaneByFaceAndDistance")
101         self._fillAttribute(self._plane_face, face)
102         self._fillAttribute(self._distance, distance)
103         pass
104
105     def setGeneralEquation(self, a, b, c, d):
106         """Modify GeneralEquation parameters of the feature.
107
108         See __init__.
109         """
110         self.__clear()
111         self._fillAttribute(self._CreationMethod, "PlaneByGeneralEquation")
112         self._fillAttribute(self._a, a)
113         self._fillAttribute(self._b, b)
114         self._fillAttribute(self._c, c)
115         self._fillAttribute(self._d, d)
116         pass