Compare commits

...

1 Commits

Author SHA1 Message Date
876a1cca57 WIP: helix artifact graph 2025-02-07 16:47:13 -05:00
2 changed files with 48 additions and 3 deletions

View File

@ -13,9 +13,7 @@ use serde::{ser::SerializeSeq, Deserialize, Serialize};
use uuid::Uuid;
use crate::{
errors::KclErrorDetails,
parsing::ast::types::{Node, Program},
KclError, SourceRange,
errors::KclErrorDetails, parsing::ast::types::{Node, Program}, KclError, SourceRange
};
#[cfg(test)]
@ -115,6 +113,14 @@ pub struct Plane {
pub code_ref: CodeRef,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS)]
#[ts(export_to = "Artifact.ts")]
#[serde(rename_all = "camelCase")]
pub struct Helix {
pub id: ArtifactId,
pub code_ref: CodeRef,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS)]
#[ts(export_to = "Artifact.ts")]
#[serde(rename_all = "camelCase")]
@ -274,6 +280,7 @@ pub struct EdgeCutEdge {
#[serde(tag = "type", rename_all = "camelCase")]
pub enum Artifact {
Plane(Plane),
Helix(Helix),
Path(Path),
Segment(Segment),
Solid2d(Solid2d),
@ -301,6 +308,7 @@ impl Artifact {
pub(crate) fn id(&self) -> ArtifactId {
match self {
Artifact::Plane(a) => a.id,
Artifact::Helix(a) => a.id,
Artifact::Path(a) => a.id,
Artifact::Segment(a) => a.id,
Artifact::Solid2d(a) => a.id,
@ -319,6 +327,7 @@ impl Artifact {
pub(crate) fn code_ref(&self) -> Option<&CodeRef> {
match self {
Artifact::Plane(a) => Some(&a.code_ref),
Artifact::Helix(a) => Some(&a.code_ref),
Artifact::Path(a) => Some(&a.code_ref),
Artifact::Segment(a) => Some(&a.code_ref),
Artifact::Solid2d(_) => None,
@ -339,6 +348,7 @@ impl Artifact {
fn merge(&mut self, new: Artifact) -> Option<Artifact> {
match self {
Artifact::Plane(a) => a.merge(new),
Artifact::Helix(a) => a.merge(new),
Artifact::Path(a) => a.merge(new),
Artifact::Segment(a) => a.merge(new),
Artifact::Solid2d(_) => Some(new),
@ -365,6 +375,17 @@ impl Plane {
}
}
impl Helix {
fn merge(&mut self, new: Artifact) -> Option<Artifact> {
let Artifact::Helix(new) = new else {
return Some(new);
};
// merge_ids(&mut self.path_ids, new.path_ids);
None
}
}
impl Path {
fn merge(&mut self, new: Artifact) -> Option<Artifact> {
let Artifact::Path(new) = new else {
@ -601,6 +622,15 @@ fn artifacts_to_update(
code_ref: CodeRef { range, path_to_node },
})]);
}
ModelingCmd::EntityMakeHelixFromParams(_) => {
if range.is_synthetic() {
return Ok(Vec::new());
}
return Ok(vec![Artifact::Helix(Helix {
id,
code_ref: CodeRef { range, path_to_node },
})]);
}
ModelingCmd::EnableSketchMode(_) => {
let current_plane_id = current_plane_id.ok_or_else(|| {
KclError::Internal(KclErrorDetails {

View File

@ -68,6 +68,7 @@ impl Artifact {
pub(crate) fn back_edges(&self) -> Vec<ArtifactId> {
match self {
Artifact::Plane(_) => Vec::new(),
Artifact::Helix(_) => Vec::new(),
Artifact::Path(a) => vec![a.plane_id],
Artifact::Segment(a) => vec![a.path_id],
Artifact::Solid2d(a) => vec![a.path_id],
@ -87,6 +88,7 @@ impl Artifact {
pub(crate) fn child_ids(&self) -> Vec<ArtifactId> {
match self {
Artifact::Plane(a) => a.path_ids.clone(),
Artifact::Helix(a) => Vec::new(),
Artifact::Path(a) => {
// Note: Don't include these since they're parents: plane_id.
let mut ids = a.seg_ids.clone();
@ -203,6 +205,7 @@ impl ArtifactGraph {
let grouped = match artifact {
Artifact::Plane(_) => false,
Artifact::Helix(_) => false,
Artifact::Path(_) => {
groups.entry(id).or_insert_with(Vec::new).push(id);
true
@ -276,6 +279,14 @@ impl ArtifactGraph {
code_ref_display(&plane.code_ref)
)?;
}
Artifact::Helix(helix) => {
writeln!(
output,
"{prefix}{}[\"Helix<br>{:?}\"]",
id,
code_ref_display(&helix.code_ref)
)?;
}
Artifact::Path(path) => {
writeln!(
output,
@ -489,6 +500,10 @@ impl ArtifactGraph {
ids_seen.clear();
writeln!(output, "{prefix}Plane")?;
}
Artifact::Helix(_helix) => {
ids_seen.clear();
writeln!(output, "{prefix}Helix")?;
}
Artifact::Path(_path) => {
writeln!(output, "{prefix}Path")?;
}