lint default planes and add a suggestion (#6587)

lint default planes and other plane cleanup

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2025-04-29 19:11:02 -07:00
committed by GitHub
parent bf63b21d74
commit 9c29756a38
123 changed files with 14097 additions and 13997 deletions

View File

@ -15,8 +15,8 @@ use crate::{
execution::{
kcl_value::FunctionSource,
types::{NumericType, PrimitiveType, RuntimeType, UnitAngle, UnitLen, UnitType},
ExecState, ExecutorContext, ExtrudeSurface, Helix, KclObjectFields, KclValue, Metadata, Sketch, SketchSurface,
Solid, TagIdentifier,
ExecState, ExecutorContext, ExtrudeSurface, Helix, KclObjectFields, KclValue, Metadata, PlaneInfo, Sketch,
SketchSurface, Solid, TagIdentifier,
},
parsing::ast::types::TagNode,
source_range::SourceRange,
@ -984,11 +984,11 @@ impl<'a> FromKclValue<'a> for super::sketch::PlaneData {
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
// Case 0: actual plane
if let KclValue::Plane { value } = arg {
return Some(Self::Plane {
origin: value.origin,
x_axis: value.x_axis,
y_axis: value.y_axis,
});
return Some(Self::Plane(PlaneInfo {
origin: value.info.origin,
x_axis: value.info.x_axis,
y_axis: value.info.y_axis,
}));
}
// Case 1: predefined plane
if let Some(s) = arg.as_str() {
@ -1008,7 +1008,7 @@ impl<'a> FromKclValue<'a> for super::sketch::PlaneData {
let origin = plane.get("origin").and_then(FromKclValue::from_kcl_val)?;
let x_axis = plane.get("xAxis").and_then(FromKclValue::from_kcl_val)?;
let y_axis = plane.get("yAxis").and_then(FromKclValue::from_kcl_val)?;
Some(Self::Plane { origin, x_axis, y_axis })
Some(Self::Plane(PlaneInfo { origin, x_axis, y_axis }))
}
}

View File

@ -24,13 +24,13 @@ async fn inner_offset_plane(
exec_state: &mut ExecState,
args: &Args,
) -> Result<Plane, KclError> {
let mut plane = Plane::from_plane_data(plane, exec_state);
let mut plane = Plane::from_plane_data(plane, exec_state)?;
// Though offset planes might be derived from standard planes, they are not
// standard planes themselves.
plane.value = PlaneType::Custom;
let normal = plane.x_axis.axes_cross_product(&plane.y_axis);
plane.origin += normal * offset.to_length_units(plane.origin.units);
let normal = plane.info.x_axis.axes_cross_product(&plane.info.y_axis);
plane.info.origin += normal * offset.to_length_units(plane.info.origin.units);
make_offset_plane_in_engine(&plane, exec_state, args).await?;
Ok(plane)
@ -53,10 +53,10 @@ async fn make_offset_plane_in_engine(plane: &Plane, exec_state: &mut ExecState,
plane.id,
ModelingCmd::from(mcmd::MakePlane {
clobber: false,
origin: plane.origin.into(),
origin: plane.info.origin.into(),
size: LengthUnit(default_size),
x_axis: plane.x_axis.into(),
y_axis: plane.y_axis.into(),
x_axis: plane.info.x_axis.into(),
y_axis: plane.info.y_axis.into(),
hide: Some(false),
}),
)

View File

@ -18,7 +18,7 @@ use crate::{
errors::{KclError, KclErrorDetails},
execution::{
types::{ArrayLen, NumericType, PrimitiveType, RuntimeType, UnitLen},
BasePath, ExecState, Face, GeoMeta, KclValue, Path, Plane, Point2d, Point3d, Sketch, SketchSurface, Solid,
BasePath, ExecState, Face, GeoMeta, KclValue, Path, Plane, PlaneInfo, Point2d, Sketch, SketchSurface, Solid,
TagEngineInfo, TagIdentifier,
},
parsing::ast::types::TagNode,
@ -953,16 +953,7 @@ pub enum PlaneData {
#[serde(rename = "-YZ", alias = "-yz")]
NegYZ,
/// A defined plane.
Plane {
/// Origin of the plane.
origin: Point3d,
/// What should the planes X axis be?
#[serde(rename = "xAxis")]
x_axis: Point3d,
/// What should the planes Y axis be?
#[serde(rename = "yAxis")]
y_axis: Point3d,
},
Plane(PlaneInfo),
}
/// Start a sketch on a specific plane or face.
@ -1177,13 +1168,13 @@ async fn inner_start_sketch_on(
}
SketchData::Plane(plane) => {
if plane.value == crate::exec::PlaneType::Uninit {
if plane.origin.units == UnitLen::Unknown {
if plane.info.origin.units == UnitLen::Unknown {
return Err(KclError::Semantic(KclErrorDetails {
message: "Origin of plane has unknown units".to_string(),
source_ranges: vec![args.source_range],
}));
}
let plane = make_sketch_plane_from_orientation(plane.into_plane_data(), exec_state, args).await?;
let plane = make_sketch_plane_from_orientation(plane.info.into_plane_data(), exec_state, args).await?;
Ok(SketchSurface::Plane(plane))
} else {
// Create artifact used only by the UI, not the engine.
@ -1252,7 +1243,7 @@ async fn make_sketch_plane_from_orientation(
exec_state: &mut ExecState,
args: &Args,
) -> Result<Box<Plane>, KclError> {
let plane = Plane::from_plane_data(data.clone(), exec_state);
let plane = Plane::from_plane_data(data.clone(), exec_state)?;
// Create the plane on the fly.
let clobber = false;
@ -1262,10 +1253,10 @@ async fn make_sketch_plane_from_orientation(
plane.id,
ModelingCmd::from(mcmd::MakePlane {
clobber,
origin: plane.origin.into(),
origin: plane.info.origin.into(),
size,
x_axis: plane.x_axis.into(),
y_axis: plane.y_axis.into(),
x_axis: plane.info.x_axis.into(),
y_axis: plane.info.y_axis.into(),
hide,
}),
)
@ -1374,7 +1365,7 @@ pub(crate) async fn inner_start_profile(
adjust_camera: false,
planar_normal: if let SketchSurface::Plane(plane) = &sketch_surface {
// We pass in the normal for the plane here.
let normal = plane.x_axis.axes_cross_product(&plane.y_axis);
let normal = plane.info.x_axis.axes_cross_product(&plane.info.y_axis);
Some(normal.into())
} else {
None