Salome HOME
Merge branch 'hydro/imps_2015'
[modules/geom.git] / src / GEOM_SWIG / STEPPluginBuilder.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 ISTEPOperations
22 import GEOM
23
24 # Engine Library Name
25 __libraryName__ = "STEPPluginEngine"
26
27 def GetSTEPPluginOperations(self):
28     anOp = self.GetPluginOperations(self.myStudyId, __libraryName__)
29     return anOp._narrow(ISTEPOperations)
30
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):
37     """
38     Export the given shape into a file with given name in STEP format.
39
40     Parameters: 
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.
44     """
45     anOp = GetSTEPPluginOperations(self)
46     anOp.ExportSTEP(theObject, theFileName, theUnit)
47     if anOp.IsDone() == 0:
48         raise RuntimeError,  "Export : " + anOp.GetErrorCode()
49         pass
50     pass
51
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 theName Object name; when specified, this parameter is used
58 #         for result publication in the study. Otherwise, if automatic
59 #         publication is switched on, default value is used for result name.
60 #
61 #  @return New GEOM.GEOM_Object, containing the imported shape.
62 #          If material names are imported it returns the list of
63 #          objects. The first one is the imported object followed by
64 #          material groups.
65 #  @note Auto publishing is allowed for the shape itself. Imported
66 #        material groups are not automatically published.
67 #
68 #  @ref swig_Import_Export "Example"
69 #  @ingroup l2_import_export
70 def ImportSTEP(self, theFileName, theIsIgnoreUnits = False, theName=None):
71     """
72     Import a shape from the STEP file with given name.
73
74     Parameters:
75         theFileName The file, containing the shape.
76         ignoreUnits If True, file length units will be ignored (set to 'meter')
77                     and result model will be scaled, if its units are not meters.
78                     If False (default), file length units will be taken into account.
79         theName Object name; when specified, this parameter is used
80                 for result publication in the study. Otherwise, if automatic
81                 publication is switched on, default value is used for result name.
82
83     Returns:
84         New GEOM.GEOM_Object, containing the imported shape.
85         If material names are imported it returns the list of
86         objects. The first one is the imported object followed by
87         material groups.
88     Note:
89         Auto publishing is allowed for the shape itself. Imported
90         material groups are not automatically published.
91     """
92     # Example: see GEOM_TestOthers.py
93     from salome.geom.geomBuilder import RaiseIfFailed
94     anOp = GetSTEPPluginOperations(self)
95     
96     anIsIgnoreUnits = theIsIgnoreUnits
97     aName = theName
98     if isinstance( theIsIgnoreUnits, basestring ):
99         anIsIgnoreUnits = False
100         aName = theIsIgnoreUnits
101         pass
102
103     aListObj = anOp.ImportSTEP(theFileName,anIsIgnoreUnits)
104     RaiseIfFailed("ImportSTEP", anOp)
105     aNbObj = len(aListObj)
106     if aNbObj > 0:
107         self._autoPublish(aListObj[0], aName, "imported")
108     if aNbObj == 1:
109         return aListObj[0]
110     return aListObj
111
112 ## Return length unit from given STEP file
113 #  @param theFileName The file, containing the shape.
114 #  @return String, containing the units name.
115 #
116 #  @ref swig_Import_Export "Example"
117 #  @ingroup l2_import_export
118 def GetSTEPUnit(self, theFileName):
119     """
120     Return length units from given STEP file
121
122     Parameters:
123         theFileName The file, containing the shape.
124
125     Returns:
126         String, containing the units name.
127     """
128     # Example: see GEOM_TestOthers.py
129     anOp = GetSTEPPluginOperations(self)
130     aUnitName = anOp.ReadValue( theFileName, "LEN_UNITS")
131     return aUnitName