From 74b48a83f1566a6b6795446dce2f93d2ab68029d Mon Sep 17 00:00:00 2001 From: spo Date: Tue, 27 Oct 2015 11:49:11 +0300 Subject: [PATCH] Add parameter feature without tests. --- src/PythonAPI/model/__init__.py | 1 + src/PythonAPI/model/parameter/__init__.py | 4 ++ src/PythonAPI/model/parameter/parameter.py | 60 ++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 src/PythonAPI/model/parameter/__init__.py create mode 100644 src/PythonAPI/model/parameter/parameter.py diff --git a/src/PythonAPI/model/__init__.py b/src/PythonAPI/model/__init__.py index 1f90375a4..8dbf44e8a 100644 --- a/src/PythonAPI/model/__init__.py +++ b/src/PythonAPI/model/__init__.py @@ -12,6 +12,7 @@ from part import Part as addPart from sketcher.sketch import addSketch from construction import * from features import * +from parameter import * # Custom exceptions diff --git a/src/PythonAPI/model/parameter/__init__.py b/src/PythonAPI/model/parameter/__init__.py new file mode 100644 index 000000000..44bde3f35 --- /dev/null +++ b/src/PythonAPI/model/parameter/__init__.py @@ -0,0 +1,4 @@ +"""Package for Parameter plugin for the Parametric Geometry API of the Modeler. +""" + +from parameter import addParameter \ No newline at end of file diff --git a/src/PythonAPI/model/parameter/parameter.py b/src/PythonAPI/model/parameter/parameter.py new file mode 100644 index 000000000..7a5c28f67 --- /dev/null +++ b/src/PythonAPI/model/parameter/parameter.py @@ -0,0 +1,60 @@ +"""Parameter Interface +Author: Sergey Pokhodenko +Copyright (C) 2014-20xx CEA/DEN, EDF R&D +""" + +from model.roots import Interface + + +def addParameter(part, *args): + """Add a Parameter feature to the Part and return Parameter. + + Pass all args to Parameter __init__ function. + """ + feature = part.addFeature("Parameter") + return Parameter(feature, *args) + + +class Parameter(Interface): + """Interface on a Parameter feature.""" + + def __init__(self, feature, *args): + """Initialize a Parameter feature with given parameters. + + Expected arguments for all modes: + feature -- a Parameter feature + + For initialization (expect 2 arguments): + name -- variable name + expression -- Python expression + """ + Interface.__init__(self, feature) + assert(self._feature.getKind() == "Parameter") + + self._CreationMethod = self._feature.data().string("CreationMethod") + self._variable = self._feature.data().selection("variable") + self._expression = self._feature.data().real("expression") + + if not args: + return + + assert(len(args) == 2) + self.setName(args[0]) + self.setExpression(args[1]) + pass + + def setName(self, name): + """Modify variable name attribute of the feature. + + See __init__. + """ + self._fill_attribute(self._name, name) + pass + + def setExpression(self, expression): + """Modify expression attribute of the feature. + + See __init__. + """ + self._fill_attribute(self._expression, expression) + pass -- 2.30.2