Salome HOME
Updated copyright comment
[modules/geom.git] / src / GEOM_SWIG / XAOPluginBuilder.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2014-2024  CEA, EDF, OPEN CASCADE
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import GEOM
22 from GEOM import IXAOOperations
23
24 # Engine Library Name
25 __libraryName__ = "XAOPluginEngine"
26
27 def GetXAOPluginOperations(self):
28     anOp = self.GetPluginOperations(__libraryName__)
29     return anOp._narrow(IXAOOperations)
30
31 ## Export a shape to XAO format
32 #  @param shape The shape to export
33 #  @param groups The list of groups to export
34 #  @param fields The list of fields to export
35 #  @param author The author of the file
36 #  @param fileName The name of the file to export
37 #  @param shapeFileName The name of the BRep file to export
38 #  @return True if operation is successful or False otherwise
39 #
40 #  @ingroup l2_import_export
41 def ExportXAO(self, shape, groups, fields, author, fileName, shapeFileName = ""):
42     """
43     Export a shape to XAO format
44     
45     Parameters:
46         shape The shape to export
47         groups The list of groups to export
48         fields The list of fields to export
49         author The author of the file
50         fileName The name of the file to export
51
52     Returns:
53         True if operation is successful or False otherwise
54     """
55     from salome.geom.geomBuilder import RaiseIfFailed
56     anOp = GetXAOPluginOperations(self)
57     res = anOp.ExportXAO(shape, groups, fields, author, fileName, shapeFileName)
58     RaiseIfFailed("ExportXAO", anOp)
59     return res
60
61 ## Export a shape to XAO format in byte array
62 #  @param shape The shape to export
63 #  @param groups The list of groups to export
64 #  @param fields The list of fields to export
65 #  @param author The author of the file
66 #  @return Byte array with exported data
67 #
68 #  @ingroup l2_import_export
69 def ExportXAOMem(self, shape, groups, fields, author):
70     """
71     Export a shape to XAO format in byte array
72     
73     Parameters:
74         shape The shape to export
75         groups The list of groups to export
76         fields The list of fields to export
77
78     Returns:
79         Byte array with exported data
80     """
81     from salome.geom.geomBuilder import RaiseIfFailed
82     anOp = GetXAOPluginOperations(self)
83     res = anOp.ExportXAOMem(shape, groups, fields, author)
84     RaiseIfFailed("ExportXAOMem", anOp)
85     return res
86
87 ## Import a shape from XAO format
88 #  @param fileName The name of the file to import
89 #  @param theName Object name; when specified, this parameter is used
90 #         for result publication in the study. Otherwise, if automatic
91 #         publication is switched on, default value is used for result name.
92
93 #  @return tuple (\a res, \a shape, \a subShapes, \a groups, \a fields)
94 #       \a res Flag indicating if the import was successful
95 #       \a shape The imported shape
96 #       \a subShapes The list of imported subShapes
97 #       \a groups The list of imported groups
98 #       \a fields The list of imported fields
99 #
100 #  @ingroup l2_import_export
101 def ImportXAO(self, fileName, theName=None):
102     """
103     Import a shape from XAO format
104     
105     Parameters:
106         fileName The name of the file to import
107         theName Object name; when specified, this parameter is used
108                 for result publication in the study. Otherwise, if automatic
109                 publication is switched on, default value is used for result name.
110
111     Returns:
112         A tuple (res, shape, subShapes, groups, fields):
113         - res: Flag indicating if the import was successful
114         - shape: The imported shape
115         - subShapes: The list of imported subShapes
116         - groups: The list of imported groups
117         - fields: The list of imported fields
118     """
119     from salome.geom.geomBuilder import RaiseIfFailed
120     anOp = GetXAOPluginOperations(self)
121     (res, shape, subShapes, groups, fields) = anOp.ImportXAO(fileName)
122     RaiseIfFailed("ImportXAO", anOp)
123     if res:
124         # publish imported shape
125         self._autoPublish(shape, theName, "imported")
126         # publish imported sub shapes, groups and fields
127         if theName or self.myMaxNbSubShapesAllowed:
128             for ss in (subShapes + groups + fields):
129                 self.addToStudyInFather(shape, ss, ss.GetName())
130                 if isinstance( ss, GEOM._objref_GEOM_Field ):
131                     listStepIDs = ss.GetSteps()
132                     for stepID in listStepIDs:
133                         step = ss.GetStep(stepID)
134                         self.addToStudyInFather(ss, step, step.GetName())
135                         pass
136                     pass
137                 pass
138             pass
139         pass
140     return (res, shape, subShapes, groups, fields)
141
142 ## Import a shape from XAO format byte array
143 #  @param byteArray byte array with XAO data
144 #  @param theName Object name; when specified, this parameter is used
145 #         for result publication in the study. Otherwise, if automatic
146 #         publication is switched on, default value is used for result name.
147
148 #  @return tuple (\a res, \a shape, \a subShapes, \a groups, \a fields)
149 #       \a res Flag indicating if the import was successful
150 #       \a shape The imported shape
151 #       \a subShapes The list of imported subShapes
152 #       \a groups The list of imported groups
153 #       \a fields The list of imported fields
154 #
155 #  @ingroup l2_import_export
156 def ImportXAOMem(self, byteArray, theName=None):
157     """
158     Import a shape from XAO format byte array
159     
160     Parameters:
161         byteArray byte array with XAO data
162         theName Object name; when specified, this parameter is used
163                 for result publication in the study. Otherwise, if automatic
164                 publication is switched on, default value is used for result name.
165
166     Returns:
167         A tuple (res, shape, subShapes, groups, fields):
168         - res: Flag indicating if the import was successful
169         - shape: The imported shape
170         - subShapes: The list of imported subShapes
171         - groups: The list of imported groups
172         - fields: The list of imported fields
173     """
174     from salome.geom.geomBuilder import RaiseIfFailed
175     anOp = GetXAOPluginOperations(self)
176     (res, shape, subShapes, groups, fields) = anOp.ImportXAOMem(byteArray)
177     RaiseIfFailed("ImportXAOMem", anOp)
178     if res:
179         # publish imported shape
180         self._autoPublish(shape, theName, "imported")
181         # publish imported sub shapes, groups and fields
182         if theName or self.myMaxNbSubShapesAllowed:
183             for ss in (subShapes + groups + fields):
184                 self.addToStudyInFather(shape, ss, ss.GetName())
185                 if isinstance( ss, GEOM._objref_GEOM_Field ):
186                     listStepIDs = ss.GetSteps()
187                     for stepID in listStepIDs:
188                         step = ss.GetStep(stepID)
189                         self.addToStudyInFather(ss, step, step.GetName())
190                         pass
191                     pass
192                 pass
193             pass
194         pass
195     return (res, shape, subShapes, groups, fields)