Salome HOME
Added support of python high level API addons proposed by DBC as test of this approach.
[modules/shaper.git] / src / PythonAddons / macros / cylinder / feature.py
1 """Cylinder macro-feature
2 Authors: Daniel Brunier-Coulin
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 import modeler
7 import geom
8
9
10 class CylinderFeature(modeler.Feature):
11
12
13 # Initializations
14
15   def __init__(self):
16     modeler.Feature.__init__(self)
17
18   @staticmethod
19   def ID():
20     return "Cylinder"
21
22   @staticmethod
23   def RADIUS_ID():
24     return "radius"
25
26   @staticmethod
27   def LENGTH_ID():
28     return "length"
29
30   def getKind(self):
31     return CylinderFeature.ID()
32
33         
34 # Creation of the cylinder at default size
35
36   def initAttributes(self):
37
38     # Creating the input arguments of the feature
39     self.addRealInput( self.RADIUS_ID() )
40     self.addRealInput( self.LENGTH_ID() )
41
42     # Creating the base of the cylinder with unit values
43     mypart = modeler.activeDocument()
44     xoy    = modeler.defaultPlane("XOY")
45
46     self.base = modeler.addSketch( mypart, xoy )
47     circle    = self.base.addCircle( 0, 0, 1)
48
49     # Setting the radius of the base with default values
50     self.radius = self.base.setRadius( circle.result(), 10 )    # Keeps the constraint for edition
51
52     # Creating the extrusion (the cylinder) at default size
53     self.cyl = modeler.addExtrusion( mypart, self.base.selectFace(), 50 )
54
55         
56 # Edition of the cylinder at user size
57
58   def execute(self):
59     # Retrieving the user inputs
60     radius = self.getRealInput( self.RADIUS_ID() )
61     length = self.getRealInput( self.LENGTH_ID() )
62
63     # Editing the cylinder
64     self.base.setValue( self.radius, radius )
65     self.cyl.setSize( length )
66
67         # Publishing the result
68     self.addResult( self.cyl.result() )