Skip to content
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

Add input co-ordinates to STEP import options #732

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 14 additions & 6 deletions modeling-cmds/src/convert_client_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@ mod format {
InputFormat::Sldprt(sldprt::import::Options { split_closed_faces }) => {
kt::InputFormat::Sldprt { split_closed_faces }
}
InputFormat::Step(step::import::Options { split_closed_faces }) => {
kt::InputFormat::Step { split_closed_faces }
}
InputFormat::Step(step::import::Options {
coords,
split_closed_faces,
}) => kt::InputFormat::Step {
coords,
split_closed_faces,
},
InputFormat::Stl(stl::import::Options { coords, units }) => kt::InputFormat::Stl {
coords: coords.into(),
units: units.into(),
Expand All @@ -168,9 +172,13 @@ mod format {
kt::InputFormat::Sldprt { split_closed_faces } => {
Self::Sldprt(crate::format::sldprt::import::Options { split_closed_faces })
}
kt::InputFormat::Step { split_closed_faces } => {
Self::Step(crate::format::step::import::Options { split_closed_faces })
}
kt::InputFormat::Step {
coords,
split_closed_faces,
} => Self::Step(crate::format::step::import::Options {
coords,
split_closed_faces,
}),
kt::InputFormat::Stl { coords, units } => Self::Stl(crate::format::stl::import::Options {
coords: coords.into(),
units: units.into(),
Expand Down
9 changes: 6 additions & 3 deletions modeling-cmds/src/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,13 @@ pub const VULKAN: &System = &System {
/// assert_eq!(b, [1.0, -2.0, 3.0]);
/// ```
#[inline]
pub fn transform(a: [f32; 3], from: &System, to: &System) -> [f32; 3] {
pub fn transform<T>(a: [T; 3], from: &System, to: &System) -> [T; 3]
where
T: Copy + From<i32> + std::ops::Mul<Output = T>,
{
let mut b = a;
b[to.forward.axis as usize] =
(from.forward.direction * to.forward.direction) as i32 as f32 * a[from.forward.axis as usize];
b[to.up.axis as usize] = (from.up.direction * to.up.direction) as i32 as f32 * a[from.up.axis as usize];
T::from((from.forward.direction * to.forward.direction) as i32) * a[from.forward.axis as usize];
b[to.up.axis as usize] = T::from((from.up.direction * to.up.direction) as i32) * a[from.up.axis as usize];
b
}
20 changes: 18 additions & 2 deletions modeling-cmds/src/format/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,33 @@ pub mod import {
use super::*;

/// Options for importing STEP format.
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("split_closed_faces: {split_closed_faces}")]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("coords: {coords}, split_closed_faces: {split_closed_faces}")]
#[serde(default, rename = "StepImportOptions")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct Options {
/// Co-ordinate system of input data.
///
/// Defaults to the [KittyCAD co-ordinate system].
///
/// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
pub coords: coord::System,

/// Splits all closed faces into two open faces.
///
/// Defaults to `false` but is implicitly `true` when importing into the engine.
pub split_closed_faces: bool,
}

impl Default for Options {
fn default() -> Self {
Self {
coords: *coord::KITTYCAD,
split_closed_faces: false,
}
}
}
}

/// Export models in STEP format.
Expand Down
Loading