@ -7,8 +7,9 @@ use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
ast::types::TagDeclarator,
|
||||
errors::{KclError, KclErrorDetails},
|
||||
executor::{ExtrudeGroup, MemoryItem},
|
||||
executor::{ExtrudeGroup, ExtrudePlane, ExtrudeSurface, GeoMeta, MemoryItem, Metadata},
|
||||
std::{sketch::FaceTag, Args},
|
||||
};
|
||||
|
||||
@ -25,9 +26,10 @@ pub struct ShellData {
|
||||
|
||||
/// Create a shell.
|
||||
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))
|
||||
}
|
||||
|
||||
@ -48,12 +50,32 @@ pub async fn shell(args: Args) -> Result<MemoryItem, KclError> {
|
||||
/// thickness: 0.25,
|
||||
/// }, 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 {
|
||||
name = "shell",
|
||||
}]
|
||||
async fn inner_shell(
|
||||
data: ShellData,
|
||||
extrude_group: Box<ExtrudeGroup>,
|
||||
tag: Option<TagDeclarator>,
|
||||
args: Args,
|
||||
) -> Result<Box<ExtrudeGroup>, KclError> {
|
||||
if data.faces.is_empty() {
|
||||
@ -64,8 +86,8 @@ async fn inner_shell(
|
||||
}
|
||||
|
||||
let mut face_ids = Vec::new();
|
||||
for tag in data.faces {
|
||||
let extrude_plane_id = tag.get_face_id(&extrude_group, &args, false).await?;
|
||||
for face_tag in data.faces {
|
||||
let extrude_plane_id = face_tag.get_face_id(&extrude_group, &args, false).await?;
|
||||
|
||||
face_ids.push(extrude_plane_id);
|
||||
}
|
||||
@ -77,8 +99,9 @@ async fn inner_shell(
|
||||
}));
|
||||
}
|
||||
|
||||
let id = uuid::Uuid::new_v4();
|
||||
args.batch_modeling_cmd(
|
||||
uuid::Uuid::new_v4(),
|
||||
id,
|
||||
ModelingCmd::Solid3DShellFace {
|
||||
face_ids,
|
||||
object_id: extrude_group.id,
|
||||
@ -87,5 +110,17 @@ async fn inner_shell(
|
||||
)
|
||||
.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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user