From 0b06f8d30e57658df09f744d5cc5c8a265b077e1 Mon Sep 17 00:00:00 2001 From: Max Wilfinger Date: Wed, 3 Sep 2025 20:17:16 +0200 Subject: [PATCH] Part: Make dragger attach to the midpoint / axis for circular edges and faces --- src/Mod/Part/App/Attacher.cpp | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/Mod/Part/App/Attacher.cpp b/src/Mod/Part/App/Attacher.cpp index 01244c7b2e..38f81a336f 100644 --- a/src/Mod/Part/App/Attacher.cpp +++ b/src/Mod/Part/App/Attacher.cpp @@ -47,6 +47,8 @@ # include # include # include +# include +# include # include # include # include @@ -58,6 +60,7 @@ # include # include # include +# include #endif #include @@ -1986,6 +1989,24 @@ AttachEngine3D::_calculateAttachedPlacement(const std::vectorgetShape(); + if (!sh.IsNull() && sh.ShapeType() == TopAbs_EDGE) { + TopoDS_Edge ed = TopoDS::Edge(sh); + BRepAdaptor_Curve adapt(ed); + if (adapt.GetType() == GeomAbs_Circle) { + // Center of the circle / arc + const gp_Circ circ = adapt.Circle(); + const gp_Pnt center = circ.Location(); + const gp_Dir axisDir = circ.Axis().Direction(); // normal to circle plane + + placement.setPosition(Base::convertTo(center)); + placement.setRotation(Base::Rotation::fromNormalVector( + Base::convertTo(axisDir))); + break; + } + } } break; @@ -2003,6 +2024,26 @@ AttachEngine3D::_calculateAttachedPlacement(const std::vector(axisCenter)); + placement.setRotation(Base::Rotation::fromNormalVector( + Base::convertTo(axisDir))); + break; + } + if (auto sphere = freecad_cast(geom.get())) { placement.setPosition(sphere->getLocation()); } else if (auto cone = freecad_cast(geom.get())) {