From 3d7092e8b389ab329d12d6aedf0dfc085757d4bb Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Thu, 17 Jan 2013 12:41:57 +0000 Subject: [PATCH] fix LoadGeometry in nglib (geom2d, stl) --- libsrc/geom2d/geom2dpkg.cpp | 34 +++++--------------- libsrc/geom2d/geometry2d.cpp | 37 ++++++++++++++++++++++ libsrc/stlgeom/stlgeom.cpp | 61 ++++++++++++++++++++++++++++++++++++ libsrc/stlgeom/stlpkg.cpp | 56 +++++---------------------------- 4 files changed, 113 insertions(+), 75 deletions(-) diff --git a/libsrc/geom2d/geom2dpkg.cpp b/libsrc/geom2d/geom2dpkg.cpp index 1456c6ac..15a64531 100644 --- a/libsrc/geom2d/geom2dpkg.cpp +++ b/libsrc/geom2d/geom2dpkg.cpp @@ -10,42 +10,24 @@ namespace netgen { - extern DLL_HEADER NetgenGeometry * ng_geometry; + // extern DLL_HEADER NetgenGeometry * ng_geometry; static VisualSceneGeometry2d vsgeom2d; - class SplineGeometryRegister : public GeometryRegister + + + class SplineGeometryVisRegister : public GeometryRegister { public: - virtual NetgenGeometry * Load (string filename) const; + virtual NetgenGeometry * Load (string filename) const { return NULL; } virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const; }; - NetgenGeometry * SplineGeometryRegister :: Load (string filename) const + VisualScene * SplineGeometryVisRegister :: GetVisualScene (const NetgenGeometry * geom) const { - const char * cfilename = filename.c_str(); - if (strcmp (&cfilename[strlen(cfilename)-4], "in2d") == 0) - { - PrintMessage (1, "Load 2D-Spline geometry file ", cfilename); - - - ifstream infile(cfilename); - - SplineGeometry2d * hgeom = new SplineGeometry2d(); - hgeom -> Load (cfilename); - return hgeom; - } - - return NULL; - } - - - - VisualScene * SplineGeometryRegister :: GetVisualScene (const NetgenGeometry * geom) const - { - SplineGeometry2d * geometry = dynamic_cast (ng_geometry); + const SplineGeometry2d * geometry = dynamic_cast (geom); if (geometry) { vsgeom2d.SetGeometry (geometry); @@ -67,6 +49,6 @@ extern "C" int Ng_geom2d_Init (Tcl_Interp * interp); int Ng_geom2d_Init (Tcl_Interp * interp) { - geometryregister.Append (new SplineGeometryRegister); + geometryregister.Append (new SplineGeometryVisRegister); return TCL_OK; } diff --git a/libsrc/geom2d/geometry2d.cpp b/libsrc/geom2d/geometry2d.cpp index 8d3418b8..403a43b8 100644 --- a/libsrc/geom2d/geometry2d.cpp +++ b/libsrc/geom2d/geometry2d.cpp @@ -945,4 +945,41 @@ namespace netgen return * new Refinement2d (*this); } + + + class SplineGeometryRegister : public GeometryRegister + { + public: + virtual NetgenGeometry * Load (string filename) const; + }; + + NetgenGeometry * SplineGeometryRegister :: Load (string filename) const + { + const char * cfilename = filename.c_str(); + if (strcmp (&cfilename[strlen(cfilename)-4], "in2d") == 0) + { + PrintMessage (1, "Load 2D-Spline geometry file ", cfilename); + + + ifstream infile(cfilename); + + SplineGeometry2d * hgeom = new SplineGeometry2d(); + hgeom -> Load (cfilename); + return hgeom; + } + + return NULL; + } + + class SplineGeoInit + { + public: + SplineGeoInit() + { + geometryregister.Append (new SplineGeometryRegister); + } + }; + + SplineGeoInit sginit; + } diff --git a/libsrc/stlgeom/stlgeom.cpp b/libsrc/stlgeom/stlgeom.cpp index cc789ec2..b93ef718 100644 --- a/libsrc/stlgeom/stlgeom.cpp +++ b/libsrc/stlgeom/stlgeom.cpp @@ -3506,4 +3506,65 @@ void STLGeometry :: SmoothGeometry () SetPoint (i, pi); } } + + + + class STLGeometryRegister : public GeometryRegister + { + public: + virtual NetgenGeometry * Load (string filename) const; + }; + + NetgenGeometry * STLGeometryRegister :: Load (string filename) const + { + const char * cfilename = filename.c_str(); + + if (strcmp (&cfilename[strlen(cfilename)-3], "stl") == 0) + { + PrintMessage (1, "Load STL geometry file ", cfilename); + + ifstream infile(cfilename); + + STLGeometry * hgeom = STLGeometry :: Load (infile); + hgeom -> edgesfound = 0; + return hgeom; + } + else if (strcmp (&cfilename[strlen(cfilename)-4], "stlb") == 0) + { + PrintMessage (1, "Load STL binary geometry file ", cfilename); + + ifstream infile(cfilename); + + STLGeometry * hgeom = STLGeometry :: LoadBinary (infile); + hgeom -> edgesfound = 0; + return hgeom; + } + else if (strcmp (&cfilename[strlen(cfilename)-3], "nao") == 0) + { + PrintMessage (1, "Load naomi (F. Kickinger) geometry file ", cfilename); + + ifstream infile(cfilename); + + STLGeometry * hgeom = STLGeometry :: LoadNaomi (infile); + hgeom -> edgesfound = 0; + return hgeom; + } + + + return NULL; + } + + + class STLInit + { + public: + STLInit() + { + geometryregister.Append (new STLGeometryRegister); + } + }; + + STLInit stlinit; + + } diff --git a/libsrc/stlgeom/stlpkg.cpp b/libsrc/stlgeom/stlpkg.cpp index 4282633a..eb1c5513 100644 --- a/libsrc/stlgeom/stlpkg.cpp +++ b/libsrc/stlgeom/stlpkg.cpp @@ -31,10 +31,10 @@ namespace netgen - class STLGeometryRegister : public GeometryRegister + class STLGeometryVisRegister : public GeometryRegister { public: - virtual NetgenGeometry * Load (string filename) const; + virtual NetgenGeometry * Load (string filename) const { return NULL; } virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const; virtual void SetParameters (Tcl_Interp * interp) { @@ -103,7 +103,7 @@ namespace netgen Tcl_Interp * interp, int argc, tcl_const char *argv[]) { - STLGeometryRegister reg; + STLGeometryVisRegister reg; reg.SetParameters (interp); return TCL_OK; @@ -406,48 +406,6 @@ namespace netgen - NetgenGeometry * STLGeometryRegister :: Load (string filename) const - { - const char * cfilename = filename.c_str(); - - if (strcmp (&cfilename[strlen(cfilename)-3], "stl") == 0) - { - PrintMessage (1, "Load STL geometry file ", cfilename); - - ifstream infile(cfilename); - - STLGeometry * hgeom = STLGeometry :: Load (infile); - hgeom -> edgesfound = 0; - return hgeom; - } - else if (strcmp (&cfilename[strlen(cfilename)-4], "stlb") == 0) - { - PrintMessage (1, "Load STL binary geometry file ", cfilename); - - ifstream infile(cfilename); - - STLGeometry * hgeom = STLGeometry :: LoadBinary (infile); - hgeom -> edgesfound = 0; - return hgeom; - } - else if (strcmp (&cfilename[strlen(cfilename)-3], "nao") == 0) - { - PrintMessage (1, "Load naomi (F. Kickinger) geometry file ", cfilename); - - ifstream infile(cfilename); - - STLGeometry * hgeom = STLGeometry :: LoadNaomi (infile); - hgeom -> edgesfound = 0; - return hgeom; - } - - - return NULL; - } - - - - @@ -581,12 +539,12 @@ namespace netgen - VisualScene * STLGeometryRegister :: GetVisualScene (const NetgenGeometry * geom) const + VisualScene * STLGeometryVisRegister :: GetVisualScene (const NetgenGeometry * geom) const { - STLGeometry * geometry = dynamic_cast (ng_geometry); + const STLGeometry * geometry = dynamic_cast (geom); if (geometry) { - vsstlmeshing.SetGeometry (geometry); + vsstlmeshing.SetGeometry (const_cast (geometry)); return &vsstlmeshing; } return NULL; @@ -599,7 +557,7 @@ using namespace netgen; extern "C" int Ng_stl_Init (Tcl_Interp * interp); int Ng_stl_Init (Tcl_Interp * interp) { - geometryregister.Append (new STLGeometryRegister); + geometryregister.Append (new STLGeometryVisRegister); Tcl_CreateCommand (interp, "Ng_SetSTLParameters", Ng_SetSTLParameters, (ClientData)NULL,