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())); }