SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Plane at Angle: use axis direction only with a pivot (#12041) (#12131)
ReDead708d5a149d07
diff --git a/assets/locales/en.json b/assets/locales/en.jsonindex 84b5500e30..3afa27bc7a 100644--- a/assets/locales/en.json+++ b/assets/locales/en.json@@ -1705,7 +1705,7 @@"help.construct.axis.two_planes": "Creates a construction axis where two planes or flat faces meet. Use it when the axis you need is the line between two faces.","help.construct.axis.two_points": "Creates a construction axis through two points, vertices or sketch points. Use it for an axis that runs between two known positions.","help.construct.plane.along_path": "Creates a construction plane square to an edge or curve, at a position along it. Use it to sketch a profile for a sweep or a section of a path.",- "help.construct.plane.at_angle": "Creates a construction plane turned by an angle from a plane or face, about an axis or edge. Use it for sloped sketches, such as an angled bracket.",+ "help.construct.plane.at_angle": "Creates a construction plane turned by an angle from a plane or face, about an axis or edge. Turn on Use axis direction only to project the axis onto the base and pivot about a point on that plane (the base origin when none is picked). Use it for sloped sketches, such as an angled bracket.","help.construct.plane.axis_point": "Creates a construction plane containing an axis and a point off that axis. Pick an origin or construction axis, a straight edge or sketch line, then a vertex, sketch point or construction point. A point on the axis cannot define a unique plane.","help.construct.plane.midplane": "Creates a construction plane halfway between two planes or flat faces, or bisecting them where they meet at an angle. Use it as a symmetry plane for mirroring.","help.construct.plane.offset": "Creates a construction plane parallel to a plane or flat face, at a distance or through a point. Use it to sketch at a set height above a face.",diff --git a/assets/locales/pending/plane-at-angle-direction-only.json b/assets/locales/pending/plane-at-angle-direction-only.jsonnew file mode 100644index 0000000000..3158374c4f--- /dev/null+++ b/assets/locales/pending/plane-at-angle-direction-only.json@@ -0,0 +1,26 @@+{+ "en": {+ "Use axis direction only": "Use axis direction only"+ },+ "ar": {+ "Use axis direction only": "استخدام اتجاه المحور فقط"+ },+ "de": {+ "Use axis direction only": "Nur Achsenrichtung verwenden"+ },+ "he": {+ "Use axis direction only": "השתמש בכיוון הציר בלבד"+ },+ "ja": {+ "Use axis direction only": "軸の方向のみを使用"+ },+ "ko": {+ "Use axis direction only": "축 방향만 사용"+ },+ "vi": {+ "Use axis direction only": "Chỉ dùng hướng trục"+ },+ "zh": {+ "Use axis direction only": "仅使用轴方向"+ }+}diff --git a/crates/doc/src/assembly.rs b/crates/doc/src/assembly.rsindex 071064a852..9815285f5b 100644--- a/crates/doc/src/assembly.rs+++ b/crates/doc/src/assembly.rs@@ -210,13 +210,16 @@ fn map_plane_ref(m: &Mat, p: &mut PlaneRef) {map_plane_ref(m, base);map_geo_ref(m, point);}- PlaneRef::AtAngle { base, axis_origin, axis_dir, line, .. } => {+ PlaneRef::AtAngle { base, axis_origin, axis_dir, line, pivot, .. } => {map_plane_ref(m, base);*axis_origin = apply_point(m, *axis_origin);*axis_dir = apply_vector(m, *axis_dir);if let Some(g) = line {map_geo_ref(m, g);}+ if let Some(g) = pivot {+ map_geo_ref(m, g);+ }}// Named origin planes and construction planes are the component's own.PlaneRef::Origin { .. } | PlaneRef::Construction { .. } => {}diff --git a/crates/doc/src/clipboard.rs b/crates/doc/src/clipboard.rsindex f2f1e75262..a7d450b29b 100644--- a/crates/doc/src/clipboard.rs+++ b/crates/doc/src/clipboard.rs@@ -119,11 +119,14 @@ fn remap_plane(p: &mut PlaneRef, ids: &BTreeMap<u64, u64>, bodies: &BTreeMap<Strremap_plane(base, ids, bodies, depth + 1)?;remap_geo(point, ids, bodies, depth + 1)?;}- PlaneRef::AtAngle { base, line, .. } => {+ PlaneRef::AtAngle { base, line, pivot, .. } => {remap_plane(base, ids, bodies, depth + 1)?;if let Some(g) = line {remap_geo(g, ids, bodies, depth + 1)?;}+ if let Some(g) = pivot {+ remap_geo(g, ids, bodies, depth + 1)?;+ }}PlaneRef::Face { name, anchor, .. } => {if let Some(name) = name {@@ -323,11 +326,14 @@ fn checked_plane(p: &PlaneRef, depth: usize) -> crate::Result<()> {}match p {PlaneRef::Offset { base, .. } | PlaneRef::Flipped { base, .. } => checked_plane(base, depth + 1)?,- PlaneRef::AtAngle { base, line, .. } => {+ PlaneRef::AtAngle { base, line, pivot, .. } => {checked_plane(base, depth + 1)?;if let Some(g) = line {checked_geo(g, depth + 1)?;}+ if let Some(g) = pivot {+ checked_geo(g, depth + 1)?;+ }}PlaneRef::Midplane { a, b } | PlaneRef::TwoEdges { a, b } | PlaneRef::AxisPoint { axis: a, point: b } => {checked_geo(a, depth + 1)?;diff --git a/crates/doc/src/construct.rs b/crates/doc/src/construct.rsindex d92f0fd055..6287428e0b 100644--- a/crates/doc/src/construct.rs+++ b/crates/doc/src/construct.rs@@ -923,9 +923,10 @@ impl PlaneRef {refs.push(point.as_mut());refs}- PlaneRef::AtAngle { base, line, .. } => {+ PlaneRef::AtAngle { base, line, pivot, .. } => {let mut v = base.refs_mut();v.extend(line.as_deref_mut());+ v.extend(pivot.as_deref_mut());v}PlaneRef::Offset { base, .. } | PlaneRef::Flipped { base, .. } => base.refs_mut(),diff --git a/crates/doc/src/document.rs b/crates/doc/src/document.rsindex 05114ff7e2..00235fbd4a 100644--- a/crates/doc/src/document.rs+++ b/crates/doc/src/document.rs@@ -61,6 +61,9 @@ pub enum PlaneRef {/// Another plane rotated about a line (in world coordinates) by an angle expression. With/// `line`, an edge or round face of the model ([`crate::construct::model_axis`]), the line is/// found there on each evaluation and `axis_origin`/`axis_dir` are where it was when picked.+ /// With `direction_only`, only the axis direction is used: it is projected onto the base+ /// (nothing of that projection is kept as geometry) and the plane turns about the line+ /// through `pivot`, or through the base origin when `pivot` is absent.AtAngle {base: Box<PlaneRef>,axis_origin: Vec3,@@ -68,6 +71,12 @@ pub enum PlaneRef {angle: Expr,#[serde(default, skip_serializing_if = "Option::is_none")]line: Option<Box<GeoRef>>,+ /// Use only the axis direction (projected onto the base), not the axis as a full line.+ #[serde(default, skip_serializing_if = "std::ops::Not::not")]+ direction_only: bool,+ /// Pivot for `direction_only`; absent means the base plane's origin.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pivot: Option<Box<GeoRef>>,},/// A construction plane feature (by id).Construction { feature: FeatureId },@@ -4434,7 +4443,7 @@ impl Document {let b = self.resolve_plane_in(vals, base, depth + 1, st)?;Ok(b.offset(Self::eval_in(vals, distance, Kind::Length)?))}- PlaneRef::AtAngle { base, axis_origin, axis_dir, angle, line } => {+ PlaneRef::AtAngle { base, axis_origin, axis_dir, angle, line, direction_only, pivot } => {let b = self.resolve_plane_in(vals, base, depth + 1, st)?;let a = Self::eval_in(vals, angle, Kind::Angle)?;let (axis_origin, axis_dir) = match line {@@ -4444,7 +4453,26 @@ impl Document {}None => (*axis_origin, *axis_dir),};- let d = axis_dir.normalized().ok_or_else(|| DocError::Invalid("rotation axis".into()))?;+ let (axis_origin, d) = if *direction_only {+ let n = b.normal();+ let in_plane = axis_dir - n * n.dot(axis_dir);+ let d = in_plane+ .normalized()+ .ok_or_else(|| DocError::Invalid("the axis is square to the plane, so it has no direction in the plane".into()))?;+ let pivot = match pivot {+ Some(g) => {+ let st = st.ok_or_else(|| DocError::Invalid("this plane is built from the model: evaluate first".into()))?;+ crate::construct::point(&crate::construct::Ctx { doc: self, vals, st, depth }, g)?+ }+ None => b.origin,+ };+ // Keep the pivot in the base so a slightly off pick still turns about an in-plane line.+ let pivot = pivot - n * n.dot(pivot - b.origin);+ (pivot, d)+ } else {+ let d = axis_dir.normalized().ok_or_else(|| DocError::Invalid("rotation axis".into()))?;+ (axis_origin, d)+ };let rot = |v: Vec3| v * a.cos() + d.cross(v) * a.sin() + d * (d.dot(v) * (1.0 - a.cos()));let o = axis_origin + rot(b.origin - axis_origin);Plane::new(o, rot(b.x), rot(b.y)).ok_or_else(|| DocError::Invalid("degenerate plane".into()))diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rsindex 89a7dedce1..1f6c2a326a 100644--- a/crates/doc/src/eval.rs+++ b/crates/doc/src/eval.rs@@ -7183,12 +7183,14 @@ pub(crate) fn sheet_face_plane_in_frame(doc: &Document, st: &ModelState, comp: uPlaneRef::Offset { base, distance } => {PlaneRef::Offset { base: Box::new(sheet_face_plane_in_frame(doc, st, comp, base)?), distance: distance.clone() }}- PlaneRef::AtAngle { base, axis_origin, axis_dir, angle, line } => PlaneRef::AtAngle {+ PlaneRef::AtAngle { base, axis_origin, axis_dir, angle, line, direction_only, pivot } => PlaneRef::AtAngle {base: Box::new(sheet_face_plane_in_frame(doc, st, comp, base)?),axis_origin: *axis_origin,axis_dir: *axis_dir,angle: angle.clone(),line: line.clone(),+ direction_only: *direction_only,+ pivot: pivot.clone(),},PlaneRef::Flipped { base, about_y } => {PlaneRef::Flipped { base: Box::new(sheet_face_plane_in_frame(doc, st, comp, base)?), about_y: *about_y }@@ -8338,7 +8340,7 @@ fn move_constructions_with(doc: &Document, st: &mut ModelState, moved: &[crate::fn plane_is_fixed(plane: &PlaneRef) -> bool {match plane {PlaneRef::Origin { .. } | PlaneRef::Custom { .. } | PlaneRef::Placed { .. } => true,- PlaneRef::AtAngle { line: Some(_), .. } => false,+ PlaneRef::AtAngle { line: Some(_), .. } | PlaneRef::AtAngle { pivot: Some(_), .. } => false,PlaneRef::Offset { base, .. } | PlaneRef::AtAngle { base, .. } | PlaneRef::Flipped { base, .. } => plane_is_fixed(base),_ => false,}@@ -8349,7 +8351,7 @@ fn plane_is_fixed(plane: &PlaneRef) -> bool {fn plane_reads_geometry(plane: &PlaneRef) -> bool {match plane {PlaneRef::Origin { .. } | PlaneRef::Custom { .. } | PlaneRef::Placed { .. } | PlaneRef::Construction { .. } => false,- PlaneRef::AtAngle { line: Some(_), .. } => true,+ PlaneRef::AtAngle { line: Some(_), .. } | PlaneRef::AtAngle { pivot: Some(_), .. } => true,PlaneRef::Offset { base, .. } | PlaneRef::AtAngle { base, .. } | PlaneRef::Flipped { base, .. } => plane_reads_geometry(base),PlaneRef::ThroughPoint { .. }| PlaneRef::Midplane { .. }diff --git a/crates/doc/src/format/pending/plane-at-angle-direction-only.rs b/crates/doc/src/format/pending/plane-at-angle-direction-only.rsnew file mode 100644index 0000000000..42bf51417c--- /dev/null+++ b/crates/doc/src/format/pending/plane-at-angle-direction-only.rs@@ -0,0 +1,5 @@+//! An at-angle construction plane may save `direction_only` and an optional `pivot` point: the+//! plane turns about the line through the pivot (or the base origin) using only the axis+//! direction projected onto the base. An older design has neither and keeps turning about the+//! axis as a full line. The last release refuses a design that has this change (the newer+//! format number) instead of opening it without the option.diff --git a/crates/doc/src/placement_reuse.rs b/crates/doc/src/placement_reuse.rsindex 723763e3e6..6391d05e6b 100644--- a/crates/doc/src/placement_reuse.rs+++ b/crates/doc/src/placement_reuse.rs@@ -63,7 +63,7 @@ fn local_plane(plane: &PlaneRef, depth: usize) -> bool {PlaneRef::Origin { name: _ } | PlaneRef::Custom { plane: _ } | PlaneRef::Placed { origin: _, x_dir: _, y_dir: _ } => true,PlaneRef::Offset { base, distance: _ }| PlaneRef::Flipped { base, about_y: _ }- | PlaneRef::AtAngle { base, axis_origin: _, axis_dir: _, angle: _, line: None } => local_plane(base, depth + 1),+ | PlaneRef::AtAngle { base, axis_origin: _, axis_dir: _, angle: _, line: None, pivot: None, .. } => local_plane(base, depth + 1),_ => false,}}diff --git a/crates/doc/src/walk.rs b/crates/doc/src/walk.rsindex c4716655fc..d09c2af339 100644--- a/crates/doc/src/walk.rs+++ b/crates/doc/src/walk.rs@@ -411,11 +411,14 @@ impl PlaneRef {base.walk_feature_refs(f, depth + 1);point.walk_feature_refs(f, depth + 1);}- Self::AtAngle { base, line, .. } => {+ Self::AtAngle { base, line, pivot, .. } => {base.walk_feature_refs(f, depth + 1);if let Some(g) = line {g.walk_feature_refs(f, depth + 1);}+ if let Some(g) = pivot {+ g.walk_feature_refs(f, depth + 1);+ }}Self::Midplane { a, b } | Self::TwoEdges { a, b } | Self::AxisPoint { axis: a, point: b } | Self::Perpendicular { plane: a, line: b } => {a.walk_feature_refs(f, depth + 1);@@ -448,11 +451,14 @@ impl PlaneRef {base.walk_feature_refs_mut(f, depth + 1);point.walk_feature_refs_mut(f, depth + 1);}- Self::AtAngle { base, line, .. } => {+ Self::AtAngle { base, line, pivot, .. } => {base.walk_feature_refs_mut(f, depth + 1);if let Some(g) = line {g.walk_feature_refs_mut(f, depth + 1);}+ if let Some(g) = pivot {+ g.walk_feature_refs_mut(f, depth + 1);+ }}Self::Midplane { a, b } | Self::TwoEdges { a, b } | Self::AxisPoint { axis: a, point: b } | Self::Perpendicular { plane: a, line: b } => {a.walk_feature_refs_mut(f, depth + 1);diff --git a/crates/engine/src/cmd/clipboard_foreign.rs b/crates/engine/src/cmd/clipboard_foreign.rsindex b33960a8c5..afdc96c786 100644--- a/crates/engine/src/cmd/clipboard_foreign.rs+++ b/crates/engine/src/cmd/clipboard_foreign.rs@@ -18,7 +18,7 @@ fn independent_plane(plane: &PlaneRef, depth: usize) -> Result<()> {}match plane {PlaneRef::Origin { .. } | PlaneRef::Custom { .. } | PlaneRef::Placed { .. } => Ok(()),- PlaneRef::Offset { base, .. } | PlaneRef::Flipped { base, .. } | PlaneRef::AtAngle { base, line: None, .. } => {+ PlaneRef::Offset { base, .. } | PlaneRef::Flipped { base, .. } | PlaneRef::AtAngle { base, line: None, pivot: None, .. } => {independent_plane(base, depth + 1)}_ => Err(bad(CMD, "the copied sketch's plane depends on model geometry; convert it to a fixed plane before pasting into another design")),diff --git a/crates/engine/src/cmd/features.rs b/crates/engine/src/cmd/features.rsindex 4690557fdc..9ecae7a246 100644--- a/crates/engine/src/cmd/features.rs+++ b/crates/engine/src/cmd/features.rs@@ -155,7 +155,7 @@ pub static COMMANDS: &[CommandSpec] = &[.icon("plane_angle").contract(&PLANE_AT_ANGLE_CONTRACT).output(output_schema_for::<FeatureResult>)- .params("base: XY|XZ|YZ|plane name, or a planar face {face: [x,y,z], body?, index?, path?}; axis: X|Y|Z|construction axis name (where it is now)|{origin, dir} | {edge|face: [x,y,z]} (a straight or circular edge, or a cylinder, cone or torus face: about its axis, followed as the model changes); angle: expr; name?"),+ .params("base: XY|XZ|YZ|plane name, or a planar face {face: [x,y,z], body?, index?, path?}; axis: X|Y|Z|construction axis name (where it is now)|{origin, dir} | {edge|face: [x,y,z]} (a straight or circular edge, or a cylinder, cone or torus face: about its axis, followed as the model changes); angle: expr; direction_only?: bool (default false: turn about the axis as a line; true: project the axis direction onto base and turn about the line through pivot, or the base origin); pivot?: point ref (only with direction_only; vertex, sketch point, construction point); name?"),CommandSpec::new("solid.split_face", "Split Face", split_face).at("SOLID", "MODIFY").icon("split_face")@@ -2533,17 +2533,30 @@ fn plane_angle(s: &mut Session, p: &Value) -> Result<Value> {let angle = req_expr(cmd, p, "angle")?;check_expr(s, &angle, Kind::Angle, cmd, "angle")?;let line = line.map(Box::new);+ let direction_only = crate::params::bool_(p, "direction_only").unwrap_or(false);+ let pivot = match p.get("pivot").filter(|t| !t.is_null()) {+ Some(_) if !direction_only => return Err(bad(cmd, "`pivot` needs `direction_only`: true")),+ Some(t) => Some(Box::new(super::construct::geo(s, Some(t), cmd, "pivot")?)),+ None => None,+ };+ let at_angle = |base: solidcraft_doc::PlaneRef| solidcraft_doc::PlaneRef::AtAngle {+ base: Box::new(base),+ axis_origin,+ axis_dir,+ angle: angle.clone(),+ line: line.clone(),+ direction_only,+ pivot: pivot.clone(),+ };// A planar body face: attached exactly, as a sketch on that face is, so the plane follows it.if let Some(face) = p.get("base").filter(|b| b.get("face").is_some()) {let base = super::sketch::face::capture(s, face, cmd)?;super::sketch::face::capture_positions(s, &base)?;- let plane = solidcraft_doc::PlaneRef::AtAngle { base: Box::new(base), axis_origin, axis_dir, angle, line };// The capture is already in the authoring frame.- return add_feature_in(s, p, FeatureKind::ConstructionPlane { plane }, false);+ return add_feature_in(s, p, FeatureKind::ConstructionPlane { plane: at_angle(base) }, false);}let base = plane_param(s, p.get("base"), cmd)?;- let plane = solidcraft_doc::PlaneRef::AtAngle { base: Box::new(base), axis_origin, axis_dir, angle, line };- add_feature(s, p, FeatureKind::ConstructionPlane { plane })+ add_feature(s, p, FeatureKind::ConstructionPlane { plane: at_angle(base) })}fn split_face(s: &mut Session, p: &Value) -> Result<Value> {diff --git a/crates/engine/src/cmd/sketch_face_tests.rs b/crates/engine/src/cmd/sketch_face_tests.rsindex 44c60602f5..ae5be96888 100644--- a/crates/engine/src/cmd/sketch_face_tests.rs+++ b/crates/engine/src/cmd/sketch_face_tests.rs@@ -418,6 +418,8 @@ fn angled_attachment_tracks_source_plane_and_reopens() {axis_dir: Vec3::X,angle: "90 deg".into(),line: None,+ direction_only: false,+ pivot: None,};s.refresh();let height = s.doc.find_feature("BaseFeature").unwrap().param_names[2].clone();diff --git a/crates/engine/src/construct_tests.rs b/crates/engine/src/construct_tests.rsindex 59389c1c49..da4cf75e1f 100644--- a/crates/engine/src/construct_tests.rs+++ b/crates/engine/src/construct_tests.rs@@ -707,6 +707,82 @@ fn disambiguated_top_plane_pocket_survives_undo_and_cold_reopen() {assert!((measured["total"]["volume_mm3"].as_f64().unwrap() - expected).abs() < 1e-6, "{measured}");}+/// Plane at Angle with "use axis direction only": the axis direction is projected onto the base+/// and the plane turns about a pivot on that plane (#12041).+#[test]+fn plane_at_angle_direction_only_projects_the_axis_and_pivots() {+ let mut s = Session::default();+ // An axis that does not lie on XY: only its in-plane direction is used, about the origin.+ run(+ &mut s,+ "construct.plane.at_angle",+ json!({+ "base": "XY",+ "axis": {"origin": [10, 0, 5], "dir": [0, 1, 1]},+ "angle": "90 deg",+ "direction_only": true,+ "name": "AboutY"+ }),+ );+ let about_y = plane(&s, "AboutY");+ assert!(near(about_y.origin, Vec3::ZERO), "{about_y:?}");+ assert!(parallel(about_y.normal(), Vec3::X), "{about_y:?}");+ assert!(on_plane(&about_y, Vec3::Y * 10.0), "{about_y:?}");++ // Same skewed axis without the option still turns about the full line (origin moves).+ run(+ &mut s,+ "construct.plane.at_angle",+ json!({+ "base": "XY",+ "axis": {"origin": [10, 0, 5], "dir": [0, 1, 1]},+ "angle": "90 deg",+ "name": "AboutLine"+ }),+ );+ let about_line = plane(&s, "AboutLine");+ assert!(!near(about_line.origin, Vec3::ZERO), "{about_line:?}");++ // An explicit pivot: turn about Y through (5, 0, 0).+ run(+ &mut s,+ "construct.plane.at_angle",+ json!({+ "base": "XY",+ "axis": {"origin": [10, 0, 5], "dir": [0, 1, 1]},+ "angle": "90 deg",+ "direction_only": true,+ "pivot": {"point": [5, 0, 0]},+ "name": "Pivoted"+ }),+ );+ let pivoted = plane(&s, "Pivoted");+ assert!(near(pivoted.origin, Vec3::new(5.0, 0.0, 5.0)), "{pivoted:?}");+ assert!(parallel(pivoted.normal(), Vec3::X), "{pivoted:?}");++ // A direction square to the base has no in-plane component.+ let before = s.doc.to_json();+ let error = s+ .execute("construct.plane.at_angle", &json!({"base": "XY", "axis": "Z", "angle": "30 deg", "direction_only": true}))+ .unwrap_err()+ .to_string();+ assert!(error.contains("square to the plane") || error.contains("no direction"), "{error}");+ assert_eq!(s.doc.to_json(), before);++ // A pivot without the option is refused.+ let error = s+ .execute("construct.plane.at_angle", &json!({"base": "XY", "axis": "Y", "angle": "10 deg", "pivot": {"point": [1, 0, 0]}}))+ .unwrap_err()+ .to_string();+ assert!(error.contains("direction_only"), "{error}");+ assert_eq!(s.doc.to_json(), before);++ // Saved fields reopen and keep the pivot.+ let saved = s.doc.to_json();+ let reopened = Session::new(solidcraft_doc::Document::from_json(&saved).unwrap());+ assert!(near(plane(&reopened, "Pivoted").origin, Vec3::new(5.0, 0.0, 5.0)));+}+/// A construction plane named like an origin plane, as an older saved design can hold.fn legacy_plane_name(s: &mut Session, id: u64, name: &str) {s.doc_mut().feature_mut(id).unwrap().name = name.to_string();diff --git a/crates/engine/src/schema/features.rs b/crates/engine/src/schema/features.rsindex 2e1e77c67c..305c6191ed 100644--- a/crates/engine/src/schema/features.rs+++ b/crates/engine/src/schema/features.rs@@ -429,6 +429,14 @@ pub struct PlaneAtAngleParams {pub axis: AxisLine,/// How far to turn, counterclockwise looking back along `axis`'s direction.pub angle: AngleExpr,+ /// Use only the axis direction (projected onto `base`), not the axis as a full line.+ /// When true, the plane turns about the line through `pivot` (or the base origin).+ #[serde(default)]+ pub direction_only: Option<bool>,+ /// Pivot for `direction_only`: a vertex, sketch point, construction point or fixed point.+ /// Omit to use the base plane's origin. `null` counts as not given.+ #[serde(default)]+ pub pivot: Option<GeoRefParam>,#[serde(flatten, deserialize_with = "feature_common")]pub common: PlaneCommon,}diff --git a/crates/engine/src/schema/features_tests.rs b/crates/engine/src/schema/features_tests.rsindex bc55cbddba..9ca9a18cd4 100644--- a/crates/engine/src/schema/features_tests.rs+++ b/crates/engine/src/schema/features_tests.rs@@ -86,7 +86,7 @@ fn schemas_and_the_key_check_agree() {assert_keys(input_schema_for::<BoundingSolidParams>(), &["bodies", "body_name", "body_names", "margin", "name", "participants"]);assert_keys(input_schema_for::<ScaleParams>(), &["bodies", "factor", "factors", "name", "origin", "participants"]);assert_keys(input_schema_for::<OffsetPlaneParams>(), &["base", "name", "offset", "participants", "through"]);- assert_keys(input_schema_for::<PlaneAtAngleParams>(), &["angle", "axis", "base", "name", "participants"]);+ assert_keys(input_schema_for::<PlaneAtAngleParams>(), &["angle", "axis", "base", "direction_only", "name", "participants", "pivot"]);assert_keys(input_schema_for::<FilletParams>(),&[diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 81063bb859..f7d80b476e 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -127,9 +127,10 @@ crate::dialog_descriptor::dialog_descriptors! {offset: String = "0 mm".into() => shown_expr(distance, ValueKind::Length),} => json!({"offset": offset});AnglePlane("construct.plane.at_angle", "PLANE AT ANGLE", [("Plane", PLANES | PLANAR_FACES, false), ("Axis", AXIS_PICKS, false)],- FeatureKind::ConstructionPlane { plane: PlaneRef::AtAngle { angle, .. } }) {+ FeatureKind::ConstructionPlane { plane: PlaneRef::AtAngle { angle, direction_only, .. } }) {angle: String = "45 deg".into() => shown_expr(angle, ValueKind::Angle),- } => json!({"angle": angle});+ direction_only: bool = false => *direction_only,+ } => json!({"angle": angle, "direction_only": direction_only});// With a reference plane, the plane touches where the face turns towards it (#8822).TangentPlane("construct.plane.tangent", "TANGENT PLANE", [("Face", FACES, false), ("Reference plane", PLANES | PLANAR_FACES, false)],FeatureKind::ConstructionPlane { plane: PlaneRef::Tangent { angle, .. } }) {@@ -1464,7 +1465,7 @@ impl Dialog {}Kind::Pipe { diameter, .. } => ("Diameter", ValueKind::Length, diameter),Kind::Stock { margin } => ("Margin", ValueKind::Length, margin),- Kind::AnglePlane { angle } => ("Angle", ValueKind::Angle, angle),+ Kind::AnglePlane { angle, .. } => ("Angle", ValueKind::Angle, angle),Kind::Scale { per_axis: true, .. } => return None,Kind::Scale { factor, .. } => ("Scale", ValueKind::Unitless, factor),Kind::OffsetFaces { distance } => ("Distance", ValueKind::Length, distance),@@ -5558,14 +5559,18 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, SNone => ("construct.plane.tangent", json!({"face": face, "angle": null})),}}- Kind::AnglePlane { .. } => {+ Kind::AnglePlane { direction_only, .. } => {need(0, "a plane")?;let base = plane_arg(app, sels(d, 0).first())?;let axis = match sels(d, 1).first() {Some(x) => axis_param(app, x)?,None => d.extra.get("axis").cloned().ok_or("pick an axis")?,};- ("construct.plane.at_angle", json!({"base": base, "axis": axis}))+ let mut p = json!({"base": base, "axis": axis, "direction_only": direction_only});+ if *direction_only && let Some(pivot) = angle_pivot(d) {+ p["pivot"] = construct_ref(app, pivot)?;+ }+ ("construct.plane.at_angle", p)}Kind::Rib { web, thickness, depth, flip, normal } => {need(0, "open sketch curves")?;@@ -6562,7 +6567,15 @@ pub(crate) fn offset_through_point(d: &Dialog) -> Option<&Sel> {sels(d, 1).first()}-/// A stored point reference back into a dialog pick: a body vertex or a sketch point.+/// Pivot pick on Plane at Angle when "Use axis direction only" is on.+pub(crate) fn angle_pivot(d: &Dialog) -> Option<&Sel> {+ if !matches!(d.kind, Kind::AnglePlane { direction_only: true, .. }) {+ return None;+ }+ d.inputs.iter().find(|i| i.label == "Pivot").and_then(|i| i.items.first())+}++/// A stored point reference back into a dialog pick: a body vertex, sketch point or construction point.fn point_sel(s: &Session, g: &solidcraft_engine::doc::construct::GeoRef) -> Option<Sel> {use solidcraft_engine::doc::construct::GeoRef;match g {@@ -6571,6 +6584,9 @@ fn point_sel(s: &Session, g: &solidcraft_engine::doc::construct::GeoRef) -> Opti_ => None,},GeoRef::SketchPoint { sketch, point } => Some(Sel::SketchPoint { id: format!("{sketch}:{point}") }),+ GeoRef::ConstructPoint { name } => Some(Sel::ConstructionPoint { name: name.to_string() }),+ GeoRef::Origin => Some(Sel::Vertex { body: String::new(), point: Vec3::ZERO }),+ GeoRef::Point { p } => Some(Sel::Vertex { body: String::new(), point: *p }),_ => None,}}@@ -7446,7 +7462,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia}d}- FeatureKind::ConstructionPlane { plane: PlaneRef::AtAngle { base, axis_origin, axis_dir, line, .. } } => {+ FeatureKind::ConstructionPlane { plane: PlaneRef::AtAngle { base, axis_origin, axis_dir, line, direction_only, pivot, .. } } => {let mut d = start("construct.plane.at_angle")?;d.kind = Kind::simple_restore(&f.kind)?;if let Some(inp) = d.inputs.first_mut() {@@ -7469,6 +7485,13 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Diad.extra.insert("axis".into(), json!({"origin": pt3(*axis_origin), "dir": pt3(*axis_dir)}));}}+ if *direction_only {+ const PIVOT: Accept = selection::VERTICES | selection::POINTS | selection::CONSTRUCTION_POINTS;+ set_object_accepting(&mut d.inputs, &mut d.active, "Pivot", PIVOT, true);+ if let Some(inp) = d.inputs.iter_mut().find(|i| i.label == "Pivot") {+ inp.items = pivot.as_deref().and_then(|g| point_sel(s, g)).into_iter().collect();+ }+ }d}FeatureKind::Split { body, plane, tool, sketch, line } => {@@ -7716,7 +7739,7 @@ mod refused_ok_tests {let mut dialog = Dialog::for_command(&app, "construct.plane.at_angle").expect("the command has a dialog");dialog.inputs[0].items = vec![Sel::Plane { name: "XY".into() }];dialog.inputs[1].items = vec![Sel::Axis { name: "X".into() }];- if let Kind::AnglePlane { angle } = &mut dialog.kind {+ if let Kind::AnglePlane { angle, .. } = &mut dialog.kind {*angle = "30 deg".into();}diff --git a/crates/ui-egui/src/dialogs_all_tests.rs b/crates/ui-egui/src/dialogs_all_tests.rsindex 0d614910ef..d31f67eb9a 100644--- a/crates/ui-egui/src/dialogs_all_tests.rs+++ b/crates/ui-egui/src/dialogs_all_tests.rs@@ -374,6 +374,7 @@ fn check_form(command: &str, labels: &[&str]) {"joint.rack_pinion" | "joint.screw" => &["Reverse"],"joint.cam" => &["Other side"],"frame.member" => &["All Lines", "Mirror"],+ "construct.plane.at_angle" => &["Use axis direction only"],_ => &[],};for label in checks {diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rsindex 7c9ce232e6..e27822734c 100644--- a/crates/ui-egui/src/dialogs_dense.rs+++ b/crates/ui-egui/src/dialogs_dense.rs@@ -898,8 +898,11 @@ fn additional_rows(app: &mut SolveApp, d: &mut Dialog, ui: &mut egui::Ui) -> booenter |= expr_row(ui, "Distance", offset);}}- Kind::AnglePlane { angle } => {+ Kind::AnglePlane { angle, direction_only } => {enter |= expr_row(ui, "Angle", angle);+ ui_kit::options(ui, "plane_angle_options", &mut [("Use axis direction only", direction_only)]);+ const PIVOT: Accept = selection::VERTICES | selection::POINTS | selection::CONSTRUCTION_POINTS;+ set_object_accepting(&mut d.inputs, &mut d.active, "Pivot", PIVOT, *direction_only);}// The angle turns the plane from its reference, so it shows once one is picked.Kind::TangentPlane { angle } => {diff --git a/crates/ui-egui/src/preselect_tests.rs b/crates/ui-egui/src/preselect_tests.rsindex 7553eff104..45c553b42f 100644--- a/crates/ui-egui/src/preselect_tests.rs+++ b/crates/ui-egui/src/preselect_tests.rs@@ -2847,6 +2847,63 @@ fn offset_plane_through_a_picked_vertex() {assert!(matches!(reopened.inputs[1].items.as_slice(), [Sel::Vertex { body, .. }] if body == "Box"), "{:?}", reopened.inputs[1].items);}+/// Plane at Angle's "Use axis direction only" option shows a Pivot pick and sends both parameters (#12041).+#[test]+fn plane_at_angle_direction_only_shows_a_pivot_and_applies() {+ let mut h = crate::scenario::Harness::new();+ h.app.run("solid.box", json!({"length":40,"width":30,"height":20,"body_name":"Box"})).unwrap();+ h.app.start("construct.plane.at_angle");+ h.frames(2);+ let d = h.app.dialog.as_mut().unwrap();+ assert!(matches!(d.kind, Kind::AnglePlane { direction_only: false, .. }));+ assert!(!d.inputs.iter().any(|i| i.label == "Pivot"), "{:?}", d.inputs);+ d.inputs[0].items = vec![Sel::Plane { name: "XY".into() }];+ d.inputs[1].items = vec![Sel::Axis { name: "Y".into() }];+ if let Kind::AnglePlane { direction_only, .. } = &mut d.kind {+ *direction_only = true;+ }+ // The dense form adds Pivot once the option is on; mirror that here for the parameter build.+ {+ let d = h.app.dialog.as_mut().unwrap();+ crate::dialogs::set_object_accepting(+ &mut d.inputs,+ &mut d.active,+ "Pivot",+ crate::selection::VERTICES | crate::selection::POINTS | crate::selection::CONSTRUCTION_POINTS,+ true,+ );+ let pivot = d.inputs.iter_mut().find(|i| i.label == "Pivot").expect("Pivot");+ pivot.items = vec![Sel::Vertex { body: "Box".into(), point: Vec3::new(40.0, 0.0, 0.0) }];+ if let Kind::AnglePlane { angle, .. } = &mut d.kind {+ *angle = "90 deg".into();+ }+ }+ let commands = apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();+ assert_eq!(+ commands.first().map(|c| c.1.clone()),+ Some(json!({+ "base": "XY",+ "axis": "Y",+ "angle": "90 deg",+ "direction_only": true,+ "pivot": {"vertex": [40.0, 0.0, 0.0]}+ }))+ );+ let (cmd, params) = commands.into_iter().next().unwrap();+ h.app.dialog = None;+ let id = h.app.run(&cmd, params).unwrap()["feature"].as_u64().unwrap();+ let pl = solidcraft_engine::view::construction_planes(&h.app.session)+ .into_iter()+ .find(|(fid, _, _)| *fid == id)+ .map(|(_, _, pl)| pl)+ .expect("the plane");+ assert!(pl.origin.dist(Vec3::new(40.0, 0.0, 40.0)) < 1e-3, "{pl:?}");+ assert!(pl.normal().cross(Vec3::X).len() < 1e-6, "{pl:?}");+ let reopened = crate::dialogs::for_feature(&h.app, id, None).unwrap();+ assert!(matches!(reopened.kind, Kind::AnglePlane { direction_only: true, .. }), "{:?}", reopened.kind);+ assert!(reopened.inputs.iter().any(|i| i.label == "Pivot" && !i.items.is_empty()), "{:?}", reopened.inputs);+}+/// Plane at Angle draws the tilted plane while its dialog is open, when created and when edited,/// and redraws it when the angle changes (it used to show only the picked plane and the label).#[test]@@ -2861,7 +2918,7 @@ fn plane_at_angle_previews_the_tilted_plane_when_edited() {assert!(d.previews(), "the edited plane is previewed");wait_feature_preview(&mut h);let first = h.app.preview.key;- if let Kind::AnglePlane { angle } = &mut h.app.dialog.as_mut().unwrap().kind {+ if let Kind::AnglePlane { angle, .. } = &mut h.app.dialog.as_mut().unwrap().kind {*angle = "30 deg".into();}wait_feature_preview(&mut h);diff --git a/crates/ui-egui/src/sketch_attachment_ui_tests.rs b/crates/ui-egui/src/sketch_attachment_ui_tests.rsindex f415eaac12..3acdfd72c8 100644--- a/crates/ui-egui/src/sketch_attachment_ui_tests.rs+++ b/crates/ui-egui/src/sketch_attachment_ui_tests.rs@@ -294,6 +294,8 @@ fn nested_anchor_saved_fixed_conversion_preserves_rotated_second_author_plane()axis_dir: Vec3::X,angle: "15 deg".into(),line: None,+ direction_only: false,+ pivot: None,};h.app.session = solidcraft_engine::Session::new(document);let raw = h.app.session.doc.sketch(id).unwrap().clone();diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex 750c711b4f..e5436cd3e4 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -7795,7 +7795,7 @@ mod tests {let mut dialog = crate::dialogs::Dialog::for_command(&app, "construct.plane.at_angle").unwrap();dialog.inputs[0].items = vec![Sel::Plane { name: "XY".into() }];dialog.inputs[1].items = vec![selected];- if let crate::dialogs::Kind::AnglePlane { angle } = &mut dialog.kind {+ if let crate::dialogs::Kind::AnglePlane { angle, .. } = &mut dialog.kind {*angle = "90 deg".into();}for (command, params) in crate::dialogs::apply_commands(&app, &dialog).unwrap() {