Skip to main content

kittycad_modeling_cmds/format/
step.rs

1use bon::Builder;
2use parse_display::{Display, FromStr};
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::coord;
7
8/// Import models in STEP format.
9pub mod import {
10    use super::*;
11
12    /// Options for importing STEP format.
13    #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
14    #[serde(default, rename = "StepImportOptions")]
15    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
16    #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
17    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
18    #[cfg_attr(
19        feature = "python",
20        pyo3_stub_gen::derive::gen_stub_pyclass,
21        pyo3::pyclass(name = "StepImportOptions")
22    )]
23    #[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
24    pub struct Options {
25        /// Co-ordinate system of input data.
26        ///
27        /// Defaults to the [KittyCAD co-ordinate system].
28        ///
29        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
30        #[builder(default = *coord::KITTYCAD)]
31        pub coords: coord::System,
32
33        /// Splits all closed faces into two open faces.
34        ///
35        /// Defaults to `false` but is implicitly `true` when importing into the engine.
36        #[builder(default)]
37        pub split_closed_faces: bool,
38    }
39
40    #[cfg(feature = "python")]
41    #[pyo3_stub_gen::derive::gen_stub_pymethods]
42    #[pyo3::pymethods]
43    impl Options {
44        #[new]
45        /// Set the options to their defaults.
46        pub fn new() -> Self {
47            Default::default()
48        }
49    }
50
51    impl Default for Options {
52        fn default() -> Self {
53            Self {
54                coords: *coord::KITTYCAD,
55                split_closed_faces: false,
56            }
57        }
58    }
59}
60
61/// Export models in STEP format.
62pub mod export {
63    use super::*;
64    use crate::units::UnitLength;
65
66    /// Describes the presentation style of the EXPRESS exchange format.
67    #[derive(
68        Default, Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
69    )]
70    #[display(style = "snake_case")]
71    #[serde(rename = "StepPresentation", rename_all = "snake_case")]
72    #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
73    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
74    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
75    #[cfg_attr(
76        feature = "python",
77        pyo3_stub_gen::derive::gen_stub_pyclass_enum,
78        pyo3::pyclass(name = "StepPresentation")
79    )]
80    #[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
81    pub enum Presentation {
82        /// Condenses the text to reduce the size of the file.
83        Compact,
84
85        /// Add extra spaces to make the text more easily readable.
86        ///
87        /// This is the default setting.
88        #[default]
89        Pretty,
90    }
91
92    /// Options for exporting STEP format.
93    #[derive(Clone, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize, Builder)]
94    #[serde(default, rename = "StepExportOptions")]
95    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
96    #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
97    #[cfg_attr(
98        feature = "python",
99        pyo3_stub_gen::derive::gen_stub_pyclass,
100        pyo3::pyclass(name = "StepExportOptions")
101    )]
102    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
103    #[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
104    pub struct Options {
105        /// Co-ordinate system of output data.
106        ///
107        /// Defaults to the [KittyCAD co-ordinate system].
108        ///
109        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
110        #[builder(default = default_coords())]
111        pub coords: coord::System,
112
113        /// Timestamp override.
114        pub created: Option<chrono::DateTime<chrono::Utc>>,
115
116        /// Export length unit.
117        ///
118        /// Defaults to meters.
119        #[builder(default = default_units())]
120        pub units: UnitLength,
121
122        /// Presentation style.
123        #[builder(default = default_presentation())]
124        pub presentation: Presentation,
125    }
126
127    #[cfg(feature = "python")]
128    #[pyo3_stub_gen::derive::gen_stub_pymethods]
129    #[pyo3::pymethods]
130    impl Options {
131        #[new]
132        /// Set the options to their defaults.
133        pub fn new() -> Self {
134            Default::default()
135        }
136    }
137
138    impl Default for Options {
139        fn default() -> Self {
140            Self {
141                coords: default_coords(),
142                created: None,
143                units: default_units(),
144                presentation: default_presentation(),
145            }
146        }
147    }
148
149    const fn default_presentation() -> Presentation {
150        Presentation::Pretty
151    }
152
153    const fn default_coords() -> coord::System {
154        *coord::KITTYCAD
155    }
156
157    const fn default_units() -> UnitLength {
158        UnitLength::Meters
159    }
160}