From 7edca5e7c667c67d5ca413ed79b74d4b482a44ec Mon Sep 17 00:00:00 2001 From: spo Date: Tue, 27 Oct 2015 12:06:37 +0300 Subject: [PATCH] Add exchange plugin without tests --- src/PythonAPI/model/__init__.py | 1 + src/PythonAPI/model/exchange/__init__.py | 4 + src/PythonAPI/model/exchange/exchange.py | 112 +++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 src/PythonAPI/model/exchange/__init__.py create mode 100644 src/PythonAPI/model/exchange/exchange.py diff --git a/src/PythonAPI/model/__init__.py b/src/PythonAPI/model/__init__.py index 8dbf44e8a..1e158cca8 100644 --- a/src/PythonAPI/model/__init__.py +++ b/src/PythonAPI/model/__init__.py @@ -11,6 +11,7 @@ from roots import * from part import Part as addPart from sketcher.sketch import addSketch from construction import * +from exchange import * from features import * from parameter import * diff --git a/src/PythonAPI/model/exchange/__init__.py b/src/PythonAPI/model/exchange/__init__.py new file mode 100644 index 000000000..756097b87 --- /dev/null +++ b/src/PythonAPI/model/exchange/__init__.py @@ -0,0 +1,4 @@ +"""Package for Exchange plugin for the Parametric Geometry API of the Modeler. +""" + +from exchange import addImport, addExport \ No newline at end of file diff --git a/src/PythonAPI/model/exchange/exchange.py b/src/PythonAPI/model/exchange/exchange.py new file mode 100644 index 000000000..c294bc4e4 --- /dev/null +++ b/src/PythonAPI/model/exchange/exchange.py @@ -0,0 +1,112 @@ +"""Import Interface +Author: Sergey Pokhodenko +Copyright (C) 2014-20xx CEA/DEN, EDF R&D +""" + +from model.roots import Interface + + +def addImport(part, *args): + """Add an Import feature to the Part and return Import. + + Pass all args to Import __init__ function. + """ + feature = part.addFeature("Import") + return Import(feature, *args) + + +class Import(Interface): + """Interface on an Import feature.""" + + def __init__(self, feature, *args): + """Initialize an Import feature with given parameters. + + Expected arguments for all modes: + feature -- an Import feature + + For initialization (expect 1 argument): + file_path -- path to the imported file + """ + Interface.__init__(self, feature) + assert(self._feature.getKind() == "Import") + + self._file_path = self._feature.data().string("file_path") + + if not args: + return + + assert(len(args) == 1) + self.setFilePath(*args) + pass + + def setFilePath(self, file_path): + """Modify file path attribute of the feature. + + See __init__. + """ + self._fill_attribute(self._file_path, file_path) + pass + + +def addExport(part, *args): + """Add an Export feature to the Part and return Export. + + Pass all args to Export __init__ function. + """ + feature = part.addFeature("Export") + return Export(feature, *args) + + +class Export(Interface): + """Interface on an Export feature.""" + + def __init__(self, feature, *args): + """Initialize an Export feature with given parameters. + + Expected arguments for all modes: + feature -- an Export feature + + For initialization (expect 3 argument): + file_path -- path to the exported file + file_format -- format of to the exported file + objects -- objects to export + """ + Interface.__init__(self, feature) + assert(self._feature.getKind() == "Export") + + self._file_path = self._feature.data().string("file_path") + self._file_format = self._feature.data().string("file_format") + self._objects = self._feature.data().selectionList("selection_list") + + if not args: + return + + assert(len(args) == 3) + self.setFilePath(args[0]) + self.setFileFormat(args[1]) + self.setObjects(args[2]) + pass + + def setFilePath(self, file_path): + """Modify file path attribute of the feature. + + See __init__. + """ + self._fill_attribute(self._file_path, file_path) + pass + + def setFileFormat(self, file_format): + """Modify file path attribute of the feature. + + See __init__. + """ + self._fill_attribute(self._file_format, file_format) + pass + + def setObjects(self, objects): + """Modify file path attribute of the feature. + + See __init__. + """ + self._fill_attribute(self._objects, object) + pass -- 2.39.2