fix(assembly): use instance suffixes for duplicate part labels #335
Reference in New Issue
Block a user
Delete Branch "fix/assembly-part-number-suffix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When parts with structured part numbers (e.g.,
P03-0001) are inserted into an assembly multiple times,UniqueNameManager::decomposeName()treats the trailing digits as an auto-generated suffix and increments them (P03-0002,P03-0003), corrupting the part number.Root Cause
AssemblyLink::synchronizeComponents()createsApp::Linkobjects for inserted parts and callsLabel.setValue(obj->Label.getValue()). SinceApp::Linkdoes not overrideallowDuplicateLabel()(returnsfalse),DocumentObject::onEarlyChangetriggersmakeUniqueLabel(), which usesUniqueNameManager::decomposeName()to split the name at trailing digits.For
P03-0001, it sees prefix=P03-, digits=0001, and increments toP03-0002.Fix
Add a
makeInstanceLabel()helper inAssemblyLink.cppthat appends-Ninstance suffixes instead. All instances get a suffix starting at-1, so the original part number is never modified:P03-0001-> labelP03-0001-1P03-0001-2P03-0001-3Applied at all three
Label.setValue()sites insynchronizeComponents()(AssemblyLink, link group, and regular link creation paths).Also adds a
UniqueNameManagertest documenting the trailing-digit decomposition behavior.Files Changed
src/Mod/Assembly/App/AssemblyLink.cpp— addmakeInstanceLabel()helper, update 3 call sitestests/src/Base/UniqueNameManager.cpp— addStructuredPartNumberDecompositiontestCloses #327