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 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 IsCreateAssemblies If True, for each assembly compound is created in
58 # the result. If False Compounds that contain a single shape
59 # are eliminated from the result.
60 # @param theName Object name; when specified, this parameter is used
61 # for result publication in the study. Otherwise, if automatic
62 # publication is switched on, default value is used for result name.
64 # @return New GEOM.GEOM_Object, containing the imported shape.
65 # If material names are imported it returns the list of
66 # objects. The first one is the imported object followed by
68 # @note Auto publishing is allowed for the shape itself. Imported
69 # material groups are not automatically published.
71 # @ref swig_Import_Export "Example"
72 # @ingroup l2_import_export
73 def ImportSTEP(self, theFileName, theIsIgnoreUnits = False,
74 IsCreateAssemblies = False, theName=None):
76 Import a shape from the STEP file with given name.
79 theFileName The file, containing the shape.
80 ignoreUnits If True, file length units will be ignored (set to 'meter')
81 and result model will be scaled, if its units are not meters.
82 If False (default), file length units will be taken into account.
83 IsCreateAssemblies If True, for each assembly compound is created in
84 the result. If False Compounds that contain a single shape
85 are eliminated from the result.
86 theName Object name; when specified, this parameter is used
87 for result publication in the study. Otherwise, if automatic
88 publication is switched on, default value is used for result name.
91 New GEOM.GEOM_Object, containing the imported shape.
92 If material names are imported it returns the list of
93 objects. The first one is the imported object followed by
96 Auto publishing is allowed for the shape itself. Imported
97 material groups are not automatically published.
99 # Example: see GEOM_TestOthers.py
100 from salome.geom.geomBuilder import RaiseIfFailed
101 anOp = GetSTEPPluginOperations(self)
103 anIsIgnoreUnits = theIsIgnoreUnits
104 anIsCreateAssemblies = IsCreateAssemblies;
106 if isinstance( theIsIgnoreUnits, basestring ):
107 anIsIgnoreUnits = False
108 aName = theIsIgnoreUnits
110 elif isinstance( IsCreateAssemblies, basestring ):
111 anIsCreateAssemblies = False
112 aName = IsCreateAssemblies
115 aListObj = anOp.ImportSTEP(theFileName,anIsIgnoreUnits,anIsCreateAssemblies)
116 RaiseIfFailed("ImportSTEP", anOp)
117 aNbObj = len(aListObj)
119 self._autoPublish(aListObj[0], aName, "imported")
124 ## Return length unit from given STEP file
125 # @param theFileName The file, containing the shape.
126 # @return String, containing the units name.
128 # @ref swig_Import_Export "Example"
129 # @ingroup l2_import_export
130 def GetSTEPUnit(self, theFileName):
132 Return length units from given STEP file
135 theFileName The file, containing the shape.
138 String, containing the units name.
140 # Example: see GEOM_TestOthers.py
141 anOp = GetSTEPPluginOperations(self)
142 aUnitName = anOp.ReadValue( theFileName, "LEN_UNITS")