forked from 1b-agent/opencadstudio-upstream
Merge PR #1279 and complete parametric UI actions
This commit is contained in:
commit
adc8555394
22 files changed
+672
-217
No files matched your search
Generated
+2
-2
@@ -919,7 +919,7 @@ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "cadkernel"
|
name = "cadkernel"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/HakanSeven12/cadkernel.git?rev=b8b664a#b8b664ae993e392fb84689966a44fa9a3f4e38cd"
|
source = "git+https://github.com/HakanSeven12/cadkernel.git?rev=ea7ace7#ea7ace7047c5c5ba170d8257080b5b881df6c063"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"acadrust",
|
"acadrust",
|
||||||
"cavalier_contours",
|
"cavalier_contours",
|
||||||
@@ -930,7 +930,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "cadkernel-constraints"
|
name = "cadkernel-constraints"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/HakanSeven12/cadkernel.git?rev=b8b664a#b8b664ae993e392fb84689966a44fa9a3f4e38cd"
|
source = "git+https://github.com/HakanSeven12/cadkernel.git?rev=ea7ace7#ea7ace7047c5c5ba170d8257080b5b881df6c063"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"nalgebra",
|
"nalgebra",
|
||||||
]
|
]
|
||||||
|
|||||||
+2
-2
@@ -33,8 +33,8 @@ rfd = "0.17"
|
|||||||
clap = { version = "4", features = ["derive", "string"] }
|
clap = { version = "4", features = ["derive", "string"] }
|
||||||
env_logger = "0.11"
|
env_logger = "0.11"
|
||||||
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "568a12c", features = ["serde"] }
|
acadrust = { git = "https://github.com/HakanSeven12/cadcodec.git", rev = "568a12c", features = ["serde"] }
|
||||||
cadkernel = { git = "https://github.com/HakanSeven12/cadkernel.git", rev = "b8b664a", features = ["acis", "offset"] }
|
cadkernel = { git = "https://github.com/HakanSeven12/cadkernel.git", rev = "ea7ace7", features = ["acis", "offset"] }
|
||||||
cadkernel-constraints = { git = "https://github.com/HakanSeven12/cadkernel.git", rev = "b8b664a" }
|
cadkernel-constraints = { git = "https://github.com/HakanSeven12/cadkernel.git", rev = "ea7ace7" }
|
||||||
dwg-thumbnailer = { path = "crates/dwg-thumbnailer" }
|
dwg-thumbnailer = { path = "crates/dwg-thumbnailer" }
|
||||||
flate2 = "1"
|
flate2 = "1"
|
||||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "bmp", "tiff"] }
|
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "bmp", "tiff"] }
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-linecap="round">
|
||||||
|
<path d="M3 20h18" stroke="#ffffff" stroke-width="1.8"/>
|
||||||
|
<path d="M7 6v11M12 10v7M17 4v13" stroke="#2496ed" stroke-width="2.2"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 236 B |
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-linecap="round">
|
||||||
|
<path d="M12 3v18" stroke="#ffffff" stroke-width="1.8" stroke-dasharray="2 2"/>
|
||||||
|
<path d="M6 7h12M8 12h8M4 17h16" stroke="#2496ed" stroke-width="2.2"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 258 B |
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-linecap="round">
|
||||||
|
<path d="M4 3v18" stroke="#ffffff" stroke-width="1.8"/>
|
||||||
|
<path d="M7 7h11M7 12h7M7 17h13" stroke="#2496ed" stroke-width="2.2"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 234 B |
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-linecap="round">
|
||||||
|
<path d="M20 3v18" stroke="#ffffff" stroke-width="1.8"/>
|
||||||
|
<path d="M6 7h11M10 12h7M4 17h13" stroke="#2496ed" stroke-width="2.2"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 236 B |
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-linecap="round">
|
||||||
|
<path d="M3 4h18" stroke="#ffffff" stroke-width="1.8"/>
|
||||||
|
<path d="M7 7v11M12 7v7M17 7v13" stroke="#2496ed" stroke-width="2.2"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 234 B |
@@ -0,0 +1,4 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-linecap="round">
|
||||||
|
<path d="M3 12h18" stroke="#ffffff" stroke-width="1.8" stroke-dasharray="2 2"/>
|
||||||
|
<path d="M7 6v12M12 8v8M17 4v16" stroke="#2496ed" stroke-width="2.2"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 258 B |
@@ -989,6 +989,9 @@ impl OpenCADStudio {
|
|||||||
.scene
|
.scene
|
||||||
.parametric_constraint_set_mut(scope)
|
.parametric_constraint_set_mut(scope)
|
||||||
.remove(id);
|
.remove(id);
|
||||||
|
if self.tabs[i].scene.selected_constraint == Some(id) {
|
||||||
|
self.tabs[i].scene.selected_constraint = None;
|
||||||
|
}
|
||||||
let changes: Vec<(Handle, crate::scene::ChangeKind)> = touched
|
let changes: Vec<(Handle, crate::scene::ChangeKind)> = touched
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|h| (h, crate::scene::ChangeKind::Modified))
|
.map(|h| (h, crate::scene::ChangeKind::Modified))
|
||||||
@@ -7906,6 +7909,7 @@ mod parametric_constraint_undo_tests {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.constraints[0]
|
.constraints[0]
|
||||||
.id;
|
.id;
|
||||||
|
app.tabs[app.active_tab].scene.selected_constraint = Some(id);
|
||||||
|
|
||||||
app.delete_parametric_constraint(id);
|
app.delete_parametric_constraint(id);
|
||||||
assert!(app.tabs[app.active_tab]
|
assert!(app.tabs[app.active_tab]
|
||||||
@@ -7914,6 +7918,7 @@ mod parametric_constraint_undo_tests {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.constraints
|
.constraints
|
||||||
.is_empty());
|
.is_empty());
|
||||||
|
assert_eq!(app.tabs[app.active_tab].scene.selected_constraint, None);
|
||||||
|
|
||||||
app.undo_steps(1);
|
app.undo_steps(1);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
@@ -1,6 +1,84 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
impl OpenCADStudio {
|
impl OpenCADStudio {
|
||||||
|
/// Align every selected object or complete group by one edge or center.
|
||||||
|
fn align_selected_bounds(&mut self, i: usize, command: &str) {
|
||||||
|
use crate::command::EntityTransform;
|
||||||
|
use cadkernel::space::BoundsAlignment;
|
||||||
|
use glam::DVec3;
|
||||||
|
|
||||||
|
let (alignment, label) = match command {
|
||||||
|
"ALIGNLEFT" => (BoundsAlignment::Left, "Align Left"),
|
||||||
|
"ALIGNHCENTER" => (BoundsAlignment::HorizontalCenter, "Align Horizontal Centers"),
|
||||||
|
"ALIGNRIGHT" => (BoundsAlignment::Right, "Align Right"),
|
||||||
|
"ALIGNTOP" => (BoundsAlignment::Top, "Align Top"),
|
||||||
|
"ALIGNVCENTER" => (BoundsAlignment::VerticalCenter, "Align Vertical Centers"),
|
||||||
|
"ALIGNBOTTOM" => (BoundsAlignment::Bottom, "Align Bottom"),
|
||||||
|
_ => return,
|
||||||
|
};
|
||||||
|
|
||||||
|
let handles: Vec<_> = self.tabs[i]
|
||||||
|
.scene
|
||||||
|
.selected_handles_in_order()
|
||||||
|
.into_iter()
|
||||||
|
.filter(|handle| !self.tabs[i].scene.is_layer_locked(*handle))
|
||||||
|
.collect();
|
||||||
|
if handles.len() < 2 {
|
||||||
|
self.command_line
|
||||||
|
.push_info(crate::t!("Select at least two unlocked objects to align.").as_ref());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let bounds: Vec<_> = self.tabs[i]
|
||||||
|
.scene
|
||||||
|
.selected_object_units(&handles)
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|unit| {
|
||||||
|
let mut min_x = f64::INFINITY;
|
||||||
|
let mut min_y = f64::INFINITY;
|
||||||
|
let mut max_x = f64::NEG_INFINITY;
|
||||||
|
let mut max_y = f64::NEG_INFINITY;
|
||||||
|
for handle in &unit {
|
||||||
|
let entity = self.tabs[i].scene.document.get_entity(*handle)?;
|
||||||
|
let bb = entity.as_entity().bounding_box();
|
||||||
|
min_x = min_x.min(bb.min.x);
|
||||||
|
min_y = min_y.min(bb.min.y);
|
||||||
|
max_x = max_x.max(bb.max.x);
|
||||||
|
max_y = max_y.max(bb.max.y);
|
||||||
|
}
|
||||||
|
let bounds = [min_x, min_y, max_x, max_y];
|
||||||
|
bounds
|
||||||
|
.iter()
|
||||||
|
.all(|value| value.is_finite())
|
||||||
|
.then_some((unit, bounds))
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
if bounds.len() < 2 {
|
||||||
|
self.command_line
|
||||||
|
.push_info(crate::t!("The selected objects do not provide usable bounds.").as_ref());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let extents: Vec<_> = bounds.iter().map(|(_, bounds)| *bounds).collect();
|
||||||
|
let offsets = cadkernel::space::align_aabbs_2d(&extents, alignment)
|
||||||
|
.expect("validated at least two finite bounds");
|
||||||
|
let pending = self.begin_undo(i, label, handles.len(), true);
|
||||||
|
for ((unit, _), [dx, dy]) in bounds.iter().zip(offsets) {
|
||||||
|
self.tabs[i].scene.transform_entities(
|
||||||
|
unit,
|
||||||
|
&EntityTransform::Translate(DVec3::new(dx, dy, 0.0)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
self.tabs[i].dirty = true;
|
||||||
|
self.refresh_properties();
|
||||||
|
if let Some(pending) = pending {
|
||||||
|
self.commit_undo_delta(i, pending);
|
||||||
|
}
|
||||||
|
self.command_line.push_output(
|
||||||
|
crate::tf!("{command}: aligned {} object(s).", bounds.len()).as_ref(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn dispatch_inquiry(&mut self, cmd: &str, i: usize) -> Option<Task<Message>> {
|
pub(super) fn dispatch_inquiry(&mut self, cmd: &str, i: usize) -> Option<Task<Message>> {
|
||||||
match cmd {
|
match cmd {
|
||||||
"3DORBIT" => {
|
"3DORBIT" => {
|
||||||
@@ -980,6 +1058,11 @@ impl OpenCADStudio {
|
|||||||
self.tabs[i].active_cmd = Some(Box::new(cmd));
|
self.tabs[i].active_cmd = Some(Box::new(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"ALIGNLEFT" | "ALIGNHCENTER" | "ALIGNRIGHT" | "ALIGNTOP" | "ALIGNVCENTER"
|
||||||
|
| "ALIGNBOTTOM" => {
|
||||||
|
self.align_selected_bounds(i, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
"LENGTHEN" => {
|
"LENGTHEN" => {
|
||||||
use crate::modules::draw::modify::lengthen::LengthenCommand;
|
use crate::modules::draw::modify::lengthen::LengthenCommand;
|
||||||
let cmd = LengthenCommand::new();
|
let cmd = LengthenCommand::new();
|
||||||
@@ -2211,3 +2294,97 @@ mod flatten_tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod align_selected_bounds_tests {
|
||||||
|
use super::*;
|
||||||
|
use acadrust::entities::{EntityType, Line};
|
||||||
|
use acadrust::types::Vector3;
|
||||||
|
|
||||||
|
fn add_line(app: &mut OpenCADStudio, x1: f64, y1: f64, x2: f64, y2: f64) -> acadrust::Handle {
|
||||||
|
app.tabs[app.active_tab]
|
||||||
|
.scene
|
||||||
|
.add_entity(EntityType::Line(Line::from_points(
|
||||||
|
Vector3::new(x1, y1, 0.0),
|
||||||
|
Vector3::new(x2, y2, 0.0),
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn line_start_x(app: &OpenCADStudio, handle: acadrust::Handle) -> f64 {
|
||||||
|
match app.tabs[app.active_tab].scene.document.get_entity(handle) {
|
||||||
|
Some(EntityType::Line(l)) => l.start.x.min(l.end.x),
|
||||||
|
other => panic!("expected a Line, got {other:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn line_max_y(app: &OpenCADStudio, handle: acadrust::Handle) -> f64 {
|
||||||
|
match app.tabs[app.active_tab].scene.document.get_entity(handle) {
|
||||||
|
Some(EntityType::Line(l)) => l.start.y.max(l.end.y),
|
||||||
|
other => panic!("expected a Line, got {other:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A single selected object has no "other object" to align to — refuse
|
||||||
|
/// with an informational message rather than silently moving nothing
|
||||||
|
/// (or panicking on the empty-bounds case).
|
||||||
|
#[test]
|
||||||
|
fn refuses_with_fewer_than_two_selected_objects() {
|
||||||
|
let mut app = OpenCADStudio::new_for_test();
|
||||||
|
let _ = app.automation_op(r#"{"op":"new"}"#);
|
||||||
|
let a = add_line(&mut app, 0.0, 0.0, 2.0, 1.0);
|
||||||
|
app.tabs[app.active_tab].scene.select_entities(&[a]);
|
||||||
|
let i = app.active_tab;
|
||||||
|
|
||||||
|
app.dispatch_inquiry("ALIGNLEFT", i);
|
||||||
|
assert_eq!(line_start_x(&app, a), 0.0, "the lone object must not move");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ALIGNLEFT moves every selected object's left edge to the leftmost
|
||||||
|
/// edge already present in the selection; ALIGNTOP does the same for
|
||||||
|
/// the topmost edge. Both are undoable as one step.
|
||||||
|
#[test]
|
||||||
|
fn aligns_left_and_top_edges_and_is_undoable() {
|
||||||
|
let mut app = OpenCADStudio::new_for_test();
|
||||||
|
let _ = app.automation_op(r#"{"op":"new"}"#);
|
||||||
|
let left = add_line(&mut app, 0.0, 0.0, 1.0, 1.0); // leftmost & topmost already
|
||||||
|
let right = add_line(&mut app, 5.0, -3.0, 8.0, -2.0); // further right and lower
|
||||||
|
app.tabs[app.active_tab].scene.select_entities(&[left, right]);
|
||||||
|
let i = app.active_tab;
|
||||||
|
|
||||||
|
app.dispatch_inquiry("ALIGNLEFT", i);
|
||||||
|
assert_eq!(line_start_x(&app, left), 0.0, "the already-leftmost object must not move");
|
||||||
|
assert_eq!(line_start_x(&app, right), 0.0, "the other object's left edge should meet it");
|
||||||
|
|
||||||
|
app.dispatch_inquiry("ALIGNTOP", i);
|
||||||
|
assert_eq!(line_max_y(&app, left), 1.0, "the already-topmost object must not move");
|
||||||
|
assert_eq!(line_max_y(&app, right), 1.0, "the other object's top edge should meet it");
|
||||||
|
|
||||||
|
app.undo_steps(1); // undo ALIGNTOP
|
||||||
|
assert_eq!(line_max_y(&app, right), -2.0, "undo should restore the pre-ALIGNTOP position");
|
||||||
|
app.undo_steps(1); // undo ALIGNLEFT
|
||||||
|
assert_eq!(line_start_x(&app, right), 5.0, "undo should restore the original geometry");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A complete, fully-selected group (`Scene::selected_object_units`)
|
||||||
|
/// moves as one rigid unit instead of each member line sliding to meet
|
||||||
|
/// the *other* members of its own group.
|
||||||
|
#[test]
|
||||||
|
fn a_complete_group_aligns_as_one_rigid_unit() {
|
||||||
|
let mut app = OpenCADStudio::new_for_test();
|
||||||
|
let _ = app.automation_op(r#"{"op":"new"}"#);
|
||||||
|
let a = add_line(&mut app, 5.0, 0.0, 6.0, 1.0);
|
||||||
|
let b = add_line(&mut app, 7.0, 0.0, 8.0, 1.0);
|
||||||
|
let other = add_line(&mut app, 0.0, 0.0, 1.0, 1.0);
|
||||||
|
app.tabs[app.active_tab].scene.create_group("pair".to_string(), vec![a, b]);
|
||||||
|
app.tabs[app.active_tab].scene.select_entities(&[a, b, other]);
|
||||||
|
let i = app.active_tab;
|
||||||
|
|
||||||
|
app.dispatch_inquiry("ALIGNLEFT", i);
|
||||||
|
// The group's own left edge (a's, at x=5) moves to meet `other`'s
|
||||||
|
// left edge (x=0): a shifts by -5, and b — sharing the same
|
||||||
|
// transform — must shift by exactly the same amount, not collapse
|
||||||
|
// onto `a`.
|
||||||
|
assert_eq!(line_start_x(&app, a), 0.0);
|
||||||
|
assert_eq!(line_start_x(&app, b), 2.0, "b must keep its offset from a, not collapse onto it");
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -2902,7 +2902,7 @@ pub enum Message {
|
|||||||
/// A Constraints-section row was clicked: select every entity in the
|
/// A Constraints-section row was clicked: select every entity in the
|
||||||
/// list (replacing the current selection) in the viewport.
|
/// list (replacing the current selection) in the viewport.
|
||||||
PropConstraintLinkClick(Vec<acadrust::Handle>),
|
PropConstraintLinkClick(Vec<acadrust::Handle>),
|
||||||
/// Remove one parametric constraint from the active standard graph scope.
|
/// Remove one parametric constraint selected from Properties or the viewport.
|
||||||
PropConstraintDelete(crate::scene::parametric_constraints::ConstraintId),
|
PropConstraintDelete(crate::scene::parametric_constraints::ConstraintId),
|
||||||
// ── About window ────────────────────────────────────────────────────
|
// ── About window ────────────────────────────────────────────────────
|
||||||
AboutOpen,
|
AboutOpen,
|
||||||
|
|||||||
@@ -4329,6 +4329,13 @@ impl OpenCADStudio {
|
|||||||
}
|
}
|
||||||
let i = self.active_tab;
|
let i = self.active_tab;
|
||||||
self.tabs[i].scene.selection.borrow_mut().context_menu = None;
|
self.tabs[i].scene.selection.borrow_mut().context_menu = None;
|
||||||
|
// A selected constraint-glyph pill takes Delete before entity
|
||||||
|
// erase — the two selections are mutually exclusive (see
|
||||||
|
// `Scene::selected_constraint`).
|
||||||
|
if let Some(id) = self.tabs[i].scene.selected_constraint {
|
||||||
|
self.delete_parametric_constraint(id);
|
||||||
|
return Task::none();
|
||||||
|
}
|
||||||
let handles: Vec<_> = self.tabs[i].scene.selected.iter().cloned().collect();
|
let handles: Vec<_> = self.tabs[i].scene.selected.iter().cloned().collect();
|
||||||
if !handles.is_empty() {
|
if !handles.is_empty() {
|
||||||
// Erase is delta-safe unless a target is in a group (group
|
// Erase is delta-safe unless a target is in a group (group
|
||||||
@@ -6263,7 +6270,6 @@ impl OpenCADStudio {
|
|||||||
self.refresh_properties();
|
self.refresh_properties();
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Options / About windows ───────────────────────────────────
|
// ── Options / About windows ───────────────────────────────────
|
||||||
Message::OptionsOpen => {
|
Message::OptionsOpen => {
|
||||||
self.active_modal = Some(super::ModalKind::Options);
|
self.active_modal = Some(super::ModalKind::Options);
|
||||||
|
|||||||
+164
-142
@@ -4423,163 +4423,185 @@ properties={:.1}ms picked={}",
|
|||||||
sel.box_current = None;
|
sel.box_current = None;
|
||||||
} else {
|
} else {
|
||||||
if box_anchor.is_none() {
|
if box_anchor.is_none() {
|
||||||
let (view_rot, eye, all_wires) = self.pick_view(i, &edit_cam, bounds);
|
// A parametric-constraint glyph draws above its geometry
|
||||||
let click_world = self.cursor_model_point(i, &edit_cam, p, bounds);
|
// and takes click priority over the entity beneath it.
|
||||||
let t_arm = crate::perf::enabled().then(Instant::now);
|
let glyph_hit = (self.tabs[i].scene.current_layout == "Model")
|
||||||
let prior_selection = self.tabs[i].scene.selected.len();
|
.then(|| {
|
||||||
let click_candidates = self.tabs[i].scene.interaction_pick_candidates_near(
|
let scope = self.tabs[i].current_parametric_scope();
|
||||||
all_wires,
|
self.tabs[i].scene.constraint_glyph_hit(
|
||||||
click_world,
|
scope,
|
||||||
view_rot,
|
canvas_sz,
|
||||||
eye,
|
self.show_constraint_values,
|
||||||
bounds,
|
p_full,
|
||||||
crate::ui::overlay::pick_box_aperture_px(self.pick_box) * 2.0,
|
)
|
||||||
);
|
})
|
||||||
let candidate_handles = self.tabs[i]
|
.flatten();
|
||||||
.scene
|
if let Some(id) = glyph_hit {
|
||||||
.interaction_candidate_handles(&click_candidates);
|
self.tabs[i].scene.deselect_all();
|
||||||
|
self.tabs[i].scene.selected_constraint = Some(id);
|
||||||
// Selection cycling: where two or more objects
|
self.refresh_properties();
|
||||||
// overlap, open a list box to pick which one; a
|
selection_just_completed = true;
|
||||||
// single object falls through to the normal click.
|
|
||||||
// Gated behind the toggle, so default picking is
|
|
||||||
// unchanged when off.
|
|
||||||
let mut handled_by_cycling = false;
|
|
||||||
if self.selection_cycling {
|
|
||||||
let cands: Vec<Handle> = scene::pick::hit_test::click_hits_all(
|
|
||||||
p,
|
|
||||||
&click_candidates,
|
|
||||||
view_rot,
|
|
||||||
eye,
|
|
||||||
bounds,
|
|
||||||
self.tabs[i].scene.document.header.lineweight_display,
|
|
||||||
crate::ui::overlay::pick_box_aperture_px(self.pick_box),
|
|
||||||
)
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|s| Scene::handle_from_wire_name(s))
|
|
||||||
.filter(|&h| self.tabs[i].scene.passes_selection_filter(h))
|
|
||||||
.collect();
|
|
||||||
if cands.len() >= 2 {
|
|
||||||
// Overlap: open the list box at the cursor.
|
|
||||||
self.cycle_candidates = Some((p_full, cands));
|
|
||||||
handled_by_cycling = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if glyph_hit.is_none() {
|
||||||
if !handled_by_cycling {
|
let (view_rot, eye, all_wires) = self.pick_view(i, &edit_cam, bounds);
|
||||||
let hit = scene::pick::hit_test::click_hit(
|
let click_world = self.cursor_model_point(i, &edit_cam, p, bounds);
|
||||||
p,
|
let t_arm = crate::perf::enabled().then(Instant::now);
|
||||||
&click_candidates,
|
let prior_selection = self.tabs[i].scene.selected.len();
|
||||||
|
let click_candidates = self.tabs[i].scene.interaction_pick_candidates_near(
|
||||||
|
all_wires,
|
||||||
|
click_world,
|
||||||
view_rot,
|
view_rot,
|
||||||
eye,
|
eye,
|
||||||
bounds,
|
bounds,
|
||||||
self.tabs[i].scene.document.header.lineweight_display,
|
crate::ui::overlay::pick_box_aperture_px(self.pick_box) * 2.0,
|
||||||
crate::ui::overlay::pick_box_aperture_px(self.pick_box),
|
);
|
||||||
)
|
let candidate_handles = self.tabs[i]
|
||||||
.and_then(|s| Scene::handle_from_wire_name(s))
|
.scene
|
||||||
.or_else(|| {
|
.interaction_candidate_handles(&click_candidates);
|
||||||
scene::pick::hit_test::click_hit_hatch(
|
|
||||||
|
// Selection cycling: where two or more objects
|
||||||
|
// overlap, open a list box to pick which one; a
|
||||||
|
// single object falls through to the normal click.
|
||||||
|
// Gated behind the toggle, so default picking is
|
||||||
|
// unchanged when off.
|
||||||
|
let mut handled_by_cycling = false;
|
||||||
|
if self.selection_cycling {
|
||||||
|
let cands: Vec<Handle> = scene::pick::hit_test::click_hits_all(
|
||||||
p,
|
p,
|
||||||
&self.tabs[i]
|
&click_candidates,
|
||||||
.scene
|
|
||||||
.visible_hatches_for_click(candidate_handles.as_ref()),
|
|
||||||
view_rot,
|
view_rot,
|
||||||
eye,
|
eye,
|
||||||
bounds,
|
bounds,
|
||||||
candidate_handles.as_ref(),
|
self.tabs[i].scene.document.header.lineweight_display,
|
||||||
)
|
|
||||||
})
|
|
||||||
.or_else(|| {
|
|
||||||
// Block-internal hatch: resolve to the parent Insert.
|
|
||||||
scene::pick::hit_test::click_hit_insert_hatch(
|
|
||||||
p,
|
|
||||||
self.tabs[i].scene.insert_hatches_for_click().as_ref(),
|
|
||||||
view_rot,
|
|
||||||
eye,
|
|
||||||
bounds,
|
|
||||||
candidate_handles.as_ref(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.or_else(|| {
|
|
||||||
// Normal 3D selection follows the displayed B-rep
|
|
||||||
// edges. Face-interior picking remains reserved for
|
|
||||||
// modelling commands that explicitly request it.
|
|
||||||
self.tabs[i].scene.solid_edge_click_hit(
|
|
||||||
p,
|
|
||||||
view_rot,
|
|
||||||
eye,
|
|
||||||
bounds,
|
|
||||||
candidate_handles.as_ref(),
|
|
||||||
crate::ui::overlay::pick_box_aperture_px(self.pick_box),
|
crate::ui::overlay::pick_box_aperture_px(self.pick_box),
|
||||||
)
|
)
|
||||||
});
|
.into_iter()
|
||||||
// Selection filter: drop a pick whose type is excluded.
|
.filter_map(|s| Scene::handle_from_wire_name(s))
|
||||||
let hit = hit.filter(|&h| self.tabs[i].scene.passes_selection_filter(h));
|
.filter(|&h| self.tabs[i].scene.passes_selection_filter(h))
|
||||||
if let Some(handle) = hit {
|
.collect();
|
||||||
// Individual picks accumulate (issue #47):
|
if cands.len() >= 2 {
|
||||||
// each plain click adds to the selection,
|
// Overlap: open the list box at the cursor.
|
||||||
// Shift+click removes the picked entity.
|
self.cycle_candidates = Some((p_full, cands));
|
||||||
// PICKADD 0 (#226): a plain click
|
handled_by_cycling = true;
|
||||||
// REPLACES the selection instead and
|
}
|
||||||
// Shift+click toggles membership.
|
}
|
||||||
if self.shift_down || self.select_remove_mode {
|
|
||||||
// Remove was asked for by name, so it only
|
if !handled_by_cycling {
|
||||||
// ever takes away — the toggle below is
|
let hit = scene::pick::hit_test::click_hit(
|
||||||
// Shift's PICKADD-0 behaviour, not its.
|
p,
|
||||||
if !self.select_remove_mode
|
&click_candidates,
|
||||||
&& !selection_pick_add
|
view_rot,
|
||||||
&& !self.tabs[i].scene.selected.contains(&handle)
|
eye,
|
||||||
{
|
bounds,
|
||||||
self.tabs[i].scene.select_entity(handle, false);
|
self.tabs[i].scene.document.header.lineweight_display,
|
||||||
self.tabs[i].scene.expand_selection_for_groups(&[handle]);
|
crate::ui::overlay::pick_box_aperture_px(self.pick_box),
|
||||||
|
)
|
||||||
|
.and_then(|s| Scene::handle_from_wire_name(s))
|
||||||
|
.or_else(|| {
|
||||||
|
scene::pick::hit_test::click_hit_hatch(
|
||||||
|
p,
|
||||||
|
&self.tabs[i]
|
||||||
|
.scene
|
||||||
|
.visible_hatches_for_click(candidate_handles.as_ref()),
|
||||||
|
view_rot,
|
||||||
|
eye,
|
||||||
|
bounds,
|
||||||
|
candidate_handles.as_ref(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.or_else(|| {
|
||||||
|
// Block-internal hatch: resolve to the parent Insert.
|
||||||
|
scene::pick::hit_test::click_hit_insert_hatch(
|
||||||
|
p,
|
||||||
|
self.tabs[i].scene.insert_hatches_for_click().as_ref(),
|
||||||
|
view_rot,
|
||||||
|
eye,
|
||||||
|
bounds,
|
||||||
|
candidate_handles.as_ref(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.or_else(|| {
|
||||||
|
// Normal 3D selection follows the displayed B-rep
|
||||||
|
// edges. Face-interior picking remains reserved for
|
||||||
|
// modelling commands that explicitly request it.
|
||||||
|
self.tabs[i].scene.solid_edge_click_hit(
|
||||||
|
p,
|
||||||
|
view_rot,
|
||||||
|
eye,
|
||||||
|
bounds,
|
||||||
|
candidate_handles.as_ref(),
|
||||||
|
crate::ui::overlay::pick_box_aperture_px(self.pick_box),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
// Selection filter: drop a pick whose type is excluded.
|
||||||
|
let hit =
|
||||||
|
hit.filter(|&h| self.tabs[i].scene.passes_selection_filter(h));
|
||||||
|
if let Some(handle) = hit {
|
||||||
|
// Individual picks accumulate (issue #47):
|
||||||
|
// each plain click adds to the selection,
|
||||||
|
// Shift+click removes the picked entity.
|
||||||
|
// PICKADD 0 (#226): a plain click
|
||||||
|
// REPLACES the selection instead and
|
||||||
|
// Shift+click toggles membership.
|
||||||
|
if self.shift_down || self.select_remove_mode {
|
||||||
|
// Remove was asked for by name, so it only
|
||||||
|
// ever takes away — the toggle below is
|
||||||
|
// Shift's PICKADD-0 behaviour, not its.
|
||||||
|
if !self.select_remove_mode
|
||||||
|
&& !selection_pick_add
|
||||||
|
&& !self.tabs[i].scene.selected.contains(&handle)
|
||||||
|
{
|
||||||
|
self.tabs[i].scene.select_entity(handle, false);
|
||||||
|
self.tabs[i].scene.expand_selection_for_groups(&[handle]);
|
||||||
|
} else {
|
||||||
|
self.tabs[i].scene.deselect_entity(handle);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
self.tabs[i].scene.deselect_entity(handle);
|
self.tabs[i]
|
||||||
|
.scene
|
||||||
|
.select_entity(handle, !selection_pick_add);
|
||||||
|
self.tabs[i].scene.expand_selection_for_groups(&[handle]);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
self.tabs[i]
|
|
||||||
.scene
|
|
||||||
.select_entity(handle, !selection_pick_add);
|
|
||||||
self.tabs[i].scene.expand_selection_for_groups(&[handle]);
|
|
||||||
}
|
|
||||||
self.refresh_properties();
|
|
||||||
selection_just_completed = true;
|
|
||||||
} else {
|
|
||||||
// Empty-space click only ARMS a box here; it
|
|
||||||
// no longer clears the selection, so a box can
|
|
||||||
// add to it (issue #83). The box completion
|
|
||||||
// (or Esc) decides what happens to the
|
|
||||||
// selection.
|
|
||||||
// PICKADD 0 (#226): OS convention — the
|
|
||||||
// empty click also drops the selection.
|
|
||||||
if !selection_pick_add && !self.shift_down {
|
|
||||||
self.tabs[i].scene.deselect_all();
|
|
||||||
self.refresh_properties();
|
self.refresh_properties();
|
||||||
}
|
selection_just_completed = true;
|
||||||
// Pin the anchor to the world point under it
|
} else {
|
||||||
// so a zoom/pan mid-drag re-projects it
|
// Empty-space click only ARMS a box here; it
|
||||||
// instead of leaving it frozen in pixels
|
// no longer clears the selection, so a box can
|
||||||
// (#234). Computed before the selection
|
// add to it (issue #83). The box completion
|
||||||
// borrow so the &self projection can't clash.
|
// (or Esc) decides what happens to the
|
||||||
let anchor_world = self.cursor_model_point(i, &edit_cam, p, bounds);
|
// selection.
|
||||||
if let Some(t) = t_arm {
|
// PICKADD 0 (#226): OS convention — the
|
||||||
let arm_ms = t.elapsed().as_secs_f64() * 1000.0;
|
// empty click also drops the selection.
|
||||||
if arm_ms >= 5.0 {
|
if !selection_pick_add && !self.shift_down {
|
||||||
crate::perf_record!(
|
self.tabs[i].scene.deselect_all();
|
||||||
"[perf] select-arm {arm_ms:>7.1}ms pick+clear, \
|
self.refresh_properties();
|
||||||
|
}
|
||||||
|
// Pin the anchor to the world point under it
|
||||||
|
// so a zoom/pan mid-drag re-projects it
|
||||||
|
// instead of leaving it frozen in pixels
|
||||||
|
// (#234). Computed before the selection
|
||||||
|
// borrow so the &self projection can't clash.
|
||||||
|
let anchor_world = self.cursor_model_point(i, &edit_cam, p, bounds);
|
||||||
|
if let Some(t) = t_arm {
|
||||||
|
let arm_ms = t.elapsed().as_secs_f64() * 1000.0;
|
||||||
|
if arm_ms >= 5.0 {
|
||||||
|
crate::perf_record!(
|
||||||
|
"[perf] select-arm {arm_ms:>7.1}ms pick+clear, \
|
||||||
was_selected={}",
|
was_selected={}",
|
||||||
prior_selection,
|
prior_selection,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut sel = self.tabs[i].scene.selection.borrow_mut();
|
||||||
|
// Full-canvas space: ViewportMove updates
|
||||||
|
// box_current in canvas coords and the overlay
|
||||||
|
// draws there; release maps back into the tile.
|
||||||
|
sel.box_anchor = Some(p_full);
|
||||||
|
sel.box_current = Some(p_full);
|
||||||
|
sel.box_anchor_world = Some(anchor_world);
|
||||||
|
if !sel.box_crossing_locked {
|
||||||
|
sel.box_crossing = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
let mut sel = self.tabs[i].scene.selection.borrow_mut();
|
|
||||||
// Full-canvas space: ViewportMove updates
|
|
||||||
// box_current in canvas coords and the overlay
|
|
||||||
// draws there; release maps back into the tile.
|
|
||||||
sel.box_anchor = Some(p_full);
|
|
||||||
sel.box_current = Some(p_full);
|
|
||||||
sel.box_anchor_world = Some(anchor_world);
|
|
||||||
if !sel.box_crossing_locked {
|
|
||||||
sel.box_crossing = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-63
@@ -813,71 +813,22 @@ bg={bg_ms:.1}ms n={view_count}"
|
|||||||
.active_cmd
|
.active_cmd
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.is_some_and(|cmd| !cmd.needs_entity_pick() && !cmd.is_selection_gathering());
|
.is_some_and(|cmd| !cmd.needs_entity_pick() && !cmd.is_selection_gathering());
|
||||||
// Constraint glyphs are displayed in model space only.
|
let constraint_glyphs: Vec<(iced::Point, [f32; 2], String, bool, bool)> = if is_paper {
|
||||||
let constraint_glyphs: Vec<(iced::Point, [f32; 2], String, bool)> = if is_paper {
|
|
||||||
Vec::new()
|
Vec::new()
|
||||||
} else {
|
} else {
|
||||||
let (vw, vh) = sel_ref.vp_size;
|
|
||||||
let scope = tab.current_parametric_scope();
|
let scope = tab.current_parametric_scope();
|
||||||
match tab.scene.parametric_constraint_set(scope) {
|
tab.scene
|
||||||
Some(set) if !set.constraints.is_empty() => {
|
.constraint_glyph_placements_screen(
|
||||||
let edit_frame = tab.scene.viewport_edit_frame((vw, vh));
|
scope,
|
||||||
let bounds = match &edit_frame {
|
sel_ref.vp_size,
|
||||||
Some((_, full)) => *full,
|
self.show_constraint_values,
|
||||||
None => tab.scene.active_model_tile_bounds(vw, vh),
|
)
|
||||||
};
|
.into_iter()
|
||||||
let (view_rot, eye) = if let Some((cam, _)) = &edit_frame {
|
.map(|(id, point, direction, label, is_conflicting)| {
|
||||||
(cam.view_proj_rte(bounds), cam.eye())
|
let selected = tab.scene.selected_constraint == Some(id);
|
||||||
} else {
|
(point, direction, label, is_conflicting, selected)
|
||||||
let cam = tab.scene.camera.borrow();
|
})
|
||||||
(cam.view_proj_rte(bounds), cam.eye())
|
.collect()
|
||||||
};
|
|
||||||
set.constraints
|
|
||||||
.iter()
|
|
||||||
.filter(|c| c.enabled)
|
|
||||||
.filter(|c| tab.scene.is_parametric_constraint_visible(scope, c.id))
|
|
||||||
.filter_map(|c| {
|
|
||||||
let (anchor, outward) =
|
|
||||||
crate::scene::parametric_constraints::glyph_placement(
|
|
||||||
&tab.scene.document,
|
|
||||||
c,
|
|
||||||
)?;
|
|
||||||
let screen = crate::scene::pick::grip::project_rte(
|
|
||||||
glam::DVec3::new(anchor.x, anchor.y, anchor.z),
|
|
||||||
view_rot,
|
|
||||||
eye,
|
|
||||||
bounds,
|
|
||||||
)?;
|
|
||||||
let outward_screen = crate::scene::pick::grip::project_rte(
|
|
||||||
glam::DVec3::new(
|
|
||||||
anchor.x + outward.x,
|
|
||||||
anchor.y + outward.y,
|
|
||||||
anchor.z + outward.z,
|
|
||||||
),
|
|
||||||
view_rot,
|
|
||||||
eye,
|
|
||||||
bounds,
|
|
||||||
)?;
|
|
||||||
let direction =
|
|
||||||
(outward_screen - screen).normalize_or(glam::Vec2::NEG_Y);
|
|
||||||
let point =
|
|
||||||
iced::Point::new(bounds.x + screen.x, bounds.y + screen.y);
|
|
||||||
let is_conflicting =
|
|
||||||
set.conflicts.iter().any(|(id, _)| *id == c.id);
|
|
||||||
let label = if self.show_constraint_values {
|
|
||||||
crate::scene::parametric_constraints::glyph_label(c)
|
|
||||||
} else {
|
|
||||||
c.kind.glyph_symbol().to_string()
|
|
||||||
};
|
|
||||||
point
|
|
||||||
.x
|
|
||||||
.is_finite()
|
|
||||||
.then(|| (point, direction.to_array(), label, is_conflicting))
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
_ => Vec::new(),
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
crate::ui::overlay::selection_overlay(
|
crate::ui::overlay::selection_overlay(
|
||||||
std::sync::Arc::clone(&tab.scene.selection),
|
std::sync::Arc::clone(&tab.scene.selection),
|
||||||
@@ -1624,7 +1575,6 @@ bg={bg_ms:.1}ms n={view_count}"
|
|||||||
} else {
|
} else {
|
||||||
34.0
|
34.0
|
||||||
};
|
};
|
||||||
|
|
||||||
// Quick Properties: stay near the selection cursor, flipping around
|
// Quick Properties: stay near the selection cursor, flipping around
|
||||||
// it as needed to remain inside the visible drawing area.
|
// it as needed to remain inside the visible drawing area.
|
||||||
if self.quick_properties && !tab.is_start {
|
if self.quick_properties && !tab.is_start {
|
||||||
@@ -1798,6 +1748,7 @@ bg={bg_ms:.1}ms n={view_count}"
|
|||||||
command_line_inset,
|
command_line_inset,
|
||||||
has_cmd,
|
has_cmd,
|
||||||
has_selection,
|
has_selection,
|
||||||
|
tab.scene.selected_constraint,
|
||||||
isolation_active,
|
isolation_active,
|
||||||
last_cmds,
|
last_cmds,
|
||||||
draworder_open,
|
draworder_open,
|
||||||
|
|||||||
@@ -1114,6 +1114,7 @@ pub(super) fn viewport_context_menu_overlay(
|
|||||||
bottom_inset: f32,
|
bottom_inset: f32,
|
||||||
has_cmd: bool,
|
has_cmd: bool,
|
||||||
has_selection: bool,
|
has_selection: bool,
|
||||||
|
selected_constraint: Option<crate::scene::parametric_constraints::ConstraintId>,
|
||||||
isolation_active: bool,
|
isolation_active: bool,
|
||||||
last_cmds: Vec<String>,
|
last_cmds: Vec<String>,
|
||||||
draworder_open: bool,
|
draworder_open: bool,
|
||||||
@@ -1250,6 +1251,15 @@ pub(super) fn viewport_context_menu_overlay(
|
|||||||
t!("Invert Selection").into_owned(),
|
t!("Invert Selection").into_owned(),
|
||||||
Message::InvertSelection,
|
Message::InvertSelection,
|
||||||
));
|
));
|
||||||
|
} else if let Some(id) = selected_constraint {
|
||||||
|
// A selected constraint-glyph pill gets its own minimal menu —
|
||||||
|
// none of the entity-selection actions above (Move/Copy/Isolate/
|
||||||
|
// Select Similar) apply to it.
|
||||||
|
items.push(item(
|
||||||
|
t!("Delete Constraint").into_owned(),
|
||||||
|
Message::PropConstraintDelete(id),
|
||||||
|
));
|
||||||
|
items.push(sep());
|
||||||
}
|
}
|
||||||
if isolation_active {
|
if isolation_active {
|
||||||
items.push(item(
|
items.push(item(
|
||||||
|
|||||||
@@ -304,6 +304,14 @@ impl AlignCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inventory::submit!(crate::command::CommandRegistration { names: &["ALIGN"] }); // AlignCommand
|
inventory::submit!(crate::command::CommandRegistration { names: &["ALIGN"] }); // AlignCommand
|
||||||
|
// ALIGNLEFT/ALIGNHCENTER/ALIGNRIGHT/ALIGNTOP/ALIGNVCENTER/ALIGNBOTTOM: one-shot
|
||||||
|
// bounding-box alignment, dispatched directly (no CadCommand of their own) by
|
||||||
|
// `OpenCADStudio::align_selected_bounds` in `src/app/commands/inquiry.rs`.
|
||||||
|
inventory::submit!(crate::command::CommandRegistration {
|
||||||
|
names: &[
|
||||||
|
"ALIGNLEFT", "ALIGNHCENTER", "ALIGNRIGHT", "ALIGNTOP", "ALIGNVCENTER", "ALIGNBOTTOM",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
@@ -203,6 +203,42 @@ impl Scene {
|
|||||||
self.bump_selection_set();
|
self.bump_selection_set();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Partition selected entity handles into visual objects for operations
|
||||||
|
/// such as edge alignment. A selectable CAD group is one object and must
|
||||||
|
/// receive one shared transform; treating its member lines independently
|
||||||
|
/// can collapse a rectangle or triangle onto its own edge.
|
||||||
|
pub fn selected_object_units(&self, handles: &[Handle]) -> Vec<Vec<Handle>> {
|
||||||
|
let selected: HashSet<Handle> = handles.iter().copied().collect();
|
||||||
|
let mut claimed = HashSet::default();
|
||||||
|
let mut units = Vec::new();
|
||||||
|
for group in self.groups().filter(|group| group.selectable) {
|
||||||
|
let members: Vec<_> = group
|
||||||
|
.entities
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.filter(|handle| selected.contains(handle))
|
||||||
|
.collect();
|
||||||
|
if !members.is_empty()
|
||||||
|
&& members.iter().all(|handle| !claimed.contains(handle))
|
||||||
|
&& group
|
||||||
|
.entities
|
||||||
|
.iter()
|
||||||
|
.all(|handle| selected.contains(handle))
|
||||||
|
{
|
||||||
|
claimed.extend(members.iter().copied());
|
||||||
|
units.push(members);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
units.extend(
|
||||||
|
handles
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.filter(|handle| !claimed.contains(handle))
|
||||||
|
.map(|handle| vec![handle]),
|
||||||
|
);
|
||||||
|
units
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -247,4 +283,31 @@ mod group_expansion_tests {
|
|||||||
assert_eq!(both, [a, b, c, d, e].into_iter().collect::<HashSet<_>>());
|
assert_eq!(both, [a, b, c, d, e].into_iter().collect::<HashSet<_>>());
|
||||||
assert!(!both.contains(&lonely));
|
assert!(!both.contains(&lonely));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `selected_object_units` is `Scene::selected_object_units`'s
|
||||||
|
/// counterpart for operations like edge alignment (`ALIGNTOP`, etc.):
|
||||||
|
/// a complete, fully-selected group collapses to one unit sharing a
|
||||||
|
/// single transform, so aligning a triangle's edge to another object
|
||||||
|
/// moves the whole triangle rather than collapsing its own lines onto
|
||||||
|
/// each other.
|
||||||
|
#[test]
|
||||||
|
fn selected_object_units_keep_a_complete_group_together() {
|
||||||
|
use acadrust::entities::{EntityType, Line};
|
||||||
|
use acadrust::types::Vector3;
|
||||||
|
|
||||||
|
let mut scene = Scene::new();
|
||||||
|
let mut line = |x: f64| {
|
||||||
|
scene.add_entity(EntityType::Line(Line::from_points(
|
||||||
|
Vector3::new(x, 0.0, 0.0),
|
||||||
|
Vector3::new(x + 1.0, 0.0, 0.0),
|
||||||
|
)))
|
||||||
|
};
|
||||||
|
let (a, b, c, standalone) = (line(0.0), line(1.0), line(2.0), line(10.0));
|
||||||
|
scene.create_group("triangle".into(), vec![a, b, c]);
|
||||||
|
|
||||||
|
let units = scene.selected_object_units(&[a, b, c, standalone]);
|
||||||
|
assert_eq!(units.len(), 2);
|
||||||
|
assert!(units.iter().any(|unit| unit == &vec![a, b, c]));
|
||||||
|
assert!(units.iter().any(|unit| unit == &vec![standalone]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1658,6 +1658,9 @@ pub struct Scene {
|
|||||||
/// Currently selected entity handles.
|
/// Currently selected entity handles.
|
||||||
pub selected: HashSet<Handle>,
|
pub selected: HashSet<Handle>,
|
||||||
selected_order: Vec<Handle>,
|
selected_order: Vec<Handle>,
|
||||||
|
/// The parametric-constraint glyph currently selected in the viewport.
|
||||||
|
/// Entity selection changes clear it so the two selections stay exclusive.
|
||||||
|
pub selected_constraint: Option<crate::scene::parametric_constraints::ConstraintId>,
|
||||||
/// Session-only ISOLATEOBJECTS / HIDEOBJECTS state. Never written to DWG/DXF.
|
/// Session-only ISOLATEOBJECTS / HIDEOBJECTS state. Never written to DWG/DXF.
|
||||||
pub object_isolation: ObjectIsolationState,
|
pub object_isolation: ObjectIsolationState,
|
||||||
/// Entity handles temporarily removed from the base render while an
|
/// Entity handles temporarily removed from the base render while an
|
||||||
@@ -2194,6 +2197,7 @@ impl Scene {
|
|||||||
lighting_cache: RefCell::new(HashMap::default()),
|
lighting_cache: RefCell::new(HashMap::default()),
|
||||||
selected: HashSet::default(),
|
selected: HashSet::default(),
|
||||||
selected_order: Vec::new(),
|
selected_order: Vec::new(),
|
||||||
|
selected_constraint: None,
|
||||||
object_isolation: ObjectIsolationState::default(),
|
object_isolation: ObjectIsolationState::default(),
|
||||||
preview_hidden: HashSet::default(),
|
preview_hidden: HashSet::default(),
|
||||||
command_preview_hidden: HashSet::default(),
|
command_preview_hidden: HashSet::default(),
|
||||||
|
|||||||
@@ -790,6 +790,98 @@ impl super::Scene {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Screen-projected parametric-constraint glyph placements for `scope`:
|
||||||
|
/// `(id, anchor, outward_screen_direction, label, is_conflicting)` for
|
||||||
|
/// every enabled, visible constraint whose glyph projects on-screen.
|
||||||
|
/// `vp_size` is the full canvas size (as `SelectionState::vp_size`
|
||||||
|
/// reports it), matching what `viewport_edit_frame`/
|
||||||
|
/// `active_model_tile_bounds` expect. Mirrors the projection
|
||||||
|
/// `crate::app::view` builds its own render list with, and is reused by
|
||||||
|
/// [`constraint_glyph_hit`](Self::constraint_glyph_hit) — both feed the
|
||||||
|
/// same `(anchor, outward, label)` triples into
|
||||||
|
/// `crate::ui::overlay::constraint_glyph_box`/`constraint_glyph_offsets`,
|
||||||
|
/// so hit-testing can never drift from what's actually drawn.
|
||||||
|
pub fn constraint_glyph_placements_screen(
|
||||||
|
&self,
|
||||||
|
scope: ParametricScope,
|
||||||
|
vp_size: (f32, f32),
|
||||||
|
show_values: bool,
|
||||||
|
) -> Vec<(ConstraintId, iced::Point, [f32; 2], String, bool)> {
|
||||||
|
let Some(set) = self.parametric_constraint_set(scope) else {
|
||||||
|
return Vec::new();
|
||||||
|
};
|
||||||
|
if set.constraints.is_empty() {
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
let edit_frame = self.viewport_edit_frame(vp_size);
|
||||||
|
let bounds = match &edit_frame {
|
||||||
|
Some((_, full)) => *full,
|
||||||
|
None => self.active_model_tile_bounds(vp_size.0, vp_size.1),
|
||||||
|
};
|
||||||
|
let (view_rot, eye) = if let Some((cam, _)) = &edit_frame {
|
||||||
|
(cam.view_proj_rte(bounds), cam.eye())
|
||||||
|
} else {
|
||||||
|
let cam = self.camera.borrow();
|
||||||
|
(cam.view_proj_rte(bounds), cam.eye())
|
||||||
|
};
|
||||||
|
set.constraints
|
||||||
|
.iter()
|
||||||
|
.filter(|c| c.enabled)
|
||||||
|
.filter(|c| self.is_parametric_constraint_visible(scope, c.id))
|
||||||
|
.filter_map(|c| {
|
||||||
|
let (anchor, outward) = glyph_placement(&self.document, c)?;
|
||||||
|
let screen = crate::scene::pick::grip::project_rte(
|
||||||
|
glam::DVec3::new(anchor.x, anchor.y, anchor.z),
|
||||||
|
view_rot,
|
||||||
|
eye,
|
||||||
|
bounds,
|
||||||
|
)?;
|
||||||
|
let outward_screen = crate::scene::pick::grip::project_rte(
|
||||||
|
glam::DVec3::new(
|
||||||
|
anchor.x + outward.x,
|
||||||
|
anchor.y + outward.y,
|
||||||
|
anchor.z + outward.z,
|
||||||
|
),
|
||||||
|
view_rot,
|
||||||
|
eye,
|
||||||
|
bounds,
|
||||||
|
)?;
|
||||||
|
let direction = (outward_screen - screen).normalize_or(glam::Vec2::NEG_Y);
|
||||||
|
let point = iced::Point::new(bounds.x + screen.x, bounds.y + screen.y);
|
||||||
|
let is_conflicting = set.conflicts.iter().any(|(id, _)| *id == c.id);
|
||||||
|
let label = if show_values {
|
||||||
|
glyph_label(c)
|
||||||
|
} else {
|
||||||
|
c.kind.glyph_symbol().to_string()
|
||||||
|
};
|
||||||
|
point.x.is_finite().then_some((c.id, point, direction.to_array(), label, is_conflicting))
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Hit-tests screen point `p` (same coordinate space as `p_full` in the
|
||||||
|
/// viewport click handler) against the glyph pills from
|
||||||
|
/// [`constraint_glyph_placements_screen`](Self::constraint_glyph_placements_screen),
|
||||||
|
/// via `crate::ui::overlay::constraint_glyph_hit_test`'s shared layout
|
||||||
|
/// math, so a click only registers where the pill is actually drawn.
|
||||||
|
pub fn constraint_glyph_hit(
|
||||||
|
&self,
|
||||||
|
scope: ParametricScope,
|
||||||
|
vp_size: (f32, f32),
|
||||||
|
show_values: bool,
|
||||||
|
p: iced::Point,
|
||||||
|
) -> Option<ConstraintId> {
|
||||||
|
let placements = self.constraint_glyph_placements_screen(scope, vp_size, show_values);
|
||||||
|
let glyphs: Vec<(iced::Point, [f32; 2], String, bool)> = placements
|
||||||
|
.iter()
|
||||||
|
.map(|(_, point, direction, label, is_conflicting)| {
|
||||||
|
(*point, *direction, label.clone(), *is_conflicting)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let index = crate::ui::overlay::constraint_glyph_hit_test(&glyphs, p)?;
|
||||||
|
Some(placements[index].0)
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle remapping lives in each command that duplicates
|
/// Handle remapping lives in each command that duplicates
|
||||||
/// entities — `Scene::copy_entities`' `handle_map` (COPY/ARRAY/MIRROR,
|
/// entities — `Scene::copy_entities`' `handle_map` (COPY/ARRAY/MIRROR,
|
||||||
/// `src/scene/modify.rs`) and `OpenCADStudio::finalize_paste`'s own
|
/// `src/scene/modify.rs`) and `OpenCADStudio::finalize_paste`'s own
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ impl Scene {
|
|||||||
if handles.is_empty() {
|
if handles.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
self.selected_constraint = None;
|
||||||
let expanded = self.expanded_with_leaders(handles);
|
let expanded = self.expanded_with_leaders(handles);
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
for handle in expanded {
|
for handle in expanded {
|
||||||
@@ -111,6 +112,7 @@ impl Scene {
|
|||||||
expanded
|
expanded
|
||||||
}
|
}
|
||||||
pub fn select_entity(&mut self, handle: Handle, exclusive: bool) {
|
pub fn select_entity(&mut self, handle: Handle, exclusive: bool) {
|
||||||
|
self.selected_constraint = None;
|
||||||
let handles = self.handles_expanded_for_leader_annotations(&[handle]);
|
let handles = self.handles_expanded_for_leader_annotations(&[handle]);
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
|
|
||||||
@@ -133,6 +135,7 @@ impl Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn deselect_all(&mut self) {
|
pub fn deselect_all(&mut self) {
|
||||||
|
self.selected_constraint = None;
|
||||||
if self.selected.is_empty() {
|
if self.selected.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -215,6 +218,7 @@ impl Scene {
|
|||||||
/// only when its contents actually changed. History/file/command paths must
|
/// only when its contents actually changed. History/file/command paths must
|
||||||
/// use this instead of assigning `selected` directly.
|
/// use this instead of assigning `selected` directly.
|
||||||
pub(crate) fn replace_selection(&mut self, selected: HashSet<Handle>) {
|
pub(crate) fn replace_selection(&mut self, selected: HashSet<Handle>) {
|
||||||
|
self.selected_constraint = None;
|
||||||
let handles: Vec<Handle> = selected.iter().copied().collect();
|
let handles: Vec<Handle> = selected.iter().copied().collect();
|
||||||
let selected: HashSet<Handle> = self
|
let selected: HashSet<Handle> = self
|
||||||
.handles_expanded_for_leader_annotations(&handles)
|
.handles_expanded_for_leader_annotations(&handles)
|
||||||
|
|||||||
+54
-6
@@ -94,6 +94,32 @@ fn constraint_glyph_offsets(glyphs: &[(Point, [f32; 2], String, bool)]) -> Vec<f
|
|||||||
offsets
|
offsets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Hit-tests screen point `p` against the same glyph-pill layout `draw`
|
||||||
|
/// renders — reusing `constraint_glyph_offsets`/`constraint_glyph_box` so
|
||||||
|
/// the clickable area can never drift from what's actually drawn, including
|
||||||
|
/// the tangential fan-out applied when several glyphs share one anchor.
|
||||||
|
/// Returns the index into `glyphs` of the topmost (last-drawn) match.
|
||||||
|
/// `Scene::constraint_glyph_hit` maps the index back to a constraint id.
|
||||||
|
pub(crate) fn constraint_glyph_hit_test(
|
||||||
|
glyphs: &[(Point, [f32; 2], String, bool)],
|
||||||
|
p: Point,
|
||||||
|
) -> Option<usize> {
|
||||||
|
let offsets = constraint_glyph_offsets(glyphs);
|
||||||
|
glyphs
|
||||||
|
.iter()
|
||||||
|
.zip(offsets)
|
||||||
|
.enumerate()
|
||||||
|
.rev()
|
||||||
|
.find_map(|(index, ((anchor, outward, label, _), tangent_offset))| {
|
||||||
|
let (top_left, size) = constraint_glyph_box(*anchor, *outward, label, tangent_offset);
|
||||||
|
let within = p.x >= top_left.x
|
||||||
|
&& p.x <= top_left.x + size.width
|
||||||
|
&& p.y >= top_left.y
|
||||||
|
&& p.y <= top_left.y + size.height;
|
||||||
|
within.then_some(index)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Convert CURSORSIZE to a screen-space arm length while keeping the original
|
/// Convert CURSORSIZE to a screen-space arm length while keeping the original
|
||||||
/// 60 px cursor at the default value and the full-viewport result at 100.
|
/// 60 px cursor at the default value and the full-viewport result at 100.
|
||||||
pub(crate) fn crosshair_arm_px(bounds: iced::Rectangle, value: i32) -> f32 {
|
pub(crate) fn crosshair_arm_px(bounds: iced::Rectangle, value: i32) -> f32 {
|
||||||
@@ -723,7 +749,7 @@ pub fn selection_overlay<'a>(
|
|||||||
crosshair_bg: [f32; 4],
|
crosshair_bg: [f32; 4],
|
||||||
crosshair: CrosshairOptions,
|
crosshair: CrosshairOptions,
|
||||||
selection_visual: SelectionVisualOptions,
|
selection_visual: SelectionVisualOptions,
|
||||||
constraint_glyphs: Vec<(Point, [f32; 2], String, bool)>,
|
constraint_glyphs: Vec<(Point, [f32; 2], String, bool, bool)>,
|
||||||
) -> Element<'a, Message> {
|
) -> Element<'a, Message> {
|
||||||
canvas(SelectionCanvas {
|
canvas(SelectionCanvas {
|
||||||
selection,
|
selection,
|
||||||
@@ -806,8 +832,10 @@ struct SelectionCanvas {
|
|||||||
crosshair_bg: [f32; 4],
|
crosshair_bg: [f32; 4],
|
||||||
crosshair: CrosshairOptions,
|
crosshair: CrosshairOptions,
|
||||||
selection_visual: SelectionVisualOptions,
|
selection_visual: SelectionVisualOptions,
|
||||||
/// Constraint glyph anchor, outward screen direction, label, and conflict state.
|
/// Constraint glyph anchor, outward screen direction, label, conflict
|
||||||
constraint_glyphs: Vec<(Point, [f32; 2], String, bool)>,
|
/// state, and whether the pill itself is the current click-to-select
|
||||||
|
/// target (`Scene::selected_constraint`) — for the current scope.
|
||||||
|
constraint_glyphs: Vec<(Point, [f32; 2], String, bool, bool)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_grip_marker(
|
fn draw_grip_marker(
|
||||||
@@ -1703,9 +1731,19 @@ impl canvas::Program<Message> for SelectionCanvas {
|
|||||||
frame.stroke(&b1, stroke.clone());
|
frame.stroke(&b1, stroke.clone());
|
||||||
frame.stroke(&b2, stroke);
|
frame.stroke(&b2, stroke);
|
||||||
}
|
}
|
||||||
// Constraint glyphs are visual-only and have no hit testing.
|
// Hit testing shares this layout math with the scene projection.
|
||||||
if !self.constraint_glyphs.is_empty() {
|
if !self.constraint_glyphs.is_empty() {
|
||||||
let offsets = constraint_glyph_offsets(&self.constraint_glyphs);
|
// `constraint_glyph_offsets` only needs the anchor/outward/label/
|
||||||
|
// conflict quadruple it was written against; project away the
|
||||||
|
// trailing `is_selected` flag rather than widen its signature.
|
||||||
|
let glyphs_for_offsets: Vec<(Point, [f32; 2], String, bool)> = self
|
||||||
|
.constraint_glyphs
|
||||||
|
.iter()
|
||||||
|
.map(|(anchor, outward, label, is_conflicting, _)| {
|
||||||
|
(*anchor, *outward, label.clone(), *is_conflicting)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let offsets = constraint_glyph_offsets(&glyphs_for_offsets);
|
||||||
let normal_bg = theme.palette().primary.base.color;
|
let normal_bg = theme.palette().primary.base.color;
|
||||||
let normal_fg = theme.palette().primary.base.text;
|
let normal_fg = theme.palette().primary.base.text;
|
||||||
// A redundant or conflicting constraint gets the danger palette
|
// A redundant or conflicting constraint gets the danger palette
|
||||||
@@ -1714,7 +1752,8 @@ impl canvas::Program<Message> for SelectionCanvas {
|
|||||||
// would show, surfaced right on the geometry.
|
// would show, surfaced right on the geometry.
|
||||||
let conflict_bg = theme.palette().danger.base.color;
|
let conflict_bg = theme.palette().danger.base.color;
|
||||||
let conflict_fg = theme.palette().danger.base.text;
|
let conflict_fg = theme.palette().danger.base.text;
|
||||||
for ((anchor, outward, label, is_conflicting), tangent_offset) in
|
let selected_ring = theme.palette().primary.strong.color;
|
||||||
|
for ((anchor, outward, label, is_conflicting, is_selected), tangent_offset) in
|
||||||
self.constraint_glyphs.iter().zip(offsets)
|
self.constraint_glyphs.iter().zip(offsets)
|
||||||
{
|
{
|
||||||
if !anchor.x.is_finite() || !anchor.y.is_finite() {
|
if !anchor.x.is_finite() || !anchor.y.is_finite() {
|
||||||
@@ -1729,6 +1768,12 @@ impl canvas::Program<Message> for SelectionCanvas {
|
|||||||
(size.height * 0.5).into(),
|
(size.height * 0.5).into(),
|
||||||
);
|
);
|
||||||
frame.fill(&pill, bg);
|
frame.fill(&pill, bg);
|
||||||
|
if *is_selected {
|
||||||
|
frame.stroke(
|
||||||
|
&pill,
|
||||||
|
canvas::Stroke::default().with_color(selected_ring).with_width(2.0),
|
||||||
|
);
|
||||||
|
}
|
||||||
frame.fill_text(canvas::Text {
|
frame.fill_text(canvas::Text {
|
||||||
content: label.clone(),
|
content: label.clone(),
|
||||||
position: Point::new(
|
position: Point::new(
|
||||||
@@ -3424,6 +3469,9 @@ mod constraint_glyph_tests {
|
|||||||
assert!(
|
assert!(
|
||||||
(anchor.y - (left.y + right_size.height) - CONSTRAINT_GLYPH_GAP).abs() < 1e-6
|
(anchor.y - (left.y + right_size.height) - CONSTRAINT_GLYPH_GAP).abs() < 1e-6
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let click = Point::new(left.x + left_size.width * 0.5, left.y + left_size.height * 0.5);
|
||||||
|
assert_eq!(constraint_glyph_hit_test(&glyphs, click), Some(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,47 @@ pub(super) const TOOLS: &[Tool] = &[
|
|||||||
icon: include_bytes!("../../../assets/icons/modify_align.svg"),
|
icon: include_bytes!("../../../assets/icons/modify_align.svg"),
|
||||||
options: &[],
|
options: &[],
|
||||||
},
|
},
|
||||||
|
// ALIGNLEFT/ALIGNHCENTER/ALIGNRIGHT/ALIGNTOP/ALIGNVCENTER/ALIGNBOTTOM:
|
||||||
|
// one-shot bounding-box alignment of the current selection — distinct
|
||||||
|
// from "ALIGN" above (point-picked 3D placement). No point prompts, so
|
||||||
|
// each is a plain one-click Tool rather than a dropdown submenu, matching
|
||||||
|
// this panel's existing flat-list convention.
|
||||||
|
Tool {
|
||||||
|
command: "ALIGNLEFT",
|
||||||
|
label: "Align Left",
|
||||||
|
icon: include_bytes!("../../../assets/icons/align_left.svg"),
|
||||||
|
options: &[],
|
||||||
|
},
|
||||||
|
Tool {
|
||||||
|
command: "ALIGNHCENTER",
|
||||||
|
label: "Align Horizontal Centers",
|
||||||
|
icon: include_bytes!("../../../assets/icons/align_hcenter.svg"),
|
||||||
|
options: &[],
|
||||||
|
},
|
||||||
|
Tool {
|
||||||
|
command: "ALIGNRIGHT",
|
||||||
|
label: "Align Right",
|
||||||
|
icon: include_bytes!("../../../assets/icons/align_right.svg"),
|
||||||
|
options: &[],
|
||||||
|
},
|
||||||
|
Tool {
|
||||||
|
command: "ALIGNTOP",
|
||||||
|
label: "Align Top",
|
||||||
|
icon: include_bytes!("../../../assets/icons/align_top.svg"),
|
||||||
|
options: &[],
|
||||||
|
},
|
||||||
|
Tool {
|
||||||
|
command: "ALIGNVCENTER",
|
||||||
|
label: "Align Vertical Centers",
|
||||||
|
icon: include_bytes!("../../../assets/icons/align_vcenter.svg"),
|
||||||
|
options: &[],
|
||||||
|
},
|
||||||
|
Tool {
|
||||||
|
command: "ALIGNBOTTOM",
|
||||||
|
label: "Align Bottom",
|
||||||
|
icon: include_bytes!("../../../assets/icons/align_bottom.svg"),
|
||||||
|
options: &[],
|
||||||
|
},
|
||||||
Tool {
|
Tool {
|
||||||
command: "BREAK",
|
command: "BREAK",
|
||||||
label: "Break",
|
label: "Break",
|
||||||
|
|||||||
Reference in new issue
Block a user