]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/features/boolean.py
Salome HOME
Fix Platine test
[modules/shaper.git] / src / PythonAPI / model / features / boolean.py
1 """Boolean operations Interface
2 Author: Daniel Brunier-Coulin with contribution by Sergey Pokhodenko
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 from GeomAlgoAPI import GeomAlgoAPI_Boolean
7
8 from model.roots import Interface
9 from model import Selection
10
11 def addAddition(part, *args):
12     """Perform addition in the Part.
13
14     .. function:: addAddition(part, main_objects, tool_objects)
15
16         This operation adds tools to the given objects.
17
18     Args:
19         part (ModelAPI_Document): part document
20         main_objects (list of :class:`model.Selection`): main objects
21         tool_objects (list of :class:`model.Selection`): (optional) tool_objects objects
22
23     Returns:
24         Boolean: boolean object
25     """
26     assert(args)
27     feature = part.addFeature("Boolean")
28     return Boolean(
29         feature, GeomAlgoAPI_Boolean.BOOL_FUSE, *args)
30
31
32 def addSubtraction(part, *args):
33     """Perform subtraction in the Part.
34
35     .. function:: addSubtraction(part, main_objects, tool_objects)
36
37         This operation subtracts tools from the given objects.
38
39     Args:
40         part (ModelAPI_Document): part document
41         main_objects (list of :class:`model.Selection`): main objects
42         tool_objects (list of :class:`model.Selection`): tool_objects objects
43
44     Returns:
45         Boolean: boolean object
46     """
47     assert(args)
48     main_objects, tool_objects = args
49     feature = part.addFeature("Boolean")
50     return Boolean(
51         feature, GeomAlgoAPI_Boolean.BOOL_CUT, main_objects, tool_objects)
52
53
54 def addIntersection(part, *args):
55     """Perform intersection in the Part.
56
57     .. function:: addIntersection(part, main_objects, tool_objects)
58
59         This operation intersects tools with the given objects.
60
61     Args:
62         part (ModelAPI_Document): part document
63         main_objects (list of :class:`model.Selection`): main objects
64         tool_objects (list of :class:`model.Selection`): tool_objects objects
65
66     Returns:
67         Boolean: boolean object
68     """
69     assert(args)
70     main_objects, tool_objects = args
71     feature = part.addFeature("Boolean")
72     return Boolean(
73         feature, GeomAlgoAPI_Boolean.BOOL_COMMON, main_objects, tool_objects)
74
75
76 class Boolean(Interface):
77     """Interface class for Boolean features.
78
79     .. function:: Boolean(feature)
80
81         Create interface for the feature without initialization.
82
83     .. function:: Boolean(feature, bool_type, main_objects)
84
85         Create interface for the feature and initialize the feature with arguments.
86
87     .. function:: Boolean(feature, bool_type, main_objects, tool_objects)
88
89         Create interface for the feature and initialize the feature with arguments.
90     """
91
92     def __init__(self, feature, *args):
93         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
94         Interface.__init__(self, feature)
95         assert(self._feature.getKind() == "Boolean")
96
97         self._main_objects = self._feature.selectionList("main_objects")
98         self._tool_objects = self._feature.selectionList("tool_objects")
99         self._bool_type = self._feature.integer("bool_type")
100
101         assert(self._main_objects)
102         assert(self._tool_objects)
103         assert(self._bool_type)
104
105         if not args:
106             return
107
108         assert(len(args) in (2, 3))
109         bool_type, main_objects = args[:2]
110
111         self.setBoolType(bool_type)
112         self.setMainObjects(main_objects)
113
114         if len(args) == 3:
115             tool_objects = args[2]
116             self.setToolObjects(tool_objects)
117
118         self.execute()
119         pass
120
121     def setMainObjects(self, main_objects):
122         """Modify main_objects attribute of the feature.
123
124         Args:
125             main_objects (list of :class:`model.Selection`): main objects
126         """
127         self._fillAttribute(self._main_objects, main_objects)
128         pass
129
130     def setToolObjects(self, tool_objects):
131         """Modify tool_objects attribute of the feature.
132
133         Args:
134             tool_objects (list of :class:`model.Selection`): tool objects
135         """
136         self._fillAttribute(self._tool_objects, tool_objects)
137         pass
138
139     def setBoolType(self, bool_type):
140         """Modify bool_type attribute of the feature.
141
142         Args:
143             bool_type (integer): type of operation
144
145         Available types:
146
147         * GeomAlgoAPI_Boolean.BOOL_FUSE
148         * GeomAlgoAPI_Boolean.BOOL_CUT
149         * GeomAlgoAPI_Boolean.BOOL_COMMON
150         """
151         self._fillAttribute(self._bool_type, bool_type)
152         pass
153
154     def result(self):
155         """F.result() -> list of Selection objects"""
156         return [Selection(result, result.shape()) for result in (self.firstResult(),)]