]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add exchange plugin without tests
authorspo <sergey.pokhodenko@opencascade.com>
Tue, 27 Oct 2015 09:06:37 +0000 (12:06 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Tue, 27 Oct 2015 09:06:37 +0000 (12:06 +0300)
src/PythonAPI/model/__init__.py
src/PythonAPI/model/exchange/__init__.py [new file with mode: 0644]
src/PythonAPI/model/exchange/exchange.py [new file with mode: 0644]

index 8dbf44e8ae64cc6b9774bb1c7e9132f4dfba58b7..1e158cca8f6c12034a7b7c5c483efc81c4e34731 100644 (file)
@@ -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 (file)
index 0000000..756097b
--- /dev/null
@@ -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 (file)
index 0000000..c294bc4
--- /dev/null
@@ -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