Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified public/kcl-samples/screenshots/bracket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/kcl-samples/screenshots/dodecahedron.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/kcl-samples/screenshots/dual-basin-utility-sink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/kcl-samples/screenshots/flange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/kcl-samples/screenshots/sheet-metal-bracket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 63 additions & 13 deletions rust/kcl-lib/src/execution/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ pub struct CompositeSolid {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub tool_ids: Vec<ArtifactId>,
pub code_ref: CodeRef,
/// This is the ID of the composite solid that this is part of, if any, as a
/// composite solid can be used as input for another composite solid.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub composite_solid_id: Option<ArtifactId>,
}

#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq, ts_rs::TS)]
Expand Down Expand Up @@ -182,6 +186,10 @@ pub struct Path {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub solid2d_id: Option<ArtifactId>,
pub code_ref: CodeRef,
/// This is the ID of the composite solid that this is part of, if any, as
/// this can be used as input for another composite solid.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub composite_solid_id: Option<ArtifactId>,
}

#[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS)]
Expand Down Expand Up @@ -585,6 +593,7 @@ impl CompositeSolid {
};
merge_ids(&mut self.solid_ids, new.solid_ids);
merge_ids(&mut self.tool_ids, new.tool_ids);
merge_opt_id(&mut self.composite_solid_id, new.composite_solid_id);

None
}
Expand All @@ -609,6 +618,7 @@ impl Path {
merge_opt_id(&mut self.sweep_id, new.sweep_id);
merge_ids(&mut self.seg_ids, new.seg_ids);
merge_opt_id(&mut self.solid2d_id, new.solid2d_id);
merge_opt_id(&mut self.composite_solid_id, new.composite_solid_id);

None
}
Expand Down Expand Up @@ -921,6 +931,7 @@ fn artifacts_to_update(
sweep_id: None,
solid2d_id: None,
code_ref,
composite_solid_id: None,
}));
let plane = artifacts.get(&ArtifactId::new(*current_plane_id));
if let Some(Artifact::Plane(plane)) = plane {
Expand Down Expand Up @@ -1359,20 +1370,59 @@ fn artifacts_to_update(
.for_each(|id| new_solid_ids.push(id)),
_ => {}
}
let return_arr = new_solid_ids
.into_iter()
.map(|solid_id| {
Artifact::CompositeSolid(CompositeSolid {
id: solid_id,
sub_type,
solid_ids: solid_ids.clone(),
tool_ids: tool_ids.clone(),
code_ref: code_ref.clone(),
})
})
.collect::<Vec<_>>();

// TODO: Should we add the reverse graph edges?
let mut return_arr = Vec::new();

// Create the new composite solids and update their linked artifacts
for solid_id in &new_solid_ids {
// Create the composite solid
return_arr.push(Artifact::CompositeSolid(CompositeSolid {
id: *solid_id,
sub_type,
solid_ids: solid_ids.clone(),
tool_ids: tool_ids.clone(),
code_ref: code_ref.clone(),
composite_solid_id: None,
}));

// Update the artifacts that were used as input for this composite solid
for input_id in &solid_ids {
if let Some(artifact) = artifacts.get(input_id) {
match artifact {
Artifact::CompositeSolid(comp) => {
let mut new_comp = comp.clone();
new_comp.composite_solid_id = Some(*solid_id);
return_arr.push(Artifact::CompositeSolid(new_comp));
}
Artifact::Path(path) => {
let mut new_path = path.clone();
new_path.composite_solid_id = Some(*solid_id);
return_arr.push(Artifact::Path(new_path));
}
_ => {}
}
}
}

// Update the tool artifacts if this is a subtract operation
for tool_id in &tool_ids {
if let Some(artifact) = artifacts.get(tool_id) {
match artifact {
Artifact::CompositeSolid(comp) => {
let mut new_comp = comp.clone();
new_comp.composite_solid_id = Some(*solid_id);
return_arr.push(Artifact::CompositeSolid(new_comp));
}
Artifact::Path(path) => {
let mut new_path = path.clone();
new_path.composite_solid_id = Some(*solid_id);
return_arr.push(Artifact::Path(new_path));
}
_ => {}
}
}
}
}

return Ok(return_arr);
}
Expand Down
11 changes: 9 additions & 2 deletions rust/kcl-lib/src/execution/artifact/mermaid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ impl Artifact {
/// the graph.
pub(crate) fn child_ids(&self) -> Vec<ArtifactId> {
match self {
Artifact::CompositeSolid(_) => {
Artifact::CompositeSolid(a) => {
// Note: Don't include these since they're parents: solid_ids,
// tool_ids.
Vec::new()
let mut ids = Vec::new();
if let Some(composite_solid_id) = a.composite_solid_id {
ids.push(composite_solid_id);
}
ids
}
Artifact::Plane(a) => a.path_ids.clone(),
Artifact::Path(a) => {
Expand All @@ -107,6 +111,9 @@ impl Artifact {
if let Some(solid2d_id) = a.solid2d_id {
ids.push(solid2d_id);
}
if let Some(composite_solid_id) = a.composite_solid_id {
ids.push(composite_solid_id);
}
ids
}
Artifact::Segment(a) => {
Expand Down
Binary file modified rust/kcl-lib/tests/import_transform/rendered_model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ flowchart LR
3 --- 11
3 --- 13
3 ---- 16
3 <--x 17
3 --- 17
4 --- 6
4 --- 7
4 --- 9
4 --- 12
4 --- 14
4 ---- 15
4 <--x 17
4 --- 17
5 --- 24
5 x--> 26
5 --- 35
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,84 +317,84 @@ flowchart LR
13 --- 67
13 --- 73
13 ---- 90
13 <--x 106
13 --- 106
14 --- 27
14 --- 45
14 --- 50
14 --- 65
14 --- 74
14 ---- 92
14 <--x 101
14 --- 101
15 --- 32
15 --- 48
15 --- 51
15 --- 71
15 --- 75
15 ---- 93
15 <--x 99
15 --- 99
16 --- 29
16 --- 40
16 --- 56
16 --- 69
16 --- 76
16 ---- 96
16 <--x 100
16 --- 100
17 --- 26
17 --- 44
17 --- 52
17 --- 63
17 --- 77
17 ---- 95
17 <--x 105
17 --- 105
18 --- 28
18 --- 47
18 --- 58
18 --- 64
18 --- 78
18 ---- 94
18 <--x 102
18 --- 102
19 --- 35
19 --- 41
19 --- 57
19 --- 66
19 --- 79
19 ---- 89
19 <--x 98
19 --- 98
20 --- 34
20 --- 42
20 --- 55
20 --- 68
20 --- 80
20 ---- 87
20 <--x 104
20 --- 104
21 --- 30
21 --- 39
21 --- 60
21 --- 70
21 --- 81
21 ---- 91
21 <--x 103
21 --- 103
22 --- 25
22 --- 46
22 --- 54
22 --- 72
22 --- 82
22 ---- 88
22 <--x 104
22 --- 104
23 --- 36
23 --- 37
23 --- 49
23 --- 62
23 --- 83
23 ---- 86
23 <--x 107
23 --- 107
24 --- 33
24 --- 43
24 --- 53
24 --- 61
24 --- 84
24 ---- 85
24 <--x 97
24 --- 97
25 --- 120
25 x--> 158
25 --- 193
Expand Down Expand Up @@ -755,16 +755,16 @@ flowchart LR
96 --- 273
96 --- 274
96 --- 275
97 <--x 98
99 x--> 97
98 <--x 103
105 x--> 99
104 x--> 100
100 <--x 107
101 <--x 102
103 x--> 101
106 x--> 105
107 x--> 106
97 --- 98
99 --- 97
98 --- 103
105 --- 99
104 --- 100
100 --- 107
101 --- 102
103 --- 101
106 --- 105
107 --- 106
182 <--x 108
230 <--x 108
231 <--x 108
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ flowchart LR
83 --- 246
83 --- 289
90 --- 159
90 x--> 193
90 x--> 192
90 --- 226
90 --- 271
104 --- 151
Expand Down Expand Up @@ -910,7 +910,7 @@ flowchart LR
211 <--x 191
212 <--x 191
213 <--x 191
226 <--x 192
226 <--x 193
239 <--x 195
240 <--x 195
241 <--x 195
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ flowchart LR
115 --- 179
115 x--> 228
115 --- 256
115 x--> 307
115 --- 308
164 <--x 116
116 --- 184
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ flowchart LR
3 --- 8
3 --- 11
3 ---- 12
3 <--x 14
3 --- 14
4 --- 9
4 --- 10
4 ---- 13
4 <--x 14
4 --- 14
5 --- 18
5 x--> 21
5 --- 25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ flowchart LR
3 --- 11
3 --- 13
3 ---- 16
3 <--x 17
3 --- 17
4 --- 6
4 --- 7
4 --- 9
4 --- 12
4 --- 14
4 ---- 15
4 <--x 17
4 --- 17
5 --- 24
5 x--> 26
5 --- 35
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ flowchart LR
3 --- 11
3 --- 13
3 ---- 16
3 <--x 17
3 --- 17
4 --- 6
4 --- 7
4 --- 9
4 --- 12
4 --- 14
4 ---- 15
4 <--x 17
4 --- 17
5 --- 24
5 x--> 26
5 --- 35
Expand Down
Loading