Salome HOME
updated copyright message
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_STLExport.cpp
index bf30792b239f5cda3d8ad52c507b0615cc37a8bf..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
@@ -56,7 +56,7 @@ bool STLExport(const std::string& theFileName,
   try
   {
 
-    double lDeflection = theDeflection;
+    double aDeflection = theDeflection;
     StlAPI_Writer aWriter;
     // copy source shape
     BRepBuilderAPI_Copy aCopy( theShape->impl<TopoDS_Shape>(), Standard_False );
@@ -65,15 +65,19 @@ bool STLExport(const std::string& theFileName,
     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 ) * theDeflection;
+      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
-    BRepMesh_IncrementalMesh aMesh( aCopyShape, lDeflection );
-    aWriter.Write( aCopyShape, theFileName.c_str() );
+    BRepTools::Clean( aCopyShape );
+    BRepMesh_IncrementalMesh aMesh( aCopyShape, aDeflection );
 
+    if (!aWriter.Write( aCopyShape, theFileName.c_str())) {
+      theError = "STL Export failed";
+      return false;
+    }
     return true;
   }
   catch( Standard_Failure )