fix edge cuts & clone (#6572)
* fix edge cuts & clone Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix edge_id Signed-off-by: Jess Frazelle <github@jessfraz.com> * code comemnt Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -301,6 +301,9 @@ async fn inner_clone(
|
||||
GeometryWithImportedGeometry::Sketch(new_sketch)
|
||||
}
|
||||
GeometryWithImportedGeometry::Solid(solid) => {
|
||||
// We flush before the clone so all the shit exists.
|
||||
args.flush_batch_for_solids(exec_state, &[solid.clone()]).await?;
|
||||
|
||||
let mut new_solid = solid.clone();
|
||||
new_solid.id = new_id;
|
||||
new_solid.sketch.original_id = new_id;
|
||||
@ -361,17 +364,19 @@ async fn fix_tags_and_references(
|
||||
|
||||
// Fix the edge cuts.
|
||||
for edge_cut in solid.edge_cuts.iter_mut() {
|
||||
let Some(new_edge_id) = entity_id_map.get(&edge_cut.edge_id()) else {
|
||||
anyhow::bail!("Failed to find new edge id for old edge id: {:?}", edge_cut.edge_id());
|
||||
};
|
||||
edge_cut.set_edge_id(*new_edge_id);
|
||||
let Some(id) = entity_id_map.get(&edge_cut.id()) else {
|
||||
anyhow::bail!(
|
||||
if let Some(id) = entity_id_map.get(&edge_cut.id()) {
|
||||
edge_cut.set_id(*id);
|
||||
} else {
|
||||
crate::log::logln!(
|
||||
"Failed to find new edge cut id for old edge cut id: {:?}",
|
||||
edge_cut.id()
|
||||
);
|
||||
};
|
||||
edge_cut.set_id(*id);
|
||||
}
|
||||
if let Some(new_edge_id) = entity_id_map.get(&edge_cut.edge_id()) {
|
||||
edge_cut.set_edge_id(*new_edge_id);
|
||||
} else {
|
||||
crate::log::logln!("Failed to find new edge id for old edge id: {:?}", edge_cut.edge_id());
|
||||
}
|
||||
}
|
||||
|
||||
// Do the after extrude things to update those ids, based on the new sketch
|
||||
@ -462,10 +467,13 @@ async fn fix_sketch_tags_and_references(
|
||||
) -> Result<()> {
|
||||
// Fix the path references in the sketch.
|
||||
for path in new_sketch.paths.as_mut_slice() {
|
||||
let Some(new_path_id) = entity_id_map.get(&path.get_id()) else {
|
||||
anyhow::bail!("Failed to find new path id for old path id: {:?}", path.get_id());
|
||||
};
|
||||
path.set_id(*new_path_id);
|
||||
if let Some(new_path_id) = entity_id_map.get(&path.get_id()) {
|
||||
path.set_id(*new_path_id);
|
||||
} else {
|
||||
// We log on these because we might have already flushed and the id is no longer
|
||||
// relevant since filleted or something.
|
||||
crate::log::logln!("Failed to find new path id for old path id: {:?}", path.get_id());
|
||||
}
|
||||
}
|
||||
|
||||
// Fix the tags
|
||||
@ -479,14 +487,14 @@ async fn fix_sketch_tags_and_references(
|
||||
}
|
||||
|
||||
// Fix the base path.
|
||||
// TODO: Right now this one does not work, ignore for now and see if we really need it.
|
||||
/* let Some(new_base_path) = entity_id_map.get(&new_sketch.start.geo_meta.id) else {
|
||||
anyhow::bail!(
|
||||
if let Some(new_base_path) = entity_id_map.get(&new_sketch.start.geo_meta.id) {
|
||||
new_sketch.start.geo_meta.id = *new_base_path;
|
||||
} else {
|
||||
crate::log::logln!(
|
||||
"Failed to find new base path id for old base path id: {:?}",
|
||||
new_sketch.start.geo_meta.id
|
||||
);
|
||||
};
|
||||
new_sketch.start.geo_meta.id = *new_base_path;*/
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -845,7 +853,6 @@ clonedCube = clone(cube)
|
||||
// references.
|
||||
// WITH TAGS AND EDGE CUTS.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[ignore = "this test is not working yet, need to fix the edge cut ids"]
|
||||
async fn kcl_test_clone_solid_with_edge_cuts() {
|
||||
let code = r#"cube = startSketchOn(XY)
|
||||
|> startProfile(at = [0,0]) // tag this one
|
||||
@ -913,28 +920,11 @@ clonedCube = clone(cube)
|
||||
#[cfg(feature = "artifact-graph")]
|
||||
assert_eq!(cloned_cube.artifact_id, cloned_cube.id.into());
|
||||
|
||||
for (path, cloned_path) in cube.sketch.paths.iter().zip(cloned_cube.sketch.paths.iter()) {
|
||||
assert_ne!(path.get_id(), cloned_path.get_id());
|
||||
assert_eq!(path.get_tag(), cloned_path.get_tag());
|
||||
}
|
||||
|
||||
for (value, cloned_value) in cube.value.iter().zip(cloned_cube.value.iter()) {
|
||||
assert_ne!(value.get_id(), cloned_value.get_id());
|
||||
assert_eq!(value.get_tag(), cloned_value.get_tag());
|
||||
}
|
||||
|
||||
for (tag_name, tag) in &cube.sketch.tags {
|
||||
let cloned_tag = cloned_cube.sketch.tags.get(tag_name).unwrap();
|
||||
|
||||
let tag_info = tag.get_cur_info().unwrap();
|
||||
let cloned_tag_info = cloned_tag.get_cur_info().unwrap();
|
||||
|
||||
assert_ne!(tag_info.id, cloned_tag_info.id);
|
||||
assert_ne!(tag_info.sketch, cloned_tag_info.sketch);
|
||||
assert_ne!(tag_info.path, cloned_tag_info.path);
|
||||
assert_ne!(tag_info.surface, cloned_tag_info.surface);
|
||||
}
|
||||
|
||||
for (edge_cut, cloned_edge_cut) in cube.edge_cuts.iter().zip(cloned_cube.edge_cuts.iter()) {
|
||||
assert_ne!(edge_cut.id(), cloned_edge_cut.id());
|
||||
assert_ne!(edge_cut.edge_id(), cloned_edge_cut.edge_id());
|
||||
|
Reference in New Issue
Block a user