fix(copy): a copy reacts only to what was copied with it

COPY and PASTE kept the source's reactors on each copy, so a copied
dimension still pointed at the source's dimension association (and
boundary or group members at the source hatch or group). Another
application reports such a drawing as damaged and, after recovery,
moves the dimensions. A copy's reactors now follow only targets copied
with it; group copies give their members the new group's reactor; and a
drawing opened with such stray dimension reactors has them dropped.

Fixes #1645
Fixes #1649

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 5.5 committed 2026-10-08 08:34:49 +03:00
1 parent e2f558ae4f
commit 9adb6f59c8
6 files changed
+80

No files matched your search

+47
View File
@@ -2434,3 +2434,50 @@ fn persisted_measurement_scale(
viewport_compensation: calculated,
})
}
/// Drop reactors an entity holds on a dimension association it has no part
/// in: neither the association's dimension nor geometry it references. Copies
/// made by earlier releases kept their source's association this way, which
/// the reference application reports as a damaged drawing. Returns how many
/// reactors were dropped.
pub(crate) fn drop_stray_dimension_reactors(document: &mut codec::CadDocument) -> usize {
let associations: rustc_hash::FxHashMap<Handle, (Handle, Vec<Handle>)> = document
.objects
.iter()
.filter_map(|(handle, object)| {
let ObjectType::Associative(object) = object else {
return None;
};
let AssociativeData::DimensionAssociation(association) = &object.data else {
return None;
};
let geometry = association
.references
.iter()
.flatten()
.flat_map(|reference| {
reference.xrefs.iter().chain(&reference.intersection_objects).copied()
})
.collect();
Some((*handle, (association.dimension, geometry)))
})
.collect();
if associations.is_empty() {
return 0;
}
let mut dropped = 0;
let handles: Vec<Handle> = document.entities().map(|entity| entity.common().handle).collect();
for handle in handles {
let Some(entity) = document.get_entity_mut(handle) else {
continue;
};
let reactors = &mut entity.common_mut().reactors;
let before = reactors.len();
reactors.retain(|reactor| match associations.get(reactor) {
Some((dimension, geometry)) => *dimension == handle || geometry.contains(&handle),
None => true,
});
dropped += before - reactors.len();
}
dropped
}