Salome HOME
28b89692f9f7a2dc834e350d6d21c8cb949020af
[modules/geom.git] / src / GEOM_SWIG / BREPPluginBuilder.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2014-2021  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 IBREPOperations
22
23 # Engine Library Name
24 __libraryName__ = "BREPPluginEngine"
25
26 def GetBREPPluginOperations(self):
27     anOp = self.GetPluginOperations(__libraryName__)
28     return anOp._narrow(IBREPOperations)
29
30 ## Export the given shape into a file with given name in BREP format.
31 #  @param theObject Shape to be stored in the file.
32 #  @param theFileName Name of the file to store the given shape in.
33 #  @ingroup l2_import_export
34 def ExportBREP(self, theObject, theFileName):
35     """
36     Export the given shape into a file with given name in BREP format.
37
38     Parameters: 
39         theObject Shape to be stored in the file.
40         theFileName Name of the file to store the given shape in.
41     """
42     anOp = GetBREPPluginOperations(self)
43     anOp.ExportBREP(theObject, theFileName)
44     if anOp.IsDone() == 0:
45         raise RuntimeError("Export : " + anOp.GetErrorCode())
46         pass
47     pass
48
49
50 ## Import a shape from the BREP file
51 #  @param theFileName The file, containing the shape.
52 #  @param theName Object name; when specified, this parameter is used
53 #         for result publication in the study. Otherwise, if automatic
54 #         publication is switched on, default value is used for result name.
55 #
56 #  @return New GEOM.GEOM_Object, containing the imported shape.
57 #          If material names are imported it returns the list of
58 #          objects. The first one is the imported object followed by
59 #          material groups.
60 #  @note Auto publishing is allowed for the shape itself. Imported
61 #        material groups are not automatically published.
62 #  @ingroup l2_import_export
63 def ImportBREP(self, theFileName, theName=None):
64     """
65     Import a shape from the BREP file
66
67     Parameters: 
68         theFileName The file, containing the shape.
69         theName Object name; when specified, this parameter is used
70                 for result publication in the study. Otherwise, if automatic
71                 publication is switched on, default value is used for result name.
72
73     Returns:
74         New GEOM.GEOM_Object, containing the imported shape.
75         If material names are imported it returns the list of
76         objects. The first one is the imported object followed by
77         material groups.
78     Note:
79         Auto publishing is allowed for the shape itself. Imported
80         material groups are not automatically published.
81     """
82     from salome.geom.geomBuilder import RaiseIfFailed
83     anOp = GetBREPPluginOperations(self)
84     aListObj = anOp.ImportBREP(theFileName)
85     RaiseIfFailed("ImportBREP", anOp)
86     aNbObj = len(aListObj)
87     if aNbObj > 0:
88         self._autoPublish(aListObj[0], theName, "imported")
89     if aNbObj == 1:
90         return aListObj[0]
91     return aListObj