Feat: ZOOM IN/OUT/WINDOW commands; ZoomToWindow CmdResult
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6f5c58612d
commit
70a8f5bf3f
6 changed files with 120 additions and 0 deletions
|
|
@ -356,6 +356,14 @@ impl H7CAD {
|
||||||
self.command_line.push_info(&p);
|
self.command_line.push_info(&p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CmdResult::ZoomToWindow { p1, p2 } => {
|
||||||
|
self.tabs[i].active_cmd = None;
|
||||||
|
self.tabs[i].snap_result = None;
|
||||||
|
self.tabs[i].scene.clear_preview_wire();
|
||||||
|
self.tabs[i].scene.zoom_to_window(p1, p2);
|
||||||
|
self.command_line.push_output("Zoom Window");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Focus the command-line input while a command is active; blur it when the command ends.
|
// Focus the command-line input while a command is active; blur it when the command ends.
|
||||||
if self.tabs[i].active_cmd.is_some() {
|
if self.tabs[i].active_cmd.is_some() {
|
||||||
|
|
|
||||||
|
|
@ -710,6 +710,23 @@ impl H7CAD {
|
||||||
self.command_line.push_output("Zoom Extents");
|
self.command_line.push_output("Zoom Extents");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"ZOOM IN"|"ZI" => {
|
||||||
|
self.tabs[i].scene.zoom_camera(1.0 / 1.5);
|
||||||
|
self.command_line.push_output("Zoom In");
|
||||||
|
}
|
||||||
|
|
||||||
|
"ZOOM OUT"|"ZO" => {
|
||||||
|
self.tabs[i].scene.zoom_camera(1.5);
|
||||||
|
self.command_line.push_output("Zoom Out");
|
||||||
|
}
|
||||||
|
|
||||||
|
"ZOOM WINDOW"|"ZOOM W"|"ZW" => {
|
||||||
|
use crate::modules::view::zoom_window::ZoomWindowCommand;
|
||||||
|
let new_cmd = ZoomWindowCommand::new();
|
||||||
|
self.command_line.push_info(&new_cmd.prompt());
|
||||||
|
self.tabs[i].active_cmd = Some(Box::new(new_cmd));
|
||||||
|
}
|
||||||
|
|
||||||
"STRETCH"|"SS" => {
|
"STRETCH"|"SS" => {
|
||||||
let handles: Vec<_> = self.tabs[i].scene.selected_entities()
|
let handles: Vec<_> = self.tabs[i].scene.selected_entities()
|
||||||
.into_iter().map(|(h, _)| h).collect();
|
.into_iter().map(|(h, _)| h).collect();
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,8 @@ pub enum CmdResult {
|
||||||
},
|
},
|
||||||
/// Paste clipboard entities translated so their centroid lands at `base_pt`; end command.
|
/// Paste clipboard entities translated so their centroid lands at `base_pt`; end command.
|
||||||
PasteClipboard { base_pt: Vec3 },
|
PasteClipboard { base_pt: Vec3 },
|
||||||
|
/// Zoom the model-space camera to fit the given corner points; end command.
|
||||||
|
ZoomToWindow { p1: Vec3, p2: Vec3 },
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Trait ─────────────────────────────────────────────────────────────────
|
// ── Trait ─────────────────────────────────────────────────────────────────
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ mod xray;
|
||||||
mod zoom_ext;
|
mod zoom_ext;
|
||||||
mod zoom_in;
|
mod zoom_in;
|
||||||
mod zoom_out;
|
mod zoom_out;
|
||||||
|
pub mod zoom_window;
|
||||||
|
|
||||||
use crate::modules::{CadModule, RibbonGroup};
|
use crate::modules::{CadModule, RibbonGroup};
|
||||||
|
|
||||||
|
|
|
||||||
72
src/modules/view/zoom_window.rs
Normal file
72
src/modules/view/zoom_window.rs
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
// ZOOM WINDOW command — pick two corners to define the zoom area.
|
||||||
|
|
||||||
|
use glam::Vec3;
|
||||||
|
|
||||||
|
use crate::command::{CadCommand, CmdResult};
|
||||||
|
use crate::scene::wire_model::WireModel;
|
||||||
|
|
||||||
|
pub struct ZoomWindowCommand {
|
||||||
|
first: Option<Vec3>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ZoomWindowCommand {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self { first: None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CadCommand for ZoomWindowCommand {
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"ZOOM WINDOW"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prompt(&self) -> String {
|
||||||
|
if self.first.is_none() {
|
||||||
|
"ZOOM WINDOW Specify first corner:".into()
|
||||||
|
} else {
|
||||||
|
"ZOOM WINDOW Specify opposite corner:".into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_point(&mut self, pt: Vec3) -> CmdResult {
|
||||||
|
if let Some(p1) = self.first {
|
||||||
|
CmdResult::ZoomToWindow { p1, p2: pt }
|
||||||
|
} else {
|
||||||
|
self.first = Some(pt);
|
||||||
|
CmdResult::NeedPoint
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_enter(&mut self) -> CmdResult {
|
||||||
|
CmdResult::Cancel
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_escape(&mut self) -> CmdResult {
|
||||||
|
CmdResult::Cancel
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_mouse_move(&mut self, pt: Vec3) -> Option<WireModel> {
|
||||||
|
let p1 = self.first?;
|
||||||
|
let min = p1.min(pt);
|
||||||
|
let max = p1.max(pt);
|
||||||
|
// Draw a rectangle preview
|
||||||
|
Some(WireModel {
|
||||||
|
name: "zoom_window_preview".into(),
|
||||||
|
points: vec![
|
||||||
|
[min.x, min.y, 0.0],
|
||||||
|
[max.x, min.y, 0.0],
|
||||||
|
[max.x, max.y, 0.0],
|
||||||
|
[min.x, max.y, 0.0],
|
||||||
|
[min.x, min.y, 0.0],
|
||||||
|
],
|
||||||
|
color: WireModel::CYAN,
|
||||||
|
selected: false,
|
||||||
|
pattern_length: 0.0,
|
||||||
|
pattern: [0.0; 8],
|
||||||
|
line_weight_px: 1.0,
|
||||||
|
snap_pts: vec![],
|
||||||
|
tangent_geoms: vec![],
|
||||||
|
key_vertices: vec![],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1687,6 +1687,26 @@ impl Scene {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Zoom the model-space camera in/out by a percentage.
|
||||||
|
/// factor > 1 = zoom out, factor < 1 = zoom in.
|
||||||
|
pub fn zoom_camera(&mut self, factor: f32) {
|
||||||
|
let mut cam = self.camera.borrow_mut();
|
||||||
|
cam.distance = (cam.distance * factor).max(0.001);
|
||||||
|
drop(cam);
|
||||||
|
self.camera_generation += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fit the camera to a world-space bounding box (corners p1, p2).
|
||||||
|
pub fn zoom_to_window(&mut self, p1: glam::Vec3, p2: glam::Vec3) {
|
||||||
|
let min = p1.min(p2);
|
||||||
|
let max = p1.max(p2);
|
||||||
|
if min == max {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.camera.borrow_mut().fit_to_bounds(min, max);
|
||||||
|
self.camera_generation += 1;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn fit_all(&mut self) {
|
pub fn fit_all(&mut self) {
|
||||||
let wires = self.entity_wires();
|
let wires = self.entity_wires();
|
||||||
if wires.is_empty() {
|
if wires.is_empty() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue