]> SALOME platform Git repositories - modules/shaper.git/blob - src/PythonAPI/model/exchange/exchange.py
Salome HOME
Add assertions to set attribute for features.
[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)
42         pass
43
44     def setFilePath(self, file_path):
45         """Modify file path attribute of the feature.
46
47         See __init__.
48         """
49         self._fill_attribute(self._file_path, file_path)
50         pass
51
52
53 def exportToFile(part, *args):
54     """Add an Export feature to the Part and return Export.
55
56     Pass all args to Export __init__ function.
57     """
58     feature = part.addFeature("Export")
59     return Export(feature, *args)
60
61
62 class Export(Interface):
63     """Interface on an Export feature."""
64
65     def __init__(self, feature, *args):
66         """Initialize an Export feature with given parameters.
67
68         Expected arguments for all modes:
69         feature -- an Export feature
70
71         For initialization (expect 3 argument):
72         file_path -- path to the exported file
73         file_format -- format of to the exported file
74         objects -- objects to export
75         """
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         pass
95
96     def setFilePath(self, file_path):
97         """Modify file path attribute of the feature.
98
99         See __init__.
100         """
101         self._fill_attribute(self._file_path, file_path)
102         pass
103
104     def setFileFormat(self, file_format):
105         """Modify file path attribute of the feature.
106
107         See __init__.
108         """
109         self._fill_attribute(self._file_format, file_format)
110         pass
111
112     def setObjects(self, objects):
113         """Modify file path attribute of the feature.
114
115         See __init__.
116         """
117         self._fill_attribute(self._objects, object)
118         pass