Salome HOME
de3894ba2b21e15834d3cf0121123226db6d8b22
[modules/geom.git] / src / GEOM_SWIG / IGESPluginBuilder.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 IIGESOperations
22
23 # Engine Library Name
24 __libraryName__ = "IGESPluginEngine"
25
26 def GetIGESPluginOperations(self):
27     anOp = self.GetPluginOperations(__libraryName__)
28     return anOp._narrow(IIGESOperations)
29
30 ## Export the given shape into a file with given name in IGES 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 #  @param theVersion Version of IGES format which defines, whether to write 
34 #                    only faces (5.1 IGES format) or shells and solids also (5.3 IGES format).
35 #  @ingroup l2_import_export
36 def ExportIGES(self, theObject, theFileName, theVersion="5.1"):
37     """
38     Export the given shape into a file with given name in IGES format.
39
40     Parameters: 
41         theObject Shape to be stored in the file.
42         theFileName Name of the file to store the given shape in.
43         theVersion Version of IGES format which defines, whether to write 
44         only faces (5.1 IGES format) or shells and solids also (5.3 IGES format).
45     """
46     anOp = GetIGESPluginOperations(self)
47     anOp.ExportIGES(theObject, theFileName, theVersion)
48     if anOp.IsDone() == 0:
49         raise RuntimeError("Export : " + anOp.GetErrorCode())
50         pass
51     pass
52
53 ## Import a shape from the IGES file with given name.
54 #  @param theFileName The file, containing the shape.
55 #  @param theIsIgnoreUnits If True, file length units will be ignored (set to 'meter')
56 #         and result model will be scaled, if its units are not meters.
57 #         If False (default), file length units will be taken into account.
58 #  @param theName Object name; when specified, this parameter is used
59 #         for result publication in the study. Otherwise, if automatic
60 #         publication is switched on, default value is used for result name.
61 #
62 #  @return New GEOM.GEOM_Object, containing the imported shape.
63 #          If material names are imported it returns the list of
64 #          objects. The first one is the imported object followed by
65 #          material groups.
66 #  @note Auto publishing is allowed for the shape itself. Imported
67 #        material groups are not automatically published.
68 #
69 #  @ref swig_Import_Export "Example"
70 #  @ingroup l2_import_export
71 def ImportIGES(self, theFileName, theIsIgnoreUnits = False, theName=None):
72     """
73     Import a shape from the IGES file with given name.
74
75     Parameters:
76         theFileName The file, containing the shape.
77         ignoreUnits If True, file length units will be ignored (set to 'meter')
78                     and result model will be scaled, if its units are not meters.
79                     If False (default), file length units will be taken into account.
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         New GEOM.GEOM_Object, containing the imported shape.
86         If material names are imported it returns the list of
87         objects. The first one is the imported object followed by
88         material groups.
89     Note:
90         Auto publishing is allowed for the shape itself. Imported
91         material groups are not automatically published.
92     """
93     # Example: see GEOM_TestOthers.py
94     from salome.geom.geomBuilder import RaiseIfFailed
95     anOp = GetIGESPluginOperations(self)
96     
97     anIsIgnoreUnits = theIsIgnoreUnits
98     aName = theName
99     if isinstance( theIsIgnoreUnits, str ):
100         anIsIgnoreUnits = False
101         aName = theIsIgnoreUnits
102         pass
103
104     aListObj = anOp.ImportIGES(theFileName,anIsIgnoreUnits)
105     RaiseIfFailed("ImportIGES", anOp)
106     aNbObj = len(aListObj)
107     if aNbObj > 0:
108         self._autoPublish(aListObj[0], aName, "imported")
109     if aNbObj == 1:
110         return aListObj[0]
111     return aListObj
112
113 ## Return length unit from given IGES file
114 #  @param theFileName The file, containing the shape.
115 #  @return String, containing the units name.
116 #
117 #  @ref swig_Import_Export "Example"
118 #  @ingroup l2_import_export
119 def GetIGESUnit(self, theFileName):
120     """
121     Return length units from given IGES file
122
123     Parameters:
124         theFileName The file, containing the shape.
125
126     Returns:
127         String, containing the units name.
128     """
129     # Example: see GEOM_TestOthers.py
130     anOp = GetIGESPluginOperations(self)
131     aUnitName = anOp.ReadValue( theFileName, "LEN_UNITS")
132     return aUnitName