Salome HOME
c884451af4c377c19667f84cd85e264fb4d48f92
[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.
11
12     .. function:: addImport(part, file_path)
13
14     Args:
15         part (ModelAPI_Document): part document
16         file_path (string): path to the imported file
17
18     Returns:
19         Import: import object
20     """
21     assert(args)
22     feature = part.addFeature("Import")
23     return Import(feature, *args)
24
25
26 class Import(Interface):
27     """Interface class for Import feature.
28
29     .. function:: Import(feature)
30
31         Create interface for the feature without initialization.
32
33     .. function:: Import(feature, file_path)
34
35         Create interface for the feature and initialize the feature with arguments.
36     """
37
38     def __init__(self, feature, *args):
39         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
40         Interface.__init__(self, feature)
41         assert(self._feature.getKind() == "Import")
42
43         self._file_path = self._feature.data().string("file_path")
44
45         assert(self._file_path)
46
47         if not args:
48             return
49
50         assert(len(args) == 1)
51         self.setFilePath(args[0])
52
53         self.execute()
54         pass
55
56     def setFilePath(self, file_path):
57         """Modify file path attribute of the feature.
58
59         See __init__.
60         """
61         self._fillAttribute(self._file_path, file_path)
62         pass
63
64
65 def exportToFile(part, *args):
66     """Perform export from the Part to file.
67
68     .. function:: exportToFile(part, file_path, file_format, selection_list)
69
70     Args:
71         part (ModelAPI_Document): part document
72         file_path (string): path to the exported file
73         file_format (string): format of to the exported file
74         selection_list (list of Selection): objects to export
75
76     Returns:
77         Export: export object
78     """
79     assert(args)
80     feature = part.addFeature("Export")
81     return Export(feature, *args)
82
83
84 class Export(Interface):
85     """Interface class for Export feature.
86
87     .. function:: Export(feature)
88
89         Create interface for the feature without initialization.
90
91     .. function:: Export(feature, file_path, file_format, selection_list)
92
93         Create interface for the feature and initialize the feature with arguments.
94     """
95
96     def __init__(self, feature, *args):
97         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
98         Interface.__init__(self, feature)
99         assert(self._feature.getKind() == "Export")
100
101         self._file_path = self._feature.data().string("file_path")
102         self._file_format = self._feature.data().string("file_format")
103         self._objects = self._feature.data().selectionList("selection_list")
104
105         assert(self._file_path)
106         assert(self._file_format)
107         assert(self._objects)
108
109         if not args:
110             return
111
112         assert(len(args) == 3)
113         self.setFilePath(args[0])
114         self.setFileFormat(args[1])
115         self.setObjects(args[2])
116
117         self.execute()
118         pass
119
120     def setFilePath(self, file_path):
121         """Modify file path attribute of the feature.
122
123         See __init__.
124         """
125         self._fillAttribute(self._file_path, file_path)
126         pass
127
128     def setFileFormat(self, file_format):
129         """Modify file path attribute of the feature.
130
131         See __init__.
132         """
133         self._fillAttribute(self._file_format, file_format)
134         pass
135
136     def setObjects(self, objects):
137         """Modify file path attribute of the feature.
138
139         See __init__.
140         """
141         self._fillAttribute(self._objects, object)
142         pass