Salome HOME
Documenting of Python code
[modules/shaper.git] / src / PythonAPI / modeler / 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     """Constructor"""
14     ### Create a feature
15     self.my = part.addFeature("Boolean")
16     self.my.data().reference("main_object").setValue(object)
17     self.my.data().reference("tool_object").setValue(tool)
18     self.my.data().integer("bool_type").setValue(type)
19
20     if ModelAPI_Session.get().validators().validate(self.my):
21       self.my.execute()
22     else:
23       raise Exception("cannot make the Boolean")
24
25
26 class Addition(Boolean):
27   """Inserts an addition to the given Part and executes the operation.
28   This operation adds tool to the given object.
29   """
30
31   def __init__(self, part, object, tool):
32     """Constructor"""
33     Boolean.__init__(self, part, object, tool, GeomAlgoAPI_Boolean.BOOL_FUSE)
34
35
36 class Subtraction(Boolean):
37   """Inserts a subtraction to the given Part and executes the operation.
38   This operation subtracts tool to the given object.
39   """
40
41   def __init__(self, part, object, tool):
42     """Constructor"""
43     Boolean.__init__(self, part, object, tool, GeomAlgoAPI_Boolean.BOOL_CUT)
44
45
46 class Intersection(Boolean):
47   """Inserts an intersection to the given Part and executes the operation.
48   This operation intersects tool to the given object.
49   """
50
51   def __init__(self, part, object, tool):
52     """Constructor"""
53     Boolean.__init__(self, part, object, tool, GeomAlgoAPI_Boolean.BOOL_COMMON)