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>
|
#include <cxxabi.h>
|
||||||
#endif
|
#endif
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
@ -111,5 +112,14 @@ namespace ngcore
|
|||||||
#endif
|
#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
|
} // namespace ngcore
|
||||||
|
|
||||||
|
@ -201,6 +201,8 @@ namespace ngcore
|
|||||||
NGCORE_API int GetCompiledSIMDSize();
|
NGCORE_API int GetCompiledSIMDSize();
|
||||||
NGCORE_API bool IsRangeCheckEnabled();
|
NGCORE_API bool IsRangeCheckEnabled();
|
||||||
|
|
||||||
|
NGCORE_API std::string GetTempFilename();
|
||||||
|
|
||||||
} // namespace ngcore
|
} // namespace ngcore
|
||||||
|
|
||||||
#endif // NETGEN_CORE_UTILS_HPP
|
#endif // NETGEN_CORE_UTILS_HPP
|
||||||
|
@ -58,11 +58,11 @@ namespace netgen
|
|||||||
|
|
||||||
OCCGeometry::OCCGeometry(const TopoDS_Shape& _shape, int aoccdim)
|
OCCGeometry::OCCGeometry(const TopoDS_Shape& _shape, int aoccdim)
|
||||||
{
|
{
|
||||||
auto filename = ".tmpfile_out.step";
|
auto filename = GetTempFilename();
|
||||||
step_utils::WriteSTEP(_shape, filename);
|
step_utils::WriteSTEP(_shape, filename.c_str());
|
||||||
LoadOCCInto(this, filename);
|
LoadOCCInto(this, filename.c_str());
|
||||||
occdim = aoccdim;
|
occdim = aoccdim;
|
||||||
std::remove(filename);
|
std::remove(filename.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
string STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * aReader)
|
string STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * aReader)
|
||||||
@ -1650,24 +1650,24 @@ namespace netgen
|
|||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
STEPControl_Writer writer;
|
STEPControl_Writer writer;
|
||||||
writer.Transfer(shape, STEPControl_AsIs);
|
writer.Transfer(shape, STEPControl_AsIs);
|
||||||
auto filename = ".tmpfile_out.step";
|
auto filename = GetTempFilename();
|
||||||
writer.Write(filename);
|
writer.Write(filename.c_str());
|
||||||
std::ifstream is(filename);
|
std::ifstream is(filename.c_str());
|
||||||
ss << is.rdbuf();
|
ss << is.rdbuf();
|
||||||
ar << ss.str();
|
ar << ss.str();
|
||||||
std::remove(filename);
|
std::remove(filename.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::string str;
|
std::string str;
|
||||||
ar & str;
|
ar & str;
|
||||||
|
|
||||||
auto filename = ".tmpfile.step";
|
auto filename = GetTempFilename();
|
||||||
auto tmpfile = std::fopen(filename, "w");
|
auto tmpfile = std::fopen(filename.c_str(), "w");
|
||||||
std::fputs(str.c_str(), tmpfile);
|
std::fputs(str.c_str(), tmpfile);
|
||||||
std::fclose(tmpfile);
|
std::fclose(tmpfile);
|
||||||
LoadOCCInto(this, filename);
|
LoadOCCInto(this, filename.c_str());
|
||||||
std::remove(filename);
|
std::remove(filename.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user