mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
util function GetTempFilename()
This commit is contained in:
parent
ef1bf2f727
commit
747367ab8a
@ -7,6 +7,7 @@
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
#include <array>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
|
||||
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user