Global 'Glue' function, preserve more history

This commit is contained in:
Joachim Schoeberl 2021-07-26 22:35:33 +02:00
parent e502eeee2f
commit 4da7f6ac72
2 changed files with 79 additions and 17 deletions

View File

@ -51,7 +51,7 @@ namespace netgen
BuildFMap();
CalcBoundingBox();
TopExp_Explorer e;
TopExp_Explorer e, exp1;
for (e.Init(shape, TopAbs_SOLID); e.More(); e.Next())
{
TopoDS_Solid solid = TopoDS::Solid(e.Current());
@ -68,16 +68,15 @@ namespace netgen
if (name == "")
name = string("bc_") + ToString(fnames.Size());
fnames.Append(name);
/*
for (exp1.Init(face, TopAbs_EDGE); exp1.More(); exp1.Next())
{
TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
// name = STEP_GetEntityName(edge,&reader);
// cout << "getname = " << name << ", mapname = " << shape_names[edge.TShape()] << endl;
name = shape_names[edge.TShape()];
occgeo->enames.Append(name);
name = global_shape_names[edge.TShape()];
enames.Append(name);
}
*/
}
}
@ -290,6 +289,17 @@ namespace netgen
;
}
#endif
Handle(BRepTools_History) history = aBuilder.History ();
for (TopExp_Explorer e(shape, TopAbs_SOLID); e.More(); e.Next())
{
auto name = OCCGeometry::global_shape_names[e.Current().TShape()];
for (auto mods : history->Modified(e.Current()))
OCCGeometry::global_shape_names[mods.TShape()] = name;
}
// result of the operation
shape = aBuilder.Shape();
BuildFMap();

View File

@ -341,16 +341,18 @@ DLL_HEADER void ExportNgOCC(py::module &m)
for (TopExp_Explorer e(shape1, TopAbs_FACE); e.More(); e.Next())
{
const string & name = OCCGeometry::global_shape_names[e.Current().TShape()];
TopTools_ListOfShape modlist = history->Modified(e.Current());
for (auto s : modlist)
// TopTools_ListOfShape modlist = history->Modified(e.Current());
// for (auto s : modlist)
for (auto s : history->Modified(e.Current()))
OCCGeometry::global_shape_names[s.TShape()] = name;
}
for (TopExp_Explorer e(shape2, TopAbs_FACE); e.More(); e.Next())
{
const string & name = OCCGeometry::global_shape_names[e.Current().TShape()];
TopTools_ListOfShape modlist = history->Modified(e.Current());
for (auto s : modlist)
// TopTools_ListOfShape modlist = history->Modified(e.Current());
// for (auto s : modlist)
for (auto s : history->Modified(e.Current()))
OCCGeometry::global_shape_names[s.TShape()] = name;
}
#endif // OCC_HAVE_HISTORY
@ -375,16 +377,66 @@ DLL_HEADER void ExportNgOCC(py::module &m)
m.def("Box", [] (gp_Pnt cp1, gp_Pnt cp2) {
return BRepPrimAPI_MakeBox (cp1, cp2).Shape();
});
m.def("Glue", [] (const std::vector<TopoDS_Shape> shapes) -> TopoDS_Shape
{
BOPAlgo_Builder builder;
for (auto & s : shapes)
for (TopExp_Explorer e(s, TopAbs_SOLID); e.More(); e.Next())
builder.AddArgument(e.Current());
builder.Perform();
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;
}
return builder.Shape();
});
m.def("Glue", [] (TopoDS_Shape shape) -> TopoDS_Shape
{
BOPAlgo_Builder builder;
for (TopExp_Explorer e(shape, TopAbs_SOLID); e.More(); e.Next())
builder.AddArgument(e.Current());
builder.Perform();
if (builder.HasErrors())
builder.DumpErrors(cout);
if (builder.HasWarnings())
builder.DumpWarnings(cout);
Handle(BRepTools_History) history = builder.History ();
for (TopExp_Explorer e(shape, TopAbs_SOLID); e.More(); e.Next())
{
auto name = OCCGeometry::global_shape_names[e.Current().TShape()];
for (auto mods : history->Modified(e.Current()))
OCCGeometry::global_shape_names[mods.TShape()] = name;
}
return builder.Shape();
});
m.def("LoadOCCGeometry",[] (const string & filename)
{
cout << "WARNING: LoadOCCGeometry is deprecated! Just use the OCCGeometry(filename) constructor. It is able to read brep and iges files as well!" << endl;
ifstream ist(filename);
OCCGeometry * instance = new OCCGeometry();
instance = LoadOCC_STEP(filename.c_str());
ng_geometry = shared_ptr<OCCGeometry>(instance, NOOP_Deleter);
return ng_geometry;
},py::call_guard<py::gil_scoped_release>());
{
cout << "WARNING: LoadOCCGeometry is deprecated! Just use the OCCGeometry(filename) constructor. It is able to read brep and iges files as well!" << endl;
ifstream ist(filename);
OCCGeometry * instance = new OCCGeometry();
instance = LoadOCC_STEP(filename.c_str());
ng_geometry = shared_ptr<OCCGeometry>(instance, NOOP_Deleter);
return ng_geometry;
},py::call_guard<py::gil_scoped_release>());
m.def("TestXCAF", [] (TopoDS_Shape shape) {