forked from 1b-agent/opencadstudio-upstream
OpenCADStudio ships no built-in plugins, so the spec and scaffold no longer describe the in-tree inventory path, demo_plugin, or the fictional Storm Sewer reference. The architecture doc now covers the external cdylib model end to end (ocs_plugin_api contract, export_plugin!, building + publishing per-platform releases, runtime loading, the marketplace + curated registry, the approach-B ABI caveat). The template becomes a standalone cdylib crate (Cargo.toml + src/lib.rs + release workflow) instead of an in-tree module. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
69 lines
1.9 KiB
Rust
69 lines
1.9 KiB
Rust
//! Open CAD Studio add-on template.
|
|
//!
|
|
//! Rename the crate (`Cargo.toml`), the ids/strings below, and `plugin.toml` to
|
|
//! match. Build with `cargo build --release` and ship the resulting cdylib plus
|
|
//! `plugin.toml` as GitHub Release assets (see `.github/workflows/release.yml`).
|
|
|
|
use ocs_plugin_api::host::{BuiltinPlugin, HostApi};
|
|
use ocs_plugin_api::manifest::{ApiVersion, PluginManifest};
|
|
use ocs_plugin_api::ribbon::{CadModule, IconKind, ModuleEvent, RibbonGroup, RibbonItem, ToolDef};
|
|
|
|
// Keep these fields in sync with `plugin.toml`.
|
|
static MANIFEST: PluginManifest = PluginManifest {
|
|
id: "opencad.my_plugin",
|
|
name: "My Plugin",
|
|
version: "0.1.0",
|
|
description: "What this plugin does.",
|
|
api_version: ApiVersion::CURRENT,
|
|
ribbon_order: 50,
|
|
xdata_apps: &[],
|
|
command_prefixes: &["MP_"],
|
|
};
|
|
|
|
/// The ribbon tab.
|
|
struct MyModule;
|
|
|
|
impl CadModule for MyModule {
|
|
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()),
|
|
})],
|
|
}]
|
|
}
|
|
}
|
|
|
|
/// The plugin entry point.
|
|
struct MyPlugin;
|
|
|
|
impl BuiltinPlugin for MyPlugin {
|
|
fn manifest(&self) -> &'static PluginManifest {
|
|
&MANIFEST
|
|
}
|
|
fn ribbon(&self) -> Box<dyn CadModule> {
|
|
Box::new(MyModule)
|
|
}
|
|
fn dispatch(&self, host: &mut dyn HostApi, cmd: &str) -> bool {
|
|
match cmd {
|
|
"MP_HELLO" => {
|
|
host.push_info("Hello from My Plugin");
|
|
true
|
|
}
|
|
_ => false,
|
|
}
|
|
}
|
|
}
|
|
|
|
// Emit the C-ABI symbols the host loader looks for.
|
|
ocs_plugin_api::export_plugin!(MyPlugin);
|