-
Notifications
You must be signed in to change notification settings - Fork 99
Artifact graph: add link between Sweep::Sweep and trajectory Path or Helix, add Helix from Cylinder to Artifact Graph
#9724
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
base: main
Are you sure you want to change the base?
Changes from all commits
25696f0
f9d18d5
b050094
a63ea57
e6c20f9
da0001e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -351,6 +351,7 @@ pub struct Helix { | |
| /// add axes to the graph. | ||
| pub axis_id: Option<ArtifactId>, | ||
| pub code_ref: CodeRef, | ||
| pub sweep_id: Option<ArtifactId>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS)] | ||
|
|
@@ -459,7 +460,7 @@ impl Artifact { | |
| Artifact::SweepEdge(_) => Some(new), | ||
| Artifact::EdgeCut(a) => a.merge(new), | ||
| Artifact::EdgeCutEdge(_) => Some(new), | ||
| Artifact::Helix(_) => Some(new), | ||
| Artifact::Helix(a) => a.merge(new), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -566,6 +567,18 @@ impl EdgeCut { | |
| } | ||
| } | ||
|
|
||
| impl Helix { | ||
| fn merge(&mut self, new: Artifact) -> Option<Artifact> { | ||
| let Artifact::Helix(new) = new else { | ||
| return Some(new); | ||
| }; | ||
| merge_opt_id(&mut self.axis_id, new.axis_id); | ||
| merge_opt_id(&mut self.sweep_id, new.sweep_id); | ||
|
|
||
| None | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Default, PartialEq, Serialize, ts_rs::TS)] | ||
| #[ts(export_to = "Artifact.ts")] | ||
| #[serde(rename_all = "camelCase")] | ||
|
|
@@ -768,6 +781,7 @@ fn merge_ids(base: &mut Vec<ArtifactId>, new: Vec<ArtifactId>) { | |
| } | ||
| } | ||
|
|
||
| /// Merge optional Artifact ID | ||
| fn merge_opt_id(base: &mut Option<ArtifactId>, new: Option<ArtifactId>) { | ||
| // Always use the new one, even if it clears it. | ||
| *base = new; | ||
|
|
@@ -1024,8 +1038,7 @@ fn artifacts_to_update( | |
| | ModelingCmd::TwistExtrude(kcmc::TwistExtrude { target, .. }) | ||
| | ModelingCmd::Revolve(kcmc::Revolve { target, .. }) | ||
| | ModelingCmd::RevolveAboutEdge(kcmc::RevolveAboutEdge { target, .. }) | ||
| | ModelingCmd::ExtrudeToReference(kcmc::ExtrudeToReference { target, .. }) | ||
| | ModelingCmd::Sweep(kcmc::Sweep { target, .. }) => { | ||
| | ModelingCmd::ExtrudeToReference(kcmc::ExtrudeToReference { target, .. }) => { | ||
| // Determine the resulting method from the specific command, if provided | ||
| let method = match cmd { | ||
| ModelingCmd::Extrude(kcmc::Extrude { extrude_method, .. }) => *extrude_method, | ||
|
|
@@ -1046,7 +1059,6 @@ fn artifacts_to_update( | |
| ModelingCmd::TwistExtrude(_) => SweepSubType::ExtrusionTwist, | ||
| ModelingCmd::Revolve(_) => SweepSubType::Revolve, | ||
| ModelingCmd::RevolveAboutEdge(_) => SweepSubType::RevolveAboutEdge, | ||
| ModelingCmd::Sweep(_) => SweepSubType::Sweep, | ||
| _ => internal_error!(range, "Sweep-like command variant not handled: id={id:?}, cmd={cmd:?}",), | ||
| }; | ||
| let mut return_arr = Vec::new(); | ||
|
|
@@ -1075,6 +1087,52 @@ fn artifacts_to_update( | |
| } | ||
| return Ok(return_arr); | ||
| } | ||
| ModelingCmd::Sweep(kcmc::Sweep { target, trajectory, .. }) => { | ||
| // Determine the resulting method from the specific command, if provided | ||
| let method = kittycad_modeling_cmds::shared::ExtrudeMethod::Merge; | ||
| let sub_type = SweepSubType::Sweep; | ||
| let mut return_arr = Vec::new(); | ||
| let target = ArtifactId::from(target); | ||
| let trajectory = ArtifactId::from(trajectory); | ||
| return_arr.push(Artifact::Sweep(Sweep { | ||
| id, | ||
| sub_type, | ||
| path_id: target, | ||
| surface_ids: Vec::new(), | ||
| edge_ids: Vec::new(), | ||
| code_ref, | ||
| method, | ||
| })); | ||
| let path = artifacts.get(&target); | ||
| if let Some(Artifact::Path(path)) = path { | ||
| let mut new_path = path.clone(); | ||
| new_path.sweep_id = Some(id); | ||
| return_arr.push(Artifact::Path(new_path)); | ||
| if let Some(inner_path_id) = path.inner_path_id | ||
| && let Some(inner_path_artifact) = artifacts.get(&inner_path_id) | ||
| && let Artifact::Path(mut inner_path_artifact) = inner_path_artifact.clone() | ||
| { | ||
| inner_path_artifact.sweep_id = Some(id); | ||
| return_arr.push(Artifact::Path(inner_path_artifact)) | ||
| } | ||
| } | ||
| if let Some(trajectory_artifact) = artifacts.get(&trajectory) { | ||
| match trajectory_artifact { | ||
| Artifact::Path(path) => { | ||
| let mut new_path = path.clone(); | ||
| new_path.sweep_id = Some(id); | ||
|
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. Do we want to do this? It kind of overloads the path's
Contributor
Author
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. Oh okay so would it be more prudent to add a new field that indicates the relationship is a trajectory specifically? The name
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. I think it's more accurately modeling what's happening if we used a new field, yeah. But it all depends on how it's used, which I don't know. |
||
| return_arr.push(Artifact::Path(new_path)); | ||
| } | ||
| Artifact::Helix(helix) => { | ||
| let mut new_helix = helix.clone(); | ||
| new_helix.sweep_id = Some(id); | ||
| return_arr.push(Artifact::Helix(new_helix)); | ||
| } | ||
| _ => {} | ||
| } | ||
| }; | ||
| return Ok(return_arr); | ||
| } | ||
| ModelingCmd::Loft(loft_cmd) => { | ||
| let Some(OkModelingCmdResponse::Loft(_)) = response else { | ||
| return Ok(Vec::new()); | ||
|
|
@@ -1382,11 +1440,22 @@ fn artifacts_to_update( | |
| } | ||
| return Ok(return_arr); | ||
| } | ||
| ModelingCmd::EntityMakeHelix(cmd) => { | ||
| let cylinder_id = ArtifactId::new(cmd.cylinder_id); | ||
| let return_arr = vec![Artifact::Helix(Helix { | ||
| id, | ||
| axis_id: Some(cylinder_id), | ||
| code_ref, | ||
| sweep_id: None, | ||
| })]; | ||
| return Ok(return_arr); | ||
| } | ||
| ModelingCmd::EntityMakeHelixFromParams(_) => { | ||
| let return_arr = vec![Artifact::Helix(Helix { | ||
| id, | ||
| axis_id: None, | ||
| code_ref, | ||
| sweep_id: None, | ||
| })]; | ||
| return Ok(return_arr); | ||
| } | ||
|
|
@@ -1396,6 +1465,7 @@ fn artifacts_to_update( | |
| id, | ||
| axis_id: Some(edge_id), | ||
| code_ref, | ||
| sweep_id: None, | ||
| })]; | ||
| // We could add the reverse graph edge connecting from the edge to | ||
| // the helix here, but it's not useful right now. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -652,6 +652,7 @@ flowchart LR | |
| 110 --- 113 | ||
| 111 --- 112 | ||
| 111 --- 113 | ||
| 114 x--> 119 | ||
| 115 --- 116 | ||
| 116 --- 117 | ||
| 116 --- 118 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.