From 131956e201dc5033de69ed09c28db332feb081c1 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sun, 18 Aug 2024 10:06:59 -0400 Subject: [PATCH] [TD]fix crash on Cosmetic line > 10m --- src/Mod/TechDraw/App/Cosmetic.cpp | 2 +- src/Mod/TechDraw/App/DrawUtil.cpp | 2 ++ src/Mod/TechDraw/App/Geometry.cpp | 7 +++++-- src/Mod/TechDraw/App/Geometry.h | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index 8004c01f2838..c2e9fe24a446 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -77,7 +77,7 @@ CosmeticEdge::CosmeticEdge(const Base::Vector3d& pt1, const Base::Vector3d& pt2) } CosmeticEdge::CosmeticEdge(const TopoDS_Edge& e) : - CosmeticEdge(TechDraw::BaseGeom::baseFactory(e)) + CosmeticEdge(TechDraw::BaseGeom::baseFactory(e, true)) { } diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index 78970cc23a55..c20de049ea55 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -1130,6 +1130,8 @@ PyObject* DrawUtil::colorToPyTuple(App::Color color) } //check for crazy edge. This is probably a geometry error of some sort. +// note that cosmetic edges are stored as unscaled, so this test will be checking 1:1 lengths. +// a 1:1 length of > 10m is perfectly reasonable, so this check causes trouble with cosmetics. bool DrawUtil::isCrazy(TopoDS_Edge e) { diff --git a/src/Mod/TechDraw/App/Geometry.cpp b/src/Mod/TechDraw/App/Geometry.cpp index 865ef3346dc9..504bea6d07c0 100644 --- a/src/Mod/TechDraw/App/Geometry.cpp +++ b/src/Mod/TechDraw/App/Geometry.cpp @@ -474,13 +474,16 @@ std::string BaseGeom::geomTypeName() } //! Convert 1 OCC edge into 1 BaseGeom (static factory method) -BaseGeomPtr BaseGeom::baseFactory(TopoDS_Edge edge) +// this should not return nullptr as things will break later on. +// regular geometry is stored scaled, but cosmetic geometry is stored in 1:1 scale, so the crazy edge +// check is not appropriate. +BaseGeomPtr BaseGeom::baseFactory(TopoDS_Edge edge, bool isCosmetic) { if (edge.IsNull()) { Base::Console().Message("BG::baseFactory - input edge is NULL \n"); } //weed out rubbish edges before making geometry - if (!validateEdge(edge)) { + if (!isCosmetic && !validateEdge(edge)) { return nullptr; } diff --git a/src/Mod/TechDraw/App/Geometry.h b/src/Mod/TechDraw/App/Geometry.h index e503193b9339..e87949e6dccb 100644 --- a/src/Mod/TechDraw/App/Geometry.h +++ b/src/Mod/TechDraw/App/Geometry.h @@ -109,7 +109,7 @@ class TechDrawExport BaseGeom : public std::enable_shared_from_this double minDist(Base::Vector3d p); Base::Vector3d nearPoint(Base::Vector3d p); Base::Vector3d nearPoint(const BaseGeomPtr p); - static BaseGeomPtr baseFactory(TopoDS_Edge edge); + static BaseGeomPtr baseFactory(TopoDS_Edge edge, bool isCosmetic=false); static bool validateEdge(TopoDS_Edge edge); static TopoDS_Edge completeEdge(const TopoDS_Edge &edge); bool closed();