From 8051b80464008ee3173ab6608ba23d4e6ee52668 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Fri, 12 Apr 2013 13:27:10 +0200 Subject: [PATCH 1/2] Fixed locale issue#67 --- src/addons/Utils/DataExchange/STEP.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/addons/Utils/DataExchange/STEP.py b/src/addons/Utils/DataExchange/STEP.py index 32036baee..8f41cd60e 100644 --- a/src/addons/Utils/DataExchange/STEP.py +++ b/src/addons/Utils/DataExchange/STEP.py @@ -18,6 +18,7 @@ ##along with pythonOCC. If not, see . import os, os.path +import locale from OCC.TopoDS import * from OCC.BRep import * from OCC.STEPControl import * @@ -32,7 +33,6 @@ from OCC.TCollection import * from OCC.XCAFDoc import * from OCC.TDF import * -#from OCC.TopoDS import * from OCC import XCAFApp, TDocStd, TCollection, XCAFDoc, BRepPrimAPI, Quantity, TopLoc, gp, TPrsStd, XCAFPrs @@ -42,7 +42,6 @@ from OCC.Quantity import * from OCC.Utils.Topology import Topo from OCC.TopAbs import * -import os class STEPImporter(object): def __init__(self,filename=None): @@ -143,13 +142,19 @@ def add_shape(self, aShape): self._shapes.append(aShape) def write_file(self): + # workaround for an OCC bug: temporarily changing the locale in order to + # avoid issues when exporting, see: + # http://tracker.dev.opencascade.org/view.php?id=22898 + loc = locale.getlocale() + locale.setlocale(locale.LC_ALL, 'C') for shp in self._shapes: status = self.stepWriter.Transfer(shp, STEPControl_AsIs ) if status == IFSelect_RetDone: status = self.stepWriter.Write(self._filename) else: return False - + # restoring the old locale + locale.setlocale(locale.LC_ALL, loc) if self.verbose: self.stepWriter.PrintStatsTransfer() @@ -319,9 +324,16 @@ def write_file(self): WS = XSControl_WorkSession() writer = STEPCAFControl_Writer( WS.GetHandle(), False ) writer.Transfer(self.h_doc, STEPControl_AsIs) + # workaround for an OCC bug: temporarily changing the locale in order to + # avoid issues when exporting, see: + # http://tracker.dev.opencascade.org/view.php?id=22898 + loc = locale.getlocale() + locale.setlocale(locale.LC_ALL, 'C') print 'writing STEP file' status = writer.Write(self.filename) print 'status:', status + # restoring the old locale + locale.setlocale(locale.LC_ALL, loc) def TestImport(): """ From c7e050ba85d09edcf010e5102fe2018fb6be8797 Mon Sep 17 00:00:00 2001 From: tpaviot Date: Fri, 12 Apr 2013 15:38:18 +0200 Subject: [PATCH 2/2] Applied Marko Knoebl patch step/locale fix --- src/examples/OCAF/step_export.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/examples/OCAF/step_export.py b/src/examples/OCAF/step_export.py index 05e402b79..215370545 100644 --- a/src/examples/OCAF/step_export.py +++ b/src/examples/OCAF/step_export.py @@ -1,3 +1,4 @@ +import locale from OCC.XCAFApp import * from OCC.STEPCAFControl import * from OCC.TDocStd import * @@ -89,9 +90,17 @@ def step_export_layers_and_colors(event=None): writer.Transfer(h_doc, STEPControl_AsIs) pth = '.' print 'writing STEP file' + # workaround for an OCC bug: temporarily changing the locale in order to + # avoid issues when exporting, see: + # http://tracker.dev.opencascade.org/view.php?id=22898 + loc = locale.getlocale() + locale.setlocale(locale.LC_ALL, 'C') status = writer.Write(os.path.join(pth, 'step_layers_colors.step')) print 'status:', status + # restoring the old locale + locale.setlocale(locale.LC_ALL, loc) + def exit(event=None): sys.exit()