forked from 1b-agent/opencadstudio-upstream
Plugins could dispatch commands but not register interactive (click-to- place) tools — the gap mf4633 flagged on #100 for Storm Sewer's SS_INLET / SS_PIPE. Add an InteractiveCommand trait + CommandStep to ocs_plugin_api and HostApi::start_interactive; a host adapter bridges it to the internal CadCommand, so a plugin tool drives the host's point-collection flow. Hybrid by construction: the same command works by clicking in the viewport AND by feeding coordinates over --serve (run "CMD x,y x,y"). Adding a HostApi method changes the contract vtable, so API_VERSION bumps to 2 — v1 plugin binaries are now refused at load. Part of the #100 extensibility epic. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
//! Plugin identity and capability declaration.
|
|
|
|
/// Host plugin API version. Bump when the host runtime surface breaks
|
|
/// compatibility. v2 added `HostApi::start_interactive` (the
|
|
/// `InteractiveCommand` hook) — a vtable change, so v1 binaries are refused.
|
|
pub const API_VERSION: u32 = 2;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub struct ApiVersion {
|
|
pub major: u32,
|
|
}
|
|
|
|
impl ApiVersion {
|
|
pub const CURRENT: Self = Self { major: API_VERSION };
|
|
|
|
pub fn is_compatible_with(host: ApiVersion) -> bool {
|
|
Self::CURRENT.major == host.major
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn current_matches_const() {
|
|
assert_eq!(ApiVersion::CURRENT.major, API_VERSION);
|
|
}
|
|
|
|
#[test]
|
|
fn same_major_is_compatible() {
|
|
assert!(ApiVersion::is_compatible_with(ApiVersion::CURRENT));
|
|
assert!(!ApiVersion::is_compatible_with(ApiVersion {
|
|
major: API_VERSION + 1,
|
|
}));
|
|
}
|
|
}
|
|
|
|
/// Static metadata every plugin supplies at registration time.
|
|
/// Keep fields in sync with `plugin.toml` beside the package.
|
|
#[derive(Clone, Copy, Debug)]
|
|
pub struct PluginManifest {
|
|
pub id: &'static str,
|
|
pub name: &'static str,
|
|
pub version: &'static str,
|
|
pub description: &'static str,
|
|
pub api_version: ApiVersion,
|
|
/// Sort key for add-on ribbon tabs (lower = further left among plugins).
|
|
pub ribbon_order: i32,
|
|
pub xdata_apps: &'static [&'static str],
|
|
pub command_prefixes: &'static [&'static str],
|
|
}
|