Salome HOME
Parametric API high level for the primitive "Box".
[modules/shaper.git] / src / PythonAPI / extension / box.py
1 """Box macro-feature Interface
2 Author: Daniel Brunier-Coulin
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 from model import Interface
7 from macros.box.feature import BoxFeature as MY
8
9
10 def addBoxScript(part, *args):
11     """Add Box feature to the part and return Box.
12
13     Pass all args to Box __init__ function.
14     """
15     feature = part.addFeature(MY.ID())
16     return Box(feature, *args)
17
18
19 class Box(Interface):
20     """Executes the macro-feature Box.
21
22     Box(feature) -> feature interface without initialization
23     Extrusion(feature, dx, dy, dz) ->
24         feature interface initialized from arguments:
25         - dx, dy, dz -- box dimensions
26     """
27
28     def __init__(self, feature, *args):
29         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
30         Interface.__init__(self, feature)
31         assert(self._feature.getKind() == MY.ID())
32
33         self._width = self._feature.real(MY.WIDTH_ID())
34         self._length = self._feature.real(MY.LENGTH_ID())
35         self._height = self._feature.real(MY.HEIGHT_ID())
36
37         assert(self._width)
38         assert(self._length)
39         assert(self._height)
40
41         if not args:
42             return
43
44         assert(len(args) == 3)
45         dx, dy, dz = args
46         self.setWidth(dx)
47         self.setLength(dy)
48         self.setHeight(dz)
49
50         self.execute()
51         pass
52
53     def setWidth(self, width):
54         """B.setWidth(float) -- modify width attribute"""
55         self._width.setValue(width)
56         pass
57
58     def setLength(self, length):
59         """B.setLength(float) -- modify length attribute"""
60         self._length.setValue(length)
61         pass
62
63     def setHeight(self, height):
64         """B.setHeight(float) -- modify height attribute"""
65         self._height.setValue(height)
66         pass