9b8fa3d357
* claim: #3005 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Browser: a body picked in the viewport is shown in the Browser (#3005) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Merge main; viewport::select takes a toggle flag now Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Phanoob <phanoob@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
6.1 KiB
Rust
109 lines
6.1 KiB
Rust
use std::sync::Arc;
|
|
|
|
use serde_json::json;
|
|
use solidcraft_engine::Sel;
|
|
|
|
use crate::test_support::component_box as fixture;
|
|
|
|
#[test]
|
|
fn navigating_and_selecting_reuse_placements_but_rows_read_live_view_state() {
|
|
let (mut h, component, occurrence) = fixture();
|
|
let first = super::model_placement(&mut h.app, &[occurrence]).unwrap();
|
|
h.app.cam.yaw += 0.25;
|
|
h.app.run("select.set", json!({"items":[Sel::Body{name:"Body1".into()}]})).unwrap();
|
|
h.app.session.visibility.hidden_bodies.push("Body1".into());
|
|
h.app.ui.locked_bodies.push("Body1".into());
|
|
let after = super::model_placement(&mut h.app, &[occurrence]).unwrap();
|
|
assert!(Arc::ptr_eq(&first, &after), "view-only changes resolved the same placement again");
|
|
let rows = super::entries(&h.app, component, "bodies");
|
|
assert_eq!(rows.len(), 1);
|
|
assert!(rows[0].selected && rows[0].locked && !rows[0].visible);
|
|
h.frames(2);
|
|
assert!(Arc::ptr_eq(&after, &super::model_placement(&mut h.app, &[occurrence]).unwrap()));
|
|
}
|
|
|
|
#[test]
|
|
fn pending_and_reverted_moves_replace_cached_transforms() {
|
|
let (mut h, _, occurrence) = fixture();
|
|
let first = super::model_placement(&mut h.app, &[occurrence]).unwrap();
|
|
h.app.run("occurrence.move", json!({"occurrence":occurrence,"translate":[20,0,0],"capture":false})).unwrap();
|
|
let moved = super::model_placement(&mut h.app, &[occurrence]).unwrap();
|
|
assert!(!Arc::ptr_eq(&first, &moved));
|
|
assert!((solidcraft_engine::doc::apply_point(&moved.world, solidcraft_engine::geom::Vec3::ZERO).x - 20.0).abs() < 1e-9);
|
|
h.app.run("component.revert_position", json!({"occurrences":[occurrence]})).unwrap();
|
|
let reverted = super::model_placement(&mut h.app, &[occurrence]).unwrap();
|
|
assert!(!Arc::ptr_eq(&moved, &reverted));
|
|
assert_eq!(first.world, reverted.world);
|
|
}
|
|
|
|
#[test]
|
|
fn feature_indices_follow_component_edits_and_undo() {
|
|
let (mut h, component, _) = fixture();
|
|
super::prepare_model(&mut h.app);
|
|
assert!(super::model_feature_indices(&h.app, 0, true).is_empty());
|
|
h.app.run("sketch.create", json!({"plane":"XY", "name":"Root sketch"})).unwrap();
|
|
h.app.run("sketch.finish", json!({})).unwrap();
|
|
super::prepare_model(&mut h.app);
|
|
assert_eq!(super::entries(&h.app, 0, "sketches")[0].label, "Root sketch");
|
|
assert!(super::entries(&h.app, component, "sketches").is_empty());
|
|
h.app.run("component.activate", json!({"component":component})).unwrap();
|
|
h.app.run("sketch.create", json!({"plane":"YZ", "name":"Part sketch"})).unwrap();
|
|
h.app.run("sketch.finish", json!({})).unwrap();
|
|
super::prepare_model(&mut h.app);
|
|
assert_eq!(super::entries(&h.app, component, "sketches")[0].label, "Part sketch");
|
|
assert_eq!(super::entries(&h.app, 0, "sketches").len(), 1);
|
|
h.app.run("edit.undo", json!({})).unwrap();
|
|
super::prepare_model(&mut h.app);
|
|
assert!(super::entries(&h.app, component, "sketches").is_empty());
|
|
assert_eq!(super::entries(&h.app, 0, "sketches").len(), 1);
|
|
}
|
|
|
|
#[test]
|
|
fn body_index_and_placements_follow_geometry_undo_and_document_identity() {
|
|
let (mut h, component, occurrence) = fixture();
|
|
let first = super::model_placement(&mut h.app, &[occurrence]).unwrap();
|
|
let copy = h.app.run("occurrence.copy", json!({"occurrence":occurrence,"translate":[50,0,0]})).unwrap()["occurrence"].as_u64().unwrap();
|
|
let second = super::model_placement(&mut h.app, &[copy]).unwrap();
|
|
assert_ne!(first.path, second.path);
|
|
assert_ne!(first.bodies[0].world, second.bodies[0].world);
|
|
assert_eq!(super::model_children(&h.app, 0), [occurrence, copy]);
|
|
h.app.run("component.activate", json!({"component":component})).unwrap();
|
|
h.app.run("solid.box", json!({"length":2,"width":2,"height":2,"corner":[20,0,0]})).unwrap();
|
|
let changed = super::model_placement(&mut h.app, &[occurrence]).unwrap();
|
|
assert_eq!(changed.bodies.len(), 2);
|
|
assert_eq!(super::entries(&h.app, component, "bodies").len(), 2);
|
|
h.app.run("edit.undo", json!({})).unwrap();
|
|
assert_eq!(super::model_placement(&mut h.app, &[occurrence]).unwrap().bodies.len(), 1);
|
|
assert_eq!(super::entries(&h.app, component, "bodies").len(), 1);
|
|
// A separate session can have the same revision and the same occurrence ids.
|
|
h.app.session = solidcraft_engine::Session::default();
|
|
assert!(super::model_placement(&mut h.app, &[occurrence]).is_none());
|
|
assert!(super::model_children(&h.app, 0).is_empty());
|
|
assert!(super::entries(&h.app, component, "bodies").is_empty());
|
|
}
|
|
|
|
/// #3005: a face picked in the viewport, on the second placement of a part whose rows are
|
|
/// closed: that placement opens down to its body's row (which the browser lights for the pick,
|
|
/// #3009); the first placement stays closed.
|
|
#[test]
|
|
fn a_face_picked_in_the_viewport_opens_the_browser_to_its_placements_body() {
|
|
let (mut h, _, occurrence) = fixture();
|
|
let copy = h.app.run("occurrence.copy", json!({"occurrence":occurrence,"translate":[50,0,0]})).unwrap()["occurrence"].as_u64().unwrap();
|
|
let first = super::model_placement(&mut h.app, &[occurrence]).unwrap().bodies[0].world.clone();
|
|
let second = super::model_placement(&mut h.app, &[copy]).unwrap().bodies[0].world.clone();
|
|
h.app.ui.show_browser = true;
|
|
let (one, two) = (super::occurrence_key(&[occurrence]), super::occurrence_key(&[copy]));
|
|
h.app.tree.collapsed.extend([one.clone(), two.clone(), format!("{two}/bodies")]);
|
|
h.frames(2);
|
|
assert!(!h.app.tree.order.contains(&format!("b:{second}")), "the body's row is closed away");
|
|
let face = Sel::Face { body: second.clone(), index: 0, point: solidcraft_engine::geom::Vec3::new(55.0, 5.0, 10.0) };
|
|
crate::viewport::select(&mut h.app, Some(face), false, false);
|
|
assert_eq!(h.app.tree.reveal.as_deref(), Some(second.as_str()));
|
|
h.frames(2);
|
|
assert!(h.app.tree.reveal.is_none(), "revealed");
|
|
assert!(!h.app.tree.collapsed.contains(&two) && !h.app.tree.collapsed.contains(&format!("{two}/bodies")));
|
|
assert!(h.app.tree.collapsed.contains(&one), "the other placement stays as it was");
|
|
assert!(h.app.tree.order.contains(&format!("b:{second}")), "the row is drawn");
|
|
assert!(!h.app.tree.order.contains(&format!("b:{first}")), "the other placement's row stays closed away");
|
|
}
|