forked from 1b-agent/opencadstudio-upstream
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:
1 parent
b1d55c6a7e
commit
657d023fb7
61 files changed
+2218
-747
No files matched your search
@@ -12,7 +12,7 @@ use acadrust::Handle;
|
||||
use glam::DVec3;
|
||||
use crate::t;
|
||||
|
||||
use crate::command::{CadCommand, CmdResult, EntityTransform};
|
||||
use crate::command::{CadCommand, CmdResult, EntityTransform, WorkingPlane};
|
||||
use crate::modules::{IconKind, ModuleEvent, ToolDef};
|
||||
use crate::scene::model::wire_model::WireModel;
|
||||
|
||||
@@ -41,6 +41,7 @@ pub struct MirrorCommand {
|
||||
text_ghosts: Vec<(WireModel, DVec3)>,
|
||||
mirror_text: bool,
|
||||
step: Step,
|
||||
plane: WorkingPlane,
|
||||
}
|
||||
|
||||
impl MirrorCommand {
|
||||
@@ -56,11 +57,16 @@ impl MirrorCommand {
|
||||
text_ghosts,
|
||||
mirror_text,
|
||||
step: Step::P1,
|
||||
plane: WorkingPlane::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CadCommand for MirrorCommand {
|
||||
fn set_working_plane(&mut self, plane: WorkingPlane) {
|
||||
self.plane = plane;
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"MIRROR"
|
||||
}
|
||||
@@ -147,18 +153,32 @@ impl CadCommand for MirrorCommand {
|
||||
let mut out: Vec<WireModel> = self
|
||||
.wire_models
|
||||
.iter()
|
||||
.map(|w| w.mirrored(p1.as_vec3(), p2.as_vec3()))
|
||||
.map(|w| {
|
||||
w.mirrored_in_plane(
|
||||
p1.as_vec3(),
|
||||
p2.as_vec3(),
|
||||
self.plane.z.as_vec3(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
// Text ghosts honour MIRRTEXT: on → true glyph mirror (full reflection);
|
||||
// off → keep glyphs readable, relocate to the mirror-symmetric position
|
||||
// by reflecting the box centre and translating.
|
||||
for (w, center) in &self.text_ghosts {
|
||||
if self.mirror_text {
|
||||
out.push(w.mirrored(p1.as_vec3(), p2.as_vec3()));
|
||||
out.push(w.mirrored_in_plane(
|
||||
p1.as_vec3(),
|
||||
p2.as_vec3(),
|
||||
self.plane.z.as_vec3(),
|
||||
));
|
||||
} else {
|
||||
let (mut cx, mut cy) = (center.x, center.y);
|
||||
crate::scene::view::transform::reflect_xy_point(&mut cx, &mut cy, p1, p2);
|
||||
let delta = glam::Vec3::new((cx - center.x) as f32, (cy - center.y) as f32, 0.0);
|
||||
let reflected = crate::scene::view::transform::reflected_point(
|
||||
*center,
|
||||
p1,
|
||||
p2,
|
||||
self.plane.z,
|
||||
);
|
||||
let delta = (reflected - *center).as_vec3();
|
||||
out.push(w.translated(delta));
|
||||
}
|
||||
}
|
||||
@@ -180,7 +200,11 @@ impl MirrorCommand {
|
||||
/// Commit the mirror. `erase` true flips the originals in place; false
|
||||
/// keeps them and adds a mirrored copy. Either way the command ends.
|
||||
fn finish(&self, p1: DVec3, p2: DVec3, erase: bool) -> CmdResult {
|
||||
let xform = EntityTransform::Mirror { p1, p2 };
|
||||
let xform = EntityTransform::Mirror {
|
||||
p1,
|
||||
p2,
|
||||
working_normal: self.plane.z,
|
||||
};
|
||||
if erase {
|
||||
CmdResult::TransformSelected(self.handles.clone(), xform)
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user