Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion crates/ui-egui/src/dialogs_assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2040,11 +2040,31 @@ pub fn origins_world(s: &Session) -> Vec<(String, solidcraft_engine::doc::Mat)>
v
}

/// Is a named joint origin's triad drawn: its occurrence shown (with its parents), and the
/// Joints folder shown in the design and on that placement. Hidden hardware keeps no triad.
pub fn origin_drawn(s: &Session, name: &str) -> bool {
let Some(o) = s.doc.assembly.origins.iter().find(|o| o.name == name) else { return false };
if s.folder_hidden("c0/joints") {
return false;
}
if o.origin.occurrence == 0 {
return true;
}
let Some(occ) = s.doc.occurrences.iter().find(|x| x.id == o.origin.occurrence) else { return false };
// The origin's own placement, not its component's first one (copies hide separately).
let mut path = s.doc.first_path(occ.parent);
path.push(occ.id);
s.occurrence_visible(&path) && !s.folder_hidden(&format!("{}/joints", Session::folder_scope(&path)))
}

/// Named joint origins in the viewport: a small triad where each sits.
pub fn origins(app: &SolveApp, painter: &egui::Painter, proj: &Proj) {
let t = Tokens::get();
let len = app.cam.half_height() * 2.0 * 0.04;
for (_, m) in origins_world(&app.session) {
for (name, m) in origins_world(&app.session) {
if !origin_drawn(&app.session, &name) {
continue;
}
let at = solidcraft_engine::doc::apply_point(&m, Vec3::ZERO);
let Some(c) = proj.to_screen(at) else { continue };
for (axis, col) in [(Vec3::X, t.axis_x), (Vec3::Y, t.axis_y), (Vec3::Z, t.axis_z)] {
Expand Down
31 changes: 31 additions & 0 deletions crates/ui-egui/src/dialogs_assembly_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,37 @@ fn joint_origins_follow_their_component() {
assert!(at(&app).dist(Vec3::new(45.0, 10.0, 25.0)) < 1e-6, "{:?}", at(&app));
}

/// A named joint origin on a hidden occurrence draws no triad; nor does one in a hidden Joints
/// folder (the design's or the placement's). Showing it again brings the triad back.
#[test]
fn joint_origin_triads_follow_occurrence_visibility() {
let mut app = two_boxes();
app.session.execute("joint.origin", &json!({"name": "Top of B", "face": [40, 10, 10]})).unwrap();
assert!(origin_drawn(&app.session, "Top of B"));
let b = occ(&app, "B");
app.session.execute("browser.visibility", &json!({"paths": [[b]], "visible": false})).unwrap();
assert!(!origin_drawn(&app.session, "Top of B"), "a hidden occurrence still draws its origin triad");
app.session.execute("browser.visibility", &json!({"paths": [[b]], "visible": true})).unwrap();
assert!(origin_drawn(&app.session, "Top of B"));
app.session.visibility.hidden_folders.push(format!("o:{b}/joints"));
assert!(!origin_drawn(&app.session, "Top of B"), "the placement's hidden Joints folder");
app.session.visibility.hidden_folders.clear();
app.session.visibility.hidden_folders.push("c0/joints".into());
assert!(!origin_drawn(&app.session, "Top of B"), "the design's hidden Joints folder");
app.session.visibility.hidden_folders.clear();
// On a copy, the triad follows that copy, not the component's first placement.
app.session.execute("occurrence.copy", &json!({"component": "B", "translate": [0, 40, 0]})).unwrap();
app.session.execute("joint.origin", &json!({"name": "Top of copy", "face": [40, 50, 10]})).unwrap();
let copy = app.session.doc.occurrences.iter().find(|o| o.component == app.session.doc.find_component("B").unwrap() && o.id != b).unwrap().id;
assert_eq!(app.session.doc.assembly.origins.iter().find(|o| o.name == "Top of copy").unwrap().origin.occurrence, copy);
app.session.execute("browser.visibility", &json!({"paths": [[b]], "visible": false})).unwrap();
assert!(origin_drawn(&app.session, "Top of copy"), "hiding the first placement hides the copy's triad");
app.session.execute("browser.visibility", &json!({"paths": [[b]], "visible": true})).unwrap();
app.session.execute("browser.visibility", &json!({"paths": [[copy]], "visible": false})).unwrap();
assert!(!origin_drawn(&app.session, "Top of copy"), "a hidden copy still draws its origin triad");
assert!(origin_drawn(&app.session, "Top of B"));
}

/// Edit Feature on a moved component: the dialog shows the feature's picks where the
/// component is (its stored points are in the component's frame).
#[test]
Expand Down
Loading