]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/exchange/exchange.py
Salome HOME
375c6fd01a212b3ab81c271f9bd7eb3184ebd0fd
[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         assert(self._file_path)
36
37         if not args:
38             return
39
40         assert(len(args) == 1)
41         self.setFilePath(args[0])
42
43         self._execute()
44         pass
45
46     def setFilePath(self, file_path):
47         """Modify file path attribute of the feature.
48
49         See __init__.
50         """
51         self._fill_attribute(self._file_path, file_path)
52         pass
53
54
55 def exportToFile(part, *args):
56     """Add an Export feature to the Part and return Export.
57
58     Pass all args to Export __init__ function.
59     """
60     feature = part.addFeature("Export")
61     return Export(feature, *args)
62
63
64 class Export(Interface):
65     """Interface on an Export feature."""
66
67     def __init__(self, feature, *args):
68         """Initialize an Export feature with given parameters.
69
70         Expected arguments for all modes:
71         feature -- an Export feature
72
73         For initialization (expect 3 argument):
74         file_path -- path to the exported file
75         file_format -- format of to the exported file
76         objects -- objects to export
77         """
78         Interface.__init__(self, feature)
79         assert(self._feature.getKind() == "Export")
80
81         self._file_path = self._feature.data().string("file_path")
82         self._file_format = self._feature.data().string("file_format")
83         self._objects = self._feature.data().selectionList("selection_list")
84
85         assert(self._file_path)
86         assert(self._file_format)
87         assert(self._objects)
88
89         if not args:
90             return
91
92         assert(len(args) == 3)
93         self.setFilePath(args[0])
94         self.setFileFormat(args[1])
95         self.setObjects(args[2])
96
97         self._execute()
98         pass
99
100     def setFilePath(self, file_path):
101         """Modify file path attribute of the feature.
102
103         See __init__.
104         """
105         self._fill_attribute(self._file_path, file_path)
106         pass
107
108     def setFileFormat(self, file_format):
109         """Modify file path attribute of the feature.
110
111         See __init__.
112         """
113         self._fill_attribute(self._file_format, file_format)
114         pass
115
116     def setObjects(self, objects):
117         """Modify file path attribute of the feature.
118
119         See __init__.
120         """
121         self._fill_attribute(self._objects, object)
122         pass