Salome HOME
4da0998e5d90ed2ea156e661aee3b869e145f1c6
[modules/shaper.git] / src / PythonAPI / model / features / placement.py
1 """Placement 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 addPlacement(part, *args):
10     """Add a Placement feature to the Part.
11
12     .. function:: addPlacement(part, objects_list, start_shape, end_shape, reverse_direction, centering)
13
14     Args:
15         part (ModelAPI_Document): part document
16         objects_list (list of Selection): solid objects
17         start_shape (Selection): start face, edge or vertex
18         end_shape (Selection): end face, edge or vertex
19         reverse_direction (boolean): reverse placement direction
20         centering (boolean): center faces under placement
21
22     Returns:
23         Placement: placement object
24     """
25     assert(args)
26     feature = part.addFeature("Placement")
27     return Placement(feature, *args)
28
29
30 class Placement(Interface):
31     """Interface class for Placement feature.
32
33     .. function:: Placement(feature)
34
35         Create interface for the feature without initialization.
36
37     .. function:: Placement(feature, objects_list, start_shape, end_shape, reverse_direction, centering)
38
39         Create interface for the feature and initialize the feature with arguments.
40     """
41
42     def __init__(self, feature, *args):
43         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
44         Interface.__init__(self, feature)
45         assert(self._feature.getKind() == "Placement")
46
47         self._objects_list = self._feature.data().selectionList("placement_objects_list")
48         self._start_shape = self._feature.data().selection("placement_start_shape")
49         self._end_shape = self._feature.data().selection("placement_end_shape")
50         self._reverse_direction = self._feature.data().boolean("placement_reverse_direction")
51         self._centering = self._feature.data().boolean("placement_centering")
52
53         assert(self._objects_list)
54         assert(self._start_shape)
55         assert(self._end_shape)
56         assert(self._reverse_direction)
57         assert(self._centering)
58
59         if not args:
60             return
61
62         assert(len(args) == 5)
63         self.setObjectList(args[0])
64         self.setStartShape(args[1])
65         self.setEndShape(args[2])
66         self.setReverseDirection(args[3])
67         self.setCentering(args[4])
68
69         self.execute()
70         pass
71
72     def setObjectList(self, objects_list):
73         """Modify placement_objects_list attribute of the feature.
74
75         See __init__.
76         """
77         self._fillAttribute(self._objects_list, objects_list)
78         pass
79
80     def setStartShape(self, start_shape):
81         """Modify start_shape attribute of the feature.
82
83         See __init__.
84         """
85         self._fillAttribute(self._start_shape, start_shape)
86         pass
87
88     def setEndShape(self, end_shape):
89         """Modify end_shape attribute of the feature.
90
91         See __init__.
92         """
93         self._fillAttribute(self._end_shape, end_shape)
94         pass
95
96     def setReverseDirection(self, reverse_direction):
97         """Modify reverse_direction attribute of the feature.
98
99         See __init__.
100         """
101         self._fillAttribute(self._reverse_direction, reverse_direction)
102         pass
103
104     def setCentering(self, centering):
105         """Modify centering attribute of the feature.
106
107         See __init__.
108         """
109         self._fillAttribute(self._centering, centering)
110         pass