forked from 1b-agent/opencadstudio-upstream
Typed values were quantized to the f32 grid before reaching the entity (e.g. a length of 2000.8 committed as 2000.8020), worsening with magnitude. The interaction point layer was all glam::Vec3 (f32). Two-layer fix: 1. Coordinate backbone -> f64. last_point, last_cursor_world, dyn_anchor, dyn_ref become DVec3; UcsXform transforms, parse_coord, the ucs helper fns, dyn_resolve_point, the OTRACK typed-distance paths, command-line coordinate entry and the coordinate readout all compute in f64. Screen/GPU/alignment stays f32 (snap engine, render geometry, projection, UCS-icon/viewcube drawing) with casts only at those boundaries. 2. Per-command committed storage -> DVec3. on_point already received a DVec3, but many command impls narrowed it back to f32 (let pt = pt.as_vec3(); Vec<Vec3> fields) and re-widened at build, quantizing the committed coordinate. Migrated PLINE, SPLINE, MLINE, LENGTHEN, INSERT, 3D primitives, every dimension/leader/mleader, ray, revcloud, wipeout, attdef, table, tolerance, array center, mview, plot_window, plus the QDIM_PLACE handler and qdim_collect_points. Preview, hit-test and rubber-band paths keep f32 at the boundary. Hatch manual boundaries are left for a follow-up: HatchModel.boundary is structurally Arc<Vec<[f32;2]>> and needs a model-level widen. Co-Authored-By: Claude Opus 4.8 <[email protected]>
121 lines
3.6 KiB
Rust
121 lines
3.6 KiB
Rust
// DIMJOGLINE command — add a jog (zigzag) symbol to a linear or aligned dimension.
|
|
//
|
|
// Workflow:
|
|
// 1. Pick the dimension
|
|
// 2. Click the position on the dimension line where the jog should appear
|
|
|
|
use acadrust::Handle;
|
|
use glam::DVec3;
|
|
|
|
use crate::command::{CadCommand, CmdResult};
|
|
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
|
use crate::scene::model::wire_model::WireModel;
|
|
|
|
pub const ICON: IconKind = IconKind::Svg(include_bytes!("../../../assets/icons/dim_jog.svg"));
|
|
|
|
pub fn tool() -> ToolDef {
|
|
ToolDef {
|
|
id: "DIMJOGLINE",
|
|
label: "Jog Line",
|
|
icon: ICON,
|
|
event: ModuleEvent::Command("DIMJOGLINE".to_string()),
|
|
}
|
|
}
|
|
|
|
enum Step {
|
|
PickDim,
|
|
PickJogPos { handle: Handle },
|
|
}
|
|
|
|
pub struct DimJogLineCommand {
|
|
step: Step,
|
|
}
|
|
|
|
impl DimJogLineCommand {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
step: Step::PickDim,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl CadCommand for DimJogLineCommand {
|
|
fn name(&self) -> &'static str {
|
|
"DIMJOGLINE"
|
|
}
|
|
|
|
fn prompt(&self) -> String {
|
|
match &self.step {
|
|
Step::PickDim => "DIMJOGLINE Select linear or aligned dimension:".into(),
|
|
Step::PickJogPos { .. } => "DIMJOGLINE Specify jog location:".into(),
|
|
}
|
|
}
|
|
|
|
fn needs_entity_pick(&self) -> bool {
|
|
matches!(self.step, Step::PickDim)
|
|
}
|
|
|
|
fn on_entity_pick(&mut self, handle: Handle, _pt: DVec3) -> CmdResult {
|
|
if handle.is_null() {
|
|
return CmdResult::NeedPoint;
|
|
}
|
|
self.step = Step::PickJogPos { handle };
|
|
CmdResult::NeedPoint
|
|
}
|
|
|
|
fn on_point(&mut self, pt: DVec3) -> CmdResult {
|
|
if let Step::PickJogPos { handle } = &self.step {
|
|
let h = *handle;
|
|
// Emit sentinel for commands.rs to store the jog position
|
|
use acadrust::entities::XLine;
|
|
let mut xl = XLine::default();
|
|
xl.common.layer = format!("__DIMJOG__{},{:.6},{:.6}", h.value(), pt.x, pt.z);
|
|
return CmdResult::ReplaceEntity(h, vec![acadrust::EntityType::XLine(xl)]);
|
|
}
|
|
CmdResult::NeedPoint
|
|
}
|
|
|
|
fn on_enter(&mut self) -> CmdResult {
|
|
CmdResult::Cancel
|
|
}
|
|
|
|
fn on_mouse_move(&mut self, pt: DVec3) -> Option<WireModel> { let pt = pt.as_vec3();
|
|
if !matches!(self.step, Step::PickJogPos { .. }) {
|
|
return None;
|
|
}
|
|
let d = 0.3_f32;
|
|
Some(WireModel {
|
|
text_verts: Vec::new(),
|
|
name: "dimjog_preview".into(),
|
|
// Jog zigzag in the XY drawing plane (Z is elevation, ~0). The old
|
|
// marker varied Z, so in the top-down view it collapsed to a flat
|
|
// line instead of a zigzag. (#150)
|
|
points: vec![
|
|
[pt.x - d, pt.y, pt.z],
|
|
[pt.x - d * 0.3, pt.y + d, pt.z],
|
|
[pt.x + d * 0.3, pt.y - d, pt.z],
|
|
[pt.x + d, pt.y, pt.z],
|
|
],
|
|
points_low: Vec::new(),
|
|
color: WireModel::CYAN,
|
|
selected: false,
|
|
pattern_length: 0.0,
|
|
pattern: [0.0; 8],
|
|
line_weight_px: 1.2,
|
|
snap_pts: vec![],
|
|
tangent_geoms: vec![],
|
|
aci: 0,
|
|
key_vertices: vec![],
|
|
aabb: WireModel::UNBOUNDED_AABB,
|
|
plinegen: true,
|
|
vp_scissor: None,
|
|
fill_tris: vec![],
|
|
fill_tris_low: Vec::new(),
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
// ── Autocomplete registry ─────────────────────────────────
|
|
inventory::submit!(crate::command::CommandRegistration { names: &["DIMJOGLINE"] }); // DimJogLineCommand
|