From b97587cab398dbc25b6ff1b9f8ca3fcbe7781416 Mon Sep 17 00:00:00 2001 From: "MA-LAPTOP\\apeltauer" Date: Mon, 10 Aug 2020 09:14:49 +0200 Subject: [PATCH] Improve the projection on surface algorithm. For now the first possible solution was taken. If several solution exists, this leads to a miss match. Now check the distance of the projection shape and the original shape and the take the projection with the smallest distance. Discussion can be found here: https://forum.freecadweb.org/viewtopic.php?f=8&t=49341&p=422925#p422925 --- src/Mod/Part/Gui/DlgProjectionOnSurface.cpp | 31 ++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp index cbfc57d023..e61e7431fa 100644 --- a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp +++ b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp @@ -45,6 +45,7 @@ # include # include # include +#include #endif #include "DlgProjectionOnSurface.h" @@ -452,16 +453,38 @@ void PartGui::DlgProjectionOnSurface::create_projection_wire(std::vector::max(); + TopoDS_Wire wireToTake; + for ( ; aProjection.More(); aProjection.Next() ) + { + auto it = aProjection.Current(); + BRepExtrema_DistShapeShape distanceMeasure(it, itCurrentShape.aFace); + distanceMeasure.Perform(); + auto currentDistance = distanceMeasure.Value(); + if ( currentDistance > minDistance ) continue; + wireToTake = it; + minDistance = currentDistance; + } + auto aWire = sort_and_heal_wire(wireToTake, itCurrentShape.surfaceToProject); itCurrentShape.aProjectedWireVec.push_back(aWire); } } else if (!itCurrentShape.aEdge.IsNull()) { BRepProj_Projection aProjection(itCurrentShape.aEdge, itCurrentShape.surfaceToProject, itCurrentShape.aProjectionDir); - auto currentProjection = aProjection.Shape(); - for (TopExp_Explorer aExplorer(currentProjection, TopAbs_EDGE); aExplorer.More(); aExplorer.Next()) + double minDistance = std::numeric_limits::max(); + TopoDS_Wire wireToTake; + for (; aProjection.More(); aProjection.Next()) + { + auto it = aProjection.Current(); + BRepExtrema_DistShapeShape distanceMeasure(it, itCurrentShape.aEdge); + distanceMeasure.Perform(); + auto currentDistance = distanceMeasure.Value(); + if (currentDistance > minDistance) continue; + wireToTake = it; + minDistance = currentDistance; + } + for (TopExp_Explorer aExplorer(wireToTake, TopAbs_EDGE); aExplorer.More(); aExplorer.Next()) { itCurrentShape.aProjectedEdgeVec.push_back(TopoDS::Edge(aExplorer.Current())); }