forked from 1b-agent/opencadstudio-upstream
Two behaviour changes that bring the command line in line with established CAD workflow: 1. **Always-on keyboard capture.** The input was blurred whenever no command was running, so typed letters went nowhere until the user clicked into the field. Replace the blur with a re-focus on every command lifecycle transition (cmd_result.rs) and on viewport / tab / ribbon clicks (update.rs), focus the input at startup, and add a global key subscription that catches any unhandled character key or backspace and routes it into the buffer via two new messages (CommandAppendChar / CommandBackspace) — so the command line keeps accumulating keystrokes even if focus parks somewhere not focusable. Removes the unused blur_cmd_input helper. 2. **Space submits.** Typing a space at the end of the input now submits the buffer the same way Enter does. Only exception: an active command that's currently collecting free-form prose (TEXT / MTEXT / DDEDIT body, ATTDEF prompt / default value, INSERT attribute value, ATTEDIT cell). Those advertise the new `CadCommand::wants_text_with_spaces()` flag so the Space character reaches the buffer as a literal. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
95 lines
3.0 KiB
Rust
95 lines
3.0 KiB
Rust
// MVIEW — interactive paper-space viewport creation.
|
|
//
|
|
// Two clicks define opposite corners of a new viewport rectangle.
|
|
// The created Viewport entity is routed to add_entity_to_layout by apply_cmd_result
|
|
// because we're in paper space.
|
|
|
|
use acadrust::entities::Viewport;
|
|
use acadrust::types::Vector3;
|
|
use acadrust::EntityType;
|
|
|
|
use crate::command::{CadCommand, CmdResult};
|
|
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
|
use crate::scene::wire_model::WireModel;
|
|
use glam::Vec3;
|
|
|
|
// ── Ribbon definition ─────────────────────────────────────────────────────
|
|
|
|
pub fn tool() -> ToolDef {
|
|
ToolDef {
|
|
id: "MVIEW",
|
|
label: "Viewport",
|
|
icon: IconKind::Glyph("⬜"),
|
|
event: ModuleEvent::Command("MVIEW".to_string()),
|
|
}
|
|
}
|
|
|
|
// ── Command ───────────────────────────────────────────────────────────────
|
|
|
|
pub struct MviewCommand {
|
|
corner1: Option<Vec3>,
|
|
}
|
|
|
|
impl MviewCommand {
|
|
pub fn new() -> Self { Self { corner1: None } }
|
|
}
|
|
|
|
impl CadCommand for MviewCommand {
|
|
fn name(&self) -> &'static str { "MVIEW" }
|
|
|
|
fn prompt(&self) -> String {
|
|
if self.corner1.is_none() {
|
|
"MVIEW Specify first corner:".to_string()
|
|
} else {
|
|
"MVIEW Specify opposite corner:".to_string()
|
|
}
|
|
}
|
|
|
|
fn on_point(&mut self, pt: Vec3) -> CmdResult {
|
|
if let Some(c1) = self.corner1 {
|
|
let w = (pt.x - c1.x).abs() as f64;
|
|
let h = (pt.z - c1.z).abs() as f64;
|
|
if w < 1.0 || h < 1.0 {
|
|
return CmdResult::Cancel;
|
|
}
|
|
let cx = ((c1.x + pt.x) / 2.0) as f64;
|
|
let cy = c1.y as f64;
|
|
let cz = ((c1.z + pt.z) / 2.0) as f64;
|
|
|
|
let mut vp = Viewport::new();
|
|
vp.center = Vector3::new(cx, cy, cz);
|
|
vp.width = w;
|
|
vp.height = h;
|
|
vp.id = 2; // user viewport (id > 1)
|
|
|
|
CmdResult::CommitAndExit(EntityType::Viewport(vp))
|
|
} else {
|
|
self.corner1 = Some(pt);
|
|
CmdResult::NeedPoint
|
|
}
|
|
}
|
|
|
|
fn on_enter(&mut self) -> CmdResult { CmdResult::Cancel }
|
|
|
|
fn on_mouse_move(&mut self, pt: Vec3) -> Option<WireModel> {
|
|
let c1 = self.corner1?;
|
|
Some(WireModel {
|
|
name: "mview_preview".to_string(),
|
|
points: vec![
|
|
[c1.x, c1.y, c1.z],
|
|
[pt.x, c1.y, c1.z],
|
|
[pt.x, pt.y, c1.z],
|
|
[c1.x, pt.y, c1.z],
|
|
[c1.x, c1.y, c1.z],
|
|
],
|
|
color: WireModel::CYAN,
|
|
selected: false,
|
|
pattern_length: 0.0,
|
|
pattern: [0.0; 8],
|
|
line_weight_px: 1.0,
|
|
snap_pts: vec![],
|
|
tangent_geoms: vec![],
|
|
})
|
|
}
|
|
}
|