From 6a8eca135b16ed2a0adb9157e04743e1a443698e Mon Sep 17 00:00:00 2001 From: wandererfan Date: Thu, 20 Apr 2023 14:16:06 -0400 Subject: [PATCH] [TD]fix null shape in GeometryMatcher --- src/Mod/TechDraw/App/GeometryMatcher.cpp | 58 +++++++++++++++++++----- src/Mod/TechDraw/App/GeometryMatcher.h | 20 ++++---- 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/src/Mod/TechDraw/App/GeometryMatcher.cpp b/src/Mod/TechDraw/App/GeometryMatcher.cpp index 029dae7331..e66b219317 100644 --- a/src/Mod/TechDraw/App/GeometryMatcher.cpp +++ b/src/Mod/TechDraw/App/GeometryMatcher.cpp @@ -55,10 +55,14 @@ bool GeometryMatcher::compareGeometry(Part::TopoShape shape1, Part::TopoShape s { // Base::Console().Message("GM::compareGeometry()\n"); if (shape1.isNull() || shape2.isNull()) { - Base::Console().Message("GM::compareGeometry - one or more shapes are null\n"); + Base::Console().Message("GM::compareGeometry - one or more TopoShapes are null\n"); } TopoDS_Shape geom1 = shape1.getShape(); TopoDS_Shape geom2 = shape2.getShape(); + if (geom1.IsNull() || geom2.IsNull()) { + Base::Console().Message("GM::compareGeometry - one or more TopoDS_Shapes are null\n"); + } + if (geom1.ShapeType() == TopAbs_VERTEX) { return comparePoints(geom1, geom2); } @@ -68,7 +72,7 @@ bool GeometryMatcher::compareGeometry(Part::TopoShape shape1, Part::TopoShape s return false; } -bool GeometryMatcher::comparePoints(TopoDS_Shape shape1, TopoDS_Shape shape2) +bool GeometryMatcher::comparePoints(TopoDS_Shape &shape1, TopoDS_Shape &shape2) { // Base::Console().Message("GM::comparePoints()\n"); if (shape1.ShapeType() != TopAbs_VERTEX || @@ -86,7 +90,7 @@ bool GeometryMatcher::comparePoints(TopoDS_Shape shape1, TopoDS_Shape shape2) return false; } -bool GeometryMatcher::compareEdges(TopoDS_Shape shape1, TopoDS_Shape shape2) +bool GeometryMatcher::compareEdges(TopoDS_Shape &shape1, TopoDS_Shape &shape2) { // Base::Console().Message("GM::compareEdges()\n"); if (shape1.ShapeType() != TopAbs_EDGE || @@ -97,6 +101,10 @@ bool GeometryMatcher::compareEdges(TopoDS_Shape shape1, TopoDS_Shape shape2) } TopoDS_Edge edge1 = TopoDS::Edge(shape1); TopoDS_Edge edge2 = TopoDS::Edge(shape2); + if (edge1.IsNull() || edge2.IsNull()) { + Base::Console().Message("GM::compareEdges - an input edge is null\n"); + } + BRepAdaptor_Curve adapt1(edge1); BRepAdaptor_Curve adapt2(edge2); @@ -132,9 +140,14 @@ bool GeometryMatcher::compareEdges(TopoDS_Shape shape1, TopoDS_Shape shape2) return compareDifferent(edge1, edge2); } -bool GeometryMatcher::compareLines(TopoDS_Edge edge1, TopoDS_Edge edge2) +bool GeometryMatcher::compareLines(TopoDS_Edge &edge1, TopoDS_Edge &edge2) { // Base::Console().Message("GM::compareLines()\n"); + // how does the edge that was NOT null in compareEdges become null here? + if (edge1.IsNull() || edge2.IsNull()) { +// Base::Console().Message("GM::compareLine - an input edge is null\n"); + return false; + } auto start1 = DU::toVector3d(BRep_Tool::Pnt(TopExp::FirstVertex(edge1))); auto end1 = DU::toVector3d(BRep_Tool::Pnt(TopExp::LastVertex(edge1))); auto start2 = DU::toVector3d(BRep_Tool::Pnt(TopExp::FirstVertex(edge2))); @@ -147,9 +160,15 @@ bool GeometryMatcher::compareLines(TopoDS_Edge edge1, TopoDS_Edge edge2) return false; } -bool GeometryMatcher::compareCircles(TopoDS_Edge edge1, TopoDS_Edge edge2) +bool GeometryMatcher::compareCircles(TopoDS_Edge &edge1, TopoDS_Edge &edge2) { // Base::Console().Message("GM::compareCircles()\n"); + // how does the edge that was NOT null in compareEdges become null here? + if (edge1.IsNull() || edge2.IsNull()) { +// Base::Console().Message("GM::compareCircles - an input edge is null\n"); + return false; + } + BRepAdaptor_Curve adapt1(edge1); BRepAdaptor_Curve adapt2(edge2); gp_Circ circle1 = adapt1.Circle(); @@ -166,8 +185,14 @@ bool GeometryMatcher::compareCircles(TopoDS_Edge edge1, TopoDS_Edge edge2) return false; } -bool GeometryMatcher::compareEllipses(TopoDS_Edge edge1, TopoDS_Edge edge2) +bool GeometryMatcher::compareEllipses(TopoDS_Edge &edge1, TopoDS_Edge &edge2) { + // how does the edge that was NOT null in compareEdges become null here? + if (edge1.IsNull() || edge2.IsNull()) { +// Base::Console().Message("GM::compareEllipses - an input edge is null\n"); + return false; + } + BRepAdaptor_Curve adapt1(edge1); BRepAdaptor_Curve adapt2(edge2); gp_Elips ellipse1 = adapt1.Ellipse(); @@ -188,8 +213,13 @@ bool GeometryMatcher::compareEllipses(TopoDS_Edge edge1, TopoDS_Edge edge2) } // for our purposes, only circles masquerading as bsplines are of interest -bool GeometryMatcher::compareBSplines(TopoDS_Edge edge1, TopoDS_Edge edge2) +bool GeometryMatcher::compareBSplines(TopoDS_Edge &edge1, TopoDS_Edge &edge2) { + // how does the edge that was NOT null in compareEdges become null here? + if (edge1.IsNull() || edge2.IsNull()) { +// Base::Console().Message("GM::compareBSplines - an input edge is null\n"); + return false; + } BRepAdaptor_Curve adapt1(edge1); BRepAdaptor_Curve adapt2(edge2); bool isArc1(false); @@ -217,27 +247,33 @@ bool GeometryMatcher::compareBSplines(TopoDS_Edge edge1, TopoDS_Edge edge2) } // this is a weak comparison. we should also check center & radius? -bool GeometryMatcher::compareCircleArcs(TopoDS_Edge edge1, TopoDS_Edge edge2) +bool GeometryMatcher::compareCircleArcs(TopoDS_Edge &edge1, TopoDS_Edge &edge2) { return compareEndPoints(edge1, edge2); } -bool GeometryMatcher::compareEllipseArcs(TopoDS_Edge edge1, TopoDS_Edge edge2) +bool GeometryMatcher::compareEllipseArcs(TopoDS_Edge &edge1, TopoDS_Edge &edge2) { return compareEndPoints(edge1, edge2); } // this is where we would try to match a bspline against a line or a circle. // not sure how successful this would be. For now, we just say it doesn't match -bool GeometryMatcher::compareDifferent(TopoDS_Edge edge1, TopoDS_Edge edge2) +bool GeometryMatcher::compareDifferent(TopoDS_Edge &edge1, TopoDS_Edge &edge2) { BRepAdaptor_Curve adapt1(edge1); BRepAdaptor_Curve adapt2(edge2); return false; } -bool GeometryMatcher::compareEndPoints(TopoDS_Edge edge1, TopoDS_Edge edge2) +bool GeometryMatcher::compareEndPoints(TopoDS_Edge &edge1, TopoDS_Edge &edge2) { + // how does the edge that was NOT null in compareEdges become null here? + if (edge1.IsNull() || edge2.IsNull()) { +// Base::Console().Message("GM::compareLine - an input edge is null\n"); + return false; + } + BRepAdaptor_Curve adapt1(edge1); BRepAdaptor_Curve adapt2(edge2); double pFirst1 = adapt1.FirstParameter(); diff --git a/src/Mod/TechDraw/App/GeometryMatcher.h b/src/Mod/TechDraw/App/GeometryMatcher.h index 99ca630177..f6b27d24a6 100644 --- a/src/Mod/TechDraw/App/GeometryMatcher.h +++ b/src/Mod/TechDraw/App/GeometryMatcher.h @@ -42,19 +42,19 @@ public: ~GeometryMatcher() = default; bool compareGeometry(Part::TopoShape geom1, Part::TopoShape geom2); - bool comparePoints(TopoDS_Shape shape1, TopoDS_Shape shape2); - bool compareEdges(TopoDS_Shape shape1, TopoDS_Shape shape2); + bool comparePoints(TopoDS_Shape& shape1, TopoDS_Shape& shape2); + bool compareEdges(TopoDS_Shape& shape1, TopoDS_Shape& shape2); - bool compareLines(TopoDS_Edge edge1, TopoDS_Edge edge2); - bool compareCircles(TopoDS_Edge edge1, TopoDS_Edge edge2); - bool compareEllipses(TopoDS_Edge edge1, TopoDS_Edge edge2); - bool compareBSplines(TopoDS_Edge edge1, TopoDS_Edge edge2); - bool compareDifferent(TopoDS_Edge edge1, TopoDS_Edge edge2); - bool compareCircleArcs(TopoDS_Edge edge1, TopoDS_Edge edge2); - bool compareEllipseArcs(TopoDS_Edge edge1, TopoDS_Edge edge2); + bool compareLines(TopoDS_Edge& edge1, TopoDS_Edge& edge2); + bool compareCircles(TopoDS_Edge& edge1, TopoDS_Edge& edge2); + bool compareEllipses(TopoDS_Edge& edge1, TopoDS_Edge& edge2); + bool compareBSplines(TopoDS_Edge& edge1, TopoDS_Edge& edge2); + bool compareDifferent(TopoDS_Edge& edge1, TopoDS_Edge& edge2); + bool compareCircleArcs(TopoDS_Edge& edge1, TopoDS_Edge& edge2); + bool compareEllipseArcs(TopoDS_Edge& edge1, TopoDS_Edge& edge2); private: - bool compareEndPoints(TopoDS_Edge edge1, TopoDS_Edge edge2); + bool compareEndPoints(TopoDS_Edge& edge1, TopoDS_Edge& edge2); DrawViewDimension* m_dimension; };