1 """Boolean operations Interface
2 Author: Daniel Brunier-Coulin with contribution by Sergey Pokhodenko
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
6 from GeomAlgoAPI import GeomAlgoAPI_Boolean
8 from model.roots import Interface
9 from model import Selection
11 def addAddition(part, *args):
12 """Perform addition in the Part.
14 .. function:: addAddition(part, main_objects, tool_objects)
16 This operation adds tools to the given objects.
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
24 Boolean: boolean object
27 feature = part.addFeature("Boolean")
29 feature, GeomAlgoAPI_Boolean.BOOL_FUSE, *args)
32 def addSubtraction(part, *args):
33 """Perform subtraction in the Part.
35 .. function:: addSubtraction(part, main_objects, tool_objects)
37 This operation subtracts tools from the given objects.
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
45 Boolean: boolean object
48 main_objects, tool_objects = args
49 feature = part.addFeature("Boolean")
51 feature, GeomAlgoAPI_Boolean.BOOL_CUT, main_objects, tool_objects)
54 def addIntersection(part, *args):
55 """Perform intersection in the Part.
57 .. function:: addIntersection(part, main_objects, tool_objects)
59 This operation intersects tools with the given objects.
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
67 Boolean: boolean object
70 main_objects, tool_objects = args
71 feature = part.addFeature("Boolean")
73 feature, GeomAlgoAPI_Boolean.BOOL_COMMON, main_objects, tool_objects)
76 class Boolean(Interface):
77 """Interface class for Boolean features.
79 .. function:: Boolean(feature)
81 Create interface for the feature without initialization.
83 .. function:: Boolean(feature, bool_type, main_objects)
85 Create interface for the feature and initialize the feature with arguments.
87 .. function:: Boolean(feature, bool_type, main_objects, tool_objects)
89 Create interface for the feature and initialize the feature with arguments.
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")
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")
101 assert(self._main_objects)
102 assert(self._tool_objects)
103 assert(self._bool_type)
108 assert(len(args) in (2, 3))
109 bool_type, main_objects = args[:2]
111 self.setBoolType(bool_type)
112 self.setMainObjects(main_objects)
115 tool_objects = args[2]
116 self.setToolObjects(tool_objects)
121 def setMainObjects(self, main_objects):
122 """Modify main_objects attribute of the feature.
125 main_objects (list of :class:`model.Selection`): main objects
127 self._fillAttribute(self._main_objects, main_objects)
130 def setToolObjects(self, tool_objects):
131 """Modify tool_objects attribute of the feature.
134 tool_objects (list of :class:`model.Selection`): tool objects
136 self._fillAttribute(self._tool_objects, tool_objects)
139 def setBoolType(self, bool_type):
140 """Modify bool_type attribute of the feature.
143 bool_type (integer): type of operation
147 * GeomAlgoAPI_Boolean.BOOL_FUSE
148 * GeomAlgoAPI_Boolean.BOOL_CUT
149 * GeomAlgoAPI_Boolean.BOOL_COMMON
151 self._fillAttribute(self._bool_type, bool_type)
155 """F.result() -> list of Selection objects"""
156 return [Selection(result, result.shape()) for result in (self.firstResult(),)]