1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2014-2024 CEA, EDF, OPEN CASCADE
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 from GEOM import IXAOOperations
25 __libraryName__ = "XAOPluginEngine"
27 def GetXAOPluginOperations(self):
28 anOp = self.GetPluginOperations(__libraryName__)
29 return anOp._narrow(IXAOOperations)
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
40 # @ingroup l2_import_export
41 def ExportXAO(self, shape, groups, fields, author, fileName, shapeFileName = ""):
43 Export a shape to XAO format
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
53 True if operation is successful or False otherwise
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)
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
68 # @ingroup l2_import_export
69 def ExportXAOMem(self, shape, groups, fields, author):
71 Export a shape to XAO format in byte array
74 shape The shape to export
75 groups The list of groups to export
76 fields The list of fields to export
79 Byte array with exported data
81 from salome.geom.geomBuilder import RaiseIfFailed
82 anOp = GetXAOPluginOperations(self)
83 res = anOp.ExportXAOMem(shape, groups, fields, author)
84 RaiseIfFailed("ExportXAOMem", anOp)
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.
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
100 # @ingroup l2_import_export
101 def ImportXAO(self, fileName, theName=None):
103 Import a shape from XAO format
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.
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
119 from salome.geom.geomBuilder import RaiseIfFailed
120 anOp = GetXAOPluginOperations(self)
121 (res, shape, subShapes, groups, fields) = anOp.ImportXAO(fileName)
122 RaiseIfFailed("ImportXAO", anOp)
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())
140 return (res, shape, subShapes, groups, fields)
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.
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
155 # @ingroup l2_import_export
156 def ImportXAOMem(self, byteArray, theName=None):
158 Import a shape from XAO format byte array
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.
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
174 from salome.geom.geomBuilder import RaiseIfFailed
175 anOp = GetXAOPluginOperations(self)
176 (res, shape, subShapes, groups, fields) = anOp.ImportXAOMem(byteArray)
177 RaiseIfFailed("ImportXAOMem", anOp)
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())
195 return (res, shape, subShapes, groups, fields)