Skip to content

Commit 6a87bd6

Browse files
committed
Merge pull request #123 from tpaviot/tp/STEP-locale
Tp/step locale
2 parents 190bca0 + c7e050b commit 6a87bd6

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/addons/Utils/DataExchange/STEP.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
1919

2020
import os, os.path
21+
import locale
2122
from OCC.TopoDS import *
2223
from OCC.BRep import *
2324
from OCC.STEPControl import *
@@ -32,7 +33,6 @@
3233
from OCC.TCollection import *
3334
from OCC.XCAFDoc import *
3435
from OCC.TDF import *
35-
#from OCC.TopoDS import *
3636

3737
from OCC import XCAFApp, TDocStd, TCollection, XCAFDoc, BRepPrimAPI, Quantity, TopLoc, gp, TPrsStd, XCAFPrs
3838

@@ -42,7 +42,6 @@
4242
from OCC.Quantity import *
4343
from OCC.Utils.Topology import Topo
4444
from OCC.TopAbs import *
45-
import os
4645

4746
class STEPImporter(object):
4847
def __init__(self,filename=None):
@@ -143,13 +142,19 @@ def add_shape(self, aShape):
143142
self._shapes.append(aShape)
144143

145144
def write_file(self):
145+
# workaround for an OCC bug: temporarily changing the locale in order to
146+
# avoid issues when exporting, see:
147+
# http://tracker.dev.opencascade.org/view.php?id=22898
148+
loc = locale.getlocale()
149+
locale.setlocale(locale.LC_ALL, 'C')
146150
for shp in self._shapes:
147151
status = self.stepWriter.Transfer(shp, STEPControl_AsIs )
148152
if status == IFSelect_RetDone:
149153
status = self.stepWriter.Write(self._filename)
150154
else:
151155
return False
152-
156+
# restoring the old locale
157+
locale.setlocale(locale.LC_ALL, loc)
153158
if self.verbose:
154159
self.stepWriter.PrintStatsTransfer()
155160

@@ -319,9 +324,16 @@ def write_file(self):
319324
WS = XSControl_WorkSession()
320325
writer = STEPCAFControl_Writer( WS.GetHandle(), False )
321326
writer.Transfer(self.h_doc, STEPControl_AsIs)
327+
# workaround for an OCC bug: temporarily changing the locale in order to
328+
# avoid issues when exporting, see:
329+
# http://tracker.dev.opencascade.org/view.php?id=22898
330+
loc = locale.getlocale()
331+
locale.setlocale(locale.LC_ALL, 'C')
322332
print 'writing STEP file'
323333
status = writer.Write(self.filename)
324334
print 'status:', status
335+
# restoring the old locale
336+
locale.setlocale(locale.LC_ALL, loc)
325337

326338
def TestImport():
327339
"""

src/examples/OCAF/step_export.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import locale
12
from OCC.XCAFApp import *
23
from OCC.STEPCAFControl import *
34
from OCC.TDocStd import *
@@ -89,9 +90,17 @@ def step_export_layers_and_colors(event=None):
8990
writer.Transfer(h_doc, STEPControl_AsIs)
9091
pth = '.'
9192
print 'writing STEP file'
93+
# workaround for an OCC bug: temporarily changing the locale in order to
94+
# avoid issues when exporting, see:
95+
# http://tracker.dev.opencascade.org/view.php?id=22898
96+
loc = locale.getlocale()
97+
locale.setlocale(locale.LC_ALL, 'C')
9298
status = writer.Write(os.path.join(pth, 'step_layers_colors.step'))
9399
print 'status:', status
94100

101+
# restoring the old locale
102+
locale.setlocale(locale.LC_ALL, loc)
103+
95104
def exit(event=None):
96105
sys.exit()
97106

0 commit comments

Comments
 (0)