1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <StlAPI_Writer.ixx>
15 #include <StlTransfer.hxx>
16 #include <TopoDS_Shape.hxx>
17 #include <Bnd_Box.hxx>
19 #include <BRepBndLib.hxx>
20 #include <OSD_Path.hxx>
22 StlAPI_Writer::StlAPI_Writer()
24 theStlMesh = new StlMesh_Mesh;
25 theASCIIMode = Standard_True;
28 Standard_Boolean& StlAPI_Writer::ASCIIMode()
33 StlAPI_ErrorStatus StlAPI_Writer::Write(const TopoDS_Shape& theShape, const Standard_CString theFileName)
35 OSD_Path aFile(theFileName);
36 StlTransfer::RetrieveMesh(theShape, theStlMesh);
38 if (theStlMesh.IsNull() || theStlMesh->IsEmpty())
39 return StlAPI_MeshIsEmpty;
41 // Write the built mesh
42 Standard_Boolean wasFileOpened = Standard_False;
44 wasFileOpened = RWStl::WriteAscii(theStlMesh, aFile);
47 wasFileOpened = RWStl::WriteBinary(theStlMesh, aFile);
51 return StlAPI_CannotOpenFile;
53 return StlAPI_StatusOK;