Salome HOME
Improve extrusion feature.
[modules/shaper.git] / src / PythonAPI / model / features / 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 from model.roots import Interface
11
12
13 def addAddition(part, object, tool):
14     """Inserts an addition to the given Part and executes the operation.
15     This operation adds tool to the given object.
16     """
17     feature = part.addFeature("Boolean")
18     return Boolean(feature, object, tool, GeomAlgoAPI_Boolean.BOOL_FUSE)
19
20
21 def addSubtraction(part, object, tool):
22     """Inserts a subtraction to the given Part and executes the operation.
23     This operation subtracts tool to the given object.
24     """
25     feature = part.addFeature("Boolean")
26     return Boolean(feature, object, tool, GeomAlgoAPI_Boolean.BOOL_CUT)
27
28
29 def addIntersection(part, object, tool):
30     """Inserts an intersection to the given Part and executes the operation.
31     This operation intersects tool to the given object.
32     """
33     feature = part.addFeature("Boolean")
34     return Boolean(feature, object, tool, GeomAlgoAPI_Boolean.BOOL_COMMON)
35
36
37 class Boolean(Interface):
38     """Abstract root class of Boolean Features."""
39     def __init__(self, feature, main_objects, tool_objects, bool_type):
40         Interface.__init__(self, feature)
41         assert(self._feature.getKind() == "Boolean")
42
43         self._main_objects = self._feature.selectionList("main_objects")
44         self._tool_objects = self._feature.selectionList("tool_objects")
45         self._bool_type = self._feature.integer("bool_type")
46
47         assert(self._main_objects)
48         assert(self._tool_objects)
49         assert(self._bool_type)
50
51         self.setMainObjects(main_objects)
52         self.setToolObjects(tool_objects)
53         self.setBoolType(bool_type)
54         pass
55
56     def setMainObjects(self, main_objects):
57         self._fill_attribute(self._main_objects, main_objects)
58         pass
59
60     def setToolObjects(self, tool_objects):
61         self._fill_attribute(self._tool_objects, tool_objects)
62         pass
63
64     def setBoolType(self, bool_type):
65         self._fill_attribute(self._bool_type, bool_type)
66         pass