@ -7,8 +7,9 @@ use schemars::JsonSchema;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
ast::types::TagDeclarator,
|
||||||
errors::{KclError, KclErrorDetails},
|
errors::{KclError, KclErrorDetails},
|
||||||
executor::{ExtrudeGroup, MemoryItem},
|
executor::{ExtrudeGroup, ExtrudePlane, ExtrudeSurface, GeoMeta, MemoryItem, Metadata},
|
||||||
std::{sketch::FaceTag, Args},
|
std::{sketch::FaceTag, Args},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -25,9 +26,10 @@ pub struct ShellData {
|
|||||||
|
|
||||||
/// Create a shell.
|
/// Create a shell.
|
||||||
pub async fn shell(args: Args) -> Result<MemoryItem, KclError> {
|
pub async fn shell(args: Args) -> Result<MemoryItem, KclError> {
|
||||||
let (data, extrude_group): (ShellData, Box<ExtrudeGroup>) = args.get_data_and_extrude_group()?;
|
let (data, extrude_group, tag): (ShellData, Box<ExtrudeGroup>, Option<TagDeclarator>) =
|
||||||
|
args.get_data_and_extrude_group_and_tag()?;
|
||||||
|
|
||||||
let extrude_group = inner_shell(data, extrude_group, args).await?;
|
let extrude_group = inner_shell(data, extrude_group, tag, args).await?;
|
||||||
Ok(MemoryItem::ExtrudeGroup(extrude_group))
|
Ok(MemoryItem::ExtrudeGroup(extrude_group))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,12 +50,32 @@ pub async fn shell(args: Args) -> Result<MemoryItem, KclError> {
|
|||||||
/// thickness: 0.25,
|
/// thickness: 0.25,
|
||||||
/// }, firstSketch)
|
/// }, firstSketch)
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// ```no_run
|
||||||
|
/// const firstSketch = startSketchOn('XY')
|
||||||
|
/// |> startProfileAt([-12, 12], %)
|
||||||
|
/// |> line([24, 0], %)
|
||||||
|
/// |> line([0, -24], %)
|
||||||
|
/// |> line([-24, 0], %)
|
||||||
|
/// |> close(%)
|
||||||
|
/// |> extrude(6, %)
|
||||||
|
/// |> shell({
|
||||||
|
/// faces: ['end'],
|
||||||
|
/// thickness: 0.25,
|
||||||
|
/// }, %, $shellFace)
|
||||||
|
///
|
||||||
|
/// // Sketch on the inside of the shell.
|
||||||
|
/// startSketchOn(firstSketch, shellFace)
|
||||||
|
/// |> circle([0, 0], 6, %)
|
||||||
|
/// |> extrude(6, %)
|
||||||
|
/// ```
|
||||||
#[stdlib {
|
#[stdlib {
|
||||||
name = "shell",
|
name = "shell",
|
||||||
}]
|
}]
|
||||||
async fn inner_shell(
|
async fn inner_shell(
|
||||||
data: ShellData,
|
data: ShellData,
|
||||||
extrude_group: Box<ExtrudeGroup>,
|
extrude_group: Box<ExtrudeGroup>,
|
||||||
|
tag: Option<TagDeclarator>,
|
||||||
args: Args,
|
args: Args,
|
||||||
) -> Result<Box<ExtrudeGroup>, KclError> {
|
) -> Result<Box<ExtrudeGroup>, KclError> {
|
||||||
if data.faces.is_empty() {
|
if data.faces.is_empty() {
|
||||||
@ -64,8 +86,8 @@ async fn inner_shell(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut face_ids = Vec::new();
|
let mut face_ids = Vec::new();
|
||||||
for tag in data.faces {
|
for face_tag in data.faces {
|
||||||
let extrude_plane_id = tag.get_face_id(&extrude_group, &args, false).await?;
|
let extrude_plane_id = face_tag.get_face_id(&extrude_group, &args, false).await?;
|
||||||
|
|
||||||
face_ids.push(extrude_plane_id);
|
face_ids.push(extrude_plane_id);
|
||||||
}
|
}
|
||||||
@ -77,8 +99,9 @@ async fn inner_shell(
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let id = uuid::Uuid::new_v4();
|
||||||
args.batch_modeling_cmd(
|
args.batch_modeling_cmd(
|
||||||
uuid::Uuid::new_v4(),
|
id,
|
||||||
ModelingCmd::Solid3DShellFace {
|
ModelingCmd::Solid3DShellFace {
|
||||||
face_ids,
|
face_ids,
|
||||||
object_id: extrude_group.id,
|
object_id: extrude_group.id,
|
||||||
@ -87,5 +110,17 @@ async fn inner_shell(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let mut extrude_group = extrude_group.clone();
|
||||||
|
extrude_group.value.push(ExtrudeSurface::ExtrudePlane(ExtrudePlane {
|
||||||
|
face_id: id,
|
||||||
|
tag,
|
||||||
|
geo_meta: GeoMeta {
|
||||||
|
id,
|
||||||
|
metadata: Metadata {
|
||||||
|
source_range: args.source_range,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
Ok(extrude_group)
|
Ok(extrude_group)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user