kittycad_modeling_cmds/format/
stl.rs

1use parse_display::{Display, FromStr};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5use crate::{coord, format::Selection, units::UnitLength};
6
7/// Import models in STL format.
8pub mod import {
9    use super::*;
10
11    /// Options for importing STL.
12    #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
13    #[display("coords: {coords}, units: {units}")]
14    #[serde(rename = "StlImportOptions")]
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        /// Co-ordinate system of input data.
19        ///
20        /// Defaults to the [KittyCAD co-ordinate system].
21        ///
22        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
23        pub coords: coord::System,
24        /// The units of the input data.
25        ///
26        /// This is very important for correct scaling and when calculating physics properties like
27        /// mass, etc.
28        ///
29        /// Defaults to millimeters.
30        pub units: UnitLength,
31    }
32
33    impl Default for Options {
34        fn default() -> Self {
35            Self {
36                coords: *coord::KITTYCAD,
37                units: UnitLength::Millimeters,
38            }
39        }
40    }
41}
42
43/// Export models in STL format.
44pub mod export {
45
46    use super::*;
47
48    /// Options for exporting STL.
49    #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
50    #[display("coords: {coords}, selection: {selection}, storage: {storage}, units: {units}")]
51    #[serde(rename = "StlExportOptions")]
52    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
53    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
54    pub struct Options {
55        /// Co-ordinate system of output data.
56        ///
57        /// Defaults to the [KittyCAD co-ordinate system].
58        ///
59        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
60        pub coords: coord::System,
61
62        /// Export selection.
63        pub selection: Selection,
64
65        /// Export storage.
66        pub storage: Storage,
67
68        /// Export length unit.
69        ///
70        /// Defaults to millimeters.
71        pub units: UnitLength,
72    }
73
74    impl Default for Options {
75        fn default() -> Self {
76            Self {
77                coords: *coord::KITTYCAD,
78                selection: Default::default(),
79                storage: Default::default(),
80                units: UnitLength::Millimeters,
81            }
82        }
83    }
84
85    /// Export storage.
86    #[derive(
87        Clone, Copy, Debug, Default, Deserialize, Display, Eq, FromStr, Hash, JsonSchema, PartialEq, Serialize,
88    )]
89    #[display(style = "snake_case")]
90    #[serde(rename = "StlStorage", rename_all = "snake_case")]
91    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
92    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
93    pub enum Storage {
94        /// Plaintext encoding.
95        Ascii,
96
97        /// Binary STL encoding.
98        ///
99        /// This is the default setting.
100        #[default]
101        Binary,
102    }
103}