make sure all enter sketch mode are with the stuff they need in the same batch order always (#5646)
* updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * comment out Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * update artifacts Signed-off-by: Jess Frazelle <github@jessfraz.com> * small Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * last of the artifacts Signed-off-by: Jess Frazelle <github@jessfraz.com> * update playwirght Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * add crazy multi-profile test Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * steps Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix artifact graph Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * cleanup Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates ; Signed-off-by: Jess Frazelle <github@jessfraz.com> * more artifact grph Signed-off-by: Jess Frazelle <github@jessfraz.com> * turn back on playwright Signed-off-by: Jess Frazelle <github@jessfraz.com> * fmt Signed-off-by: Jess Frazelle <github@jessfraz.com> * playwright fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * playwright fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -6,7 +6,7 @@ use kittycad_modeling_cmds::{
|
||||
ok_response::OkModelingCmdResponse,
|
||||
shared::ExtrusionFaceCapType,
|
||||
websocket::{BatchResponse, OkWebSocketResponseData, WebSocketResponse},
|
||||
EnableSketchMode, ModelingCmd, SketchModeDisable,
|
||||
EnableSketchMode, ModelingCmd,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{ser::SerializeSeq, Deserialize, Serialize};
|
||||
@ -498,13 +498,23 @@ pub(super) fn build_artifact_graph(
|
||||
) -> Result<ArtifactGraph, KclError> {
|
||||
let mut map = IndexMap::new();
|
||||
|
||||
let mut path_to_plane_id_map = FnvHashMap::default();
|
||||
let mut current_plane_id = None;
|
||||
|
||||
for artifact_command in artifact_commands {
|
||||
if let ModelingCmd::EnableSketchMode(EnableSketchMode { entity_id, .. }) = artifact_command.command {
|
||||
current_plane_id = Some(entity_id);
|
||||
}
|
||||
if let ModelingCmd::SketchModeDisable(SketchModeDisable { .. }) = artifact_command.command {
|
||||
// If we get a start path command, we need to set the plane ID to the
|
||||
// current plane ID.
|
||||
// THIS IS THE ONLY THING WE CAN ASSUME IS ALWAYS SEQUENTIAL SINCE ITS PART OF THE
|
||||
// SAME ATOMIC COMMANDS BATCHING.
|
||||
if let ModelingCmd::StartPath(_) = artifact_command.command {
|
||||
if let Some(plane_id) = current_plane_id {
|
||||
path_to_plane_id_map.insert(artifact_command.cmd_id, plane_id);
|
||||
}
|
||||
}
|
||||
if let ModelingCmd::SketchModeDisable(_) = artifact_command.command {
|
||||
current_plane_id = None;
|
||||
}
|
||||
|
||||
@ -513,7 +523,7 @@ pub(super) fn build_artifact_graph(
|
||||
&map,
|
||||
artifact_command,
|
||||
&flattened_responses,
|
||||
current_plane_id,
|
||||
&path_to_plane_id_map,
|
||||
ast,
|
||||
exec_artifacts,
|
||||
)?;
|
||||
@ -609,7 +619,7 @@ fn artifacts_to_update(
|
||||
artifacts: &IndexMap<ArtifactId, Artifact>,
|
||||
artifact_command: &ArtifactCommand,
|
||||
responses: &FnvHashMap<Uuid, OkModelingCmdResponse>,
|
||||
current_plane_id: Option<Uuid>,
|
||||
path_to_plane_id_map: &FnvHashMap<Uuid, Uuid>,
|
||||
_ast: &Node<Program>,
|
||||
exec_artifacts: &IndexMap<ArtifactId, Artifact>,
|
||||
) -> Result<Vec<Artifact>, KclError> {
|
||||
@ -643,20 +653,12 @@ fn artifacts_to_update(
|
||||
code_ref: CodeRef { range, path_to_node },
|
||||
})]);
|
||||
}
|
||||
ModelingCmd::EnableSketchMode(_) => {
|
||||
let current_plane_id = current_plane_id.ok_or_else(|| {
|
||||
KclError::Internal(KclErrorDetails {
|
||||
message: format!(
|
||||
"Expected a current plane ID when processing EnableSketchMode command, but we have none: {id:?}"
|
||||
),
|
||||
source_ranges: vec![range],
|
||||
})
|
||||
})?;
|
||||
let existing_plane = artifacts.get(&ArtifactId::new(current_plane_id));
|
||||
ModelingCmd::EnableSketchMode(EnableSketchMode { entity_id, .. }) => {
|
||||
let existing_plane = artifacts.get(&ArtifactId::new(*entity_id));
|
||||
match existing_plane {
|
||||
Some(Artifact::Wall(wall)) => {
|
||||
return Ok(vec![Artifact::Wall(Wall {
|
||||
id: current_plane_id.into(),
|
||||
id: entity_id.into(),
|
||||
seg_id: wall.seg_id,
|
||||
edge_cut_edge_ids: wall.edge_cut_edge_ids.clone(),
|
||||
sweep_id: wall.sweep_id,
|
||||
@ -666,7 +668,7 @@ fn artifacts_to_update(
|
||||
}
|
||||
Some(Artifact::Cap(cap)) => {
|
||||
return Ok(vec![Artifact::Cap(Cap {
|
||||
id: current_plane_id.into(),
|
||||
id: entity_id.into(),
|
||||
sub_type: cap.sub_type,
|
||||
edge_cut_edge_ids: cap.edge_cut_edge_ids.clone(),
|
||||
sweep_id: cap.sweep_id,
|
||||
@ -680,7 +682,7 @@ fn artifacts_to_update(
|
||||
_ => Vec::new(),
|
||||
};
|
||||
return Ok(vec![Artifact::Plane(Plane {
|
||||
id: current_plane_id.into(),
|
||||
id: entity_id.into(),
|
||||
path_ids,
|
||||
code_ref: CodeRef { range, path_to_node },
|
||||
})]);
|
||||
@ -689,7 +691,7 @@ fn artifacts_to_update(
|
||||
}
|
||||
ModelingCmd::StartPath(_) => {
|
||||
let mut return_arr = Vec::new();
|
||||
let current_plane_id = current_plane_id.ok_or_else(|| {
|
||||
let current_plane_id = path_to_plane_id_map.get(&artifact_command.cmd_id).ok_or_else(|| {
|
||||
KclError::Internal(KclErrorDetails {
|
||||
message: format!(
|
||||
"Expected a current plane ID when processing StartPath command, but we have none: {id:?}"
|
||||
@ -699,24 +701,24 @@ fn artifacts_to_update(
|
||||
})?;
|
||||
return_arr.push(Artifact::Path(Path {
|
||||
id,
|
||||
plane_id: current_plane_id.into(),
|
||||
plane_id: (*current_plane_id).into(),
|
||||
seg_ids: Vec::new(),
|
||||
sweep_id: None,
|
||||
solid2d_id: None,
|
||||
code_ref: CodeRef { range, path_to_node },
|
||||
}));
|
||||
let plane = artifacts.get(&ArtifactId::new(current_plane_id));
|
||||
let plane = artifacts.get(&ArtifactId::new(*current_plane_id));
|
||||
if let Some(Artifact::Plane(plane)) = plane {
|
||||
let code_ref = plane.code_ref.clone();
|
||||
return_arr.push(Artifact::Plane(Plane {
|
||||
id: current_plane_id.into(),
|
||||
id: (*current_plane_id).into(),
|
||||
path_ids: vec![id],
|
||||
code_ref,
|
||||
}));
|
||||
}
|
||||
if let Some(Artifact::Wall(wall)) = plane {
|
||||
return_arr.push(Artifact::Wall(Wall {
|
||||
id: current_plane_id.into(),
|
||||
id: (*current_plane_id).into(),
|
||||
seg_id: wall.seg_id,
|
||||
edge_cut_edge_ids: wall.edge_cut_edge_ids.clone(),
|
||||
sweep_id: wall.sweep_id,
|
||||
@ -726,7 +728,7 @@ fn artifacts_to_update(
|
||||
}
|
||||
if let Some(Artifact::Cap(cap)) = plane {
|
||||
return_arr.push(Artifact::Cap(Cap {
|
||||
id: current_plane_id.into(),
|
||||
id: (*current_plane_id).into(),
|
||||
sub_type: cap.sub_type,
|
||||
edge_cut_edge_ids: cap.edge_cut_edge_ids.clone(),
|
||||
sweep_id: cap.sweep_id,
|
||||
|
@ -3,15 +3,14 @@ use std::ops::{Add, AddAssign, Mul};
|
||||
use anyhow::Result;
|
||||
use indexmap::IndexMap;
|
||||
use kittycad_modeling_cmds as kcmc;
|
||||
use kittycad_modeling_cmds::length_unit::LengthUnit;
|
||||
use kittycad_modeling_cmds::{each_cmd as mcmd, length_unit::LengthUnit, websocket::ModelingCmdReq, ModelingCmd};
|
||||
use parse_display::{Display, FromStr};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::ArtifactId;
|
||||
use crate::{
|
||||
errors::KclError,
|
||||
execution::{ExecState, Metadata, TagEngineInfo, TagIdentifier, UnitLen},
|
||||
execution::{ArtifactId, ExecState, Metadata, TagEngineInfo, TagIdentifier, UnitLen},
|
||||
parsing::ast::types::{Node, NodeRef, TagDeclarator, TagNode},
|
||||
std::sketch::PlaneData,
|
||||
};
|
||||
@ -532,6 +531,41 @@ pub struct Sketch {
|
||||
pub meta: Vec<Metadata>,
|
||||
}
|
||||
|
||||
impl Sketch {
|
||||
// Tell the engine to enter sketch mode on the sketch.
|
||||
// Run a specific command, then exit sketch mode.
|
||||
pub(crate) fn build_sketch_mode_cmds(
|
||||
&self,
|
||||
exec_state: &mut ExecState,
|
||||
inner_cmd: ModelingCmdReq,
|
||||
) -> Vec<ModelingCmdReq> {
|
||||
vec![
|
||||
// Before we extrude, we need to enable the sketch mode.
|
||||
// We do this here in case extrude is called out of order.
|
||||
ModelingCmdReq {
|
||||
cmd: ModelingCmd::from(mcmd::EnableSketchMode {
|
||||
animated: false,
|
||||
ortho: false,
|
||||
entity_id: self.on.id(),
|
||||
adjust_camera: false,
|
||||
planar_normal: if let SketchSurface::Plane(plane) = &self.on {
|
||||
// We pass in the normal for the plane here.
|
||||
Some(plane.z_axis.into())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
}),
|
||||
cmd_id: exec_state.next_uuid().into(),
|
||||
},
|
||||
inner_cmd,
|
||||
ModelingCmdReq {
|
||||
cmd: ModelingCmd::SketchModeDisable(mcmd::SketchModeDisable::default()),
|
||||
cmd_id: exec_state.next_uuid().into(),
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
/// A sketch type.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
|
Reference in New Issue
Block a user