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