From 7e0f0326de9a155853c1d8ef720e1dfda6b9a161 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Mon, 26 Jul 2021 09:10:50 +0200 Subject: [PATCH] occ material, copy names from step-loading to global names --- libsrc/occ/occgeom.cpp | 3 +++ libsrc/occ/python_occ.cpp | 55 +++++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index e28a4247..fa470e41 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -1555,6 +1555,9 @@ namespace netgen // for (auto pair : shape_names) // cout << "name = " << pair.second << endl; } + + for (auto [s,n] : shape_names) + OCCGeometry::global_shape_names[s] = n; timer_getnames.Start(); diff --git a/libsrc/occ/python_occ.cpp b/libsrc/occ/python_occ.cpp index 3482fc28..7cb9b18e 100644 --- a/libsrc/occ/python_occ.cpp +++ b/libsrc/occ/python_occ.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +// #include #include #include @@ -70,31 +70,36 @@ DLL_HEADER void ExportNgOCC(py::module &m) auto geo = make_shared (shape); ng_geometry = geo; - geo->BuildFMap(); - geo->CalcBoundingBox(); + // geo->BuildFMap(); + // geo->CalcBoundingBox(); return geo; }), py::arg("shape"), "Create Netgen OCCGeometry from existing TopoDS_Shape") .def(py::init([] (const std::vector shapes) { - BOPAlgo_Builder aBuilder; - - // Setting arguments - TopTools_ListOfShape aLSObjects; - /* - for (TopExp_Explorer exp_solid(shape, TopAbs_SOLID); exp_solid.More(); exp_solid.Next()) - aLSObjects.Append (exp_solid.Current()); - */ + cout << "start gluing" << endl; + BOPAlgo_Builder builder; for (auto & s : shapes) - aLSObjects.Append (s); - aBuilder.SetArguments(aLSObjects); - aBuilder.Perform(); - - auto geo = make_shared (aBuilder.Shape()); + builder.AddArgument(s); + builder.Perform(); + cout << "glued together" << endl; + + Handle(BRepTools_History) history = builder.History (); + + for (auto & s : shapes) + for (TopExp_Explorer e(s, TopAbs_SOLID); e.More(); e.Next()) + { + auto name = OCCGeometry::global_shape_names[e.Current().TShape()]; + TopTools_ListOfShape modlist = history->Modified(e.Current()); + for (auto mods : modlist) + OCCGeometry::global_shape_names[mods.TShape()] = name; + } + + auto geo = make_shared (builder.Shape()); ng_geometry = geo; - geo->BuildFMap(); - geo->CalcBoundingBox(); + // geo->BuildFMap(); + // geo->CalcBoundingBox(); return geo; }), py::arg("shape"), "Create Netgen OCCGeometry from existing TopoDS_Shape") @@ -291,8 +296,14 @@ DLL_HEADER void ExportNgOCC(py::module &m) .def("bc", [](const TopoDS_Shape & shape, const string & name) { - TopExp_Explorer e; - for (e.Init(shape, TopAbs_FACE); e.More(); e.Next()) + for (TopExp_Explorer e(shape, TopAbs_FACE); e.More(); e.Next()) + OCCGeometry::global_shape_names[e.Current().TShape()] = 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; return shape; }) @@ -378,7 +389,7 @@ DLL_HEADER void ExportNgOCC(py::module &m) app->NewDocument ("STEP-XCAF",doc); Handle(XCAFDoc_ShapeTool) shape_tool = XCAFDoc_DocumentTool::ShapeTool(doc->Main()); Handle(XCAFDoc_MaterialTool) material_tool = XCAFDoc_DocumentTool::MaterialTool(doc->Main()); - Handle(XCAFDoc_VisMaterialTool) vismaterial_tool = XCAFDoc_DocumentTool::VisMaterialTool(doc->Main()); + // Handle(XCAFDoc_VisMaterialTool) vismaterial_tool = XCAFDoc_DocumentTool::VisMaterialTool(doc->Main()); cout << "handle(shape) = " << *(void**)(void*)(&(shape.TShape())) << endl; @@ -415,7 +426,7 @@ DLL_HEADER void ExportNgOCC(py::module &m) // cout << "findshape = " << shape_tool -> FindShape(shape) << endl; cout << "IsMaterial = " << material_tool->IsMaterial(label) << endl; - cout << "IsVisMaterial = " << vismaterial_tool->IsMaterial(label) << endl; + // cout << "IsVisMaterial = " << vismaterial_tool->IsMaterial(label) << endl; } }, py::arg("shape")=TopoDS_Shape());