fix(assembly): use instance suffixes for duplicate part labels #335

Merged
forbes merged 1 commits from fix/assembly-part-number-suffix into main 2026-02-26 16:34:36 +00:00
Owner

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() creates App::Link objects for inserted parts and calls Label.setValue(obj->Label.getValue()). Since App::Link does not override allowDuplicateLabel() (returns false), DocumentObject::onEarlyChange triggers makeUniqueLabel(), which uses UniqueNameManager::decomposeName() to split the name at trailing digits.

For P03-0001, it sees prefix=P03-, digits=0001, and increments to P03-0002.

Fix

Add a makeInstanceLabel() helper in AssemblyLink.cpp that appends -N instance suffixes instead. All instances get a suffix starting at -1, so the original part number is never modified:

  • Insert P03-0001 -> label P03-0001-1
  • Insert again -> label P03-0001-2
  • Insert again -> label P03-0001-3

Applied at all three Label.setValue() sites in synchronizeComponents() (AssemblyLink, link group, and regular link creation paths).

Also adds a UniqueNameManager test documenting the trailing-digit decomposition behavior.

Files Changed

  • src/Mod/Assembly/App/AssemblyLink.cpp — add makeInstanceLabel() helper, update 3 call sites
  • tests/src/Base/UniqueNameManager.cpp — add StructuredPartNumberDecomposition test

Closes #327

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()` creates `App::Link` objects for inserted parts and calls `Label.setValue(obj->Label.getValue())`. Since `App::Link` does not override `allowDuplicateLabel()` (returns `false`), `DocumentObject::onEarlyChange` triggers `makeUniqueLabel()`, which uses `UniqueNameManager::decomposeName()` to split the name at trailing digits. For `P03-0001`, it sees prefix=`P03-`, digits=`0001`, and increments to `P03-0002`. ## Fix Add a `makeInstanceLabel()` helper in `AssemblyLink.cpp` that appends `-N` instance suffixes instead. All instances get a suffix starting at `-1`, so the original part number is never modified: - Insert `P03-0001` -> label `P03-0001-1` - Insert again -> label `P03-0001-2` - Insert again -> label `P03-0001-3` Applied at all three `Label.setValue()` sites in `synchronizeComponents()` (AssemblyLink, link group, and regular link creation paths). Also adds a `UniqueNameManager` test documenting the trailing-digit decomposition behavior. ## Files Changed - `src/Mod/Assembly/App/AssemblyLink.cpp` — add `makeInstanceLabel()` helper, update 3 call sites - `tests/src/Base/UniqueNameManager.cpp` — add `StructuredPartNumberDecomposition` test Closes #327
forbes added 1 commit 2026-02-26 15:00:36 +00:00
fix(assembly): use instance suffixes for duplicate part labels
All checks were successful
Build and Test / build (pull_request) Successful in 29m11s
7c85b2ad93
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.

Add a makeInstanceLabel() helper in AssemblyLink.cpp that appends -N
instance suffixes instead (P03-0001-1, P03-0001-2). All instances get
a suffix starting at -1 so the original part number is never modified.

Applied at all three Label.setValue() sites in
synchronizeComponents() (AssemblyLink, link group, and regular link
creation paths).

Also add a UniqueNameManager test documenting the trailing-digit
decomposition behavior for structured part numbers.

Closes #327
forbes merged commit 69ccdbf742 into main 2026-02-26 16:34:36 +00:00
forbes deleted branch fix/assembly-part-number-suffix 2026-02-26 16:34:36 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/create#335