Compare commits

...

4 Commits

Author SHA1 Message Date
a947e23ef9 Merge branch 'main' into achalmers/extrude-in-batch 2024-04-11 15:30:55 -07:00
b3695c060d Unit test which draws 3 cubes 2024-04-09 16:46:39 -05:00
09374081ea Batch the Extrude, ObjectBringToFront and Solid3DGetExtrusionFaceInfo calls into one batch
This means sketching a cube takes 2 batches, not 1.
2024-04-09 15:19:10 -05:00
3d40650cab Debugging prints 2024-04-09 15:19:09 -05:00
7 changed files with 66 additions and 13 deletions

View File

@ -28,6 +28,16 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
id_to_source_range: std::collections::HashMap<uuid::Uuid, crate::executor::SourceRange>,
) -> Result<kittycad::types::OkWebSocketResponseData, crate::errors::KclError>;
fn push_to_batch(
&self,
cmd_id: uuid::Uuid,
source_range: crate::executor::SourceRange,
cmd: kittycad::types::ModelingCmd,
) {
let req = WebSocketRequest::ModelingCmdReq { cmd, cmd_id };
self.batch().lock().unwrap().push((req, source_range))
}
async fn send_modeling_cmd(
&self,
id: uuid::Uuid,
@ -94,7 +104,8 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
} else {
batched_requests
};
// println!("Running batch: {final_req:#?}");
// TODO: Uncomment this.
debug_batch(&final_req);
// Create the map of original command IDs to source range.
// This is for the wasm side, kurt needs it for selections.
@ -191,3 +202,18 @@ pub fn is_cmd_with_return_values(cmd: &kittycad::types::ModelingCmd) -> bool {
true
}
#[allow(dead_code)] // Only used in debugging.
fn debug_batch(msg: &WebSocketRequest) {
match msg {
WebSocketRequest::ModelingCmdReq { cmd, .. } => {
println!("[ {:?} ]", cmd);
}
WebSocketRequest::ModelingCmdBatchReq { requests, .. } => {
let names: Vec<_> = requests.iter().map(|req| format!("{:?}", req.cmd)).collect();
println!("[ {} ]", names.join(", "))
}
other => panic!("this isn't a modeling command or batch: {other:?}"),
}
}

View File

@ -38,15 +38,14 @@ async fn inner_extrude(length: f64, sketch_group: Box<SketchGroup>, args: Args)
let id = uuid::Uuid::new_v4();
// Extrude the element.
args.send_modeling_cmd(
args.push_to_batch(
id,
kittycad::types::ModelingCmd::Extrude {
target: sketch_group.id,
distance: length,
cap: true,
},
)
.await?;
);
do_post_extrude(sketch_group, length, id, args).await
}
@ -66,13 +65,12 @@ pub(crate) async fn do_post_extrude(
// Bring the object to the front of the scene.
// See: https://github.com/KittyCAD/modeling-app/issues/806
args.send_modeling_cmd(
args.push_to_batch(
uuid::Uuid::new_v4(),
kittycad::types::ModelingCmd::ObjectBringToFront {
object_id: sketch_group.id,
},
)
.await?;
);
if sketch_group.value.is_empty() {
return Err(KclError::Type(KclErrorDetails {

View File

@ -214,6 +214,10 @@ impl Args {
self.ctx.engine.send_modeling_cmd(id, self.source_range, cmd).await
}
pub fn push_to_batch(&self, id: uuid::Uuid, cmd: kittycad::types::ModelingCmd) {
self.ctx.engine.push_to_batch(id, self.source_range, cmd)
}
fn make_user_val_from_json(&self, j: serde_json::Value) -> Result<MemoryItem, KclError> {
Ok(MemoryItem::UserVal(crate::executor::UserVal {
value: j,

View File

@ -224,7 +224,7 @@ async fn inner_revolve(
match data.axis {
RevolveAxis::Axis(axis) => {
let (axis, origin) = axis.axis_and_origin()?;
args.send_modeling_cmd(
args.push_to_batch(
id,
ModelingCmd::Revolve {
angle,
@ -234,8 +234,7 @@ async fn inner_revolve(
tolerance: DEFAULT_TOLERANCE,
axis_is_2d: true,
},
)
.await?;
);
}
RevolveAxis::Edge(edge) => {
let edge_id = match edge {
@ -256,7 +255,7 @@ async fn inner_revolve(
.id
}
};
args.send_modeling_cmd(
args.push_to_batch(
id,
ModelingCmd::RevolveAboutEdge {
angle,
@ -264,8 +263,7 @@ async fn inner_revolve(
edge_id,
tolerance: DEFAULT_TOLERANCE,
},
)
.await?;
);
}
}

View File

@ -0,0 +1,18 @@
const width = 20
fn cube = (cx, cy) => {
let d = width/2
startSketchAt([cx-d, cy-d])
|> lineTo([cx+d, cy-d], %)
|> lineTo([cx+d, cy+d], %)
|> lineTo([cx-d, cy+d], %)
|> lineTo([cx-d, cy-d], %)
|> close(%)
|> extrude(width, %)
}
let interval = 30
cube(interval,interval)
cube(0,0)
cube(-interval,interval)

View File

@ -110,6 +110,15 @@ const part002 = startSketchOn(part001, "here")
twenty_twenty::assert_image("tests/executor/outputs/sketch_on_face.png", &result, 0.999);
}
#[tokio::test(flavor = "multi_thread")]
async fn serial_test_three_cubes() {
let code = include_str!("inputs/three_cubes.kcl");
let result = execute_and_snapshot(code, kittycad::types::UnitLength::Mm)
.await
.unwrap();
twenty_twenty::assert_image("tests/executor/outputs/three_cubes.png", &result, 0.999);
}
#[tokio::test(flavor = "multi_thread")]
async fn serial_test_riddle_small() {
let code = include_str!("inputs/riddle_small.kcl");

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB