]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/features/boolean.py
Salome HOME
Create folder model for sphinx documentation
[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 model.roots import Interface
7
8 def addAddition(part, *args):
9     """Inserts an addition to the given Part and executes the operation.
10     This operation adds tool to the given object.
11     """
12     assert(args)
13     object, tool = args
14     feature = part.addFeature("Boolean")
15     return Boolean(feature, object, tool, GeomAlgoAPI_Boolean.BOOL_FUSE)
16
17
18 def addSubtraction(part, *args):
19     """Inserts a subtraction to the given Part and executes the operation.
20     This operation subtracts tool to the given object.
21     """
22     assert(args)
23     object, tool = args
24     feature = part.addFeature("Boolean")
25     return Boolean(feature, object, tool, GeomAlgoAPI_Boolean.BOOL_CUT)
26
27
28 def addIntersection(part, *args):
29     """Inserts an intersection to the given Part and executes the operation.
30     This operation intersects tool to the given object.
31     """
32     assert(args)
33     object, tool = args
34     feature = part.addFeature("Boolean")
35     return Boolean(feature, object, tool, GeomAlgoAPI_Boolean.BOOL_COMMON)
36
37
38 class Boolean(Interface):
39     """Interface class for Boolean features.
40
41     Boolean(feature) -> feature interface without initialization
42     Boolean(feature, main_objects, tool_objects, bool_type) ->
43         feature interface initialized from arguments
44     """
45
46     def __init__(self, feature, *args):
47         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
48         Interface.__init__(self, feature)
49         assert(self._feature.getKind() == "Boolean")
50
51         self._main_objects = self._feature.selectionList("main_objects")
52         self._tool_objects = self._feature.selectionList("tool_objects")
53         self._bool_type = self._feature.integer("bool_type")
54
55         assert(self._main_objects)
56         assert(self._tool_objects)
57         assert(self._bool_type)
58
59         if not args:
60             return
61
62         assert(len(args) == 3)
63         main_objects, tool_objects, bool_type = args
64
65         self.setMainObjects(main_objects)
66         self.setToolObjects(tool_objects)
67         self.setBoolType(bool_type)
68
69         self.execute()
70         pass
71
72     def setMainObjects(self, main_objects):
73         """F.setMainObjects(iterable) -- modify main_objects attribute"""
74         self._fillAttribute(self._main_objects, main_objects)
75         pass
76
77     def setToolObjects(self, tool_objects):
78         """F.setToolObjects(iterable) -- modify tool_objects attribute"""
79         self._fillAttribute(self._tool_objects, tool_objects)
80         pass
81
82     def setBoolType(self, bool_type):
83         """F.setBoolType(integer) -- modify bool_type attribute.
84
85         Available types:
86         - GeomAlgoAPI_Boolean.BOOL_FUSE
87         - GeomAlgoAPI_Boolean.BOOL_CUT
88         - GeomAlgoAPI_Boolean.BOOL_COMMON
89         """
90         self._fillAttribute(self._bool_type, bool_type)
91         pass