forked from 1b-agent/opencadstudio-upstream
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:
1 parent
1199895f0e
commit
e46701456f
66 files changed
+4538
-141
No files matched your search
@@ -0,0 +1,42 @@
|
||||
// Compile-time plugin registry via `inventory`.
|
||||
|
||||
use super::host::{BuiltinPlugin, HostSession};
|
||||
use crate::app::OpenCADStudio;
|
||||
use crate::modules::{registry as core_registry, CadModule};
|
||||
|
||||
pub struct PluginRegistration {
|
||||
pub construct: fn() -> Box<dyn BuiltinPlugin>,
|
||||
}
|
||||
|
||||
inventory::collect!(PluginRegistration);
|
||||
|
||||
/// Construct every registered built-in plugin (once per process).
|
||||
pub fn all_plugins() -> Vec<Box<dyn BuiltinPlugin>> {
|
||||
inventory::iter::<PluginRegistration>
|
||||
.into_iter()
|
||||
.map(|r| (r.construct)())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Core ribbon tabs plus add-on tabs (sorted by `manifest.ribbon_order`).
|
||||
pub fn all_ribbon_modules() -> Vec<Box<dyn CadModule>> {
|
||||
let mut core = core_registry::all_modules();
|
||||
let mut addons: Vec<(i32, Box<dyn CadModule>)> = all_plugins()
|
||||
.into_iter()
|
||||
.map(|p| (p.manifest().ribbon_order, p.ribbon()))
|
||||
.collect();
|
||||
addons.sort_by_key(|(order, _)| *order);
|
||||
core.extend(addons.into_iter().map(|(_, ribbon)| ribbon));
|
||||
core
|
||||
}
|
||||
|
||||
/// Try each plugin until one handles `cmd`. Returns true if handled.
|
||||
pub(crate) fn try_dispatch(app: &mut OpenCADStudio, tab: usize, cmd: &str) -> bool {
|
||||
let mut host = HostSession::new(app, tab);
|
||||
for plugin in all_plugins() {
|
||||
if plugin.dispatch(&mut host, cmd) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
Reference in new issue
Block a user