From 5859dfd5a2c82a18d7f79b7afd95959f09192374 Mon Sep 17 00:00:00 2001 From: spo Date: Thu, 29 Oct 2015 17:31:17 +0300 Subject: [PATCH] Improve extrusion feature. --- src/PythonAPI/model/__init__.py | 1 + src/PythonAPI/model/features/extrusion.py | 102 +++++++++++----------- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/src/PythonAPI/model/__init__.py b/src/PythonAPI/model/__init__.py index fff311722..26c520ca0 100644 --- a/src/PythonAPI/model/__init__.py +++ b/src/PythonAPI/model/__init__.py @@ -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 diff --git a/src/PythonAPI/model/features/extrusion.py b/src/PythonAPI/model/features/extrusion.py index 0ca424be0..d7aea072f 100644 --- a/src/PythonAPI/model/features/extrusion.py +++ b/src/PythonAPI/model/features/extrusion.py @@ -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(),)] -- 2.39.2