Salome HOME
[PythonAPI / sketcher] Syntax modifications (conformity with PEP8)
[modules/shaper.git] / src / PythonAPI / model / 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.string("CreationMethod").setValue("BySizes")
15     self.my.data().selectionList("base").append(sketch.result(), sketch.buildShape())
16     if size < 0:
17           self.my.data().real("from_size").setValue(-size)
18           self.my.data().real("to_size").setValue(0)
19     else:
20           self.my.data().real("to_size").setValue(size)
21           self.my.data().real("from_size").setValue(0)
22
23
24     if ModelAPI_Session.get().validators().validate(self.my):
25       self.my.execute()
26     else:
27       raise Exception("cannot make the Extrusion")
28
29
30   def setSize (self, size):
31     """Modifies the size of this extrusion according to the given size."""
32     if size < 0:
33           self.my.data().real("from_size").setValue(-size)
34           self.my.data().real("to_size").setValue(0)
35     else:
36           self.my.data().real("to_size").setValue(size)
37           self.my.data().real("from_size").setValue(0)
38
39     self.my.execute()
40
41   def result (self):
42     """Returns the result data of this Feature."""
43     return self.my.firstResult()