forked from 1b-agent/opencadstudio-upstream
Whole command/snap/grip/cursor chain now builds on f64 DVec3 end to end,
so picked points, snaps and grip drags stay precise at UTM-scale
coordinates instead of quantizing to ~0.5 m through f32.
- All ~80 command files migrated: draw (line/circle/arc/ellipse/shapes
in full f64; others via point methods), modify, annotate, insert, view,
inquiry, layers, groups, clipboard, layout.
- Entity apply_grip impls updated for GripApply::{Absolute,Translate}(DVec3).
- Construction sites (EntityTransform/CmdResult/DynAnchor) emit DVec3;
wire-preview boundaries cast to f32 only at the GPU edge.
- Modify/annotate commands keep internal Vec3 geometry where precision is
non-critical, casting at the DVec3 boundary; key draw commands store f64.
Builds clean (no warnings). Visual verification of crosshair/snap/grip at
extreme UTM zoom pending.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
145 lines
4.1 KiB
Rust
145 lines
4.1 KiB
Rust
// PEDIT command — edit a polyline entity.
|
|
//
|
|
// Supports LwPolyline and (partially) Polyline2D.
|
|
// Subcommands (text input after entity pick):
|
|
// C / CLOSE — toggle closed flag
|
|
// O / OPEN — clear closed flag
|
|
// W <width> — set uniform width (LwPolyline)
|
|
// E — enter vertex editing mode (not implemented, use grips)
|
|
// J — join (same as JOIN command, triggered as alias)
|
|
// X / EXIT — exit
|
|
|
|
use acadrust::{EntityType, Handle};
|
|
use glam::DVec3;
|
|
|
|
use crate::command::{CadCommand, CmdResult};
|
|
|
|
pub struct PeditCommand {
|
|
target: Option<Handle>,
|
|
}
|
|
|
|
impl PeditCommand {
|
|
pub fn new() -> Self {
|
|
Self { target: None }
|
|
}
|
|
}
|
|
|
|
impl CadCommand for PeditCommand {
|
|
fn name(&self) -> &'static str {
|
|
"PEDIT"
|
|
}
|
|
|
|
fn prompt(&self) -> String {
|
|
if self.target.is_none() {
|
|
"PEDIT Select polyline:".into()
|
|
} else {
|
|
"PEDIT Enter option [C=Close O=Open W=Width X=Exit]:".into()
|
|
}
|
|
}
|
|
|
|
fn needs_entity_pick(&self) -> bool {
|
|
self.target.is_none()
|
|
}
|
|
|
|
fn on_entity_pick(&mut self, handle: Handle, _pt: DVec3) -> CmdResult {
|
|
if handle.is_null() {
|
|
return CmdResult::NeedPoint;
|
|
}
|
|
self.target = Some(handle);
|
|
CmdResult::NeedPoint
|
|
}
|
|
|
|
fn wants_text_input(&self) -> bool {
|
|
self.target.is_some()
|
|
}
|
|
|
|
fn on_text_input(&mut self, text: &str) -> Option<CmdResult> {
|
|
let handle = self.target?;
|
|
let up = text.trim().to_uppercase();
|
|
|
|
match up.as_str() {
|
|
"X" | "EXIT" => return Some(CmdResult::Cancel),
|
|
"C" | "CLOSE" => {
|
|
return Some(CmdResult::PeditOp {
|
|
handle,
|
|
op: PeditOp::SetClosed(true),
|
|
})
|
|
}
|
|
"O" | "OPEN" => {
|
|
return Some(CmdResult::PeditOp {
|
|
handle,
|
|
op: PeditOp::SetClosed(false),
|
|
})
|
|
}
|
|
_ => {}
|
|
}
|
|
|
|
if let Some(rest) = up.strip_prefix("W ").or_else(|| up.strip_prefix("W")) {
|
|
let w: f64 = rest
|
|
.trim()
|
|
.replace(',', ".")
|
|
.parse()
|
|
.ok()
|
|
.filter(|&v: &f64| v >= 0.0)?;
|
|
return Some(CmdResult::PeditOp {
|
|
handle,
|
|
op: PeditOp::SetWidth(w),
|
|
});
|
|
}
|
|
|
|
None
|
|
}
|
|
|
|
fn on_point(&mut self, _pt: DVec3) -> CmdResult {
|
|
CmdResult::NeedPoint
|
|
}
|
|
fn on_enter(&mut self) -> CmdResult {
|
|
CmdResult::Cancel
|
|
}
|
|
}
|
|
|
|
// ── Op enum (used in CmdResult) ────────────────────────────────────────────
|
|
|
|
#[derive(Clone)]
|
|
pub enum PeditOp {
|
|
SetClosed(bool),
|
|
SetWidth(f64),
|
|
}
|
|
|
|
// ── Apply logic ────────────────────────────────────────────────────────────
|
|
|
|
pub fn apply_pedit(entity: &mut EntityType, op: &PeditOp) -> bool {
|
|
match op {
|
|
PeditOp::SetClosed(closed) => match entity {
|
|
EntityType::LwPolyline(p) => {
|
|
p.is_closed = *closed;
|
|
true
|
|
}
|
|
EntityType::Polyline2D(p) => {
|
|
if *closed {
|
|
p.close();
|
|
} else {
|
|
p.flags.set_closed(false);
|
|
}
|
|
true
|
|
}
|
|
_ => false,
|
|
},
|
|
PeditOp::SetWidth(w) => match entity {
|
|
EntityType::LwPolyline(p) => {
|
|
p.constant_width = *w;
|
|
for v in &mut p.vertices {
|
|
v.start_width = *w;
|
|
v.end_width = *w;
|
|
}
|
|
true
|
|
}
|
|
_ => false,
|
|
},
|
|
}
|
|
}
|
|
|
|
|
|
// ── Autocomplete registry ─────────────────────────────────
|
|
inventory::submit!(crate::command::CommandRegistration { names: &["PE", "PEDIT"] }); // PeditCommand
|