Skip to content
Closed
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
42 changes: 42 additions & 0 deletions assets/locales/pending/joint-both-grounded.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"en": {
"joint.both_grounded": "{joint} moves neither part: both are grounded ({a}, {b}). Unground one to let the joint place it.",
"joint.conflicts": "{joint} doesn't hold: {why}",
"joint.unground": "Unground {part}"
},
"ar": {
"joint.both_grounded": "لا يحرّك {joint} أيًّا من الجزأين: كلاهما مثبّت بالأرض ({a}، {b}). فُكّ تثبيت أحدهما ليضعه المفصل في مكانه.",
"joint.conflicts": "لا يتحقق {joint}: {why}",
"joint.unground": "فك تثبيت {part} بالأرض"
},
"de": {
"joint.both_grounded": "{joint} bewegt keines der beiden Teile: Beide sind festgesetzt ({a}, {b}). Lösen Sie die Fixierung eines Teils, damit das Gelenk es platziert.",
"joint.conflicts": "{joint} hält nicht: {why}",
"joint.unground": "Fixierung von {part} lösen"
},
"he": {
"joint.both_grounded": "{joint} לא מזיז אף אחד מהחלקים: שניהם מעוגנים ({a}, {b}). בטלו את העיגון של אחד מהם כדי שהמפרק ימקם אותו.",
"joint.conflicts": "{joint} לא מתקיים: {why}",
"joint.unground": "ביטול עיגון של {part}"
},
"ja": {
"joint.both_grounded": "{joint} はどちらの部品も動かしません: 両方とも空間固定されています ({a}, {b})。ジョイントで配置するには、どちらかの固定を解除してください。",
"joint.conflicts": "{joint} が成り立ちません: {why}",
"joint.unground": "{part} の固定を解除"
},
"ko": {
"joint.both_grounded": "{joint}은(는) 어느 부품도 움직이지 않습니다: 둘 다 고정되어 있습니다({a}, {b}). 관절이 배치하도록 하나의 고정을 해제하세요.",
"joint.conflicts": "{joint}이(가) 성립하지 않습니다: {why}",
"joint.unground": "{part} 고정 해제"
},
"vi": {
"joint.both_grounded": "{joint} không di chuyển chi tiết nào: cả hai đều đã cố định ({a}, {b}). Hủy cố định một chi tiết để khớp nối đặt nó vào vị trí.",
"joint.conflicts": "{joint} không được thỏa mãn: {why}",
"joint.unground": "Hủy cố định {part}"
},
"zh": {
"joint.both_grounded": "{joint} 不移动任何一个零件:两者都已固定({a}、{b})。请取消其中一个的固定,让接头放置它。",
"joint.conflicts": "{joint} 无法满足:{why}",
"joint.unground": "取消固定 {part}"
}
}
26 changes: 26 additions & 0 deletions assets/locales/pending/joint-ground-skips.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"en": {
"joint.skips_part": "{joint} doesn't place {part}: {why}"
},
"ar": {
"joint.skips_part": "لا يضع {joint} الجزء {part} في مكانه: {why}"
},
"de": {
"joint.skips_part": "{joint} platziert {part} nicht: {why}"
},
"he": {
"joint.skips_part": "{joint} לא ממקם את {part}: {why}"
},
"ja": {
"joint.skips_part": "{joint} は {part} を配置しません: {why}"
},
"ko": {
"joint.skips_part": "{joint}이(가) {part}을(를) 배치하지 않습니다: {why}"
},
"vi": {
"joint.skips_part": "{joint} không đặt {part} vào vị trí: {why}"
},
"zh": {
"joint.skips_part": "{joint} 无法放置 {part}:{why}"
}
}
15 changes: 10 additions & 5 deletions crates/doc/src/joints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2505,11 +2505,16 @@ pub fn solve_holding_with_analysis(doc: &Document, st: &ModelState, held: &Held,
// Measured at the joint, where the loop solver closes it.
let (dt, da) = mismatch(&mat_mul(&want, &frames.b), &mat_mul(tb, &frames.b));
if dt > CONFLICT_MM || da > CONFLICT_RAD {
sol.conflicts.push((
j.id,
j.name.clone(),
format!("off by {dt:.4} mm and {:.3}° from the placement the other joints give", da.to_degrees()),
));
let why = if tree.fixed.contains_key(&j.a.occurrence) && tree.fixed.contains_key(&j.b.occurrence) {
let name = |occ: u64| doc.occurrences.iter().find(|o| o.id == occ).map_or_else(|| occ.to_string(), |o| o.name.clone());
match (j.a.occurrence, j.b.occurrence) {
(0, o) | (o, 0) => format!("it joins the design's base to {}, which is grounded, so it can move neither", name(o)),
(a, b) => format!("both its parts are grounded ({}, {}), so it can move neither", name(a), name(b)),
}
} else {
format!("off by {dt:.4} mm and {:.3}° from the placement the other joints give", da.to_degrees())
};
sol.conflicts.push((j.id, j.name.clone(), why));
} else if stuck.contains(id) {
// It meets there, but the loop would have to come apart on the way (a rocker
// driven a full turn ends where it started).
Expand Down
48 changes: 46 additions & 2 deletions crates/engine/src/cmd/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! share contents, "paste new" copies them) and can be grounded and moved.

use solidcraft_geom::prelude::*;
use std::collections::HashMap;
use std::collections::{BTreeMap, BTreeSet, HashMap};

use serde_json::{Value, json};
use solidcore_record::Vec3;
Expand All @@ -21,6 +21,7 @@ use crate::schema::component::{
OccurrencePropertiesResult, PasteNewParams, PasteNewResult, PlacementEntry, PlacementInfo, PropertiesParams, PropertiesResult, RenameParams,
RenameResult, ReparentItemsParams, ReparentItemsResult, RevertPositionParams, RevertPositionResult, UnlockParams, UnlockResult,
};
use crate::schema::joints::JointProblem;
use crate::schema::{TypedContract, output_schema_for};
use crate::{Result, Session};

Expand Down Expand Up @@ -1066,7 +1067,50 @@ fn ground(s: &mut Session, p: &Value) -> Result<Value> {
let o = s.doc_mut().occurrences.iter_mut().find(|o| o.id == id).ok_or_else(|| bad(cmd, "occurrence"))?;
o.grounded = want.unwrap_or(!o.grounded);
let g = o.grounded;
reply(GroundResult { occurrence: id, grounded: g, param_warnings: Vec::new() })
reply(after_grounding(s, id, g))
}

/// The reply to `occurrence.ground` once the joints are solved for the new flag: the occurrences
/// the solve moved, where this one is now, the conflicts, and the joints the solve skips (an
/// origin that no longer resolves) among those touching the free parts joined to this one.
/// Ungrounding a part that no joint places also warns, naming each such skipped joint and why.
fn after_grounding(s: &mut Session, id: u64, grounded: bool) -> GroundResult {
let before: BTreeMap<u64, Mat> = s.doc.occurrences.iter().map(|o| (o.id, o.transform)).collect();
let sol = if s.doc.assembly.joints.is_empty() { solidcraft_doc::joints::Solution::default() } else { s.place_joints() };
let moved: Vec<u64> = s.doc.occurrences.iter().filter(|o| before.get(&o.id).is_some_and(|m| *m != o.transform)).map(|o| o.id).collect();
let (name, transform) = s.doc.occurrences.iter().find(|o| o.id == id).map(|o| (o.name.clone(), o.transform)).unwrap_or_default();
let on = joints_of_group(s, id, &sol.fixed);
let problem = |(joint, name, why): (u64, String, String)| JointProblem { joint, name, why };
let skipped: Vec<JointProblem> = sol.errors.into_iter().filter(|(j, ..)| on.contains(j)).map(problem).collect();
let warning = (!grounded && !sol.world.contains_key(&id) && !skipped.is_empty())
.then(|| skipped.iter().map(|e| format!("{} doesn't place {name}: {}", e.name, e.why)).collect::<Vec<_>>().join("; "));
GroundResult {
occurrence: id,
grounded,
transform,
moved,
conflicts: sol.conflicts.into_iter().map(problem).collect(),
skipped,
warning,
param_warnings: Vec::new(),
}
}

/// The joints touching `id` and the free parts joined to it: a walk over the joints that stops
/// at the fixed occurrences.
fn joints_of_group(s: &Session, id: u64, fixed: &[u64]) -> BTreeSet<u64> {
let joints: Vec<_> = s.doc.assembly.joints.iter().filter(|j| !j.suppressed).take(solidcraft_doc::joints::MAX_JOINTS).collect();
let mut group = BTreeSet::from([id]);
let mut pending = vec![id];
while let Some(occ) = pending.pop() {
for j in joints.iter().filter(|j| j.a.occurrence == occ || j.b.occurrence == occ) {
let other = if j.a.occurrence == occ { j.b.occurrence } else { j.a.occurrence };
if !fixed.contains(&other) && group.insert(other) {
pending.push(other);
}
}
}
joints.iter().filter(|j| group.contains(&j.a.occurrence) || group.contains(&j.b.occurrence)).map(|j| j.id).collect()
}

fn capture(s: &mut Session, _p: &Value) -> Result<Value> {
Expand Down
12 changes: 10 additions & 2 deletions crates/engine/src/cmd/joints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ fn add_joint(s: &mut Session, mut j: Joint, p: &Value) -> Result<Value> {
let round = |v: f64| (v * 1e6).round() / 1e6;
// As the reply shows them: a value that is not a number reads as null, and null is null.
let same = |a: f64, b: f64| a == b || (a.is_nan() && b.is_nan());
let warnings: Vec<String> = named_value_list(&j, &q)
let mut warnings: Vec<String> = named_value_list(&j, &q)
.iter()
.zip(named_value_list(&j, &j.values))
.filter(|(now, was)| !same(now.value, was.value))
Expand All @@ -1205,13 +1205,19 @@ fn add_joint(s: &mut Session, mut j: Joint, p: &Value) -> Result<Value> {
j.values = q;
let id = j.id;
let name = j.name.clone();
let sides = [j.a.occurrence, j.b.occurrence];
// A new joint starts shown, even if a stale visibility entry came from an older design.
s.visibility.hidden_joints.retain(|h| *h != id);
s.doc_mut().assembly.joints.push(j);
let mut sol = resolve(s);
if sol.conflicts.iter().any(|(c, ..)| *c == id) && close_by_half_turn(s, id, &sol) {
sol = resolve(s);
}
if sides.iter().all(|o| sol.fixed.contains(o))
&& let Some((.., why)) = sol.conflicts.iter().find(|(c, ..)| *c == id)
{
warnings.push(format!("{name}: {why}"));
}
reply("joint.create", JointAddedResult { solved: solve_report(&sol, p), joint: id, name, warnings, param_warnings: Vec::new() })
}

Expand Down Expand Up @@ -2200,7 +2206,9 @@ pub(super) fn edit_joint(s: &mut Session, p: &Value, plain: bool) -> Result<Valu
if placed && sol.conflicts.iter().any(|(c, ..)| *c == id) && close_by_half_turn(s, id, &sol) {
sol = resolve(s);
}
Ok(sol_json(&sol, p))
let mut out = sol_json(&sol, p);
out["joint"] = json!(id);
Ok(out)
}

/// Shared mutation for individual joints and timeline folders; the caller resolves once.
Expand Down
Loading