]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/features/boolean.py
Salome HOME
Improve PythonAPI documentation
[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
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`): tool_objects objects
22
23     Returns:
24         Boolean: boolean object
25     """
26     assert(args)
27     main_objects, tool_objects = args
28     feature = part.addFeature("Boolean")
29     return Boolean(
30         feature, main_objects, tool_objects, GeomAlgoAPI_Boolean.BOOL_FUSE)
31
32
33 def addSubtraction(part, *args):
34     """Perform subtraction in the Part.
35
36     .. function:: addSubtraction(part, main_objects, tool_objects)
37
38         This operation subtracts tools from the given objects.
39
40     Args:
41         part (ModelAPI_Document): part document
42         main_objects (list of :class:`model.Selection`): main objects
43         tool_objects (list of :class:`model.Selection`): tool_objects objects
44
45     Returns:
46         Boolean: boolean object
47     """
48     assert(args)
49     main_objects, tool_objects = args
50     feature = part.addFeature("Boolean")
51     return Boolean(
52         feature, main_objects, tool_objects, GeomAlgoAPI_Boolean.BOOL_CUT)
53
54
55 def addIntersection(part, *args):
56     """Perform intersection in the Part.
57
58     .. function:: addIntersection(part, main_objects, tool_objects)
59
60         This operation intersects tools with the given objects.
61
62     Args:
63         part (ModelAPI_Document): part document
64         main_objects (list of :class:`model.Selection`): main objects
65         tool_objects (list of :class:`model.Selection`): tool_objects objects
66
67     Returns:
68         Boolean: boolean object
69     """
70     assert(args)
71     main_objects, tool_objects = args
72     feature = part.addFeature("Boolean")
73     return Boolean(
74         feature, main_objects, tool_objects, GeomAlgoAPI_Boolean.BOOL_COMMON)
75
76
77 class Boolean(Interface):
78     """Interface class for Boolean features.
79
80     .. function:: Boolean(feature)
81
82         Create interface for the feature without initialization.
83
84     .. function:: Boolean(feature, main_objects, tool_objects, bool_type)
85
86         Create interface for the feature and initialize the feature with arguments.
87     """
88
89     def __init__(self, feature, *args):
90         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
91         Interface.__init__(self, feature)
92         assert(self._feature.getKind() == "Boolean")
93
94         self._main_objects = self._feature.selectionList("main_objects")
95         self._tool_objects = self._feature.selectionList("tool_objects")
96         self._bool_type = self._feature.integer("bool_type")
97
98         assert(self._main_objects)
99         assert(self._tool_objects)
100         assert(self._bool_type)
101
102         if not args:
103             return
104
105         assert(len(args) == 3)
106         main_objects, tool_objects, bool_type = args
107
108         self.setMainObjects(main_objects)
109         self.setToolObjects(tool_objects)
110         self.setBoolType(bool_type)
111
112         self.execute()
113         pass
114
115     def setMainObjects(self, main_objects):
116         """Modify main_objects attribute of the feature.
117
118         Args:
119             main_objects (list of :class:`model.Selection`): main objects
120         """
121         self._fillAttribute(self._main_objects, main_objects)
122         pass
123
124     def setToolObjects(self, tool_objects):
125         """Modify tool_objects attribute of the feature.
126
127         Args:
128             tool_objects (list of :class:`model.Selection`): tool objects
129         """
130         self._fillAttribute(self._tool_objects, tool_objects)
131         pass
132
133     def setBoolType(self, bool_type):
134         """Modify bool_type attribute of the feature.
135
136         Args:
137             bool_type (integer): type of operation
138
139         Available types:
140
141         * GeomAlgoAPI_Boolean.BOOL_FUSE
142         * GeomAlgoAPI_Boolean.BOOL_CUT
143         * GeomAlgoAPI_Boolean.BOOL_COMMON
144         """
145         self._fillAttribute(self._bool_type, bool_type)
146         pass