Salome HOME
Added support of python high level API addons proposed by DBC as test of this approach.
[modules/shaper.git] / src / PythonAPI / modeler / extrusion.py
1 """Extrusion Interface
2 Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 from ModelAPI import *
7
8
9 class Extrusion():
10
11   def __init__ (self, part, sketch, size):
12     """Inserts an extrusion of the given Sketch to the given Part and executes the operation."""
13     self.my = part.addFeature("Extrusion")
14     self.my.data().selectionList("base").append(sketch.result(), sketch.buildShape())
15     if size < 0:
16           self.my.data().boolean("reverse").setValue(True)
17           size = -size
18     else:
19           self.my.data().boolean("reverse").setValue(False)
20
21     self.my.data().real("size").setValue(size)
22
23     if ModelAPI_Session.get().validators().validate(self.my):
24       self.my.execute()
25     else:
26       raise Exception("cannot make the Extrusion")
27
28
29   def setSize (self, size):
30     """Modifies the size of this extrusion according to the given size."""
31     if size < 0:
32           self.my.data().boolean("reverse").setValue(True)
33           size = -size
34     else:
35       self.my.data().boolean("reverse").setValue(False)
36
37     self.my.data().real("size").setValue(size)
38     self.my.execute()
39
40   def result (self):
41     """Returns the result data of this Feature."""
42     return self.my.firstResult()