Salome HOME
Improve PythonAPI documentstion.
[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     """Interface class for Boolean features.
39
40     Boolean(feature) -> feature interface without initialization
41     Boolean(feature, main_objects, tool_objects, bool_type) ->
42         feature interface initialized from arguments
43     """
44
45     def __init__(self, feature, *args):
46         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
47         Interface.__init__(self, feature)
48         assert(self._feature.getKind() == "Boolean")
49
50         self._main_objects = self._feature.selectionList("main_objects")
51         self._tool_objects = self._feature.selectionList("tool_objects")
52         self._bool_type = self._feature.integer("bool_type")
53
54         assert(self._main_objects)
55         assert(self._tool_objects)
56         assert(self._bool_type)
57
58         if not args:
59             return
60
61         assert(len(args) == 3)
62         main_objects, tool_objects, bool_type = args
63
64         self.setMainObjects(main_objects)
65         self.setToolObjects(tool_objects)
66         self.setBoolType(bool_type)
67
68         self._execute()
69         pass
70
71     def setMainObjects(self, main_objects):
72         """F.setMainObjects(iterable) -- modify main_objects attribute"""
73         self._fill_attribute(self._main_objects, main_objects)
74         pass
75
76     def setToolObjects(self, tool_objects):
77         """F.setToolObjects(iterable) -- modify tool_objects attribute"""
78         self._fill_attribute(self._tool_objects, tool_objects)
79         pass
80
81     def setBoolType(self, bool_type):
82         """F.setBoolType(integer) -- modify bool_type attribute.
83
84         Available types:
85         - GeomAlgoAPI_Boolean.BOOL_FUSE
86         - GeomAlgoAPI_Boolean.BOOL_CUT
87         - GeomAlgoAPI_Boolean.BOOL_COMMON
88         """
89         self._fill_attribute(self._bool_type, bool_type)
90         pass