1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2014-2016 CEA/DEN, EDF R&D, 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
21 from GEOM import IIGESOperations
24 __libraryName__ = "IGESPluginEngine"
26 def GetIGESPluginOperations(self):
27 anOp = self.GetPluginOperations(self.myStudyId, __libraryName__)
28 return anOp._narrow(IIGESOperations)
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"):
38 Export the given shape into a file with given name in IGES format.
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).
46 anOp = GetIGESPluginOperations(self)
47 anOp.ExportIGES(theObject, theFileName, theVersion)
48 if anOp.IsDone() == 0:
49 raise RuntimeError, "Export : " + anOp.GetErrorCode()
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.
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
66 # @note Auto publishing is allowed for the shape itself. Imported
67 # material groups are not automatically published.
69 # @ref swig_Import_Export "Example"
70 # @ingroup l2_import_export
71 def ImportIGES(self, theFileName, theIsIgnoreUnits = False, theName=None):
73 Import a shape from the IGES file with given name.
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.
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
90 Auto publishing is allowed for the shape itself. Imported
91 material groups are not automatically published.
93 # Example: see GEOM_TestOthers.py
94 from salome.geom.geomBuilder import RaiseIfFailed
95 anOp = GetIGESPluginOperations(self)
97 anIsIgnoreUnits = theIsIgnoreUnits
99 if isinstance( theIsIgnoreUnits, basestring ):
100 anIsIgnoreUnits = False
101 aName = theIsIgnoreUnits
104 aListObj = anOp.ImportIGES(theFileName,anIsIgnoreUnits)
105 RaiseIfFailed("ImportIGES", anOp)
106 aNbObj = len(aListObj)
108 self._autoPublish(aListObj[0], aName, "imported")
113 ## Return length unit from given IGES file
114 # @param theFileName The file, containing the shape.
115 # @return String, containing the units name.
117 # @ref swig_Import_Export "Example"
118 # @ingroup l2_import_export
119 def GetIGESUnit(self, theFileName):
121 Return length units from given IGES file
124 theFileName The file, containing the shape.
127 String, containing the units name.
129 # Example: see GEOM_TestOthers.py
130 anOp = GetIGESPluginOperations(self)
131 aUnitName = anOp.ReadValue( theFileName, "LEN_UNITS")