feat(ucs): integrate coordinate systems

Route coordinate input, geometry creation, transforms, properties,\nviews, and viewport persistence through a shared working plane.\n\nRefs #484
This commit is contained in:
Hakan Seven committed 2026-08-04 23:17:54 +03:00
1 parent b1d55c6a7e
commit 657d023fb7
61 files changed
+2218 -747

No files matched your search

+14 -2
View File
@@ -4,7 +4,7 @@ use acadrust::EntityType;
use glam::{DVec3, Vec3};
use crate::t;
use crate::command::{CadCommand, CmdResult};
use crate::command::{CadCommand, CmdResult, WorkingPlane};
use crate::modules::{IconKind, ModuleEvent, ToolDef};
use crate::scene::model::wire_model::WireModel;
@@ -59,6 +59,7 @@ pub struct InsertBlockCommand {
/// is measured from, so `on_preview_wires` can rubber-band it to the
/// cursor. Set by paste-as-block; empty for a plain INSERT.
preview: Option<(Vec<WireModel>, Vec3)>,
plane: WorkingPlane,
}
impl InsertBlockCommand {
@@ -72,6 +73,7 @@ impl InsertBlockCommand {
awaiting: None,
pending_insert: None,
preview: None,
plane: WorkingPlane::default(),
}
}
@@ -89,11 +91,16 @@ impl InsertBlockCommand {
awaiting: None,
pending_insert: None,
preview: Some((preview_wires, base)),
plane: WorkingPlane::default(),
}
}
}
impl CadCommand for InsertBlockCommand {
fn set_working_plane(&mut self, plane: WorkingPlane) {
self.plane = plane;
}
fn name(&self) -> &'static str {
"INSERT"
}
@@ -146,10 +153,15 @@ impl CadCommand for InsertBlockCommand {
match &self.step {
Step::Name => CmdResult::NeedPoint,
Step::Point { name } => {
let mut ins = Insert::new(name.clone(), Vector3::new(pt.x, pt.y, pt.z));
let point = self.plane.to_local(pt);
let mut ins = Insert::new(
name.clone(),
Vector3::new(point.x, point.y, point.z),
);
ins.set_x_scale(self.x_scale);
ins.set_y_scale(self.y_scale);
ins.rotation = self.rotation_rad;
ins.apply_transform(&self.plane.to_world_transform());
let block_name = name.clone();
self.pending_insert = Some(ins);
// Signal the host to check for attdefs.
+10 -3
View File
@@ -12,7 +12,7 @@ use acadrust::EntityType;
use glam::DVec3;
use crate::t;
use crate::command::{CadCommand, CmdResult};
use crate::command::{CadCommand, CmdResult, WorkingPlane};
use crate::modules::{IconKind, ModuleEvent, ToolDef};
#[allow(dead_code)]
@@ -67,6 +67,7 @@ pub struct MinsertCommand {
columns: u16,
row_spacing: f64,
column_spacing: f64,
plane: WorkingPlane,
}
impl MinsertCommand {
@@ -78,6 +79,7 @@ impl MinsertCommand {
columns: 1,
row_spacing: 0.0,
column_spacing: 0.0,
plane: WorkingPlane::default(),
}
}
@@ -88,7 +90,7 @@ impl MinsertCommand {
ins.column_count = self.columns.max(1);
ins.row_spacing = self.row_spacing;
ins.column_spacing = self.column_spacing;
CmdResult::CommitAndExit(EntityType::Insert(ins))
CmdResult::CommitAndExit(self.plane.place_entity(EntityType::Insert(ins)))
}
/// Advance from the parameter currently at `idx` to the next, or build the
@@ -109,6 +111,10 @@ impl MinsertCommand {
}
impl CadCommand for MinsertCommand {
fn set_working_plane(&mut self, plane: WorkingPlane) {
self.plane = plane;
}
fn name(&self) -> &'static str {
"MINSERT"
}
@@ -160,7 +166,8 @@ impl CadCommand for MinsertCommand {
Step::Name => CmdResult::NeedPoint,
Step::Point { name } => {
let name = name.clone();
let point = Vector3::new(pt.x, pt.y, pt.z);
let point = self.plane.to_local(pt);
let point = Vector3::new(point.x, point.y, point.z);
self.step = Step::Params {
name,
point,
+15 -5
View File
@@ -16,7 +16,7 @@ use glam::DVec3;
use crate::t;
use crate::command::{CadCommand, CmdResult};
use crate::command::{CadCommand, CmdResult, WorkingPlane};
use crate::modules::{IconKind, ModuleEvent, ToolDef};
use crate::scene::model::wire_model::WireModel;
use crate::scene::Scene;
@@ -33,17 +33,26 @@ pub fn tool() -> ToolDef {
pub struct XAttachCommand {
path: String,
block_name: String,
plane: WorkingPlane,
}
impl XAttachCommand {
/// Create an XATTACH command with a path already filled in (from file-picker).
pub fn with_path(path: String) -> Self {
let block_name = path_to_block_name(&path);
Self { path, block_name }
Self {
path,
block_name,
plane: WorkingPlane::default(),
}
}
}
impl CadCommand for XAttachCommand {
fn set_working_plane(&mut self, plane: WorkingPlane) {
self.plane = plane;
}
fn name(&self) -> &'static str {
"XATTACH"
}
@@ -59,10 +68,11 @@ impl CadCommand for XAttachCommand {
fn on_point(&mut self, pt: DVec3) -> CmdResult {
// We return the INSERT entity; the command handler in commands.rs
// calls `prepare_xref_block` on the scene before committing.
CmdResult::CommitAndExit(EntityType::Insert(Insert::new(
let point = self.plane.to_local(pt);
CmdResult::CommitAndExit(self.plane.place_entity(EntityType::Insert(Insert::new(
self.block_name.clone(),
Vector3::new(pt.x as f64, pt.y as f64, pt.z as f64),
)))
Vector3::new(point.x, point.y, point.z),
))))
}
fn on_enter(&mut self) -> CmdResult {