From 66de9d451003b6d04c5aed7a8108de8b1bd85bb5 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Thu, 29 Jul 2021 12:15:03 +0200 Subject: [PATCH] global_shape_properties, instead of individual maps --- libsrc/occ/occgenmesh.cpp | 6 +++--- libsrc/occ/occgeom.cpp | 4 ++-- libsrc/occ/occgeom.hpp | 17 ++++++++++++++++- libsrc/occ/python_occ.cpp | 33 +++++++++++++++++++++++++-------- 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/libsrc/occ/occgenmesh.cpp b/libsrc/occ/occgenmesh.cpp index 309cc322..15bf581f 100644 --- a/libsrc/occ/occgenmesh.cpp +++ b/libsrc/occ/occgenmesh.cpp @@ -410,10 +410,10 @@ namespace netgen } else { - auto it = OCCGeometry::global_shape_cols.find(face.TShape()); - if (it != OCCGeometry::global_shape_cols.end()) + auto it = OCCGeometry::global_shape_properties.find(face.TShape()); + if (it != OCCGeometry::global_shape_properties.end() && it->second.col) { - Vec<3> col = it->second; + Vec<3> col = it->second.col.value_or(Vec<3>(0,1,0)); mesh.GetFaceDescriptor(facenr).SetSurfColour(col); } else diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index 2edad454..9426405d 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -42,8 +42,8 @@ namespace netgen { std::map OCCGeometry::global_shape_names; - std::map> OCCGeometry::global_shape_cols; - + // std::map> OCCGeometry::global_shape_cols; + std::map OCCGeometry::global_shape_properties; OCCGeometry::OCCGeometry(const TopoDS_Shape& _shape) { diff --git a/libsrc/occ/occgeom.hpp b/libsrc/occ/occgeom.hpp index a07f6d45..d073b7cc 100644 --- a/libsrc/occ/occgeom.hpp +++ b/libsrc/occ/occgeom.hpp @@ -203,14 +203,29 @@ namespace netgen void Print (ostream & ost) const; }; + + class ShapeProperties + { + public: + optional name; + optional> col; + void Merge(const ShapeProperties & prop2) + { + if (prop2.name) name = prop2.name; + if (prop2.col) col = prop2.col; + } + }; + class DLL_HEADER OCCGeometry : public NetgenGeometry { Point<3> center; OCCParameters occparam; public: + static std::map global_shape_properties; + static std::map global_shape_names; - static std::map> global_shape_cols; + // static std::map> global_shape_cols; TopoDS_Shape shape; TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap; diff --git a/libsrc/occ/python_occ.cpp b/libsrc/occ/python_occ.cpp index a180d975..ba47cc58 100644 --- a/libsrc/occ/python_occ.cpp +++ b/libsrc/occ/python_occ.cpp @@ -376,32 +376,39 @@ DLL_HEADER void ExportNgOCC(py::module &m) .def("bc", [](const TopoDS_Shape & shape, const string & name) { for (TopExp_Explorer e(shape, TopAbs_FACE); e.More(); e.Next()) - OCCGeometry::global_shape_names[e.Current().TShape()] = name; + { + OCCGeometry::global_shape_names[e.Current().TShape()] = name; + OCCGeometry::global_shape_properties[e.Current().TShape()].name = name; + } return shape; }) .def("mat", [](const TopoDS_Shape & shape, const string & name) { for (TopExp_Explorer e(shape, TopAbs_SOLID); e.More(); e.Next()) - OCCGeometry::global_shape_names[e.Current().TShape()] = name; + { + OCCGeometry::global_shape_names[e.Current().TShape()] = name; + OCCGeometry::global_shape_properties[e.Current().TShape()].name = name; + } return shape; }) .def_property("name", [](const TopoDS_Shape & self) { return OCCGeometry::global_shape_names[self.TShape()]; }, [](const TopoDS_Shape & self, string name) { - OCCGeometry::global_shape_names[self.TShape()] = name; + OCCGeometry::global_shape_names[self.TShape()] = name; + OCCGeometry::global_shape_properties[self.TShape()].name = name; }) .def_property("col", [](const TopoDS_Shape & self) { - auto it = OCCGeometry::global_shape_cols.find(self.TShape()); + auto it = OCCGeometry::global_shape_properties.find(self.TShape()); Vec<3> col(0.2, 0.2, 0.2); - if (it != OCCGeometry::global_shape_cols.end()) - col = it->second; + if (it != OCCGeometry::global_shape_properties.end() && it->second.col) + col = it->second.col.value(); return std::vector ( { col(0), col(1), col(2) } ); }, [](const TopoDS_Shape & self, std::vector c) { Vec<3> col(c[0], c[1], c[2]); - OCCGeometry::global_shape_cols[self.TShape()] = col; + OCCGeometry::global_shape_properties[self.TShape()].col = col; }) @@ -429,6 +436,10 @@ DLL_HEADER void ExportNgOCC(py::module &m) const string & name = OCCGeometry::global_shape_names[e.Current().TShape()]; for (auto smod : history->Modified(e.Current())) OCCGeometry::global_shape_names[smod.TShape()] = name; + + auto & prop = OCCGeometry::global_shape_properties[e.Current().TShape()]; + for (auto smod : history->Modified(e.Current())) + OCCGeometry::global_shape_properties[smod.TShape()].Merge(prop); } #endif // OCC_HAVE_HISTORY @@ -448,11 +459,17 @@ DLL_HEADER void ExportNgOCC(py::module &m) const string & name = OCCGeometry::global_shape_names[e.Current().TShape()]; for (auto s : history->Modified(e.Current())) OCCGeometry::global_shape_names[s.TShape()] = name; - + + /* auto it = OCCGeometry::global_shape_cols.find(e.Current().TShape()); if (it != OCCGeometry::global_shape_cols.end()) for (auto s : history->Modified(e.Current())) OCCGeometry::global_shape_cols[s.TShape()] = it->second; + */ + auto propit = OCCGeometry::global_shape_properties.find(e.Current().TShape()); + if (propit != OCCGeometry::global_shape_properties.end()) + for (auto s : history->Modified(e.Current())) + OCCGeometry::global_shape_properties[s.TShape()].Merge(propit->second); } /*