Kernel_Utils::Localizer - common interface to solve problems with non-"C" locales

This commit is contained in:
ouv 2009-11-02 12:24:42 +00:00
parent 5878f0928c
commit 625eaaf497
5 changed files with 15 additions and 20 deletions

View File

@ -28,6 +28,8 @@
#include <GEOMImpl_IMeasureOperations.hxx> #include <GEOMImpl_IMeasureOperations.hxx>
#include <Basics_Utils.hxx>
// OCCT Includes // OCCT Includes
#include <BRepBuilderAPI_Transform.hxx> #include <BRepBuilderAPI_Transform.hxx>
#include <BRep_Tool.hxx> #include <BRep_Tool.hxx>
@ -79,15 +81,11 @@ Standard_Integer GEOMImpl_SketcherDriver::Execute(TFunction_Logbook& log) const
TopoDS_Shape aShape; TopoDS_Shape aShape;
// Set "C" numeric locale to save numbers correctly // Set "C" numeric locale to save numbers correctly
std::string aCurLocale = setlocale(LC_NUMERIC, 0); Kernel_Utils::Localizer loc;
setlocale(LC_NUMERIC, "C");
// create sketcher // create sketcher
Sketcher_Profile aProfile (aCommand.ToCString()); Sketcher_Profile aProfile (aCommand.ToCString());
// Return previous locale
setlocale(LC_NUMERIC, aCurLocale.data());
if (!aProfile.IsDone()) { if (!aProfile.IsDone()) {
Standard_ConstructionError::Raise("Sketcher creation failed"); Standard_ConstructionError::Raise("Sketcher creation failed");
} }

View File

@ -26,6 +26,8 @@
// //
#include "utilities.h" #include "utilities.h"
#include <Basics_Utils.hxx>
#include <IGESControl_Controller.hxx> #include <IGESControl_Controller.hxx>
#include <IGESControl_Writer.hxx> #include <IGESControl_Writer.hxx>
#include <Interface_Static.hxx> #include <Interface_Static.hxx>
@ -74,8 +76,7 @@ IGESEXPORT_EXPORT
aBrepMode = 1; aBrepMode = 1;
// Set "C" numeric locale to save numbers correctly // Set "C" numeric locale to save numbers correctly
std::string aCurLocale = setlocale(LC_NUMERIC, 0); Kernel_Utils::Localizer loc;
setlocale(LC_NUMERIC, "C");
// initialize writer // initialize writer
IGESControl_Controller::Init(); IGESControl_Controller::Init();
@ -90,7 +91,6 @@ IGESEXPORT_EXPORT
bool ok = ICW.Write( theFileName.ToCString() ); bool ok = ICW.Write( theFileName.ToCString() );
// Return previous locale // Return previous locale
setlocale(LC_NUMERIC, aCurLocale.data());
if ( ok ) if ( ok )
return 1; return 1;
} }

View File

@ -26,6 +26,8 @@
// //
#include "utilities.h" #include "utilities.h"
#include <Basics_Utils.hxx>
#include <IFSelect_ReturnStatus.hxx> #include <IFSelect_ReturnStatus.hxx>
#include <IGESControl_Reader.hxx> #include <IGESControl_Reader.hxx>
#include <IGESData_IGESModel.hxx> #include <IGESData_IGESModel.hxx>
@ -72,8 +74,7 @@ IGESIMPORT_EXPORT
const TDF_Label&) const TDF_Label&)
{ {
// Set "C" numeric locale to save numbers correctly // Set "C" numeric locale to save numbers correctly
std::string aCurLocale = setlocale(LC_NUMERIC, 0); Kernel_Utils::Localizer loc;
setlocale(LC_NUMERIC, "C");
IGESControl_Reader aReader; IGESControl_Reader aReader;
TopoDS_Shape aResShape; TopoDS_Shape aResShape;
@ -103,8 +104,6 @@ IGESIMPORT_EXPORT
TopoDS_Vertex V; TopoDS_Vertex V;
B.MakeVertex(V,P,1.e-7); B.MakeVertex(V,P,1.e-7);
aResShape = V; aResShape = V;
// Return previous locale before return from import
setlocale(LC_NUMERIC, aCurLocale.data());
return aResShape; return aResShape;
} }
if( theFormatName == "IGES_SCALE" ) { if( theFormatName == "IGES_SCALE" ) {
@ -155,8 +154,6 @@ IGESIMPORT_EXPORT
theError = aFail->GetMessageString(); theError = aFail->GetMessageString();
aResShape.Nullify(); aResShape.Nullify();
} }
// Return previous locale
setlocale(LC_NUMERIC, aCurLocale.data());
return aResShape; return aResShape;
} }
} }

View File

@ -26,6 +26,8 @@
// //
#include "utilities.h" #include "utilities.h"
#include <Basics_Utils.hxx>
#include <IFSelect_ReturnStatus.hxx> #include <IFSelect_ReturnStatus.hxx>
#include <STEPControl_Writer.hxx> #include <STEPControl_Writer.hxx>
@ -68,8 +70,7 @@ STEPEXPORT_EXPORT
try try
{ {
// Set "C" numeric locale to save numbers correctly // Set "C" numeric locale to save numbers correctly
std::string aCurLocale = setlocale(LC_NUMERIC, 0); Kernel_Utils::Localizer loc;
setlocale(LC_NUMERIC, "C");
IFSelect_ReturnStatus status ; IFSelect_ReturnStatus status ;
//VRV: OCC 4.0 migration //VRV: OCC 4.0 migration
@ -83,7 +84,6 @@ STEPEXPORT_EXPORT
status = aWriter.Write( theFileName.ToCString() ); status = aWriter.Write( theFileName.ToCString() );
// Return previous locale // Return previous locale
setlocale(LC_NUMERIC, aCurLocale.data());
if ( status == IFSelect_RetDone ) if ( status == IFSelect_RetDone )
return 1; return 1;
} }

View File

@ -26,6 +26,8 @@
// //
#include "utilities.h" #include "utilities.h"
#include <Basics_Utils.hxx>
#include <BRep_Builder.hxx> #include <BRep_Builder.hxx>
#include <IFSelect_ReturnStatus.hxx> #include <IFSelect_ReturnStatus.hxx>
@ -75,8 +77,7 @@ STEPIMPORT_EXPORT
{ {
MESSAGE("Import STEP model from file " << theFileName.ToCString()); MESSAGE("Import STEP model from file " << theFileName.ToCString());
// Set "C" numeric locale to save numbers correctly // Set "C" numeric locale to save numbers correctly
std::string aCurLocale = setlocale(LC_NUMERIC, 0); Kernel_Utils::Localizer loc;
setlocale(LC_NUMERIC, "C");
TopoDS_Shape aResShape; TopoDS_Shape aResShape;
//VRV: OCC 4.0 migration //VRV: OCC 4.0 migration
STEPControl_Reader aReader; STEPControl_Reader aReader;
@ -156,7 +157,6 @@ STEPIMPORT_EXPORT
aResShape.Nullify(); aResShape.Nullify();
} }
// Return previous locale // Return previous locale
setlocale(LC_NUMERIC, aCurLocale.data());
return aResShape; return aResShape;
} }
} }