Salome HOME
Fixes in python code to avoid modifications outside of a transaction:
[modules/shaper.git] / src / PythonFeaturesPlugin / PythonFeaturesPlugin_Box.py
1 import ModelAPI
2 import examples
3
4 class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
5   "Feature to create a box by drawing a sketch and extruding it"
6   def __init__(self):
7     ModelAPI.ModelAPI_Feature.__init__(self)
8
9   @staticmethod
10   def ID():
11     return "Box"
12
13   @staticmethod
14   def WIDTH_ID():
15     return "box_width"
16   
17   @staticmethod
18   def LENGTH_ID():
19     return "box_length"
20   
21   @staticmethod
22   def HEIGHT_ID():
23     return "box_height"
24
25   def getKind(self):
26     return PythonFeaturesPlugin_Box.ID()
27
28   def initAttributes(self):
29     # C++ static methods (in example "type()" of the ModelAPI_AttributeDouble
30     # should be called like this: moduleName.ClassName_staticMethod()
31     self.data().addAttribute(PythonFeaturesPlugin_Box.WIDTH_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
32     self.data().addAttribute(PythonFeaturesPlugin_Box.LENGTH_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
33     self.data().addAttribute(PythonFeaturesPlugin_Box.HEIGHT_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
34
35   def execute(self):
36     aWidth  = self.real(PythonFeaturesPlugin_Box.WIDTH_ID()).value()
37     aLength = self.real(PythonFeaturesPlugin_Box.LENGTH_ID()).value()
38     aHeight = self.real(PythonFeaturesPlugin_Box.HEIGHT_ID()).value()
39     print ("Box W:{0} L:{1} H:{2}".format(aWidth, aLength, aHeight))
40     aResultBody = self.document().createBody(self.data())
41     aResult = examples.makeBox(aLength, aWidth, aHeight)
42     #aShape = modelAPI_ResultConstruction(aResult).shape()
43     #aResultBody.store(aShape)
44     self.setResult(aResultBody)
45
46 # TEST
47 """
48 if __name__=='__main__':
49   session = ModelAPI.ModelAPI_Session.get()
50   part = session.activeDocument()
51   session.startOperation()
52   feature = part.addFeature('Box')
53   feature.real('box_width').setValue(10)
54   feature.real('box_length').setValue(10)
55   feature.real('box_height').setValue(10)
56   feature.execute()
57   session.finishOperation()
58 """
59   
60
61