RectangleC, Plan B when occ-normal is undefined, replace History by builder.Modified

This commit is contained in:
Joachim Schoeberl 2021-09-01 22:50:09 +02:00
parent e9fc5f12a1
commit bb54e40139
2 changed files with 44 additions and 38 deletions

View File

@ -117,6 +117,11 @@ namespace netgen
return Point<3> (p.X(), p.Y(), p.Z()); return Point<3> (p.X(), p.Y(), p.Z());
} }
inline Point<2> occ2ng (const gp_Pnt2d & p)
{
return Point<2> (p.X(), p.Y());
}
inline Vec<3> occ2ng (const gp_Vec & v) inline Vec<3> occ2ng (const gp_Vec & v)
{ {
return Vec<3> (v.X(), v.Y(), v.Z()); return Vec<3> (v.X(), v.Y(), v.Z());

View File

@ -146,15 +146,14 @@ void ExtractFaceData( const TopoDS_Face & face, int index, std::vector<double> *
pts[k] = occ2ng( (triangulation -> Node(triangle(k+1))).Transformed(loc) ); pts[k] = occ2ng( (triangulation -> Node(triangle(k+1))).Transformed(loc) );
for (int k = 0; k < 3; k++) for (int k = 0; k < 3; k++)
{ {
auto uv = triangulation -> UVNode(triangle(k+1)); auto uv = triangulation -> UVNode(triangle(k+1));
prop.SetParameters (uv.X(), uv.Y()); prop.SetParameters (uv.X(), uv.Y());
if (!prop.IsNormalDefined()) if (prop.IsNormalDefined())
throw Exception("No normal defined on face"); normals[k] = occ2ng (prop.Normal());
auto normal = prop.Normal(); else
normals[k] = { normal.X(), normal.Y(), normal.Z() }; normals[k] = Cross(pts[1]-pts[0], pts[2]-pts[0]);
}
}
if(flip) if(flip)
{ {
@ -203,16 +202,17 @@ py::object CastShape(const TopoDS_Shape & s)
template <class TBuilder> template <class TBuilder>
void PropagateProperties (TBuilder & builder, TopoDS_Shape shape) void PropagateProperties (TBuilder & builder, TopoDS_Shape shape)
{ {
#ifdef OCC_HAVE_HISTORY // #ifdef OCC_HAVE_HISTORY
Handle(BRepTools_History) history = builder.History(); // Handle(BRepTools_History) history = builder.History();
for (auto typ : { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE }) for (auto typ : { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE })
for (TopExp_Explorer e(shape, typ); e.More(); e.Next()) for (TopExp_Explorer e(shape, typ); e.More(); e.Next())
{ {
auto prop = OCCGeometry::global_shape_properties[e.Current().TShape()]; auto prop = OCCGeometry::global_shape_properties[e.Current().TShape()];
for (auto mods : history->Modified(e.Current())) // for (auto mods : history->Modified(e.Current()))
for (auto mods : builder.Modified(e.Current()))
OCCGeometry::global_shape_properties[mods.TShape()].Merge(prop); OCCGeometry::global_shape_properties[mods.TShape()].Merge(prop);
} }
#endif // #endif
} }
@ -466,13 +466,27 @@ public:
Rotate (90); Rotate (90);
Line(w); Line(w);
Rotate (90); Rotate (90);
// wires.push_back (wire_builder.Wire());
// wire_builder = BRepBuilderAPI_MakeWire();
return shared_from_this(); return shared_from_this();
} }
auto RectangleCentered (double l, double w)
{
Move(-l/2);
Rotate(-90);
Move(w/2);
Rotate(90);
Rectangle(l,w);
Rotate(-90);
Move(-w/2);
Rotate(90);
Move(l/2);
return shared_from_this();
}
auto Circle(double x, double y, double r) auto Circle(double x, double y, double r)
{ {
/*
MoveTo(x+r, y); MoveTo(x+r, y);
Direction (0, 1); Direction (0, 1);
Arc(r, 180); Arc(r, 180);
@ -480,30 +494,18 @@ public:
// wires.push_back (wire_builder.Wire()); // wires.push_back (wire_builder.Wire());
// wire_builder = BRepBuilderAPI_MakeWire(); // wire_builder = BRepBuilderAPI_MakeWire();
return shared_from_this(); return shared_from_this();
*/
/* gp_Pnt2d p(x,y);
Handle(Geom2d_Circle) circ_curve = GCE2d_MakeCircle(p, r).Value();
// could not get it working with MakeCircle auto edge = BRepBuilderAPI_MakeEdge(circ_curve, surf).Edge();
BRepLib::BuildCurves3d(edge);
cout << "make circle, p = " << p.X() << "/" << p.Y() << ", r = " << r << endl;
// Handle(Geom2d_Circle) circ_curve = GCE2d_MakeCircle(p, r).Value();
// Handle(Geom2d_Curve) curve2d = new Geom2d_TrimmedCurve (circ_curve, 0, M_PI);
gp_Vec2d v(r,0);
Handle(Geom2d_TrimmedCurve) curve2d = GCE2d_MakeArcOfCircle(p.Translated(v),
p.Translated(-v),
p.Translated(v)).Value();
// Handle(Geom2d_TrimmedCurve) curve2d = GCE2d_MakeCircle(p, r).Value();
auto edge = BRepBuilderAPI_MakeEdge(curve2d, surf).Edge();
cout << "have edge, is null = " << edge.IsNull() << endl;
wire_builder.Add(edge); wire_builder.Add(edge);
wires.push_back (wire_builder.Wire()); wires.push_back (wire_builder.Wire());
cout << "have wire, is null = " << wires.back().IsNull() << endl;
wire_builder = BRepBuilderAPI_MakeWire(); wire_builder = BRepBuilderAPI_MakeWire();
return shared_from_this(); return shared_from_this();
*/
} }
auto NameVertex (string name) auto NameVertex (string name)
@ -806,8 +808,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
ShapeUpgrade_UnifySameDomain unify(fused, true, true, true); ShapeUpgrade_UnifySameDomain unify(fused, true, true, true);
unify.Build(); unify.Build();
/* // #ifdef OCC_HAVE_HISTORY
#ifdef OCC_HAVE_HISTORY
Handle(BRepTools_History) history = unify.History (); Handle(BRepTools_History) history = unify.History ();
for (auto typ : { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE }) for (auto typ : { TopAbs_SOLID, TopAbs_FACE, TopAbs_EDGE })
@ -817,9 +818,8 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
for (auto mods : history->Modified(e.Current())) for (auto mods : history->Modified(e.Current()))
OCCGeometry::global_shape_properties[mods.TShape()].Merge(prop); OCCGeometry::global_shape_properties[mods.TShape()].Merge(prop);
} }
#endif // #endif
*/ // PropagateProperties (unify, fused);
PropagateProperties (unify, fused);
return unify.Shape(); return unify.Shape();
} }
@ -1856,6 +1856,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
.def("Line", [](WorkPlane&wp,double h,double v, optional<string> name) { return wp.Line(h,v,name); }, .def("Line", [](WorkPlane&wp,double h,double v, optional<string> name) { return wp.Line(h,v,name); },
py::arg("dx"), py::arg("dy"), py::arg("name")=nullopt) py::arg("dx"), py::arg("dy"), py::arg("name")=nullopt)
.def("Rectangle", &WorkPlane::Rectangle) .def("Rectangle", &WorkPlane::Rectangle)
.def("RectangleC", &WorkPlane::RectangleCentered)
.def("Circle", [](WorkPlane&wp, double x, double y, double r) { .def("Circle", [](WorkPlane&wp, double x, double y, double r) {
return wp.Circle(x,y,r); }, py::arg("x"), py::arg("y"), py::arg("r")) return wp.Circle(x,y,r); }, py::arg("x"), py::arg("y"), py::arg("r"))
.def("Circle", [](WorkPlane&wp, double r) { return wp.Circle(r); }, py::arg("r")) .def("Circle", [](WorkPlane&wp, double r) { return wp.Circle(r); }, py::arg("r"))