diff --git a/LatticeDehomogenization/src/fileExchange/CADExtensions.h b/LatticeDehomogenization/src/fileExchange/CADExtensions.h index 568fb9a5d538734192e767025d17b302365970bd..fd057c7f8432c6d1fc46823484cf74f3ced376aa 100644 --- a/LatticeDehomogenization/src/fileExchange/CADExtensions.h +++ b/LatticeDehomogenization/src/fileExchange/CADExtensions.h @@ -4,7 +4,7 @@ enum FileExt { Invalid = 0, - STEP, IGES, STL, + STEP, IGES, STL, STLB }; typedef std::unordered_map<std::string, FileExt> ExtensionFinder; @@ -17,4 +17,8 @@ static const ExtensionFinder fileExtensions = { { ".iges", IGES }, { ".igs", IGES }, { ".ige", IGES }, + + { ".stla", STL }, + { ".stlb", STLB }, + { ".stl", STL }, }; \ No newline at end of file diff --git a/LatticeDehomogenization/src/fileExchange/CADwriter.cpp b/LatticeDehomogenization/src/fileExchange/CADwriter.cpp index 7374b2c511a6f750dd40a597fa46655ef6166774..73f497c3c28bfd4f2371dbd32736c0a9fd0be6c4 100644 --- a/LatticeDehomogenization/src/fileExchange/CADwriter.cpp +++ b/LatticeDehomogenization/src/fileExchange/CADwriter.cpp @@ -5,6 +5,10 @@ #include "STEPControl_Writer.hxx" #include "IGESControl_Writer.hxx" +#include "StlAPI_Writer.hxx" +#include "Standard_WarningsDisable.hxx" +#include "BRepMesh_IncrementalMesh.hxx" +#include "Standard_WarningsRestore.hxx" CADwriter::CADwriter(const std::string& savepath) { @@ -13,6 +17,8 @@ CADwriter::CADwriter(const std::string& savepath) { case FileExt::STEP: case FileExt::IGES: + case FileExt::STL: + case FileExt::STLB: _saveType = ext; break; @@ -35,6 +41,10 @@ void CADwriter::write(const TopoDS_Shape& saveshape) case IGES: writeIGES(saveshape); return; + case STLB: + case STL: + writeSTL(saveshape); + return; default: _errors.push(ErrorCodes::UnknownError); _errorMsgs.push("File Extension not defined"); @@ -98,3 +108,22 @@ void CADwriter::writeIGES(const TopoDS_Shape& saveshape) _errorMsgs.push("Unknown error occured while exporting"); } } + +void CADwriter::writeSTL(const TopoDS_Shape& saveshape) +{ + IMeshTools_Parameters meshParams; + BRepMesh_IncrementalMesh mesher(saveshape, meshParams); + mesher.Perform(); + + StlAPI_Writer writer; + if (_saveType == STLB) + writer.ASCIIMode() = false; + Message::DefaultMessenger()->RemovePrinters(STANDARD_TYPE(Message_PrinterOStream)); + bool status = writer.Write(saveshape, _savepath.c_str()); + + if (status == false) + { + _errors.push(ErrorCodes::SaveFailed); + _errorMsgs.push("Unknown error occured while exporting"); + } +} diff --git a/LatticeDehomogenization/src/fileExchange/CADwriter.h b/LatticeDehomogenization/src/fileExchange/CADwriter.h index b7f1c68b5a381d48b0192085f6fff4f2e3e989ef..7e55c2c9f9241792a31a991d9fbf2d8d48f6df92 100644 --- a/LatticeDehomogenization/src/fileExchange/CADwriter.h +++ b/LatticeDehomogenization/src/fileExchange/CADwriter.h @@ -18,6 +18,7 @@ private: void writeSTEP(const TopoDS_Shape& saveshape); void writeIGES(const TopoDS_Shape& saveshape); + void writeSTL(const TopoDS_Shape& saveshape); public: CADwriter()