1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2014-2015 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 ISTEPOperations
25 __libraryName__ = "STEPPluginEngine"
27 def GetSTEPPluginOperations(self):
28 anOp = self.GetPluginOperations(self.myStudyId, __libraryName__)
29 return anOp._narrow(ISTEPOperations)
31 ## Export the given shape into a file with given name in STEP format.
32 # @param theObject Shape to be stored in the file.
33 # @param theFileName Name of the file to store the given shape in.
34 # @param theUnit the length unit (see GEOM::length_unit). In meters by default.
35 # @ingroup l2_import_export
36 def ExportSTEP(self, theObject, theFileName, theUnit=GEOM.LU_METER):
38 Export the given shape into a file with given name in STEP format.
41 theObject Shape to be stored in the file.
42 theFileName Name of the file to store the given shape in.
43 theUnit the length unit (see GEOM::length_unit). In meters by default.
45 anOp = GetSTEPPluginOperations(self)
46 anOp.ExportSTEP(theObject, theFileName, theUnit)
47 if anOp.IsDone() == 0:
48 raise RuntimeError, "Export : " + anOp.GetErrorCode()
52 ## Import a shape from the STEP file with given name.
53 # @param theFileName The file, containing the shape.
54 # @param theIsIgnoreUnits If True, file length units will be ignored (set to 'meter')
55 # and result model will be scaled, if its units are not meters.
56 # If False (default), file length units will be taken into account.
57 # @param theName Object name; when specified, this parameter is used
58 # for result publication in the study. Otherwise, if automatic
59 # publication is switched on, default value is used for result name.
61 # @return New GEOM.GEOM_Object, containing the imported shape.
62 # If material names are imported it returns the list of
63 # objects. The first one is the imported object followed by
65 # @note Auto publishing is allowed for the shape itself. Imported
66 # material groups are not automatically published.
68 # @ref swig_Import_Export "Example"
69 # @ingroup l2_import_export
70 def ImportSTEP(self, theFileName, theIsIgnoreUnits = False, theName=None):
72 Import a shape from the STEP file with given name.
75 theFileName The file, containing the shape.
76 ignoreUnits If True, file length units will be ignored (set to 'meter')
77 and result model will be scaled, if its units are not meters.
78 If False (default), file length units will be taken into account.
79 theName Object name; when specified, this parameter is used
80 for result publication in the study. Otherwise, if automatic
81 publication is switched on, default value is used for result name.
84 New GEOM.GEOM_Object, containing the imported shape.
85 If material names are imported it returns the list of
86 objects. The first one is the imported object followed by
89 Auto publishing is allowed for the shape itself. Imported
90 material groups are not automatically published.
92 # Example: see GEOM_TestOthers.py
93 from salome.geom.geomBuilder import RaiseIfFailed
94 anOp = GetSTEPPluginOperations(self)
96 anIsIgnoreUnits = theIsIgnoreUnits
98 if isinstance( theIsIgnoreUnits, basestring ):
99 anIsIgnoreUnits = False
100 aName = theIsIgnoreUnits
103 aListObj = anOp.ImportSTEP(theFileName,anIsIgnoreUnits)
104 RaiseIfFailed("ImportSTEP", anOp)
105 aNbObj = len(aListObj)
107 self._autoPublish(aListObj[0], aName, "imported")
112 ## Return length unit from given STEP file
113 # @param theFileName The file, containing the shape.
114 # @return String, containing the units name.
116 # @ref swig_Import_Export "Example"
117 # @ingroup l2_import_export
118 def GetSTEPUnit(self, theFileName):
120 Return length units from given STEP file
123 theFileName The file, containing the shape.
126 String, containing the units name.
128 # Example: see GEOM_TestOthers.py
129 anOp = GetSTEPPluginOperations(self)
130 aUnitName = anOp.ReadValue( theFileName, "LEN_UNITS")