Skip to content

Commit

Permalink
change to index map, re-fmt, and fillet face id
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <[email protected]>
  • Loading branch information
jessfraz committed Sep 19, 2024
1 parent 4285e81 commit 2025b72
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 100 deletions.
16 changes: 9 additions & 7 deletions src/wasm-lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/wasm-lib/kcl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ git_rev = "0.1.0"
gltf-json = "1.4.1"
http = { workspace = true }
image = { version = "0.25.1", default-features = false, features = ["png"] }
indexmap = { version = "2.5.0", features = ["serde"] }
kittycad = { workspace = true }
kittycad-modeling-cmds = { workspace = true }
lazy_static = "1.5.0"
Expand Down
9 changes: 4 additions & 5 deletions src/wasm-lib/kcl/src/ast/modify.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::sync::Arc;

use kcmc::each_cmd as mcmd;
use kcmc::ok_response::OkModelingCmdResponse;
use kcmc::shared::PathCommand;
use kcmc::websocket::OkWebSocketResponseData;
use kcmc::ModelingCmd;
use kcmc::{
each_cmd as mcmd, ok_response::OkModelingCmdResponse, shared::PathCommand, websocket::OkWebSocketResponseData,
ModelingCmd,
};
use kittycad_modeling_cmds as kcmc;

use crate::{
Expand Down
22 changes: 11 additions & 11 deletions src/wasm-lib/kcl/src/engine/conn.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//! Functions for setting up our WebSocket and WebRTC connections for communications with the
//! engine.

use std::{
collections::HashMap,
sync::{Arc, Mutex},
};
use std::sync::{Arc, Mutex};

use anyhow::{anyhow, Result};
use dashmap::DashMap;
use futures::{SinkExt, StreamExt};
use kcmc::websocket::{
BatchResponse, FailureWebSocketResponse, ModelingCmdReq, ModelingSessionData, OkWebSocketResponseData,
SuccessWebSocketResponse, WebSocketRequest, WebSocketResponse,
use indexmap::IndexMap;
use kcmc::{
websocket::{
BatchResponse, FailureWebSocketResponse, ModelingCmdReq, ModelingSessionData, OkWebSocketResponseData,
SuccessWebSocketResponse, WebSocketRequest, WebSocketResponse,
},
ModelingCmd,
};
use kcmc::ModelingCmd;
use kittycad_modeling_cmds as kcmc;
use tokio::sync::{mpsc, oneshot, RwLock};
use tokio_tungstenite::tungstenite::Message as WsMsg;
Expand All @@ -39,7 +39,7 @@ pub struct EngineConnection {
tcp_read_handle: Arc<TcpReadHandle>,
socket_health: Arc<Mutex<SocketHealth>>,
batch: Arc<Mutex<Vec<(WebSocketRequest, crate::executor::SourceRange)>>>,
batch_end: Arc<Mutex<HashMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>>,
batch_end: Arc<Mutex<IndexMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>>,

/// The default planes for the scene.
default_planes: Arc<RwLock<Option<DefaultPlanes>>>,
Expand Down Expand Up @@ -269,7 +269,7 @@ impl EngineConnection {
responses,
socket_health,
batch: Arc::new(Mutex::new(Vec::new())),
batch_end: Arc::new(Mutex::new(HashMap::new())),
batch_end: Arc::new(Mutex::new(IndexMap::new())),
default_planes: Default::default(),
session_data,
})
Expand All @@ -282,7 +282,7 @@ impl EngineManager for EngineConnection {
self.batch.clone()
}

fn batch_end(&self) -> Arc<Mutex<HashMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>> {
fn batch_end(&self) -> Arc<Mutex<IndexMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>> {
self.batch_end.clone()
}

Expand Down
17 changes: 10 additions & 7 deletions src/wasm-lib/kcl/src/engine/conn_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ use std::{
};

use anyhow::Result;
use kcmc::ok_response::OkModelingCmdResponse;
use kcmc::websocket::{
BatchResponse, ModelingBatch, OkWebSocketResponseData, SuccessWebSocketResponse, WebSocketRequest,
WebSocketResponse,
use indexmap::IndexMap;
use kcmc::{
ok_response::OkModelingCmdResponse,
websocket::{
BatchResponse, ModelingBatch, OkWebSocketResponseData, SuccessWebSocketResponse, WebSocketRequest,
WebSocketResponse,
},
};
use kittycad_modeling_cmds::{self as kcmc};

Expand All @@ -19,14 +22,14 @@ use crate::{errors::KclError, executor::DefaultPlanes};
#[derive(Debug, Clone)]
pub struct EngineConnection {
batch: Arc<Mutex<Vec<(WebSocketRequest, crate::executor::SourceRange)>>>,
batch_end: Arc<Mutex<HashMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>>,
batch_end: Arc<Mutex<IndexMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>>,
}

impl EngineConnection {
pub async fn new() -> Result<EngineConnection> {
Ok(EngineConnection {
batch: Arc::new(Mutex::new(Vec::new())),
batch_end: Arc::new(Mutex::new(HashMap::new())),
batch_end: Arc::new(Mutex::new(IndexMap::new())),
})
}
}
Expand All @@ -37,7 +40,7 @@ impl crate::engine::EngineManager for EngineConnection {
self.batch.clone()
}

fn batch_end(&self) -> Arc<Mutex<HashMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>> {
fn batch_end(&self) -> Arc<Mutex<IndexMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>> {
self.batch_end.clone()
}

Expand Down
7 changes: 4 additions & 3 deletions src/wasm-lib/kcl/src/engine/conn_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
};

use anyhow::Result;
use indexmap::IndexMap;
use kcmc::websocket::{WebSocketRequest, WebSocketResponse};
use kittycad_modeling_cmds as kcmc;
use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -43,7 +44,7 @@ extern "C" {
pub struct EngineConnection {
manager: Arc<EngineCommandManager>,
batch: Arc<Mutex<Vec<(WebSocketRequest, crate::executor::SourceRange)>>>,
batch_end: Arc<Mutex<HashMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>>,
batch_end: Arc<Mutex<IndexMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>>,
}

// Safety: WebAssembly will only ever run in a single-threaded context.
Expand All @@ -55,7 +56,7 @@ impl EngineConnection {
Ok(EngineConnection {
manager: Arc::new(manager),
batch: Arc::new(Mutex::new(Vec::new())),
batch_end: Arc::new(Mutex::new(HashMap::new())),
batch_end: Arc::new(Mutex::new(IndexMap::new())),
})
}
}
Expand All @@ -66,7 +67,7 @@ impl crate::engine::EngineManager for EngineConnection {
self.batch.clone()
}

fn batch_end(&self) -> Arc<Mutex<HashMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>> {
fn batch_end(&self) -> Arc<Mutex<IndexMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>> {
self.batch_end.clone()
}

Expand Down
21 changes: 12 additions & 9 deletions src/wasm-lib/kcl/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ use std::{
sync::{Arc, Mutex},
};

use kcmc::each_cmd as mcmd;
use kcmc::length_unit::LengthUnit;
use kcmc::ok_response::OkModelingCmdResponse;
use kcmc::shared::Color;
use kcmc::websocket::ModelingBatch;
use kcmc::websocket::{
BatchResponse, ModelingCmdReq, ModelingSessionData, OkWebSocketResponseData, WebSocketRequest, WebSocketResponse,
use indexmap::IndexMap;
use kcmc::{
each_cmd as mcmd,
length_unit::LengthUnit,
ok_response::OkModelingCmdResponse,
shared::Color,
websocket::{
BatchResponse, ModelingBatch, ModelingCmdReq, ModelingSessionData, OkWebSocketResponseData, WebSocketRequest,
WebSocketResponse,
},
ModelingCmd,
};
use kcmc::ModelingCmd;
use kittycad_modeling_cmds as kcmc;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -44,7 +47,7 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
fn batch(&self) -> Arc<Mutex<Vec<(WebSocketRequest, crate::executor::SourceRange)>>>;

/// Get the batch of end commands to be sent to the engine.
fn batch_end(&self) -> Arc<Mutex<HashMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>>;
fn batch_end(&self) -> Arc<Mutex<IndexMap<uuid::Uuid, (WebSocketRequest, crate::executor::SourceRange)>>>;

/// Get the default planes.
async fn default_planes(
Expand Down
10 changes: 6 additions & 4 deletions src/wasm-lib/kcl/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use std::{collections::HashMap, sync::Arc};

use anyhow::Result;
use async_recursion::async_recursion;
use kcmc::each_cmd as mcmd;
use kcmc::ok_response::{output::TakeSnapshot, OkModelingCmdResponse};
use kcmc::websocket::{ModelingSessionData, OkWebSocketResponseData};
use kcmc::{ImageFormat, ModelingCmd};
use kcmc::{
each_cmd as mcmd,
ok_response::{output::TakeSnapshot, OkModelingCmdResponse},
websocket::{ModelingSessionData, OkWebSocketResponseData},
ImageFormat, ModelingCmd,
};
use kittycad_modeling_cmds as kcmc;
use kittycad_modeling_cmds::length_unit::LengthUnit;
use parse_display::{Display, FromStr};
Expand Down
5 changes: 2 additions & 3 deletions src/wasm-lib/kcl/src/std/args.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::any::type_name;

use anyhow::Result;
use kcmc::websocket::OkWebSocketResponseData;
use kcmc::ModelingCmd;
use kcmc::{websocket::OkWebSocketResponseData, ModelingCmd};
use kittycad_modeling_cmds as kcmc;
use serde::de::DeserializeOwned;

Expand Down Expand Up @@ -166,7 +165,7 @@ impl Args {
// before what ever we call next.
for id in ids {
// Pop it off the batch_end and add it to the batch.
let Some(item) = self.ctx.engine.batch_end().lock().unwrap().remove(&id) else {
let Some(item) = self.ctx.engine.batch_end().lock().unwrap().shift_remove(&id) else {
// It might be in the batch already.
continue;
};
Expand Down
3 changes: 1 addition & 2 deletions src/wasm-lib/kcl/src/std/array.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use derive_docs::stdlib;
use schemars::JsonSchema;

use super::{args::FromArgs, Args, FnAsArg};
use crate::{
errors::{KclError, KclErrorDetails},
executor::{ExecState, KclValue, SketchGroup, SourceRange, UserVal},
function_param::FunctionParam,
};

use super::{args::FromArgs, Args, FnAsArg};

/// For each item in an array, update a value.
pub async fn array_reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let (array, start, f): (Vec<u64>, SketchGroup, FnAsArg<'_>) = FromArgs::from_args(&args, 0)?;
Expand Down
7 changes: 4 additions & 3 deletions src/wasm-lib/kcl/src/std/chamfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

use anyhow::Result;
use derive_docs::stdlib;
use kcmc::each_cmd as mcmd;
use kcmc::length_unit::LengthUnit;
use kcmc::{shared::CutType, ModelingCmd};
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, shared::CutType, ModelingCmd};
use kittycad_modeling_cmds as kcmc;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -146,6 +144,9 @@ async fn inner_chamfer(
radius: LengthUnit(data.length),
tolerance: LengthUnit(DEFAULT_TOLERANCE), // We can let the user set this in the future.
cut_type: CutType::Chamfer,
// We pass in the command id as the face id.
// So the resulting face of the fillet will be the same.
// This is because that's how most other endpoints work.
face_id: Some(id),
}),
)
Expand Down
9 changes: 4 additions & 5 deletions src/wasm-lib/kcl/src/std/extrude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use std::collections::HashMap;

use anyhow::Result;
use derive_docs::stdlib;
use kcmc::each_cmd as mcmd;
use kcmc::length_unit::LengthUnit;
use kcmc::ok_response::OkModelingCmdResponse;
use kcmc::websocket::OkWebSocketResponseData;
use kcmc::{output::ExtrusionFaceInfo, shared::ExtrusionFaceCapType, ModelingCmd};
use kcmc::{
each_cmd as mcmd, length_unit::LengthUnit, ok_response::OkModelingCmdResponse, output::ExtrusionFaceInfo,
shared::ExtrusionFaceCapType, websocket::OkWebSocketResponseData, ModelingCmd,
};
use kittycad_modeling_cmds as kcmc;
use schemars::JsonSchema;
use uuid::Uuid;
Expand Down
14 changes: 8 additions & 6 deletions src/wasm-lib/kcl/src/std/fillet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

use anyhow::Result;
use derive_docs::stdlib;
use kcmc::each_cmd as mcmd;
use kcmc::length_unit::LengthUnit;
use kcmc::ok_response::OkModelingCmdResponse;
use kcmc::websocket::OkWebSocketResponseData;
use kcmc::{shared::CutType, ModelingCmd};
use kcmc::{
each_cmd as mcmd, length_unit::LengthUnit, ok_response::OkModelingCmdResponse, shared::CutType,
websocket::OkWebSocketResponseData, ModelingCmd,
};
use kittycad_modeling_cmds as kcmc;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -150,7 +149,10 @@ async fn inner_fillet(
radius: LengthUnit(data.radius),
tolerance: LengthUnit(data.tolerance.unwrap_or(default_tolerance(&args.ctx.settings.units))),
cut_type: CutType::Fillet,
face_id: None,
// We pass in the command id as the face id.
// So the resulting face of the fillet will be the same.
// This is because that's how most other endpoints work.
face_id: Some(id),
}),
)
.await?;
Expand Down
5 changes: 1 addition & 4 deletions src/wasm-lib/kcl/src/std/helix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

use anyhow::Result;
use derive_docs::stdlib;
use kcmc::each_cmd as mcmd;
use kcmc::length_unit::LengthUnit;
use kcmc::shared::Angle;
use kcmc::ModelingCmd;
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, shared::Angle, ModelingCmd};
use kittycad_modeling_cmds as kcmc;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down
Loading

0 comments on commit 2025b72

Please sign in to comment.