Add plugin host architecture and Storm Sewer add-on package

Generic plugin runtime (src/plugin/, HostSession, per-tab plugin_state, command router). QGIS-style add-on layout with plugin.toml and single PluginRegistration. Storm Sewer refactored as reference consumer with dispatch.rs, catchments, LandXML, headless tests (43 passing). Core update.rs decoupled from storm_sewer via CadCommand object-pick hooks. Docs: plugin-architecture.md, plugin-template, PR and issue-78 reply drafts.
This commit is contained in:
Michael Flynn 2026-06-09 13:41:21 -04:00
commit e46701456f
66 changed files with 4538 additions and 141 deletions

View file

@ -0,0 +1,11 @@
# My Plugin (`opencad.my_plugin`)
## Commands
| Command | Description |
|---------|-------------|
| `MP_HELLO` | Example command |
## XDATA
Document entity record layouts here when your plugin tags geometry.

View file

@ -0,0 +1,31 @@
# Add-on plugin template
Copy this folder to `src/modules/<your_module>/` and rename placeholders.
## Quick start
1. Copy files into `src/modules/my_plugin/`.
2. Replace `MY_PLUGIN`, `my_plugin`, `opencad.my_plugin`, `MP_` throughout.
3. Add `pub mod my_plugin;` to `src/modules/mod.rs`.
4. `cargo build` — ribbon tab and commands register automatically.
## Required files
| File | Purpose |
|------|---------|
| `plugin.toml` | Metadata (QGIS-style); excludes dir from `build.rs` ribbon scan |
| `manifest.rs` | Compile-time `PluginManifest` — keep in sync with `plugin.toml` |
| `register.rs` | `inventory::submit!(PluginRegistration { … })` only |
| `plugin.rs` | Thin `BuiltinPlugin` impl |
| `dispatch.rs` | All command handlers |
| `mod.rs` | `CadModule` ribbon + `CommandRegistration` for autocomplete |
| `PLUGIN.md` | XDATA schemas and command reference |
## Optional
| File | Purpose |
|------|---------|
| `state.rs` | Per-document tab state via `host.ensure_plugin_state(PLUGIN_ID, …)` |
| `crates/my_engine/` | Headless domain logic (no iced/acadrust) |
See `docs/plugin-architecture.md` for the full spec.

View file

@ -0,0 +1,14 @@
use crate::plugin::host::HostSession;
use super::manifest::PLUGIN_ID;
pub fn handle(host: &mut HostSession<'_>, cmd: &str) -> bool {
let _ = (host, PLUGIN_ID);
match cmd {
"MP_HELLO" => {
host.push_info("Hello from my_plugin");
true
}
_ => false,
}
}

View file

@ -0,0 +1,14 @@
use crate::plugin::manifest::{ApiVersion, PluginManifest};
pub const PLUGIN_ID: &str = "opencad.my_plugin";
pub static MANIFEST: PluginManifest = PluginManifest {
id: PLUGIN_ID,
name: "My Plugin",
version: "0.1.0",
description: "Short description of what this add-on does",
api_version: ApiVersion::CURRENT,
ribbon_order: 60,
xdata_apps: &["MYPLUGIN_RECORD"],
command_prefixes: &["MP_"],
};

View file

@ -0,0 +1,34 @@
pub mod dispatch;
pub mod manifest;
pub mod plugin;
pub mod register;
use crate::modules::{CadModule, IconKind, ModuleEvent, RibbonGroup, RibbonItem, ToolDef};
inventory::submit!(crate::command::CommandRegistration {
names: &["MP_HELLO"]
});
pub struct MyPluginModule;
impl CadModule for MyPluginModule {
fn id(&self) -> &'static str {
"my_plugin"
}
fn title(&self) -> &'static str {
"My Plugin"
}
fn ribbon_groups(&self) -> Vec<RibbonGroup> {
vec![RibbonGroup {
title: "Tools",
tools: vec![RibbonItem::LargeTool(ToolDef {
id: "MP_HELLO",
label: "Hello",
icon: IconKind::Glyph("★"),
event: ModuleEvent::Command("MP_HELLO".to_string()),
})],
}]
}
}

View file

@ -0,0 +1,21 @@
use crate::plugin::host::{BuiltinPlugin, HostSession};
use crate::plugin::manifest::PluginManifest;
use super::dispatch;
use super::manifest;
pub struct MyPlugin;
impl BuiltinPlugin for MyPlugin {
fn manifest(&self) -> &'static PluginManifest {
&manifest::MANIFEST
}
fn ribbon(&self) -> Box<dyn crate::modules::CadModule> {
Box::new(super::MyPluginModule)
}
fn dispatch(&self, host: &mut HostSession<'_>, cmd: &str) -> bool {
dispatch::handle(host, cmd)
}
}

View file

@ -0,0 +1,13 @@
[plugin]
id = "opencad.my_plugin"
name = "My Plugin"
version = "0.1.0"
description = "Short description of what this add-on does"
author = "Your Name"
license = "GPL-3.0-only"
[opencad]
api_version = 1
ribbon_order = 60
command_prefixes = ["MP_"]
xdata_apps = ["MYPLUGIN_RECORD"]

View file

@ -0,0 +1,7 @@
use super::plugin::MyPlugin;
inventory::submit! {
crate::plugin::registry::PluginRegistration {
construct: || Box::new(MyPlugin),
}
}