Salome HOME
Remove linking to GeomValidators.
[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 modeler
7 import geom
8
9
10 class BoxFeature(modeler.Feature):
11   """An example of Box feature implementation"""
12
13 # Initializations
14
15   def __init__(self):
16     """Constructor"""
17     modeler.Feature.__init__(self)
18
19   @staticmethod
20   def ID():
21     """Return Id of the feature"""
22     return "Box"
23
24   @staticmethod
25   def WIDTH_ID():
26     """Returns ID of Width parameter"""
27     return "width"
28
29   @staticmethod
30   def LENGTH_ID():
31     """Returns ID of Length parameter"""
32     return "length"
33
34   @staticmethod
35   def HEIGHT_ID():
36     """Returns ID of Height parameter"""
37     return "height"
38
39   def getKind(self):
40     """Returns ID of еру ауфегку"""
41     return BoxFeature.ID()
42
43         
44 # Creation of the box at default size
45
46   def initAttributes(self):
47     """Initialise attributes of the feature"""
48     # Creating the input arguments of the feature
49     self.addRealInput( self.WIDTH_ID() )
50     self.addRealInput( self.LENGTH_ID() )
51     self.addRealInput( self.HEIGHT_ID() )
52
53     # Creating the base of the box with unit values
54     mypart = modeler.activeDocument()
55     xoy    = modeler.defaultPlane("XOY")
56
57     ### A base of the geometry
58     self.base = modeler.addSketch( mypart, xoy )
59
60     p1 = geom.Pnt2d( 0, 0 )
61     p2 = geom.Pnt2d( 0, 1 )
62     p3 = geom.Pnt2d( 1, 1 )
63     p4 = geom.Pnt2d( 1, 0 )
64
65     line = self.base.addPolygon(p1, p2, p3, p4)
66
67     self.base.setParallel( line[0].result(), line[2].result() )
68     self.base.setParallel( line[1].result(), line[3].result() )
69     self.base.setPerpendicular( line[0].result(), line[3].result() )
70
71     # Setting the size of the base with default values
72     ### Width
73     self.width  = self.base.setLength( line[0].result(), 50 )   # Keeps the constraint for edition
74     ### Length
75     self.length = self.base.setLength( line[3].result(), 50 )   # Keeps the constraint for edition
76
77     # Creating the extrusion (the box) at default size
78     ### A box result
79     self.box = modeler.addExtrusion( mypart, self.base.selectFace(), 50 )
80
81         
82 # Edition of the box at user size
83
84   def execute(self):
85     """Compute the feature result"""
86     # Retrieving the user inputs
87     width  = self.getRealInput( self.WIDTH_ID() )
88     length = self.getRealInput( self.LENGTH_ID() )
89     height = self.getRealInput( self.HEIGHT_ID() )
90
91     # Editing the box
92     self.base.setValue( self.width,  width )
93     self.base.setValue( self.length, length )
94     self.box.setSize( height )
95
96     # Publishing the result: not needed for Macro feature
97     #self.addResult( self.box.result() )
98   
99   def isMacro(self):
100     """Returns True"""
101     # Box feature is macro: removes itself on the creation transaction finish
102     return True