Rename SolveCraft to SolidCraft everywhere, with compatibility shims (#389)
* WIP deep rename (not for push) * WIP2 * WIP3 * WIP4 wxs fix * rustfmt * Rename the remaining identifiers in merged crash-report code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RjGw4gA5ZvKrU8MQP6sBgT --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
27415e4dd7
commit
296683229d
464 files changed
+3408
-2956
No files matched your search
@@ -1,9 +1,9 @@
|
||||
//! Sketch commands: create/edit/finish sketches, draw curves, constraints and dimensions.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use solvecraft_doc::{FeatureKind, PlaneRef, expr::Kind};
|
||||
use solvecraft_geom::{Plane, Vec2, Vec3};
|
||||
use solvecraft_sketch::{Analysis, Budget, ConstraintKind, CurveKind, Hold, Sketch, SolveReport, solve, solve_with};
|
||||
use solidcraft_doc::{FeatureKind, PlaneRef, expr::Kind};
|
||||
use solidcraft_geom::{Plane, Vec2, Vec3};
|
||||
use solidcraft_sketch::{Analysis, Budget, ConstraintKind, CurveKind, Hold, Sketch, SolveReport, solve, solve_with};
|
||||
|
||||
use super::{CommandSpec, in_sketch};
|
||||
use crate::params::{bad, bool_, expr, num, req_vec2, str_, string_list, vec2, vec3};
|
||||
@@ -222,7 +222,7 @@ pub(super) fn edit<T>(
|
||||
p: &Value,
|
||||
cmd: &str,
|
||||
strict: bool,
|
||||
f: impl FnOnce(&mut Sketch, &mut solvecraft_doc::Document) -> Result<T>,
|
||||
f: impl FnOnce(&mut Sketch, &mut solidcraft_doc::Document) -> Result<T>,
|
||||
) -> Result<(T, Value)> {
|
||||
let id = target_sketch(s, p, cmd)?;
|
||||
let (out, rep) = edit_solved(s, id, strict, |sk, doc| Ok((f(sk, doc)?, Left::Unsolved)))?;
|
||||
@@ -262,7 +262,7 @@ pub(super) fn edit_solved<T>(
|
||||
s: &mut Session,
|
||||
id: u64,
|
||||
strict: bool,
|
||||
f: impl FnOnce(&mut Sketch, &mut solvecraft_doc::Document) -> Result<(T, Left)>,
|
||||
f: impl FnOnce(&mut Sketch, &mut solidcraft_doc::Document) -> Result<(T, Left)>,
|
||||
) -> Result<(T, Option<SolveReport>)> {
|
||||
let mut doc = (*s.doc).clone();
|
||||
let mut sk = doc.sketch(id)?.clone();
|
||||
@@ -333,7 +333,7 @@ pub(super) fn counted_solve(
|
||||
/// Inside an `edit` closure: solve the sketch for the document's parameter values from its
|
||||
/// stored solved state, as the edit's own solve does, for commands that work on the current
|
||||
/// geometry.
|
||||
pub(super) fn solve_current(sk: &mut Sketch, doc: &solvecraft_doc::Document) -> Result<SolveReport> {
|
||||
pub(super) fn solve_current(sk: &mut Sketch, doc: &solidcraft_doc::Document) -> Result<SolveReport> {
|
||||
let stored = sk.driving_values();
|
||||
let (values, _) = doc.param_values();
|
||||
Ok(doc.solve_sketch(&values, sk, &stored)?)
|
||||
@@ -345,7 +345,7 @@ pub(super) fn solve_current(sk: &mut Sketch, doc: &solvecraft_doc::Document) ->
|
||||
pub(super) mod solve_counts {
|
||||
use std::cell::Cell;
|
||||
|
||||
use solvecraft_sketch::Analysis;
|
||||
use solidcraft_sketch::Analysis;
|
||||
|
||||
thread_local! {
|
||||
static COUNTS: Cell<(usize, usize)> = const { Cell::new((0, 0)) };
|
||||
@@ -395,7 +395,7 @@ pub(super) fn draw(
|
||||
s: &mut Session,
|
||||
p: &Value,
|
||||
cmd: &str,
|
||||
f: impl FnOnce(&mut Sketch, &mut solvecraft_doc::Document) -> Result<(Vec<String>, Vec<String>)>,
|
||||
f: impl FnOnce(&mut Sketch, &mut solidcraft_doc::Document) -> Result<(Vec<String>, Vec<String>)>,
|
||||
) -> Result<((Vec<String>, Vec<String>), Value)> {
|
||||
edit(s, p, cmd, false, |sk, doc| {
|
||||
let first = sk.points.len();
|
||||
@@ -497,7 +497,7 @@ pub(crate) fn created(before: Option<&Sketch>, after: &Sketch) -> Value {
|
||||
let points: Vec<&str> = after.points.iter().map(|x| x.id.as_str()).filter(new).collect();
|
||||
let curves: Vec<&str> = after.curves.iter().map(|x| x.id.as_str()).filter(new).collect();
|
||||
let (dims, cons): (Vec<_>, Vec<_>) = after.constraints.iter().filter(|c| new(&c.id.as_str())).partition(|c| c.kind.is_dimension());
|
||||
let ids = |v: Vec<&solvecraft_sketch::Constraint>| v.into_iter().map(|c| c.id.clone()).collect::<Vec<_>>();
|
||||
let ids = |v: Vec<&solidcraft_sketch::Constraint>| v.into_iter().map(|c| c.id.clone()).collect::<Vec<_>>();
|
||||
let mut out = json!({"points": points, "curves": curves, "constraints": ids(cons), "dimensions": ids(dims)});
|
||||
let wires: Vec<&str> = after.wires.iter().map(|x| x.id.as_str()).filter(new).collect();
|
||||
if !wires.is_empty()
|
||||
@@ -515,7 +515,7 @@ pub(super) fn result(sk_out: (Vec<String>, Vec<String>), info: Value) -> Value {
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Sketch lifecycle
|
||||
|
||||
pub(crate) fn author_path_for_rebind(s: &Session, feature: &solvecraft_doc::Feature, p: &Value, cmd: &str) -> Result<Vec<u64>> {
|
||||
pub(crate) fn author_path_for_rebind(s: &Session, feature: &solidcraft_doc::Feature, p: &Value, cmd: &str) -> Result<Vec<u64>> {
|
||||
let mut saved = None;
|
||||
if let FeatureKind::Sketch { plane, .. } = &feature.kind {
|
||||
let mut plane = plane;
|
||||
@@ -553,7 +553,7 @@ pub(crate) fn author_path_for_rebind(s: &Session, feature: &solvecraft_doc::Feat
|
||||
if feature.component != 0 && path.is_empty() {
|
||||
return Err(bad(cmd, "a component sketch needs an explicit complete author_path"));
|
||||
}
|
||||
solvecraft_doc::EmbossFace::component_frame(&s.placed_document(), feature.component, &path)?;
|
||||
solidcraft_doc::EmbossFace::component_frame(&s.placed_document(), feature.component, &path)?;
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
@@ -581,7 +581,7 @@ pub(super) fn plane_ref(s: &Session, p: &Value, cmd: &str) -> Result<PlaneRef> {
|
||||
}
|
||||
|
||||
/// Does triangle set of face `fi` contain point `p` (within `tol` of the face plane)?
|
||||
pub(super) fn face_contains(m: &solvecraft_geom::Mesh, fi: usize, p: Vec3, tol: f64) -> bool {
|
||||
pub(super) fn face_contains(m: &solidcraft_geom::Mesh, fi: usize, p: Vec3, tol: f64) -> bool {
|
||||
m.triangles.iter().zip(&m.tri_face).filter(|(_, f)| **f as usize == fi).any(|(t, _)| {
|
||||
let Some([a, b, c]) = m.tri(t) else { return false };
|
||||
let n = (b - a).cross(c - a);
|
||||
@@ -672,7 +672,7 @@ fn edit_sketch(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
_ => None,
|
||||
};
|
||||
if let Some(path) = authored_path {
|
||||
solvecraft_doc::EmbossFace::component_frame(&s.placed_document(), component, &path)
|
||||
solidcraft_doc::EmbossFace::component_frame(&s.placed_document(), component, &path)
|
||||
.map_err(|error| bad("sketch.edit", format!("{error}; explicitly rebind the author placement before editing")))?;
|
||||
s.active_component = component;
|
||||
s.active_occurrence_path = (!path.is_empty()).then_some(path);
|
||||
@@ -1282,7 +1282,7 @@ pub(super) fn apply_in_order(sk: &mut Sketch, rep: &SolveReport, first: &[Ent],
|
||||
const TEMP: &str = "__keep_size";
|
||||
for (h, extra) in tries {
|
||||
let mut trial = sk.clone();
|
||||
trial.constraints.extend(extra.into_iter().map(|kind| solvecraft_sketch::Constraint {
|
||||
trial.constraints.extend(extra.into_iter().map(|kind| solidcraft_sketch::Constraint {
|
||||
id: TEMP.into(),
|
||||
kind,
|
||||
param: None,
|
||||
@@ -1764,7 +1764,7 @@ fn measured(is_angle: bool, v: f64) -> (f64, &'static str) {
|
||||
fn solved_measure(s: &Session, p: &Value, cmd: &str) -> Option<(f64, &'static str)> {
|
||||
let sk = s.doc.sketch(target_sketch(s, p, cmd).ok()?).ok()?;
|
||||
let k = &sk.constraints.last()?.kind;
|
||||
Some(measured(k.is_angle(), solvecraft_sketch::measure_dimension(sk, k)?))
|
||||
Some(measured(k.is_angle(), solidcraft_sketch::measure_dimension(sk, k)?))
|
||||
}
|
||||
|
||||
/// The type of a dimension between `a` and `b` (two points or a line's ends). `auto` takes it
|
||||
@@ -1793,8 +1793,8 @@ fn auto_orientation(ty: &str, a: Vec2, b: Vec2, text_at: Option<Vec2>) -> &str {
|
||||
/// dimension so it follows the geometry.
|
||||
fn place_text(sk: &mut Sketch, id: &str, at: Option<Vec2>) {
|
||||
let Some(i) = sk.constraints.iter().position(|c| c.id == id) else { return };
|
||||
let text = match (at, sk.constraints.get(i).and_then(|c| solvecraft_sketch::dim_frame(sk, &c.kind))) {
|
||||
(Some(at), Some(f)) => Some(solvecraft_sketch::encode_text(&f, at)),
|
||||
let text = match (at, sk.constraints.get(i).and_then(|c| solidcraft_sketch::dim_frame(sk, &c.kind))) {
|
||||
(Some(at), Some(f)) => Some(solidcraft_sketch::encode_text(&f, at)),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(c) = sk.constraints.get_mut(i) {
|
||||
@@ -1827,7 +1827,7 @@ fn diameter_about(sk: &Sketch, l: usize, ty: &str) -> bool {
|
||||
|
||||
fn arc_len(sk: &Sketch, c: usize) -> Option<f64> {
|
||||
match sk.segs(c).first()? {
|
||||
solvecraft_geom::Seg2::Arc { radius, sweep, .. } if matches!(sk.curves.get(c)?.kind, CurveKind::Arc { .. }) => Some(radius * sweep),
|
||||
solidcraft_geom::Seg2::Arc { radius, sweep, .. } if matches!(sk.curves.get(c)?.kind, CurveKind::Arc { .. }) => Some(radius * sweep),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -1948,7 +1948,7 @@ fn sketch_delete(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
&& topology
|
||||
.roles
|
||||
.iter()
|
||||
.any(|role| !role.retired && role.kind == solvecraft_sketch::OffsetRoleKind::Arc && !removed.contains(role.output.as_str()))
|
||||
.any(|role| !role.retired && role.kind == solidcraft_sketch::OffsetRoleKind::Arc && !removed.contains(role.output.as_str()))
|
||||
{
|
||||
return Err(bad(cmd, "break the offset association before deleting only part of its curved boundary"));
|
||||
}
|
||||
@@ -2011,7 +2011,7 @@ fn drag_frame(s: &mut Session, p: &Value, live: bool) -> Result<(Value, Option<c
|
||||
let sk = s.doc.sketch(id)?;
|
||||
let moves: Vec<Vec2> = d.moving.iter().filter_map(|&(q, was)| Some(sk.point(q)? - was)).collect();
|
||||
let at = from + moves.iter().fold(Vec2::ZERO, |a, m| a + *m) * (1.0 / moves.len().max(1) as f64);
|
||||
let rep = rep.or_else(|| last.map(|last| SolveReport { status: solvecraft_sketch::SolveStatus::Solved, failing: Vec::new(), ..last }));
|
||||
let rep = rep.or_else(|| last.map(|last| SolveReport { status: solidcraft_sketch::SolveStatus::Solved, failing: Vec::new(), ..last }));
|
||||
let out = json!({"sketch": rep.as_ref().map(report_json), "reached": d.reached, "at": [at.x, at.y]});
|
||||
Ok((out, rep.filter(|_| live).map(|report| crate::LiveEdit { sketch: id, report })))
|
||||
}
|
||||
@@ -2048,7 +2048,7 @@ fn drag_end(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
|
||||
/// The Sketch Palette options of a sketch, by their palette names (true = shown / on).
|
||||
fn options_json(v: &solvecraft_sketch::SketchView) -> Value {
|
||||
fn options_json(v: &solidcraft_sketch::SketchView) -> Value {
|
||||
json!({
|
||||
"show_profile": !v.hide_profile,
|
||||
"show_points": !v.hide_points,
|
||||
|
||||
Reference in new issue
Block a user