]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/exchange/exchange.py
Salome HOME
c294bc4e4a764c11cdc9d35ae1b451b8bc38bf58
[modules/shaper.git] / src / PythonAPI / model / exchange / exchange.py
1 """Import Interface
2 Author: Sergey Pokhodenko
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 from model.roots import Interface
7
8
9 def addImport(part, *args):
10     """Add an Import feature to the Part and return Import.
11
12     Pass all args to Import __init__ function.
13     """
14     feature = part.addFeature("Import")
15     return Import(feature, *args)
16
17
18 class Import(Interface):
19     """Interface on an Import feature."""
20
21     def __init__(self, feature, *args):
22         """Initialize an Import feature with given parameters.
23
24         Expected arguments for all modes:
25         feature -- an Import feature
26
27         For initialization (expect 1 argument):
28         file_path -- path to the imported file
29         """
30         Interface.__init__(self, feature)
31         assert(self._feature.getKind() == "Import")
32
33         self._file_path = self._feature.data().string("file_path")
34
35         if not args:
36             return
37
38         assert(len(args) == 1)
39         self.setFilePath(*args)
40         pass
41
42     def setFilePath(self, file_path):
43         """Modify file path attribute of the feature.
44
45         See __init__.
46         """
47         self._fill_attribute(self._file_path, file_path)
48         pass
49
50
51 def addExport(part, *args):
52     """Add an Export feature to the Part and return Export.
53
54     Pass all args to Export __init__ function.
55     """
56     feature = part.addFeature("Export")
57     return Export(feature, *args)
58
59
60 class Export(Interface):
61     """Interface on an Export feature."""
62
63     def __init__(self, feature, *args):
64         """Initialize an Export feature with given parameters.
65
66         Expected arguments for all modes:
67         feature -- an Export feature
68
69         For initialization (expect 3 argument):
70         file_path -- path to the exported file
71         file_format -- format of to the exported file
72         objects -- objects to export
73         """
74         Interface.__init__(self, feature)
75         assert(self._feature.getKind() == "Export")
76
77         self._file_path = self._feature.data().string("file_path")
78         self._file_format = self._feature.data().string("file_format")
79         self._objects = self._feature.data().selectionList("selection_list")
80
81         if not args:
82             return
83
84         assert(len(args) == 3)
85         self.setFilePath(args[0])
86         self.setFileFormat(args[1])
87         self.setObjects(args[2])
88         pass
89
90     def setFilePath(self, file_path):
91         """Modify file path attribute of the feature.
92
93         See __init__.
94         """
95         self._fill_attribute(self._file_path, file_path)
96         pass
97
98     def setFileFormat(self, file_format):
99         """Modify file path attribute of the feature.
100
101         See __init__.
102         """
103         self._fill_attribute(self._file_format, file_format)
104         pass
105
106     def setObjects(self, objects):
107         """Modify file path attribute of the feature.
108
109         See __init__.
110         """
111         self._fill_attribute(self._objects, object)
112         pass