kittycad_modeling_cmds/format/
step.rs

1use parse_display::{Display, FromStr};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5use crate::coord;
6
7/// Import models in STEP format.
8pub mod import {
9    use super::*;
10
11    /// Options for importing STEP format.
12    #[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
13    #[display("split_closed_faces: {split_closed_faces}")]
14    #[serde(default, rename = "StepImportOptions")]
15    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
16    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
17    #[cfg_attr(
18        feature = "python",
19        pyo3_stub_gen::derive::gen_stub_pyclass,
20        pyo3::pyclass(name = "StepImportOptions")
21    )]
22    pub struct Options {
23        /// Splits all closed faces into two open faces.
24        ///
25        /// Defaults to `false` but is implicitly `true` when importing into the engine.
26        pub split_closed_faces: bool,
27    }
28
29    #[cfg(feature = "python")]
30    #[pyo3_stub_gen::derive::gen_stub_pymethods]
31    #[pyo3::pymethods]
32    impl Options {
33        #[new]
34        /// Set the options to their defaults.
35        pub fn new() -> Self {
36            Default::default()
37        }
38    }
39}
40
41/// Export models in STEP format.
42pub mod export {
43    use super::*;
44
45    /// Options for exporting STEP format.
46    #[derive(Clone, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)]
47    #[serde(rename = "StepExportOptions")]
48    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
49    #[cfg_attr(
50        feature = "python",
51        pyo3_stub_gen::derive::gen_stub_pyclass,
52        pyo3::pyclass(name = "StepExportOptions")
53    )]
54    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
55    pub struct Options {
56        /// Co-ordinate system of output data.
57        ///
58        /// Defaults to the [KittyCAD co-ordinate system].
59        ///
60        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
61        pub coords: coord::System,
62
63        /// Timestamp override.
64        pub created: Option<chrono::DateTime<chrono::Utc>>,
65    }
66
67    #[cfg(feature = "python")]
68    #[pyo3_stub_gen::derive::gen_stub_pymethods]
69    #[pyo3::pymethods]
70    impl Options {
71        #[new]
72        /// Set the options to their defaults.
73        pub fn new() -> Self {
74            Default::default()
75        }
76    }
77
78    impl Default for Options {
79        fn default() -> Self {
80            Self {
81                coords: *coord::KITTYCAD,
82                created: None,
83            }
84        }
85    }
86
87    impl std::fmt::Display for Options {
88        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
89            write!(f, "coords: {}", self.coords)
90        }
91    }
92
93    impl std::str::FromStr for Options {
94        type Err = <coord::System as std::str::FromStr>::Err;
95        fn from_str(s: &str) -> Result<Self, Self::Err> {
96            Ok(Self {
97                coords: <coord::System as std::str::FromStr>::from_str(s)?,
98                created: None,
99            })
100        }
101    }
102}