Salome HOME
4d71529aac90aedf1c1f58023651a029e31c8f55
[modules/geom.git] / src / GEOM_SWIG / XAOPluginBuilder.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2014-2023  CEA/DEN, EDF R&D, 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 from GEOM import IXAOOperations
22
23 # Engine Library Name
24 __libraryName__ = "XAOPluginEngine"
25
26 def GetXAOPluginOperations(self):
27     anOp = self.GetPluginOperations(__libraryName__)
28     return anOp._narrow(IXAOOperations)
29
30 ## Export a shape to XAO format
31 #  @param shape The shape to export
32 #  @param groups The list of groups to export
33 #  @param fields The list of fields to export
34 #  @param author The author of the file
35 #  @param fileName The name of the file to export
36 #  @param shapeFileName The name of the BRep file to export
37 #  @return True if operation is successful or False otherwise
38 #
39 #  @ingroup l2_import_export
40 def ExportXAO(self, shape, groups, fields, author, fileName, shapeFileName = ""):
41     """
42     Export a shape to XAO format
43     
44     Parameters:
45         shape The shape to export
46         groups The list of groups to export
47         fields The list of fields to export
48         author The author of the file
49         fileName The name of the file to export
50
51     Returns:
52         True if operation is successful or False otherwise
53     """
54     from salome.geom.geomBuilder import RaiseIfFailed
55     anOp = GetXAOPluginOperations(self)
56     res = anOp.ExportXAO(shape, groups, fields, author, fileName, shapeFileName)
57     RaiseIfFailed("ExportXAO", anOp)
58     return res
59
60 ## Import a shape from XAO format
61 #  @param fileName The name of the file to import
62 #  @param theName Object name; when specified, this parameter is used
63 #         for result publication in the study. Otherwise, if automatic
64 #         publication is switched on, default value is used for result name.
65
66 #  @return tuple (\a res, \a shape, \a subShapes, \a groups, \a fields)
67 #       \a res Flag indicating if the import was successful
68 #       \a shape The imported shape
69 #       \a subShapes The list of imported subShapes
70 #       \a groups The list of imported groups
71 #       \a fields The list of imported fields
72 #
73 #  @ingroup l2_import_export
74 def ImportXAO(self, fileName, theName=None):
75     """
76     Import a shape from XAO format
77     
78     Parameters:
79         fileName The name of the file to import
80         theName Object name; when specified, this parameter is used
81                 for result publication in the study. Otherwise, if automatic
82                 publication is switched on, default value is used for result name.
83
84     Returns:
85         A tuple (res, shape, subShapes, groups, fields):
86         - res: Flag indicating if the import was successful
87         - shape: The imported shape
88         - subShapes: The list of imported subShapes
89         - groups: The list of imported groups
90         - fields: The list of imported fields
91     """
92     from salome.geom.geomBuilder import RaiseIfFailed
93     anOp = GetXAOPluginOperations(self)
94     res = anOp.ImportXAO(fileName)
95     RaiseIfFailed("ImportXAO", anOp)
96     self._autoPublish(res[1], theName, "imported")
97     return res