forked from 1b-agent/opencadstudio-upstream
Type-as-you-go suggestion popup above the input that filters known command names by substring (so `LEADER` surfaces both LEADER and MLEADER). Up / Down navigates the list, Enter dispatches the highlighted entry, clicking a row dispatches directly. Esc on a non-empty input clears the buffer instead of escalating to command-cancel. The name corpus comes from `inventory::submit!` blocks placed next to each `CadCommand` impl rather than a hand-maintained static list. Adding a new interactive command means dropping one `inventory::submit!` line in its own module file — the autocomplete picks it up at the next compile. 98 submissions seeded across 60 module files; `command::all_registered_command_names()` flattens them at runtime. One-shot dispatch arms in `app/commands.rs` (NEW, OPEN, SAVE, UNDO, …) don't have a `CadCommand` impl and are therefore absent from autocomplete by design. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
62 lines
1.6 KiB
Rust
62 lines
1.6 KiB
Rust
// Point tool — ribbon definition + interactive command.
|
|
//
|
|
// Command: POINT (PO)
|
|
// Single click → commits EntityType::Point. Stays active for more points.
|
|
|
|
use acadrust::types::Vector3;
|
|
use acadrust::{EntityType, Point as CadPoint};
|
|
|
|
use crate::command::{CadCommand, CmdResult};
|
|
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
|
use crate::scene::wire_model::WireModel;
|
|
use glam::Vec3;
|
|
|
|
#[allow(dead_code)]
|
|
pub fn tool() -> ToolDef {
|
|
ToolDef {
|
|
id: "POINT",
|
|
label: "Point",
|
|
icon: IconKind::Svg(include_bytes!("../../../../assets/icons/point.svg")),
|
|
event: ModuleEvent::Command("POINT".to_string()),
|
|
}
|
|
}
|
|
|
|
pub struct PointCommand;
|
|
|
|
impl PointCommand {
|
|
pub fn new() -> Self {
|
|
Self
|
|
}
|
|
}
|
|
|
|
impl CadCommand for PointCommand {
|
|
fn name(&self) -> &'static str {
|
|
"POINT"
|
|
}
|
|
fn prompt(&self) -> String {
|
|
"POINT Specify point [Enter=done]:".into()
|
|
}
|
|
|
|
fn on_point(&mut self, pt: Vec3) -> CmdResult {
|
|
let p = CadPoint {
|
|
location: Vector3::new(pt.x as f64, pt.y as f64, pt.z as f64),
|
|
..Default::default()
|
|
};
|
|
CmdResult::CommitEntity(EntityType::Point(p))
|
|
}
|
|
|
|
fn on_enter(&mut self) -> CmdResult {
|
|
CmdResult::Cancel
|
|
}
|
|
fn on_escape(&mut self) -> CmdResult {
|
|
CmdResult::Cancel
|
|
}
|
|
fn on_mouse_move(&mut self, _pt: Vec3) -> Option<WireModel> {
|
|
None
|
|
}
|
|
}
|
|
|
|
|
|
// ── Autocomplete registry ─────────────────────────────────
|
|
inventory::submit!(crate::command::CommandRegistration { names: &["PO", "POINT"] }); // PointCommand
|