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