From e0afa0a91610cac1bad99e37ab1b42506e288141 Mon Sep 17 00:00:00 2001 From: "mhochsteger@cerbsim.com" Date: Wed, 10 Nov 2021 18:19:18 +0100 Subject: [PATCH] Use TextOutArchive to store OCCGeometry in mesh files --- libsrc/meshing/basegeom.cpp | 18 ++++++++++++++++++ libsrc/occ/occgeom.cpp | 12 ++++++++++++ libsrc/occ/occgeom.hpp | 1 + 3 files changed, 31 insertions(+) diff --git a/libsrc/meshing/basegeom.cpp b/libsrc/meshing/basegeom.cpp index 40e45fc1..62c0b981 100644 --- a/libsrc/meshing/basegeom.cpp +++ b/libsrc/meshing/basegeom.cpp @@ -507,6 +507,24 @@ namespace netgen shared_ptr GeometryRegisterArray :: LoadFromMeshFile (istream & ist) const { + if (!ist.good()) + return nullptr; + + string token; + ist >> token; + if(token == "TextOutArchive") + { + NetgenGeometry *geo = nullptr; + size_t string_length; + ist >> string_length; + string buffer(string_length+1, '\0'); + ist.read(&buffer[0], string_length); + auto ss = make_shared(buffer); + TextInArchive in(ss); + in & geo; + + return shared_ptr(geo); + } for (int i = 0; i < Size(); i++) { NetgenGeometry * hgeom = (*this)[i]->LoadFromMeshFile (ist, token); diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index c70019a2..734044b4 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -1654,6 +1654,18 @@ namespace netgen } } + void OCCGeometry :: SaveToMeshFile (ostream & ost) const + { + auto ss = make_shared(); + TextOutArchive out(ss); + NetgenGeometry *geo = const_cast(this); + out & geo; + + ost << "TextOutArchive" << endl; + ost << ss->str().size() << endl; + ost << ss->str(); + } + void OCCGeometry :: DoArchive(Archive& ar) { if(ar.Output()) diff --git a/libsrc/occ/occgeom.hpp b/libsrc/occ/occgeom.hpp index 59e5245c..381a3df1 100644 --- a/libsrc/occ/occgeom.hpp +++ b/libsrc/occ/occgeom.hpp @@ -380,6 +380,7 @@ namespace netgen void FinalizeMesh(Mesh& mesh) const override; void Save (string filename) const override; + void SaveToMeshFile (ostream & /* ost */) const override; void DoArchive(Archive& ar) override;