Files
OneCAD-Draft/plugins/opencad-python/src/patch_helpers.rs.inc
T
Felix RiestraandClaude Sonnet 5 b3f5388208 Complete MultiLeader host model coverage
Extends the adapter generator (Color, LineWeight, mixed unit/payload enums,
fixed float arrays, bitflags-2 newtypes, keep_types override) and maps
MultiLeader with a merge-style context patch, host validation and
reference checks. staged_python_multileader_lifecycle_over_real_ipc passes
the full gate including DWG and DXF reopen.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-20 14:27:43 +02:00

24 lines
1.1 KiB
C++

// Merge helpers for nested structs that scripts edit as a partial patch.
/// Apply `patch` (a dict of context fields) onto `existing`, so a script can
/// change one context field without resetting the rest. Unknown keys error.
fn merge_multileader_context(
existing: &acadrust::entities::MultiLeaderAnnotContext,
patch: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<acadrust::entities::MultiLeaderAnnotContext> {
let patch = patch.try_into_value::<rustpython_vm::builtins::PyDictRef>(vm)?;
let merged = multi_leader_annot_context_to_dict(vm, existing)?
.try_into_value::<rustpython_vm::builtins::PyDictRef>(vm)?;
for key in patch.keys_vec() {
let name = key.clone().try_into_value::<String>(vm)?;
if merged.get_item_opt(name.as_str(), vm)?.is_none() {
return Err(vm.new_value_error(format!(
"ocs: MultiLeader.context property {name:?} is outside the editable schema"
)));
}
merged.set_item(name.as_str(), patch.get_item(name.as_str(), vm)?, vm)?;
}
dict_to_multi_leader_annot_context(merged.into(), vm)
}