Salome HOME
Rename _fill_attribute to _fillAttribute. Make redirection using functions.
[modules/shaper.git] / src / PythonAPI / model / features / revolution.py
index 02ff467389edb03d00ef2daf84d17abea8c9b072..e816d62047968e30e0198b7de554edc8953a57f9 100644 (file)
@@ -17,29 +17,28 @@ def addRevolution(part, *args):
 
 
 class Revolution(Interface):
-    """Interface on an Revolution feature."""
-
-    def __init__(self, feature, base=None, axis_object=None, *args):
-        """Initialize an Revolution feature with given parameters.
-
-        Expected arguments for all modes:
-        feature -- an Revolution feature
-
-        Expected arguments for initializing the feature:
-        base -- name, sketch or list of names and sketches.
-        If base is None then don't change the feature.
-        axis_object -- name, edge for axis
-
-        For ByAngles mode (expect 2 arguments):
-        to_angle -- upper angle
-        from_angle -- lower angle
+    """Interface class for Revolution features.
+
+    Revolution(feature) -> feature interface without initialization
+    Revolution(feature, base, axis_object, to_angle, from_angle) ->
+        feature interface initialized from arguments:
+        - base -- name, sketch or list of names and sketches
+        - axis_object -- name, edge for axis
+        - to_angle -- upper angle
+        - from_angle -- lower angle
+    Revolution(feature, base, axis_object,
+               to_object, to_offset, from_object, from_offset) ->
+        feature interface initialized from arguments:
+        - base -- name, sketch or list of names and sketches
+        - axis_object -- name, edge for axis
+        - to_object -- upper object (plane)
+        - to_offset -- offset from upper object
+        - from_object -- lower object (plane)
+        - from_offset -- offset from lower object
+    """
 
-        For ByPlanesAndOffsets mode (expect 4 arguments):
-        to_object -- upper object (plane)
-        to_offset -- offset from upper object
-        from_object -- lower object (plane)
-        from_offset -- offset from lower object
-        """
+    def __init__(self, feature, *args):
+        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
         Interface.__init__(self, feature)
         assert(self._feature.getKind() == "Revolution")
 
@@ -63,74 +62,41 @@ class Revolution(Interface):
         assert(self._from_object)
         assert(self._from_offset)
 
-        if base is None:
+        if not args:
             return
 
-        self.__setBase(base)
-        self.__setAxisObject(axis_object)
+        assert(len(args) in (4, 6))
+
+        base, axis_object = args[:2]
+        args = args[2:]
+
+        self.setBase(base)
+        self.setAxisObject(axis_object)
 
         if len(args) == 4:
-            self.__createByPlanesAndOffsets(*args)
+            self.setPlanesAndOffsets(*args)
         elif len(args) == 2:
-            self.__createByAngles(*args)
-        else:
-            raise AssertionError(
-                "Revolution takes 5 or 7 arguments (%s given)" %
-                (len(args) + 3)
-                )
-
-        self.__execute()
-        pass
+            self.setAngles(*args)
 
-    def __setBase(self, base):
-        self._fill_attribute(self._base, base)
-        pass
-
-    def __setAxisObject(self, axis_object):
-        self._fill_attribute(self._axis_object, axis_object)
+        self._execute()
         pass
 
     def __clear(self):
         self._CreationMethod.setValue("ByAngles")
-        self._fill_attribute(self._to_angle, 0)
-        self._fill_attribute(self._from_angle, 0)
-        self._fill_attribute(self._to_object, None)
-        self._fill_attribute(self._to_offset, 0)
-        self._fill_attribute(self._from_object, None)
-        self._fill_attribute(self._from_offset, 0)
-        pass
-
-    def __createByAngles(self, to_angle, from_angle):
-        self.__clear()
-        self._CreationMethod.setValue("ByAngles")
-        self._fill_attribute(self._to_angle, to_angle)
-        self._fill_attribute(self._from_angle, from_angle)
-        pass
-
-    def __createByPlanesAndOffsets(self, to_object, to_offset,
-                                   from_object, from_offset):
-        self.__clear()
-        self._CreationMethod.setValue("ByPlanesAndOffsets")
-        self._fill_attribute(self._to_object, to_object)
-        self._fill_attribute(self._to_offset, to_offset)
-        self._fill_attribute(self._from_object, from_object)
-        self._fill_attribute(self._from_offset, from_offset)
+        self._fillAttribute(self._to_angle, 0)
+        self._fillAttribute(self._from_angle, 0)
+        self._fillAttribute(self._to_object, None)
+        self._fillAttribute(self._to_offset, 0)
+        self._fillAttribute(self._from_object, None)
+        self._fillAttribute(self._from_offset, 0)
         pass
 
-    def __execute(self):
-        if self.areInputValid():
-            self.execute()
-        else:
-            raise Exception("Cannot execute Revolution: %s" %
-                            self._feature.error())
-
     def setBase(self, base):
         """Modify base attribute of the feature.
 
         See __init__.
         """
-        self.__setBase(base)
-        self.__execute()
+        self._fillAttribute(self._base, base)
         pass
 
     def setAxisObject(self, axis_object):
@@ -138,24 +104,30 @@ class Revolution(Interface):
 
         See __init__.
         """
-        self.__setAxisObject(axis_object)
-        self.__execute()
+        self._fillAttribute(self._axis_object, axis_object)
         pass
 
-    def setAngles(self, *args):
+    def setAngles(self, to_angle, from_angle):
         """Modify the to_angle, from_angle attributes of the feature.
 
         See __init__.
         """
-        self.__createByAngles(*args)
-        self.__execute()
+        self.__clear()
+        self._CreationMethod.setValue("ByAngles")
+        self._fillAttribute(self._to_angle, to_angle)
+        self._fillAttribute(self._from_angle, from_angle)
         pass
 
-    def setPlanesAndOffsets(self, *args):
+    def setPlanesAndOffsets(self, to_object, to_offset,
+                            from_object, from_offset):
         """Modify planes and offsets attributes of the feature.
 
         See __init__.
         """
-        self.__createByPlanesAndOffsets(*args)
-        self.__execute()
+        self.__clear()
+        self._CreationMethod.setValue("ByPlanesAndOffsets")
+        self._fillAttribute(self._to_object, to_object)
+        self._fillAttribute(self._to_offset, to_offset)
+        self._fillAttribute(self._from_object, from_object)
+        self._fillAttribute(self._from_offset, from_offset)
         pass