Salome HOME
Add partition feature without tests.
[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 an Partition feature to the Part and return Partition.
11
12     Pass all args to Partition __init__ function.
13     """
14     assert(len(args) > 0 and args[0] is not None)
15     feature = part.addFeature("Partition")
16     return Partition(feature, *args)
17
18
19 class Partition(Interface):
20     """Interface on an Partition feature."""
21
22     def __init__(self, feature, main_objects=None,
23                  tool_objects=None, partition_combine=None):
24         """Initialize an Partition feature with given parameters.
25
26         Expected arguments:
27         feature -- an Partition feature
28
29         Expected arguments for initializing the feature:
30         main_objects -- list of solids.
31         tool_objects -- list of solids.
32         partition_combine -- boolean value.
33         """
34         Interface.__init__(self, feature)
35         assert(self._feature.getKind() == "Partition")
36
37         self._main_objects = self._feature.data().selectionList("main_objects")
38         self._tool_objects = self._feature.data().selectionList("tool_objects")
39         self._partition_combine = self._feature.data().boolean("partition_combine")
40
41         if main_objects is None:
42             return
43
44         self._fill_attribute(self._main_objects, main_objects)
45         self._fill_attribute(self._tool_objects, tool_objects)
46         self._fill_attribute(self._partition_combine, partition_combine)
47
48         self.__execute()
49         pass
50
51     def __execute(self):
52         if self.areInputValid():
53             self.execute()
54         else:
55             raise Exception("Cannot execute Partition: %s" %
56                             self._feature.error())
57
58     def setMainObjects(self, main_objects):
59         """Modify base attribute of the feature.
60
61         See __init__.
62         """
63         self._fill_attribute(self._main_objects, main_objects)
64         self.__execute()
65         pass
66
67     def setToolObjects(self, tool_objects):
68         """Modify the to_size, from_size attributes of the feature.
69
70         See __init__.
71         """
72         self._fill_attribute(self._tool_objects, tool_objects)
73         self.__execute()
74         pass
75
76     def setPartitionCombine(self, partition_combine):
77         """Modify planes and offsets attributes of the feature.
78
79         See __init__.
80         """
81         self._fill_attribute(self._partition_combine, partition_combine)
82         self.__execute()
83         pass