Files
makeCAD/crates/engine/src/schema/joints.rs
T
momysnow 60b9e9d188 Edit Joint: show the two sides and pick them again (#9686) (#9692)
* claim: #9686

Co-Authored-By: Claude <noreply@anthropic.com>

* Edit Joint: joint.edit takes the two sides

joint.edit accepts a and b in the form joint.create takes them (read by the same origin_param), so a joint can move its attachment without being deleted. A side left out keeps its place. The two sides must stay on different occurrences, checked as joint.create does. Limits, values, expressions and the name are kept; a relation's values start again where its parts are.

joint.edit gets an input contract and reply type (schema/joints.rs), and leaves schema/unconverted.txt.

Co-Authored-By: Claude <noreply@anthropic.com>

* Edit Joint shows both sides and picks them again

The Edit Joint dialog now shows the two sides in the same selection inputs as Joint, each pre-filled with the face or edge of its own component under the origin. OK sends joint.edit a or b only for a side picked again, so an untouched side keeps its origin exactly.

Co-Authored-By: Claude <noreply@anthropic.com>

* Edit Joint: a moved side turns the part as joint.create would

joint.edit kept the joint's old angle when a side changed, so the part could turn by a half turn about its axis when the new origin's x lay the other way. When a side moves and no angle is given, the angle is worked out again as joint.create does (the least turn from where the part is now); a relation's angle is its tilt and stays.

The mechanisms reference says joint.edit takes a and b.

Co-Authored-By: Claude <noreply@anthropic.com>

* Edit Joint: pre-fill sides by name, send the angle only when changed

A side shows the face or edge its snap names, the piece nearest its stored pick when the name has several, else the one nearest that pick; it no longer searches outward from the frame origin, which could show the plate beside a hole for the hole's wall. A point or frame side shows nothing. OK sends the angle only when the user changed it, so a side moved without it turns the part as joint.create would.

Co-Authored-By: Claude <noreply@anthropic.com>

* Edit Joint: a moved side leaves an angle expression alone (#9686)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-31 02:27:54 +00:00

114 lines
4.7 KiB
Rust

//! Contracts and result types for the commands in `cmd/joints.rs`.
use std::borrow::Cow;
use schemars::{JsonSchema, Schema, SchemaGenerator, json_schema};
use serde::de::Error as _;
use serde::{Deserialize, Deserializer, Serialize};
use serde_json::Value;
use super::types::{AngleExpr, IdOrName, LengthExpr, present};
/// A joint origin as joint.create takes it: a joint origin's name, or an object with the snap
/// (`occurrence`, then `face`, `circle`, `edge` or `point`, or a `frame`). Kept as given, for the
/// handler, which reads it as it reads joint.create's sides.
#[derive(Clone, Debug, PartialEq)]
pub struct JointOriginParam(pub Value);
impl<'de> Deserialize<'de> for JointOriginParam {
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
match Value::deserialize(d)? {
v @ (Value::String(_) | Value::Object(_)) => Ok(JointOriginParam(v)),
_ => Err(D::Error::custom("must be a joint origin's name or an object")),
}
}
}
impl JsonSchema for JointOriginParam {
fn schema_name() -> Cow<'static, str> {
"JointOrigin".into()
}
fn json_schema(_: &mut SchemaGenerator) -> Schema {
json_schema!({
"description": "A joint origin, as joint.create takes a side: a joint origin's name, or an object with occurrence and face, circle, edge or point (world coordinates, or a face's name), with z?, x?, end?, on?, corner?, or with a frame {origin, z, x?}.",
"anyOf": [
{"type": "string", "minLength": 1},
{"type": "object"}
]
})
}
}
/// Edit a joint in place. The sides `a` and `b` take a joint origin as joint.create does; a side
/// left out keeps its place, and the two must stay on different occurrences. The joint re-solves
/// and keeps its limits, its drive and the expressions it follows; a relation's values start
/// again where its parts are when its sides, type, offset, angle or flip change.
#[derive(Debug, Deserialize, JsonSchema)]
#[schemars(deny_unknown_fields)]
pub struct EditJointParams {
/// The joint, by id or name.
pub joint: IdOrName,
/// Side a: a joint origin, as joint.create takes it. Default: a keeps its place.
#[serde(default, deserialize_with = "present")]
pub a: Option<JointOriginParam>,
/// Side b: a joint origin, as joint.create takes it. Default: b keeps its place.
#[serde(default, deserialize_with = "present")]
pub b: Option<JointOriginParam>,
/// The joint's type, as joint.create takes it (rigid, revolute, slider, ...).
#[serde(default, rename = "type", deserialize_with = "present")]
pub kind: Option<String>,
/// Whether b's z lies along a's instead of against it, as joint.create's `flip`.
#[serde(default, deserialize_with = "present")]
pub flip: Option<bool>,
/// The distance from a's frame to b's along z: a length, or an expression the joint follows.
#[serde(default, deserialize_with = "present")]
pub offset: Option<LengthExpr>,
/// The turn about that distance: an angle, or an expression the joint follows.
#[serde(default, deserialize_with = "present")]
pub angle: Option<AngleExpr>,
/// Suppress the joint (true) or bring it back (false).
#[serde(default, deserialize_with = "present")]
pub suppressed: Option<bool>,
/// The joint's new name.
#[serde(default, deserialize_with = "present")]
pub name: Option<String>,
/// Leave out the degrees of freedom and the fixed occurrences in the reply.
#[serde(default, deserialize_with = "present")]
pub quiet: Option<bool>,
}
/// A joint the solve reports: its id, name and why.
#[derive(Debug, Serialize, JsonSchema)]
pub struct JointProblem {
pub joint: u64,
pub name: String,
pub why: String,
}
/// The degrees of freedom one occurrence keeps (6 free, 0 fixed).
#[derive(Debug, Serialize, JsonSchema)]
pub struct OccurrenceDof {
pub occurrence: u64,
pub dof: usize,
}
/// What `joint.edit` returns: the joints that disagree with the solved placement, and those the
/// solve could not apply. Unless `quiet`, also each occurrence's degrees of freedom and the
/// occurrences fixed in place.
#[derive(Debug, Serialize, JsonSchema)]
pub struct EditJointResult {
pub conflicts: Vec<JointProblem>,
pub errors: Vec<JointProblem>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub dof: Option<Vec<OccurrenceDof>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub fixed: Option<Vec<u64>>,
/// In the warn parameter-check mode: what the call's parameters got wrong.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub param_warnings: Vec<String>,
}
#[cfg(test)]
#[path = "joints_tests.rs"]
mod tests;