Sweep spatial profiles as surfaces, keep swept surfaces linked to expressions

A closed 3D polyline profile that does not lie in one plane sweeps a
surface with the reference's refusals. Swept surfaces made with an
Expression scale or twist follow the named parameters, and reference
surfaces linked through their associative action are picked up on open.
Saving keeps the associative actions the constraint graph does not
rebuild and stores each scope network through its own dictionary.
Kernel 23138fc, codec 64fe2a6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ramox81andClaude Opus 5.5 committed 2026-10-07 16:47:30 +03:00
1 parent 0c3ca96822
commit 07499968d8
11 files changed
+444 -24

No files matched your search

+189 -16
View File
@@ -1250,7 +1250,7 @@ impl Allocator<'_> {
has_cached_value: false,
cached_value: String::new(),
flag: false,
reserved: 0,
dependencies: Vec::new(),
}),
);
self.variables.insert(name.to_string(), handle);
@@ -2463,9 +2463,31 @@ fn sync_retained_group_constraints(document: &mut CadDocument, set: &ParametricC
fn detach_preserved_scope(
document: &mut CadDocument,
owner: Handle,
) -> (FxHashMap<String, Handle>, Vec<Handle>) {
) -> (FxHashMap<String, Handle>, Vec<Handle>, Vec<Handle>) {
let Some(network_handle) = native_scope_network_handle(document, owner) else {
return (FxHashMap::default(), Vec::new());
return (FxHashMap::default(), Vec::new(), Vec::new());
};
// Actions the constraint graph does not rebuild (a swept surface's
// action and the unnamed variables holding its expressions) stay in the
// network with everything they own.
let foreign_actions: Vec<Handle> = match document.objects.get(&network_handle) {
Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::Network(network),
..
})) => network
.actions
.iter()
.map(|action| action.dependency)
.filter(|handle| match document.objects.get(handle) {
Some(ObjectType::Associative(object)) => match &object.data {
AssociativeData::ConstraintGroup(_) | AssociativeData::Network(_) => false,
AssociativeData::Variable(variable) => variable.name.trim().is_empty(),
_ => true,
},
_ => false,
})
.collect(),
_ => Vec::new(),
};
let preserved_groups: Vec<_> = native_group_handles(document, owner)
.into_iter()
@@ -2479,11 +2501,33 @@ fn detach_preserved_scope(
)
})
.collect();
if preserved_groups.is_empty() {
return (FxHashMap::default(), Vec::new());
if preserved_groups.is_empty() && foreign_actions.is_empty() {
return (FxHashMap::default(), Vec::new(), Vec::new());
}
let mut variable_handles = Vec::new();
// The named variables the kept actions read keep their handles.
for (_, object) in &document.objects {
let ObjectType::Associative(AssociativeObject {
owner,
data: AssociativeData::ValueDependency(value),
..
}) = object
else {
continue;
};
let handle = value.dependency.dependent_on;
let named = matches!(
document.objects.get(&handle),
Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::Variable(variable),
..
})) if !variable.name.trim().is_empty()
);
if named && foreign_actions.contains(owner) && !variable_handles.contains(&handle) {
variable_handles.push(handle);
}
}
for group_handle in &preserved_groups {
let Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::ConstraintGroup(group),
@@ -2510,7 +2554,7 @@ fn detach_preserved_scope(
let dictionary = document
.extension_dictionary_handle(owner)
.unwrap_or(Handle::NULL);
for handle in &preserved_groups {
for handle in preserved_groups.iter().chain(&foreign_actions) {
if let Some(ObjectType::Associative(object)) = document.objects.get_mut(handle) {
object.owner = dictionary;
}
@@ -2527,7 +2571,100 @@ fn detach_preserved_scope(
}
debug_assert!(document.objects.contains_key(&network_handle));
(variables, preserved_groups)
(variables, preserved_groups, foreign_actions)
}
/// Re-evaluates the unnamed variables of kept actions (a swept surface's
/// scale or twist expression) and the values their actions cache, so the
/// file carries the values the named parameters give.
fn refresh_foreign_values(
document: &mut CadDocument,
foreign_actions: &[Handle],
parameters: &ParameterTable,
) {
let value_of = |document: &CadDocument, handle: Handle| match document.objects.get(&handle) {
Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::Variable(variable),
..
})) => {
let mut table = parameters.clone();
table.set("foreignExpression", &variable.expression).ok()?;
table.resolve("foreignExpression").ok().filter(|value| value.is_finite())
}
_ => None,
};
let dependencies: Vec<(Handle, Handle)> = document
.objects
.iter()
.filter_map(|(handle, object)| match object {
ObjectType::Associative(AssociativeObject {
owner,
data: AssociativeData::ValueDependency(value),
..
}) if foreign_actions.contains(owner) => Some((*handle, value.dependency.dependent_on)),
_ => None,
})
.collect();
for &handle in foreign_actions {
if let Some(value) = value_of(document, handle) {
if let Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::Variable(variable),
..
})) = document.objects.get_mut(&handle)
{
variable.value = Allocator::numeric_eval(value);
}
}
}
for (dependency, source) in dependencies {
let Some(value) = value_of(document, source) else { continue };
if let Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::ValueDependency(dependency),
..
})) = document.objects.get_mut(&dependency)
{
dependency.value = Allocator::numeric_eval(value);
}
}
for &handle in foreign_actions {
let Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::Action(action),
..
})) = document.objects.get(&handle)
else {
continue;
};
let mut updates = Vec::new();
for (index, param) in action.values.iter().enumerate() {
for (slot, variable) in param.variables.iter().enumerate() {
let Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::ValueDependency(dependency),
..
})) = document.objects.get(&variable.handle)
else {
continue;
};
let Some(value) = value_of(document, dependency.dependency.dependent_on) else {
continue;
};
// Angle parameters are cached in radians.
let value = if param.unit_type == 2 { value.to_radians() } else { value };
updates.push((index, slot, value));
}
}
if let Some(ObjectType::Associative(AssociativeObject {
data: AssociativeData::Action(action),
..
})) = document.objects.get_mut(&handle)
{
for (index, slot, value) in updates {
action.values[index].variables[slot].value = AssocEvalVariant {
code: 40,
value: AssocEvalValue::Real(value),
};
}
}
}
}
/// Materializes one scope into the drawing's associative object graph.
@@ -2540,6 +2677,7 @@ fn materialize_scope(
action_index: i32,
existing_variables: FxHashMap<String, Handle>,
preserved_groups: Vec<Handle>,
foreign_actions: Vec<Handle>,
materialize_all_parameters: bool,
) -> Option<Handle> {
let dictionary_handle = ensure_extension_dictionary(document, owner);
@@ -2575,6 +2713,7 @@ fn materialize_scope(
&& parameters.is_empty()
&& existing_variables.is_empty()
&& preserved_groups.is_empty()
&& foreign_actions.is_empty()
{
return None;
}
@@ -2741,6 +2880,25 @@ fn materialize_scope(
}
}
let first_foreign = allocator.variable_actions.len() as i32
+ i32::from(group_handle.is_some())
+ preserved_groups.len() as i32;
for (offset, handle) in foreign_actions.iter().copied().enumerate() {
if let Some(ObjectType::Associative(object)) = allocator.document.objects.get_mut(&handle) {
object.owner = network_handle;
let action = match &mut object.data {
AssociativeData::Action(action) => Some(action),
AssociativeData::Variable(variable) => Some(&mut variable.action),
_ => None,
};
if let Some(action) = action {
action.owning_network = network_handle;
action.action_index = first_foreign + offset as i32 + 1;
}
}
}
refresh_foreign_values(allocator.document, &foreign_actions, parameters);
let network = AssocNetwork {
action: AssocAction {
class_version: 2,
@@ -2749,15 +2907,14 @@ fn materialize_scope(
..Default::default()
},
network_version: 0,
network_action_index: allocator.variable_actions.len() as i32
+ i32::from(group_handle.is_some())
+ preserved_groups.len() as i32,
network_action_index: first_foreign + foreign_actions.len() as i32,
actions: allocator
.variable_actions
.iter()
.copied()
.chain(group_handle)
.chain(preserved_groups)
.chain(foreign_actions)
.map(|dependency| AssocActionDependency {
is_owned: true,
dependency,
@@ -2765,9 +2922,23 @@ fn materialize_scope(
.collect(),
owned_actions: Vec::new(),
};
// The reference holds a scope's network through a dictionary of its own
// under the owner's extension dictionary; its parameter commands do not
// find a network stored directly there.
let holder_handle = allocator.document.allocate_handle();
let mut holder = codec::objects::Dictionary::new();
holder.handle = holder_handle;
holder.owner = dictionary_handle;
holder.duplicate_cloning = 1;
holder.reactors.push(dictionary_handle);
holder.add_entry(NETWORK_DICTIONARY_KEY, network_handle);
allocator
.document
.objects
.insert(holder_handle, ObjectType::Dictionary(holder));
allocator.insert_associative_at(
network_handle,
dictionary_handle,
holder_handle,
"ASSOCNETWORK",
"AcDbAssocNetwork",
AssociativeData::Network(network),
@@ -2775,14 +2946,14 @@ fn materialize_scope(
if let Some(ObjectType::Associative(network)) =
allocator.document.objects.get_mut(&network_handle)
{
network.reactors.push(dictionary_handle);
network.reactors.push(holder_handle);
}
set_dictionary_entry(
allocator.document,
dictionary_handle,
NETWORK_DICTIONARY_KEY,
network_handle,
holder_handle,
);
Some(network_handle)
}
@@ -2845,6 +3016,7 @@ impl Scene {
// `enabled` / `axis_direction` / `distance_direction` / `angle_sector`
// writes, which happen on the local set during decode.
self.bump_constraints_epoch();
self.import_sweep_expression_links();
}
/// Makes the standard associative graph match the live command model.
@@ -2890,7 +3062,7 @@ impl Scene {
if let Some(set) = &set {
sync_retained_group_constraints(&mut self.document, set);
}
let (variables, groups) = detach_preserved_scope(&mut self.document, owner);
let (variables, groups, foreign) = detach_preserved_scope(&mut self.document, owner);
let mut set = set.unwrap_or_else(|| {
if owner == model_owner {
ParametricConstraintSet::new(ParametricScope::ModelSpace)
@@ -2906,7 +3078,7 @@ impl Scene {
for constraint in &mut set.constraints {
constraint.native_origin = None;
}
scopes.push((owner, set, variables, groups));
scopes.push((owner, set, variables, groups, foreign));
}
if scopes.is_empty() {
return;
@@ -2921,7 +3093,7 @@ impl Scene {
);
let root_network_handle = self.document.allocate_handle();
let mut child_networks = Vec::new();
for (index, (owner, set, variables, groups)) in scopes.into_iter().enumerate() {
for (index, (owner, set, variables, groups, foreign)) in scopes.into_iter().enumerate() {
let parameters = if set.local_parameters.is_empty() {
&self.named_parameters
} else {
@@ -2936,6 +3108,7 @@ impl Scene {
index as i32 + 1,
variables,
groups,
foreign,
owner == model_owner,
) {
child_networks.push(handle);