From f99abec58e710ba44af899404b4910f9ea626ef7 Mon Sep 17 00:00:00 2001 From: Paddle Date: Mon, 7 Mar 2022 16:22:40 +0100 Subject: [PATCH] Sketcher: Create Geometry ConstraintToAttachment function --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 6ea90ff521..3d82c1e40a 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -190,6 +190,30 @@ void removeRedundantHorizontalVertical(Sketcher::SketchObject* psketch, } } +void ConstraintToAttachment(Sketcher::GeoElementId element, Sketcher::GeoElementId attachment, double distance, App::DocumentObject* obj) { + if (distance == 0.) { + + if(attachment.isCurve()) { + Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('PointOnObject',%d,%d,%d)) ", + element.GeoId, element.posIdAsInt(), attachment.GeoId); + + } + else { + Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Coincident',%d,%d,%d,%d)) ", + element.GeoId, element.posIdAsInt(), attachment.GeoId, attachment.posIdAsInt()); + } + } + else { + if(attachment == Sketcher::GeoElementId::VAxis) { + Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%f)) ", + element.GeoId, element.posIdAsInt(), distance); + } + else if(attachment == Sketcher::GeoElementId::HAxis) { + Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%f)) ", + element.GeoId, element.posIdAsInt(), distance); + } + } +} /* Sketch commands =======================================================*/