Salome HOME
e9ded2cd267362d5f67ecba8e6982fb85dfcefb9
[modules/geom.git] / src / GEOM_SWIG / STLPluginBuilder.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2014-2015  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 from GEOM import ISTLOperations
22
23 # Engine Library Name
24 __libraryName__ = "STLPluginEngine"
25
26 def GetSTLPluginOperations(self):
27     anOp = self.GetPluginOperations(self.myStudyId, __libraryName__)
28     return anOp._narrow(ISTLOperations)
29
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 ):
40     """
41     Export the given shape into a file with given name in STL format.
42
43     Parameters: 
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.
51     """
52     anOp = GetSTLPluginOperations(self)
53     anOp.ExportSTL(theObject, theFileName, theIsASCII, theDeflection, theIsRelative )
54     if anOp.IsDone() == 0:
55         raise RuntimeError,  "Export : " + anOp.GetErrorCode()
56         pass
57     pass
58
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.
64 #
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
68 #          material groups.
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):
73     """
74     Import a shape from the STL file
75
76     Parameters: 
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.
81
82     Returns:
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
86         material groups.
87     Note:
88         Auto publishing is allowed for the shape itself. Imported
89         material groups are not automatically published.
90     """
91     from salome.geom.geomBuilder import RaiseIfFailed
92     anOp = GetSTLPluginOperations(self)
93     aListObj = anOp.ImportSTL(theFileName)
94     RaiseIfFailed("ImportSTL", anOp)
95     aNbObj = len(aListObj)
96     if aNbObj > 0:
97         self._autoPublish(aListObj[0], theName, "imported")
98     if aNbObj == 1:
99         return aListObj[0]
100     return aListObj