Salome HOME
Python API and example plugin are corrected to perform basic actions without crashes
[modules/shaper.git] / src / PythonFeaturesPlugin / PythonFeaturesPlugin_Box.py
1 import ModelAPI
2
3 class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
4   "Feature to create a box by drawing a sketch and extruding it"
5   def __init__(self):
6     ModelAPI.ModelAPI_Feature.__init__(self)
7
8   @staticmethod
9   def ID():
10     return "Box"
11
12   @staticmethod
13   def WIDTH_ID():
14     return "box_width"
15   
16   @staticmethod
17   def LENGTH_ID():
18     return "box_length"
19   
20   @staticmethod
21   def HEIGHT_ID():
22     return "box_height"
23
24   def getKind(self):
25     return PythonFeaturesPlugin_Box.ID()
26
27   def initAttributes(self):
28     # C++ static methods (in example Type() of ModelAPI_AttributeDouble
29     # should be called like this: moduleName.ClassName_StaticMethod()
30     self.data().addAttribute(PythonFeaturesPlugin_Box.WIDTH_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
31     self.data().addAttribute(PythonFeaturesPlugin_Box.LENGTH_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
32     self.data().addAttribute(PythonFeaturesPlugin_Box.HEIGHT_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
33
34   def execute(self):
35     aWidth  = self.real(PythonFeaturesPlugin_Box.WIDTH_ID()).value()
36     aLength = self.real(PythonFeaturesPlugin_Box.LENGTH_ID()).value()
37     aHeight = self.real(PythonFeaturesPlugin_Box.HEIGHT_ID()).value()
38     print ("Box W:{0} L:{1} H:{2}".format(aWidth, aLength, aHeight))
39     # aResult = document().createBody(data())
40     # aResult.store(UserPackage.makeBox(aLength, aWidth, aHeight)
41     # self.setResult(aResult)
42
43
44     
45
46