diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Draft-segments-should-look-right-3-Google-Chrome-linux.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Draft-segments-should-look-right-3-Google-Chrome-linux.png index fe961f431..06a2716a3 100644 Binary files a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Draft-segments-should-look-right-3-Google-Chrome-linux.png and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Draft-segments-should-look-right-3-Google-Chrome-linux.png differ diff --git a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Draft-segments-should-look-right-4-Google-Chrome-linux.png b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Draft-segments-should-look-right-4-Google-Chrome-linux.png index 2b782ba28..6aa1e34f3 100644 Binary files a/e2e/playwright/snapshot-tests.spec.ts-snapshots/Draft-segments-should-look-right-4-Google-Chrome-linux.png and b/e2e/playwright/snapshot-tests.spec.ts-snapshots/Draft-segments-should-look-right-4-Google-Chrome-linux.png differ diff --git a/public/kcl-samples/screenshots/ball-joint-rod-end.png b/public/kcl-samples/screenshots/ball-joint-rod-end.png index 1c268856a..d9c2a0650 100644 Binary files a/public/kcl-samples/screenshots/ball-joint-rod-end.png and b/public/kcl-samples/screenshots/ball-joint-rod-end.png differ diff --git a/rust/kcl-lib/src/std/extrude.rs b/rust/kcl-lib/src/std/extrude.rs index 0277a75a7..f40752f4c 100644 --- a/rust/kcl-lib/src/std/extrude.rs +++ b/rust/kcl-lib/src/std/extrude.rs @@ -175,10 +175,10 @@ pub(crate) async fn do_post_extrude<'a>( ) .await?; - let any_edge_id = if let Some(id) = edge_id { - id - } else if let Some(edge_id) = sketch.mirror { + let any_edge_id = if let Some(edge_id) = sketch.mirror { edge_id + } else if let Some(id) = edge_id { + id } else { // The "get extrusion face info" API call requires *any* edge on the sketch being extruded. // So, let's just use the first one. diff --git a/rust/kcl-lib/src/std/mirror.rs b/rust/kcl-lib/src/std/mirror.rs index 9ec83b032..f27e55b46 100644 --- a/rust/kcl-lib/src/std/mirror.rs +++ b/rust/kcl-lib/src/std/mirror.rs @@ -3,8 +3,8 @@ use anyhow::Result; use kcmc::{each_cmd as mcmd, ModelingCmd}; use kittycad_modeling_cmds::{ - self as kcmc, length_unit::LengthUnit, ok_response::OkModelingCmdResponse, output::EntityGetAllChildUuids, - shared::Point3d, websocket::OkWebSocketResponseData, + self as kcmc, length_unit::LengthUnit, ok_response::OkModelingCmdResponse, shared::Point3d, + websocket::OkWebSocketResponseData, }; use crate::{ @@ -41,19 +41,14 @@ async fn inner_mirror_2d( ) -> Result, KclError> { let mut starting_sketches = sketches.clone(); - // Update all to have a mirror. - starting_sketches.iter_mut().for_each(|sketch| { - sketch.mirror = Some(exec_state.next_uuid()); - }); - if args.ctx.no_engine_commands().await { return Ok(starting_sketches); } match axis { Axis2dOrEdgeReference::Axis { direction, origin } => { - exec_state - .batch_modeling_cmd( + let resp = exec_state + .send_modeling_cmd( (&args).into(), ModelingCmd::from(mcmd::EntityMirror { ids: starting_sketches.iter().map(|sketch| sketch.id).collect(), @@ -70,12 +65,42 @@ async fn inner_mirror_2d( }), ) .await?; + + if let OkWebSocketResponseData::Modeling { + modeling_response: OkModelingCmdResponse::EntityMirror(mirror_info), + } = &resp + { + let face_edge_info = &mirror_info.entity_face_edge_ids; + + starting_sketches + .iter_mut() + .zip(face_edge_info.iter()) + .try_for_each(|(sketch, info)| { + sketch.id = info.object_id; + let first_edge = info.edges.first().copied(); + match first_edge { + Some(edge) => sketch.mirror = Some(edge), + None => { + return Err(KclError::new_engine(KclErrorDetails::new( + "No edges found in mirror info".to_string(), + vec![args.source_range], + ))) + } + } + Ok(()) + })?; + } else { + return Err(KclError::new_engine(KclErrorDetails::new( + format!("EntityMirror response was not as expected: {:?}", resp), + vec![args.source_range], + ))); + }; } Axis2dOrEdgeReference::Edge(edge) => { let edge_id = edge.get_engine_id(exec_state, &args)?; - exec_state - .batch_modeling_cmd( + let resp = exec_state + .send_modeling_cmd( (&args).into(), ModelingCmd::from(mcmd::EntityMirrorAcrossEdge { ids: starting_sketches.iter().map(|sketch| sketch.id).collect(), @@ -83,41 +108,36 @@ async fn inner_mirror_2d( }), ) .await?; - } - }; - // After the mirror, get the first child uuid for the path. - // The "get extrusion face info" API call requires *any* edge on the sketch being extruded. - // But if you mirror2d a sketch these IDs might change so we need to get the children versus - // using the IDs we already have. - // We only do this with mirrors because otherwise it is a waste of a websocket call. - for sketch in &mut starting_sketches { - let response = exec_state - .send_modeling_cmd( - (&args).into(), - ModelingCmd::from(mcmd::EntityGetAllChildUuids { entity_id: sketch.id }), - ) - .await?; - let OkWebSocketResponseData::Modeling { - modeling_response: - OkModelingCmdResponse::EntityGetAllChildUuids(EntityGetAllChildUuids { entity_ids: child_ids }), - } = response - else { - return Err(KclError::new_internal(KclErrorDetails::new( - "Expected a successful response from EntityGetAllChildUuids".to_string(), - vec![args.source_range], - ))); - }; + if let OkWebSocketResponseData::Modeling { + modeling_response: OkModelingCmdResponse::EntityMirrorAcrossEdge(mirror_info), + } = &resp + { + let face_edge_info = &mirror_info.entity_face_edge_ids; - if child_ids.len() >= 2 { - // The first child is the original sketch, the second is the mirrored sketch. - let child_id = child_ids[1]; - sketch.mirror = Some(child_id); - } else { - return Err(KclError::new_type(KclErrorDetails::new( - "Expected child uuids to be >= 2".to_string(), - vec![args.source_range], - ))); + starting_sketches + .iter_mut() + .zip(face_edge_info.iter()) + .try_for_each(|(sketch, info)| { + sketch.id = info.object_id; + let first_edge = info.edges.first().copied(); + match first_edge { + Some(edge) => sketch.mirror = Some(edge), + None => { + return Err(KclError::new_engine(KclErrorDetails::new( + "No edges found in mirror info".to_string(), + vec![args.source_range], + ))) + } + } + Ok(()) + })?; + } else { + return Err(KclError::new_engine(KclErrorDetails::new( + format!("EntityMirrorAcrossEdge response was not as expected: {:?}", resp), + vec![args.source_range], + ))); + }; } } diff --git a/rust/kcl-lib/tests/kcl_samples/ball-joint-rod-end/rendered_model.png b/rust/kcl-lib/tests/kcl_samples/ball-joint-rod-end/rendered_model.png index 1c268856a..d9c2a0650 100644 Binary files a/rust/kcl-lib/tests/kcl_samples/ball-joint-rod-end/rendered_model.png and b/rust/kcl-lib/tests/kcl_samples/ball-joint-rod-end/rendered_model.png differ diff --git a/rust/kcl-lib/tests/kcl_samples/bottle/artifact_commands.snap b/rust/kcl-lib/tests/kcl_samples/bottle/artifact_commands.snap index 6afc00c64..b6d573455 100644 --- a/rust/kcl-lib/tests/kcl_samples/bottle/artifact_commands.snap +++ b/rust/kcl-lib/tests/kcl_samples/bottle/artifact_commands.snap @@ -148,14 +148,6 @@ description: Artifact commands bottle.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], diff --git a/rust/kcl-lib/tests/kcl_samples/cold-plate/artifact_commands.snap b/rust/kcl-lib/tests/kcl_samples/cold-plate/artifact_commands.snap index 7c5e9c41c..2cd11f782 100644 --- a/rust/kcl-lib/tests/kcl_samples/cold-plate/artifact_commands.snap +++ b/rust/kcl-lib/tests/kcl_samples/cold-plate/artifact_commands.snap @@ -327,14 +327,6 @@ description: Artifact commands cold-plate.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], diff --git a/rust/kcl-lib/tests/kcl_samples/cpu-cooler/artifact_commands.snap b/rust/kcl-lib/tests/kcl_samples/cpu-cooler/artifact_commands.snap index 0afd79ce1..6f9113f7f 100644 --- a/rust/kcl-lib/tests/kcl_samples/cpu-cooler/artifact_commands.snap +++ b/rust/kcl-lib/tests/kcl_samples/cpu-cooler/artifact_commands.snap @@ -4828,14 +4828,6 @@ description: Artifact commands cpu-cooler.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], @@ -4856,14 +4848,6 @@ description: Artifact commands cpu-cooler.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], @@ -6095,14 +6079,6 @@ description: Artifact commands cpu-cooler.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], @@ -6436,14 +6412,6 @@ description: Artifact commands cpu-cooler.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], diff --git a/rust/kcl-lib/tests/kcl_samples/helium-tank/artifact_commands.snap b/rust/kcl-lib/tests/kcl_samples/helium-tank/artifact_commands.snap index 7bb66a105..7fe7d23e5 100644 --- a/rust/kcl-lib/tests/kcl_samples/helium-tank/artifact_commands.snap +++ b/rust/kcl-lib/tests/kcl_samples/helium-tank/artifact_commands.snap @@ -1136,14 +1136,6 @@ description: Artifact commands helium-tank.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], @@ -1362,14 +1354,6 @@ description: Artifact commands helium-tank.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], diff --git a/rust/kcl-lib/tests/kcl_samples/i-beam/artifact_commands.snap b/rust/kcl-lib/tests/kcl_samples/i-beam/artifact_commands.snap index 7401134da..a24c84307 100644 --- a/rust/kcl-lib/tests/kcl_samples/i-beam/artifact_commands.snap +++ b/rust/kcl-lib/tests/kcl_samples/i-beam/artifact_commands.snap @@ -176,14 +176,6 @@ description: Artifact commands i-beam.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], @@ -204,14 +196,6 @@ description: Artifact commands i-beam.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], diff --git a/rust/kcl-lib/tests/kcl_samples/t-slot-rail/artifact_commands.snap b/rust/kcl-lib/tests/kcl_samples/t-slot-rail/artifact_commands.snap index 2c1add90a..135a28b66 100644 --- a/rust/kcl-lib/tests/kcl_samples/t-slot-rail/artifact_commands.snap +++ b/rust/kcl-lib/tests/kcl_samples/t-slot-rail/artifact_commands.snap @@ -342,14 +342,6 @@ description: Artifact commands t-slot-rail.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], @@ -370,14 +362,6 @@ description: Artifact commands t-slot-rail.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], @@ -398,14 +382,6 @@ description: Artifact commands t-slot-rail.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], diff --git a/rust/kcl-lib/tests/subtract_regression10/artifact_commands.snap b/rust/kcl-lib/tests/subtract_regression10/artifact_commands.snap index 75cc10f13..edc11c367 100644 --- a/rust/kcl-lib/tests/subtract_regression10/artifact_commands.snap +++ b/rust/kcl-lib/tests/subtract_regression10/artifact_commands.snap @@ -1170,14 +1170,6 @@ description: Artifact commands subtract_regression10.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], @@ -1639,14 +1631,6 @@ description: Artifact commands subtract_regression10.kcl "edge_id": "[uuid]" } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [], @@ -1895,14 +1879,6 @@ description: Artifact commands subtract_regression10.kcl } } }, - { - "cmdId": "[uuid]", - "range": [], - "command": { - "type": "entity_get_all_child_uuids", - "entity_id": "[uuid]" - } - }, { "cmdId": "[uuid]", "range": [],