From: spo Date: Tue, 27 Oct 2015 07:31:09 +0000 (+0300) Subject: Add revolution and repackage Features plugin interface. X-Git-Tag: V_2.1.0~206^2~65 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ca946912d46cecc030953f2b7549a8164f681f7e;p=modules%2Fshaper.git Add revolution and repackage Features plugin interface. --- diff --git a/src/PythonAPI/CMakeLists.txt b/src/PythonAPI/CMakeLists.txt index 8247ab6bf..b6ab797df 100644 --- a/src/PythonAPI/CMakeLists.txt +++ b/src/PythonAPI/CMakeLists.txt @@ -29,4 +29,5 @@ ADD_UNIT_TESTS( TestSketcherSetFillet.py TestFeaturesExtrusion.py + TestFeaturesRevolution.py ) diff --git a/src/PythonAPI/model/__init__.py b/src/PythonAPI/model/__init__.py index efd70a30c..35eeabb27 100644 --- a/src/PythonAPI/model/__init__.py +++ b/src/PythonAPI/model/__init__.py @@ -10,8 +10,7 @@ from roots import * from part import Part as addPart from sketcher.sketch import addSketch -from extrusion import addExtrusion -from revolution import addRevolution +from features import * from boolean import Addition as addAddition from boolean import Subtraction as addSubtraction from boolean import Intersection as addIntersection diff --git a/src/PythonAPI/model/extrusion.py b/src/PythonAPI/model/extrusion.py deleted file mode 100644 index a60493145..000000000 --- a/src/PythonAPI/model/extrusion.py +++ /dev/null @@ -1,135 +0,0 @@ -"""Extrusion Interface -Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov - and Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from .roots import Interface - - -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) - feature = part.addFeature("Extrusion") - return Extrusion(feature, *args) - - -class Extrusion(Interface): - """Interface on an Extrusion feature.""" - - def __init__(self, feature, base=None, *args): - """Initialize an Extrusion feature with given parameters. - - Expected arguments for all modes: - feature -- an Extrusion 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. - - For BySize mode (expect 2 arguments): - to_size -- upper size - from_size -- lower size - - 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 - """ - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Extrusion") - - self._base = self._feature.data().selectionList("base") - self._CreationMethod = self._feature.string("CreationMethod") - self._to_size = self._feature.data().real("to_size") - self._from_size = self._feature.data().real("from_size") - self._to_object = self._feature.data().selection("to_object") - self._to_offset = self._feature.data().real("to_offset") - self._from_object = self._feature.data().selection("from_object") - self._from_offset = self._feature.data().real("from_offset") - - if base is None: - return - - self.__setBase(base) - - if len(args) == 4: - self.__createByPlanesAndOffsets(*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) - pass - - def __clear(self): - self._CreationMethod.setValue("BySizes") - self._fill_attribute(self._to_size, 0) - self._fill_attribute(self._from_size, 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 __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() - pass - - def setSizes(self, *args): - """Modify the to_size, from_size attributes of the feature. - - See __init__. - """ - self.__createBySizes(*args) - self.__execute() - pass - - def setPlanesAndOffsets(self, *args): - """Modify planes and offsets attributes of the feature. - - See __init__. - """ - self.__createByPlanesAndOffsets(*args) - self.__execute() - pass diff --git a/src/PythonAPI/model/features/__init__.py b/src/PythonAPI/model/features/__init__.py new file mode 100644 index 000000000..ffbd5955d --- /dev/null +++ b/src/PythonAPI/model/features/__init__.py @@ -0,0 +1,5 @@ +"""Package for Features plugin for the Parametric Geometry API of the Modeler. +""" + +from extrusion import addExtrusion +from revolution import addRevolution \ No newline at end of file diff --git a/src/PythonAPI/model/features/extrusion.py b/src/PythonAPI/model/features/extrusion.py new file mode 100644 index 000000000..0ca424be0 --- /dev/null +++ b/src/PythonAPI/model/features/extrusion.py @@ -0,0 +1,135 @@ +"""Extrusion Interface +Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov + and Sergey Pokhodenko +Copyright (C) 2014-20xx CEA/DEN, EDF R&D +""" + +from model.roots import Interface + + +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) + feature = part.addFeature("Extrusion") + return Extrusion(feature, *args) + + +class Extrusion(Interface): + """Interface on an Extrusion feature.""" + + def __init__(self, feature, base=None, *args): + """Initialize an Extrusion feature with given parameters. + + Expected arguments for all modes: + feature -- an Extrusion 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. + + For BySize mode (expect 2 arguments): + to_size -- upper size + from_size -- lower size + + 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 + """ + Interface.__init__(self, feature) + assert(self._feature.getKind() == "Extrusion") + + self._base = self._feature.data().selectionList("base") + self._CreationMethod = self._feature.string("CreationMethod") + self._to_size = self._feature.data().real("to_size") + self._from_size = self._feature.data().real("from_size") + self._to_object = self._feature.data().selection("to_object") + self._to_offset = self._feature.data().real("to_offset") + self._from_object = self._feature.data().selection("from_object") + self._from_offset = self._feature.data().real("from_offset") + + if base is None: + return + + self.__setBase(base) + + if len(args) == 4: + self.__createByPlanesAndOffsets(*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) + pass + + def __clear(self): + self._CreationMethod.setValue("BySizes") + self._fill_attribute(self._to_size, 0) + self._fill_attribute(self._from_size, 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 __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() + pass + + def setSizes(self, *args): + """Modify the to_size, from_size attributes of the feature. + + See __init__. + """ + self.__createBySizes(*args) + self.__execute() + pass + + def setPlanesAndOffsets(self, *args): + """Modify planes and offsets attributes of the feature. + + See __init__. + """ + self.__createByPlanesAndOffsets(*args) + self.__execute() + pass diff --git a/src/PythonAPI/model/features/revolution.py b/src/PythonAPI/model/features/revolution.py new file mode 100644 index 000000000..cd43c9106 --- /dev/null +++ b/src/PythonAPI/model/features/revolution.py @@ -0,0 +1,151 @@ +"""Revolution Interface +Author: Sergey Pokhodenko +Copyright (C) 2014-20xx CEA/DEN, EDF R&D +""" + +from model.roots import Interface + + +def addRevolution(part, *args): + """Add an Revolution feature to the Part and return Revolution. + + Pass all args to Revolution __init__ function. + """ + assert(len(args) > 0 and args[0] is not None) + feature = part.addFeature("Revolution") + return Revolution(feature, *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 + + 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 + """ + Interface.__init__(self, feature) + assert(self._feature.getKind() == "Revolution") + + self._base = self._feature.data().selectionList("base") + self._axis_object = self._feature.data().selection("axis_object") + self._CreationMethod = self._feature.string("CreationMethod") + self._to_angle = self._feature.data().real("to_angle") + self._from_angle = self._feature.data().real("from_angle") + self._to_object = self._feature.data().selection("to_object") + self._to_offset = self._feature.data().real("to_offset") + self._from_object = self._feature.data().selection("from_object") + self._from_offset = self._feature.data().real("from_offset") + + if base is None: + return + + self.__setBase(base) + self.__setAxisObject(axis_object) + + if len(args) == 4: + self.__createByPlanesAndOffsets(*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 + + def __setBase(self, base): + self._fill_attribute(self._base, base) + pass + + def __setAxisObject(self, axis_object): + self._fill_attribute(self._axis_object, axis_object) + 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) + 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() + pass + + def setAxisObject(self, axis_object): + """Modify axis_object attribute of the feature. + + See __init__. + """ + self.__setAxisObject(axis_object) + self.__execute() + pass + + def setAngles(self, *args): + """Modify the to_angle, from_angle attributes of the feature. + + See __init__. + """ + self.__createByAngles(*args) + self.__execute() + pass + + def setPlanesAndOffsets(self, *args): + """Modify planes and offsets attributes of the feature. + + See __init__. + """ + self.__createByPlanesAndOffsets(*args) + self.__execute() + pass diff --git a/src/PythonAPI/model/revolution.py b/src/PythonAPI/model/revolution.py deleted file mode 100644 index 2d878a246..000000000 --- a/src/PythonAPI/model/revolution.py +++ /dev/null @@ -1,151 +0,0 @@ -"""Revolution Interface -Author: Sergey Pokhodenko -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from .roots import Interface - - -def addRevolution(part, *args): - """Add an Revolution feature to the Part and return Revolution. - - Pass all args to Revolution __init__ function. - """ - assert(len(args) > 0 and args[0] is not None) - feature = part.addFeature("Revolution") - return Revolution(feature, *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 - - 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 - """ - Interface.__init__(self, feature) - assert(self._feature.getKind() == "Revolution") - - self._base = self._feature.data().selectionList("base") - self._axis_object = self._feature.data().selection("axis_object") - self._CreationMethod = self._feature.string("CreationMethod") - self._to_angle = self._feature.data().real("to_angle") - self._from_angle = self._feature.data().real("from_angle") - self._to_object = self._feature.data().selection("to_object") - self._to_offset = self._feature.data().real("to_offset") - self._from_object = self._feature.data().selection("from_object") - self._from_offset = self._feature.data().real("from_offset") - - if base is None: - return - - self.__setBase(base) - self.__setAxisObject(axis_object) - - if len(args) == 4: - self.__createByPlanesAndOffsets(*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 - - def __setBase(self, base): - self._fill_attribute(self._base, base) - pass - - def __setAxisObject(self, axis_object): - self._fill_attribute(self._axis_object, axis_object) - 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) - 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() - pass - - def setAxisObject(self, axis_object): - """Modify axis_object attribute of the feature. - - See __init__. - """ - self.__setAxisObject(axis_object) - self.__execute() - pass - - def setAngles(self, *args): - """Modify the to_angle, from_angle attributes of the feature. - - See __init__. - """ - self.__createByAngles(*args) - self.__execute() - pass - - def setPlanesAndOffsets(self, *args): - """Modify planes and offsets attributes of the feature. - - See __init__. - """ - self.__createByPlanesAndOffsets(*args) - self.__execute() - pass