From 14f32f73c08bc59328d860841ccf48c6f9a1ad42 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Sat, 6 Nov 2021 10:44:01 +0100 Subject: [PATCH] range-based for for TopExp_Explorer --- libsrc/occ/occgeom.cpp | 48 ++++++++++++++---------------------------- libsrc/occ/occgeom.hpp | 26 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index 7ae89306..0cbf47cf 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -779,7 +779,6 @@ namespace netgen - void OCCGeometry :: BuildFMap() { somap.Clear(); @@ -881,7 +880,7 @@ namespace netgen TopoDS_Face face = TopoDS::Face(exp2.Current()); if (fmap.FindIndex(face) < 1) { - fmap.Add (face); + fmap.Add (face); for (exp3.Init(face, TopAbs_WIRE); exp3.More(); exp3.Next()) { @@ -913,39 +912,24 @@ namespace netgen // Free Faces - - for (exp2.Init(shape, TopAbs_FACE, TopAbs_SHELL); exp2.More(); exp2.Next()) - { - TopoDS_Face face = TopoDS::Face(exp2.Current()); - if (fmap.FindIndex(face) < 1) - { + for (auto face : MyExplorer(shape, TopAbs_FACE, TopAbs_SHELL)) + if (fmap.FindIndex(face) < 1) + { fmap.Add (face); - - for (exp3.Init(exp2.Current(), TopAbs_WIRE); exp3.More(); exp3.Next()) - { - TopoDS_Wire wire = TopoDS::Wire (exp3.Current()); - if (wmap.FindIndex(wire) < 1) - { + for (auto wire : MyExplorer(face, TopAbs_WIRE)) + if (wmap.FindIndex(wire) < 1) + { wmap.Add (wire); - - for (exp4.Init(exp3.Current(), TopAbs_EDGE); exp4.More(); exp4.Next()) - { - TopoDS_Edge edge = TopoDS::Edge(exp4.Current()); - if (emap.FindIndex(edge) < 1) - { + for (auto edge : MyExplorer(wire, TopAbs_EDGE)) + if (emap.FindIndex(edge) < 1) + { emap.Add (edge); - for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next()) - { - TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current()); - if (vmap.FindIndex(vertex) < 1) - vmap.Add (vertex); - } - } - } - } - } - } - } + for (auto vertex : MyExplorer(edge, TopAbs_VERTEX)) + if (vmap.FindIndex(vertex) < 1) + vmap.Add (vertex); + } + } + } // Free Wires diff --git a/libsrc/occ/occgeom.hpp b/libsrc/occ/occgeom.hpp index e2fd950b..a1544b81 100644 --- a/libsrc/occ/occgeom.hpp +++ b/libsrc/occ/occgeom.hpp @@ -243,6 +243,32 @@ namespace netgen bool inverse; string name; }; + + + class MyExplorer + { + class Iterator + { + TopExp_Explorer exp; + public: + Iterator (TopoDS_Shape ashape, TopAbs_ShapeEnum atoFind, TopAbs_ShapeEnum atoAvoid) + : exp(ashape, atoFind, atoAvoid) { } + auto operator*() { return exp.Current(); } + Iterator & operator++() { exp.Next(); return *this; } + bool operator!= (nullptr_t nu) { return exp.More(); } + }; + + public: + TopoDS_Shape shape; + TopAbs_ShapeEnum toFind; + TopAbs_ShapeEnum toAvoid; + MyExplorer (TopoDS_Shape ashape, TopAbs_ShapeEnum atoFind, TopAbs_ShapeEnum atoAvoid = TopAbs_SHAPE) + : shape(ashape), toFind(atoFind), toAvoid(atoAvoid) { ; } + Iterator begin() { return Iterator(shape, toFind, toAvoid); } + auto end() { return nullptr; } + }; + + class DLL_HEADER OCCGeometry : public NetgenGeometry {