Salome HOME
171c988d42af89471b923778cb93e40e92a35232
[modules/shaper.git] / src / PythonAPI / model / features / translation.py
1 """Translation 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 addTranslation(part, *args):
10     """Add a Translation feature to the Part.
11
12     .. function:: addTranslation(part, main_objects, axis_object, distance)
13
14     Args:
15         part (ModelAPI_Document): part document
16         main_objects (list of Selection): main objects
17         axis_object (Selection): axis objects
18         distance (double): distance
19
20     Returns:
21         Translation: translation object
22     """
23     assert(args)
24     feature = part.addFeature("Translation")
25     return Translation(feature, *args)
26
27
28 class Translation(Interface):
29     """Interface class for Translation features.
30
31     .. function:: Translation(feature)
32
33         Create interface for the feature without initialization.
34
35     .. function:: Translation(feature, main_objects, axis_object, distance)
36
37         Create interface for the feature and initialize the feature with arguments.
38     """
39
40     def __init__(self, feature, *args):
41         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
42         Interface.__init__(self, feature)
43         assert(self._feature.getKind() == "Translation")
44
45         self._main_objects = self._feature.data().selectionList("main_objects")
46         self._axis_object = self._feature.data().selection("axis_object")
47         self._distance = self._feature.data().real("distance")
48
49         assert(self._main_objects)
50         assert(self._axis_object)
51         assert(self._distance)
52
53         if not args:
54             return
55
56         assert(len(args) == 3)
57         self.setMainObjects(args[0])
58         self.setAxisObject(args[1])
59         self.setDistance(args[2])
60
61         self.execute()
62         pass
63
64     def setMainObjects(self, main_objects):
65         """Modify main_objects attribute of the feature.
66
67         See __init__.
68         """
69         self._fillAttribute(self._main_objects, main_objects)
70         pass
71
72     def setAxisObject(self, axis_object):
73         """Modify axis_object attribute of the feature.
74
75         See __init__.
76         """
77         self._fillAttribute(self._axis_object, axis_object)
78         pass
79
80     def setDistance(self, distance):
81         """Modify distance attribute of the feature.
82
83         See __init__.
84         """
85         self._fillAttribute(self._distance, distance)
86         pass