]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Improve extrusion feature.
authorspo <sergey.pokhodenko@opencascade.com>
Thu, 29 Oct 2015 14:31:17 +0000 (17:31 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 30 Oct 2015 13:42:48 +0000 (16:42 +0300)
src/PythonAPI/model/__init__.py
src/PythonAPI/model/features/extrusion.py

index fff3117224239a9d009053ff0d03a6f4d02a417d..26c520ca06da5de20a97529c5e57270b6b74bec3 100644 (file)
@@ -10,6 +10,7 @@ All features are available via model.add*() functions. Exceptions are:
 
 from services  import *
 from roots     import *
+from tools import Selection
 
 # Built-in features
 
index 0ca424be08f4fd5faf056638fcd673e12943abda..d7aea072f77db082e2efcea9d051f74f99da55c3 100644 (file)
@@ -5,14 +5,14 @@ Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 """
 
 from model.roots import Interface
-
+from model import Selection
 
 def addExtrusion(part, *args):
     """Add an Extrusion feature to the Part and return Extrusion.
 
     Pass all args to Extrusion __init__ function.
     """
-    assert(len(args) > 0 and args[0] is not None)
+    assert(args)
     feature = part.addFeature("Extrusion")
     return Extrusion(feature, *args)
 
@@ -20,7 +20,7 @@ def addExtrusion(part, *args):
 class Extrusion(Interface):
     """Interface on an Extrusion feature."""
 
-    def __init__(self, feature, base=None, *args):
+    def __init__(self, feature, *args):
         """Initialize an Extrusion feature with given parameters.
 
         Expected arguments for all modes:
@@ -52,25 +52,29 @@ class Extrusion(Interface):
         self._from_object = self._feature.data().selection("from_object")
         self._from_offset = self._feature.data().real("from_offset")
 
-        if base is None:
+        assert(self._base)
+        assert(self._CreationMethod)
+        assert(self._to_size)
+        assert(self._from_size)
+        assert(self._to_object)
+        assert(self._to_offset)
+        assert(self._from_object)
+        assert(self._from_offset)
+
+        if not args:
             return
 
-        self.__setBase(base)
+        self.setBase(args[0])
+
+        args = args[1:]
+        assert(len(args) in (1, 2, 4))
 
         if len(args) == 4:
-            self.__createByPlanesAndOffsets(*args)
+            self.setPlanesAndOffsets(*args)
         elif len(args) == 2:
-            self.__createBySizes(*args)
-        else:
-            raise AssertionError(
-                "Extrusion takes 4 or 6 arguments (%s given)." % (len(args) + 2)
-                )
-
-        self.__execute()
-        pass
-
-    def __setBase(self, base):
-        self._fill_attribute(self._base, base)
+            self.setSizes(*args)
+        elif len(args) == 1:
+            self.setSize(args[0])
         pass
 
     def __clear(self):
@@ -83,53 +87,53 @@ class Extrusion(Interface):
         self._fill_attribute(self._from_offset, 0)
         pass
 
-    def __createBySizes(self, to_size, from_size):
-        self.__clear()
-        self._CreationMethod.setValue("BySizes")
-        self._fill_attribute(self._to_size, to_size)
-        self._fill_attribute(self._from_size, from_size)
-        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)
-        pass
-
-    def __execute(self):
-        if self.areInputValid():
-            self.execute()
-        else:
-            raise Exception("Cannot execute Extrusion: %s" %
-                            self._feature.error())
-
     def setBase(self, base):
         """Modify base attribute of the feature.
 
         See __init__.
         """
-        self.__setBase(base)
-        self.__execute()
+        self._fill_attribute(self._base, base)
         pass
 
-    def setSizes(self, *args):
+    def setSizes(self, to_size, from_size):
         """Modify the to_size, from_size attributes of the feature.
 
         See __init__.
         """
-        self.__createBySizes(*args)
-        self.__execute()
+        self.__clear()
+        self._CreationMethod.setValue("BySizes")
+        self._fill_attribute(self._to_size, to_size)
+        self._fill_attribute(self._from_size, from_size)
         pass
 
-    def setPlanesAndOffsets(self, *args):
+    def setSize(self, size):
+        """Modify the size of the feature.
+
+        If size is positive then initialize to_size with size.
+        If size is negative then initialize from_size with -size.
+        """
+        to_size, from_size = 0, 0
+        if size >= 0:
+            to_size = size
+        else:
+            from_size = -size
+
+        self.setSizes(to_size, from_size)
+        pass
+
+    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._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)
         pass
+
+    def result(self):
+        return [Selection(result, result.shape()) for result in (self.firstResult(),)]