From c0b5dcba95adae3c3bb415fd0723d6216222109f Mon Sep 17 00:00:00 2001 From: spo Date: Tue, 27 Oct 2015 16:33:26 +0300 Subject: [PATCH] Add features RevolutionCut/Fuse/Sketch and ExtrusionCut/Fuse/Sketch without tests. --- src/PythonAPI/model/features/__init__.py | 8 +- .../model/features/extrusion_boolean.py | 85 +++++++++++++++++ .../model/features/extrusion_sketch.py | 76 +++++++++++++++ .../model/features/revolution_boolean.py | 95 +++++++++++++++++++ .../model/features/revolution_sketch.py | 86 +++++++++++++++++ src/PythonAPI/model/features/roots.py | 27 ++++++ 6 files changed, 376 insertions(+), 1 deletion(-) create mode 100644 src/PythonAPI/model/features/extrusion_boolean.py create mode 100644 src/PythonAPI/model/features/extrusion_sketch.py create mode 100644 src/PythonAPI/model/features/revolution_boolean.py create mode 100644 src/PythonAPI/model/features/revolution_sketch.py create mode 100644 src/PythonAPI/model/features/roots.py diff --git a/src/PythonAPI/model/features/__init__.py b/src/PythonAPI/model/features/__init__.py index 763938ccc..f38dee15e 100644 --- a/src/PythonAPI/model/features/__init__.py +++ b/src/PythonAPI/model/features/__init__.py @@ -5,6 +5,12 @@ from boolean import Addition as addAddition from boolean import Subtraction as addSubtraction from boolean import Intersection as addIntersection +from partition import addPartition + from extrusion import addExtrusion +from extrusion_boolean import addExtrusionCut, addExtrusionFuse +from extrusion_sketch import addExtrusionSketch + from revolution import addRevolution -from partition import addPartition +from revolution_boolean import addRevolutionCut, addRevolutionFuse +from revolution_sketch import addRevolutionSketch diff --git a/src/PythonAPI/model/features/extrusion_boolean.py b/src/PythonAPI/model/features/extrusion_boolean.py new file mode 100644 index 000000000..61f40a72a --- /dev/null +++ b/src/PythonAPI/model/features/extrusion_boolean.py @@ -0,0 +1,85 @@ +"""ExtrusionCut and ExtrusionFuse Interfaces +Author: Sergey Pokhodenko +Copyright (C) 2014-20xx CEA/DEN, EDF R&D +""" + +from .roots import CompositeBoolean + + +def addExtrusionCut(part, *args): + """Add an ExtrusionCut feature to the Part and return ExtrusionBoolean. + + Pass all args to Extrusion __init__ function. + """ + assert(args) + feature = part.addFeature("ExtrusionCut") + return ExtrusionBoolean(feature, *args) + +def addExtrusionFuse(part, *args): + """Add an ExtrusionFuse feature to the Part and return ExtrusionBoolean. + + Pass all args to Extrusion __init__ function. + """ + assert(args) + feature = part.addFeature("ExtrusionFuse") + return ExtrusionBoolean(feature, *args) + + +class ExtrusionBoolean(CompositeBoolean): + + def __init__(self, feature, *args): + CompositeBoolean.__init__(self, feature, *args) + + 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 not args: + return + + assert(len(args) == 4 or len(args) == 2) + if len(args) == 4: + self.setPlanesAndOffsets(*args) + elif len(args) == 2: + self.setSizes(*args) + 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 setSizes(self, to_size, from_size): + """Modify the to_size, from_size attributes of the feature. + + See __init__. + """ + 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, to_object, to_offset, + from_object, from_offset): + """Modify planes and offsets attributes of the feature. + + See __init__. + """ + 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 + diff --git a/src/PythonAPI/model/features/extrusion_sketch.py b/src/PythonAPI/model/features/extrusion_sketch.py new file mode 100644 index 000000000..fea6ff974 --- /dev/null +++ b/src/PythonAPI/model/features/extrusion_sketch.py @@ -0,0 +1,76 @@ +"""ExtrusionSketch Interfaces +Author: Sergey Pokhodenko +Copyright (C) 2014-20xx CEA/DEN, EDF R&D +""" + +from .roots import CompositeSketch + + +def addExtrusionSketch(part, *args): + """Add an ExtrusionSketch feature to the Part and return ExtrusionSketch. + + Pass all args to ExtrusionSketch __init__ function. + """ + assert(args) + feature = part.addFeature("ExtrusionSketch") + return ExtrusionSketch(feature, *args) + + +class ExtrusionSketch(CompositeSketch): + + def __init__(self, feature, *args): + CompositeSketch.__init__(self, feature, *args) + + 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 not args: + return + + assert(len(args) == 4 or len(args) == 2) + if len(args) == 4: + self.setPlanesAndOffsets(*args) + elif len(args) == 2: + self.setSizes(*args) + 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 setSizes(self, to_size, from_size): + """Modify the to_size, from_size attributes of the feature. + + See __init__. + """ + 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, to_object, to_offset, + from_object, from_offset): + """Modify planes and offsets attributes of the feature. + + See __init__. + """ + 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 + diff --git a/src/PythonAPI/model/features/revolution_boolean.py b/src/PythonAPI/model/features/revolution_boolean.py new file mode 100644 index 000000000..4f50c4941 --- /dev/null +++ b/src/PythonAPI/model/features/revolution_boolean.py @@ -0,0 +1,95 @@ +"""RevolutionCut and RevolutionFuse Interface +Author: Sergey Pokhodenko +Copyright (C) 2014-20xx CEA/DEN, EDF R&D +""" + +from .roots import CompositeBoolean + + +def addRevolutionCut(part, *args): + """Add an RevolutionCut feature to the Part and return RevolutionBoolean. + + Pass all args to RevolutionCut __init__ function. + """ + assert(args) + feature = part.addFeature("RevolutionCut") + return RevolutionBoolean(feature, *args) + +def addRevolutionFuse(part, *args): + """Add an RevolutionFuse feature to the Part and return RevolutionBoolean. + + Pass all args to RevolutionFuse __init__ function. + """ + assert(args) + feature = part.addFeature("RevolutionFuse") + return RevolutionBoolean(feature, *args) + + +class RevolutionBoolean(CompositeBoolean): + + def __init__(self, feature, *args): + CompositeBoolean.__init__(self, feature, *args) + + 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 not args: + return + + self.setAxisObject(args[0]) + + if len(args) == 4: + self.setPlanesAndOffsets(*args[1:]) + elif len(args) == 2: + self.setAngles(*args[1:]) + 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 setAxisObject(self, axis_object): + """Modify axis_object attribute of the feature. + + See __init__. + """ + self._fill_attribute(self._axis_object, axis_object) + pass + + def setAngles(self, to_angle, from_angle): + """Modify the to_angle, from_angle attributes of the feature. + + See __init__. + """ + self.__clear() + self._CreationMethod.setValue("ByAngles") + self._fill_attribute(self._to_angle, to_angle) + self._fill_attribute(self._from_angle, from_angle) + pass + + def setPlanesAndOffsets(self, to_object, to_offset, + from_object, from_offset): + """Modify planes and offsets attributes of the feature. + + See __init__. + """ + 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 + diff --git a/src/PythonAPI/model/features/revolution_sketch.py b/src/PythonAPI/model/features/revolution_sketch.py new file mode 100644 index 000000000..5f27690a9 --- /dev/null +++ b/src/PythonAPI/model/features/revolution_sketch.py @@ -0,0 +1,86 @@ +"""RevolutionSketch Interface +Author: Sergey Pokhodenko +Copyright (C) 2014-20xx CEA/DEN, EDF R&D +""" + +from .roots import CompositeSketch + + +def addRevolutionSketch(part, *args): + """Add an RevolutionSketch feature to the Part and return RevolutionSketch. + + Pass all args to RevolutionSketch __init__ function. + """ + assert(args) + feature = part.addFeature("RevolutionSketch") + return RevolutionSketch(feature, *args) + + +class RevolutionSketch(CompositeSketch): + + def __init__(self, feature, *args): + CompositeSketch.__init__(self, feature, *args) + + 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 not args: + return + + self.setAxisObject(args[0]) + + if len(args) == 4: + self.setPlanesAndOffsets(*args[1:]) + elif len(args) == 2: + self.setAngles(*args[1:]) + 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 setAxisObject(self, axis_object): + """Modify axis_object attribute of the feature. + + See __init__. + """ + self._fill_attribute(self._axis_object, axis_object) + pass + + def setAngles(self, to_angle, from_angle): + """Modify the to_angle, from_angle attributes of the feature. + + See __init__. + """ + self.__clear() + self._CreationMethod.setValue("ByAngles") + self._fill_attribute(self._to_angle, to_angle) + self._fill_attribute(self._from_angle, from_angle) + pass + + def setPlanesAndOffsets(self, to_object, to_offset, + from_object, from_offset): + """Modify planes and offsets attributes of the feature. + + See __init__. + """ + 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 + diff --git a/src/PythonAPI/model/features/roots.py b/src/PythonAPI/model/features/roots.py new file mode 100644 index 000000000..ab7ac3e32 --- /dev/null +++ b/src/PythonAPI/model/features/roots.py @@ -0,0 +1,27 @@ + + +from model.roots import Interface + + +class CompositeBoolean(Interface): + + def __init__(self, feature, *args): + Interface.__init__(self, feature) + + self._sketch = self._feature.reference("sketch") + self._sketch_selection = self._feature.selection("sketch_selection") + self._boolean_objects = self._feature.selectionList("boolean_objects") + + if not args: + return + +class CompositeSketch(Interface): + + def __init__(self, feature, *args): + Interface.__init__(self, feature) + + self._sketch = self._feature.reference("sketch") + self._sketch_selection = self._feature.selection("sketch_selection") + + if not args: + return -- 2.39.2