Salome HOME
0022766: [EDF] Transport of names
[modules/geom.git] / src / GEOM_SWIG / STEPPluginBuilder.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2014  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 ISTEPOperations
22
23 # Engine Library Name
24 __libraryName__ = "STEPPluginEngine"
25
26 def GetSTEPPluginOperations(self):
27     anOp = self.GetPluginOperations(self.myStudyId, __libraryName__)
28     return anOp._narrow(ISTEPOperations)
29
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):
35     """
36     Export the given shape into a file with given name in STEP format.
37
38     Parameters: 
39         theObject Shape to be stored in the file.
40         theFileName Name of the file to store the given shape in.
41     """
42     anOp = GetSTEPPluginOperations(self)
43     anOp.ExportSTEP(theObject, theFileName)
44     if anOp.IsDone() == 0:
45         raise RuntimeError,  "Export : " + anOp.GetErrorCode()
46         pass
47     pass
48
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.
57 #
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
61 #          material groups.
62 #  @note Auto publishing is allowed for the shape itself. Imported
63 #        material groups are not automatically published.
64 #
65 #  @ref swig_Import_Export "Example"
66 #  @ingroup l2_import_export
67 def ImportSTEP(self, theFileName, theIsIgnoreUnits = False, theName=None):
68     """
69     Import a shape from the STEP file with given name.
70
71     Parameters:
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.
79
80     Returns:
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
84         material groups.
85     Note:
86         Auto publishing is allowed for the shape itself. Imported
87         material groups are not automatically published.
88     """
89     # Example: see GEOM_TestOthers.py
90     from salome.geom.geomBuilder import RaiseIfFailed
91     anOp = GetSTEPPluginOperations(self)
92     
93     anIsIgnoreUnits = theIsIgnoreUnits
94     aName = theName
95     if isinstance( theIsIgnoreUnits, basestring ):
96         anIsIgnoreUnits = False
97         aName = theIsIgnoreUnits
98         pass
99
100     aListObj = anOp.ImportSTEP(theFileName,anIsIgnoreUnits)
101     RaiseIfFailed("ImportSTEP", anOp)
102     aNbObj = len(aListObj)
103     if aNbObj > 0:
104         self._autoPublish(aListObj[0], aName, "imported")
105     if aNbObj == 1:
106         return aListObj[0]
107     return aListObj
108
109 ## Return length unit from given STEP file
110 #  @param theFileName The file, containing the shape.
111 #  @return String, containing the units name.
112 #
113 #  @ref swig_Import_Export "Example"
114 #  @ingroup l2_import_export
115 def GetSTEPUnit(self, theFileName):
116     """
117     Return length units from given STEP file
118
119     Parameters:
120         theFileName The file, containing the shape.
121
122     Returns:
123         String, containing the units name.
124     """
125     # Example: see GEOM_TestOthers.py
126     anOp = GetSTEPPluginOperations(self)
127     aUnitName = anOp.ReadValue( theFileName, "LEN_UNITS")
128     return aUnitName