forked from 1b-agent/opencadstudio-upstream
refactor: remove remaining world_offset vestiges in app/
Clean up the last zero-valued world_offset locals outside the scene tessellation core: the UCS wire-affine / grid-basis origin shift (document.rs), the coordinate readout (view.rs), grip absolute-apply (update.rs), the dead properties-edit re-offset guard, the MTEXT preview glyph-box shift (mtext_editor.rs), and the cross-drawing paste correction (commands.rs / cmd_result.rs) — including the now-dead `clipboard_world_offset` field. Coordinates are absolute throughout. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
ef8d5b2610
commit
cc43969ce0
8 files changed
+12
-82
No files matched your search
+1
-13
@@ -604,19 +604,7 @@ impl OpenCADStudio {
|
||||
if self.clipboard.is_empty() {
|
||||
self.command_line.push_error("Clipboard is empty.");
|
||||
} else {
|
||||
// The centroid was measured in the source drawing's
|
||||
// offset-relative frame and `base_pt` is in this drawing's;
|
||||
// correct by the world_offset difference so a cross-drawing
|
||||
// paste lands at the cursor instead of drifting by the
|
||||
// offset gap. Zero for a same-drawing paste. (#135)
|
||||
let src_wo = self.clipboard_world_offset;
|
||||
let tgt_wo = [0.0_f64; 3];
|
||||
let wo_corr = glam::DVec3::new(
|
||||
tgt_wo[0] - src_wo[0],
|
||||
tgt_wo[1] - src_wo[1],
|
||||
tgt_wo[2] - src_wo[2],
|
||||
);
|
||||
let delta = base_pt - self.clipboard_centroid + wo_corr;
|
||||
let delta = base_pt - self.clipboard_centroid;
|
||||
let translate = crate::command::EntityTransform::Translate(delta);
|
||||
self.push_undo_snapshot(i, "PASTECLIP");
|
||||
let count = self.clipboard.len();
|
||||
|
||||
+1
-15
@@ -540,7 +540,6 @@ impl OpenCADStudio {
|
||||
self.clipboard_centroid = super::helpers::entities_centroid(
|
||||
&self.tabs[i].scene.wire_models_for(&handles),
|
||||
);
|
||||
self.clipboard_world_offset = [0.0_f64; 3];
|
||||
self.clipboard = entities;
|
||||
self.clipboard_deps = super::ClipboardDeps::capture(
|
||||
&self.tabs[i].scene.document,
|
||||
@@ -573,7 +572,6 @@ impl OpenCADStudio {
|
||||
self.clipboard_centroid = super::helpers::entities_centroid(
|
||||
&self.tabs[i].scene.wire_models_for(&handles),
|
||||
);
|
||||
self.clipboard_world_offset = [0.0_f64; 3];
|
||||
let count = entities.len();
|
||||
self.clipboard = entities;
|
||||
self.clipboard_deps = super::ClipboardDeps::capture(
|
||||
@@ -595,19 +593,7 @@ impl OpenCADStudio {
|
||||
self.command_line.push_error("Clipboard is empty.");
|
||||
} else {
|
||||
let wires = self.tabs[i].scene.wires_for_entities(&self.clipboard);
|
||||
// The preview wires are tessellated in THIS drawing's
|
||||
// offset-relative frame, but the stored centroid is in the
|
||||
// source drawing's. Shift it by the world_offset difference
|
||||
// so the ghost tracks the cursor instead of drifting by the
|
||||
// offset gap. Zero within one drawing. (#135)
|
||||
let src_wo = self.clipboard_world_offset;
|
||||
let tgt_wo = [0.0_f64; 3];
|
||||
let centroid = self.clipboard_centroid
|
||||
+ glam::DVec3::new(
|
||||
src_wo[0] - tgt_wo[0],
|
||||
src_wo[1] - tgt_wo[1],
|
||||
src_wo[2] - tgt_wo[2],
|
||||
);
|
||||
let centroid = self.clipboard_centroid;
|
||||
use crate::modules::draw::clipboard::paste::PasteCommand;
|
||||
// The ghost anchor is a display-only offset; the precise
|
||||
// paste delta is computed in f64 at commit time.
|
||||
|
||||
+6
-8
@@ -288,11 +288,10 @@ impl DocumentTab {
|
||||
return glam::Mat4::IDENTITY;
|
||||
}
|
||||
let (o, x, y, z) = self.ucs_xform().axes();
|
||||
let wo = [0.0_f64; 3];
|
||||
let origin = glam::Vec3::new(
|
||||
o.x - wo[0] as f32,
|
||||
o.y - wo[1] as f32,
|
||||
o.z - wo[2] as f32,
|
||||
o.x as f32,
|
||||
o.y as f32,
|
||||
o.z as f32,
|
||||
);
|
||||
glam::Mat4::from_cols(
|
||||
x.extend(0.0),
|
||||
@@ -321,11 +320,10 @@ impl DocumentTab {
|
||||
}
|
||||
let xf = self.ucs_xform();
|
||||
let (o, ..) = xf.axes();
|
||||
let wo = [0.0_f64; 3];
|
||||
let origin = glam::Vec3::new(
|
||||
o.x - wo[0] as f32,
|
||||
o.y - wo[1] as f32,
|
||||
o.z - wo[2] as f32,
|
||||
o.x as f32,
|
||||
o.y as f32,
|
||||
o.z as f32,
|
||||
);
|
||||
(origin, xf.rotation_mat())
|
||||
}
|
||||
|
||||
@@ -372,12 +372,6 @@ pub(super) struct OpenCADStudio {
|
||||
clipboard: Vec<acadrust::EntityType>,
|
||||
/// Centroid of the clipboard entities (world XY plane).
|
||||
clipboard_centroid: glam::DVec3,
|
||||
/// The source drawing's `world_offset` at copy time. The centroid above is
|
||||
/// measured in that drawing's offset-relative frame; pasting into a drawing
|
||||
/// with a different offset (e.g. a large-coordinate file → a fresh one)
|
||||
/// must correct the paste translation by the offset difference, else the
|
||||
/// objects land `source_offset − target_offset` away from the cursor.
|
||||
clipboard_world_offset: [f64; 3],
|
||||
/// Table records (layer / linetype / text + dim style) the clipboard
|
||||
/// entities reference, captured from the source drawing at copy time so a
|
||||
/// paste into a *different* drawing can recreate any that are missing —
|
||||
@@ -1809,7 +1803,6 @@ impl OpenCADStudio {
|
||||
update_notice_body: None,
|
||||
clipboard: Vec::new(),
|
||||
clipboard_centroid: glam::DVec3::ZERO,
|
||||
clipboard_world_offset: [0.0; 3],
|
||||
clipboard_deps: ClipboardDeps::default(),
|
||||
shift_down: false,
|
||||
mtext_editor: None,
|
||||
|
||||
+2
-11
@@ -395,7 +395,6 @@ impl super::OpenCADStudio {
|
||||
let Some(ed) = self.mtext_editor.as_ref() else { return };
|
||||
let mt = ed.build_mtext();
|
||||
let entity = EntityType::MText(mt.clone());
|
||||
let woff = [0.0_f64; 3];
|
||||
let anno = self.tabs[i].scene.annotation_scale;
|
||||
let wires: Vec<WireModel> = tessellate::tessellate(
|
||||
&self.tabs[i].scene.document,
|
||||
@@ -409,16 +408,8 @@ impl super::OpenCADStudio {
|
||||
anno,
|
||||
None,
|
||||
);
|
||||
// Per-character boxes in the same offset-subtracted frame as the
|
||||
// preview wires (tessellate removes world_offset; mirror that).
|
||||
let mut boxes = crate::entities::mtext::glyph_boxes(&mt, &self.tabs[i].scene.document);
|
||||
let (ox, oy) = (woff[0] as f32, woff[1] as f32);
|
||||
for b in &mut boxes {
|
||||
b.xmin -= ox;
|
||||
b.xmax -= ox;
|
||||
b.ymin -= oy;
|
||||
b.ymax -= oy;
|
||||
}
|
||||
// Per-character boxes share the preview wires' absolute coordinate frame.
|
||||
let boxes = crate::entities::mtext::glyph_boxes(&mt, &self.tabs[i].scene.document);
|
||||
if let Some(ed) = self.mtext_editor.as_mut() {
|
||||
ed.preview_wires = wires;
|
||||
ed.glyph_boxes = boxes;
|
||||
|
||||
@@ -652,18 +652,6 @@ impl OpenCADStudio {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// Commands pick points in local space (camera coordinates with world_offset
|
||||
// already subtracted). Re-add world_offset so the entity lands at the correct
|
||||
// DXF coordinate. Skip for paper-space entities (they use sheet mm coords).
|
||||
let is_paper = self.tabs[i].scene.current_layout != "Model";
|
||||
if !is_paper {
|
||||
let wo = [0.0_f64; 3];
|
||||
if wo[0] != 0.0 || wo[1] != 0.0 || wo[2] != 0.0 {
|
||||
let delta = acadrust::types::Vector3::new(wo[0], wo[1], wo[2]);
|
||||
let t = acadrust::types::Transform::from_translation(delta);
|
||||
entity.apply_transform(&t);
|
||||
}
|
||||
}
|
||||
|
||||
if matches!(&entity, acadrust::EntityType::Viewport(_))
|
||||
&& self.tabs[i].scene.current_layout != "Model"
|
||||
|
||||
+1
-9
@@ -2713,18 +2713,10 @@ impl OpenCADStudio {
|
||||
}
|
||||
}
|
||||
|
||||
// Paper-space entities use sheet coordinates (no world_offset).
|
||||
// Only add world_offset when converting local → DXF space in model space.
|
||||
let wo_vec = if self.tabs[i].scene.current_layout == "Model" {
|
||||
let wo = [0.0_f64; 3];
|
||||
glam::DVec3::new(wo[0], wo[1], wo[2])
|
||||
} else {
|
||||
glam::DVec3::ZERO
|
||||
};
|
||||
let apply = if grip.is_translate {
|
||||
GripApply::Translate(snapped - grip.last_world)
|
||||
} else {
|
||||
GripApply::Absolute(snapped + wo_vec)
|
||||
GripApply::Absolute(snapped)
|
||||
};
|
||||
self.tabs[i]
|
||||
.scene
|
||||
|
||||
+1
-7
@@ -949,13 +949,7 @@ impl OpenCADStudio {
|
||||
// The readout follows the active pane's UCS — model space
|
||||
// or inside a floating viewport (no-op without a UCS).
|
||||
if tab.editing_model_space() {
|
||||
let wo = [0.0_f64; 3];
|
||||
let wcs = glam::Vec3::new(
|
||||
lc.x + wo[0] as f32,
|
||||
lc.y + wo[1] as f32,
|
||||
lc.z + wo[2] as f32,
|
||||
);
|
||||
tab.ucs_xform().to_ucs(wcs)
|
||||
tab.ucs_xform().to_ucs(lc)
|
||||
} else {
|
||||
lc
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user