]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/GeomAlgoAPI/GeomAlgoAPI_STLExport.cpp
Salome HOME
updated copyright message
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_STLExport.cpp
index e7d82b642a068582c46b2cd49f70f944c0123c1c..1c742269f323a939476c79e3e4dcbf5ec7a8e362 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #define MAX3(X, Y, Z)   ( MAX2 ( MAX2(X, Y) , Z ) )
 
 bool STLExport(const std::string& theFileName,
-                const std::string& /*theFormatName*/,
-                const std::shared_ptr<GeomAPI_Shape>& theShape,
-                const double aDeflection,
-                const bool anIsRelative, 
-                const bool anIsASCII,
-                std::string& theError)
+               const std::shared_ptr<GeomAPI_Shape>& theShape,
+               const double theDeflection,
+               const bool theIsRelative,
+               const bool theIsASCII,
+               std::string& theError)
 {
   #ifdef _DEBUG
   std::cout << "Export STl into file " << theFileName << std::endl;
@@ -56,28 +55,29 @@ bool STLExport(const std::string& theFileName,
 
   try
   {
-    // Set "C" numeric locale to save numbers correctly
-    GeomAlgoAPI_Tools::Localizer loc;
 
-    double lDeflection = aDeflection;
+    double aDeflection = theDeflection;
     StlAPI_Writer aWriter;
     // copy source shape
     BRepBuilderAPI_Copy aCopy( theShape->impl<TopoDS_Shape>(), Standard_False );
     TopoDS_Shape aCopyShape = aCopy.Shape();
     // ASCII mode
-    aWriter.ASCIIMode() = anIsASCII;
-    if ( anIsRelative ) {
+    aWriter.ASCIIMode() = theIsASCII;
+    if ( theIsRelative ) {
       Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
-      Bnd_Box bndBox;
-      BRepBndLib::Add( theShape->impl<TopoDS_Shape>(), bndBox );
-      bndBox.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
-      lDeflection = MAX3( aXmax-aXmin, aYmax-aYmin, aZmax-aZmin ) * aDeflection;
+      Bnd_Box aBndBox;
+      BRepBndLib::Add( theShape->impl<TopoDS_Shape>(), aBndBox );
+      aBndBox.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
+      aDeflection = MAX3( aXmax-aXmin, aYmax-aYmin, aZmax-aZmin ) * theDeflection;
     }
     //Compute triangulation
     BRepTools::Clean( aCopyShape );
-    BRepMesh_IncrementalMesh aMesh( aCopyShape, lDeflection );
-    aWriter.Write( aCopyShape, theFileName.c_str() );
+    BRepMesh_IncrementalMesh aMesh( aCopyShape, aDeflection );
 
+    if (!aWriter.Write( aCopyShape, theFileName.c_str())) {
+      theError = "STL Export failed";
+      return false;
+    }
     return true;
   }
   catch( Standard_Failure )