Assembly: ground the first part; drag free joint chains (#2804) (#2805)

* assembly(feat): ground first parts and drag free joint chains

Ground the first top-level part when it is created and let face dragging reposition free occurrences or any member of a floating joint chain in one undo step. Preserve exact repeated-placement frames, joint values, modifier selection and Escape cancellation. Keep the accumulated fixture, viewport layout and documentation integration fixes from the existing PR.

Signed-off-by: Karl Von Richter<karl@embeint.com>

* assembly(fix): update movable fixtures for first-part grounding

Accept the documented grounded override in component creation, explicitly free movement fixtures, and keep linked clipboard pastes movable even in an empty document. Cover first and reused linked pastes, default insertion grounding, and single-step undo in the existing link tests.

Signed-off-by: Karl Von Richter<karl@embeint.com>

* assembly(test): keep the motion-cost crank free

Unground the first component in the document-level joint-face measurement fixture so its motion samples can rotate after first-part grounding. Preserve the rotation and shared-measurement assertions that caught the Linux CI failure.

Signed-off-by: Karl Von Richter<karl@embeint.com>

* assembly(test): free the frame placement fixture

Create the frame-member placement fixture ungrounded before moving it above its root sketch. Keep its world-space member assertions while respecting first-part grounding in the frame tests added on main.

Signed-off-by: Karl Von Richter<karl@embeint.com>

---------

Signed-off-by: Karl Von Richter<karl@embeint.com>
This commit is contained in:
Karl Von Richter authored and GitHub committed 2026-10-23 23:15:34 +00:00
1 parent 30b01e8d79
commit 0dffb206b1
75 files changed
+1094 -115

No files matched your search

+4
View File
@@ -587,6 +587,10 @@ completed drawings publish atomically. The browser still exports synchronously.
continuous collision detection; local thin walls and small details remain limitations.
See [contact-set limits and recovery](docs/contact-sets.md).
## Assembly dragging
The design's first part is grounded when it is made, and a left-button drag repositions a free part (`occurrence.drag`: one undo step, exact occurrence paths including repeated jointed definitions, any floating-chain member carries the chain, grounded parts and joints hold where present, Escape cancels).
## 3D sketch bridges
3D sketch drawing snaps to points on other visible sketch planes without flattening them onto
+2 -1
View File
@@ -36,8 +36,9 @@ impl Script {
);
}
/// A part placed after it is built: free, even as the design's first part (#2804).
fn component(&mut self, name: &str) {
self.c("component.create", json!({"name": name}));
self.c("component.create", json!({"name": name, "grounded": false}));
}
fn root(&mut self) {
+1 -1
View File
@@ -1412,7 +1412,7 @@ fn a_sketch_on_a_patterned_boss_top() {
fn construction_geometry_and_holes_on_a_moved_component() {
let moved = || {
vec![
json!({"command": "component.create", "params": {"name": "Arm"}}),
json!({"command": "component.create", "params": {"name": "Arm", "grounded": false}}),
json!({"command": "solid.box", "params": {"corner": [20, 0, 0], "length": 10, "width": 4, "height": 4, "body_name": "ArmBody"}}),
json!({"command": "component.activate", "params": {"component": 0}}),
json!({"command": "occurrence.move", "params": {"occurrence": "Arm:1", "translate": [0, 50, 0]}}),
@@ -1,6 +1,6 @@
{"commands": [
{"command": "solid.box", "params": {"length": 10, "width": 10, "height": 10, "body_name": "Base"}},
{"command": "component.create", "params": {"name": "Arm"}},
{"command": "component.create", "params": {"name": "Arm", "grounded": false}},
{"command": "solid.box", "params": {"corner": [20, 0, 0], "length": 10, "width": 4, "height": 4, "body_name": "ArmBody"}},
{"command": "solid.fillet", "params": {"edges": [[25, 4, 4]], "radius": 1}},
{"command": "component.activate", "params": {"component": 0}},
+1
View File
@@ -779,6 +779,7 @@
"cmd.motion_trace_edit": "Edit Motion Trace",
"cmd.motion_trace_keep": "Keep Motion Trace",
"cmd.occurrence_copy": "Paste (Instance)",
"cmd.occurrence_drag": "Drag Occurrence",
"cmd.occurrence_ground": "Ground",
"cmd.occurrence_move": "Move Occurrence",
"cmd.occurrence_properties": "Occurrence Physical Properties",
+1
View File
@@ -779,6 +779,7 @@
"cmd.motion_trace_edit": "モーション トレースを編集",
"cmd.motion_trace_keep": "モーション トレースを保持",
"cmd.occurrence_copy": "貼り付け(インスタンス)",
"cmd.occurrence_drag": "オカレンスをドラッグ",
"cmd.occurrence_ground": "空間固定",
"cmd.occurrence_move": "オカレンスを移動",
"cmd.occurrence_properties": "オカレンスの物理的プロパティ",
+1
View File
@@ -779,6 +779,7 @@
"cmd.motion_trace_edit": "编辑运动轨迹",
"cmd.motion_trace_keep": "保留运动轨迹",
"cmd.occurrence_copy": "粘贴(实例)",
"cmd.occurrence_drag": "拖动实例",
"cmd.occurrence_ground": "固定",
"cmd.occurrence_move": "移动实例",
"cmd.occurrence_properties": "实例物理属性",
+10 -1
View File
@@ -3018,7 +3018,16 @@ impl Document {
}
};
self.components.push(Component { id, name, parent, ..Default::default() });
self.add_occurrence(id, parent, crate::IDENTITY)?;
let occurrence = self.add_occurrence(id, parent, crate::IDENTITY)?;
// The design's first part is grounded, so joints and drags have something fixed to work
// from (#2804); later parts and copies start free. Only creation decides this: opening a
// design never grounds anything.
if parent == 0
&& !self.occurrences.iter().any(|o| o.parent == 0 && o.id != occurrence)
&& let Some(o) = self.occurrences.iter_mut().find(|o| o.id == occurrence)
{
o.grounded = true;
}
Ok(id)
}
+3 -1
View File
@@ -45,7 +45,9 @@ fn joint_face_measurements_are_shared_across_motion_samples_and_snap_kinds() {
use crate::joints::{Joint, JointKind, JointOrigin, Snap, XRef};
let mut doc = Document::new("joint face work");
let part = doc.add_component(Some("Crank"), 0).unwrap();
let occurrence = doc.occurrences.iter().find(|o| o.component == part).unwrap().id;
let occurrence = doc.occurrences.iter_mut().find(|o| o.component == part).unwrap();
occurrence.grounded = false;
let occurrence = occurrence.id;
let id = doc
.add_feature(
FeatureKind::Cylinder {
+27 -8
View File
@@ -11,6 +11,8 @@ use super::CommandSpec;
use crate::params::{bad, bool_, str_, string_list, vec3};
use crate::{Result, Session};
#[path = "component_drag.rs"]
mod drag;
#[path = "component_matrix.rs"]
pub(super) mod matrix;
#[path = "component_properties.rs"]
@@ -27,7 +29,7 @@ pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("component.create", "New Component", new_component)
.at("SOLID", "ASSEMBLE")
.icon("component")
.params("name?, parent?: component id or name (default: the active one); parent_path?: exact parent placement; activate?: bool (default true)"),
.params("name?, parent?: component id or name (default: the active one); parent_path?: exact parent placement; activate?: bool (default true); grounded?: bool (default: true for the design's first part, false otherwise)"),
CommandSpec::new("component.from_bodies", "Create Components from Bodies", from_bodies)
.icon("component")
.params("bodies: [names] → one new component per body, named after it"),
@@ -54,7 +56,12 @@ pub static COMMANDS: &[CommandSpec] = &[
.params("component (or occurrence): what to place again; path?: validates selected occurrence; parent?: component (default: the same parent); translate?: [x,y,z]. Copies the selected effective transform, including pending moves"),
CommandSpec::new("component.paste_new", "Paste New", paste_new).icon("paste").params("component: independently copy its nested definition graph and history, materials and styles; occurrence?, path?: selected source placement; translate?: [x,y,z]. Reassigned external bodies become base geometry; retained external links and omitted boundary joints are reported"),
CommandSpec::new("occurrence.move", "Move Occurrence", move_occurrence).icon("move")
.params("occurrence; path?: exact placement; space?: local|world (default local); translate?: [x,y,z]; axis?: [x,y,z], angle?: radians or \"30 deg\", origin?: [x,y,z]; matrix?: [12 or 16 numbers] (instead of translate/axis/angle/origin: a rigid move as a row-major 3x4 rotation-and-translation or 4x4 matrix, flat or as rows; one that is a rotation only up to rounding is orthonormalised, a scale, shear or mirror is refused); tolerance?: largest accepted |RᵀR − I| (default 1e-9, at most 1e-3); capture?: bool (default true; false keeps it pending until Capture Position). Nested occurrence definitions remain shared"),
.params("occurrence; path?: exact placement; space?: local|world (default local); translate?: [x,y,z]; axis?: [x,y,z], angle?: radians or \"30 deg\", origin?: [x,y,z]; matrix?: [12 or 16 numbers] (instead of translate/axis/angle/origin: a rigid move as a row-major 3x4 rotation-and-translation or 4x4 matrix, flat or as rows; one that is a rotation only up to rounding is orthonormalised, a scale, shear or mirror is refused); tolerance?: largest accepted |RᵀR − I| (default 1e-9, at most 1e-3); capture?: bool (default true; false keeps it pending until Capture Position); move_grounded?: bool (default false: a grounded occurrence refuses; true moves it and it stays grounded). Nested occurrence definitions remain shared"),
CommandSpec::new("occurrence.drag", "Drag Occurrence", drag::drag).icon("move").params(
"occurrence or path: exact placement; at: [x,y,z] world point on it; point: [x,y,z] where it goes. Moves the placement by \
point - at (with any chain of joints it is in that is joined to nothing grounded) and captures its position; other pending \
moves stay pending. Shared definitions move in all placements. Grounded parts and parts joints hold to something fixed are refused (joint.reach moves those)",
),
CommandSpec::new("occurrence.ground", "Ground", ground).icon("ground").params("occurrence; grounded?: bool (default toggles)"),
CommandSpec::new("component.capture_position", "Capture Position", capture).at("SOLID", "POSITION").icon("capture").params("keeps pending occurrence moves"),
CommandSpec::new("component.revert_position", "Revert Position", revert).at("SOLID", "POSITION").icon("revert").noundo().params("occurrences?: [ids] (default all); drops selected pending occurrence moves"),
@@ -110,10 +117,10 @@ pub(super) fn valid_position(m: &Mat) -> bool {
pub(super) fn new_component(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "component.create";
if let Some(params) = p.as_object()
&& let Some(key) = params.keys().find(|key| !matches!(key.as_str(), "name" | "parent" | "parent_path" | "activate"))
&& let Some(key) = params.keys().find(|key| !matches!(key.as_str(), "name" | "parent" | "parent_path" | "activate" | "grounded"))
{
let hint = if params.contains_key("bodies") { "; use component.move_bodies or component.from_bodies to move bodies" } else { "" };
return Err(bad(cmd, format!("unknown parameter `{key}`; accepted parameters: name, parent, parent_path, activate{hint}")));
return Err(bad(cmd, format!("unknown parameter `{key}`; accepted parameters: name, parent, parent_path, activate, grounded{hint}")));
}
let parent = if p.get("parent").is_some() { component(s, p, "parent", cmd)? } else { s.active_component };
let parent_path = if let Some(value) = p.get("parent_path") {
@@ -135,7 +142,16 @@ pub(super) fn new_component(s: &mut Session, p: &Value) -> Result<Value> {
if parent_path.len() >= 64 {
return Err(bad(cmd, "new component exceeds occurrence depth limit"));
}
let grounded = match p.get("grounded") {
None => None,
Some(v) => Some(v.as_bool().ok_or_else(|| bad(cmd, "grounded must be true or false"))?),
};
let id = s.doc_mut().add_component(str_(p, "name"), parent)?;
if let Some(grounded) = grounded
&& let Some(o) = s.doc_mut().occurrences.iter_mut().find(|o| o.component == id)
{
o.grounded = grounded;
}
if p.get("activate").and_then(Value::as_bool).unwrap_or(true) {
let mut path = parent_path;
if let Some(o) = s.doc.occurrence_of(id) {
@@ -145,8 +161,8 @@ pub(super) fn new_component(s: &mut Session, p: &Value) -> Result<Value> {
s.active_occurrence_path = Some(path);
}
let name = s.doc.components.iter().find(|c| c.id == id).map(|c| c.name.clone()).unwrap_or_default();
let occ = s.doc.occurrence_of(id).map(|o| o.id);
Ok(json!({"component": id, "name": name, "parent": parent, "occurrence": occ}))
let occ = s.doc.occurrence_of(id);
Ok(json!({"component": id, "name": name, "parent": parent, "occurrence": occ.map(|o| o.id), "grounded": occ.is_some_and(|o| o.grounded)}))
}
fn from_bodies(s: &mut Session, p: &Value) -> Result<Value> {
@@ -394,8 +410,11 @@ fn move_occurrence(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "occurrence.move";
let id = occurrence(s, p, cmd)?;
let o = s.doc.occurrences.iter().find(|o| o.id == id).cloned().ok_or_else(|| bad(cmd, "occurrence"))?;
if o.grounded {
return Err(bad(cmd, format!("{} is grounded", o.name)));
if o.grounded && bool_(p, "move_grounded") != Some(true) {
return Err(bad(
cmd,
format!("{} is grounded: unground it first (occurrence.ground; a design's first part is grounded when it is made)", o.name),
));
}
if let Some(mut group) = s.held_by_rigid_group(id) {
// The outermost component the group holds it in moves it.
+2 -1
View File
@@ -275,7 +275,8 @@ pub(super) fn paste(
clone_path.push(root_occurrence);
if let Some(o) = scratch.doc_mut().occurrences.iter_mut().find(|o| o.id == root_occurrence) {
o.transform = transform;
o.grounded = source_occurrence.as_ref().is_some_and(|o| o.grounded);
// A copy starts free, even of a grounded part (#2804); the parts inside it keep theirs.
o.grounded = false;
}
if let Some(o) = &source_occurrence {
occurrences.insert(o.id, root_occurrence);
@@ -5,7 +5,7 @@ fn run(s: &mut Session, cmd: &str, p: Value) -> Value {
s.execute(cmd, &p).unwrap()
}
fn component(s: &mut Session, name: &str) -> u64 {
run(s, "component.create", json!({"name":name}))["component"].as_u64().unwrap()
run(s, "component.create", json!({"name":name,"grounded":false}))["component"].as_u64().unwrap()
}
fn volume(s: &mut Session, id: u64) -> f64 {
run(s, "component.properties", json!({"component":id}))["total"]["volume_mm3"].as_f64().unwrap()
+162
View File
@@ -0,0 +1,162 @@
//! Dragging a part to put it somewhere (#2804): what the viewport's left-button drag on a free
//! part runs each frame, and what scripts and agents use to move a placement by a grabbed point.
//! A grounded part stays where it is, and so does one that joints hold to something fixed
//! (`joint.reach` moves those as far as their joints allow). A chain of joints joined to nothing
//! fixed moves as one, so its joints stay as they are.
use serde_json::{Value, json};
use solidcraft_doc::{mat_inverse, mat_mul};
use super::{move_vector, occurrence, occurrence_path, translation, valid_position};
use crate::params::bad;
use crate::{EngineError, Result, Session};
#[cfg(test)]
#[path = "component_drag_tests.rs"]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests;
/// Most placements one drag moves (the dragged one and the chain of joints it is in).
const MAX_MOVED: usize = 1000;
fn refused(message: String) -> EngineError {
EngineError::Other(message)
}
impl Session {
/// The placements a drag on the placement `path` moves, each by its exact path: that
/// placement first, then those a chain of joints joined to nothing fixed carries along with
/// it. An error says why it can't be dragged (grounded, held by joints to something fixed,
/// or held in a rigid group). Shared definitions move in all of their placements.
pub fn drag_group(&self, path: &[u64]) -> Result<Vec<Vec<u64>>> {
let placement = self.occurrence_placement(path)?;
let doc = &self.doc;
let name = |id: u64| doc.occurrences.iter().find(|o| o.id == id).map_or_else(|| id.to_string(), |o| o.name.clone());
let dragged = placement.occurrence;
if placement.grounded {
return Err(refused(format!("{} is grounded", placement.name)));
}
if let Some(group) = self.held_by_rigid_group(dragged) {
let group = doc.components.iter().find(|c| c.id == group).map(|c| c.name.clone()).unwrap_or_default();
return Err(refused(format!("{} is held in {group} by a rigid group: drag {group}, or Unlock Contents first", placement.name)));
}
// Is `o` the placement `top` or inside its component (in every placement of it)?
let within = |o: u64, top: u64| -> bool {
if o == top {
return true;
}
let (Some(o), Some(top)) = (doc.occurrences.iter().find(|x| x.id == o), doc.occurrences.iter().find(|x| x.id == top)) else {
return false;
};
o.parent != 0 && doc.component_within(o.parent, top.component)
};
let joints: Vec<_> = doc.assembly.joints.iter().filter(|j| !j.suppressed).collect();
let mut members = vec![dragged];
// Grow the chain one joint at a time; each pass adds a member or stops.
for _ in 0..MAX_MOVED {
let inside = |o: u64| members.iter().any(|m| within(o, *m));
let next = joints.iter().find_map(|j| match (inside(j.a.occurrence), inside(j.b.occurrence)) {
(true, false) => Some((j, j.b.occurrence)),
(false, true) => Some((j, j.a.occurrence)),
_ => None,
});
let Some((joint, other)) = next else {
break;
};
if other == 0 {
return Err(refused(format!("{} holds {} to the design's origin", joint.name, placement.name)));
}
// Only this member's placement is edited. A grounded ancestor fixes its own
// transform, while its free contents may still move inside that frame.
if doc.occurrences.iter().any(|o| o.id == other && o.grounded) {
return Err(refused(format!(
"{} holds {} to grounded {}: it moves only as far as its joints allow (joint.reach)",
joint.name,
placement.name,
name(other)
)));
}
if path.contains(&other) || within(dragged, other) {
return Err(refused(format!("{} holds {} to the assembly it is in: drag {}", joint.name, placement.name, name(other))));
}
members.push(other);
if members.len() > MAX_MOVED {
return Err(refused(format!("the chain of joints {} is in moves more than {MAX_MOVED} parts", placement.name)));
}
}
// A member inside another one moves with it (moving both would move it twice).
let tops: Vec<u64> = members.iter().copied().filter(|m| !members.iter().any(|o| o != m && within(*m, *o))).collect();
let mut out = vec![path.to_vec()];
for m in tops.into_iter().filter(|m| *m != dragged) {
let parent = doc.occurrences.iter().find(|o| o.id == m).map_or(0, |o| o.parent);
let mut chain = doc.first_path(parent);
chain.push(m);
out.push(chain);
}
Ok(out)
}
}
/// `occurrence.drag`: move a placement by `point - at` in world coordinates (and the free chain
/// of joints it is in), capturing its position.
pub(super) fn drag(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "occurrence.drag";
let path = if p.get("occurrence").is_some() {
let id = occurrence(s, p, cmd)?;
occurrence_path(s, p, id, cmd)?
} else {
let path = p
.get("path")
.and_then(Value::as_array)
.filter(|a| !a.is_empty() && a.len() <= 64)
.and_then(|a| a.iter().map(Value::as_u64).collect::<Option<Vec<_>>>())
.ok_or_else(|| bad(cmd, "give `occurrence` or `path` (1..64 occurrence ids)"))?;
s.occurrence_placement(&path).map_err(|e| bad(cmd, e.to_string()))?;
path
};
if p.get("at").is_none() || p.get("point").is_none() {
return Err(bad(cmd, "`at` and `point` must both be given"));
}
let at = move_vector(p, "at", Default::default(), true, cmd)?;
let point = move_vector(p, "point", Default::default(), true, cmd)?;
let t = point - at;
let world_move = translation(t);
let group = s.drag_group(&path).map_err(|e| bad(cmd, e.to_string()))?;
let dragged = s.occurrence_placement(&path).map_err(|e| bad(cmd, e.to_string()))?;
let inverse = mat_inverse(&dragged.parent_world).ok_or_else(|| bad(cmd, "parent frame is singular"))?;
let local_delta = mat_mul(&mat_mul(&inverse, &world_move), &dragged.parent_world);
// Joints refer to shared occurrence definitions, and the solver places them through their
// first path. Carry the selected placement's local change into that same frame before
// moving its peers. Using the pointer's world delta directly would break the joint when
// the selected instance has a different rotation from the first one.
let parent = s.doc.occurrences.iter().find(|o| o.id == dragged.occurrence).map_or(0, |o| o.parent);
let mut first_path = s.doc.first_path(parent);
first_path.push(dragged.occurrence);
let first = s.occurrence_placement(&first_path).map_err(|e| bad(cmd, e.to_string()))?;
let first_inverse = mat_inverse(&first.parent_world).ok_or_else(|| bad(cmd, "parent frame is singular"))?;
let world_delta = mat_mul(&mat_mul(&first.parent_world, &local_delta), &first_inverse);
// Every new position first, from the placements as they are, then all of them at once.
let mut moves = Vec::with_capacity(group.len());
for placement_path in &group {
let placement = s.occurrence_placement(placement_path).map_err(|e| bad(cmd, e.to_string()))?;
let inverse = mat_inverse(&placement.parent_world).ok_or_else(|| bad(cmd, "parent frame is singular"))?;
let delta =
if placement.occurrence == dragged.occurrence { local_delta } else { mat_mul(&mat_mul(&inverse, &world_delta), &placement.parent_world) };
let next = mat_mul(&delta, &placement.local);
if !valid_position(&next) {
return Err(bad(cmd, "drag exceeds supported numeric range"));
}
moves.push((placement.occurrence, next));
}
let moved: Vec<u64> = moves.iter().map(|(id, _)| *id).collect();
if world_move != solidcraft_doc::IDENTITY {
for (id, next) in moves {
s.pending_moves.remove(&id);
if let Some(o) = s.doc_mut().occurrences.iter_mut().find(|o| o.id == id) {
o.transform = next;
}
}
}
let continuous = p.get("continuous").and_then(Value::as_bool).unwrap_or(false);
Ok(json!({"occurrence": path.last(), "path": path, "moved": moved, "translate": [t.x, t.y, t.z], "continuous": continuous}))
}
@@ -0,0 +1,289 @@
//! The design's first part is grounded; dragging a free part moves it (#2804).
use serde_json::{Value, json};
use crate::Session;
fn run(s: &mut Session, command: &str, p: Value) -> Value {
s.execute(command, &p).unwrap_or_else(|e| panic!("{command} {p}: {e}"))
}
/// A new top-level part holding a 10 mm cube at `corner` (activates the design first, so the
/// part goes into it): (component, occurrence).
fn part(s: &mut Session, name: &str, corner: [f64; 3]) -> (u64, u64) {
run(s, "component.activate", json!({"component": "root"}));
let c = run(s, "component.create", json!({"name": name}));
run(s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": corner}));
run(s, "component.activate", json!({"component": "root"}));
(c["component"].as_u64().unwrap(), c["occurrence"].as_u64().unwrap())
}
fn grounded(s: &Session, occurrence: u64) -> bool {
s.doc.occurrences.iter().find(|o| o.id == occurrence).unwrap().grounded
}
/// Where the placement `path` puts its origin, in world coordinates (pending moves included).
fn origin(s: &Session, path: &[u64]) -> [f64; 3] {
let w = s.occurrence_placement(path).unwrap().world;
[w[3][0], w[3][1], w[3][2]]
}
fn near(a: [f64; 3], b: [f64; 3]) {
assert!(a.iter().zip(b).all(|(x, y)| (x - y).abs() < 1e-9), "{a:?} != {b:?}");
}
#[test]
fn the_first_top_level_part_is_grounded_and_later_parts_and_copies_are_free() {
let mut s = Session::default();
let (a, first) = part(&mut s, "A", [0.0, 0.0, 0.0]);
let created = s.doc.occurrences.iter().find(|o| o.id == first).cloned().unwrap();
assert!(created.grounded, "the first part is grounded");
let (_, second) = part(&mut s, "B", [20.0, 0.0, 0.0]);
assert!(!grounded(&s, second), "a later part starts free");
let instance = run(&mut s, "occurrence.copy", json!({"occurrence": first, "translate": [0, 20, 0]}))["occurrence"].as_u64().unwrap();
assert!(!grounded(&s, instance), "Paste (Instance) of the grounded part is free");
let copy = run(&mut s, "component.paste_new", json!({"component": a, "translate": [0, 40, 0]}));
let copy = s.doc.occurrence_of(copy["component"].as_u64().unwrap()).unwrap().id;
assert!(!grounded(&s, copy), "Paste New of the grounded part is free");
// A part made inside another one is placed in it, not in the design: free.
run(&mut s, "component.activate", json!({"component": a}));
let nested = run(&mut s, "component.create", json!({"name": "Inner"}))["occurrence"].as_u64().unwrap();
assert!(!grounded(&s, nested));
// Several parts may be grounded, or none.
run(&mut s, "occurrence.ground", json!({"occurrence": second, "grounded": true}));
assert!(grounded(&s, first) && grounded(&s, second));
for o in [first, second] {
run(&mut s, "occurrence.ground", json!({"occurrence": o, "grounded": false}));
}
assert!(!s.doc.occurrences.iter().any(|o| o.grounded));
}
#[test]
fn components_from_bodies_ground_only_the_first_part() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "body_name": "One"}));
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [20, 0, 0], "body_name": "Two", "operation": "new"}));
let made = run(&mut s, "component.from_bodies", json!({"bodies": ["One", "Two"]}));
let occurrence = |i: usize| s.doc.occurrence_of(made["components"][i]["component"].as_u64().unwrap()).unwrap().id;
let (one, two) = (occurrence(0), occurrence(1));
assert!(grounded(&s, one) && !grounded(&s, two));
}
#[test]
fn ungrounded_designs_stay_ungrounded_through_new_parts_and_reopening() {
let mut s = Session::default();
let (_, first) = part(&mut s, "A", [0.0, 0.0, 0.0]);
run(&mut s, "occurrence.ground", json!({"occurrence": first, "grounded": false}));
let (_, second) = part(&mut s, "B", [20.0, 0.0, 0.0]);
assert!(!grounded(&s, first) && !grounded(&s, second), "a part added later grounds nothing");
let back = solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap();
assert!(!back.occurrences.iter().any(|o| o.grounded), "opening a design grounds nothing");
// With every part gone, the next one is the design's first part again.
for c in ["A", "B"] {
run(&mut s, "component.delete", json!({"component": c}));
}
let (_, again) = part(&mut s, "C", [0.0, 0.0, 0.0]);
assert!(grounded(&s, again));
}
#[test]
fn dragging_moves_a_free_part_by_the_grabbed_point_in_one_undo_step() {
let mut s = Session::default();
let (_, base) = part(&mut s, "Base", [0.0, 0.0, 0.0]);
let (_, free) = part(&mut s, "Free", [20.0, 0.0, 0.0]);
let undo = s.undo.len();
let r = run(&mut s, "occurrence.drag", json!({"occurrence": free, "at": [25, 5, 10], "point": [35, 10, 10]}));
assert_eq!(r["moved"], json!([free]));
near(origin(&s, &[free]), [10.0, 5.0, 0.0]);
assert_eq!(s.undo.len(), undo + 1);
assert_eq!(s.undo.last().map(|u| u.label.as_str()), Some("Drag Occurrence"));
// Saved and opened again, it is where it was dragged.
let back = solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap();
let t = back.occurrences.iter().find(|o| o.id == free).unwrap().transform;
near([t[3][0], t[3][1], t[3][2]], [10.0, 5.0, 0.0]);
run(&mut s, "edit.undo", json!({}));
near(origin(&s, &[free]), [0.0, 0.0, 0.0]);
// A grounded part stays where it is.
let e = s.execute("occurrence.drag", &json!({"occurrence": base, "at": [0, 0, 0], "point": [5, 0, 0]})).unwrap_err().to_string();
assert!(e.contains("grounded"), "{e}");
near(origin(&s, &[base]), [0.0, 0.0, 0.0]);
}
#[test]
fn a_drag_captures_its_part_and_leaves_other_pending_moves_pending() {
let mut s = Session::default();
part(&mut s, "Base", [0.0, 0.0, 0.0]);
let (_, a) = part(&mut s, "A", [20.0, 0.0, 0.0]);
let (_, b) = part(&mut s, "B", [40.0, 0.0, 0.0]);
run(&mut s, "occurrence.move", json!({"occurrence": a, "translate": [0, 7, 0], "capture": false}));
run(&mut s, "occurrence.move", json!({"occurrence": b, "translate": [0, 9, 0], "capture": false}));
run(&mut s, "occurrence.drag", json!({"occurrence": a, "at": [0, 0, 0], "point": [3, 0, 0]}));
assert!(!s.pending_moves.contains_key(&a), "the dragged part's position is captured");
let t = s.doc.occurrences.iter().find(|o| o.id == a).unwrap().transform;
near([t[3][0], t[3][1], t[3][2]], [3.0, 7.0, 0.0]);
assert!(s.pending_moves.contains_key(&b), "another part's move stays pending");
near(origin(&s, &[b]), [0.0, 9.0, 0.0]);
run(&mut s, "edit.undo", json!({}));
near(origin(&s, &[a]), [0.0, 7.0, 0.0]);
assert!(s.pending_moves.contains_key(&a), "undo gives the pending move back");
}
#[test]
fn dragging_uses_the_exact_path_of_a_repeated_placement() {
let mut s = Session::default();
part(&mut s, "Base", [0.0, 0.0, 0.0]);
let (asm, first) = part(&mut s, "Asm", [0.0, 0.0, 0.0]);
run(&mut s, "occurrence.move", json!({"occurrence": first, "axis": [0, 0, 1], "angle": "90 deg"}));
run(&mut s, "component.activate", json!({"component": asm}));
let leaf = run(&mut s, "component.create", json!({"name": "Leaf"}))["occurrence"].as_u64().unwrap();
run(&mut s, "solid.box", json!({"length": 2, "width": 2, "height": 2}));
run(&mut s, "component.activate", json!({"component": "root"}));
let second = run(&mut s, "occurrence.copy", json!({"occurrence": first, "translate": [100, 0, 0]}))["occurrence"].as_u64().unwrap();
// The second instance of the assembly moves alone.
run(&mut s, "occurrence.drag", json!({"path": [second], "at": [100, 0, 0], "point": [100, 30, 0]}));
near(origin(&s, &[second]), [100.0, 30.0, 0.0]);
near(origin(&s, &[first]), [0.0, 0.0, 0.0]);
// Its leaf, a definition shared by both instances, moves in world X through that path's
// rotated frame, and so in both.
let before = origin(&s, &[first, leaf]);
run(&mut s, "occurrence.drag", json!({"path": [second, leaf], "at": [100, 30, 0], "point": [110, 30, 0]}));
near(origin(&s, &[second, leaf]), [110.0, 30.0, 0.0]);
near(origin(&s, &[first, leaf]), [before[0] + 10.0, before[1], before[2]]);
// The leaf alone, without the path of the instance it is in, is ambiguous.
let e = s.execute("occurrence.drag", &json!({"occurrence": leaf, "at": [0, 0, 0], "point": [1, 0, 0]})).unwrap_err().to_string();
assert!(e.contains("path"), "{e}");
}
#[test]
fn joints_hold_a_part_to_something_grounded_and_carry_a_free_chain_along() {
let mut s = Session::default();
let (_, base) = part(&mut s, "Base", [0.0, 0.0, 0.0]);
let (_, arm) = part(&mut s, "Arm", [0.0, 0.0, 10.0]);
let at = |o: u64, z: f64| json!({"occurrence": o, "point": [0, 0, z], "z": [0, 0, 1]});
run(&mut s, "joint.create", json!({"type": "revolute", "a": at(base, 10.0), "b": at(arm, 10.0), "flip": true, "name": "Hinge"}));
let e = s.execute("occurrence.drag", &json!({"occurrence": arm, "at": [0, 0, 0], "point": [5, 0, 0]})).unwrap_err().to_string();
assert!(e.contains("grounded") && e.contains("Hinge"), "{e}");
// Two parts jointed to each other and to nothing grounded move together.
let (_, x) = part(&mut s, "X", [50.0, 0.0, 0.0]);
let (_, y) = part(&mut s, "Y", [50.0, 0.0, 10.0]);
run(&mut s, "joint.create", json!({"type": "rigid", "a": at(x, 10.0), "b": at(y, 10.0), "flip": true, "name": "Weld"}));
let (x0, y0) = (origin(&s, &[x]), origin(&s, &[y]));
let r = run(&mut s, "occurrence.drag", json!({"occurrence": y, "at": [0, 0, 0], "point": [0, 25, 0]}));
assert_eq!(r["moved"].as_array().map(Vec::len), Some(2), "{r}");
near(origin(&s, &[x]), [x0[0], x0[1] + 25.0, x0[2]]);
near(origin(&s, &[y]), [y0[0], y0[1] + 25.0, y0[2]]);
// Suppressed, the joint holds nothing.
run(&mut s, "joint.edit", json!({"joint": "Hinge", "suppressed": true}));
run(&mut s, "occurrence.drag", json!({"occurrence": arm, "at": [0, 0, 0], "point": [5, 0, 0]}));
}
#[test]
fn a_drag_and_a_world_move_leave_the_same_design() {
// Whatever follows a moved part (projections, joints, Properties) follows a dragged one.
let build = || {
let mut s = Session::default();
part(&mut s, "Base", [0.0, 0.0, 0.0]);
let (_, free) = part(&mut s, "Free", [20.0, 0.0, 0.0]);
run(&mut s, "sketch.create", json!({"plane": "XY"}));
run(&mut s, "sketch.project", json!({"refs": [{"edge": [25, 0, 0]}]}));
run(&mut s, "sketch.finish", json!({}));
(s, free)
};
let (mut dragged, free) = build();
let (mut moved, _) = build();
run(&mut dragged, "occurrence.drag", json!({"occurrence": free, "at": [25, 0, 0], "point": [25, 15, 0]}));
run(&mut moved, "occurrence.move", json!({"occurrence": free, "space": "world", "translate": [0, 15, 0]}));
assert_eq!(dragged.doc.to_json(), moved.doc.to_json());
let shown = |s: &Session| format!("{:?}", s.world_state().sketches.iter().map(|k| &k.sketch.points).collect::<Vec<_>>());
assert_eq!(shown(&dragged), shown(&moved));
}
#[test]
fn bad_drag_parameters_are_refused() {
let mut s = Session::default();
part(&mut s, "Base", [0.0, 0.0, 0.0]);
let (_, free) = part(&mut s, "Free", [20.0, 0.0, 0.0]);
for p in [
json!({}),
json!({"occurrence": free}),
json!({"occurrence": free, "at": [0, 0, 0]}),
json!({"occurrence": free, "at": [0, 0, 0], "point": [1e300, 0, 0]}),
json!({"occurrence": free, "at": [0, 0, "x"], "point": [0, 0, 0]}),
json!({"path": [], "at": [0, 0, 0], "point": [1, 0, 0]}),
json!({"path": [free, free], "at": [0, 0, 0], "point": [1, 0, 0]}),
json!({"path": [999_999], "at": [0, 0, 0], "point": [1, 0, 0]}),
json!({"occurrence": "nothing", "at": [0, 0, 0], "point": [1, 0, 0]}),
] {
assert!(s.execute("occurrence.drag", &p).is_err(), "{p}");
}
near(origin(&s, &[free]), [0.0, 0.0, 0.0]);
}
#[test]
fn moving_a_grounded_part_needs_saying_so_and_it_stays_grounded() {
let mut s = Session::default();
let (_, base) = part(&mut s, "Base", [0.0, 0.0, 0.0]);
let e = s.execute("occurrence.move", &json!({"occurrence": base, "translate": [5, 0, 0]})).unwrap_err().to_string();
assert!(e.contains("is grounded") && e.contains("occurrence.ground"), "{e}");
run(&mut s, "occurrence.move", json!({"occurrence": base, "translate": [5, 0, 0], "move_grounded": true}));
near(origin(&s, &[base]), [5.0, 0.0, 0.0]);
assert!(grounded(&s, base));
}
/// The solver uses definitions' first paths; a drag through a rotated instance must carry
/// that local change to its jointed peers, including peers that are themselves shared.
#[test]
fn shared_joint_chains_follow_the_selected_frame_and_survive_solving() {
let mut s = Session::default();
part(&mut s, "Base", [0.0, 0.0, 0.0]);
let asm = run(&mut s, "component.create", json!({"name": "Assembly"}));
let first = asm["occurrence"].as_u64().unwrap();
let a = run(&mut s, "component.create", json!({"name": "A"}))["occurrence"].as_u64().unwrap();
run(&mut s, "solid.box", json!({"length": 4, "width": 4, "height": 4}));
run(&mut s, "component.activate", json!({"component": asm["component"]}));
let b = run(&mut s, "component.create", json!({"name": "B"}))["occurrence"].as_u64().unwrap();
run(&mut s, "solid.box", json!({"length": 4, "width": 4, "height": 4, "corner": [10, 0, 0]}));
run(&mut s, "component.activate", json!({"component": "root"}));
let at = |o| json!({"occurrence": o, "point": [0, 0, 0], "z": [0, 0, 1]});
run(&mut s, "joint.create", json!({"type": "revolute", "a": at(a), "b": at(b), "flip": true}));
let second = run(&mut s, "occurrence.copy", json!({"occurrence": first, "translate": [100, 0, 0]}))["occurrence"].as_u64().unwrap();
run(&mut s, "occurrence.move", json!({"occurrence": second, "angle": std::f64::consts::FRAC_PI_2, "origin": [100, 0, 0]}));
run(&mut s, "occurrence.ground", json!({"occurrence": first, "grounded": true}));
let undo = s.undo.len();
let before = s.doc.to_json();
let values = s.doc.assembly.joints[0].values.clone();
// Drag the non-root side, through the second assembly's rotated frame.
run(&mut s, "occurrence.drag", json!({"path": [second, b], "at": [100, 0, 0], "point": [110, 0, 0]}));
near(origin(&s, &[second, a]), [110.0, 0.0, 0.0]);
near(origin(&s, &[second, b]), [110.0, 0.0, 0.0]);
near(origin(&s, &[first, a]), [0.0, -10.0, 0.0]);
near(origin(&s, &[first, b]), [0.0, -10.0, 0.0]);
let dragged = s.doc.to_json();
let solution = run(&mut s, "joint.solve", json!({}));
assert_eq!(solution["conflicts"], json!([]));
assert_eq!(s.doc.to_json(), dragged, "solving preserves the dragged pose");
assert_eq!(s.doc.assembly.joints[0].values, values);
assert_eq!(s.undo.len(), undo + 1);
run(&mut s, "edit.undo", json!({}));
assert_eq!(s.doc.to_json(), before);
}
#[test]
fn a_unique_part_can_drag_a_chain_through_a_shared_peer() {
let mut s = Session::default();
part(&mut s, "Base", [0.0, 0.0, 0.0]);
let (_, free) = part(&mut s, "Free", [20.0, 0.0, 0.0]);
let asm = run(&mut s, "component.create", json!({"name": "Assembly"}));
let first = asm["occurrence"].as_u64().unwrap();
let peer = run(&mut s, "component.create", json!({"name": "Peer"}))["occurrence"].as_u64().unwrap();
run(&mut s, "component.activate", json!({"component": "root"}));
let second = run(&mut s, "occurrence.copy", json!({"occurrence": first, "translate": [100, 0, 0]}))["occurrence"].as_u64().unwrap();
let at = |o| json!({"occurrence": o, "point": [0, 0, 0], "z": [0, 0, 1]});
run(&mut s, "joint.create", json!({"type": "rigid", "a": at(free), "b": at(peer), "flip": true}));
run(&mut s, "occurrence.drag", json!({"occurrence": free, "at": [0, 0, 0], "point": [0, 15, 0]}));
near(origin(&s, &[free]), [0.0, 15.0, 0.0]);
near(origin(&s, &[first, peer]), [0.0, 15.0, 0.0]);
near(origin(&s, &[second, peer]), [100.0, 15.0, 0.0]);
let before = s.doc.to_json();
run(&mut s, "joint.solve", json!({}));
assert_eq!(s.doc.to_json(), before);
}
+1 -1
View File
@@ -758,7 +758,7 @@ mod tests {
let mut s = Session::default();
run(&mut s, "parameters.add", json!({"name": "plate_h", "expression": "12 mm"}));
run(&mut s, "parameters.add", json!({"name": "unused", "expression": "3 mm"}));
let plate = run(&mut s, "component.create", json!({"name": "Plate"}));
let plate = run(&mut s, "component.create", json!({"name": "Plate", "grounded": false}));
let (plate, plate_occ) = (plate["component"].as_u64().unwrap(), plate["occurrence"].as_u64().unwrap());
run(&mut s, "solid.box", json!({"length": 40, "width": 30, "height": "plate_h", "body_name": "PlateBody"}));
let pin = run(&mut s, "component.create", json!({"name": "Pin", "parent": plate}));
+5 -1
View File
@@ -27,7 +27,7 @@ pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("component.insert_design", "Insert Design", insert_design).at("SOLID", "ASSEMBLE").icon("component").params(
"path: a .solidcraft design → a new component linked to it, holding its solid bodies as placed in that design; \
name? (default: the design's name); parent?: component id or name (default: the active one); translate?: [x,y,z]; \
reuse?: bool (default false): insert another occurrence of an existing link to the same file",
reuse?: bool (default false): insert a free occurrence, reusing an existing link to the same file when available",
),
CommandSpec::new("component.update_links", "Update Links", update_links).icon("update").params(
"component?: id or name (default: every linked component) — reads the linked designs again and replaces their bodies where they changed",
@@ -181,6 +181,10 @@ fn insert_design(s: &mut Session, p: &Value) -> Result<Value> {
let (design_name, sf) = linked_bodies(&file, s.path.as_deref())?;
let name = str_(p, "name").filter(|n| !n.trim().is_empty()).map(str::to_string).unwrap_or(design_name);
let mut create = json!({"name": name, "activate": false});
// Clipboard insertion uses reuse even for the first paste, which must stay movable.
if p.get("reuse").and_then(Value::as_bool).unwrap_or(false) {
create["grounded"] = json!(false);
}
if let Some(parent) = p.get("parent") {
create["parent"] = parent.clone();
}
@@ -8,7 +8,7 @@ fn close(actual: &Value, expected: f64) {
assert!((actual.as_f64().unwrap() - expected).abs() < 1e-6, "{actual} != {expected}");
}
fn box_in(s: &mut Session, name: &str) -> (u64, u64, String) {
let c = run(s, "component.create", json!({"name": name}));
let c = run(s, "component.create", json!({"name": name, "grounded": false}));
run(s, "solid.box", json!({"length": 10, "width": 10, "height": 10}));
let body = s.model.state().bodies.last().unwrap().name.clone();
(c["component"].as_u64().unwrap(), c["occurrence"].as_u64().unwrap(), body)
@@ -81,7 +81,7 @@ fn body_reassignment_offsets_preserve_world_properties() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10}));
let body = s.model.state().bodies.first().unwrap().name.clone();
let c = run(&mut s, "component.create", json!({"name": "Moved"}));
let c = run(&mut s, "component.create", json!({"name": "Moved", "grounded": false}));
run(&mut s, "occurrence.move", json!({"occurrence": c["occurrence"], "translate": [100, 0, 0]}));
run(&mut s, "component.move_bodies", json!({"bodies": [body], "component": c["component"]}));
let r = run(&mut s, "component.properties", json!({"component": c["component"]}));
@@ -24,6 +24,28 @@ fn volume(s: &mut Session) -> f64 {
run(s, "inspect.measure", json!({}))["total"]["volume_mm3"].as_f64().unwrap()
}
#[test]
fn reused_design_insertion_is_free_even_before_a_link_exists() {
let dir = folder("reuse-grounding");
let file = dir.join("part.solidcraft");
part(&file, 30);
let mut s = Session::default();
for count in 1..=2 {
let inserted = run(&mut s, "component.insert_design", json!({"path": file, "reuse": true}));
let occurrence = inserted["occurrence"].as_u64().unwrap();
assert!(!s.doc.occurrences.iter().find(|o| o.id == occurrence).unwrap().grounded);
assert_eq!(s.doc.links.len(), 1);
assert_eq!(s.undo.len(), count, "each paste is one undo step");
run(&mut s, "occurrence.move", json!({"occurrence": occurrence, "translate": [10, 0, 0]}));
run(&mut s, "edit.undo", json!({}));
}
let mut ordinary = Session::default();
let inserted = run(&mut ordinary, "component.insert_design", json!({"path": file}));
let occurrence = inserted["occurrence"].as_u64().unwrap();
assert!(ordinary.doc.occurrences.iter().find(|o| o.id == occurrence).unwrap().grounded);
let _ = std::fs::remove_dir_all(dir);
}
#[test]
fn relink_repairs_a_moved_source_for_every_instance_in_one_undo_step() {
let dir = folder("moved");
@@ -117,6 +139,7 @@ fn relink_keeps_joint_definitions_and_reports_solver_diagnostics() {
let inserted = run(&mut s, "component.insert_design", json!({"path": original}));
let component = inserted["component"].as_u64().unwrap();
let occurrence = inserted["occurrence"].as_u64().unwrap();
run(&mut s, "occurrence.ground", json!({"occurrence": occurrence, "grounded": false}));
// Explicit points can keep solving after the source changes, even if the intended
// connection no longer exists. The source-change warning must still be present.
run(
@@ -34,7 +34,7 @@ fn recorded_assignment_preserves_sample_joined_material_and_timeline() {
fn transformed_pending_destination_repeated_transfer_preserves_world_pose() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Block"}));
let created = run(&mut s, "component.create", json!({"name":"Destination"}));
let created = run(&mut s, "component.create", json!({"name":"Destination","grounded":false}));
let to = created["component"].as_u64().unwrap();
let occurrence = created["occurrence"].as_u64().unwrap();
run(&mut s, "occurrence.move", json!({"occurrence":occurrence,"translate":[30,20,0],"angle":90,"axis":[0,0,1],"capture":false}));
@@ -141,7 +141,7 @@ fn transferred_thread_follows_body_frame_without_changing_world_axis() {
run(&mut s, "solid.cylinder", json!({"radius":4,"height":20,"body_name":"Shaft"}));
run(&mut s, "solid.thread", json!({"face":[4,0,10],"designation":"M8"}));
let before = s.world_state().threads[0].clone();
let c = run(&mut s, "component.create", json!({"name":"Threaded"}));
let c = run(&mut s, "component.create", json!({"name":"Threaded","grounded":false}));
let to = c["component"].as_u64().unwrap();
let occurrence = c["occurrence"].as_u64().unwrap();
run(&mut s, "occurrence.move", json!({"occurrence":occurrence,"translate":[30,20,10],"axis":[1,0,0],"angle":90,"capture":true}));
@@ -199,7 +199,7 @@ fn deleting_external_transfer_source_refuses_without_dangling_archive() {
#[test]
fn earlier_selected_cylinder_emboss_keeps_source_frame_after_transfer_and_edit() {
let mut s = Session::default();
let source = run(&mut s, "component.create", json!({"name":"Source"}));
let source = run(&mut s, "component.create", json!({"name":"Source","grounded":false}));
let occurrence = source["occurrence"].as_u64().unwrap();
run(&mut s, "solid.cylinder", json!({"radius":10,"height":20,"body_name":"Sleeve"}));
run(&mut s, "occurrence.move", json!({"occurrence":occurrence,"translate":[30,0,0],"capture":true}));
@@ -227,7 +227,7 @@ fn earlier_selected_cylinder_emboss_keeps_source_frame_after_transfer_and_edit()
#[test]
fn transfer_undo_redo_restores_original_pending_source_world_pose() {
let mut s = Session::default();
let created = run(&mut s, "component.create", json!({"name":"Source"}));
let created = run(&mut s, "component.create", json!({"name":"Source","grounded":false}));
let source = created["component"].as_u64().unwrap();
let occurrence = created["occurrence"].as_u64().unwrap();
run(&mut s, "solid.box", json!({"length":2,"width":2,"height":2,"body_name":"Block"}));
@@ -248,7 +248,7 @@ fn transfer_undo_redo_restores_original_pending_source_world_pose() {
#[test]
fn transfer_checkpoint_restores_pending_world_pose_and_history() {
let mut s = Session::default();
let created = run(&mut s, "component.create", json!({"name":"Source"}));
let created = run(&mut s, "component.create", json!({"name":"Source","grounded":false}));
let source = created["component"].as_u64().unwrap();
let occurrence = created["occurrence"].as_u64().unwrap();
run(&mut s, "solid.box", json!({"length":2,"width":2,"height":2,"body_name":"Block"}));
@@ -214,7 +214,7 @@ fn certified_side_transfer_preserves_geometry_and_unsupported_taper_refuses_atom
run(&mut s, "sketch.finish", json!({}));
let source = run(&mut s, "solid.extrude", json!({"distance":10,"body_name":"Round"}))["feature"].as_u64().unwrap();
paint(&mut s, "Round", json!([10, 0, 5]));
let created = run(&mut s, "component.create", json!({"name":"Placed"}));
let created = run(&mut s, "component.create", json!({"name":"Placed","grounded":false}));
let destination = created["component"].as_u64().unwrap();
let occurrence = created["occurrence"].as_u64().unwrap();
run(&mut s, "occurrence.move", json!({"occurrence":occurrence,"translate":[30,20,0],"angle":90,"axis":[0,0,1],"capture":false}));
+1 -1
View File
@@ -84,7 +84,7 @@ fn revolute_cannot_cross_a_blocker_between_clear_endpoints() {
let mut s = Session::default();
for (name, corner) in [("Arm", [20, -2, -2]), ("Blocker", [-2, 20, -2])] {
run(&mut s, "component.activate", json!({"component": 0}));
run(&mut s, "component.create", json!({"name": name}));
run(&mut s, "component.create", json!({"name": name, "grounded": false}));
run(&mut s, "solid.box", json!({"length": 4, "width": 4, "height": 4, "corner": corner}));
}
run(
+1 -1
View File
@@ -340,7 +340,7 @@ fn redefine_cannot_publish_a_second_transfer_that_breaks_existing_ownership() {
fn redefine_maps_placement_inputs_in_the_feature_owner_frame() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 4, "width": 4, "height": 4, "name": "RootBox", "body_name": "RootBody"}));
let owner = run(&mut s, "component.create", json!({"name": "Owner"}));
let owner = run(&mut s, "component.create", json!({"name": "Owner", "grounded": false}));
run(&mut s, "solid.box", json!({"length": 4, "width": 4, "height": 4, "corner": [10, 0, 0], "name": "OwnedBox", "body_name": "OwnedBody"}));
run(&mut s, "solid.fillet", json!({"edges": [[12, 0, 4]], "radius": 0.5, "body": "OwnedBody", "name": "OwnerRound"}));
run(&mut s, "occurrence.move", json!({"occurrence": owner["occurrence"], "translate": [100, 0, 0]}));
+2 -2
View File
@@ -84,7 +84,7 @@ fn internal_capture_does_not_bypass_missing_ambiguous_or_invalid_path_picks() {
fn generated_profiles_and_press_pull_convert_rotated_occurrence_picks_once() {
for hole in [false, true] {
let mut s = Session::default();
let component = run(&mut s, "component.create", json!({"name":"Arm"}));
let component = run(&mut s, "component.create", json!({"name":"Arm","grounded":false}));
let cid = component["component"].as_u64().unwrap();
let occ = component["occurrence"].as_u64().unwrap();
run(&mut s, "solid.box", json!({"length":40,"width":30,"height":20,"name":"Base","body_name":"Stock"}));
@@ -147,7 +147,7 @@ fn raised_half(s: &mut Session, body: &str) {
#[test]
fn legacy_internal_capture_refuses_an_uncaptured_source_in_another_component() {
let mut s = Session::default();
let component = run(&mut s, "component.create", json!({"name":"Source"}));
let component = run(&mut s, "component.create", json!({"name":"Source","grounded":false}));
let occurrence = component["occurrence"].as_u64().unwrap();
// A face Offset Face raised has no construction certificate or exact history name yet:
// the legacy path.
+5 -5
View File
@@ -5,7 +5,7 @@ use crate::Session;
#[test]
fn grouped_face_auto_operation_keeps_implicit_and_explicit_participants() {
let mut s = Session::default();
let part = run(&mut s, "component.create", json!({"name":"Part"}));
let part = run(&mut s, "component.create", json!({"name":"Part","grounded":false}));
run(&mut s, "solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Stock"}));
run(&mut s, "component.activate", json!({"component":0}));
for offset in [0., 30.] {
@@ -417,7 +417,7 @@ fn cylinder_cross_component_emboss_keeps_source_owner_and_placements() {
for (pick_offset, auto) in [(0., false), (80., false), (0., true), (80., true)] {
let run = |s: &mut Session, id: &str, p: Value| run(s, id, auto_emboss_params(p, auto && matches!(id, "solid.emboss" | "timeline.redefine")));
let mut s = Session::default();
let a = run(&mut s, "component.create", json!({"name":"Source"}))["component"].as_u64().unwrap();
let a = run(&mut s, "component.create", json!({"name":"Source","grounded":false}))["component"].as_u64().unwrap();
run(&mut s, "solid.cylinder", json!({"radius":10,"height":20,"body_name":"Sleeve"}));
let source_feature = s.model.state().bodies.first().unwrap().feature;
let source_names = solidcraft_doc::naming::face_names(s.model.state().body("Sleeve").unwrap());
@@ -532,7 +532,7 @@ fn check_active_second_source(auto: bool) {
fn cylinder_pending_leaf_or_ancestor_positions_require_capture_atomically() {
for (ancestor, auto) in [(false, false), (true, false), (false, true), (true, true)] {
let mut s = Session::default();
let parent = run(&mut s, "component.create", json!({"name":"Parent"}))["occurrence"].as_u64().unwrap();
let parent = run(&mut s, "component.create", json!({"name":"Parent","grounded":false}))["occurrence"].as_u64().unwrap();
let leaf = run(&mut s, "component.create", json!({"name":"Source"}))["occurrence"].as_u64().unwrap();
run(&mut s, "solid.cylinder", json!({"radius":10,"height":20,"body_name":"Sleeve"}));
run(&mut s, "sketch.create", json!({"plane":{"origin":[0,10,0],"x_dir":[-1,0,0],"y_dir":[0,0,1]},"name":"Badge"}));
@@ -561,7 +561,7 @@ fn cylinder_pending_third_component_profile_requires_capture_atomically() {
fn check_pending_third_profile(auto: bool) {
let mut s = Session::default();
run(&mut s, "solid.cylinder", json!({"radius":10,"height":20,"body_name":"Sleeve"}));
let profile_occurrence = run(&mut s, "component.create", json!({"name":"ProfileOwner"}))["occurrence"].as_u64().unwrap();
let profile_occurrence = run(&mut s, "component.create", json!({"name":"ProfileOwner","grounded":false}))["occurrence"].as_u64().unwrap();
run(&mut s, "sketch.create", json!({"plane":{"origin":[0,10,0],"x_dir":[-1,0,0],"y_dir":[0,0,1]},"name":"Badge"}));
run(&mut s, "sketch.rectangle.two_point", json!({"p0":[-2,5],"p1":[2,10]}));
run(&mut s, "sketch.finish", json!({}));
@@ -594,7 +594,7 @@ fn check_body_offset(auto: bool) {
let mut s = Session::default();
run(&mut s, "solid.cylinder", json!({"radius":10,"height":20,"body_name":"Sleeve"}));
let before = exact_cylinder_volume(&s);
let holder = run(&mut s, "component.create", json!({"name":"Holder"}))["component"].as_u64().unwrap();
let holder = run(&mut s, "component.create", json!({"name":"Holder","grounded":false}))["component"].as_u64().unwrap();
run(&mut s, "occurrence.move", json!({"occurrence":"Holder:1","translate":[0,50,0]}));
std::sync::Arc::make_mut(&mut s.doc).body_components.insert("Sleeve".into(), holder);
std::sync::Arc::make_mut(&mut s.doc)
+1 -1
View File
@@ -794,7 +794,7 @@ mod tests {
#[test]
fn preview_saves_do_not_build_cold_placements_or_persist_transient_edits() {
let mut s = Session::default();
let created = s.execute("component.create", &json!({"name":"PreviewPart"})).unwrap();
let created = s.execute("component.create", &json!({"name":"PreviewPart","grounded":false})).unwrap();
let occurrence = created["occurrence"].as_u64().unwrap();
s.execute("solid.box", &json!({"length":2,"width":3,"height":4,"body_name":"Block","operation":"new"})).unwrap();
for body in &s.model.state().bodies {
+1 -1
View File
@@ -595,7 +595,7 @@ fn bare_profile_numbers_are_in_the_design_units() {
fn members_follow_a_frame_sketch_in_another_component() {
let mut s = Session::default();
rectangle_frame(&mut s);
let c = run(&mut s, "component.create", json!({"name": "Frame parts"}))["component"].as_u64().unwrap();
let c = run(&mut s, "component.create", json!({"name": "Frame parts", "grounded": false}))["component"].as_u64().unwrap();
let o = s.doc.occurrence_of(c).unwrap().id;
run(&mut s, "occurrence.move", json!({"occurrence": o, "translate": [0, 0, 100], "capture": true}));
// Made in the moved component, the members still lie on the root's frame sketch.
@@ -26,7 +26,7 @@ fn disc(s: &mut Session, name: &str, x: f64, r: &str) {
/// The disc alone, on no joint.
fn loose_disc(s: &mut Session, name: &str, x: f64, r: &str) {
run(s, "component.activate", json!({"component": "root"}));
run(s, "component.create", json!({"name": name}));
run(s, "component.create", json!({"name": name, "grounded": false}));
run(s, "solid.cylinder", json!({"base": [x, 0, 0], "axis": [0, 0, 1], "radius": r, "height": 5}));
}
@@ -123,7 +123,7 @@ fn rack() -> Session {
disc(&mut s, "Pinion", 0.0, "8 mm");
for (name, corner, length) in [("Rack", [-20.0, -14.0, 0.0], 40.0), ("Stop", [30.0, -14.0, 0.0], 4.0)] {
run(&mut s, "component.activate", json!({"component": "root"}));
run(&mut s, "component.create", json!({"name": name}));
run(&mut s, "component.create", json!({"name": name, "grounded": false}));
run(&mut s, "solid.box", json!({"length": length, "width": 4, "height": 4, "corner": corner}));
}
pin(&mut s, "slider", "Rail", "Base", "Rack", Vec3::new(0.0, -10.0, 0.0), Vec3::X);
+3 -3
View File
@@ -49,7 +49,7 @@ fn deleted_joint_ids_are_not_reused_after_reopening() {
/// at y = 33, z = 4.
fn leaf(s: &mut Session, name: &str) {
run(s, "component.activate", json!({"component": "root"}));
run(s, "component.create", json!({"name": name}));
run(s, "component.create", json!({"name": name, "grounded": false}));
run(s, "solid.box", json!({"length": 40, "width": 30, "height": 3, "corner": [0, 0, 0]}));
run(s, "solid.cylinder", json!({"base": [0, 33, 4], "axis": [1, 0, 0], "radius": 4, "height": 40, "operation": "new"}));
}
@@ -128,7 +128,7 @@ fn two_cubes() -> Session {
let mut s = Session::default();
for (name, x) in [("A", 0), ("B", 20)] {
run(&mut s, "component.activate", json!({"component": "root"}));
run(&mut s, "component.create", json!({"name": name}));
run(&mut s, "component.create", json!({"name": name, "grounded": false}));
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [x, 0, 0]}));
}
let o = occ(&s, "A");
@@ -369,7 +369,7 @@ fn interference_box_sweep_matches_every_pair_check() {
/// A small block in a new component: a part of a linkage, where only its joints matter.
pub(super) fn part(s: &mut Session, name: &str, corner: [f64; 3]) {
run(s, "component.activate", json!({"component": "root"}));
run(s, "component.create", json!({"name": name}));
run(s, "component.create", json!({"name": name, "grounded": false}));
run(s, "solid.box", json!({"length": 2, "width": 2, "height": 2, "corner": corner}));
}
+1 -1
View File
@@ -11,7 +11,7 @@ use crate::Session;
/// A part made of one box (`size` from `corner`) in a new component.
fn block(s: &mut Session, name: &str, corner: [f64; 3], size: [f64; 3]) {
run(s, "component.activate", json!({"component": "root"}));
run(s, "component.create", json!({"name": name}));
run(s, "component.create", json!({"name": name, "grounded": false}));
run(s, "solid.box", json!({"length": size[0], "width": size[1], "height": size[2], "corner": corner}));
}
+10 -10
View File
@@ -62,7 +62,7 @@ enum JoinSelection {
fn joined_motion_part(authoring: PartAuthoring, selection: JoinSelection) -> Session {
let mut s = Session::default();
if matches!(authoring, PartAuthoring::InComponent) {
run(&mut s, "component.create", json!({"name":"Rotor"}));
run(&mut s, "component.create", json!({"name":"Rotor","grounded":false}));
}
run(&mut s, "solid.box", json!({"length":10,"width":8,"height":6,"body_name":"Part","name":"Base"}));
run(&mut s, "select.set", json!({"items":[]}));
@@ -75,12 +75,12 @@ fn joined_motion_part(authoring: PartAuthoring, selection: JoinSelection) -> Ses
run(&mut s, "solid.box", p);
if !matches!(authoring, PartAuthoring::InComponent) {
let parent = if matches!(authoring, PartAuthoring::RootThenNestedTransfer) {
run(&mut s, "component.create", json!({"name":"Group","activate":false}));
run(&mut s, "component.create", json!({"name":"Group","activate":false,"grounded":false}));
"Group"
} else {
"root"
};
run(&mut s, "component.create", json!({"name":"Rotor","parent":parent,"activate":false}));
run(&mut s, "component.create", json!({"name":"Rotor","parent":parent,"activate":false,"grounded":false}));
run(&mut s, "component.move_bodies", json!({"bodies":["Part"],"component":"Rotor"}));
}
let driven = if matches!(authoring, PartAuthoring::RootThenNestedTransfer) { "Group" } else { "Rotor" };
@@ -95,7 +95,7 @@ fn attach_motion_rotor(s: &mut Session, component: &str, joint: &str) {
fn unrelated_motion_rotor(s: &mut Session) {
run(s, "component.activate", json!({"component":"root"}));
run(s, "component.create", json!({"name":"Unrelated"}));
run(s, "component.create", json!({"name":"Unrelated","grounded":false}));
run(s, "solid.box", json!({"length":2,"width":2,"height":2,"corner":[100,100,100],"body_name":"Remote"}));
attach_motion_rotor(s, "Unrelated", "Other turn");
}
@@ -179,7 +179,7 @@ fn joint_pose_joined_cylinders_keep_mesh_cells_at_unseen_angles() {
"solid.cylinder",
json!({"radius":2.8,"height":30,"base":[0,36,0],"axis":[0.981627183447664,0,0.1908089953765448],"operation":"join","targets":["Crank"]}),
);
run(&mut s, "component.create", json!({"name":"Crank","activate":false}));
run(&mut s, "component.create", json!({"name":"Crank","activate":false,"grounded":false}));
run(&mut s, "component.move_bodies", json!({"bodies":["Crank"],"component":"Crank"}));
run(&mut s, "joint.as_built", json!({"type":"revolute","name":"Crank","a":0,"b":"Crank","at":{"occurrence":0,"point":[0,0,0],"z":[0,1,0]}}));
assert_joint_only_moves(&mut s, "Crank");
@@ -258,7 +258,7 @@ fn joint_pose_combine_ignores_unrelated_motion() {
/// with the target preserves that volume and must preserve the computed definition too.
fn cross_component_motion_cut(move_tool_with_target: bool, kind: &str) -> Session {
let mut s = Session::default();
run(&mut s, "component.create", json!({"name":"MovingTarget"}));
run(&mut s, "component.create", json!({"name":"MovingTarget","grounded":false}));
run(&mut s, "solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Target"}));
run(&mut s, "component.activate", json!({"component":"root"}));
if move_tool_with_target {
@@ -280,7 +280,7 @@ fn motion_target_volume(s: &Session) -> f64 {
fn motion_combine_cut(kind: &str, together: bool) -> Session {
let mut s = Session::default();
run(&mut s, "component.create", json!({"name":"MovingTarget"}));
run(&mut s, "component.create", json!({"name":"MovingTarget","grounded":false}));
run(&mut s, "solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Target"}));
run(&mut s, "component.activate", json!({"component":"root"}));
run(&mut s, "component.create", json!({"name":"Tool"}));
@@ -440,7 +440,7 @@ fn joint_pose_undo_and_redo_match_fresh_geometry() {
fn joint_pose_geometry_edit_invalidates_the_warm_definition_mesh() {
let mut s = Session::default();
run(&mut s, "parameters.add", json!({"name":"span","expression":"10 mm"}));
run(&mut s, "component.create", json!({"name":"Rotor"}));
run(&mut s, "component.create", json!({"name":"Rotor","grounded":false}));
run(&mut s, "solid.box", json!({"length":"span","width":8,"height":6,"body_name":"Part"}));
attach_motion_rotor(&mut s, "Rotor", "Turn");
run(&mut s, "joint.drive", json!({"joint":"Turn","value":5}));
@@ -563,7 +563,7 @@ fn contact_check_finds_plates_crossing_face_to_face() {
fn contact_uses_preserved_body_placements_after_component_reassignment() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "body_name": "Transferred"}));
let component = run(&mut s, "component.create", json!({"name": "Carrier"}));
let component = run(&mut s, "component.create", json!({"name": "Carrier", "grounded": false}));
run(&mut s, "occurrence.move", json!({"occurrence": component["occurrence"], "translate": [100, 0, 0]}));
run(&mut s, "component.move_bodies", json!({"bodies": ["Transferred"], "component": component["component"]}));
run(&mut s, "component.activate", json!({"component": "root"}));
@@ -581,7 +581,7 @@ fn contact_uses_preserved_body_placements_after_component_reassignment() {
fn automatic_explode_centres_follow_reassigned_bodies() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "body_name": "Transferred"}));
let component = run(&mut s, "component.create", json!({"name": "Carrier"}));
let component = run(&mut s, "component.create", json!({"name": "Carrier", "grounded": false}));
run(&mut s, "occurrence.move", json!({"occurrence": component["occurrence"], "translate": [100, 0, 0]}));
run(&mut s, "component.move_bodies", json!({"bodies": ["Transferred"], "component": component["component"]}));
run(&mut s, "component.activate", json!({"component": "root"}));
+1 -1
View File
@@ -6,7 +6,7 @@ fn run(s: &mut Session, command: &str, p: Value) -> Value {
s.execute(command, &p).unwrap()
}
fn created(s: &mut Session, name: &str) -> (u64, u64) {
let c = run(s, "component.create", json!({"name": name}));
let c = run(s, "component.create", json!({"name": name, "grounded": false}));
(c["component"].as_u64().unwrap(), c["occurrence"].as_u64().unwrap())
}
fn near(value: &Value, expected: f64) {
+2 -1
View File
@@ -396,7 +396,8 @@ fn insert(s: &mut Session, p: &Value) -> Result<Value> {
};
let name = str_(p, "name").map(str::to_string).unwrap_or_else(|| part_name(&family, &size, &sh));
let active = s.active_component;
let c = run(s, "component.create", json!({"name": name}))?;
// Hardware is fitted to other parts: it starts free even as the design's first part (#2804).
let c = run(s, "component.create", json!({"name": name, "grounded": false}))?;
let (comp, occ) = (c["component"].as_u64().unwrap_or(0), c["occurrence"].as_u64().unwrap_or(0));
build(s, &sh)?;
s.doc_mut().parts.insert(comp, solidcraft_doc::StandardPart { family: family.clone(), size: size.clone(), length: shape_len(&sh) });
@@ -7,7 +7,7 @@ fn save(s: &mut Session, patch: Value) {
#[test]
fn settings_history_preserves_geometry_cache_and_dirty_state() {
let mut s = Session::default();
let component = s.execute("component.create", &json!({"name":"Part"})).unwrap();
let component = s.execute("component.create", &json!({"name":"Part","grounded":false})).unwrap();
s.execute("solid.box", &json!({"length":10,"width":20,"height":5})).unwrap();
s.execute("component.activate", &json!({"component":0})).unwrap();
s.execute("occurrence.move", &json!({"occurrence":component["occurrence"],"translate":[30,0,0]})).unwrap();
+2 -2
View File
@@ -124,7 +124,7 @@ fn rotated_component_bend_picks_follow_connected_panels() {
let mut sizes = Vec::new();
for rotated in [false, true] {
let mut s = Session::default();
let component = run(&mut s, "component.create", json!({"name": "Bent part"}));
let component = run(&mut s, "component.create", json!({"name": "Bent part", "grounded": false}));
rule(&mut s, "Test", 2.0, 0.5, 1.0, 0.5);
let corners = bent_section(&mut s, &[(0.0, 0.0), (60.0, 0.0), (60.0, 40.0), (90.0, 40.0)], 2.0, 1.0, 100.0);
// The remote bend is picked on its tangent edge, where it meets the web.
@@ -145,7 +145,7 @@ fn rotated_component_bend_picks_follow_connected_panels() {
#[test]
fn rotated_component_disconnected_bend_reports_world_point() {
let mut s = Session::default();
let component = run(&mut s, "component.create", json!({"name": "Bent part"}));
let component = run(&mut s, "component.create", json!({"name": "Bent part", "grounded": false}));
rule(&mut s, "Test", 2.0, 0.5, 1.0, 0.5);
section(&mut s, &[(0.0, 0.0), (60.0, 0.0), (60.0, 40.0), (90.0, 40.0)], 2.0, 100.0);
run(&mut s, "occurrence.move", json!({"occurrence": component["occurrence"], "axis": [1, 0, 0], "angle": "90 deg"}));
+4 -4
View File
@@ -434,7 +434,7 @@ fn sheet_pocket_transfer_keeps_local_depth_world_pose_and_history() {
run(&mut s, "solid.extrude", json!({"sketch":"Pocket","distance":1,"operation":"cut"}));
let name = s.model.state().sheets[0].body.clone();
check(&s, &name, 0, Vec3::ZERO, Vec3::Y, false);
let destination = run(&mut s, "component.create", json!({"name":"Machined","parent":0}));
let destination = run(&mut s, "component.create", json!({"name":"Machined","parent":0,"grounded":false}));
let component = destination["component"].as_u64().unwrap();
let occurrence = destination["occurrence"].as_u64().unwrap();
run(&mut s, "occurrence.move", json!({"occurrence":occurrence,"translate":[30,20,10],"axis":[1,0,0],"angle":"90 deg","capture":true}));
@@ -2269,7 +2269,7 @@ fn partial_depth_intersect_flipped_tool_and_transferred_sheet_keep_depth_side_an
run(&mut s, "solid.extrude", json!({"sketch":"RetainDepth","distance":1,"start_offset":0.5,"operation":"intersect","name":"RetainSlab"}));
let before = s.world_state().bodies[0].mesh().bounds();
let name = s.model.state().sheets[0].body.clone();
let destination = run(&mut s, "component.create", json!({"name":"Destination","parent":0}));
let destination = run(&mut s, "component.create", json!({"name":"Destination","parent":0,"grounded":false}));
let owner = destination["component"].as_u64().unwrap();
let occurrence = destination["occurrence"].as_u64().unwrap();
run(&mut s, "occurrence.move", json!({"occurrence":occurrence,"translate":[30,20,10],"axis":[1,0,0],"angle":"90 deg","capture":true}));
@@ -2315,7 +2315,7 @@ fn partial_depth_intersect_full_gauge_in_rotated_frames_does_not_invent_pockets(
let mut s = Session::default();
base(&mut s, 100.0, 60.0);
let name = s.model.state().sheets[0].body.clone();
let destination = run(&mut s, "component.create", json!({"name":"Destination","parent":0}));
let destination = run(&mut s, "component.create", json!({"name":"Destination","parent":0,"grounded":false}));
let owner = destination["component"].as_u64().unwrap();
run(
&mut s,
@@ -2493,7 +2493,7 @@ fn partial_depth_intersect_sub_extrusion_resolution_layers_refuse_atomically() {
let mut s = Session::default();
base(&mut s, 100.0, 60.0);
let name = s.model.state().sheets[0].body.clone();
let destination = run(&mut s, "component.create", json!({"name":"Far","parent":0}));
let destination = run(&mut s, "component.create", json!({"name":"Far","parent":0,"grounded":false}));
let owner = destination["component"].as_u64().unwrap();
run(
&mut s,
@@ -123,7 +123,7 @@ fn wire_frame_hostile_inputs_rollback_full_session() {
fn wire_frame_include_other_component_refresh_break_lost_and_reopen() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length":10,"width":10,"height":10}));
let component = run(&mut s, "component.create", json!({"name":"Receiver"}));
let component = run(&mut s, "component.create", json!({"name":"Receiver","grounded":false}));
let occurrence = component["occurrence"].as_u64().unwrap();
run(&mut s, "occurrence.move", json!({"occurrence":occurrence,"translate":[20,0,0]}));
run(&mut s, "sketch.create", json!({"plane":"XY","name":"Include target"}));
@@ -235,7 +235,7 @@ fn wire_frame_cross_owner_sweep_follows_world_path_edit_undo_and_reopen() {
run(&mut s, "sketch.options", json!({"sketch_3d":true}));
let wire = run(&mut s, "sketch.line3d", json!({"points":[[17,32,45],[17,32,55]]}))["curves"][0].as_str().unwrap().to_string();
run(&mut s, "sketch.finish", json!({}));
let owner = run(&mut s, "component.create", json!({"name":"Sweep owner"}))["occurrence"].as_u64().unwrap();
let owner = run(&mut s, "component.create", json!({"name":"Sweep owner","grounded":false}))["occurrence"].as_u64().unwrap();
run(&mut s, "occurrence.move", json!({"occurrence":owner,"axis":[0,0,1],"angle":"90 deg","translate":[20,30,40]}));
let profile = run(&mut s, "sketch.create", json!({"plane":"XY","offset":5,"name":"Profile"}))["sketch"].as_u64().unwrap();
run(&mut s, "sketch.circle.center", json!({"center":[2,3],"radius":2}));
@@ -264,7 +264,7 @@ fn wire_frame_cross_owner_sweep_follows_world_path_edit_undo_and_reopen() {
#[test]
fn wire_frame_three_owner_sweep_profile_move_invalidates_warm_cache() {
let mut s = Session::default();
let profile_owner = run(&mut s, "component.create", json!({"name":"Profile owner","parent":0}));
let profile_owner = run(&mut s, "component.create", json!({"name":"Profile owner","parent":0,"grounded":false}));
let profile_occurrence = profile_owner["occurrence"].as_u64().unwrap();
run(&mut s, "occurrence.move", json!({"occurrence":profile_occurrence,"translate":[4,7,5]}));
let profile = run(&mut s, "sketch.create", json!({"plane":"XY","name":"Foreign profile"}))["sketch"].as_u64().unwrap();
@@ -116,7 +116,7 @@ fn live_text_edit_rejects_bad_values_and_leaves_the_design_as_it_was() {
#[test]
fn text_move_in_a_rotated_component_preserves_font_and_local_coordinates() {
let mut s = Session::default();
let component = run(&mut s, "component.create", json!({"name":"Label"}));
let component = run(&mut s, "component.create", json!({"name":"Label","grounded":false}));
run(&mut s, "occurrence.move", json!({"occurrence":component["occurrence"],"translate":[30,20,10],"axis":[0,0,1],"angle":90}));
let created = run(&mut s, "sketch.create", json!({"plane":"XY"}));
let sid = created["sketch"].as_u64().unwrap();
+1 -1
View File
@@ -383,7 +383,7 @@ fn urdf_names_are_unique_across_links_joints_and_files() {
let mut s = Session::default();
for name in ["Arm", "base", "Arm_link1"] {
run(&mut s, "component.activate", json!({"component": "root"}));
run(&mut s, "component.create", json!({"name": name}));
run(&mut s, "component.create", json!({"name": name, "grounded": false}));
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [0, 0, 0]}));
}
run(&mut s, "solid.box", json!({"length": 5, "width": 5, "height": 5, "corner": [50, 50, 0]}));
+1 -1
View File
@@ -308,7 +308,7 @@ mod tests {
#[test]
fn normal_to_selection_uses_the_world_normal_of_a_moved_component() {
let mut s = Session::default();
s.execute("component.create", &json!({"name":"Part"})).unwrap();
s.execute("component.create", &json!({"name":"Part","grounded":false})).unwrap();
s.execute("solid.box", &json!({"length":40,"width":30,"height":20})).unwrap();
s.execute("occurrence.move", &json!({"occurrence":"Part:1","translate":[50,20,10],"axis":[1,2,3],"angle":"37 deg"})).unwrap();
let state = s.world_state();
+2 -2
View File
@@ -245,7 +245,7 @@ fn construction_on_a_3d_wire_ignores_its_sketch_plane_and_follows_edits() {
#[test]
fn plane_on_a_3d_wire_moves_with_its_component() {
let mut s = Session::default();
run(&mut s, "component.create", json!({"name":"Part"}));
run(&mut s, "component.create", json!({"name":"Part","grounded":false}));
let sketch = run(&mut s, "sketch.create", json!({"plane":"XY"}))["sketch"].as_u64().unwrap();
run(&mut s, "sketch.options", json!({"sketch_3d":true}));
let wire = run(&mut s, "sketch.line3d", json!({"points":[[0,0,10],[0,0,40]]}))["curves"][0].as_str().unwrap().to_string();
@@ -311,7 +311,7 @@ fn a_plane_through_three_vertices_follows_them() {
#[test]
fn construction_lives_in_the_component_frame() {
let mut s = Session::default();
run(&mut s, "component.create", json!({"name": "Part"}));
run(&mut s, "component.create", json!({"name": "Part", "grounded": false}));
run(&mut s, "solid.cylinder", json!({"radius": 5, "height": 10, "body_name": "Pin"}));
run(&mut s, "occurrence.move", json!({"occurrence": "Part:1", "translate": [50, 0, 0]}));
run(&mut s, "construct.axis.through_cylinder", json!({"face": {"face": [55, 0, 5]}, "name": "PinAxis"}));
+1 -1
View File
@@ -174,7 +174,7 @@ fn a_name_that_finds_no_face_is_refused_and_the_design_is_unchanged() {
#[test]
fn names_find_the_faces_of_a_moved_component() {
let mut s = Session::default();
run(&mut s, "component.create", json!({"name": "Part"}));
run(&mut s, "component.create", json!({"name": "Part", "grounded": false}));
run(&mut s, "solid.box", json!({"length": 30, "width": 20, "height": 10, "body_name": "Block"}));
run(&mut s, "solid.cylinder", json!({"base": [15, 10, -1], "radius": 3, "height": 12, "operation": "cut"}));
run(&mut s, "occurrence.move", json!({"occurrence": "Part:1", "translate": [50, 0, 0]}));
+2 -2
View File
@@ -37,7 +37,7 @@ fn volume(s: &mut Session) -> f64 {
/// and a construction plane, moved 50 mm along X.
fn moved_part() -> Session {
let mut s = Session::default();
run(&mut s, "component.create", json!({"name": "Part"}));
run(&mut s, "component.create", json!({"name": "Part", "grounded": false}));
run(&mut s, "sketch.create", json!({"plane": "XY", "name": "Base"}));
run(&mut s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [30, 20]}));
run(&mut s, "sketch.finish", json!({}));
@@ -211,7 +211,7 @@ fn sketch_world_points(s: &mut Session, sketch: &str) -> Vec<Vec3> {
/// A block "C" (40 x 30 x 20) in its own component, the root active again.
fn block_in_component() -> Session {
let mut s = Session::default();
run(&mut s, "component.create", json!({"name": "C"}));
run(&mut s, "component.create", json!({"name": "C", "grounded": false}));
run(&mut s, "solid.box", json!({"length": 40, "width": 30, "height": 20}));
run(&mut s, "component.activate", json!({"component": "root"}));
s
+1 -1
View File
@@ -60,7 +60,7 @@ mod tests {
#[test]
fn product_scene_keeps_placed_appearances_and_meshes_without_design_overlays() {
let mut s = Session::default();
let component = s.execute("component.create", &json!({"name":"Part"})).unwrap();
let component = s.execute("component.create", &json!({"name":"Part","grounded":false})).unwrap();
s.execute("solid.box", &json!({"length":10,"width":10,"height":10,"body_name":"Block"})).unwrap();
s.execute("appearance.assign", &json!({"bodies":["Block"],"color":"#20a080","opacity":0.4})).unwrap();
s.execute("appearance.assign", &json!({"faces":[[5,5,10]],"color":"#ff0000","opacity":0.7})).unwrap();
+1 -1
View File
@@ -1872,7 +1872,7 @@ fn components_occurrences_and_world_placement() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "body_name": "Base"}));
// A component, active: its box is authored in its frame.
let c = run(&mut s, "component.create", json!({"name": "Arm"}));
let c = run(&mut s, "component.create", json!({"name": "Arm", "grounded": false}));
let (cid, occ) = (c["component"].as_u64().unwrap(), c["occurrence"].as_u64().unwrap());
run(&mut s, "solid.box", json!({"corner": [20, 0, 0], "length": 10, "width": 4, "height": 4, "body_name": "ArmBody"}));
run(&mut s, "component.activate", json!({"component": 0}));
+7 -5
View File
@@ -14,7 +14,7 @@ use crate::*;
fn moved_component_picks_and_frames() {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "body_name": "Base"}));
let c = run(&mut s, "component.create", json!({"name": "Arm"}));
let c = run(&mut s, "component.create", json!({"name": "Arm", "grounded": false}));
let (cid, occ) = (c["component"].as_u64().unwrap(), c["occurrence"].as_u64().unwrap());
run(&mut s, "solid.box", json!({"corner": [20, 0, 0], "length": 10, "width": 4, "height": 4, "body_name": "ArmBody"}));
run(&mut s, "component.activate", json!({"component": 0}));
@@ -61,6 +61,7 @@ fn extrude_in_a_moved_component_from_a_root_sketch() {
run(&mut s, "solid.extrude", json!({"distance": 10, "body_name": "Jaw"}));
let made = run(&mut s, "component.from_bodies", json!({"bodies": ["Jaw"]}));
let jaw = made["components"][0]["component"].as_u64().unwrap();
run(&mut s, "occurrence.ground", json!({"occurrence": "Jaw:1", "grounded": false}));
// Turned half a turn about Z: the jaw now lies along +X (x 0..40, y -5..5).
run(&mut s, "occurrence.move", json!({"occurrence": "Jaw:1", "axis": [0, 0, 1], "angle": "180 deg", "origin": [0, 0, 0]}));
run(&mut s, "component.activate", json!({"component": 0}));
@@ -89,6 +90,7 @@ fn extrude_to_a_face_in_a_moved_component() {
run(&mut s, "solid.extrude", json!({"distance": 10, "body_name": "Jaw"}));
let made = run(&mut s, "component.from_bodies", json!({"bodies": ["Jaw"]}));
let jaw = made["components"][0]["component"].as_u64().unwrap();
run(&mut s, "occurrence.ground", json!({"occurrence": "Jaw:1", "grounded": false}));
run(&mut s, "occurrence.move", json!({"occurrence": "Jaw:1", "axis": [0, 0, 1], "angle": "180 deg", "origin": [0, 0, 0]}));
// Lifted too, so the jaw's own frame and the world differ in height (x 0..40, z 5..15).
run(&mut s, "occurrence.move", json!({"occurrence": "Jaw:1", "translate": [0, 0, 5]}));
@@ -113,7 +115,7 @@ fn extrude_to_a_face_in_a_moved_component() {
/// frame), its occurrence moved by `moves`, then a new component `Post`, active, with a 6 x 6 mm
/// sketch `Pad` centred at the origin (#928).
fn ramp_and_pad(s: &mut Session, moves: &[serde_json::Value]) {
run(s, "component.create", json!({"name": "Target"}));
run(s, "component.create", json!({"name": "Target", "grounded": false}));
run(s, "sketch.create", json!({"plane": "YZ", "name": "Wedge"}));
run(s, "sketch.line", json!({"points": [[-20, -30], [20, -30], [20, -10], [-20, -30]]}));
run(s, "sketch.finish", json!({}));
@@ -202,7 +204,7 @@ fn extrude_to_a_face_in_another_component_follows_it() {
#[test]
fn revolve_to_a_cylinder_in_another_moved_component() {
let mut s = Session::default();
run(&mut s, "component.create", json!({"name": "Pin"}));
run(&mut s, "component.create", json!({"name": "Pin", "grounded": false}));
run(&mut s, "solid.cylinder", json!({"base": [0, 14, -5], "radius": 4, "height": 15, "body_name": "PostBody"}));
run(&mut s, "component.activate", json!({"component": "root"}));
// From 90° round to 45° about Z: the post's axis is at (14 sin 45°, 14 cos 45°).
@@ -236,7 +238,7 @@ fn revolve_to_a_cylinder_in_another_moved_component() {
fn extrude_to_names_the_face_it_is_on() {
for moved in [false, true] {
let mut s = Session::default();
run(&mut s, "component.create", json!({"name": "Other"}));
run(&mut s, "component.create", json!({"name": "Other", "grounded": false}));
let z = if moved { -40.02 + 10.0 } else { -40.02 };
run(&mut s, "solid.box", json!({"corner": [-50, -50, z], "length": 100, "width": 100, "height": 20, "body_name": "Shim"}));
run(&mut s, "component.activate", json!({"component": "root"}));
@@ -264,7 +266,7 @@ fn extrude_to_names_the_face_it_is_on() {
#[test]
fn extrude_to_a_named_face_keeps_it_when_another_part_touches_it() {
let mut s = Session::default();
run(&mut s, "component.create", json!({"name": "Other"}));
run(&mut s, "component.create", json!({"name": "Other", "grounded": false}));
// A plate whose top face is z = 50, out of the way for now.
run(&mut s, "solid.box", json!({"corner": [-50, -50, 30], "length": 100, "width": 100, "height": 20, "body_name": "Plate"}));
run(&mut s, "component.activate", json!({"component": "root"}));
+3 -1
View File
@@ -221,6 +221,8 @@ fn an_imported_assembly_moves_as_one_until_it_is_unlocked() {
for o in &inside {
assert_eq!(dof.get(o), dof.get(&rig), "occurrence {o} moves only with the import: {r}");
}
// The design's first part is grounded when it comes in; free, it moves.
run(&mut s, "occurrence.ground", json!({"occurrence": "rig:1", "grounded": false}));
// Moving the import's component moves everything in it.
run(&mut s, "occurrence.move", json!({"occurrence": "rig:1", "translate": [0, 0, 50]}));
@@ -322,7 +324,7 @@ fn a_design_with_a_loose_import_rebuilds_unchanged() {
/// first placement turned and moved), with `Outer` itself turned about X and lifted.
fn nested_file(dir: &std::path::Path) -> String {
let mut s = Session::default();
let outer = run(&mut s, "component.create", json!({"name": "Outer"}))["occurrence"].clone();
let outer = run(&mut s, "component.create", json!({"name": "Outer", "grounded": false}))["occurrence"].clone();
run(&mut s, "solid.box", json!({"length": 30, "width": 30, "height": 5, "body_name": "Plate"}));
let inner = run(&mut s, "component.create", json!({"name": "Inner"}))["occurrence"].clone();
run(&mut s, "solid.box", json!({"length": 40, "width": 20, "height": 10, "body_name": "Block"}));
+5 -2
View File
@@ -25,7 +25,7 @@ fn assert_box(got: (Vec3, Vec3), want: (Vec3, Vec3)) {
/// A component "Arm" holding "ArmBody", its occurrence turned and moved; the root is active.
fn moved_arm(s: &mut Session) -> (u64, u64) {
let c = run(s, "component.create", json!({"name": "Arm"}));
let c = run(s, "component.create", json!({"name": "Arm", "grounded": false}));
let (component, occurrence) = (c["component"].as_u64().unwrap(), c["occurrence"].as_u64().unwrap());
run(s, "solid.box", json!({"corner": [10, 0, 0], "length": 20, "width": 4, "height": 6, "body_name": "ArmBody"}));
run(s, "component.activate", json!({"component": 0}));
@@ -171,6 +171,9 @@ fn moving_an_unrelated_occurrence_does_not_evaluate_the_mirror_again() {
run(&mut s, "solid.box", json!({"length": 8, "width": 8, "height": 8, "corner": [30, 0, 0], "body_name": "B"}));
run(&mut s, "component.from_bodies", json!({"bodies": ["A", "B"]}));
let occurrences: Vec<u64> = s.doc.occurrences.iter().map(|o| o.id).collect();
for occurrence in &occurrences {
run(&mut s, "occurrence.ground", json!({"occurrence": occurrence, "grounded": false}));
}
assert_eq!(occurrences.len(), 2, "{:?}", s.doc.occurrences);
let a = s.doc.body_frames(&s.model.state()).into_iter().find(|(name, ..)| name == "A").map(|(_, _, path, _)| path).unwrap();
let (mine, other) = if a.contains(&occurrences[0]) { (occurrences[0], occurrences[1]) } else { (occurrences[1], occurrences[0]) };
@@ -190,7 +193,7 @@ fn moving_an_unrelated_occurrence_does_not_evaluate_the_mirror_again() {
#[test]
fn mirrored_copies_of_a_placed_component_intersect() {
let mut s = Session::default();
let c = run(&mut s, "component.create", json!({"name": "Pair"}));
let c = run(&mut s, "component.create", json!({"name": "Pair", "grounded": false}));
let occurrence = c["occurrence"].as_u64().unwrap();
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [10, 0, 0], "body_name": "P"}));
run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [15, 5, 5], "body_name": "Q"}));
+1 -1
View File
@@ -106,7 +106,7 @@ fn point_parameters_rename_and_store() {
fn point_expressions_in_a_moved_component() {
let mut s = Session::default();
run(&mut s, "parameters.change", json!({"name": "x0", "expression": "10 mm"}));
let c = run(&mut s, "component.create", json!({"name": "Arm"}));
let c = run(&mut s, "component.create", json!({"name": "Arm", "grounded": false}));
let (cid, occ) = (c["component"].as_u64().unwrap(), c["occurrence"].as_u64().unwrap());
run(&mut s, "component.activate", json!({"component": 0}));
run(&mut s, "occurrence.move", json!({"occurrence": occ, "translate": [0, 50, 0]}));
@@ -182,7 +182,7 @@ fn adopted_scratch_keeps_its_warm_geometry_and_history_stages_invalidate_it() {
#[test]
fn moved_component_bodies_are_not_placed_again_when_something_else_changes() {
let mut session = Session::default();
let created = run(&mut session, "component.create", json!({"name":"Wheel"}));
let created = run(&mut session, "component.create", json!({"name":"Wheel","grounded":false}));
let occurrence = created["occurrence"].as_u64().unwrap();
run(&mut session, "solid.box", json!({"length":60,"width":60,"height":5,"body_name":"Rim"}));
run(&mut session, "component.activate", json!({"component":"root"}));
@@ -220,7 +220,7 @@ fn moved_component_bodies_are_not_placed_again_when_something_else_changes() {
fn joint_drive_reuses_reference_tessellation_across_rigid_poses() {
let mut session = Session::default();
run(&mut session, "solid.cylinder", json!({"radius":3,"height":8,"base":[4,0,0],"body_name":"Crank"}));
run(&mut session, "component.create", json!({"name":"Crank","parent":"root","activate":false}));
run(&mut session, "component.create", json!({"name":"Crank","parent":"root","activate":false,"grounded":false}));
run(&mut session, "component.move_bodies", json!({"bodies":["Crank"],"component":"Crank"}));
run(
&mut session,
+4 -1
View File
@@ -2299,7 +2299,10 @@ pub const SAVE: &str = "__save";
/// that capture, revert or keep moving.
pub fn needs_capture(app: &SolveApp, what: &str) -> bool {
!app.session.pending_moves.is_empty()
&& !matches!(what, "component.capture_position" | "component.revert_position" | "occurrence.move" | "edit.undo" | "edit.redo")
&& !matches!(
what,
"component.capture_position" | "component.revert_position" | "occurrence.move" | "occurrence.drag" | "edit.undo" | "edit.redo"
)
&& app.tree.capture_prompt.is_none()
}
+1 -1
View File
@@ -277,7 +277,7 @@ fn contribution_linked_paste_uses_the_pointer_and_pending_numeric_move() {
fn contribution_paste_pointer_uses_parent_coordinates_and_safe_fallbacks() {
use solidcraft_engine::{doc, geom::Vec3};
let mut h = crate::scenario::Harness::new();
let parent = h.app.run("component.create", json!({"name":"Parent"})).unwrap();
let parent = h.app.run("component.create", json!({"name":"Parent","grounded":false})).unwrap();
h.app
.run("occurrence.move", json!({"occurrence":parent["occurrence"],"translate":[20,30,10],"axis":[1,0,0],"angle":"45 deg","capture":true}))
.unwrap();
+1 -1
View File
@@ -110,7 +110,7 @@ fn to_offset_canvas_edit_changes_offset_and_one_undo_restores_extent() {
#[test]
fn moved_owner_references_survive_actual_edit_with_another_component_active() {
let mut h = Harness::new();
let owner = h.app.run("component.create", json!({"name":"Owner"})).unwrap();
let owner = h.app.run("component.create", json!({"name":"Owner","grounded":false})).unwrap();
let mut h = make_in(h, json!({"from":[0,0,5],"to":[0,0,15],"to_offset":"2 mm"}));
h.app.run("occurrence.move", json!({"occurrence":owner["occurrence"],"translate":[100,0,20]})).unwrap();
let other = h.app.run("component.create", json!({"name":"Other","parent":0})).unwrap();
+1 -1
View File
@@ -349,7 +349,7 @@ mod tests {
#[test]
fn identity_component_feedback_skips_moved_and_repeated_placements() {
let mut h = Harness::new();
let made = h.app.run("component.create", json!({"name":"Imported part"})).unwrap();
let made = h.app.run("component.create", json!({"name":"Imported part","grounded":false})).unwrap();
h.app.run("solid.box", json!({"length":4,"width":3,"height":5,"body_name":"Stock"})).unwrap();
let world = h.app.session.world_state();
let face =
+1
View File
@@ -95,6 +95,7 @@ mod measurement_ui_tests;
mod menu_tests;
pub(crate) mod mesh_lod;
pub mod messages;
pub mod occurrence_drag;
#[cfg(test)]
mod pattern_arrow_tests;
#[cfg(test)]
+1 -1
View File
@@ -251,7 +251,7 @@ mod tests {
let folder = std::env::temp_dir().join(format!("solidcraft-extract-ui-{}", std::process::id()));
std::fs::create_dir_all(&folder).unwrap();
let mut app = SolveApp::new(Session::default(), Default::default());
let made = app.run("component.create", json!({"name": "Bracket"})).unwrap();
let made = app.run("component.create", json!({"name": "Bracket", "grounded": false})).unwrap();
let (component, occurrence) = (made["component"].as_u64().unwrap(), made["occurrence"].as_u64().unwrap());
app.run("solid.box", json!({"length": 10, "width": 20, "height": 30})).unwrap();
let find = |app: &SolveApp, id: u64| context_menu::items(app, &Target::Component { id }).into_iter().find(|i| i.id == "ui.extractComponent");
+7
View File
@@ -279,6 +279,11 @@ fn component_menu_activates_grounds_and_pastes() {
let t = Target::Component { id: c };
act(&mut app, &t, "Activate");
assert_eq!(app.session.active_component, c);
// The design's first part comes in grounded (#2804); the menu frees it and grounds it again.
assert!(app.session.doc.occurrence_of(c).unwrap().grounded);
act(&mut app, &t, "Unground");
assert!(!app.session.doc.occurrence_of(c).unwrap().grounded);
assert!(find(&context_menu::items(&app, &t), "Move/Copy").enabled, "free");
act(&mut app, &t, "Ground");
assert!(app.session.doc.occurrence_of(c).unwrap().grounded);
assert!(!find(&context_menu::items(&app, &t), "Move/Copy").enabled, "grounded");
@@ -709,6 +714,7 @@ fn an_uncaptured_move_asks_before_the_next_command() {
let b = body(&app);
app.run("component.from_bodies", json!({"bodies": [b]})).unwrap();
let occ = app.session.doc.occurrences[0].id;
app.run("occurrence.ground", json!({"occurrence": occ, "grounded": false})).unwrap();
app.run("occurrence.move", json!({"occurrence": occ, "translate": [10, 0, 0], "capture": false})).unwrap();
app.start("sketch.create");
assert_eq!(app.tree.capture_prompt.as_deref(), Some("sketch.create"), "asks first");
@@ -748,6 +754,7 @@ fn occurrence_moves_turn_about_their_origin_then_move() {
let b = body(&app);
app.run("component.from_bodies", json!({"bodies": [b]})).unwrap();
let occ = app.session.doc.occurrences[0].id;
app.run("occurrence.ground", json!({"occurrence": occ, "grounded": false})).unwrap();
let mut m = crate::browser::OccMove::new(occ);
m.pivot = Some(solidcraft_engine::geom::Vec3::new(5.0, 0.0, 0.0));
m.translate = [10.0, 0.0, 0.0];
+153
View File
@@ -0,0 +1,153 @@
//! Dragging a free part puts it somewhere else (#2804): with the design (or the assembly holding
//! it) active, a left-button drag on a part moves its placement in that assembly, the one on the
//! picked body's exact path just inside the active placement. The point grabbed follows the
//! pointer in the plane through it that faces the view. Each frame runs `occurrence.drag`; the
//! whole drag is one undo step, and Escape puts everything back as it was.
//!
//! Floating chains move together whichever member is grabbed. Parts held
//! by joints to something fixed go to `joint_drag`; grounded parts and the active component's
//! own bodies are left to the selection box.
use std::sync::Arc;
use egui::Pos2;
use serde_json::json;
use solidcraft_engine::doc::{Document, apply_point, mat_inverse};
use solidcraft_engine::geom::Vec3;
use crate::SolveApp;
use crate::viewport::{Hit, Proj};
/// A drag under way.
#[derive(Clone, Debug)]
pub struct Drag {
/// The placement moved: its exact occurrence path.
path: Vec<u64>,
/// The point grabbed, in the placement's own coordinates.
local: Vec3,
/// The plane the pointer moves the point in: through where it was grabbed, facing the view.
origin: Vec3,
normal: Vec3,
/// What Escape goes back to (`edit.checkpoint`).
checkpoint: Option<u64>,
/// The drag's undo step is on top of the history (it went in with the first frame that
/// moved); the design it holds tells it from a step that replaced it.
step: Option<Arc<Document>>,
}
/// The placement a drag on `body` moves: the one on its path just inside the active placement.
fn placement_of(app: &SolveApp, body: &str) -> Option<Vec<u64>> {
let s = &app.session;
let (_, _, path, _) = s.doc.body_frames(&s.model.state()).into_iter().find(|f| f.0 == body)?;
let active = if s.active_component == 0 {
Vec::new()
} else {
s.active_occurrence_path
.clone()
.filter(|p| s.occurrence_placement(p).is_ok_and(|x| x.component == s.active_component))
.unwrap_or_else(|| s.doc.first_path(s.active_component))
};
if path.len() <= active.len() || !path.starts_with(&active) {
return None;
}
path.get(..active.len() + 1).map(<[u64]>::to_vec)
}
/// Begin a drag on the part under `p` when nothing holds it in place. True when one began.
pub fn start(app: &mut SolveApp, proj: &Proj, p: Pos2) -> bool {
// The face under the pointer, past the part's own edges and vertices (not past sketches or
// construction geometry in front of it).
let hits = crate::viewport::pick(app, proj, p);
let Some((body, at)) =
hits.into_iter().take_while(|h| matches!(h, Hit::Face { .. } | Hit::Edge { .. } | Hit::Vertex { .. })).find_map(|h| match h {
Hit::Face { body, point, .. } => Some((body, point)),
_ => None,
})
else {
return false;
};
let Some(path) = placement_of(app, &body) else { return false };
let s = &app.session;
if s.drag_group(&path).is_err() {
return false;
}
let Some(local) = s.occurrence_placement(&path).ok().and_then(|x| mat_inverse(&x.world)).map(|inv| apply_point(&inv, at)) else {
return false;
};
let checkpoint = app.session.execute("edit.checkpoint", &json!({})).ok().and_then(|r| r["checkpoint"].as_u64());
app.viewport.occurrence_drag = Some(Drag { path, local, origin: at, normal: proj.ray(p).1, checkpoint, step: None });
true
}
pub fn active(app: &SolveApp) -> bool {
app.viewport.occurrence_drag.is_some()
}
/// Bring the grabbed point to the pointer at `p`.
pub fn to(app: &mut SolveApp, proj: &Proj, p: Pos2) {
let Some(d) = app.viewport.occurrence_drag.clone() else { return };
// Something else took the drag's undo step (undo pressed mid-drag): the drag ends there.
if let Some(doc) = &d.step
&& !app.session.undo.last().is_some_and(|step| Arc::ptr_eq(&step.doc, doc))
{
end(app);
return;
}
let (o, dir) = proj.ray(p);
let facing = dir.dot(d.normal);
if facing.abs() < 1e-9 {
return;
}
let target = o + dir * ((d.origin - o).dot(d.normal) / facing);
let Ok(placement) = app.session.occurrence_placement(&d.path) else {
end(app);
return;
};
let at = apply_point(&placement.world, d.local);
if !target.is_finite() || !at.is_finite() || target.dist(at) < 1e-9 {
return;
}
let params = json!({"path": d.path, "at": [at.x, at.y, at.z], "point": [target.x, target.y, target.z], "continuous": true});
// One undo step for the whole drag: the first frame's, kept on top while the others run.
let own = if d.step.is_some() { app.session.undo.pop() } else { None };
let before = app.session.doc.clone();
let pushed = app.run("occurrence.drag", params).is_ok() && !Arc::ptr_eq(&before, &app.session.doc);
match own {
Some(step) => {
if pushed {
app.session.undo.pop();
}
app.session.undo.push(step);
}
None if pushed => {
let step = app.session.undo.last().map(|step| step.doc.clone());
if let Some(d) = app.viewport.occurrence_drag.as_mut() {
d.step = step;
}
}
None => {}
}
}
/// Let go: the part stays where it was dragged.
pub fn end(app: &mut SolveApp) {
if let Some(Drag { checkpoint: Some(checkpoint), .. }) = app.viewport.occurrence_drag.take() {
let _ = app.session.execute("edit.restore_checkpoint", &json!({"checkpoint": checkpoint, "forget": true}));
}
}
/// Escape: the part goes back, and the drag leaves no undo step. True when a drag was cancelled.
pub fn cancel(app: &mut SolveApp) -> bool {
let Some(d) = app.viewport.occurrence_drag.take() else { return false };
match d.checkpoint {
Some(checkpoint) => drop(app.session.execute("edit.restore_checkpoint", &json!({"checkpoint": checkpoint}))),
// Without a checkpoint the drag's own step takes it back.
None if d.step.is_some() => drop(app.session.execute("edit.undo", &json!({}))),
None => {}
}
true
}
#[cfg(test)]
#[path = "occurrence_drag_tests.rs"]
mod tests;
+200
View File
@@ -0,0 +1,200 @@
//! A left-button drag on a free part repositions it (#2804).
use serde_json::{Value, json};
use solidcraft_engine::geom::Vec3;
use crate::scenario::Harness;
fn run(h: &mut Harness, id: &str, p: Value) -> Value {
h.app.run(id, p.clone()).unwrap_or_else(|e| panic!("{id} {p}: {e}"))
}
fn screen(h: &mut Harness, p: Vec3) -> egui::Pos2 {
let [x, y] = h.at(&json!({"world": [p.x, p.y, p.z]})).expect("on screen");
egui::pos2(x as f32, y as f32)
}
/// Where the placement `path` puts its origin.
fn origin(h: &Harness, path: &[u64]) -> Vec3 {
let w = h.app.session.occurrence_placement(path).expect("placement").world;
Vec3::new(w[3][0], w[3][1], w[3][2])
}
/// A grounded base (the design's first part) and a free 10 mm cube beside it, seen from the top:
/// (harness, base occurrence, free occurrence).
fn two_parts() -> (Harness, u64, u64) {
let mut h = Harness::new();
h.app.home.open = false;
let mut occurrences = Vec::new();
for (name, corner) in [("Base", [-5, -5, 0]), ("Free", [20, 0, 0])] {
run(&mut h, "component.activate", json!({"component": "root"}));
occurrences.push(run(&mut h, "component.create", json!({"name": name}))["occurrence"].as_u64().expect("occurrence"));
run(&mut h, "solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": corner}));
}
run(&mut h, "component.activate", json!({"component": "root"}));
h.call("ui.view", json!({"view": "top"}));
h.app.cam.distance = 200.0;
h.frames(3);
(h, occurrences[0], occurrences[1])
}
fn play(h: &mut Harness) {
while !h.app.synthetic.is_empty() {
h.frame();
}
h.frames(2);
}
/// Press at `a` (holding `modifiers`) and move to `b` in 12 frames, holding the button there.
fn press_and_move(h: &mut Harness, a: egui::Pos2, b: egui::Pos2, modifiers: egui::Modifiers) {
h.app.synthetic.push(egui::Event::PointerMoved(a));
h.app.synthetic.push(egui::Event::PointerButton { pos: a, button: egui::PointerButton::Primary, pressed: true, modifiers });
h.app.synthetic.extend((1..=12).map(|k| egui::Event::PointerMoved(a + (b - a) * (k as f32 / 12.0))));
play(h);
}
fn release(h: &mut Harness, b: egui::Pos2) {
h.app.synthetic.push(egui::Event::PointerButton { pos: b, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() });
play(h);
}
/// Dragged by its top face, a free part follows the pointer in the plane facing the view, in one
/// undo step that undo takes back; frames are not echoed one by one.
#[test]
fn dragging_a_free_part_moves_it_in_one_undo_step() {
let (mut h, base, free) = two_parts();
assert!(h.app.session.doc.occurrences.iter().any(|o| o.id == base && o.grounded), "the first part is grounded");
let undo = h.app.session.undo.len();
let (a, b) = (screen(&mut h, Vec3::new(25.0, 5.0, 10.0)), screen(&mut h, Vec3::new(25.0, 35.0, 10.0)));
press_and_move(&mut h, a, b, Default::default());
assert!(h.app.viewport.occurrence_drag.is_some() && h.app.viewport.boxsel.is_none(), "the drag moves the part, not a selection box");
release(&mut h, b);
assert!(h.app.viewport.occurrence_drag.is_none());
assert!(origin(&h, &[free]).dist(Vec3::new(0.0, 30.0, 0.0)) < 0.5, "{:?}", origin(&h, &[free]));
assert!(origin(&h, &[base]).dist(Vec3::ZERO) < 1e-9, "the grounded part stays");
assert_eq!(h.app.session.undo.len(), undo + 1, "one undo step for the drag");
assert_eq!(h.app.session.undo.last().map(|s| s.label.as_str()), Some("Drag Occurrence"));
assert!(h.app.session.pending_moves.is_empty(), "the position is captured");
assert!(!h.app.session.log.iter().any(|l| l.contains("Drag Occurrence")), "frames are not echoed: {:?}", h.app.session.log);
run(&mut h, "edit.undo", json!({}));
assert!(origin(&h, &[free]).dist(Vec3::ZERO) < 1e-9, "{:?}", origin(&h, &[free]));
}
/// A drag on the grounded part, from empty space, or with Shift, Ctrl or Alt held on a free part
/// draws a selection box and moves nothing.
#[test]
fn grounded_parts_empty_space_and_modifier_drags_draw_a_selection_box() {
let (mut h, base, free) = two_parts();
let cases = [
(Vec3::new(0.0, 0.0, 10.0), egui::Modifiers::NONE),
(Vec3::new(-40.0, 40.0, 0.0), egui::Modifiers::NONE),
(Vec3::new(25.0, 5.0, 10.0), egui::Modifiers::SHIFT),
(Vec3::new(25.0, 5.0, 10.0), egui::Modifiers::CTRL),
(Vec3::new(25.0, 5.0, 10.0), egui::Modifiers { command: true, mac_cmd: true, ..Default::default() }),
(Vec3::new(25.0, 5.0, 10.0), egui::Modifiers::ALT),
];
for (at, modifiers) in cases {
let undo = h.app.session.undo.len();
let a = screen(&mut h, at);
let b = a + egui::vec2(60.0, 40.0);
press_and_move(&mut h, a, b, modifiers);
assert!(h.app.viewport.occurrence_drag.is_none() && h.app.viewport.boxsel.is_some(), "{at:?} {modifiers:?}: a selection box");
release(&mut h, b);
assert!(origin(&h, &[base]).dist(Vec3::ZERO) < 1e-9 && origin(&h, &[free]).dist(Vec3::ZERO) < 1e-9, "{at:?} {modifiers:?}");
assert_eq!(h.app.session.undo.len(), undo, "{at:?} {modifiers:?}");
}
}
/// Escape during a drag puts the part back and leaves no undo step.
#[test]
fn escape_cancels_a_drag() {
let (mut h, _, free) = two_parts();
let undo = h.app.session.undo.len();
let (a, b) = (screen(&mut h, Vec3::new(25.0, 5.0, 10.0)), screen(&mut h, Vec3::new(25.0, 35.0, 10.0)));
press_and_move(&mut h, a, b, Default::default());
assert!(origin(&h, &[free]).dist(Vec3::ZERO) > 1.0, "it moved while dragged");
for pressed in [true, false] {
h.app.synthetic.push(egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed, repeat: false, modifiers: Default::default() });
}
play(&mut h);
assert!(h.app.viewport.occurrence_drag.is_none());
assert!(origin(&h, &[free]).dist(Vec3::ZERO) < 1e-9, "{:?}", origin(&h, &[free]));
release(&mut h, b);
assert!(origin(&h, &[free]).dist(Vec3::ZERO) < 1e-9, "the release after Escape moves nothing");
assert_eq!(h.app.session.undo.len(), undo);
}
/// With the design active, a drag on a part inside an assembly moves that assembly's placement;
/// with the assembly active, the part inside it.
#[test]
fn the_active_placement_decides_which_occurrence_moves() {
let (mut h, _, free) = two_parts();
let asm = h.app.session.doc.occurrences.iter().find(|o| o.id == free).map_or(0, |o| o.component);
run(&mut h, "component.activate", json!({"component": asm}));
let leaf = run(&mut h, "component.create", json!({"name": "Leaf"}))["occurrence"].as_u64().expect("occurrence");
run(&mut h, "solid.box", json!({"length": 4, "width": 4, "height": 4, "corner": [40, 0, 0]}));
run(&mut h, "component.activate", json!({"component": "root"}));
h.frames(2);
let (a, b) = (screen(&mut h, Vec3::new(42.0, 2.0, 4.0)), screen(&mut h, Vec3::new(42.0, 22.0, 4.0)));
press_and_move(&mut h, a, b, Default::default());
release(&mut h, b);
assert!(origin(&h, &[free]).dist(Vec3::new(0.0, 20.0, 0.0)) < 0.5, "the assembly moves: {:?}", origin(&h, &[free]));
assert!(origin(&h, &[free, leaf]).dist(Vec3::new(0.0, 20.0, 0.0)) < 0.5, "with its part");
run(&mut h, "component.activate", json!({"component": asm, "occurrence": free, "path": [free]}));
h.frames(2);
let (a, b) = (screen(&mut h, Vec3::new(42.0, 22.0, 4.0)), screen(&mut h, Vec3::new(52.0, 22.0, 4.0)));
press_and_move(&mut h, a, b, Default::default());
release(&mut h, b);
assert!(origin(&h, &[free]).dist(Vec3::new(0.0, 20.0, 0.0)) < 0.5, "the active assembly stays: {:?}", origin(&h, &[free]));
assert!(origin(&h, &[free, leaf]).dist(Vec3::new(10.0, 20.0, 0.0)) < 0.5, "its part moves: {:?}", origin(&h, &[free, leaf]));
}
#[test]
fn either_member_of_a_floating_hinge_drags_the_whole_chain() {
let (mut h, base, free) = two_parts();
run(&mut h, "occurrence.ground", json!({"occurrence": base, "grounded": false}));
let at = |o| json!({"occurrence": o, "point": [0, 0, 0], "z": [0, 0, 1]});
run(&mut h, "joint.create", json!({"type": "revolute", "a": at(base), "b": at(free), "flip": true}));
// The base's centre is under the joint glyph; grab its face away from that glyph.
for grab in [Vec3::new(25.0, 5.0, 10.0), Vec3::new(4.0, 4.0, 10.0)] {
h.frames(2);
h.step(&json!({"shot": "floating-chain-before"})).unwrap();
let before = h.app.session.doc.to_json();
let values = h.app.session.doc.assembly.joints[0].values.clone();
let undo = h.app.session.undo.len();
let (a, b) = (screen(&mut h, grab), screen(&mut h, grab + Vec3::new(0.0, 30.0, 0.0)));
press_and_move(&mut h, a, b, Default::default());
assert!(
h.app.viewport.occurrence_drag.is_some(),
"grab={grab:?}, base={:?}, free={:?}, group={:?}, joint={:?}, box={:?}",
origin(&h, &[base]),
origin(&h, &[free]),
h.app.session.drag_group(&[free]),
h.app.viewport.joint_drag,
h.app.viewport.boxsel
);
assert!(h.app.viewport.joint_drag.is_none());
release(&mut h, b);
h.step(&json!({"shot": "floating-chain-after"})).unwrap();
for o in [base, free] {
assert!(origin(&h, &[o]).dist(Vec3::new(0.0, 30.0, 0.0)) < 0.5);
}
assert_eq!(h.app.session.doc.assembly.joints[0].values, values);
assert_eq!(h.app.session.undo.len(), undo + 1);
run(&mut h, "edit.undo", json!({}));
assert_eq!(h.app.session.doc.to_json(), before);
}
}
fn key(h: &mut Harness, key: egui::Key, pressed: bool) {
h.app.synthetic.push(egui::Event::Key { key, physical_key: None, pressed, repeat: false, modifiers: Default::default() });
play(h);
}
#[test]
fn r_still_starts_rectangle_with_a_free_part_in_the_design() {
let (mut h, _, _) = two_parts();
key(&mut h, egui::Key::R, true);
key(&mut h, egui::Key::R, false);
assert!(matches!(h.app.dialog.as_ref().map(|d| &d.kind), Some(crate::dialogs::Kind::Sketch)), "R starts Rectangle through Create Sketch");
assert_eq!(h.app.dialog.as_ref().and_then(|d| d.then_start), Some("sketch.rectangle.two_point"));
}
+1 -1
View File
@@ -9,7 +9,7 @@ use solidcraft_engine::{Sel, doc, geom::Vec3};
#[test]
fn occurrence_gizmo_drag_matches_numeric_input_and_preserves_joints_capture_and_undo() {
let mut h = Harness::new();
let part = h.app.run("component.create", json!({"name":"Block"})).unwrap();
let part = h.app.run("component.create", json!({"name":"Block","grounded":false})).unwrap();
let first = part["occurrence"].as_u64().unwrap();
h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
h.app.run("component.activate", json!({"component":0})).unwrap();
+7 -3
View File
@@ -404,7 +404,7 @@ fn cylinder_emboss_target_face_and_edit_keep_the_anchored_operation() {
#[test]
fn cylinder_emboss_edit_retains_second_source_and_author_paths_and_all_profiles() {
let mut h = crate::scenario::Harness::new();
let source = h.app.run("component.create", json!({"name":"Source"})).unwrap()["component"].as_u64().unwrap();
let source = h.app.run("component.create", json!({"name":"Source","grounded":false})).unwrap()["component"].as_u64().unwrap();
h.app.run("solid.cylinder", json!({"radius":10,"height":20,"body_name":"Sleeve"})).unwrap();
h.app.run("occurrence.move", json!({"occurrence":"Source:1","axis":[0,0,1],"angle":"90 deg","translate":[50,0,0]})).unwrap();
let source_second = h.app.run("occurrence.copy", json!({"component":source,"translate":[80,0,0]})).unwrap()["occurrence"].as_u64().unwrap();
@@ -499,7 +499,11 @@ fn cylinder_emboss_edit_retains_second_source_and_author_paths_and_all_profiles(
fn cylinder_emboss_profile_guide_uses_target_or_unique_foreign_sketch_frame() {
for target_owned in [true, false] {
let mut h = crate::scenario::Harness::new();
let source = if target_owned { h.app.run("component.create", json!({"name":"Source"})).unwrap()["component"].as_u64().unwrap() } else { 0 };
let source = if target_owned {
h.app.run("component.create", json!({"name":"Source","grounded":false})).unwrap()["component"].as_u64().unwrap()
} else {
0
};
h.app.run("solid.cylinder", json!({"radius":10,"height":20,"body_name":"Sleeve"})).unwrap();
let (profile_owner, expected, target, face) = if target_owned {
h.app.run("occurrence.move", json!({"occurrence":"Source:1","axis":[0,0,1],"angle":"90 deg","translate":[50,0,0]})).unwrap();
@@ -507,7 +511,7 @@ fn cylinder_emboss_profile_guide_uses_target_or_unique_foreign_sketch_frame() {
let target = h.app.session.occurrence_bodies(&[second], false).unwrap().remove(0);
(source, Vec3::new(120.0, 0.0, 0.0), target, json!([120, 0, 7.5]))
} else {
let profile = h.app.run("component.create", json!({"name":"Profile"})).unwrap()["component"].as_u64().unwrap();
let profile = h.app.run("component.create", json!({"name":"Profile","grounded":false})).unwrap()["component"].as_u64().unwrap();
h.app.run("occurrence.move", json!({"occurrence":"Profile:1","axis":[0,0,1],"angle":"90 deg","translate":[50,20,0]})).unwrap();
(profile, Vec3::new(0.0, 10.0, 0.0), "Sleeve".to_string(), json!([0, 10, 7.5]))
};
+2
View File
@@ -156,6 +156,7 @@ fn capture_question_offers_capture_revert_and_cancel() {
let body = h.app.session.model.state().bodies[0].name.clone();
h.app.run("component.from_bodies", json!({"bodies": [body]})).unwrap();
let occ = h.app.session.doc.occurrences[0].id;
h.app.run("occurrence.ground", json!({"occurrence": occ, "grounded": false})).unwrap();
h.app.run("occurrence.move", json!({"occurrence": occ, "translate": [10, 0, 0], "capture": false})).unwrap();
h.app.start("sketch.create");
card_is_drawn(&mut h);
@@ -184,6 +185,7 @@ fn occurrence_move_card_edits_distances_and_captures_or_reverts() {
let body = h.app.session.model.state().bodies[0].name.clone();
h.app.run("component.from_bodies", json!({"bodies": [body]})).unwrap();
let occ = h.app.session.doc.occurrences[0].id;
h.app.run("occurrence.ground", json!({"occurrence": occ, "grounded": false})).unwrap();
h.app.tree.occurrence_move = Some(crate::browser::OccMove::new(occ));
card_is_drawn(&mut h);
for k in 0..3 {
+3 -3
View File
@@ -94,7 +94,7 @@ fn to_object_noop_retains_dormant_secondary_angle_and_downstream_dimension() {
#[test]
fn rotated_owner_to_point_remains_exact_on_noop_edit() {
let mut h = Harness::new();
let owner = h.app.run("component.create", json!({"name":"Owner"})).unwrap();
let owner = h.app.run("component.create", json!({"name":"Owner","grounded":false})).unwrap();
let mut h = make_params(h, json!({"origin":[0,0,0],"dir":[0,2,0]}), json!({"to":[0,2,12],"angle":"45 deg"}));
h.app.run("occurrence.move", json!({"occurrence":owner["occurrence"],"translate":[100,0,20],"axis":[0,0,1],"angle":"17 deg"})).unwrap();
h.app.run("component.create", json!({"name":"Other","parent":0})).unwrap();
@@ -192,7 +192,7 @@ fn revolve_angle_edit_preserves_axis_downstream_binding_and_one_undo() {
#[test]
fn rotated_owner_explicit_axis_is_lossless_with_another_component_active() {
let mut h = Harness::new();
let owner = h.app.run("component.create", json!({"name":"Owner"})).unwrap();
let owner = h.app.run("component.create", json!({"name":"Owner","grounded":false})).unwrap();
let mut h = make(h, json!({"origin":[0,0,0],"dir":[0,2,0]}));
h.app.run("occurrence.move", json!({"occurrence":owner["occurrence"],"translate":[100,0,20],"axis":[0,0,1],"angle":"17 deg"})).unwrap();
h.app.run("component.create", json!({"name":"Other","parent":0})).unwrap();
@@ -214,7 +214,7 @@ fn rotated_owner_explicit_axis_is_lossless_with_another_component_active() {
fn world_and_sketch_axis_handles_follow_authoring_occurrence() {
for selected in [json!("Y"), json!("y")] {
let mut h = Harness::new();
let owner = h.app.run("component.create", json!({"name":"Owner"})).unwrap();
let owner = h.app.run("component.create", json!({"name":"Owner","grounded":false})).unwrap();
let mut h = make(h, selected);
h.app.run("occurrence.move", json!({"occurrence":owner["occurrence"],"translate":[100,0,20],"axis":[0,0,1],"angle":"17 deg"})).unwrap();
let original = axis(&h);
@@ -205,7 +205,7 @@ fn sketch_preselected_points_toggle_once_and_empty_shift_box_keeps_reference() {
#[test]
fn sketch_modify_previews_use_the_active_occurrences_world_placement() {
let mut h = Harness::new();
let part = h.app.run("component.create", json!({"name":"Part"})).unwrap();
let part = h.app.run("component.create", json!({"name":"Part","grounded":false})).unwrap();
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
let sid = h.app.session.active_sketch.unwrap();
h.app.run("sketch.line", json!({"points":[[-30,0],[-20,0]]})).unwrap();
+5 -2
View File
@@ -44,8 +44,11 @@ pub fn stand_up(app: &mut SolveApp) -> Result<(), String> {
app.stand_up_reason = false;
let Some(bodies) = app.stand_up.take() else { return Err("no file is waiting to be stood up".into()) };
match app.stand_up_occurrence.take() {
// The import's component turns about its parent's origin, contents and all.
Some(occurrence) => app.run("occurrence.move", json!({ "occurrence": occurrence, "axis": [1, 0, 0], "angle": "90 deg" })),
// The import's component turns about its parent's origin, contents and all, even when it
// came in as the design's grounded first part (#2804): it is still being placed.
Some(occurrence) => {
app.run("occurrence.move", json!({ "occurrence": occurrence, "axis": [1, 0, 0], "angle": "90 deg", "move_grounded": true }))
}
None => app.run("solid.move", json!({ "bodies": bodies, "axis": [1, 0, 0], "angle": "90 deg" })),
}
.map_err(|e| e.to_string())?;
+2 -2
View File
@@ -33,10 +33,10 @@ pub(crate) fn click(h: &mut Harness, handle: &str) {
h.frames(3);
}
/// One component named Block, with its original occurrence and the root active.
/// One component named Block, with its original occurrence free and the root active.
pub(crate) fn component_box() -> (Harness, u64, u64) {
let mut h = Harness::new();
let part = h.app.run("component.create", json!({"name":"Block"})).unwrap();
let part = h.app.run("component.create", json!({"name":"Block","grounded":false})).unwrap();
let component = part["component"].as_u64().unwrap();
let occurrence = part["occurrence"].as_u64().unwrap();
h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
+1 -1
View File
@@ -2022,7 +2022,7 @@ pub fn shortcuts(app: &mut SolveApp, ctx: &egui::Context) {
}
continue;
}
if crate::sketch_text_move::cancel_drag(app) {
if crate::sketch_text_move::cancel_drag(app) || crate::occurrence_drag::cancel(app) {
continue;
}
if crate::select_other::is_open(app) {
+22 -5
View File
@@ -154,6 +154,8 @@ pub struct ViewportState {
pub(crate) text_drag: Option<(u64, String)>,
/// A part that joints place, being dragged.
pub(crate) joint_drag: Option<crate::joint_drag::Drag>,
/// A free part being dragged to a new place (#2804).
pub(crate) occurrence_drag: Option<crate::occurrence_drag::Drag>,
/// The plane the grid was last drawn on while Preferences ▸ Grid follows the view is on
/// (#1470), kept so the choice is hysteretic near the thresholds (#1993).
pub(crate) grid_plane: std::sync::Mutex<GridPlane>,
@@ -3362,26 +3364,40 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
if crate::sketch_text_handles::dragging(app) && !crate::issue_report::cad_input_blocked() && !ui.input(|i| i.pointer.primary_down()) {
crate::sketch_text_handles::drag_end(app);
}
// Dragging a part that joints place moves it as far as they allow (outside sketches).
// Dragging a part moves its free chain (outside sketches), or reaches within its joints
// when the chain is anchored. Shift, Ctrl/Cmd or Alt held as the drag starts
// draws a selection box instead, as a drag from empty space does.
if app.tool.is_none() && app.dialog.is_none() && primary_nav.is_none() && mode.is_none() && app.session.active_sketch.is_none() && !held {
if resp.drag_started_by(egui::PointerButton::Primary)
// Physical Ctrl on macOS is not the primary click-selection modifier, but must
// still keep a modified drag from moving a part.
&& !(mods.shift || mods.command || mods.ctrl || mods.alt)
&& let Some(a) = ui.input(|i| i.pointer.press_origin())
&& rect.contains(a)
&& !crate::shell::covered(app, a)
&& !axes.contains(a)
&& !crate::occurrence_drag::start(app, &proj, a)
{
crate::joint_drag::start(app, &proj, a);
}
if crate::joint_drag::active(app)
&& resp.dragged_by(egui::PointerButton::Primary)
if resp.dragged_by(egui::PointerButton::Primary)
&& let Some(p) = hover
{
crate::joint_drag::to(app, &proj, p);
if crate::joint_drag::active(app) {
crate::joint_drag::to(app, &proj, p);
} else if crate::occurrence_drag::active(app) {
ui.ctx().set_cursor_icon(egui::CursorIcon::Grabbing);
crate::occurrence_drag::to(app, &proj, p);
}
}
}
if crate::joint_drag::active(app) && (resp.drag_stopped() || !ui.input(|i| i.pointer.primary_down())) {
crate::joint_drag::end(app);
}
// A drag whose release never came (focus lost, a tool or dialog took over) ends where it is.
if crate::occurrence_drag::active(app) && (resp.drag_stopped() || !ui.input(|i| i.pointer.primary_down())) {
crate::occurrence_drag::end(app);
}
// Box selection: a primary drag on the model when no navigation mode is on.
if app.tool.is_none()
&& !held
@@ -3389,6 +3405,7 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
&& mode.is_none()
&& app.viewport.point_drag.is_none()
&& !crate::joint_drag::active(app)
&& !crate::occurrence_drag::active(app)
&& !crate::dim_view::dragging()
&& !crate::sketch3d::dragging()
&& !crate::sketch_text_handles::dragging(app)
@@ -5103,7 +5120,7 @@ mod tests {
#[test]
fn timeline_modifier_highlight_follows_component_instances() {
let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
app.run("component.create", json!({"name":"Part"})).unwrap();
app.run("component.create", json!({"name":"Part","grounded":false})).unwrap();
app.run("solid.box", json!({"length":20,"width":20,"height":20})).unwrap();
let id = app.run("solid.fillet", json!({"edges":[[0,0,10]],"radius":2})).unwrap()["feature"].as_u64().unwrap();
app.run("occurrence.move", json!({"occurrence":"Part:1","translate":[30,0,0]})).unwrap();
@@ -119,6 +119,26 @@
}
}
},
{
"note": "The design's first part is made grounded (#2804): free it before moving it."
},
{
"call": "ui.menu",
"params": {
"x": 100,
"y": 170,
"target": {
"type": "component",
"id": 1
}
}
},
{
"call": "ui.menuPick",
"params": {
"item": "Unground"
}
},
{
"click": {
"handle": "row:occurrence:2"
@@ -7,7 +7,8 @@
"params": {
"command": "component.create",
"params": {
"name": "C"
"name": "C",
"grounded": false
}
}
},
@@ -6,7 +6,9 @@
"call": "engine.execute",
"params": {
"command": "component.create",
"params": {}
"params": {
"grounded": false
}
}
},
{
+1
View File
@@ -126,6 +126,7 @@ fn turn_up_axis_in_the_component_menu_turns_and_undo_restores() {
h.run(&json!([{"click": {"handle": "stand_up:leave"}}])).unwrap();
h.frames(3);
let occurrence = h.app.session.doc.occurrences.iter().map(|o| o.id).max().expect("the import's occurrence");
h.app.run("occurrence.ground", json!({"occurrence": occurrence, "grounded": false})).unwrap();
let items = solidcraft_ui_egui::context_menu::items(&h.app, &solidcraft_ui_egui::context_menu::Target::Occurrence { path: vec![occurrence] });
let turn = items.iter().find(|i| i.id == "ui.turnUpAxis").expect("Turn Up Axis is in the menu");
let labels: Vec<_> = turn.children.iter().map(|c| c.label.as_str()).collect();
+27 -3
View File
@@ -9,7 +9,31 @@ faded.
A component is placed by its **occurrences**. Paste creates another instance of the same
component, and **Paste New** creates an independent copy. Move an occurrence with the move
triad, then **Capture Position** to keep it or **Revert** to put it back. SolidCraft asks before
the next command if a move wasn't captured. **Ground** fixes an occurrence in place.
the next command if a move wasn't captured. **Ground** fixes an occurrence in place, and
**Unground** (the same row of the browser's context menu) frees it again.
The design's first part is grounded when it is made: the first occurrence placed directly in the
design by **New Component**, **Create Components from Bodies** or an import. Parts made after it,
standard parts and copies made with Paste or Paste New start free, so do parts made inside other
components. Any number of parts may be grounded, or none; opening a design never grounds
anything. A grounded part refuses Move until it is ungrounded, and `component.create` takes
`grounded: true` or `false` to choose for itself.
**Drag a part to put it somewhere else.** With the design active, press the left button on a part
and drag: the part follows the pointer, the point you grabbed moving in the plane through it that
faces the view, and stays where you let go, with its position captured. The whole drag is one
undo step, and Escape during the drag puts the part back. The drag moves the placement of the
active component that holds the part, so with the design active a part inside a subassembly
moves the whole subassembly; activate the subassembly to move the part inside it. Moving a
definition shared by several placements moves it in all of them, as Move does. A grounded part
does not move, and a part that joints hold to something grounded moves only as far as its joints
allow (below). Dragging any member of a chain joined to nothing grounded moves the whole chain,
preserving its joint values. Shared nested definitions move in every instance; the selected
instance follows the pointer even when its parent is rotated differently from the first one. A drag that starts on empty space, on a part that can't move, or
with Shift, Ctrl (Cmd) or Alt held draws a selection box instead. Other uncaptured moves stay
pending. Scripts and agents do the same with `occurrence.drag {occurrence or path, at, point}`,
which moves the placement by `point - at` in world coordinates and answers the placements it
`moved`.
Paste New copies nested component definitions, sketches, feature histories and generated
dimension parameters. Repeated child instances remain shared within the new copy. Materials,
@@ -185,8 +209,8 @@ picked in the browser, or on the first joint that moves when none is picked.
grabbed follows the pointer in the plane through it that faces the view, the joints on the
part's chain take the values that bring it nearest, within their limits, through motion links,
and with closed loops kept closed, and a four-bar's rocker stops at the end of its swing. The
whole drag is one undo step. A grounded part, or one no joint places, is not moved; a drag on
it draws a selection box as before. Each frame runs `joint.reach`, which scripts and agents use
whole drag is one undo step. A grounded part, or one its joints hold fixed, is not moved; a drag
on it draws a selection box. Each frame runs `joint.reach`, which scripts and agents use
directly to put a part's point somewhere: `joint.reach {occurrence, point}` moves the joints on
its chain from where they are to the nearest pose (the arm keeps its elbow up or down, and a
linkage stays on its branch). `at` picks the part's point (the centre of its bodies by
+1 -1
View File
@@ -229,7 +229,7 @@ One placed copy of a component inside its parent component.
A component can have several occurrences. Moving an occurrence moves only that copy; editing the
component changes every copy. The browser names occurrences with a number, such as `Bolt M20:3`.
- **In SolidCraft:** `occurrence.copy`, `occurrence.move`, `occurrence.ground`,
- **In SolidCraft:** `occurrence.copy`, `occurrence.move`, `occurrence.drag`, `occurrence.ground`,
`occurrence.properties`; the `occurrences` design-file key; the `path` of occurrence ids.
- **Don't use:** instance, placement.
- **Elsewhere:** occurrence, instance, component instance.
+16
View File
@@ -14,6 +14,14 @@ Properties accepts the leaf occurrence ID and the full path. Move can use world
{"occurrence":4,"path":[2,4],"space":"world","translate":[10,0,0],"capture":false}
```
A drag in the viewport, or `occurrence.drag`, moves one exact placement and its floating joint chain by a world translation:
```json
{"path":[2,4],"at":[0,0,10],"point":[20,0,10]}
```
It captures that placement's position (other pending positions stay pending) and is one undo step. With the design active, the viewport drags the placement on the picked body's path just inside the design; with a component placement active, the one just inside it. Grounded placements and placements that joints hold to something fixed are refused; a free chain of joints moves together, and a chain through a placement used several times is refused. The design's first top-level part is grounded when it is made (not when a design is opened); copies start free.
World movement includes pending parent and child positions. The default space remains parent-local for existing scripts. Capture Position commits pending transforms; Revert Position drops them. Copying an occurrence copies that selected occurrence's effective transform, including its pending position.
An occurrence definition inside a component is shared by every instance of that parent component. Moving, grounding, copying, or deleting that nested definition changes all its parent instances. Selecting its exact path determines the world frame used for movement and Properties; it does not create an independent child definition.
@@ -60,6 +68,14 @@ Use `sketch.redefine` with the sketch ID and a new plane to repair or convert an
Paste New remaps internal certified targets and authoring paths to the copied definitions. Timeline paste reports retained external face targets and refuses translating such attachments until an explicit fixed-plane conversion establishes independent geometry. Rename preserves certified body identity; another producer using the same body name cannot repair a lost attachment.
## Floating joint chains
Dragging any member of a floating joint chain carries the chain together without changing its
joint values. A chain joined to a grounded part still uses `joint.reach` within its joints.
Repeated nested definitions are shared: their other instances follow in their respective
parent frames. The selected exact path determines the local change, which is carried through
the solver's first-placement frame to jointed peers, including repeated peers.
## Change the size of a standard component
An inserted standard part is one component with an active catalogue configuration.
+1 -1
View File
@@ -26,7 +26,7 @@ Written against SolidCraft `main` after 0.11.1, which counts the degrees of free
1. **Components and grounding.**
- Bodies made in the root go into components with `component.create {"name":..., "parent":"root", "activate":false}`, then `component.move_bodies {"bodies":[...], "component":...}`.
- A part that moves in two pieces, such as an actuator's barrel and rod, becomes two components.
- Ground the base: `occurrence.ground {"occurrence":"Frame:1", "grounded":true}`. Occurrences are named `<component>:<n>`. Joint commands also take a component name (its first occurrence); `occurrence.ground` does not.
- Ground the base: `occurrence.ground {"occurrence":"Frame:1", "grounded":true}`. The design's first top-level part is grounded when it is made; check `joint.list` `fixed`, and unground it (`"grounded":false`) if it is not the base. A grounded part refuses `occurrence.move`. Occurrences are named `<component>:<n>`. Joint commands also take a component name (its first occurrence); `occurrence.ground` does not.
2. **Open-chain joints in one batch.** Read `occurrence.properties` of each moving occurrence before the batch and after it. If something moved, split the batch to find the joint.
3. **Each joint that closes a loop, in a call of its own.** Then check `conflicts` in its reply.
4. **Motion links.**