Part: Fix AttacherEngine property not synced with AttacherType (#15716)

When Part2DObject (e.g., Sketch) is created, it calls setAttacher() to
set up AttachEnginePlane. This updated the internal AttacherType property
but left the user-visible AttacherEngine enum at its default "Engine 3D".

Now setAttacher() also updates AttacherEngine for non-base attachers,
keeping the visible property in sync with the actual engine type.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Timothy Miller
2026-01-21 14:52:06 -05:00
committed by Kacper Donat
parent eabd052c17
commit 27f077c62b
2 changed files with 33 additions and 0 deletions
+8
View File
@@ -293,6 +293,14 @@ void AttachExtension::setAttacher(AttachEngine* pAttacher, bool base)
// onChange->changeAttacherType->onChange...
props.attacherType->setValue(typeName);
}
// Also update the visible AttacherEngine property for non-base attachers
// to keep it in sync with AttacherType (fixes issue #15716)
if (!base) {
const char* enumVal = classToEnum(typeName);
if (strcmp(AttacherEngine.getValueAsString(), enumVal) != 0) {
AttacherEngine.setValue(enumVal);
}
}
updateAttacherVals(base);
}
else {
@@ -185,6 +185,31 @@ class RegressionTests(unittest.TestCase):
for name, pos, normal, xaxis in expected_planes:
check_plane(name, pos, normal, xaxis)
def test_issue_15716_AttacherEngine_sync(self):
"""
15716: AttacherType and AttacherEngine property conflict
When creating a Part2DObject (like a Sketch), the AttacherEngine property
should be synchronized with AttacherType. Previously, AttacherType was
correctly set to "Attacher::AttachEnginePlane" but AttacherEngine stayed
at the default "Engine 3D" instead of "Engine Plane".
"""
if "BUILD_SKETCHER" in FreeCAD.__cmake__:
# Create a new sketch (which inherits from Part2DObject)
sketch = self.Doc.addObject("Sketcher::SketchObject", "TestSketch")
self.Doc.recompute()
# The visible AttacherEngine property should match the actual engine type
# AttacherType is the internal type name, AttacherEngine is the user-visible enum
attacher_type = sketch.AttacherType
attacher_engine = sketch.AttacherEngine
# For a sketch, AttacherType should be AttachEnginePlane
self.assertEqual(attacher_type, "Attacher::AttachEnginePlane")
# AttacherEngine should show "Engine Plane" (not "Engine 3D")
self.assertEqual(attacher_engine, "Engine Plane")
def tearDown(self):
"""Clean up our test, optionally preserving the test document"""
# This flag allows doing something like this: