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    pub struct Options {
18        /// Splits all closed faces into two open faces.
19        ///
20        /// Defaults to `false` but is implicitly `true` when importing into the engine.
21        pub split_closed_faces: bool,
22    }
23}
24
25/// Export models in STEP format.
26pub mod export {
27    use super::*;
28
29    /// Options for exporting STEP format.
30    #[derive(Clone, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)]
31    #[serde(rename = "StepExportOptions")]
32    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
33    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
34    pub struct Options {
35        /// Co-ordinate system of output data.
36        ///
37        /// Defaults to the [KittyCAD co-ordinate system].
38        ///
39        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
40        pub coords: coord::System,
41
42        /// Timestamp override.
43        pub created: Option<chrono::DateTime<chrono::Utc>>,
44    }
45
46    impl Default for Options {
47        fn default() -> Self {
48            Self {
49                coords: *coord::KITTYCAD,
50                created: None,
51            }
52        }
53    }
54
55    impl std::fmt::Display for Options {
56        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
57            write!(f, "coords: {}", self.coords)
58        }
59    }
60
61    impl std::str::FromStr for Options {
62        type Err = <coord::System as std::str::FromStr>::Err;
63        fn from_str(s: &str) -> Result<Self, Self::Err> {
64            Ok(Self {
65                coords: <coord::System as std::str::FromStr>::from_str(s)?,
66                created: None,
67            })
68        }
69    }
70}