Salome HOME
[PythonAPI] Rename 'modeler' into 'model'
[modules/shaper.git] / src / PythonAPI / model / boolean.py
1 """Boolean operations Interface
2 Author: Daniel Brunier-Coulin
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 from ModelAPI    import *
7 from GeomAlgoAPI import *
8
9
10 class Boolean():
11   """Abstract root class of Boolean Features."""
12   def __init__(self, part, object, tool, type):
13     self.my = part.addFeature("Boolean")
14     self.my.data().reference("main_object").setValue(object)
15     self.my.data().reference("tool_object").setValue(tool)
16     self.my.data().integer("bool_type").setValue(type)
17
18     if ModelAPI_Session.get().validators().validate(self.my):
19       self.my.execute()
20     else:
21       raise Exception("cannot make the Boolean")
22
23
24 class Addition(Boolean):
25
26   def __init__(self, part, object, tool):
27     """Inserts an addition to the given Part and executes the operation.
28     This operation adds tool to the given object.
29     """
30     Boolean.__init__(self, part, object, tool, GeomAlgoAPI_Boolean.BOOL_FUSE)
31
32
33 class Subtraction(Boolean):
34
35   def __init__(self, part, object, tool):
36     """Inserts a subtraction to the given Part and executes the operation.
37     This operation subtracts tool to the given object.
38     """
39     Boolean.__init__(self, part, object, tool, GeomAlgoAPI_Boolean.BOOL_CUT)
40
41
42 class Intersection(Boolean):
43
44   def __init__(self, part, object, tool):
45     """Inserts an intersection to the given Part and executes the operation.
46     This operation intersects tool to the given object.
47     """
48     Boolean.__init__(self, part, object, tool, GeomAlgoAPI_Boolean.BOOL_COMMON)