This commit is contained in:
1 parent
4b8872e4d0
commit
f06b76e14f
4 files changed
+49
-22
No files matched your search
@@ -453,26 +453,15 @@ fn add_feature_in(s: &mut Session, p: &Value, kind: FeatureKind, world: bool) ->
|
||||
s.active_sketch = None;
|
||||
s.refresh();
|
||||
// A feature that makes more bodies than it was given names (a multi-profile extrude with one
|
||||
// `body_name`) names the rest after the first: `Ribs`, `Ribs (2)`, `Ribs (3)`… (#266). The
|
||||
// names are stored on the feature, so recomputes and saved designs keep them.
|
||||
if let Some(base) = names.first().map(|n| n.trim().to_string()).filter(|n| !n.is_empty()) {
|
||||
let st = s.model.state();
|
||||
let made = st.bodies.iter().filter(|b| b.feature == id).count();
|
||||
if made > names.len() {
|
||||
let mut taken: std::collections::BTreeSet<String> = st.bodies.iter().map(|b| b.name.clone()).collect();
|
||||
taken.extend(names.iter().cloned());
|
||||
let mut i = 1usize;
|
||||
while names.len() < made {
|
||||
i += 1;
|
||||
let n = format!("{base} ({i})");
|
||||
if taken.insert(n.clone()) {
|
||||
names.push(n);
|
||||
}
|
||||
}
|
||||
if let Some(f) = s.doc_mut().feature_mut(id) {
|
||||
f.body_names = names;
|
||||
}
|
||||
s.refresh();
|
||||
// `body_name`) has the rest numbered after the first by the evaluator: `Ribs`, `Ribs (2)`,
|
||||
// `Ribs (3)`… (#266, #373). They are stored on the feature, so recomputes and saved designs
|
||||
// keep them even when the profiles are later picked in another order.
|
||||
if names.first().is_some_and(|n| !n.trim().is_empty()) {
|
||||
let made: Vec<String> = s.model.state().bodies.iter().filter(|b| b.feature == id).map(|b| b.name.clone()).collect();
|
||||
if made.len() > names.len()
|
||||
&& let Some(f) = s.doc_mut().feature_mut(id)
|
||||
{
|
||||
f.body_names = made;
|
||||
}
|
||||
}
|
||||
let r = s.model.result(id).cloned();
|
||||
|
||||
@@ -2735,7 +2735,6 @@ fn raising_a_pattern_count_after_a_rename_numbers_the_new_copy_after_the_others(
|
||||
/// A profile added to the sketch after a named multi-profile extrude is named after `body_name`
|
||||
/// too (#373).
|
||||
#[test]
|
||||
#[ignore = "fails until #373 is fixed"]
|
||||
fn a_profile_added_later_is_named_after_body_name() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "sketch.create", json!({"plane": "XY", "name": "R"}));
|
||||
@@ -2765,3 +2764,29 @@ fn extrude_reply_lists_the_bodies_it_created() {
|
||||
let r = run(&mut s, "solid.extrude", json!({"sketch": "R", "distance": "10", "operation": "new_body", "body_name": "Ribs"}));
|
||||
assert_eq!(r["created_bodies"], json!(["Ribs", "Ribs (2)", "Ribs (3)"]), "{r}");
|
||||
}
|
||||
|
||||
/// A design saved before format 14 names the bodies past its stored names `BodyN`, as it did when
|
||||
/// it was saved, so later features that name them still find them (#373).
|
||||
#[test]
|
||||
fn a_design_saved_before_format_14_keeps_generic_names_past_body_name() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "sketch.create", json!({"plane": "XY", "name": "R"}));
|
||||
for x in [0, 10, 20] {
|
||||
run(&mut s, "sketch.rectangle.two_point", json!({"p0": [x, 0], "p1": [x + 5, 30]}));
|
||||
}
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
run(&mut s, "solid.extrude", json!({"sketch": "R", "distance": "10", "operation": "new_body", "body_name": "Ribs"}));
|
||||
let mut legacy: Value = serde_json::from_str(&s.doc.to_json()).unwrap();
|
||||
legacy["format"] = json!("solvecraft/13");
|
||||
let extrude = legacy["features"].as_array_mut().unwrap().iter_mut().find(|f| f["type"] == "extrude").unwrap();
|
||||
extrude["body_names"] = json!(["Ribs"]);
|
||||
let dir = std::env::temp_dir().join(format!("solvecraft-373-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let design = dir.join("ribs.solvecraft");
|
||||
std::fs::write(&design, legacy.to_string()).unwrap();
|
||||
let mut old = Session::default();
|
||||
run(&mut old, "doc.open", json!({"path": design.to_string_lossy()}));
|
||||
let names: Vec<String> = old.model.state().bodies.iter().map(|b| b.name.clone()).collect();
|
||||
assert_eq!(names, ["Ribs", "Body1", "Body2"]);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
Reference in new issue
Block a user