kittycad_modeling_cmds/format/
ply.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 PLY format.
8pub mod import {
9    use super::*;
10
11    /// Options for importing PLY.
12    #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
13    #[display("coords: {coords}, units: {units}")]
14    #[serde(rename = "PlyImportOptions")]
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 = "PlyImportOptions")
21    )]
22    pub struct Options {
23        /// Co-ordinate system of input data.
24        ///
25        /// Defaults to the [KittyCAD co-ordinate system].
26        ///
27        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
28        pub coords: coord::System,
29
30        /// The units of the input data.
31        ///
32        /// This is very important for correct scaling and when calculating physics properties like
33        /// mass, etc.
34        ///
35        /// Defaults to millimeters.
36        pub units: UnitLength,
37    }
38
39    #[cfg(feature = "python")]
40    #[pyo3_stub_gen::derive::gen_stub_pymethods]
41    #[pyo3::pymethods]
42    impl Options {
43        #[new]
44        /// Set the options to their defaults.
45        pub fn new() -> Self {
46            Default::default()
47        }
48    }
49
50    impl Default for Options {
51        fn default() -> Self {
52            Self {
53                coords: *coord::KITTYCAD,
54                units: UnitLength::Millimeters,
55            }
56        }
57    }
58}
59
60/// Export models in PLY format.
61pub mod export {
62
63    use super::*;
64
65    /// Options for exporting PLY.
66    #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
67    #[display("coords: {coords}, selection: {selection}, storage: {storage}, units: {units}")]
68    #[serde(rename = "PlyExportOptions")]
69    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
70    #[cfg_attr(
71        feature = "python",
72        pyo3_stub_gen::derive::gen_stub_pyclass,
73        pyo3::pyclass(name = "PlyExportOptions")
74    )]
75    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
76    pub struct Options {
77        /// Co-ordinate system of output data.
78        ///
79        /// Defaults to the [KittyCAD co-ordinate system].
80        ///
81        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
82        pub coords: coord::System,
83
84        /// Export selection.
85        pub selection: Selection,
86
87        /// The storage for the output PLY file.
88        pub storage: Storage,
89
90        /// Export length unit.
91        ///
92        /// Defaults to millimeters.
93        pub units: UnitLength,
94    }
95
96    #[cfg(feature = "python")]
97    #[pyo3_stub_gen::derive::gen_stub_pymethods]
98    #[pyo3::pymethods]
99    impl Options {
100        #[new]
101        /// Set the options to their defaults.
102        pub fn new() -> Self {
103            Default::default()
104        }
105    }
106
107    impl Default for Options {
108        fn default() -> Self {
109            Self {
110                coords: *coord::KITTYCAD,
111                selection: Default::default(),
112                storage: Default::default(),
113                units: UnitLength::Millimeters,
114            }
115        }
116    }
117
118    /// The storage for the output PLY file.
119    #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr, Default)]
120    #[display(style = "snake_case")]
121    #[serde(rename = "PlyStorage", rename_all = "snake_case")]
122    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
123    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
124    #[cfg_attr(
125        feature = "python",
126        pyo3_stub_gen::derive::gen_stub_pyclass_enum,
127        pyo3::pyclass(name = "PlyStorage")
128    )]
129    pub enum Storage {
130        /// Write numbers in their ascii representation (e.g. -13, 6.28, etc.). Properties are separated by spaces and elements are separated by line breaks.
131        #[default]
132        Ascii,
133        /// Encode payload as binary using little endian.
134        BinaryLittleEndian,
135        /// Encode payload as binary using big endian.
136        BinaryBigEndian,
137    }
138}