diff --git a/libsrc/core/utils.cpp b/libsrc/core/utils.cpp index 107d131c..28247492 100644 --- a/libsrc/core/utils.cpp +++ b/libsrc/core/utils.cpp @@ -7,6 +7,7 @@ #include #endif #include +#include #include #include @@ -111,5 +112,14 @@ namespace ngcore #endif } + NGCORE_API std::string GetTempFilename() + { + static int counter = 0; + auto path = std::filesystem::temp_directory_path(); + std::string filename = ".temp_netgen_file_"+ToString(counter++)+"_"+ToString(GetTimeCounter()); + path.append(filename); + return path; + } + } // namespace ngcore diff --git a/libsrc/core/utils.hpp b/libsrc/core/utils.hpp index f9783c7b..e48b7162 100644 --- a/libsrc/core/utils.hpp +++ b/libsrc/core/utils.hpp @@ -201,6 +201,8 @@ namespace ngcore NGCORE_API int GetCompiledSIMDSize(); NGCORE_API bool IsRangeCheckEnabled(); + NGCORE_API std::string GetTempFilename(); + } // namespace ngcore #endif // NETGEN_CORE_UTILS_HPP diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index 537da6ef..cb80b790 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -58,11 +58,11 @@ namespace netgen OCCGeometry::OCCGeometry(const TopoDS_Shape& _shape, int aoccdim) { - auto filename = ".tmpfile_out.step"; - step_utils::WriteSTEP(_shape, filename); - LoadOCCInto(this, filename); + auto filename = GetTempFilename(); + step_utils::WriteSTEP(_shape, filename.c_str()); + LoadOCCInto(this, filename.c_str()); occdim = aoccdim; - std::remove(filename); + std::remove(filename.c_str()); } string STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * aReader) @@ -1650,24 +1650,24 @@ namespace netgen std::stringstream ss; STEPControl_Writer writer; writer.Transfer(shape, STEPControl_AsIs); - auto filename = ".tmpfile_out.step"; - writer.Write(filename); - std::ifstream is(filename); + auto filename = GetTempFilename(); + writer.Write(filename.c_str()); + std::ifstream is(filename.c_str()); ss << is.rdbuf(); ar << ss.str(); - std::remove(filename); + std::remove(filename.c_str()); } else { std::string str; ar & str; - auto filename = ".tmpfile.step"; - auto tmpfile = std::fopen(filename, "w"); + auto filename = GetTempFilename(); + auto tmpfile = std::fopen(filename.c_str(), "w"); std::fputs(str.c_str(), tmpfile); std::fclose(tmpfile); - LoadOCCInto(this, filename); - std::remove(filename); + LoadOCCInto(this, filename.c_str()); + std::remove(filename.c_str()); } }