Salome HOME
Merge Dev_2.1.0 with PythonAPI branch
[modules/shaper.git] / src / PythonAPI / model / features / partition.py
1 """Partition Interface
2 Author: Sergey Pokhodenko
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 from model.roots import Interface
7
8
9 def addPartition(part, *args):
10     """Add a Partition feature to the Part.
11
12     .. function:: addPartition(part, main_objects, tool_objects, partition_combine)
13
14     Args:
15         part (ModelAPI_Document): part document
16         main_objects (list of Selection): main objects
17         tool_objects (list of Selection): tool objects
18         partition_combine (boolean):
19             If True combines all results to one. If False builds separate result for each object.
20
21     Returns:
22         Partition: partition object
23     """
24     assert(len(args) > 0 and args[0] is not None)
25     feature = part.addFeature("Partition")
26     return Partition(feature, *args)
27
28
29 class Partition(Interface):
30     """Interface class for Partition feature.
31
32     .. function:: Partition(feature)
33
34         Create interface for the feature without initialization.
35
36     .. function:: Partition(feature, main_objects, tool_objects, partition_combine)
37
38         Create interface for the feature and initialize the feature with arguments.
39     """
40
41     def __init__(self, feature, *args):
42         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
43         Interface.__init__(self, feature)
44         assert(self._feature.getKind() == "Partition")
45
46         self._main_objects = self._feature.data().selectionList("main_objects")
47         self._tool_objects = self._feature.data().selectionList("tool_objects")
48         self._partition_combine = self._feature.data().boolean("partition_combine")
49
50         assert(self._main_objects)
51         assert(self._tool_objects)
52         assert(self._partition_combine)
53
54         if not args:
55             return
56
57         assert(len(args) == 3)
58         main_objects, tool_objects, partition_combine = args
59
60         self.setMainObjects(main_objects)
61         self.setToolObjects(tool_objects)
62         self.setPartitionCombine(partition_combine)
63
64         self.execute()
65         pass
66
67     def setMainObjects(self, main_objects):
68         """Modify base attribute of the feature.
69
70         See __init__.
71         """
72         self._fillAttribute(self._main_objects, main_objects)
73         pass
74
75     def setToolObjects(self, tool_objects):
76         """Modify the to_size, from_size attributes of the feature.
77
78         See __init__.
79         """
80         self._fillAttribute(self._tool_objects, tool_objects)
81         pass
82
83     def setPartitionCombine(self, partition_combine):
84         """Modify planes and offsets attributes of the feature.
85
86         See __init__.
87         """
88         self._fillAttribute(self._partition_combine, partition_combine)
89         pass