feat(plugin): InteractiveCommand hook for click-to-place (API v2)
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>
This commit is contained in:
parent
8d3d0c30cc
commit
931eb908a9
5 changed files with 141 additions and 4 deletions
|
|
@ -203,7 +203,7 @@ version = "0.1.0"
|
|||
description = "…"
|
||||
|
||||
[opencad]
|
||||
api_version = 1
|
||||
api_version = 2
|
||||
ribbon_order = 50
|
||||
command_prefixes = ["EX_"]
|
||||
xdata_apps = []
|
||||
|
|
@ -225,6 +225,24 @@ tool fires `ModuleEvent::Command("EX_FOO")`, which round-trips to
|
|||
tool request a native file picker; on selection the host dispatches
|
||||
`"<command> <path>"` back with the path's original case preserved.
|
||||
|
||||
### Interactive (click-to-place) commands
|
||||
|
||||
For tools that collect points — placing a structure, drawing a pipe — call
|
||||
`host.start_interactive(Box::new(my_cmd))` from `dispatch`, where `my_cmd`
|
||||
implements `ocs_plugin_api::host::InteractiveCommand`:
|
||||
|
||||
```rust
|
||||
fn on_point(&mut self, pt: [f64; 3]) -> CommandStep {
|
||||
// … return NeedPoint, Commit(entity), CommitAndEnd(entity), Done, or Cancel
|
||||
}
|
||||
```
|
||||
|
||||
The host drives it through its normal point-collection flow, so the **same**
|
||||
command works by clicking in the viewport and by feeding coordinates over the
|
||||
`--serve` automation API (`run "MY_CMD 0,0 10,10"`). This is what bumped the
|
||||
API to **v2** — the added `HostApi` method changes the contract's vtable, so v1
|
||||
binaries are refused at load.
|
||||
|
||||
### XDATA — domain persistence
|
||||
|
||||
Store domain data on entities as XDATA (under your `xdata_apps` ids), not in a
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ author = "Your Name"
|
|||
license = "GPL-3.0-only"
|
||||
|
||||
[opencad]
|
||||
api_version = 1
|
||||
api_version = 2
|
||||
ribbon_order = 60
|
||||
command_prefixes = ["MP_"]
|
||||
xdata_apps = ["MYPLUGIN_RECORD"]
|
||||
Loading…
Reference in a new issue