-
Notifications
You must be signed in to change notification settings - Fork 99
KCL refactor: Solid should not have a Sketch field #9641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adamchalmers
wants to merge
3
commits into
main
Choose a base branch
from
achalmers/sketch-base-codex
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,17 @@ impl<'a> StatementKind<'a> { | |
| } | ||
| } | ||
|
|
||
| fn tags_object_from_map(tags: &IndexMap<String, TagIdentifier>, source_range: SourceRange) -> KclValue { | ||
| KclValue::Object { | ||
| meta: vec![Metadata { source_range }], | ||
| value: tags | ||
| .iter() | ||
| .map(|(k, tag)| (k.to_owned(), KclValue::TagIdentifier(Box::new(tag.to_owned())))) | ||
| .collect(), | ||
| constrainable: false, | ||
| } | ||
| } | ||
|
|
||
| impl ExecutorContext { | ||
| /// Returns true if importing the prelude should be skipped. | ||
| async fn handle_annotations( | ||
|
|
@@ -2016,10 +2027,18 @@ impl Node<MemberExpression> { | |
| vec![self.clone().into()], | ||
| ))) | ||
| } | ||
| (KclValue::Solid { value }, Property::String(prop), false) if prop == "sketch" => Ok(KclValue::Sketch { | ||
| value: Box::new(value.sketch), | ||
| (KclValue::Solid { value }, Property::String(prop), false) if prop == "sketch" => { | ||
| let source_range = SourceRange::from(self.clone()); | ||
| Ok(KclValue::Object { | ||
| meta: vec![Metadata { source_range }], | ||
| value: HashMap::from([( | ||
| "tags".to_owned(), | ||
| tags_object_from_map(&value.sketch.tags, source_range), | ||
| )]), | ||
| constrainable: false, | ||
| } | ||
| .continue_()) | ||
| } | ||
| .continue_()), | ||
| (geometry @ KclValue::Solid { .. }, Property::String(prop), false) if prop == "tags" => { | ||
| // This is a common mistake. | ||
| Err(KclError::new_semantic(KclErrorDetails::new( | ||
|
|
@@ -2030,18 +2049,9 @@ impl Node<MemberExpression> { | |
| vec![self.clone().into()], | ||
| ))) | ||
| } | ||
| (KclValue::Sketch { value: sk }, Property::String(prop), false) if prop == "tags" => Ok(KclValue::Object { | ||
| meta: vec![Metadata { | ||
| source_range: SourceRange::from(self.clone()), | ||
| }], | ||
| value: sk | ||
| .tags | ||
| .iter() | ||
| .map(|(k, tag)| (k.to_owned(), KclValue::TagIdentifier(Box::new(tag.to_owned())))) | ||
| .collect(), | ||
| constrainable: false, | ||
| (KclValue::Sketch { value: sk }, Property::String(prop), false) if prop == "tags" => { | ||
| Ok(tags_object_from_map(&sk.tags, SourceRange::from(self.clone())).continue_()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing about cloning. |
||
| } | ||
| .continue_()), | ||
| (geometry @ (KclValue::Sketch { .. } | KclValue::Solid { .. }), Property::String(property), false) => { | ||
| Err(KclError::new_semantic(KclErrorDetails::new( | ||
| format!("Property `{property}` not found on {}", geometry.human_friendly_type()), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -682,6 +682,62 @@ pub struct Sketch { | |
| pub is_closed: ProfileClosed, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS)] | ||
| #[ts(export)] | ||
| #[serde(tag = "type", rename_all = "camelCase")] | ||
| pub struct SketchBase { | ||
| /// The id of the sketch (this will change when the engine's reference to it changes). | ||
| pub id: uuid::Uuid, | ||
| /// The paths in the sketch. | ||
| /// Only paths on the "outside" i.e. the perimeter. | ||
| /// Does not include paths "inside" the profile (for example, edges made by subtracting a profile) | ||
| pub paths: Vec<Path>, | ||
| /// Inner paths, resulting from subtract2d to carve profiles out of the sketch. | ||
| #[serde(default, skip_serializing_if = "Vec::is_empty")] | ||
| pub inner_paths: Vec<Path>, | ||
| /// What the sketch is on (can be a plane or a face). | ||
| pub on: SketchSurface, | ||
| /// The starting path. | ||
| pub start: BasePath, | ||
| /// Tag identifiers that have been declared in this sketch. | ||
| #[serde(default, skip_serializing_if = "IndexMap::is_empty")] | ||
| pub tags: IndexMap<String, TagIdentifier>, | ||
| /// The original id of the sketch. This stays the same even if the sketch is | ||
| /// is sketched on face etc. | ||
| pub artifact_id: ArtifactId, | ||
| #[ts(skip)] | ||
| pub original_id: uuid::Uuid, | ||
| /// If the sketch includes a mirror. | ||
| #[serde(skip)] | ||
| pub mirror: Option<uuid::Uuid>, | ||
| /// If the sketch is a clone of another sketch. | ||
| #[serde(skip)] | ||
| pub clone: Option<uuid::Uuid>, | ||
| } | ||
|
|
||
| impl From<Sketch> for SketchBase { | ||
| fn from(value: Sketch) -> Self { | ||
| Self { | ||
| id: value.id, | ||
| paths: value.paths, | ||
| inner_paths: value.inner_paths, | ||
| on: value.on, | ||
| start: value.start, | ||
| tags: value.tags, | ||
| artifact_id: value.artifact_id, | ||
| original_id: value.original_id, | ||
| mirror: value.mirror, | ||
| clone: value.clone, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<&Sketch> for SketchBase { | ||
| fn from(value: &Sketch) -> Self { | ||
| value.clone().into() | ||
| } | ||
| } | ||
|
|
||
| impl ProfileClosed { | ||
| #[expect(dead_code, reason = "it's not actually dead, it's called by serde")] | ||
| fn explicitly() -> Self { | ||
|
|
@@ -881,6 +937,63 @@ impl Sketch { | |
| } | ||
| } | ||
|
|
||
| impl SketchBase { | ||
| pub(crate) fn add_tag( | ||
| &mut self, | ||
| tag: NodeRef<'_, TagDeclarator>, | ||
| current_path: &Path, | ||
| exec_state: &ExecState, | ||
| surface: Option<&ExtrudeSurface>, | ||
| ) { | ||
| let mut tag_identifier: TagIdentifier = tag.into(); | ||
| let base = current_path.get_base(); | ||
| tag_identifier.info.push(( | ||
| exec_state.stack().current_epoch(), | ||
| TagEngineInfo { | ||
| id: base.geo_meta.id, | ||
| sketch: self.id, | ||
| path: Some(current_path.clone()), | ||
| surface: surface.cloned(), | ||
| }, | ||
| )); | ||
|
|
||
| self.tags.insert(tag.name.to_string(), tag_identifier); | ||
| } | ||
|
|
||
| pub(crate) fn merge_tags<'a>(&mut self, tags: impl Iterator<Item = &'a TagIdentifier>) { | ||
| for t in tags { | ||
| match self.tags.get_mut(&t.value) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could probably use the Entry API here. |
||
| Some(id) => { | ||
| id.merge_info(t); | ||
| } | ||
| None => { | ||
| self.tags.insert(t.value.clone(), t.clone()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Sketch { | ||
| pub(crate) fn from_base_with_solid_context(base: &SketchBase, solid: &Solid) -> Self { | ||
| Self { | ||
| id: base.id, | ||
| paths: base.paths.clone(), | ||
| inner_paths: base.inner_paths.clone(), | ||
| on: base.on.clone(), | ||
| start: base.start.clone(), | ||
| tags: base.tags.clone(), | ||
| artifact_id: base.artifact_id, | ||
| original_id: base.original_id, | ||
| mirror: base.mirror, | ||
| clone: base.clone, | ||
| units: solid.units, | ||
| meta: solid.meta.clone(), | ||
| is_closed: ProfileClosed::Explicitly, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS)] | ||
| #[ts(export)] | ||
| #[serde(tag = "type", rename_all = "camelCase")] | ||
|
|
@@ -892,7 +1005,7 @@ pub struct Solid { | |
| /// The extrude surfaces. | ||
| pub value: Vec<ExtrudeSurface>, | ||
| /// The sketch. | ||
| pub sketch: Sketch, | ||
| pub sketch: SketchBase, | ||
| /// The id of the extrusion start cap | ||
| pub start_cap_id: Option<uuid::Uuid>, | ||
| /// The id of the extrusion end cap | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to avoid cloning the entire AST node with something like this.