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