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 ISTLOperations
24 __libraryName__ = "STLPluginEngine"
26 def GetSTLPluginOperations(self):
27 anOp = self.GetPluginOperations(self.myStudyId, __libraryName__)
28 return anOp._narrow(ISTLOperations)
30 ## Export the given shape into a file with given name in STL 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 theIsASCII The format of the exported file (ASCII or Binary)
34 # @param theDeflection Deflection of the given shape.
35 # @param theIsRelative If True (default value), the deflection
36 # is calculated relatively to the size of the shape;
37 # if False, the user defined deflection is used.
38 # @ingroup l2_import_export
39 def ExportSTL(self, theObject, theFileName, theIsASCII = True, theDeflection = 0.001, theIsRelative = True ):
41 Export the given shape into a file with given name in STL format.
44 theObject Shape to be stored in the file.
45 theFileName Name of the file to store the given shape in.
46 theIsASCII The format of the exported file (ASCII or Binary).
47 theDeflection Deflection of the given shape.
48 theRelative If True (default value), the deflection
49 is calculated relatively to the size of the shape;
50 if False, the user defined deflection is used.
52 anOp = GetSTLPluginOperations(self)
53 anOp.ExportSTL(theObject, theFileName, theIsASCII, theDeflection, theIsRelative )
54 if anOp.IsDone() == 0:
55 raise RuntimeError, "Export : " + anOp.GetErrorCode()
59 ## Import a shape from the STL file
60 # @param theFileName The file, containing the shape.
61 # @param theName Object name; when specified, this parameter is used
62 # for result publication in the study. Otherwise, if automatic
63 # publication is switched on, default value is used for result name.
65 # @return New GEOM.GEOM_Object, containing the imported shape.
66 # If material names are imported it returns the list of
67 # objects. The first one is the imported object followed by
69 # @note Auto publishing is allowed for the shape itself. Imported
70 # material groups are not automatically published.
71 # @ingroup l2_import_export
72 def ImportSTL(self, theFileName, theName=None):
74 Import a shape from the STL file
77 theFileName The file, containing the shape.
78 theName Object name; when specified, this parameter is used
79 for result publication in the study. Otherwise, if automatic
80 publication is switched on, default value is used for result name.
83 New GEOM.GEOM_Object, containing the imported shape.
84 If material names are imported it returns the list of
85 objects. The first one is the imported object followed by
88 Auto publishing is allowed for the shape itself. Imported
89 material groups are not automatically published.
91 from salome.geom.geomBuilder import RaiseIfFailed
92 anOp = GetSTLPluginOperations(self)
93 aListObj = anOp.ImportSTL(theFileName)
94 RaiseIfFailed("ImportSTL", anOp)
95 aNbObj = len(aListObj)
97 self._autoPublish(aListObj[0], theName, "imported")