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
9 changes: 9 additions & 0 deletions apps/solidcraft-cli/src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ pub fn to_script(recipe: &Value) -> Result<Value, String> {
let bodies = f.get("result_bodies").cloned().unwrap_or(json!([]));
match f.get("op").and_then(Value::as_str) {
Some("sketch") => sketch_cmds(f, &mut out)?,
Some("frame_member") => {
let mut p = json!({"name": name});
for key in ["sketch", "lines", "continuous", "profile", "profile_sketch", "profiles", "anchor", "angle", "mirror", "body_name"] {
if let Some(v) = f.get(key) {
p[key] = v.clone();
}
}
out.push(json!({"command": "frame.member", "params": p}));
}
Some("extrude") => {
let mut p = json!({"sketch": profile_sketch(f), "profiles": profiles_of(f), "operation": op(f), "name": name, "body_names": bodies});
// Thin: {sketch, curves, thickness, side?, thickness2?} instead of profiles.
Expand Down
34 changes: 34 additions & 0 deletions assets/locales/pending/frame-continuous-paths.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"en": {
"ui.frame.continuous": "One Continuous Member",
"ui.frame.continuous_requires_selection": "Select connected lines and arcs in path order; turn off All Lines for one continuous member."
},
"ar": {
"ui.frame.continuous": "عنصر هيكلي واحد متصل",
"ui.frame.continuous_requires_selection": "حدّد خطوطًا وأقواسًا متصلة بترتيب المسار؛ عطّل «كل الخطوط» لإنشاء عنصر هيكلي واحد متصل."
},
"de": {
"ui.frame.continuous": "Ein durchgehendes Rahmenelement",
"ui.frame.continuous_requires_selection": "Zusammenhängende Linien und Bögen in Pfadreihenfolge auswählen; für ein durchgehendes Rahmenelement Alle Linien ausschalten."
},
"he": {
"ui.frame.continuous": "איבר מסגרת רציף אחד",
"ui.frame.continuous_requires_selection": "בחרו קווים וקשתות מחוברים לפי סדר המסלול; בטלו את ״כל הקווים״ כדי ליצור איבר מסגרת רציף אחד."
},
"ja": {
"ui.frame.continuous": "1 本の連続部材",
"ui.frame.continuous_requires_selection": "接続された線と円弧をパスの順に選択し、連続部材では「すべての線」をオフにしてください。"
},
"ko": {
"ui.frame.continuous": "하나의 연속 부재",
"ui.frame.continuous_requires_selection": "연결된 선과 원호를 경로 순서대로 선택하고 연속 부재에서는 모든 선을 끄세요."
},
"vi": {
"ui.frame.continuous": "Một phần tử khung kết cấu liên tục",
"ui.frame.continuous_requires_selection": "Chọn các đoạn thẳng và cung tròn nối tiếp theo thứ tự đường dẫn; tắt Tất cả đoạn thẳng để tạo một phần tử khung kết cấu liên tục."
},
"zh": {
"ui.frame.continuous": "单根连续构件",
"ui.frame.continuous_requires_selection": "按路径顺序选择相连的直线和圆弧;创建连续构件时请关闭所有直线。"
}
}
1 change: 1 addition & 0 deletions attribution/pending/frame-continuous-paths.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| `assets/locales/pending/frame-continuous-paths.json` | SolidCraft contributors | Original continuous frame-member labels and translations | MIT OR Apache-2.0 |
9 changes: 6 additions & 3 deletions crates/doc/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,9 +1491,8 @@ pub enum FeatureKind {
#[walk(angle = "Angle")]
angle: Expr,
},
/// Structural members (#4003): one body per straight line of a frame sketch (2D sketch lines
/// and 3D sketch lines), then one per pair of points (#15705), its cross-section the profile,
/// square to the line from end to end.
/// Structural members (#4003): one body per selected line, arc or pair of points,
/// or one continuous tangent sketch path. Ordinary straight members retain corner processing.
FrameMember {
/// The frame sketch; none: a Frame Member of pairs only.
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand All @@ -1502,6 +1501,10 @@ pub enum FeatureKind {
/// construction, not projected or otherwise linked, not of no length).
#[serde(default, skip_serializing_if = "Vec::is_empty")]
lines: Vec<String>,
/// The explicitly selected curves form one open, tangent line/arc chain, in selection
/// order. Otherwise each selected curve makes a separate member.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
continuous: bool,
profile: crate::frame::MemberProfile,
/// The profile point that sits on the line.
#[serde(default, skip_serializing_if = "crate::frame::Anchor::is_origin")]
Expand Down
80 changes: 56 additions & 24 deletions crates/doc/src/eval_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ use crate::{DocError, Document, Feature, FeatureId, FeatureKind, ProfileSel, Res
#[path = "frame_earlier.rs"]
mod earlier;

#[path = "frame_paths.rs"]
mod paths;

/// Most profiles a profile sketch may have for its material to be worked out.
const MAX_PROFILE_PIECES: usize = 256;
/// Shortest member (mm).
const MIN_LENGTH: f64 = 1e-6;
/// How far (mm) a 3D sketch curve may stray from the line between its ends and still be a line.
const STRAIGHT_TOL: f64 = 1e-3;

/// Evaluate a `FrameMember` feature: one new body per member (a line, a pair, or under every type but None each
/// piece of a line cut where tubes cross, [`pieced`], but for a piece left wholly inside the tubes it is fitted to),
Expand All @@ -55,6 +56,9 @@ pub(super) fn evaluate(doc: &Document, vals: &BTreeMap<String, Value>, f: &Featu

// Preserve main's complete flat/grouped evaluation before adding optional provenance.
fn evaluate_members(doc: &Document, vals: &BTreeMap<String, Value>, f: &Feature, st: &mut ModelState) -> Result<()> {
if paths::uses(st, &f.kind)? {
return paths::evaluate(doc, vals, f, st);
}
if let Some(groups) = frame::group_features(f)? {
let FeatureKind::FrameMember { profile, names, .. } = &f.kind else {
return Err(DocError::Invalid("not a frame member feature".into()));
Expand Down Expand Up @@ -1842,10 +1846,27 @@ fn layout(doc: &Document, vals: &BTreeMap<String, Value>, f: &Feature, st: &Mode
if matches!(&f.kind, FeatureKind::FrameMember { groups, .. } if !groups.is_empty()) {
return Err(DocError::Invalid("not supported yet: joint layout across frame member groups".into()));
}
let (segments, sketch_x, drawn, planes) = segments(doc, vals, f, st)?;
let Section { regions, description, at, turn, turns, centre, origin } = section(doc, vals, f, st)?;
Ok(Layout { segments, regions, description, at, turn, sketch_x, drawn, planes, turns, centre, origin })
}

/// Shared section settings; Auto seam handling remains in the unchanged section preparation.
struct Section {
/// The unmirrored profile origin, also used by the straight-member section view.
origin: Vec2,
regions: Vec<Region2>,
description: String,
at: Vec2,
turn: f64,
turns: BTreeMap<String, f64>,
centre: Vec2,
}

fn section(doc: &Document, vals: &BTreeMap<String, Value>, f: &Feature, st: &ModelState) -> Result<Section> {
let FeatureKind::FrameMember { profile, anchor, locate, angle, mirror, corner, .. } = &f.kind else {
return Err(DocError::Invalid("not a frame member feature".into()));
};
let (segments, sketch_x, drawn, planes) = segments(doc, vals, f, st)?;
let (mut regions, description, origin) = profile_regions(vals, st, profile)?;
if *mirror {
regions = regions.iter().map(frame::mirrored).collect();
Expand Down Expand Up @@ -1879,7 +1900,7 @@ fn layout(doc: &Document, vals: &BTreeMap<String, Value>, f: &Feature, st: &Mode
}
let turns = member_turns(doc, vals, FeatureId(f.id)).into_iter().map(|(line, (_, a))| (line, a)).collect();
let centre = frame::anchor_point(&regions, frame::Anchor::Center);
Ok(Layout { segments, regions, description, at, turn, sketch_x, drawn, planes, turns, centre, origin })
Ok(Section { regions, description, at, turn, turns, centre, origin })
}

/// The profile point on the line of a member a Rotate step turns `t` (radians) further (#15070): the profile turns
Expand Down Expand Up @@ -1968,6 +1989,9 @@ type Path = (Vec<(String, Vec3, Vec3)>, Option<Vec3>, Vec<usize>, Vec<MemberPlan
/// Each member's centreline where the view shows it: (member id, start, end), in the world.
/// `st` is the model the feature was evaluated on (`Model::state_before`).
pub fn member_segments(doc: &Document, st: &ModelState, f: &Feature) -> Result<Vec<(String, Vec3, Vec3)>> {
if paths::uses(st, &f.kind)? {
return paths::member_segments(doc, st, f);
}
let m = doc.component_transform(f.component);
let place = |p: Vec3| crate::apply_point(&m, p);
Ok(segments(doc, &doc.evaluation_values(), f, st)?.0.into_iter().map(|(id, a, b)| (id, place(a), place(b))).collect())
Expand Down Expand Up @@ -2057,6 +2081,9 @@ pub(crate) fn member_section(
st: &ModelState,
line: &str,
) -> Result<(Plane, f64, Region2, [bool; 2])> {
if paths::uses(st, &f.kind)? {
return paths::member_section(doc, vals, f, st, line);
}
if let Some(groups) = frame::group_features(f)? {
let group = groups
.into_iter()
Expand Down Expand Up @@ -2116,6 +2143,9 @@ pub(crate) fn member_section(
/// The point member `line` of `f` turns about, halfway along it: the centre of the profile's
/// bounding box, which a Rotate step's turn leaves where it is ([`turned_at`]).
pub(crate) fn member_pivot(doc: &Document, vals: &BTreeMap<String, Value>, f: &Feature, st: &ModelState, line: &str) -> Result<Vec3> {
if paths::uses(st, &f.kind)? {
return paths::member_pivot(doc, vals, f, st, line);
}
if let Some(groups) = frame::group_features(f)? {
let group = groups
.into_iter()
Expand Down Expand Up @@ -2262,6 +2292,9 @@ pub(super) fn check_turn(doc: &Document, vals: &BTreeMap<String, Value>, f: &Fea
if !member_line_ids(st, &source.kind)?.contains(&member.line) {
return Err(DocError::Invalid(format!("Line `{}` of its frame member is gone", member.line)));
}
if paths::uses(st, &source.kind)? {
paths::member_pivot(doc, vals, source, st, &member.line)?;
}
turn_angle(vals, angle).map(|_| ())
}

Expand All @@ -2273,6 +2306,9 @@ pub fn member_line_ids(st: &ModelState, kind: &FeatureKind) -> Result<Vec<String

/// [`member_line_ids`], and which of them are later pieces of a cut line ([`LaterPieces`]).
pub fn member_parts(st: &ModelState, kind: &FeatureKind) -> Result<(Vec<String>, LaterPieces)> {
if paths::uses(st, kind)? {
return paths::member_parts(st, kind);
}
if let FeatureKind::FrameMember { groups, path_sketch: Some(path), .. } = kind
&& !groups.is_empty()
{
Expand Down Expand Up @@ -2608,7 +2644,7 @@ pub fn is_member_line(sk: &Sketch, ci: usize) -> bool {
/// Whether wire `wi` of `sk` is a 3D line a frame member is laid on unless lines are picked: a
/// straight one drawn in it (not projected or otherwise linked), as [`member_lines`] takes them.
pub fn is_member_wire(sk: &Sketch, wi: usize) -> bool {
sk.wires.get(wi).is_some_and(|w| w.link.is_none() && straight(&w.pts).is_some())
sk.wires.get(wi).is_some_and(|w| w.link.is_none() && wire_line(w).is_ok_and(|line| line.is_some()))
}

/// Each member's place in the sketch's drawing order: a 2D line's curve index, a 3D line's wire
Expand Down Expand Up @@ -2636,7 +2672,7 @@ fn member_lines(ss: &SolvedSketch, ids: &[String]) -> Result<Vec<(String, Vec3,
}
}
for w in sk.wires.iter().filter(|w| w.link.is_none()) {
if let Some((a, b)) = straight(&w.pts)
if let Some((a, b)) = wire_line(w)?
&& a.dist(b) > MIN_LENGTH
{
out.push((w.id.clone(), a, b));
Expand All @@ -2659,12 +2695,15 @@ fn member_lines(ss: &SolvedSketch, ids: &[String]) -> Result<Vec<(String, Vec3,
return Err(DocError::Invalid(format!("line `{id}` is listed twice")));
}
let line = if let Some(wi) = sk.wire_index(id) {
sk.wires.get(wi).and_then(|w| straight(&w.pts))
match sk.wires.get(wi) {
Some(w) => wire_line(w)?,
None => None,
}
} else {
let ci = sk.curve_index(id).ok_or_else(|| DocError::Unknown(format!("line `{id}` in {}", ss.name)))?;
planar_line(ss, ci)
};
let (a, b) = line.ok_or_else(|| DocError::Invalid(format!("`{id}` is not a straight line (members run along lines)")))?;
let (a, b) = line.ok_or_else(|| DocError::Invalid(format!("`{id}` is not a straight line or an exact circular arc")))?;
if !(a.dist(b) > MIN_LENGTH) {
return Err(DocError::Invalid(format!("line `{id}` has no length")));
}
Expand All @@ -2680,22 +2719,15 @@ fn planar_line(ss: &SolvedSketch, ci: usize) -> Option<(Vec3, Vec3)> {
Some((ss.plane.to_world(pa), ss.plane.to_world(pb)))
}

/// The ends of a 3D polyline that runs straight from its first point to its last: every point
/// within [`STRAIGHT_TOL`] of the line between them, none behind the start, past the end or back
/// from a point before it.
fn straight(pts: &[Vec3]) -> Option<(Vec3, Vec3)> {
let (a, b) = (*pts.first()?, *pts.last()?);
let (len, d) = (a.dist(b), (b - a).normalized()?);
let mut reached = 0.0_f64;
for p in pts {
let q = *p - a;
let t = q.dot(d);
if (q - d * t).len() > STRAIGHT_TOL || t < reached - STRAIGHT_TOL || t > len + STRAIGHT_TOL {
return None;
}
reached = reached.max(t);
}
Some((a, b))
/// Exact straight stock only: defining line points or one retained analytic line.
/// A display polyline never turns a spline into straight member stock.
fn wire_line(w: &solidcraft_sketch::Wire) -> Result<Option<(Vec3, Vec3)>> {
paths::wire_line(w).map(|line| {
line.map(|p| {
let d = p.data();
(d.a, d.b)
})
})
}

/// The regions of a member's profile, in the profile's own coordinates: one piece of material,
Expand Down
4 changes: 4 additions & 0 deletions crates/doc/src/format/pending/frame-continuous-paths.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! Frame members can retain explicitly selected circular arcs and a `continuous` line/arc
//! chain as one physical member. Older designs default to separate members, with the existing
//! all-straight-lines selection unchanged. A release that lacks this change opens the design
//! with a warning and preserves fields it cannot read when saving it.
12 changes: 2 additions & 10 deletions crates/doc/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub const MAX_PROFILE_SIZE: f64 = 10_000.0;
pub const MIN_PROFILE_DIMENSION: f64 = 0.01;
/// How far from vertical (radians) a member's line may lean and still count as vertical for its
/// orientation ([`member_axes`]).
pub const VERTICAL_TOLERANCE: f64 = 1e-6;
pub const VERTICAL_TOLERANCE: f64 = solidcore_ops::frame_member::VERTICAL_TOLERANCE;

/// A built-in profile and its dimensions (mm). `Option` dimensions take a default worked out from
/// the profile's size ([`Profile::filled`] says which).
Expand Down Expand Up @@ -919,15 +919,7 @@ pub fn mirrored(region: &Region2) -> Region2 {
/// profile counter-clockwise about the line, seen looking back from its end. `None` for a
/// direction of no length.
pub fn member_axes(d: Vec3, angle: f64) -> Option<(Vec3, Vec3)> {
let d = d.normalized()?;
let up = Vec3::Z - d * Vec3::Z.dot(d);
// `up` is as long as the sine of the line's lean from vertical.
let (x, y) = match up.normalized().filter(|_| up.len() > VERTICAL_TOLERANCE) {
Some(y) => (y.cross(d), y),
None => (Vec3::X, d.cross(Vec3::X)),
};
let (c, s) = (angle.cos(), angle.sin());
Some((x * c + y * s, y * c - x * s))
solidcore_ops::frame_member::member_axes(d, angle).ok().flatten()
}

/// [`member_axes`] for a member running along `dir` with its `up` given (#4003 Auto's lined-up sections): the
Expand Down
Loading
Loading