27d2fe6ec0
* claim: #4003 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Frames: the profile library (#4003) The first slice of frames and weldments: the cross-sections structural members will be made of, each SolidCraft's own parametric definition built in code (no vendor or standard size tables are shipped). - solidcraft_doc::frame: bar, round bar, rectangular and round tube, angle, channel, I-beam and a generic T-slot extrusion as exact line/arc regions, with defaults worked out from the profile's size, refusals that name the dimension that does not fit, anchors and placement, and exact section properties (area, centroid, Ixx/Iyy/Ixy by Green's theorem). - frame.profile.list, frame.profile.properties (with mass per metre for a density) and frame.profile.insert (draws a profile into a sketch, locked by default, at a point, anchor and angle). - Tests against hand-computed values (rectangles, circles, composite rectangles by the parallel-axis theorem, fillet spandrels), hostile input, extrusion volume, undo; catalog entries in every locale; docs/frames.md; ROADMAP M15. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Frames: drop the built-in T-slot profile (#4003) Aluminium extrusions and other vendor sections come from the user's own sketch (drawn or inserted from the vendor's DXF), so the library keeps the plain steel shapes only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Frames: members along frame sketch lines (#4003) frame.member lays one body per straight line of a frame sketch (2D lines or 3D sketch lines), its cross-section square to the line from end to end: - profile: a built-in profile, or profile_sketch, a sketch whose material (nested loops alternating, so two circles make a tube) is the section in its own x and y around its origin; profiles picks override it. - anchor (origin, centre, centroid or a bounding-box corner or edge middle), angle (an angle expression, so a parameter), mirror. - Orientation: the profile's y as near world up as the line allows, x square to both; a vertical member's x is world X (frame::member_axes). - Members follow sketch and parameter edits, undo as one step, save and reopen (format: pending/frame-members.rs), and are named after the profile (Rect Tube 40x40x3, (2)…), numbering on past names already taken. Tests against hand-computed volumes and bounding boxes (rectangle, 3D tower lines, parameter edit, sketch tube profile and picks, anchor/angle/ mirror), refusals, undo/redo and reopen; walk fixtures and goldens; docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Frames: fixes from the adversarial review (#4003) - Default member lines are what was drawn: projected and other linked curves and 3D wires (a face sketch's edges) and lines of no length are left out. - A profile sketch's material starts from its drawn profiles, as solid.extrude's "all" does, so a section sketched on a face works; the even-odd test uses outlines and boxes worked out once, capped at 256. - Member names are pinned to their lines (`names`, by line id; `body_name` is the base): deleting or adding a line, or deleting another feature, no longer renames other members, and frame.member stores every name it gives. body.rename renames a member on its line (also for later member features); a copy whose body_names were set still names its members by position. - Built-in profile dimensions are expressions (ProfileSpec): they follow parameters, bare numbers take the design's units, and they are feature inputs. frame.profile.properties/insert read them the same way. - Default root/toe radii shrink to the room a thick section leaves; radii given are checked by name; a radius must be 0 or at least 0.01 mm; error messages report the wall or flange value given, not twice it. - A line within 1e-6 rad of vertical orients as vertical, so rounding never turns a post a quarter turn. - A 2D frame sketch in a differently placed component is mapped into the member's frame, and member features recompute when placements change. - Caps before lookups for a design's `lines`; a line listed twice is refused; a 3D wire that runs back on itself is not a line. Regression tests for each, from the review's scenarios. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Frames: the Frame Member dialog on the ribbon (#4003) - Frame Member (MODEL > Create) opens a dialog: the frame sketch's lines picked in the view (or All Lines), a built-in profile and its dimensions or a section picked in another sketch, anchor, angle, mirror and name, with a live preview. Edit Feature reopens it filled in. - Lines picked in the view keep their sketch (a SKETCH_LINES input picks ExternalSketchCurve): line ids are each sketch's own, so two 3D sketches both have a `w2`, and the members went on the newer sketch's lines. - timeline.redefine takes frame.member. Members keep their names through an edit unless it gives them a new body_name; frame.member takes `names`. - A member whose section is a whole profile sketch keeps it when edited (the dialog shows the sketch instead of picking every region, which would fill a tube's hole). - An original frame_member icon, open for review, on the ribbon, timeline and browser. - The angle profile is listed as L-Angle, and web and flange as Web/Flange thickness, so they translate apart from the existing Angle, Web and Flange; the dialog's labels are in en, ja and zh. en-GB no longer repeats the frame command labels it spells the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
198 lines
9.7 KiB
Rust
198 lines
9.7 KiB
Rust
use crate::test_support::run_all;
|
||
use serde_json::json;
|
||
use solidcraft_engine::Session;
|
||
|
||
use super::*;
|
||
use crate::Services;
|
||
use crate::dialogs::{Dialog, apply_commands, for_feature as edit_dialog};
|
||
|
||
fn app_with(cmds: &[(&str, Value)]) -> SolveApp {
|
||
let mut s = Session::default();
|
||
for (id, p) in cmds {
|
||
s.execute(id, p).unwrap();
|
||
}
|
||
SolveApp::new(s, Services::default())
|
||
}
|
||
|
||
/// A 600 × 400 rectangle on XY as the frame sketch `Frame`, and, drawn after it on YZ, a ring of
|
||
/// two circles as the section sketch `Ring` (its circles' ids are not the frame's line ids).
|
||
fn frame_app() -> SolveApp {
|
||
app_with(&[
|
||
("sketch.create", json!({"plane": "XY", "name": "Frame"})),
|
||
("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [600, 400]})),
|
||
("sketch.finish", json!({})),
|
||
("sketch.create", json!({"plane": "YZ", "name": "Ring"})),
|
||
("sketch.circle.center", json!({"center": [0, 0], "radius": 20})),
|
||
("sketch.circle.center", json!({"center": [0, 0], "radius": 17})),
|
||
("sketch.finish", json!({})),
|
||
])
|
||
}
|
||
|
||
fn sketch_id(app: &SolveApp, name: &str) -> u64 {
|
||
app.session.doc.find_feature(name).unwrap().id
|
||
}
|
||
|
||
fn frame_lines(app: &SolveApp) -> Vec<String> {
|
||
app.session.doc.sketch(sketch_id(app, "Frame")).unwrap().curves.iter().map(|c| c.id.clone()).collect()
|
||
}
|
||
|
||
fn body_names(app: &SolveApp) -> Vec<String> {
|
||
app.session.world_state().bodies.iter().map(|b| b.name.clone()).collect()
|
||
}
|
||
|
||
/// The dialog started with the given lines picked.
|
||
fn dialog_on(app: &mut SolveApp, lines: &[String]) -> Dialog {
|
||
app.session.selection = lines.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||
app.start("frame.member");
|
||
app.dialog.clone().unwrap()
|
||
}
|
||
|
||
fn member(d: &mut Dialog) -> &mut Member {
|
||
match &mut d.kind {
|
||
Kind::Frame(m) => m,
|
||
k => panic!("{k:?}"),
|
||
}
|
||
}
|
||
|
||
/// Picked lines and the default built-in profile make one member a line; Edit Feature refills
|
||
/// the dialog and runs `timeline.redefine`, and the members keep their names.
|
||
#[test]
|
||
fn members_from_picked_lines_and_a_built_in_profile() {
|
||
let mut app = frame_app();
|
||
let lines = frame_lines(&app);
|
||
let mut d = dialog_on(&mut app, &lines[..2]);
|
||
let c = apply_commands(&app, &d).unwrap();
|
||
assert_eq!(c[0].0, "frame.member");
|
||
let p = &c[0].1;
|
||
assert_eq!(p["sketch"], json!(sketch_id(&app, "Frame")), "the frame sketch, not the newer section sketch: {p}");
|
||
assert_eq!(p["lines"], json!(lines[..2]));
|
||
assert_eq!(p["profile"], json!({"kind": "rect_tube", "width": "40 mm", "height": "40 mm", "wall": "3 mm"}));
|
||
assert!(p.get("anchor").is_none() && p.get("angle").is_none() && p.get("mirror").is_none() && p.get("body_name").is_none(), "{p}");
|
||
// Another built-in profile and its dimensions; an optional one left empty takes its default.
|
||
let m = member(&mut d);
|
||
m.kind = frame::profile_kinds().iter().position(|k| k.kind == "angle").unwrap();
|
||
m.dims[m.kind][2] = "4 mm".into();
|
||
let c = apply_commands(&app, &d).unwrap();
|
||
assert_eq!(c[0].1["profile"], json!({"kind": "angle", "width": "50 mm", "height": "50 mm", "thickness": "4 mm"}));
|
||
run_all(&mut app, c);
|
||
assert_eq!(body_names(&app), ["Angle 50x50x4", "Angle 50x50x4 (2)"]);
|
||
app.run("body.rename", json!({"body": "Angle 50x50x4 (2)", "name": "Rail"})).unwrap();
|
||
let f = app.session.doc.features.last().unwrap().id;
|
||
let mut e = edit_dialog(&app, f, None).unwrap();
|
||
assert_eq!(e.inputs[0].items.len(), 2);
|
||
let m = member(&mut e);
|
||
assert_eq!((frame::profile_kinds()[m.kind].kind, m.dims[m.kind][2].as_str()), ("angle", "4 mm"));
|
||
m.dims[m.kind][2] = "5 mm".into();
|
||
let c = apply_commands(&app, &e).unwrap();
|
||
assert_eq!(c[0].0, "timeline.redefine");
|
||
run_all(&mut app, c);
|
||
assert_eq!(body_names(&app), ["Angle 50x50x4", "Rail"], "the members keep their names through the edit");
|
||
}
|
||
|
||
/// A section picked in another sketch is the profile, the picks naming its regions; All Lines,
|
||
/// anchor, angle, mirror and name reach the command and come back when editing.
|
||
#[test]
|
||
fn a_picked_section_and_the_placement() {
|
||
let mut app = frame_app();
|
||
let lines = frame_lines(&app);
|
||
let ring = sketch_id(&app, "Ring");
|
||
let mut d = dialog_on(&mut app, &lines[..1]);
|
||
// The ring between the circles: the region whose interior point lies between radii 17 and 20.
|
||
let ss = app.session.world_state().sketch(ring).unwrap().clone();
|
||
let index = ss.profiles.iter().position(|p| (p.region.interior_point().len() - 18.5).abs() < 1.5).unwrap();
|
||
d.inputs[1].items = vec![Sel::Profile { sketch: ring, index }];
|
||
let m = member(&mut d);
|
||
m.all = true;
|
||
m.anchor = ANCHORS.iter().position(|a| a.0 == "bottom").unwrap();
|
||
m.angle = "15 deg".into();
|
||
m.mirror = true;
|
||
m.name = " Rail ".into();
|
||
let c = apply_commands(&app, &d).unwrap();
|
||
let p = &c[0].1;
|
||
assert_eq!(p["sketch"], json!(sketch_id(&app, "Frame")));
|
||
assert!(p.get("lines").is_none() && p.get("profile").is_none(), "{p}");
|
||
assert_eq!((&p["profile_sketch"], &p["profiles"]), (&json!(ring), &json!([index])));
|
||
assert_eq!((&p["anchor"], &p["angle"], &p["mirror"], &p["body_name"]), (&json!("bottom"), &json!("15 deg"), &json!(true), &json!("Rail")));
|
||
run_all(&mut app, c);
|
||
assert_eq!(body_names(&app), ["Rail", "Rail (2)", "Rail (3)", "Rail (4)"]);
|
||
let f = app.session.doc.features.last().unwrap().id;
|
||
let mut e = edit_dialog(&app, f, None).unwrap();
|
||
assert_eq!(e.inputs[0].items.len(), 4, "every line of the sketch shows as picked");
|
||
assert_eq!(e.inputs[1].items, [Sel::Profile { sketch: ring, index }]);
|
||
let m = member(&mut e);
|
||
assert!(m.all && m.mirror && m.name == "Rail" && m.angle == "15 deg" && ANCHORS[m.anchor].0 == "bottom", "{m:?}");
|
||
}
|
||
|
||
/// A member whose section is a whole profile sketch keeps it when edited: the dialog shows the
|
||
/// sketch rather than picking every region of it, which would fill the tube's hole.
|
||
#[test]
|
||
fn a_whole_sketch_section_stays_whole_through_an_edit() {
|
||
let mut app = frame_app();
|
||
app.run("frame.member", json!({"sketch": "Frame", "profile_sketch": "Ring"})).unwrap();
|
||
let volume = |app: &mut SolveApp| app.session.execute("inspect.measure", &json!({})).unwrap()["bodies"][0]["volume_mm3"].as_f64().unwrap();
|
||
let before = volume(&mut app);
|
||
let f = app.session.doc.features.last().unwrap().id;
|
||
let mut e = edit_dialog(&app, f, None).unwrap();
|
||
assert!(e.inputs[1].items.is_empty());
|
||
assert_eq!(member(&mut e).whole, Some(sketch_id(&app, "Ring")));
|
||
member(&mut e).angle = "30 deg".into();
|
||
let c = apply_commands(&app, &e).unwrap();
|
||
assert!(c[0].1["params"].get("profiles").is_none(), "{}", c[0].1);
|
||
run_all(&mut app, c);
|
||
assert!((volume(&mut app) - before).abs() < 1e-6 * before, "still the ring, not the filled circle");
|
||
// Unticked, the section is a built-in profile again.
|
||
let mut e = edit_dialog(&app, f, None).unwrap();
|
||
member(&mut e).whole = None;
|
||
assert_eq!(apply_commands(&app, &e).unwrap()[0].1["params"]["profile"]["kind"], "rect_tube");
|
||
}
|
||
|
||
/// Without lines there is nothing to place; lines and the section in one sketch are refused.
|
||
#[test]
|
||
fn missing_or_mixed_picks_are_refused() {
|
||
let mut app = frame_app();
|
||
let d = dialog_on(&mut app, &[]);
|
||
assert!(apply_commands(&app, &d).unwrap_err().contains("lines"));
|
||
let ring = sketch_id(&app, "Ring");
|
||
let circles: Vec<String> = app.session.doc.sketch(ring).unwrap().curves.iter().map(|c| c.id.clone()).collect();
|
||
let mut d = dialog_on(&mut app, &circles[..1]);
|
||
d.inputs[1].items = vec![Sel::Profile { sketch: ring, index: 0 }];
|
||
assert!(apply_commands(&app, &d).is_err());
|
||
}
|
||
|
||
/// Lines picked in the view keep their sketch: two 3D sketches both number their lines `w1`…, and
|
||
/// the members go on the lines that were clicked, not on the newer sketch's lines of those ids.
|
||
#[test]
|
||
fn picked_lines_stay_in_the_sketch_they_were_picked_in() {
|
||
let mut app = app_with(&[
|
||
("sketch.create", json!({"plane": "XY", "name": "Uprights"})),
|
||
("sketch.options", json!({"sketch_3d": true})),
|
||
("sketch.line3d", json!({"points": [[0, 0, 0], [0, 0, 500]]})),
|
||
("sketch.line3d", json!({"points": [[300, 0, 0], [300, 0, 500]]})),
|
||
("sketch.finish", json!({})),
|
||
("sketch.create", json!({"plane": "XY", "name": "Rails"})),
|
||
("sketch.options", json!({"sketch_3d": true})),
|
||
("sketch.line3d", json!({"points": [[0, 0, 250], [300, 0, 250]]})),
|
||
("sketch.line3d", json!({"points": [[0, 0, 480], [300, 0, 480]]})),
|
||
("sketch.finish", json!({})),
|
||
]);
|
||
let (uprights, rails) = (sketch_id(&app, "Uprights"), sketch_id(&app, "Rails"));
|
||
let wires = |id: u64| -> Vec<String> { app.session.doc.sketch(id).unwrap().wires.iter().map(|w| w.id.clone()).collect() };
|
||
let ids = wires(uprights);
|
||
assert_eq!(ids, wires(rails), "the two sketches share their line ids");
|
||
app.start("frame.member");
|
||
let mut d = app.dialog.clone().unwrap();
|
||
d.inputs[0].items = ids.iter().map(|id| Sel::ExternalSketchCurve { sketch: uprights, id: id.clone() }).collect();
|
||
let c = apply_commands(&app, &d).unwrap();
|
||
assert_eq!(c[0].1["sketch"], json!(uprights));
|
||
run_all(&mut app, c.clone());
|
||
// Two posts the height of the uprights, not two rails.
|
||
let m = app.session.execute("inspect.measure", &json!({})).unwrap();
|
||
for b in m["bodies"].as_array().unwrap() {
|
||
let (lo, hi) = (b["bbox"]["min"][2].as_f64().unwrap(), b["bbox"]["max"][2].as_f64().unwrap());
|
||
assert!(lo.abs() < 1e-6 && (hi - 500.0).abs() < 1e-6, "{b}");
|
||
}
|
||
// Lines picked in two sketches are refused.
|
||
d.inputs[0].items.push(Sel::ExternalSketchCurve { sketch: rails, id: ids[0].clone() });
|
||
assert!(apply_commands(&app, &d).unwrap_err().contains("one sketch"));
|
||
}
|