Compare commits
4 Commits
remove-the
...
achalmers/
Author | SHA1 | Date | |
---|---|---|---|
a947e23ef9 | |||
b3695c060d | |||
09374081ea | |||
3d40650cab |
@ -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>,
|
id_to_source_range: std::collections::HashMap<uuid::Uuid, crate::executor::SourceRange>,
|
||||||
) -> Result<kittycad::types::OkWebSocketResponseData, crate::errors::KclError>;
|
) -> 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(
|
async fn send_modeling_cmd(
|
||||||
&self,
|
&self,
|
||||||
id: uuid::Uuid,
|
id: uuid::Uuid,
|
||||||
@ -94,7 +104,8 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
|
|||||||
} else {
|
} else {
|
||||||
batched_requests
|
batched_requests
|
||||||
};
|
};
|
||||||
// println!("Running batch: {final_req:#?}");
|
// TODO: Uncomment this.
|
||||||
|
debug_batch(&final_req);
|
||||||
|
|
||||||
// Create the map of original command IDs to source range.
|
// Create the map of original command IDs to source range.
|
||||||
// This is for the wasm side, kurt needs it for selections.
|
// 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
|
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:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -38,15 +38,14 @@ async fn inner_extrude(length: f64, sketch_group: Box<SketchGroup>, args: Args)
|
|||||||
let id = uuid::Uuid::new_v4();
|
let id = uuid::Uuid::new_v4();
|
||||||
|
|
||||||
// Extrude the element.
|
// Extrude the element.
|
||||||
args.send_modeling_cmd(
|
args.push_to_batch(
|
||||||
id,
|
id,
|
||||||
kittycad::types::ModelingCmd::Extrude {
|
kittycad::types::ModelingCmd::Extrude {
|
||||||
target: sketch_group.id,
|
target: sketch_group.id,
|
||||||
distance: length,
|
distance: length,
|
||||||
cap: true,
|
cap: true,
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
.await?;
|
|
||||||
|
|
||||||
do_post_extrude(sketch_group, length, id, args).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.
|
// Bring the object to the front of the scene.
|
||||||
// See: https://github.com/KittyCAD/modeling-app/issues/806
|
// See: https://github.com/KittyCAD/modeling-app/issues/806
|
||||||
args.send_modeling_cmd(
|
args.push_to_batch(
|
||||||
uuid::Uuid::new_v4(),
|
uuid::Uuid::new_v4(),
|
||||||
kittycad::types::ModelingCmd::ObjectBringToFront {
|
kittycad::types::ModelingCmd::ObjectBringToFront {
|
||||||
object_id: sketch_group.id,
|
object_id: sketch_group.id,
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
.await?;
|
|
||||||
|
|
||||||
if sketch_group.value.is_empty() {
|
if sketch_group.value.is_empty() {
|
||||||
return Err(KclError::Type(KclErrorDetails {
|
return Err(KclError::Type(KclErrorDetails {
|
||||||
|
@ -214,6 +214,10 @@ impl Args {
|
|||||||
self.ctx.engine.send_modeling_cmd(id, self.source_range, cmd).await
|
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> {
|
fn make_user_val_from_json(&self, j: serde_json::Value) -> Result<MemoryItem, KclError> {
|
||||||
Ok(MemoryItem::UserVal(crate::executor::UserVal {
|
Ok(MemoryItem::UserVal(crate::executor::UserVal {
|
||||||
value: j,
|
value: j,
|
||||||
|
@ -224,7 +224,7 @@ async fn inner_revolve(
|
|||||||
match data.axis {
|
match data.axis {
|
||||||
RevolveAxis::Axis(axis) => {
|
RevolveAxis::Axis(axis) => {
|
||||||
let (axis, origin) = axis.axis_and_origin()?;
|
let (axis, origin) = axis.axis_and_origin()?;
|
||||||
args.send_modeling_cmd(
|
args.push_to_batch(
|
||||||
id,
|
id,
|
||||||
ModelingCmd::Revolve {
|
ModelingCmd::Revolve {
|
||||||
angle,
|
angle,
|
||||||
@ -234,8 +234,7 @@ async fn inner_revolve(
|
|||||||
tolerance: DEFAULT_TOLERANCE,
|
tolerance: DEFAULT_TOLERANCE,
|
||||||
axis_is_2d: true,
|
axis_is_2d: true,
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
RevolveAxis::Edge(edge) => {
|
RevolveAxis::Edge(edge) => {
|
||||||
let edge_id = match edge {
|
let edge_id = match edge {
|
||||||
@ -256,7 +255,7 @@ async fn inner_revolve(
|
|||||||
.id
|
.id
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
args.send_modeling_cmd(
|
args.push_to_batch(
|
||||||
id,
|
id,
|
||||||
ModelingCmd::RevolveAboutEdge {
|
ModelingCmd::RevolveAboutEdge {
|
||||||
angle,
|
angle,
|
||||||
@ -264,8 +263,7 @@ async fn inner_revolve(
|
|||||||
edge_id,
|
edge_id,
|
||||||
tolerance: DEFAULT_TOLERANCE,
|
tolerance: DEFAULT_TOLERANCE,
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
src/wasm-lib/tests/executor/inputs/three_cubes.kcl
Normal file
18
src/wasm-lib/tests/executor/inputs/three_cubes.kcl
Normal 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)
|
||||||
|
|
@ -110,6 +110,15 @@ const part002 = startSketchOn(part001, "here")
|
|||||||
twenty_twenty::assert_image("tests/executor/outputs/sketch_on_face.png", &result, 0.999);
|
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")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn serial_test_riddle_small() {
|
async fn serial_test_riddle_small() {
|
||||||
let code = include_str!("inputs/riddle_small.kcl");
|
let code = include_str!("inputs/riddle_small.kcl");
|
||||||
|
BIN
src/wasm-lib/tests/executor/outputs/three_cubes.png
Normal file
BIN
src/wasm-lib/tests/executor/outputs/three_cubes.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 116 KiB |
Reference in New Issue
Block a user