diff --git a/libsrc/core/archive.hpp b/libsrc/core/archive.hpp index 4d72e826..f841bb14 100644 --- a/libsrc/core/archive.hpp +++ b/libsrc/core/archive.hpp @@ -5,6 +5,7 @@ #include // for array #include // for complex #include // for size_t, strlen +#include // for path #include // for ifstream, ofstream #include // for function #include // for map @@ -740,7 +741,7 @@ namespace ngcore BinaryOutArchive(std::shared_ptr&& astream) : Archive(true), stream(std::move(astream)) { } - BinaryOutArchive(const std::string& filename) + BinaryOutArchive(const std::filesystem::path& filename) : BinaryOutArchive(std::make_shared(filename)) {} ~BinaryOutArchive () override { FlushBuffer(); } @@ -828,7 +829,7 @@ namespace ngcore BinaryInArchive (std::shared_ptr&& astream) : Archive(false), stream(std::move(astream)) { } - BinaryInArchive (const std::string& filename) + BinaryInArchive (const std::filesystem::path& filename) : BinaryInArchive(std::make_shared(filename)) { ; } using Archive::operator&; @@ -903,7 +904,7 @@ namespace ngcore TextOutArchive (std::shared_ptr&& astream) : Archive(true), stream(std::move(astream)) { } - TextOutArchive (const std::string& filename) : + TextOutArchive (const std::filesystem::path& filename) : TextOutArchive(std::make_shared(filename)) { } using Archive::operator&; @@ -958,7 +959,7 @@ namespace ngcore TextInArchive (std::shared_ptr&& astream) : Archive(false), stream(std::move(astream)) { } - TextInArchive (const std::string& filename) + TextInArchive (const std::filesystem::path& filename) : TextInArchive(std::make_shared(filename)) {} using Archive::operator&; diff --git a/libsrc/core/python_ngcore.hpp b/libsrc/core/python_ngcore.hpp index d1b41eab..bf78fe59 100644 --- a/libsrc/core/python_ngcore.hpp +++ b/libsrc/core/python_ngcore.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "array.hpp" #include "table.hpp" diff --git a/libsrc/core/utils.cpp b/libsrc/core/utils.cpp index b0ad1e98..62d4d136 100644 --- a/libsrc/core/utils.cpp +++ b/libsrc/core/utils.cpp @@ -112,13 +112,12 @@ namespace ngcore #endif } - NGCORE_API std::string GetTempFilename() + NGCORE_API std::filesystem::path 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.string(); + path += ".temp_netgen_file_"+ToString(counter++)+"_"+ToString(GetTimeCounter()); + return path; } } // namespace ngcore diff --git a/libsrc/core/utils.hpp b/libsrc/core/utils.hpp index e48b7162..87a619ed 100644 --- a/libsrc/core/utils.hpp +++ b/libsrc/core/utils.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -81,6 +82,22 @@ namespace ngcore return ss.str(); } + inline std::string ToLower( const std::string & s ) + { + std::string res; + res.reserve(s.size()); + + for(auto & c : res) + res.push_back(tolower(c)); + + return res; + } + + inline std::string ToLower( const std::filesystem::path & p ) + { + return ToLower(p.string()); + } + template std::ostream& operator << (std::ostream& ost, const std::map& map) { @@ -201,7 +218,7 @@ namespace ngcore NGCORE_API int GetCompiledSIMDSize(); NGCORE_API bool IsRangeCheckEnabled(); - NGCORE_API std::string GetTempFilename(); + NGCORE_API std::filesystem::path GetTempFilename(); } // namespace ngcore diff --git a/libsrc/csg/csgeom.cpp b/libsrc/csg/csgeom.cpp index 663b60d1..45c76170 100644 --- a/libsrc/csg/csgeom.cpp +++ b/libsrc/csg/csgeom.cpp @@ -264,7 +264,7 @@ namespace netgen } - void CSGeometry :: Save (string filename) const + void CSGeometry :: Save (const filesystem::path & filename) const { ofstream ost (filename.c_str()); Save (ost); @@ -1619,21 +1619,21 @@ namespace netgen class CSGeometryRegister : public GeometryRegister { public: - virtual NetgenGeometry * Load (string filename) const; + virtual NetgenGeometry * Load (const filesystem::path & filename) const; virtual NetgenGeometry * LoadFromMeshFile (istream & ist, string token) const; // virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const; }; extern CSGeometry * ParseCSG (istream & istr, CSGeometry *instance=nullptr); - NetgenGeometry * CSGeometryRegister :: Load (string filename) const + NetgenGeometry * CSGeometryRegister :: Load (const filesystem::path & filename) const { - const char * cfilename = filename.c_str(); - if (strcmp (&cfilename[strlen(cfilename)-3], "geo") == 0) + string extension = filename.extension().string(); + if (extension == ".geo") { - PrintMessage (1, "Load CSG geometry file ", cfilename); + PrintMessage (1, "Load CSG geometry file ", filename); - ifstream infile(cfilename); + ifstream infile(filename); CSGeometry * hgeom = ParseCSG (infile); if (!hgeom) @@ -1643,18 +1643,16 @@ namespace netgen return hgeom; } - if (strcmp (&cfilename[strlen(cfilename)-3], "ngg") == 0) + if (extension == ".ngg") { - PrintMessage (1, "Load new CSG geometry file ", cfilename); + PrintMessage (1, "Load new CSG geometry file ", filename); - ifstream infile(cfilename); + ifstream infile(filename); CSGeometry * hgeom = new CSGeometry(""); hgeom -> Load (infile); return hgeom; } - - return NULL; } diff --git a/libsrc/csg/csgeom.hpp b/libsrc/csg/csgeom.hpp index 1ba979c4..63de9443 100644 --- a/libsrc/csg/csgeom.hpp +++ b/libsrc/csg/csgeom.hpp @@ -182,7 +182,7 @@ namespace netgen void Clean (); - virtual void Save (string filename) const override; + virtual void Save (const filesystem::path & filename) const override; void Save (ostream & ost) const; void Load (istream & ist); diff --git a/libsrc/csg/csgpkg.cpp b/libsrc/csg/csgpkg.cpp index 0e1e39d9..488d7bc2 100644 --- a/libsrc/csg/csgpkg.cpp +++ b/libsrc/csg/csgpkg.cpp @@ -547,86 +547,10 @@ namespace netgen } - /* - class CSGeometryRegister : public GeometryRegister - { - public: - virtual NetgenGeometry * Load (string filename) const; - virtual NetgenGeometry * LoadFromMeshFile (istream & ist) const; - virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const; - }; - - extern CSGeometry * ParseCSG (istream & istr); - - NetgenGeometry * CSGeometryRegister :: Load (string filename) const - { - const char * cfilename = filename.c_str(); - if (strcmp (&cfilename[strlen(cfilename)-3], "geo") == 0) - { - PrintMessage (1, "Load CSG geometry file ", cfilename); - - ifstream infile(cfilename); - - CSGeometry * hgeom = ParseCSG (infile); - if (!hgeom) - throw NgException ("geo-file should start with 'algebraic3d'"); - - hgeom -> FindIdenticSurfaces(1e-8 * hgeom->MaxSize()); - return hgeom; - } - - if (strcmp (&cfilename[strlen(cfilename)-3], "ngg") == 0) - { - PrintMessage (1, "Load new CSG geometry file ", cfilename); - - ifstream infile(cfilename); - CSGeometry * hgeom = new CSGeometry(""); - hgeom -> Load (infile); - - return hgeom; - } - - - - return NULL; - } - - NetgenGeometry * CSGeometryRegister :: LoadFromMeshFile (istream & ist) const - { - string auxstring; - if (ist.good()) - { - ist >> auxstring; - if (auxstring == "csgsurfaces") - { - CSGeometry * geometry = new CSGeometry (""); - geometry -> LoadSurfaces(ist); - return geometry; - } - // else - // ist.putback (auxstring); - } - return NULL; - } - - VisualScene * CSGeometryRegister :: GetVisualScene (const NetgenGeometry * geom) const - { - CSGeometry * geometry = dynamic_cast (ng_geometry.get()); - if (geometry) - { - vsgeom.SetGeometry (geometry); - return &vsgeom; - } - return NULL; - } - */ - - - class CSGeometryVisRegister : public GeometryRegister { public: - virtual NetgenGeometry * Load (string filename) const { return NULL; } + virtual NetgenGeometry * Load (const filesystem::path & filename) const { return NULL; } virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const; }; diff --git a/libsrc/general/gzstream.cpp b/libsrc/general/gzstream.cpp index 95c90f51..49003377 100644 --- a/libsrc/general/gzstream.cpp +++ b/libsrc/general/gzstream.cpp @@ -44,7 +44,7 @@ namespace GZSTREAM_NAMESPACE { // class gzstreambuf: // -------------------------------------- -gzstreambuf* gzstreambuf::open( const char* name, int open_mode) { +gzstreambuf* gzstreambuf::open( const filesystem::path & name, int open_mode) { if ( is_open()) return (gzstreambuf*)0; mode = open_mode; @@ -60,7 +60,11 @@ gzstreambuf* gzstreambuf::open( const char* name, int open_mode) { *fmodeptr++ = 'w'; *fmodeptr++ = 'b'; *fmodeptr = '\0'; - file = gzopen( name, fmode); +#ifdef WIN32 + file = gzopen_w( name.c_str(), fmode); +#else // WIN32 + file = gzopen( name.c_str(), fmode); +#endif // WIN32 if (file == 0) return (gzstreambuf*)0; opened = 1; @@ -139,17 +143,17 @@ int gzstreambuf::sync() { // class gzstreambase: // -------------------------------------- -gzstreambase::gzstreambase( const char* name, int mode) { +gzstreambase::gzstreambase( const filesystem::path & name, int mode) { init( &buf); - open( name, mode); + open( name.c_str(), mode); } gzstreambase::~gzstreambase() { buf.close(); } -void gzstreambase::open( const char* name, int open_mode) { - if ( ! buf.open( name, open_mode)) +void gzstreambase::open( const filesystem::path & name, int open_mode) { + if ( ! buf.open( name.c_str(), open_mode)) clear( rdstate() | std::ios::badbit); } diff --git a/libsrc/general/gzstream.h b/libsrc/general/gzstream.h index 74854a80..6f0c8060 100644 --- a/libsrc/general/gzstream.h +++ b/libsrc/general/gzstream.h @@ -62,7 +62,7 @@ public: // ASSERT: both input & output capabilities will not be used together } int is_open() { return opened; } - gzstreambuf* open( const char* name, int open_mode); + gzstreambuf* open( const filesystem::path & name, int open_mode); gzstreambuf* close(); ~gzstreambuf() { close(); } @@ -76,9 +76,9 @@ protected: gzstreambuf buf; public: gzstreambase() { init(&buf); } - DLL_HEADER gzstreambase( const char* name, int open_mode); + DLL_HEADER gzstreambase( const filesystem::path & name, int open_mode); DLL_HEADER ~gzstreambase(); - void open( const char* name, int open_mode); + void open( const filesystem::path & name, int open_mode); void close(); gzstreambuf* rdbuf() { return &buf; } }; @@ -92,10 +92,10 @@ public: class DLL_HEADER igzstream : public gzstreambase, public std::istream { public: igzstream() : std::istream( &buf) {} - igzstream( const char* name, int open_mode = std::ios::in) + igzstream( const filesystem::path & name, int open_mode = std::ios::in) : gzstreambase( name, open_mode), std::istream( &buf) {} gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); } - void open( const char* name, int open_mode = std::ios::in) { + void open( const filesystem::path & name, int open_mode = std::ios::in) { gzstreambase::open( name, open_mode); } }; @@ -103,10 +103,10 @@ public: class DLL_HEADER ogzstream : public gzstreambase, public std::ostream { public: ogzstream() : std::ostream( &buf) {} - ogzstream( const char* name, int mode = std::ios::out) + ogzstream( const filesystem::path & name, int mode = std::ios::out) : gzstreambase( name, mode), std::ostream( &buf) {} gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); } - void open( const char* name, int open_mode = std::ios::out) { + void open( const filesystem::path & name, int open_mode = std::ios::out) { gzstreambase::open( name, open_mode); } }; diff --git a/libsrc/general/mystring.cpp b/libsrc/general/mystring.cpp index c5525da1..a369fed5 100644 --- a/libsrc/general/mystring.cpp +++ b/libsrc/general/mystring.cpp @@ -223,6 +223,10 @@ MyStr::MyStr(const string & st) strcpy (str, st.c_str()); } +MyStr::MyStr(const filesystem::path & path) + : MyStr(path.string()) +{ } + MyStr MyStr::Left(unsigned r) diff --git a/libsrc/general/mystring.hpp b/libsrc/general/mystring.hpp index 0fb2bbd2..ee364d77 100644 --- a/libsrc/general/mystring.hpp +++ b/libsrc/general/mystring.hpp @@ -19,6 +19,8 @@ #ifndef MYSTRING__H #define MYSTRING__H +#include + namespace netgen { @@ -58,6 +60,7 @@ public: MyStr(const Point3d& p); MyStr(const Vec3d& p); MyStr(const string & st); + MyStr(const filesystem::path & st); ~MyStr(); MyStr Left(unsigned); diff --git a/libsrc/geom2d/geom2dpkg.cpp b/libsrc/geom2d/geom2dpkg.cpp index 735e15e9..87392192 100644 --- a/libsrc/geom2d/geom2dpkg.cpp +++ b/libsrc/geom2d/geom2dpkg.cpp @@ -21,7 +21,7 @@ namespace netgen class SplineGeometryVisRegister : public GeometryRegister { public: - virtual NetgenGeometry * Load (string filename) const { return NULL; } + virtual NetgenGeometry * Load (const filesystem::path & filename) const { return NULL; } virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const; }; diff --git a/libsrc/geom2d/geometry2d.cpp b/libsrc/geom2d/geometry2d.cpp index ad7143b8..f3332258 100644 --- a/libsrc/geom2d/geometry2d.cpp +++ b/libsrc/geom2d/geometry2d.cpp @@ -92,7 +92,7 @@ namespace netgen return Vec<3> (0,0,1); } - void SplineGeometry2d :: Load (const char * filename) + void SplineGeometry2d :: Load (const filesystem::path & filename) { ifstream infile; @@ -104,7 +104,7 @@ namespace netgen if ( ! infile.good() ) throw NgException(string ("Input file '") + - string (filename) + + filename.string() + string ("' not available!")); TestComment ( infile ); @@ -1075,21 +1075,20 @@ namespace netgen class SplineGeometryRegister : public GeometryRegister { public: - virtual NetgenGeometry * Load (string filename) const; + virtual NetgenGeometry * Load (const filesystem::path & filename) const; }; - NetgenGeometry * SplineGeometryRegister :: Load (string filename) const + NetgenGeometry * SplineGeometryRegister :: Load (const filesystem::path & filename) const { - const char * cfilename = filename.c_str(); - if (strcmp (&cfilename[strlen(cfilename)-4], "in2d") == 0) + string ext = ToLower(filename.extension()); + if (ext == ".in2d") { - PrintMessage (1, "Load 2D-Spline geometry file ", cfilename); - + PrintMessage (1, "Load 2D-Spline geometry file ", filename); - ifstream infile(cfilename); + ifstream infile(filename); SplineGeometry2d * hgeom = new SplineGeometry2d(); - hgeom -> Load (cfilename); + hgeom -> Load (filename); return hgeom; } diff --git a/libsrc/geom2d/geometry2d.hpp b/libsrc/geom2d/geometry2d.hpp index 08c3fc9d..a399d103 100644 --- a/libsrc/geom2d/geometry2d.hpp +++ b/libsrc/geom2d/geometry2d.hpp @@ -143,7 +143,7 @@ namespace netgen public: DLL_HEADER virtual ~SplineGeometry2d(); - DLL_HEADER void Load (const char * filename); + DLL_HEADER void Load (const filesystem::path & filename); DLL_HEADER void LoadData( ifstream & infile ); DLL_HEADER void LoadDataNew ( ifstream & infile ); diff --git a/libsrc/interface/read_fnf_mesh.cpp b/libsrc/interface/read_fnf_mesh.cpp index 83d583bf..39ad99ea 100644 --- a/libsrc/interface/read_fnf_mesh.cpp +++ b/libsrc/interface/read_fnf_mesh.cpp @@ -60,9 +60,9 @@ namespace netgen void ReadFNFFormat (Mesh & mesh, - const string & filename) + const filesystem::path & filename) { - ifstream fin (filename.c_str()); + ifstream fin (filename); string buf; diff --git a/libsrc/interface/readtetmesh.cpp b/libsrc/interface/readtetmesh.cpp index 46607c59..1ffcce69 100644 --- a/libsrc/interface/readtetmesh.cpp +++ b/libsrc/interface/readtetmesh.cpp @@ -20,10 +20,8 @@ namespace netgen void ReadTETFormat (Mesh & mesh, - const string & hfilename) + const filesystem::path & filename) { - const char * filename = hfilename.c_str(); - cout << "Reading .tet mesh" << endl; ifstream in (filename); diff --git a/libsrc/interface/readuser.cpp b/libsrc/interface/readuser.cpp index f211f38e..763aad4b 100644 --- a/libsrc/interface/readuser.cpp +++ b/libsrc/interface/readuser.cpp @@ -15,22 +15,18 @@ namespace netgen { void ReadFile (Mesh & mesh, - const string & hfilename) + const filesystem::path & filename) { PrintMessage(3, "Read User File"); - const char * filename = hfilename.c_str(); + auto ext = filename.extension(); char reco[100]; int np, nbe; - // ".surf" - mesh - - if ( (strlen (filename) > 5) && - strcmp (&filename[strlen (filename)-5], ".surf") == 0 ) - + if ( ext == ".surf" ) { cout << "Surface file" << endl; @@ -80,11 +76,7 @@ namespace netgen } - - - - if ( (strlen (filename) > 4) && - strcmp (&filename[strlen (filename)-4], ".unv") == 0 ) + if ( ext == ".unv" ) { char reco[100]; // int invert; @@ -407,8 +399,7 @@ namespace netgen // fepp format2d: - if ( (strlen (filename) > 7) && - strcmp (&filename[strlen (filename)-7], ".mesh2d") == 0 ) + if ( ext == ".mesh2d" ) { cout << "Reading FEPP2D Mesh" << endl; @@ -449,8 +440,7 @@ namespace netgen } - else if ( (strlen (filename) > 5) && - strcmp (&filename[strlen (filename)-5], ".mesh") == 0 ) + else if ( ext == ".mesh" ) { cout << "Reading Neutral Format" << endl; @@ -522,21 +512,17 @@ namespace netgen } - if ( (strlen (filename) > 4) && - strcmp (&filename[strlen (filename)-4], ".emt") == 0 ) + if ( ext == ".emt" ) { ifstream inemt (filename); - string pktfile = filename; - int len = strlen (filename); - pktfile[len-3] = 'p'; - pktfile[len-2] = 'k'; - pktfile[len-1] = 't'; + auto pktfile = filename; + pktfile.replace_extension("pkt"); cout << "pktfile = " << pktfile << endl; int np, nse, i; int bcprop; - ifstream inpkt (pktfile.c_str()); + ifstream inpkt (pktfile); inpkt >> np; NgArray values(np); for (i = 1; i <= np; i++) @@ -629,31 +615,20 @@ namespace netgen // .tet mesh - if ( (strlen (filename) > 4) && - strcmp (&filename[strlen (filename)-4], ".tet") == 0 ) - { + if ( ext == ".tet" ) ReadTETFormat (mesh, filename); - } - // .fnf mesh (FNF - PE neutral format) - if ( (strlen (filename) > 4) && - strcmp (&filename[strlen (filename)-4], ".fnf") == 0 ) - { + if ( ext == ".fnf" ) ReadFNFFormat (mesh, filename); - } // .cgns file - CFD General Notation System - if ( (strlen (filename) > 5) && - strcmp (&filename[strlen (filename)-5], ".cgns") == 0 ) - { + if ( ext == ".cgns" ) ReadCGNSMesh (mesh, filename); - } - if ( ( (strlen (filename) > 4) && strcmp (&filename[strlen (filename)-4], ".stl") == 0 ) || - ( (strlen (filename) > 5) && strcmp (&filename[strlen (filename)-5], ".stlb") == 0 ) ) + if ( ext == ".stl" || ext == ".stlb" ) { - ifstream ist{string{filename}}; + ifstream ist{filename}; auto geom = shared_ptr(STLGeometry::Load(ist)); mesh.SetDimension (3); diff --git a/libsrc/interface/rw_cgns.cpp b/libsrc/interface/rw_cgns.cpp index 32f1aaf4..ad0869a7 100644 --- a/libsrc/interface/rw_cgns.cpp +++ b/libsrc/interface/rw_cgns.cpp @@ -629,12 +629,12 @@ namespace netgen::cg namespace netgen { - int ReadCGNSMesh (Mesh & mesh, const string & filename, Array> & zones) + int ReadCGNSMesh (Mesh & mesh, const filesystem::path & filename, Array> & zones) { mesh.SetDimension(3); static Timer tall("CGNS::ReadMesh"); RegionTimer rtall(tall); int fn; - cg_open(filename.c_str(),CG_MODE_READ,&fn); + cg_open(filename.string().c_str(),CG_MODE_READ,&fn); int base = 1; int nzones; @@ -698,7 +698,7 @@ namespace netgen return fn; } - void ReadCGNSMesh (Mesh & mesh, const string & filename) + void ReadCGNSMesh (Mesh & mesh, const filesystem::path & filename) { Array> zones; int fn = ReadCGNSMesh(mesh, filename, zones); @@ -706,7 +706,7 @@ namespace netgen } // Reads mesh and solutions of .csns file - tuple, vector, vector>, vector> ReadCGNSFile(string filename, int base) + tuple, vector, vector>, vector> ReadCGNSFile(const filesystem::path & filename, int base) { static Timer tall("CGNS::ReadFile"); RegionTimer rtall(tall); @@ -775,11 +775,11 @@ namespace netgen } - void WriteCGNSMesh (const Mesh & mesh, const string & filename) + void WriteCGNSMesh (const Mesh & mesh, const filesystem::path & filename) { static Timer tall("CGNS::WriteMesh"); RegionTimer rtall(tall); int fn, base, zone; - cg_open(filename.c_str(),CG_MODE_WRITE,&fn); + cg_open(filename.string().c_str(),CG_MODE_WRITE,&fn); WriteCGNSMesh(mesh, fn, base, zone); @@ -787,11 +787,11 @@ namespace netgen } - void WriteCGNSFile(shared_ptr mesh, string filename, vector fields, vector> values, vector locations) + void WriteCGNSFile(shared_ptr mesh, const filesystem::path & filename, vector fields, vector> values, vector locations) { static Timer tall("CGNS::WriteFile"); RegionTimer rtall(tall); int fn, base, zone; - cg_open(filename.c_str(),CG_MODE_WRITE,&fn); + cg_open(filename.string().c_str(),CG_MODE_WRITE,&fn); WriteCGNSMesh(*mesh, fn, base, zone); @@ -814,22 +814,22 @@ namespace netgen namespace netgen { - void ReadCGNSMesh (Mesh & mesh, const string & filename) + void ReadCGNSMesh (Mesh & mesh, const filesystem::path & filename) { PrintMessage(1, "Could not import CGNS mesh: Netgen was built without CGNS support"); } - tuple, vector, vector>, vector> ReadCGNSFile(string filename, int base) + tuple, vector, vector>, vector> ReadCGNSFile(const filesystem::path & filename, int base) { throw Exception("Netgen was built without CGNS support"); } - void WriteCGNSMesh (const Mesh & mesh, const string & filename) + void WriteCGNSMesh (const Mesh & mesh, const filesystem::path & filename) { PrintMessage(1, "Could not write CGNS mesh: Netgen was built without CGNS support"); } - void WriteCGNSFile(shared_ptr mesh, string filename, vector fields, vector> values, vector locations) + void WriteCGNSFile(shared_ptr mesh, const filesystem::path & filename, vector fields, vector> values, vector locations) { throw Exception("Netgen was built without CGNS support"); } diff --git a/libsrc/interface/writeOpenFOAM15x.cpp b/libsrc/interface/writeOpenFOAM15x.cpp index db7f99c7..8b185d75 100644 --- a/libsrc/interface/writeOpenFOAM15x.cpp +++ b/libsrc/interface/writeOpenFOAM15x.cpp @@ -597,7 +597,7 @@ namespace netgen - void WriteOpenFOAM15xFormat (const Mesh & mesh, const string & casename, const bool compressed) + void WriteOpenFOAM15xFormat (const Mesh & mesh, const filesystem::path & dirname, const bool compressed) { bool error = false; char casefiles[256]; @@ -639,22 +639,12 @@ namespace netgen } - cout << "Writing OpenFOAM 1.5+ Mesh files to case: " << casename << "\n"; + cout << "Writing OpenFOAM 1.5+ Mesh files to case: " << dirname.string() << "\n"; // Create the case directory if it does not already exist // NOTE: This needs to be improved for the Linux variant....!!! - #ifdef WIN32 - char casedir[256]; - sprintf(casedir, "mkdir %s\\constant\\polyMesh", casename.c_str()); - system(casedir); - #else - char casedir[256]; - mkdir(casename.c_str(), S_IRWXU|S_IRWXG); - sprintf(casedir, "%s/constant", casename.c_str()); - mkdir(casedir, S_IRWXU|S_IRWXG); - sprintf(casedir, "%s/constant/polyMesh", casename.c_str()); - mkdir(casedir, S_IRWXU|S_IRWXG); - #endif + auto mesh_dir = filesystem::path(dirname).append("constant").append("polyMesh"); + filesystem::create_directories(mesh_dir); // Open handles to the five required mesh files // points @@ -662,59 +652,21 @@ namespace netgen // owner // neighbour // boundary - ostream *outfile_pnts; - ostream *outfile_faces; - ostream *outfile_own; - ostream *outfile_nei; - ostream *outfile_bnd; - if(compressed) - { - sprintf(casefiles, "%s/constant/polyMesh/points.gz", casename.c_str()); - outfile_pnts = new ogzstream(casefiles); - } - else - { - sprintf(casefiles, "%s/constant/polyMesh/points", casename.c_str()); - outfile_pnts = new ofstream(casefiles); - } + auto get_name = [compressed, &mesh_dir]( string s ) { + auto p = filesystem::path(mesh_dir).append(s); + if(compressed) + p.concat(".gz"); + return p; + }; - if(compressed) - { - sprintf(casefiles, "%s/constant/polyMesh/faces.gz", casename.c_str()); - outfile_faces = new ogzstream(casefiles); - } - else - { - sprintf(casefiles, "%s/constant/polyMesh/faces", casename.c_str()); - outfile_faces = new ofstream(casefiles); - } + auto outfile_pnts = make_unique(get_name("points")); + auto outfile_faces = make_unique(get_name("faces")); + auto outfile_own = make_unique(get_name("owner")); + auto outfile_nei = make_unique(get_name("neighbor")); - if(compressed) - { - sprintf(casefiles, "%s/constant/polyMesh/owner.gz", casename.c_str()); - outfile_own = new ogzstream(casefiles); - } - else - { - sprintf(casefiles, "%s/constant/polyMesh/owner", casename.c_str()); - outfile_own = new ofstream(casefiles); - } - - if(compressed) - { - sprintf(casefiles, "%s/constant/polyMesh/neighbour.gz", casename.c_str()); - outfile_nei = new ogzstream(casefiles); - } - else - { - sprintf(casefiles, "%s/constant/polyMesh/neighbour", casename.c_str()); - outfile_nei = new ofstream(casefiles); - } - - // Note... the boundary file is not compressed - sprintf(casefiles, "%s/constant/polyMesh/boundary", casename.c_str()); - outfile_bnd = new ofstream(casefiles); + // Note... the boundary file is not compressed + auto outfile_bnd = make_unique(mesh_dir.append("boundary")); ResetTime(); @@ -731,8 +683,7 @@ namespace netgen if(outfile_own->good() && !error) { cout << "Writing the owner file: "; - WriteOwnerFile(outfile_own); - delete outfile_own; + WriteOwnerFile(outfile_own.get()); cout << "Done! (Time Elapsed = " << GetTime() << " sec)\n"; } else @@ -746,8 +697,7 @@ namespace netgen if(outfile_nei->good() && !error) { cout << "Writing the neighbour file: "; - WriteNeighbourFile(outfile_nei); - delete outfile_nei; + WriteNeighbourFile(outfile_nei.get()); cout << "Done! (Time Elapsed = " << GetTime() << " sec)\n"; } else @@ -761,8 +711,7 @@ namespace netgen if(outfile_faces->good() && !error) { cout << "Writing the faces file: "; - WriteFacesFile(outfile_faces, mesh); - delete outfile_faces; + WriteFacesFile(outfile_faces.get(), mesh); cout << "Done! (Time Elapsed = " << GetTime() << " sec)\n"; } else @@ -776,8 +725,7 @@ namespace netgen if(outfile_pnts->good() && !error) { cout << "Writing the points file: "; - WritePointsFile(outfile_pnts,mesh); - delete outfile_pnts; + WritePointsFile(outfile_pnts.get(),mesh); cout << "Done! (Time Elapsed = " << GetTime() << " sec)\n"; } else @@ -791,8 +739,7 @@ namespace netgen if(outfile_bnd->good() && !error) { cout << "Writing the boundary file: "; - WriteBoundaryFile(outfile_bnd); - delete outfile_bnd; + WriteBoundaryFile(outfile_bnd.get()); cout << "Done! (Time Elapsed = " << GetTime() << " sec)\n"; } else diff --git a/libsrc/interface/writeabaqus.cpp b/libsrc/interface/writeabaqus.cpp index 209ac89a..8d698b0b 100644 --- a/libsrc/interface/writeabaqus.cpp +++ b/libsrc/interface/writeabaqus.cpp @@ -18,13 +18,13 @@ namespace netgen void WriteAbaqusFormat (const Mesh & mesh, - const string & filename) + const filesystem::path & filename) { cout << "\nWrite Abaqus Volume Mesh" << endl; - ofstream outfile (filename.c_str()); + ofstream outfile (filename); outfile << "*Heading" << endl; outfile << " " << filename << endl; @@ -124,16 +124,11 @@ void WriteAbaqusFormat (const Mesh & mesh, // periodic identification, implementation for // Helmut J. Boehm, TU Vienna - char cfilename[255]; - strcpy (cfilename, filename.c_str()); - - char mpcfilename[255]; - strcpy (mpcfilename, cfilename); - size_t len = strlen (cfilename); - if (len >= 4 && (strcmp (mpcfilename+len-4, ".inp") == 0)) - strcpy (mpcfilename+len-4, ".mpc"); + auto mpcfilename = filename; + if (filename.extension() == ".inp") + mpcfilename.replace_extension(".mpc"); else - strcat (mpcfilename, ".mpc"); + mpcfilename.concat(".mpc"); ofstream mpc (mpcfilename); diff --git a/libsrc/interface/writediffpack.cpp b/libsrc/interface/writediffpack.cpp index 6e25793d..1c6ba159 100644 --- a/libsrc/interface/writediffpack.cpp +++ b/libsrc/interface/writediffpack.cpp @@ -21,12 +21,12 @@ namespace netgen void WriteDiffPackFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename) + const filesystem::path & filename) { // double scale = globflags.GetNumFlag ("scale", 1); double scale = 1; - ofstream outfile(filename.c_str()); + ofstream outfile(filename); outfile.precision(14); diff --git a/libsrc/interface/writedolfin.cpp b/libsrc/interface/writedolfin.cpp index 8fd9e749..01b4e91c 100644 --- a/libsrc/interface/writedolfin.cpp +++ b/libsrc/interface/writedolfin.cpp @@ -19,7 +19,7 @@ namespace netgen - void WriteDolfinFormat (const Mesh & mesh, const string & filename) + void WriteDolfinFormat (const Mesh & mesh, const filesystem::path & filename) { cout << "start writing dolfin export" << endl; @@ -30,7 +30,7 @@ namespace netgen // int invertsurf = mparam.inverttrigs; // int i, j; - ofstream outfile (filename.c_str()); + ofstream outfile (filename); // char str[100]; outfile.precision(8); diff --git a/libsrc/interface/writeelmer.cpp b/libsrc/interface/writeelmer.cpp index d0dc2a7d..ebaa97f7 100644 --- a/libsrc/interface/writeelmer.cpp +++ b/libsrc/interface/writeelmer.cpp @@ -21,7 +21,7 @@ namespace netgen void WriteElmerFormat (const Mesh &mesh, - const string &filename) + const filesystem::path &dirname) { cout << "write elmer mesh files" << endl; @@ -62,25 +62,17 @@ void WriteElmerFormat (const Mesh &mesh, int inverttets = mparam.inverttets; int invertsurf = mparam.inverttrigs; -#ifdef WIN32 - char a[256]; - sprintf( a, "mkdir %s", filename.c_str() ); - system( a ); -#else - // int rc = - mkdir(filename.c_str(), S_IRWXU|S_IRWXG); -#endif + filesystem::create_directories(dirname); - sprintf( str, "%s/mesh.header", filename.c_str() ); - ofstream outfile_h(str); - sprintf( str, "%s/mesh.nodes", filename.c_str() ); - ofstream outfile_n(str); - sprintf( str, "%s/mesh.elements", filename.c_str() ); - ofstream outfile_e(str); - sprintf( str, "%s/mesh.boundary", filename.c_str() ); - ofstream outfile_b(str); - sprintf( str, "%s/mesh.names", filename.c_str() ); - ofstream outfile_names(str); + auto get_name = [&dirname]( string s ) { + return filesystem::path(dirname).append(s); + }; + + ofstream outfile_h(get_name("mesh.header")); + ofstream outfile_n(get_name("mesh.nodes")); + ofstream outfile_e(get_name("mesh.elements")); + ofstream outfile_b(get_name("mesh.boundary")); + ofstream outfile_names(get_name("mesh.names")); for( auto codim : IntRange(0, mesh.GetDimension()-1) ) { diff --git a/libsrc/interface/writefeap.cpp b/libsrc/interface/writefeap.cpp index 84f71eef..0b5aad61 100644 --- a/libsrc/interface/writefeap.cpp +++ b/libsrc/interface/writefeap.cpp @@ -22,7 +22,7 @@ namespace netgen void WriteFEAPFormat (const Mesh & mesh, - const string & filename) + const filesystem::path & filename) { // Feap format by A. Rieger @@ -35,7 +35,7 @@ void WriteFEAPFormat (const Mesh & mesh, double scale = 1; // globflags.GetNumFlag ("scale", 1); - ofstream outfile(filename.c_str()); + ofstream outfile(filename); outfile << "feap" << "\n"; outfile << mesh.GetNP(); diff --git a/libsrc/interface/writefluent.cpp b/libsrc/interface/writefluent.cpp index 1fb07cdb..2029193d 100644 --- a/libsrc/interface/writefluent.cpp +++ b/libsrc/interface/writefluent.cpp @@ -18,7 +18,7 @@ namespace netgen void WriteFluentFormat (const Mesh & mesh, - const string & filename) + const filesystem::path & filename) { cout << "start writing fluent export" << endl; @@ -28,7 +28,7 @@ void WriteFluentFormat (const Mesh & mesh, int nse = mesh.GetNSE(); int i, j; - ofstream outfile (filename.c_str()); + ofstream outfile (filename); char str[100]; outfile.precision(6); diff --git a/libsrc/interface/writegmsh.cpp b/libsrc/interface/writegmsh.cpp index c4adfbd6..1048f582 100644 --- a/libsrc/interface/writegmsh.cpp +++ b/libsrc/interface/writegmsh.cpp @@ -32,9 +32,9 @@ namespace netgen void WriteGmshFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename) + const filesystem::path & filename) { - ofstream outfile (filename.c_str()); + ofstream outfile (filename); outfile.precision(6); outfile.setf (ios::fixed, ios::floatfield); outfile.setf (ios::showpoint); diff --git a/libsrc/interface/writegmsh2.cpp b/libsrc/interface/writegmsh2.cpp index e0c84f8d..c80208c4 100644 --- a/libsrc/interface/writegmsh2.cpp +++ b/libsrc/interface/writegmsh2.cpp @@ -49,9 +49,9 @@ namespace netgen */ void WriteGmsh2Format (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename) + const filesystem::path & filename) { - ofstream outfile (filename.c_str()); + ofstream outfile (filename); outfile.precision(6); outfile.setf (ios::fixed, ios::floatfield); outfile.setf (ios::showpoint); diff --git a/libsrc/interface/writejcm.cpp b/libsrc/interface/writejcm.cpp index f418cd64..7732b413 100644 --- a/libsrc/interface/writejcm.cpp +++ b/libsrc/interface/writejcm.cpp @@ -17,7 +17,7 @@ namespace netgen void WriteJCMFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename) + const filesystem::path & filename) { if (mesh.GetDimension() != 3) { @@ -122,7 +122,7 @@ void WriteJCMFormat (const Mesh & mesh, nbquad++; } - ofstream outfile (filename.c_str()); + ofstream outfile (filename); outfile.precision(6); outfile.setf (ios::fixed, ios::floatfield); outfile.setf (ios::showpoint); diff --git a/libsrc/interface/writepermas.cpp b/libsrc/interface/writepermas.cpp index 7d2013e1..9e01e76c 100644 --- a/libsrc/interface/writepermas.cpp +++ b/libsrc/interface/writepermas.cpp @@ -22,18 +22,18 @@ namespace netgen // This should be the new function to export a PERMAS file - void WritePermasFormat (const Mesh &mesh, const string &filename, + void WritePermasFormat (const Mesh &mesh, const filesystem::path &filename, string &strComp, string &strSitu) { - ofstream outfile (filename.c_str()); + ofstream outfile (filename); addComponent(strComp, strSitu, outfile); WritePermasFormat ( mesh, filename); } - void WritePermasFormat (const Mesh &mesh, const string &filename) + void WritePermasFormat (const Mesh &mesh, const filesystem::path &filename) { string strComp, strSitu; - ofstream outfile (filename.c_str()); + ofstream outfile (filename); outfile.precision(8); diff --git a/libsrc/interface/writetecplot.cpp b/libsrc/interface/writetecplot.cpp index 323f8c46..2c130efb 100644 --- a/libsrc/interface/writetecplot.cpp +++ b/libsrc/interface/writetecplot.cpp @@ -28,7 +28,7 @@ void WriteTecPlotFormat (const Mesh & mesh, INDEX nse = mesh.GetNSE(); NgArray sn(np); - ofstream outfile(filename.c_str()); + ofstream outfile(filename); outfile << "TITLE=\" " << filename << "\"" << endl; diff --git a/libsrc/interface/writetet.cpp b/libsrc/interface/writetet.cpp index 2dbfa440..8e952ae9 100644 --- a/libsrc/interface/writetet.cpp +++ b/libsrc/interface/writetet.cpp @@ -272,7 +272,7 @@ namespace netgen - ofstream outfile(filename.c_str()); + ofstream outfile(filename); outfile.precision(16); diff --git a/libsrc/interface/writetochnog.cpp b/libsrc/interface/writetochnog.cpp index c9ec6e3c..3068a385 100644 --- a/libsrc/interface/writetochnog.cpp +++ b/libsrc/interface/writetochnog.cpp @@ -20,11 +20,11 @@ namespace netgen void WriteTochnogFormat (const Mesh & mesh, - const string & filename) + const filesystem::path & filename) { cout << "\nWrite Tochnog Volume Mesh" << endl; - ofstream outfile (filename.c_str()); + ofstream outfile (filename); outfile << "(Nodes and Elements generated with NETGEN" << endl; outfile << " " << filename << ")" << endl; diff --git a/libsrc/interface/writeuser.cpp b/libsrc/interface/writeuser.cpp index 4a50f825..43a89057 100644 --- a/libsrc/interface/writeuser.cpp +++ b/libsrc/interface/writeuser.cpp @@ -58,9 +58,9 @@ namespace netgen -bool WriteUserFormat (const string & format, +bool WriteUserFormat (const filesystem::path & format, const Mesh & mesh, - const string & filename) + const filesystem::path & filename) { // cout << "write user &hgeom = " << &hgeom << endl; // const CSGeometry & geom = *dynamic_cast (&hgeom); @@ -167,7 +167,7 @@ bool WriteUserFormat (const string & format, void WriteNeutralFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename) + const filesystem::path & filename) { cout << "write neutral, new" << endl; int np = mesh.GetNP(); @@ -179,7 +179,7 @@ void WriteNeutralFormat (const Mesh & mesh, int inverttets = mparam.inverttets; int invertsurf = mparam.inverttrigs; - ofstream outfile (filename.c_str()); + ofstream outfile (filename); outfile.precision(6); outfile.setf (ios::fixed, ios::floatfield); @@ -283,14 +283,14 @@ void WriteNeutralFormat (const Mesh & mesh, void WriteSurfaceFormat (const Mesh & mesh, - const string & filename) + const filesystem::path & filename) { // surface mesh int i, j; cout << "Write Surface Mesh" << endl; - ofstream outfile (filename.c_str()); + ofstream outfile (filename); outfile << "surfacemesh" << endl; @@ -325,16 +325,17 @@ void WriteSurfaceFormat (const Mesh & mesh, */ void WriteSTLFormat (const Mesh & mesh, - const string & filename) + const filesystem::path & filename) { cout << "\nWrite STL Surface Mesh" << endl; + auto ext = filename.extension(); ostream *outfile; - if(filename.substr(filename.length()-3,3) == ".gz") - outfile = new ogzstream(filename.c_str()); + if(ext == ".gz") + outfile = new ogzstream(filename); else - outfile = new ofstream(filename.c_str()); + outfile = new ofstream(filename); int i; @@ -382,16 +383,17 @@ void WriteSTLFormat (const Mesh & mesh, * when using a third-party mesher */ void WriteSTLExtFormat (const Mesh & mesh, - const string & filename) + const filesystem::path & filename) { cout << "\nWrite STL Surface Mesh (with separated boundary faces)" << endl; + auto ext = filename.extension(); ostream *outfile; - if(filename.substr(filename.length()-3,3) == ".gz") - outfile = new ogzstream(filename.c_str()); + if(ext == ".gz") + outfile = new ogzstream(filename); else - outfile = new ofstream(filename.c_str()); + outfile = new ofstream(filename); outfile->precision(10); @@ -474,7 +476,7 @@ void WriteSTLExtFormat (const Mesh & mesh, void WriteVRMLFormat (const Mesh & mesh, bool faces, - const string & filename) + const filesystem::path & filename) { if (faces) @@ -487,7 +489,7 @@ void WriteVRMLFormat (const Mesh & mesh, int nse = mesh.GetNSE(); int i, j; - ofstream outfile (filename.c_str()); + ofstream outfile (filename); outfile.precision(6); outfile.setf (ios::fixed, ios::floatfield); @@ -563,7 +565,7 @@ void WriteVRMLFormat (const Mesh & mesh, int nse = mesh.GetNSE(); int i, j; - ofstream outfile (filename.c_str()); + ofstream outfile (filename); outfile.precision(6); outfile.setf (ios::fixed, ios::floatfield); @@ -639,10 +641,10 @@ void WriteVRMLFormat (const Mesh & mesh, */ void WriteFEPPFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename) + const filesystem::path & filename) { - ofstream outfile (filename.c_str()); + ofstream outfile (filename); if (mesh.GetDimension() == 3) @@ -770,7 +772,7 @@ void WriteFEPPFormat (const Mesh & mesh, void WriteEdgeElementFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename) + const filesystem::path & filename) { cout << "write edge element format" << endl; @@ -785,7 +787,7 @@ void WriteEdgeElementFormat (const Mesh & mesh, int invertsurf = mparam.inverttrigs; NgArray edges; - ofstream outfile (filename.c_str()); + ofstream outfile (filename); outfile.precision(6); outfile.setf (ios::fixed, ios::floatfield); @@ -908,8 +910,8 @@ void WriteEdgeElementFormat (const Mesh & mesh, void WriteFile (int typ, const Mesh & mesh, const CSGeometry & geom, - const char * filename, - const char * geomfile, + const filesystem::path & filename, + const filesystem::path & geomfile, double h) { diff --git a/libsrc/interface/writeuser.hpp b/libsrc/interface/writeuser.hpp index b40b8706..2c604e9d 100644 --- a/libsrc/interface/writeuser.hpp +++ b/libsrc/interface/writeuser.hpp @@ -13,15 +13,15 @@ DLL_HEADER extern void WriteFile (int typ, const Mesh & mesh, const NetgenGeometry & geom, - const char * filename, - const char * geomfile = NULL, + const filesystem::path & filename, + const filesystem::path & geomfile = "", double h = 0); DLL_HEADER extern void ReadFile (Mesh & mesh, - const string & filename); + const filesystem::path & filename); @@ -31,15 +31,15 @@ void ReadFile (Mesh & mesh, extern void WriteNeutralFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename); + const filesystem::path & filename); extern void WriteSurfaceFormat (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void WriteSTLFormat (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); // Philippose - 16 August 2010 @@ -48,134 +48,134 @@ void WriteSTLFormat (const Mesh & mesh, // a separate "solid" entity in the STL file extern void WriteSTLExtFormat (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void WriteVRMLFormat (const Mesh & mesh, bool faces, - const string & filename); + const filesystem::path & filename); extern void WriteFEPPFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename); + const filesystem::path & filename); extern void WriteGmshFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename); + const filesystem::path & filename); // Philippose - 29/01/2009 // Added GMSH v2.xx Mesh Export support void WriteGmsh2Format (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename); + const filesystem::path & filename); // Philippose - 25/10/2009 // Added OpenFOAM 1.5+ Mesh Export support extern void WriteOpenFOAM15xFormat (const Mesh & mesh, - const string & casename, + const filesystem::path & casename, const bool compressed); extern void WriteUserChemnitz (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void WriteJCMFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename); + const filesystem::path & filename); extern void WriteDiffPackFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename); + const filesystem::path & filename); extern void WriteTochnogFormat (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void WriteTecPlotFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename); + const filesystem::path & filename); extern void WriteAbaqusFormat (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void WriteFluentFormat (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void WritePermasFormat (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void WriteFEAPFormat (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void WriteElmerFormat (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void WriteEdgeElementFormat (const Mesh & mesh, const NetgenGeometry & geom, - const string & filename); + const filesystem::path & filename); #ifdef OLIVER extern void WriteTETFormat (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); #endif extern void ReadTETFormat (Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void ReadFNFFormat (Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void DLL_HEADER ReadCGNSMesh (Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void DLL_HEADER WriteCGNSMesh (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); // read/write mesh and solutions from CGNS file extern tuple, vector, vector>, vector> -DLL_HEADER ReadCGNSFile(string filename, int base); +DLL_HEADER ReadCGNSFile(const filesystem::path & filename, int base); -extern void DLL_HEADER WriteCGNSFile(shared_ptr mesh,string filename, vector fields, +extern void DLL_HEADER WriteCGNSFile(shared_ptr mesh, const filesystem::path & filename, vector fields, vector> values, vector locations); void WriteDolfinFormat (const Mesh & mesh, - const string & filename); + const filesystem::path & filename); extern void DLL_HEADER RegisterUserFormats (NgArray & names, NgArray & extensions); -extern bool DLL_HEADER WriteUserFormat (const string & format, +extern bool DLL_HEADER WriteUserFormat (const filesystem::path & format, const Mesh & mesh, // const NetgenGeometry & geom, - const string & filename); + const filesystem::path & filename); } diff --git a/libsrc/interface/wuchemnitz.cpp b/libsrc/interface/wuchemnitz.cpp index 872dcc76..6798993f 100644 --- a/libsrc/interface/wuchemnitz.cpp +++ b/libsrc/interface/wuchemnitz.cpp @@ -306,9 +306,9 @@ namespace netgen void WriteUserChemnitz (const Mesh & mesh, - const string & filename) + const filesystem::path & filename) { - ofstream outfile (filename.c_str()); + ofstream outfile (filename); ReadFileMesh (mesh); Convert (); diff --git a/libsrc/meshing/basegeom.cpp b/libsrc/meshing/basegeom.cpp index 49731499..ca1b7651 100644 --- a/libsrc/meshing/basegeom.cpp +++ b/libsrc/meshing/basegeom.cpp @@ -1124,7 +1124,7 @@ namespace netgen return 0; } - void NetgenGeometry :: Save (string filename) const + void NetgenGeometry :: Save (const filesystem::path & filename) const { throw NgException("Cannot save geometry - no geometry available"); } diff --git a/libsrc/meshing/basegeom.hpp b/libsrc/meshing/basegeom.hpp index db82c11c..bb411a4d 100644 --- a/libsrc/meshing/basegeom.hpp +++ b/libsrc/meshing/basegeom.hpp @@ -7,7 +7,6 @@ /* Date: 23. Aug. 09 */ /**************************************************************************/ - struct Tcl_Interp; namespace netgen @@ -298,7 +297,7 @@ namespace netgen return i; throw Exception("Couldn't find edge index"); } - virtual void Save (string filename) const; + virtual void Save (const filesystem::path & filename) const; virtual void SaveToMeshFile (ostream & /* ost */) const { ; } }; @@ -310,7 +309,7 @@ namespace netgen { public: virtual ~GeometryRegister(); - virtual NetgenGeometry * Load (string filename) const = 0; + virtual NetgenGeometry * Load (const filesystem::path & filename) const = 0; virtual NetgenGeometry * LoadFromMeshFile (istream & /* ist */, string) const { return NULL; } virtual class VisualScene * GetVisualScene (const NetgenGeometry * /* geom */) const { return NULL; } diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index ed0a11a0..6254d675 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -627,9 +627,12 @@ namespace netgen - void Mesh :: Save (const string & filename) const + void Mesh :: Save (const filesystem::path & filename) const { - if (filename.find(".vol.bin") != string::npos) + string ext0 = filename.stem().extension().string(); + string ext = filename.extension().string(); + + if (ext0 == ".vol" && ext == ".bin") { BinaryOutArchive in(filename); in & const_cast(*this); @@ -637,12 +640,12 @@ namespace netgen } ostream * outfile; - if (filename.find(".vol.gz")!=string::npos) - outfile = new ogzstream(filename.c_str()); - else if (filename.find(".vol")!=string::npos) - outfile = new ofstream(filename.c_str()); + if (ext0 == ".vol" && ext == ".gz") + outfile = new ogzstream(filename); + else if (ext == ".vol") + outfile = new ofstream(filename); else - outfile = new ogzstream((filename+".vol.gz").c_str()); + outfile = new ogzstream(filesystem::path(filename).concat(".vol.gz")); Save(*outfile); delete outfile; @@ -1109,11 +1112,14 @@ namespace netgen - void Mesh :: Load (const string & filename) + void Mesh :: Load (const filesystem::path & filename) { - cout << "filename = " << filename << endl; + PrintMessage (1, "filename = ", filename); - if (filename.find(".vol.bin") != string::npos) + string ext0 = filename.stem().extension().string(); + string ext = filename.extension().string(); + + if (ext0 == ".vol" && ext == ".bin") { BinaryInArchive in(filename); in & (*this); @@ -1122,12 +1128,11 @@ namespace netgen istream * infile = NULL; - if (filename.find(".vol.gz") != string::npos) - infile = new igzstream (filename.c_str()); + if (ext0 == ".vol" && ext == ".gz") + infile = new igzstream (filename); else - infile = new ifstream (filename.c_str()); + infile = new ifstream (filename); - // ifstream infile(filename.c_str()); if (! (infile -> good()) ) throw NgException ("mesh file not found"); @@ -1651,6 +1656,10 @@ namespace netgen clusters -> Update(); } + auto geo = geometryregister.LoadFromMeshFile (infile); + if(geo) + geometry = geo; + SetNextMajorTimeStamp(); // PrintMemInfo (cout); } @@ -1840,9 +1849,9 @@ namespace netgen } - void Mesh :: Merge (const string & filename, const int surfindex_offset) + void Mesh :: Merge (const filesystem::path & filename, const int surfindex_offset) { - ifstream infile(filename.c_str()); + ifstream infile(filename); if (!infile.good()) throw NgException ("mesh file not found"); @@ -3758,7 +3767,7 @@ namespace netgen } - void Mesh :: LoadLocalMeshSize (const string & meshsizefilename) + void Mesh :: LoadLocalMeshSize (const filesystem::path & meshsizefilename) { // Philippose - 10/03/2009 // Improve error checking when loading and reading @@ -3766,7 +3775,7 @@ namespace netgen if (meshsizefilename.empty()) return; - ifstream msf(meshsizefilename.c_str()); + ifstream msf(meshsizefilename); // Philippose - 09/03/2009 // Adding print message information in case the specified diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index f16ba622..9346ffba 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -11,8 +11,12 @@ The mesh class */ +#include + namespace netgen { + using namespace std; + enum resthtype { RESTRICTH_FACE, RESTRICTH_EDGE, RESTRICTH_SURFACEELEMENT, RESTRICTH_POINT, RESTRICTH_SEGMENT }; @@ -446,7 +450,7 @@ namespace netgen /// DLL_HEADER void RestrictLocalH (resthtype rht, int nr, double loch); /// - DLL_HEADER void LoadLocalMeshSize (const string & meshsizefilename); + DLL_HEADER void LoadLocalMeshSize (const filesystem::path & meshsizefilename); /// DLL_HEADER void SetGlobalH (double h); /// @@ -546,11 +550,11 @@ namespace netgen /// DLL_HEADER void Merge (istream & infile, const int surfindex_offset = 0); /// - DLL_HEADER void Save (const string & filename) const; + DLL_HEADER void Save (const filesystem::path & filename) const; /// - DLL_HEADER void Load (const string & filename); + DLL_HEADER void Load (const filesystem::path & filename); /// - DLL_HEADER void Merge (const string & filename, const int surfindex_offset = 0); + DLL_HEADER void Merge (const filesystem::path & filename, const int surfindex_offset = 0); DLL_HEADER void DoArchive (Archive & archive); diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index f335565e..c6bcc168 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -813,8 +813,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) if(geo!=nullptr) mesh->SetGeometry(geo); else if(ng_geometry!=nullptr) mesh->SetGeometry(ng_geometry); }),py::call_guard()) - // static_cast(&Mesh::Load)) - .def("Save", static_cast(&Mesh::Save),py::call_guard()) + .def("Save", static_cast(&Mesh::Save),py::call_guard()) .def("Export", [] (Mesh & self, string filename, string format) { diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index f6d38a2b..7e26cf65 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -68,7 +68,7 @@ namespace netgen { - void LoadOCCInto(OCCGeometry* occgeo, const char* filename); + void LoadOCCInto(OCCGeometry* occgeo, const filesystem::path & filename); void PrintContents (OCCGeometry * geom); std::map OCCGeometry::global_shape_properties; @@ -140,10 +140,10 @@ namespace netgen if(copy) { auto filename = GetTempFilename(); - step_utils::WriteSTEP(_shape, filename.c_str()); - LoadOCCInto(this, filename.c_str()); + step_utils::WriteSTEP(_shape, filename); + LoadOCCInto(this, filename); dimension = aoccdim; - std::remove(filename.c_str()); + filesystem::remove(filename); } else { @@ -1347,7 +1347,7 @@ namespace netgen // } - void LoadOCCInto(OCCGeometry* occgeo, const char* filename) + void LoadOCCInto(OCCGeometry* occgeo, const filesystem::path & filename) { static Timer timer_all("LoadOCC"); RegionTimer rtall(timer_all); static Timer timer_readfile("LoadOCC-ReadFile"); @@ -1375,7 +1375,7 @@ namespace netgen // Enable transfer of colours reader.SetColorMode(Standard_True); reader.SetNameMode(Standard_True); - Standard_Integer stat = reader.ReadFile((char*)filename); + Standard_Integer stat = reader.ReadFile(filename.string().c_str()); timer_readfile.Stop(); timer_transfer.Start(); @@ -1411,7 +1411,7 @@ namespace netgen to extract individual surface colours via the extended OpenCascade XDE and XCAF Feature set. */ - OCCGeometry *LoadOCC_IGES(const char *filename) + OCCGeometry *LoadOCC_IGES(const filesystem::path & filename) { OCCGeometry *occgeo; occgeo = new OCCGeometry; @@ -1432,7 +1432,7 @@ namespace netgen IGESCAFControl_Reader reader; - Standard_Integer stat = reader.ReadFile((char*)filename); + Standard_Integer stat = reader.ReadFile(filename.string().c_str()); if(stat != IFSelect_RetDone) { @@ -1485,7 +1485,7 @@ namespace netgen to extract individual surface colours via the extended OpenCascade XDE and XCAF Feature set. */ - OCCGeometry * LoadOCC_STEP (const char * filename) + OCCGeometry * LoadOCC_STEP (const filesystem::path & filename) { OCCGeometry * occgeo; occgeo = new OCCGeometry; @@ -1497,13 +1497,13 @@ namespace netgen - OCCGeometry *LoadOCC_BREP (const char *filename) + OCCGeometry *LoadOCC_BREP (const filesystem::path & filename) { OCCGeometry * occgeo; occgeo = new OCCGeometry; BRep_Builder aBuilder; - Standard_Boolean result = BRepTools::Read(occgeo->shape, const_cast (filename),aBuilder); + Standard_Boolean result = BRepTools::Read(occgeo->shape, filename.string().c_str(), aBuilder); if(!result) { @@ -1521,34 +1521,36 @@ namespace netgen } - void OCCGeometry :: Save (string sfilename) const + void OCCGeometry :: Save (const filesystem::path & filename) const { - const char * filename = sfilename.c_str(); - if (strlen(filename) < 4) - throw NgException ("illegal filename"); - - if (strcmp (&filename[strlen(filename)-3], "igs") == 0) + string ext = ToLower(filename.extension()); + auto s_filename = filename.string(); + auto c_filename = s_filename.c_str(); + + if (ext == ".igs") { IGESControl_Writer writer("millimeters", 1); writer.AddShape (shape); - writer.Write (filename); + writer.Write (c_filename); } - else if (strcmp (&filename[strlen(filename)-3], "stp") == 0) + else if (ext == ".stp") { step_utils::WriteSTEP(*this, filename); } - else if (strcmp (&filename[strlen(filename)-3], "stl") == 0) + else if (ext == ".stl") { StlAPI_Writer writer; writer.ASCIIMode() = Standard_True; - writer.Write (shape, filename); + writer.Write (shape, c_filename); } - else if (strcmp (&filename[strlen(filename)-4], "stlb") == 0) + else if (ext == ".stlb") { StlAPI_Writer writer; writer.ASCIIMode() = Standard_False; - writer.Write (shape, filename); + writer.Write (shape, c_filename); } + + throw NgException ("Unkown target format: " + filename); } void OCCGeometry :: SaveToMeshFile (ostream & ost) const @@ -2267,7 +2269,7 @@ namespace netgen OCCGeometry::identifications[shape_origin.TShape()] = result; } - void WriteSTEP(const TopoDS_Shape & shape, string filename) + void WriteSTEP(const TopoDS_Shape & shape, const filesystem::path & filename) { Interface_Static::SetCVal("write.step.schema", "AP242IS"); Interface_Static::SetIVal("write.step.assembly",1); @@ -2303,7 +2305,7 @@ namespace netgen for (TopExp_Explorer e(shape, typ); e.More(); e.Next()) WriteProperties(model, finder, e.Current()); - writer.Write(filename.c_str()); + writer.Write(filename.string().c_str()); } } // namespace step_utils diff --git a/libsrc/occ/occgeom.hpp b/libsrc/occ/occgeom.hpp index 52fe6601..c36342aa 100644 --- a/libsrc/occ/occgeom.hpp +++ b/libsrc/occ/occgeom.hpp @@ -196,7 +196,7 @@ namespace netgen int nr, FlatArray glob2loc) const override; // void OptimizeSurface(Mesh& mesh, const MeshingParameters& mparam) const override {} - void Save (string filename) const override; + void Save (const filesystem::path & filename) const override; void SaveToMeshFile (ostream & /* ost */) const override; void DoArchive(Archive& ar) override; @@ -356,9 +356,9 @@ namespace netgen void PrintContents (OCCGeometry * geom); - DLL_HEADER OCCGeometry * LoadOCC_IGES (const char * filename); - DLL_HEADER OCCGeometry * LoadOCC_STEP (const char * filename); - DLL_HEADER OCCGeometry * LoadOCC_BREP (const char * filename); + DLL_HEADER OCCGeometry * LoadOCC_IGES (const filesystem::path & filename); + DLL_HEADER OCCGeometry * LoadOCC_STEP (const filesystem::path & filename); + DLL_HEADER OCCGeometry * LoadOCC_BREP (const filesystem::path & filename); // Philippose - 31.09.2009 // External access to the mesh generation functions within the OCC @@ -535,9 +535,9 @@ namespace netgen const Handle(TDocStd_Document) step_doc); void WriteProperties(const Handle(Interface_InterfaceModel) model, const Handle(Transfer_FinderProcess) finder, const TopoDS_Shape & shape); - void WriteSTEP(const TopoDS_Shape & shape, string filename); + void WriteSTEP(const TopoDS_Shape & shape, const filesystem::path & filename); - inline void WriteSTEP(const OCCGeometry & geo, string filename) + inline void WriteSTEP(const OCCGeometry & geo, const filesystem::path & filename) { WriteSTEP(geo.GetShape(), filename); } diff --git a/libsrc/occ/occpkg.cpp b/libsrc/occ/occpkg.cpp index 8df3a289..80c38e6e 100644 --- a/libsrc/occ/occpkg.cpp +++ b/libsrc/occ/occpkg.cpp @@ -43,7 +43,7 @@ namespace netgen class OCCGeometryRegister : public GeometryRegister { public: - virtual NetgenGeometry * Load (string filename) const; + virtual NetgenGeometry * Load (const filesystem::path & filename) const; virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const; virtual void SetParameters (Tcl_Interp * interp) @@ -893,55 +893,27 @@ namespace netgen - NetgenGeometry * OCCGeometryRegister :: Load (string filename) const + NetgenGeometry * OCCGeometryRegister :: Load (const filesystem::path & filename) const { - const char * lgfilename = filename.c_str(); + string ext = ToLower(filename.extension()); - - /* - if (strcmp (&cfilename[strlen(cfilename)-3], "geo") == 0) + if (ext == ".iges" || ext == ".igs") { - PrintMessage (1, "Load OCCG geometry file ", cfilename); - - extern OCCGeometry * ParseOCCG (istream & istr); - - ifstream infile(cfilename); - - OCCGeometry * hgeom = ParseOCCG (infile); - if (!hgeom) - throw NgException ("geo-file should start with 'algebraic3d'"); - - hgeom -> FindIdenticSurfaces(1e-8 * hgeom->MaxSize()); - return hgeom; - } - */ - - - if ((strcmp (&lgfilename[strlen(lgfilename)-4], "iges") == 0) || - (strcmp (&lgfilename[strlen(lgfilename)-3], "igs") == 0) || - (strcmp (&lgfilename[strlen(lgfilename)-3], "IGS") == 0) || - (strcmp (&lgfilename[strlen(lgfilename)-4], "IGES") == 0)) - { - PrintMessage (1, "Load IGES geometry file ", lgfilename); - OCCGeometry * occgeometry = LoadOCC_IGES (lgfilename); + PrintMessage (1, "Load IGES geometry file ", filename); + OCCGeometry * occgeometry = LoadOCC_IGES (filename); return occgeometry; } - else if ((strcmp (&lgfilename[strlen(lgfilename)-4], "step") == 0) || - (strcmp (&lgfilename[strlen(lgfilename)-3], "stp") == 0) || - (strcmp (&lgfilename[strlen(lgfilename)-3], "STP") == 0) || - (strcmp (&lgfilename[strlen(lgfilename)-4], "STEP") == 0)) + else if (ext == ".stp" || ext == ".step") { - PrintMessage (1, "Load STEP geometry file ", lgfilename); - OCCGeometry * occgeometry = LoadOCC_STEP (lgfilename); + PrintMessage (1, "Load STEP geometry file ", filename); + OCCGeometry * occgeometry = LoadOCC_STEP (filename); return occgeometry; } - else if ((strcmp (&lgfilename[strlen(lgfilename)-4], "brep") == 0) || - (strcmp (&lgfilename[strlen(lgfilename)-4], "Brep") == 0) || - (strcmp (&lgfilename[strlen(lgfilename)-4], "BREP") == 0)) + else if (ext == ".brep") { - PrintMessage (1, "Load BREP geometry file ", lgfilename); - OCCGeometry * occgeometry = LoadOCC_BREP (lgfilename); + PrintMessage (1, "Load BREP geometry file ", filename); + OCCGeometry * occgeometry = LoadOCC_BREP (filename); return occgeometry; } diff --git a/libsrc/occ/python_occ.cpp b/libsrc/occ/python_occ.cpp index bfb39cac..f13deb2e 100644 --- a/libsrc/occ/python_occ.cpp +++ b/libsrc/occ/python_occ.cpp @@ -137,11 +137,11 @@ DLL_HEADER void ExportNgOCC(py::module &m) { shared_ptr geo; if(EndsWith(filename, ".step") || EndsWith(filename, ".stp")) - geo.reset(LoadOCC_STEP(filename.c_str())); + geo.reset(LoadOCC_STEP(filename)); else if(EndsWith(filename, ".brep")) - geo.reset(LoadOCC_BREP(filename.c_str())); + geo.reset(LoadOCC_BREP(filename)); else if(EndsWith(filename, ".iges")) - geo.reset(LoadOCC_IGES(filename.c_str())); + geo.reset(LoadOCC_IGES(filename)); else throw Exception("Cannot load file " + filename + "\nValid formats are: step, stp, brep, iges"); ng_geometry = geo; @@ -279,7 +279,7 @@ DLL_HEADER void ExportNgOCC(py::module &m) - m.def("LoadOCCGeometry",[] (const string & filename) + m.def("LoadOCCGeometry",[] (filesystem::path filename) { cout << "WARNING: LoadOCCGeometry is deprecated! Just use the OCCGeometry(filename) constructor. It is able to read brep and iges files as well!" << endl; ifstream ist(filename); diff --git a/libsrc/stlgeom/stlgeom.cpp b/libsrc/stlgeom/stlgeom.cpp index 69991987..fe5cc4a0 100644 --- a/libsrc/stlgeom/stlgeom.cpp +++ b/libsrc/stlgeom/stlgeom.cpp @@ -68,28 +68,27 @@ STLGeometry :: ~STLGeometry() // delete edgedata; } -void STLGeometry :: Save (string filename) const +void STLGeometry :: Save (const filesystem::path & filename) const { - const char * cfilename = filename.c_str(); - if (strlen(cfilename) < 4) - throw NgException ("illegal filename"); + string ext = ToLower(filename.extension()); - if (strlen(cfilename) > 3 && - strcmp (&cfilename[strlen(cfilename)-3], "stl") == 0) + if (ext == ".stl") { - STLTopology::Save (cfilename); + STLTopology::Save (filename); + return; } - else if (strlen(cfilename) > 4 && - strcmp (&cfilename[strlen(cfilename)-4], "stlb") == 0) + else if (ext == ".stlb") { - SaveBinary (cfilename,"Binary STL Geometry"); - + SaveBinary (filename,"Binary STL Geometry"); + return; } - else if (strlen(cfilename) > 4 && - strcmp (&cfilename[strlen(cfilename)-4], "stle") == 0) + else if (ext == ".stle") { - SaveSTLE (cfilename); + SaveSTLE (filename); + return; } + + throw Exception ("Unknown target format: " + filename.string()); } @@ -1100,22 +1099,22 @@ void STLGeometry :: ExportEdges() } -void STLGeometry :: LoadEdgeData(const char* file) +void STLGeometry :: LoadEdgeData(const filesystem::path & filename) { StoreEdgeData(); - PrintFnStart("Load edges from file '", file, "'"); - ifstream fin(file); + PrintFnStart("Load edges from file '", filename, "'"); + ifstream fin(filename); edgedata->Read(fin); // calcedgedataanglesnew = 1; } -void STLGeometry :: SaveEdgeData(const char* file) +void STLGeometry :: SaveEdgeData(const filesystem::path & filename) { - PrintFnStart("save edges to file '", file, "'"); - ofstream fout(file); + PrintFnStart("save edges to file '", filename, "'"); + ofstream fout(filename); edgedata->Write(fout); } @@ -3627,7 +3626,7 @@ void STLGeometry :: SmoothGeometry () } } -void STLGeometry :: WriteChartToFile( ChartId chartnumber, string filename ) +void STLGeometry :: WriteChartToFile( ChartId chartnumber, filesystem::path filename ) { PrintMessage(1,"write chart ", int(chartnumber), " to ", filename); Array trignums; @@ -3701,38 +3700,38 @@ void STLGeometry :: WriteChartToFile( ChartId chartnumber, string filename ) class STLGeometryRegister : public GeometryRegister { public: - virtual NetgenGeometry * Load (string filename) const; + virtual NetgenGeometry * Load (const filesystem::path & filename) const; }; - NetgenGeometry * STLGeometryRegister :: Load (string filename) const + NetgenGeometry * STLGeometryRegister :: Load (const filesystem::path & filename) const { - const char * cfilename = filename.c_str(); + string ext = ToLower(filename.extension()); - if (strcmp (&cfilename[strlen(cfilename)-3], "stl") == 0) + if (ext == ".stl") { - PrintMessage (1, "Load STL geometry file ", cfilename); + PrintMessage (1, "Load STL geometry file ", filename); - ifstream infile(cfilename); + ifstream infile(filename); STLGeometry * hgeom = STLGeometry :: Load (infile); hgeom -> edgesfound = 0; return hgeom; } - else if (strcmp (&cfilename[strlen(cfilename)-4], "stlb") == 0) + else if (ext == ".stlb") { - PrintMessage (1, "Load STL binary geometry file ", cfilename); + PrintMessage (1, "Load STL binary geometry file ", filename); - ifstream infile(cfilename); + ifstream infile(filename); STLGeometry * hgeom = STLGeometry :: LoadBinary (infile); hgeom -> edgesfound = 0; return hgeom; } - else if (strcmp (&cfilename[strlen(cfilename)-3], "nao") == 0) + else if (ext == ".nao") { - PrintMessage (1, "Load naomi (F. Kickinger) geometry file ", cfilename); + PrintMessage (1, "Load naomi (F. Kickinger) geometry file ", filename); - ifstream infile(cfilename); + ifstream infile(filename); STLGeometry * hgeom = STLGeometry :: LoadNaomi (infile); hgeom -> edgesfound = 0; diff --git a/libsrc/stlgeom/stlgeom.hpp b/libsrc/stlgeom/stlgeom.hpp index 9b57f634..cc15a57a 100644 --- a/libsrc/stlgeom/stlgeom.hpp +++ b/libsrc/stlgeom/stlgeom.hpp @@ -190,7 +190,7 @@ namespace netgen void Clear(); - virtual void Save (string filename) const override; + virtual void Save (const filesystem::path & filename) const override; bool CalcPointGeomInfo(int surfind, PointGeomInfo& gi, const Point<3> & p3) const override; PointGeomInfo ProjectPoint(INDEX surfind, Point<3> & p) const override; @@ -236,8 +236,8 @@ namespace netgen DLL_HEADER void ImportEdges(); DLL_HEADER void AddEdges(const NgArray >& eps); DLL_HEADER void ExportEdges(); - DLL_HEADER void LoadEdgeData(const char* file); - DLL_HEADER void SaveEdgeData(const char* file); + DLL_HEADER void LoadEdgeData(const filesystem::path & file); + DLL_HEADER void SaveEdgeData(const filesystem::path & file); // void SetEdgeAtSelected(int mode); @@ -475,7 +475,7 @@ namespace netgen int GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam) override; // Add additional Point to chart to close the surface and write the resulting stl to a file - DLL_HEADER void WriteChartToFile( ChartId chartnumber, string filename="chart.slb" ); + DLL_HEADER void WriteChartToFile( ChartId chartnumber, filesystem::path filename="chart.slb" ); }; diff --git a/libsrc/stlgeom/stlpkg.cpp b/libsrc/stlgeom/stlpkg.cpp index bf9c80e3..ff0897f0 100644 --- a/libsrc/stlgeom/stlpkg.cpp +++ b/libsrc/stlgeom/stlpkg.cpp @@ -36,7 +36,7 @@ namespace netgen class STLGeometryVisRegister : public GeometryRegister { public: - virtual NetgenGeometry * Load (string filename) const { return NULL; } + virtual NetgenGeometry * Load (const filesystem::path & filename) const { return NULL; } virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const; virtual void SetParameters (Tcl_Interp * interp) { diff --git a/libsrc/stlgeom/stltopology.cpp b/libsrc/stlgeom/stltopology.cpp index b595e0c4..9426f879 100644 --- a/libsrc/stlgeom/stltopology.cpp +++ b/libsrc/stlgeom/stltopology.cpp @@ -90,7 +90,7 @@ STLGeometry * STLTopology :: LoadBinary (istream & ist) } -void STLTopology :: SaveBinary (const char* filename, const char* aname) const +void STLTopology :: SaveBinary (const filesystem::path & filename, const char* aname) const { ofstream ost(filename); PrintFnStart("Write STL binary file '",filename,"'"); @@ -149,7 +149,7 @@ void STLTopology :: SaveBinary (const char* filename, const char* aname) const } -void STLTopology :: SaveSTLE (const char* filename) const +void STLTopology :: SaveSTLE (const filesystem::path & filename) const { ofstream outf (filename); int i, j; @@ -266,7 +266,7 @@ STLGeometry * STLTopology :: LoadNaomi (istream & ist) return geom; } -void STLTopology :: Save (const char* filename) const +void STLTopology :: Save (const filesystem::path & filename) const { PrintFnStart("Write stl-file '",filename, "'"); diff --git a/libsrc/stlgeom/stltopology.hpp b/libsrc/stlgeom/stltopology.hpp index ba6bce7e..5b9ba058 100644 --- a/libsrc/stlgeom/stltopology.hpp +++ b/libsrc/stlgeom/stltopology.hpp @@ -316,9 +316,9 @@ public: static STLGeometry * Load (istream & ist); static STLGeometry * LoadBinary (istream & ist); - void Save (const char* filename) const; - void SaveBinary (const char* filename, const char* aname) const; - void SaveSTLE (const char * filename) const; // stores trigs and edges + void Save (const filesystem::path & filename) const; + void SaveBinary (const filesystem::path & filename, const char* aname) const; + void SaveSTLE (const filesystem::path & filename) const; // stores trigs and edges virtual void DoArchive(Archive& ar) { diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index ab950d79..1384acc7 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -205,9 +205,9 @@ namespace netgen Tcl_Interp * interp, int argc, tcl_const char *argv[]) { - string filename (argv[1]); + auto filename = filesystem::u8path(argv[1]); - if (filename.find(".vol") == string::npos) + if (filename.string().find(".vol") == string::npos) { return Ng_ImportMesh(clientData,interp,argc,argv); } @@ -217,42 +217,15 @@ namespace netgen mesh = make_shared(); try { - istream * infile; - // if (filename.substr (filename.length()-3, 3) == ".gz") - if (filename.find(".vol.gz") != string::npos) - infile = new igzstream (filename.c_str()); - else - infile = new ifstream (filename.c_str()); - - // ifstream infile(filename.c_str()); - mesh -> Load(*infile); - // vsmesh.SetMesh (mesh); + mesh -> Load(filename); SetGlobalMesh (mesh); #ifdef PARALLEL MyMPI_SendCmd ("mesh"); mesh -> Distribute(); #endif - auto geo = geometryregister.LoadFromMeshFile (*infile); - if(geo) - ng_geometry = geo; - delete infile; - - /* - string auxstring; - if(infile.good()) - { - infile >> auxstring; - if(auxstring == "csgsurfaces") - { - CSGeometry * geometry = new CSGeometry (""); - geometry -> LoadSurfaces(infile); - - delete ng_geometry; - ng_geometry = geometry; - } - } - */ + if(mesh->GetGeometry()) + ng_geometry = mesh->GetGeometry(); } catch (NgException e) {