]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAddons/macros/box/feature.py
Salome HOME
f160a396e52a233f49c8d353dd136203b4525e54
[modules/shaper.git] / src / PythonAddons / macros / box / feature.py
1 """Box macro-feature
2 Authors: Renaud Nedelec - Daniel Brunier-Coulin
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 import model
7 import geom
8
9
10 class BoxFeature(model.Feature):
11
12
13 # Initializations
14
15     def __init__(self):
16         model.Feature.__init__(self)
17
18     @staticmethod
19     def ID():
20         return "Box"
21
22     @staticmethod
23     def WIDTH_ID():
24         return "width"
25
26     @staticmethod
27     def LENGTH_ID():
28         return "length"
29
30     @staticmethod
31     def HEIGHT_ID():
32         return "height"
33
34     def getKind(self):
35         return BoxFeature.ID()
36
37
38 # Creation of the box at default size
39
40     def initAttributes(self):
41
42         # Creating the input arguments of the feature
43         self.addRealInput(self.WIDTH_ID())
44         self.addRealInput(self.LENGTH_ID())
45         self.addRealInput(self.HEIGHT_ID())
46
47         # Creating the base of the box with unit values
48         mypart = model.activeDocument()
49         xoy = model.defaultPlane("XOY")
50
51         self.base = model.addSketch(mypart, xoy)
52
53         p1 = geom.Pnt2d(0, 0)
54         p2 = geom.Pnt2d(0, 1)
55         p3 = geom.Pnt2d(1, 1)
56         p4 = geom.Pnt2d(1, 0)
57
58         line = self.base.addPolygon(p1, p2, p3, p4)
59
60         self.base.setParallel(line[0].result(), line[2].result())
61         self.base.setParallel(line[1].result(), line[3].result())
62         self.base.setPerpendicular(line[0].result(), line[3].result())
63
64         # Setting the size of the base with default values
65         self.width = self.base.setLength(line[0].result(), 50)  # Keeps the constraint for edition
66         self.length = self.base.setLength(line[3].result(), 50)  # Keeps the constraint for edition
67
68         # Creating the extrusion (the box) at default size
69         self.box = model.addExtrusion(mypart, self.base.selectFace(), 50)
70
71
72 # Edition of the box at user size
73
74     def execute(self):
75         # Retrieving the user inputs
76         width = self.getRealInput(self.WIDTH_ID())
77         length = self.getRealInput(self.LENGTH_ID())
78         height = self.getRealInput(self.HEIGHT_ID())
79
80         # Editing the box
81         self.base.setValue(self.width, width)
82         self.base.setValue(self.length, length)
83         self.box.setSize(height)
84
85         # Publishing the result: not needed for Macro feature
86         # self.addResult( self.box.result() )
87
88     def isMacro(self):
89         # Box feature is macro: removes itself on the creation transaction finish
90         return True