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
24 __libraryName__ = "STEPPluginEngine"
26 def GetSTEPPluginOperations(self):
27 anOp = self.GetPluginOperations(self.myStudyId, __libraryName__)
28 return anOp._narrow(ISTEPOperations)
30 ## Export the given shape into a file with given name in STEP 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 ExportSTEP(self, theObject, theFileName):
36 Export the given shape into a file with given name in STEP format.
39 theObject Shape to be stored in the file.
40 theFileName Name of the file to store the given shape in.
42 anOp = GetSTEPPluginOperations(self)
43 anOp.ExportSTEP(theObject, theFileName)
44 if anOp.IsDone() == 0:
45 raise RuntimeError, "Export : " + anOp.GetErrorCode()
49 ## Import a shape from the STEP file with given name.
50 # @param theFileName The file, containing the shape.
51 # @param theIsIgnoreUnits If True, file length units will be ignored (set to 'meter')
52 # and result model will be scaled, if its units are not meters.
53 # If False (default), file length units will be taken into account.
54 # @param theName Object name; when specified, this parameter is used
55 # for result publication in the study. Otherwise, if automatic
56 # publication is switched on, default value is used for result name.
58 # @return New GEOM.GEOM_Object, containing the imported shape.
59 # If material names are imported it returns the list of
60 # objects. The first one is the imported object followed by
62 # @note Auto publishing is allowed for the shape itself. Imported
63 # material groups are not automatically published.
65 # @ref swig_Import_Export "Example"
66 # @ingroup l2_import_export
67 def ImportSTEP(self, theFileName, theIsIgnoreUnits = False, theName=None):
69 Import a shape from the STEP file with given name.
72 theFileName The file, containing the shape.
73 ignoreUnits If True, file length units will be ignored (set to 'meter')
74 and result model will be scaled, if its units are not meters.
75 If False (default), file length units will be taken into account.
76 theName Object name; when specified, this parameter is used
77 for result publication in the study. Otherwise, if automatic
78 publication is switched on, default value is used for result name.
81 New GEOM.GEOM_Object, containing the imported shape.
82 If material names are imported it returns the list of
83 objects. The first one is the imported object followed by
86 Auto publishing is allowed for the shape itself. Imported
87 material groups are not automatically published.
89 # Example: see GEOM_TestOthers.py
90 from salome.geom.geomBuilder import RaiseIfFailed
91 anOp = GetSTEPPluginOperations(self)
93 anIsIgnoreUnits = theIsIgnoreUnits
95 if isinstance( theIsIgnoreUnits, basestring ):
96 anIsIgnoreUnits = False
97 aName = theIsIgnoreUnits
100 aListObj = anOp.ImportSTEP(theFileName,anIsIgnoreUnits)
101 RaiseIfFailed("ImportSTEP", anOp)
102 aNbObj = len(aListObj)
104 self._autoPublish(aListObj[0], aName, "imported")
109 ## Return length unit from given STEP file
110 # @param theFileName The file, containing the shape.
111 # @return String, containing the units name.
113 # @ref swig_Import_Export "Example"
114 # @ingroup l2_import_export
115 def GetSTEPUnit(self, theFileName):
117 Return length units from given STEP file
120 theFileName The file, containing the shape.
123 String, containing the units name.
125 # Example: see GEOM_TestOthers.py
126 anOp = GetSTEPPluginOperations(self)
127 aUnitName = anOp.ReadValue( theFileName, "LEN_UNITS")