From d218ec1451d1fac3f980a8fadd41ec097cdabe23 Mon Sep 17 00:00:00 2001 From: yztink Date: Wed, 23 Sep 2026 15:19:33 -0700 Subject: [PATCH] feat(plugin): add CommitMany and CommitManyAndEnd for multi-entity interactive commands --- crates/ocs_plugin_api/src/host.rs | 4 ++++ crates/ocs_plugin_api/src/runner.rs | 2 ++ src/app/plugin_host.rs | 23 ++++++++++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/crates/ocs_plugin_api/src/host.rs b/crates/ocs_plugin_api/src/host.rs index 59a4026ce..88a764ac2 100644 --- a/crates/ocs_plugin_api/src/host.rs +++ b/crates/ocs_plugin_api/src/host.rs @@ -645,8 +645,12 @@ pub enum CommandStep { NeedPoint, /// Commit an entity to the document and keep collecting points. Commit(EntityType), + /// Commit multiple entities to the document and keep collecting points. + CommitMany(Vec), /// Commit an entity and end the command. CommitAndEnd(EntityType), + /// Commit multiple entities to the document and end the command. + CommitManyAndEnd(Vec), /// End the command without committing. Done, /// Cancel the command. diff --git a/crates/ocs_plugin_api/src/runner.rs b/crates/ocs_plugin_api/src/runner.rs index ddf1758cb..237ddc982 100644 --- a/crates/ocs_plugin_api/src/runner.rs +++ b/crates/ocs_plugin_api/src/runner.rs @@ -197,6 +197,7 @@ fn handle_host_request( CommandStep::Done | CommandStep::Cancel | CommandStep::CommitAndEnd(_) + | CommandStep::CommitManyAndEnd(_) ); (Ok(s), is_done) } @@ -335,6 +336,7 @@ fn handle_host_request_v4( CommandStep::Done | CommandStep::Cancel | CommandStep::CommitAndEnd(_) + | CommandStep::CommitManyAndEnd(_) ); (Ok(s), is_done) } diff --git a/src/app/plugin_host.rs b/src/app/plugin_host.rs index 198d68679..1bba6f6d7 100644 --- a/src/app/plugin_host.rs +++ b/src/app/plugin_host.rs @@ -2797,7 +2797,12 @@ impl crate::command::CadCommand for PluginProcessInteractiveAdapter { .interactive_event(self.command_id, InteractiveEvent::Point([pt.x, pt.y, pt.z])) .map(plugin_step_to_result) .unwrap_or(crate::command::CmdResult::Cancel); - if matches!(result, crate::command::CmdResult::CommitAndExit(_) | crate::command::CmdResult::Cancel) { + if matches!( + result, + crate::command::CmdResult::CommitAndExit(_) + | crate::command::CmdResult::CommitEntitiesAndExit(_) + | crate::command::CmdResult::Cancel + ) { self.is_done = true; } self.refresh(); @@ -2810,7 +2815,12 @@ impl crate::command::CadCommand for PluginProcessInteractiveAdapter { .interactive_event(self.command_id, InteractiveEvent::Enter) .map(plugin_step_to_result) .unwrap_or(crate::command::CmdResult::Cancel); - if matches!(result, crate::command::CmdResult::CommitAndExit(_) | crate::command::CmdResult::Cancel) { + if matches!( + result, + crate::command::CmdResult::CommitAndExit(_) + | crate::command::CmdResult::CommitEntitiesAndExit(_) + | crate::command::CmdResult::Cancel + ) { self.is_done = true; } self.refresh(); @@ -2836,7 +2846,12 @@ impl crate::command::CadCommand for PluginProcessInteractiveAdapter { ) .map(plugin_step_to_result) .unwrap_or(crate::command::CmdResult::Cancel); - if matches!(result, crate::command::CmdResult::CommitAndExit(_) | crate::command::CmdResult::Cancel) { + if matches!( + result, + crate::command::CmdResult::CommitAndExit(_) + | crate::command::CmdResult::CommitEntitiesAndExit(_) + | crate::command::CmdResult::Cancel + ) { self.is_done = true; } self.refresh(); @@ -2870,7 +2885,9 @@ fn plugin_step_to_result(step: ocs_plugin_api::host::CommandStep) -> crate::comm match step { CommandStep::NeedPoint => CmdResult::NeedPoint, CommandStep::Commit(e) => CmdResult::CommitEntity(e), + CommandStep::CommitMany(es) => CmdResult::CommitEntities(es), CommandStep::CommitAndEnd(e) => CmdResult::CommitAndExit(e), + CommandStep::CommitManyAndEnd(es) => CmdResult::CommitEntitiesAndExit(es), CommandStep::Done | CommandStep::Cancel => CmdResult::Cancel, } }