Add building the artifact graph in sketch mode, take 2 (#7557)
* Add building the artifact graph in mock execution * Update output * Add updating the artifact graph after mock execution * Fix spelling * Fix to return it all the way * Fix to not make artifact fields undefined in TS
This commit is contained in:
@ -85,10 +85,8 @@ pub struct CompositeSolid {
|
|||||||
pub id: ArtifactId,
|
pub id: ArtifactId,
|
||||||
pub sub_type: CompositeSolidSubType,
|
pub sub_type: CompositeSolidSubType,
|
||||||
/// Constituent solids of the composite solid.
|
/// Constituent solids of the composite solid.
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
pub solid_ids: Vec<ArtifactId>,
|
pub solid_ids: Vec<ArtifactId>,
|
||||||
/// Tool solids used for asymmetric operations like subtract.
|
/// Tool solids used for asymmetric operations like subtract.
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
pub tool_ids: Vec<ArtifactId>,
|
pub tool_ids: Vec<ArtifactId>,
|
||||||
pub code_ref: CodeRef,
|
pub code_ref: CodeRef,
|
||||||
/// This is the ID of the composite solid that this is part of, if any, as a
|
/// This is the ID of the composite solid that this is part of, if any, as a
|
||||||
@ -141,12 +139,10 @@ pub struct Segment {
|
|||||||
pub path_id: ArtifactId,
|
pub path_id: ArtifactId,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub surface_id: Option<ArtifactId>,
|
pub surface_id: Option<ArtifactId>,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
pub edge_ids: Vec<ArtifactId>,
|
pub edge_ids: Vec<ArtifactId>,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub edge_cut_id: Option<ArtifactId>,
|
pub edge_cut_id: Option<ArtifactId>,
|
||||||
pub code_ref: CodeRef,
|
pub code_ref: CodeRef,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
pub common_surface_ids: Vec<ArtifactId>,
|
pub common_surface_ids: Vec<ArtifactId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,9 +154,7 @@ pub struct Sweep {
|
|||||||
pub id: ArtifactId,
|
pub id: ArtifactId,
|
||||||
pub sub_type: SweepSubType,
|
pub sub_type: SweepSubType,
|
||||||
pub path_id: ArtifactId,
|
pub path_id: ArtifactId,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
pub surface_ids: Vec<ArtifactId>,
|
pub surface_ids: Vec<ArtifactId>,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
pub edge_ids: Vec<ArtifactId>,
|
pub edge_ids: Vec<ArtifactId>,
|
||||||
pub code_ref: CodeRef,
|
pub code_ref: CodeRef,
|
||||||
}
|
}
|
||||||
@ -209,10 +203,8 @@ pub struct StartSketchOnPlane {
|
|||||||
pub struct Wall {
|
pub struct Wall {
|
||||||
pub id: ArtifactId,
|
pub id: ArtifactId,
|
||||||
pub seg_id: ArtifactId,
|
pub seg_id: ArtifactId,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
pub edge_cut_edge_ids: Vec<ArtifactId>,
|
pub edge_cut_edge_ids: Vec<ArtifactId>,
|
||||||
pub sweep_id: ArtifactId,
|
pub sweep_id: ArtifactId,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
pub path_ids: Vec<ArtifactId>,
|
pub path_ids: Vec<ArtifactId>,
|
||||||
/// This is for the sketch-on-face plane, not for the wall itself. Traverse
|
/// This is for the sketch-on-face plane, not for the wall itself. Traverse
|
||||||
/// to the extrude and/or segment to get the wall's code_ref.
|
/// to the extrude and/or segment to get the wall's code_ref.
|
||||||
@ -227,10 +219,8 @@ pub struct Wall {
|
|||||||
pub struct Cap {
|
pub struct Cap {
|
||||||
pub id: ArtifactId,
|
pub id: ArtifactId,
|
||||||
pub sub_type: CapSubType,
|
pub sub_type: CapSubType,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
pub edge_cut_edge_ids: Vec<ArtifactId>,
|
pub edge_cut_edge_ids: Vec<ArtifactId>,
|
||||||
pub sweep_id: ArtifactId,
|
pub sweep_id: ArtifactId,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
pub path_ids: Vec<ArtifactId>,
|
pub path_ids: Vec<ArtifactId>,
|
||||||
/// This is for the sketch-on-face plane, not for the cap itself. Traverse
|
/// This is for the sketch-on-face plane, not for the cap itself. Traverse
|
||||||
/// to the extrude and/or segment to get the cap's code_ref.
|
/// to the extrude and/or segment to get the cap's code_ref.
|
||||||
@ -259,7 +249,6 @@ pub struct SweepEdge {
|
|||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
pub sweep_id: ArtifactId,
|
pub sweep_id: ArtifactId,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
pub common_surface_ids: Vec<ArtifactId>,
|
pub common_surface_ids: Vec<ArtifactId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +267,6 @@ pub struct EdgeCut {
|
|||||||
pub id: ArtifactId,
|
pub id: ArtifactId,
|
||||||
pub sub_type: EdgeCutSubType,
|
pub sub_type: EdgeCutSubType,
|
||||||
pub consumed_edge_id: ArtifactId,
|
pub consumed_edge_id: ArtifactId,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
pub edge_ids: Vec<ArtifactId>,
|
pub edge_ids: Vec<ArtifactId>,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub surface_id: Option<ArtifactId>,
|
pub surface_id: Option<ArtifactId>,
|
||||||
@ -540,6 +528,11 @@ impl ArtifactGraph {
|
|||||||
self.map.is_empty()
|
self.map.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) fn iter(&self) -> impl Iterator<Item = (&ArtifactId, &Artifact)> {
|
||||||
|
self.map.iter()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn values(&self) -> impl Iterator<Item = &Artifact> {
|
pub fn values(&self) -> impl Iterator<Item = &Artifact> {
|
||||||
self.map.values()
|
self.map.values()
|
||||||
}
|
}
|
||||||
@ -728,10 +721,7 @@ fn artifacts_to_update(
|
|||||||
exec_artifacts: &IndexMap<ArtifactId, Artifact>,
|
exec_artifacts: &IndexMap<ArtifactId, Artifact>,
|
||||||
) -> Result<Vec<Artifact>, KclError> {
|
) -> Result<Vec<Artifact>, KclError> {
|
||||||
let uuid = artifact_command.cmd_id;
|
let uuid = artifact_command.cmd_id;
|
||||||
let Some(response) = responses.get(&uuid) else {
|
let response = responses.get(&uuid);
|
||||||
// Response not found or not successful.
|
|
||||||
return Ok(Vec::new());
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Build path-to-node from artifact_command source range. Right now,
|
// TODO: Build path-to-node from artifact_command source range. Right now,
|
||||||
// we're serializing an empty array, and the TS wrapper fills it in with the
|
// we're serializing an empty array, and the TS wrapper fills it in with the
|
||||||
@ -875,7 +865,7 @@ fn artifacts_to_update(
|
|||||||
new_path.seg_ids = vec![id];
|
new_path.seg_ids = vec![id];
|
||||||
return_arr.push(Artifact::Path(new_path));
|
return_arr.push(Artifact::Path(new_path));
|
||||||
}
|
}
|
||||||
if let OkModelingCmdResponse::ClosePath(close_path) = response {
|
if let Some(OkModelingCmdResponse::ClosePath(close_path)) = response {
|
||||||
return_arr.push(Artifact::Solid2d(Solid2d {
|
return_arr.push(Artifact::Solid2d(Solid2d {
|
||||||
id: close_path.face_id.into(),
|
id: close_path.face_id.into(),
|
||||||
path_id,
|
path_id,
|
||||||
@ -895,8 +885,8 @@ fn artifacts_to_update(
|
|||||||
ids: original_path_ids, ..
|
ids: original_path_ids, ..
|
||||||
}) => {
|
}) => {
|
||||||
let face_edge_infos = match response {
|
let face_edge_infos = match response {
|
||||||
OkModelingCmdResponse::EntityMirror(resp) => &resp.entity_face_edge_ids,
|
Some(OkModelingCmdResponse::EntityMirror(resp)) => &resp.entity_face_edge_ids,
|
||||||
OkModelingCmdResponse::EntityMirrorAcrossEdge(resp) => &resp.entity_face_edge_ids,
|
Some(OkModelingCmdResponse::EntityMirrorAcrossEdge(resp)) => &resp.entity_face_edge_ids,
|
||||||
_ => internal_error!(
|
_ => internal_error!(
|
||||||
range,
|
range,
|
||||||
"Mirror response variant not handled: id={id:?}, cmd={cmd:?}, response={response:?}"
|
"Mirror response variant not handled: id={id:?}, cmd={cmd:?}, response={response:?}"
|
||||||
@ -983,7 +973,7 @@ fn artifacts_to_update(
|
|||||||
return Ok(return_arr);
|
return Ok(return_arr);
|
||||||
}
|
}
|
||||||
ModelingCmd::Loft(loft_cmd) => {
|
ModelingCmd::Loft(loft_cmd) => {
|
||||||
let OkModelingCmdResponse::Loft(_) = response else {
|
let Some(OkModelingCmdResponse::Loft(_)) = response else {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
};
|
};
|
||||||
let mut return_arr = Vec::new();
|
let mut return_arr = Vec::new();
|
||||||
@ -1013,7 +1003,7 @@ fn artifacts_to_update(
|
|||||||
return Ok(return_arr);
|
return Ok(return_arr);
|
||||||
}
|
}
|
||||||
ModelingCmd::Solid3dGetExtrusionFaceInfo(_) => {
|
ModelingCmd::Solid3dGetExtrusionFaceInfo(_) => {
|
||||||
let OkModelingCmdResponse::Solid3dGetExtrusionFaceInfo(face_info) = response else {
|
let Some(OkModelingCmdResponse::Solid3dGetExtrusionFaceInfo(face_info)) = response else {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
};
|
};
|
||||||
let mut return_arr = Vec::new();
|
let mut return_arr = Vec::new();
|
||||||
@ -1134,7 +1124,7 @@ fn artifacts_to_update(
|
|||||||
return Ok(return_arr);
|
return Ok(return_arr);
|
||||||
}
|
}
|
||||||
ModelingCmd::Solid3dGetAdjacencyInfo(kcmc::Solid3dGetAdjacencyInfo { .. }) => {
|
ModelingCmd::Solid3dGetAdjacencyInfo(kcmc::Solid3dGetAdjacencyInfo { .. }) => {
|
||||||
let OkModelingCmdResponse::Solid3dGetAdjacencyInfo(info) = response else {
|
let Some(OkModelingCmdResponse::Solid3dGetAdjacencyInfo(info)) = response else {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1315,21 +1305,21 @@ fn artifacts_to_update(
|
|||||||
let not_cmd_id = move |solid_id: &ArtifactId| *solid_id != id;
|
let not_cmd_id = move |solid_id: &ArtifactId| *solid_id != id;
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
OkModelingCmdResponse::BooleanIntersection(intersection) => intersection
|
Some(OkModelingCmdResponse::BooleanIntersection(intersection)) => intersection
|
||||||
.extra_solid_ids
|
.extra_solid_ids
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.map(ArtifactId::new)
|
.map(ArtifactId::new)
|
||||||
.filter(not_cmd_id)
|
.filter(not_cmd_id)
|
||||||
.for_each(|id| new_solid_ids.push(id)),
|
.for_each(|id| new_solid_ids.push(id)),
|
||||||
OkModelingCmdResponse::BooleanSubtract(subtract) => subtract
|
Some(OkModelingCmdResponse::BooleanSubtract(subtract)) => subtract
|
||||||
.extra_solid_ids
|
.extra_solid_ids
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.map(ArtifactId::new)
|
.map(ArtifactId::new)
|
||||||
.filter(not_cmd_id)
|
.filter(not_cmd_id)
|
||||||
.for_each(|id| new_solid_ids.push(id)),
|
.for_each(|id| new_solid_ids.push(id)),
|
||||||
OkModelingCmdResponse::BooleanUnion(union) => union
|
Some(OkModelingCmdResponse::BooleanUnion(union)) => union
|
||||||
.extra_solid_ids
|
.extra_solid_ids
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
|
@ -20,7 +20,7 @@ use crate::{
|
|||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
/// A static mutable lock for updating the last successful execution state for the cache.
|
/// A static mutable lock for updating the last successful execution state for the cache.
|
||||||
static ref OLD_AST: Arc<RwLock<Option<GlobalState>>> = Default::default();
|
static ref OLD_AST: Arc<RwLock<Option<GlobalState>>> = Default::default();
|
||||||
// The last successful run's memory. Not cleared after an unssuccessful run.
|
// The last successful run's memory. Not cleared after an unsuccessful run.
|
||||||
static ref PREV_MEMORY: Arc<RwLock<Option<(Stack, ModuleInfoMap)>>> = Default::default();
|
static ref PREV_MEMORY: Arc<RwLock<Option<(Stack, ModuleInfoMap)>>> = Default::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2286,6 +2286,25 @@ w = f() + f()
|
|||||||
ctx2.close().await;
|
ctx2.close().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "artifact-graph")]
|
||||||
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
|
async fn mock_has_stable_ids() {
|
||||||
|
let ctx = ExecutorContext::new_mock(None).await;
|
||||||
|
let code = "sk = startSketchOn(XY)
|
||||||
|
|> startProfile(at = [0, 0])";
|
||||||
|
let program = crate::Program::parse_no_errs(code).unwrap();
|
||||||
|
let result = ctx.run_mock(program, false).await.unwrap();
|
||||||
|
let ids = result.artifact_graph.iter().map(|(k, _)| *k).collect::<Vec<_>>();
|
||||||
|
assert!(!ids.is_empty(), "IDs should not be empty");
|
||||||
|
|
||||||
|
let ctx2 = ExecutorContext::new_mock(None).await;
|
||||||
|
let program2 = crate::Program::parse_no_errs(code).unwrap();
|
||||||
|
let result = ctx2.run_mock(program2, false).await.unwrap();
|
||||||
|
let ids2 = result.artifact_graph.iter().map(|(k, _)| *k).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
assert_eq!(ids, ids2, "Generated IDs should match");
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "artifact-graph")]
|
#[cfg(feature = "artifact-graph")]
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn sim_sketch_mode_real_mock_real() {
|
async fn sim_sketch_mode_real_mock_real() {
|
||||||
|
@ -177,7 +177,7 @@ impl ExecState {
|
|||||||
#[cfg(feature = "artifact-graph")]
|
#[cfg(feature = "artifact-graph")]
|
||||||
operations: Default::default(),
|
operations: Default::default(),
|
||||||
#[cfg(feature = "artifact-graph")]
|
#[cfg(feature = "artifact-graph")]
|
||||||
artifact_graph: Default::default(),
|
artifact_graph: self.global.artifacts.graph,
|
||||||
errors: self.global.errors,
|
errors: self.global.errors,
|
||||||
filenames: Default::default(),
|
filenames: Default::default(),
|
||||||
default_planes: ctx.engine.get_default_planes().read().await.clone(),
|
default_planes: ctx.engine.get_default_planes().read().await.clone(),
|
||||||
|
@ -14,9 +14,12 @@ flowchart LR
|
|||||||
end
|
end
|
||||||
1["Plane<br>[10, 27, 0]"]
|
1["Plane<br>[10, 27, 0]"]
|
||||||
%% [ProgramBodyItem { index: 0 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 0 }]
|
%% [ProgramBodyItem { index: 0 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 0 }]
|
||||||
|
7["Sweep Extrusion<br>[226, 245, 0]"]
|
||||||
|
%% [ProgramBodyItem { index: 0 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 6 }]
|
||||||
1 --- 2
|
1 --- 2
|
||||||
2 --- 3
|
2 --- 3
|
||||||
2 --- 4
|
2 --- 4
|
||||||
2 --- 5
|
2 --- 5
|
||||||
2 --- 6
|
2 --- 6
|
||||||
|
2 ---- 7
|
||||||
```
|
```
|
||||||
|
@ -185,7 +185,9 @@ flowchart LR
|
|||||||
%% face_code_ref=Missing NodePath
|
%% face_code_ref=Missing NodePath
|
||||||
110["SweepEdge Opposite"]
|
110["SweepEdge Opposite"]
|
||||||
111["SweepEdge Adjacent"]
|
111["SweepEdge Adjacent"]
|
||||||
112["StartSketchOnPlane<br>[1430, 1475, 0]"]
|
112["CompositeSolid Subtract<br>[1634, 1677, 0]"]
|
||||||
|
%% [ProgramBodyItem { index: 10 }, VariableDeclarationDeclaration, VariableDeclarationInit]
|
||||||
|
113["StartSketchOnPlane<br>[1430, 1475, 0]"]
|
||||||
%% [ProgramBodyItem { index: 7 }, VariableDeclarationDeclaration, VariableDeclarationInit]
|
%% [ProgramBodyItem { index: 7 }, VariableDeclarationDeclaration, VariableDeclarationInit]
|
||||||
1 --- 2
|
1 --- 2
|
||||||
1 --- 13
|
1 --- 13
|
||||||
@ -302,6 +304,7 @@ flowchart LR
|
|||||||
44 --- 50
|
44 --- 50
|
||||||
44 --- 51
|
44 --- 51
|
||||||
44 ---- 60
|
44 ---- 60
|
||||||
|
44 --- 112
|
||||||
45 --- 61
|
45 --- 61
|
||||||
45 x--> 67
|
45 x--> 67
|
||||||
45 --- 69
|
45 --- 69
|
||||||
@ -334,6 +337,7 @@ flowchart LR
|
|||||||
52 --- 58
|
52 --- 58
|
||||||
52 --- 59
|
52 --- 59
|
||||||
52 ---- 81
|
52 ---- 81
|
||||||
|
52 --- 112
|
||||||
53 --- 87
|
53 --- 87
|
||||||
53 x--> 88
|
53 x--> 88
|
||||||
53 --- 100
|
53 --- 100
|
||||||
@ -447,10 +451,11 @@ flowchart LR
|
|||||||
98 <--x 89
|
98 <--x 89
|
||||||
100 <--x 89
|
100 <--x 89
|
||||||
102 --- 103
|
102 --- 103
|
||||||
102 <--x 112
|
102 <--x 113
|
||||||
103 --- 104
|
103 --- 104
|
||||||
103 --- 105
|
103 --- 105
|
||||||
103 ---- 106
|
103 ---- 106
|
||||||
|
103 --- 112
|
||||||
104 --- 107
|
104 --- 107
|
||||||
104 x--> 109
|
104 x--> 109
|
||||||
104 --- 110
|
104 --- 110
|
||||||
|
@ -139,6 +139,8 @@ flowchart LR
|
|||||||
83["SweepEdge Adjacent"]
|
83["SweepEdge Adjacent"]
|
||||||
84["EdgeCut Fillet<br>[1691, 1773, 0]"]
|
84["EdgeCut Fillet<br>[1691, 1773, 0]"]
|
||||||
%% [ProgramBodyItem { index: 14 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 7 }]
|
%% [ProgramBodyItem { index: 14 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 7 }]
|
||||||
|
85["CompositeSolid Union<br>[1939, 1960, 0]"]
|
||||||
|
%% [ProgramBodyItem { index: 15 }, ExpressionStatementExpr]
|
||||||
1 --- 2
|
1 --- 2
|
||||||
2 --- 3
|
2 --- 3
|
||||||
2 --- 4
|
2 --- 4
|
||||||
@ -150,6 +152,7 @@ flowchart LR
|
|||||||
2 --- 10
|
2 --- 10
|
||||||
2 --- 11
|
2 --- 11
|
||||||
2 ---- 12
|
2 ---- 12
|
||||||
|
2 --- 85
|
||||||
3 --- 13
|
3 --- 13
|
||||||
3 x--> 22
|
3 x--> 22
|
||||||
3 --- 23
|
3 --- 23
|
||||||
@ -247,6 +250,7 @@ flowchart LR
|
|||||||
40 --- 44
|
40 --- 44
|
||||||
40 --- 45
|
40 --- 45
|
||||||
40 ---- 46
|
40 ---- 46
|
||||||
|
40 --- 85
|
||||||
41 --- 47
|
41 --- 47
|
||||||
41 x--> 52
|
41 x--> 52
|
||||||
41 --- 53
|
41 --- 53
|
||||||
|
@ -68,6 +68,8 @@ flowchart LR
|
|||||||
38["SweepEdge Adjacent"]
|
38["SweepEdge Adjacent"]
|
||||||
39["SweepEdge Opposite"]
|
39["SweepEdge Opposite"]
|
||||||
40["SweepEdge Adjacent"]
|
40["SweepEdge Adjacent"]
|
||||||
|
41["CompositeSolid Union<br>[1346, 1377, 0]"]
|
||||||
|
%% [ProgramBodyItem { index: 11 }, VariableDeclarationDeclaration, VariableDeclarationInit]
|
||||||
1 --- 2
|
1 --- 2
|
||||||
2 --- 3
|
2 --- 3
|
||||||
2 --- 4
|
2 --- 4
|
||||||
@ -75,6 +77,7 @@ flowchart LR
|
|||||||
2 --- 6
|
2 --- 6
|
||||||
2 --- 7
|
2 --- 7
|
||||||
2 ---- 8
|
2 ---- 8
|
||||||
|
2 --- 41
|
||||||
3 --- 9
|
3 --- 9
|
||||||
3 x--> 13
|
3 x--> 13
|
||||||
3 --- 15
|
3 --- 15
|
||||||
@ -127,6 +130,7 @@ flowchart LR
|
|||||||
24 --- 27
|
24 --- 27
|
||||||
24 --- 28
|
24 --- 28
|
||||||
24 ---- 29
|
24 ---- 29
|
||||||
|
24 --- 41
|
||||||
25 --- 30
|
25 --- 30
|
||||||
25 x--> 33
|
25 x--> 33
|
||||||
25 --- 35
|
25 --- 35
|
||||||
|
@ -572,6 +572,7 @@ export class KclManager extends EventTarget {
|
|||||||
this.lastSuccessfulVariables = execState.variables
|
this.lastSuccessfulVariables = execState.variables
|
||||||
this.lastSuccessfulOperations = execState.operations
|
this.lastSuccessfulOperations = execState.operations
|
||||||
}
|
}
|
||||||
|
await this.updateArtifactGraph(execState.artifactGraph)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
cancelAllExecutions() {
|
cancelAllExecutions() {
|
||||||
|
@ -314,14 +314,7 @@ export function emptyExecState(): ExecState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function execStateFromRust(execOutcome: RustExecOutcome): ExecState {
|
export function execStateFromRust(execOutcome: RustExecOutcome): ExecState {
|
||||||
const artifactGraph = rustArtifactGraphToMap(execOutcome.artifactGraph)
|
const artifactGraph = artifactGraphFromRust(execOutcome.artifactGraph)
|
||||||
// Translate NodePath to PathToNode.
|
|
||||||
for (const [_id, artifact] of artifactGraph) {
|
|
||||||
if (!artifact) continue
|
|
||||||
if (!('codeRef' in artifact)) continue
|
|
||||||
const pathToNode = pathToNodeFromRustNodePath(artifact.codeRef.nodePath)
|
|
||||||
artifact.codeRef.pathToNode = pathToNode
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
variables: execOutcome.variables,
|
variables: execOutcome.variables,
|
||||||
@ -333,29 +326,26 @@ export function execStateFromRust(execOutcome: RustExecOutcome): ExecState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mockExecStateFromRust(execOutcome: RustExecOutcome): ExecState {
|
|
||||||
return {
|
|
||||||
variables: execOutcome.variables,
|
|
||||||
operations: execOutcome.operations,
|
|
||||||
artifactGraph: new Map<ArtifactId, Artifact>(),
|
|
||||||
errors: execOutcome.errors,
|
|
||||||
filenames: execOutcome.filenames,
|
|
||||||
defaultPlanes: execOutcome.defaultPlanes,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ArtifactGraph = Map<ArtifactId, Artifact>
|
export type ArtifactGraph = Map<ArtifactId, Artifact>
|
||||||
|
|
||||||
function rustArtifactGraphToMap(
|
function artifactGraphFromRust(
|
||||||
rustArtifactGraph: RustArtifactGraph
|
rustArtifactGraph: RustArtifactGraph
|
||||||
): ArtifactGraph {
|
): ArtifactGraph {
|
||||||
const map = new Map<ArtifactId, Artifact>()
|
const artifactGraph = new Map<ArtifactId, Artifact>()
|
||||||
|
// Convert to a Map.
|
||||||
for (const [id, artifact] of Object.entries(rustArtifactGraph.map)) {
|
for (const [id, artifact] of Object.entries(rustArtifactGraph.map)) {
|
||||||
if (!artifact) continue
|
if (!artifact) continue
|
||||||
map.set(id, artifact)
|
artifactGraph.set(id, artifact)
|
||||||
}
|
}
|
||||||
|
|
||||||
return map
|
// Translate NodePath to PathToNode.
|
||||||
|
for (const [_id, artifact] of artifactGraph) {
|
||||||
|
if (!artifact) continue
|
||||||
|
if (!('codeRef' in artifact)) continue
|
||||||
|
const pathToNode = pathToNodeFromRustNodePath(artifact.codeRef.nodePath)
|
||||||
|
artifact.codeRef.pathToNode = pathToNode
|
||||||
|
}
|
||||||
|
return artifactGraph
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sketchFromKclValueOptional(
|
export function sketchFromKclValueOptional(
|
||||||
@ -407,7 +397,7 @@ export const errFromErrWithOutputs = (e: any): KCLError => {
|
|||||||
parsed.error.details.backtrace,
|
parsed.error.details.backtrace,
|
||||||
parsed.nonFatal,
|
parsed.nonFatal,
|
||||||
parsed.operations,
|
parsed.operations,
|
||||||
rustArtifactGraphToMap(parsed.artifactGraph),
|
artifactGraphFromRust(parsed.artifactGraph),
|
||||||
parsed.filenames,
|
parsed.filenames,
|
||||||
parsed.defaultPlanes
|
parsed.defaultPlanes
|
||||||
)
|
)
|
||||||
|
@ -13,11 +13,7 @@ import type { Models } from '@kittycad/lib/dist/types/src'
|
|||||||
import type { EngineCommandManager } from '@src/lang/std/engineConnection'
|
import type { EngineCommandManager } from '@src/lang/std/engineConnection'
|
||||||
import { fileSystemManager } from '@src/lang/std/fileSystemManager'
|
import { fileSystemManager } from '@src/lang/std/fileSystemManager'
|
||||||
import type { ExecState } from '@src/lang/wasm'
|
import type { ExecState } from '@src/lang/wasm'
|
||||||
import {
|
import { errFromErrWithOutputs, execStateFromRust } from '@src/lang/wasm'
|
||||||
errFromErrWithOutputs,
|
|
||||||
execStateFromRust,
|
|
||||||
mockExecStateFromRust,
|
|
||||||
} from '@src/lang/wasm'
|
|
||||||
import { initPromise } from '@src/lang/wasmUtils'
|
import { initPromise } from '@src/lang/wasmUtils'
|
||||||
import type ModelingAppFile from '@src/lib/modelingAppFile'
|
import type ModelingAppFile from '@src/lib/modelingAppFile'
|
||||||
import type { DefaultPlaneStr } from '@src/lib/planes'
|
import type { DefaultPlaneStr } from '@src/lib/planes'
|
||||||
@ -120,7 +116,7 @@ export default class RustContext {
|
|||||||
JSON.stringify(settings),
|
JSON.stringify(settings),
|
||||||
usePrevMemory
|
usePrevMemory
|
||||||
)
|
)
|
||||||
return mockExecStateFromRust(result)
|
return execStateFromRust(result)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return Promise.reject(errFromErrWithOutputs(e))
|
return Promise.reject(errFromErrWithOutputs(e))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user