Salome HOME
Unit tests:
[modules/shaper.git] / src / PythonAPI / model / features / partition.py
index d7226537a3da275c0a494c4a7c1df86a9946b938..26173e0d6e89bb2deb320dfd4a5c19cdd866550d 100644 (file)
@@ -7,9 +7,19 @@ from model.roots import Interface
 
 
 def addPartition(part, *args):
-    """Add an Partition feature to the Part and return Partition.
+    """Add a Partition feature to the Part.
 
-    Pass all args to Partition __init__ function.
+    .. function:: addPartition(part, main_objects, tool_objects, partition_combine)
+
+    Args:
+        part (ModelAPI_Document): part document
+        main_objects (list of Selection): main objects
+        tool_objects (list of Selection): tool objects
+        partition_combine (boolean):
+            If True combines all results to one. If False builds separate result for each object.
+
+    Returns:
+        Partition: partition object
     """
     assert(len(args) > 0 and args[0] is not None)
     feature = part.addFeature("Partition")
@@ -17,20 +27,19 @@ def addPartition(part, *args):
 
 
 class Partition(Interface):
-    """Interface on an Partition feature."""
+    """Interface class for Partition feature.
 
-    def __init__(self, feature, main_objects=None,
-                 tool_objects=None, partition_combine=None):
-        """Initialize an Partition feature with given parameters.
+    .. function:: Partition(feature)
 
-        Expected arguments:
-        feature -- an Partition feature
+        Create interface for the feature without initialization.
 
-        Expected arguments for initializing the feature:
-        main_objects -- list of solids.
-        tool_objects -- list of solids.
-        partition_combine -- boolean value.
-        """
+    .. function:: Partition(feature, main_objects, tool_objects, partition_combine)
+
+        Create interface for the feature and initialize the feature with arguments.
+    """
+
+    def __init__(self, feature, *args):
+        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
         Interface.__init__(self, feature)
         assert(self._feature.getKind() == "Partition")
 
@@ -38,30 +47,29 @@ class Partition(Interface):
         self._tool_objects = self._feature.data().selectionList("tool_objects")
         self._partition_combine = self._feature.data().boolean("partition_combine")
 
-        if main_objects is None:
+        assert(self._main_objects)
+        assert(self._tool_objects)
+        assert(self._partition_combine)
+
+        if not args:
             return
 
-        self._fill_attribute(self._main_objects, main_objects)
-        self._fill_attribute(self._tool_objects, tool_objects)
-        self._fill_attribute(self._partition_combine, partition_combine)
+        assert(len(args) == 3)
+        main_objects, tool_objects, partition_combine = args
 
-        self.__execute()
-        pass
+        self.setMainObjects(main_objects)
+        self.setToolObjects(tool_objects)
+        self.setPartitionCombine(partition_combine)
 
-    def __execute(self):
-        if self.areInputValid():
-            self.execute()
-        else:
-            raise Exception("Cannot execute Partition: %s" %
-                            self._feature.error())
+        self.execute()
+        pass
 
     def setMainObjects(self, main_objects):
         """Modify base attribute of the feature.
 
         See __init__.
         """
-        self._fill_attribute(self._main_objects, main_objects)
-        self.__execute()
+        self._fillAttribute(self._main_objects, main_objects)
         pass
 
     def setToolObjects(self, tool_objects):
@@ -69,8 +77,7 @@ class Partition(Interface):
 
         See __init__.
         """
-        self._fill_attribute(self._tool_objects, tool_objects)
-        self.__execute()
+        self._fillAttribute(self._tool_objects, tool_objects)
         pass
 
     def setPartitionCombine(self, partition_combine):
@@ -78,6 +85,5 @@ class Partition(Interface):
 
         See __init__.
         """
-        self._fill_attribute(self._partition_combine, partition_combine)
-        self.__execute()
+        self._fillAttribute(self._partition_combine, partition_combine)
         pass