1use kittycad::types as kt;
2
3impl From<crate::ImportFile> for kt::ImportFile {
4 fn from(crate::ImportFile { path, data }: crate::ImportFile) -> Self {
5 Self { path, data }
6 }
7}
8
9impl From<kt::ImportFile> for crate::ImportFile {
10 fn from(kt::ImportFile { path, data }: kt::ImportFile) -> Self {
11 Self { path, data }
12 }
13}
14
15#[cfg(feature = "websocket")]
16impl From<crate::websocket::ModelingSessionData> for kt::ModelingSessionData {
17 fn from(crate::websocket::ModelingSessionData { api_call_id }: crate::websocket::ModelingSessionData) -> Self {
18 Self { api_call_id }
19 }
20}
21
22impl From<crate::units::UnitDensity> for kt::UnitDensity {
23 fn from(value: crate::units::UnitDensity) -> Self {
24 match value {
25 crate::units::UnitDensity::PoundsPerCubicFeet => Self::LbFt3,
26 crate::units::UnitDensity::KilogramsPerCubicMeter => Self::KgM3,
27 }
28 }
29}
30
31impl From<kt::UnitDensity> for crate::units::UnitDensity {
32 fn from(value: kt::UnitDensity) -> Self {
33 match value {
34 kt::UnitDensity::LbFt3 => Self::PoundsPerCubicFeet,
35 kt::UnitDensity::KgM3 => Self::KilogramsPerCubicMeter,
36 }
37 }
38}
39impl From<kt::UnitMass> for crate::units::UnitMass {
40 fn from(value: kt::UnitMass) -> Self {
41 match value {
42 kt::UnitMass::G => Self::Grams,
43 kt::UnitMass::Kg => Self::Kilograms,
44 kt::UnitMass::Lb => Self::Pounds,
45 }
46 }
47}
48impl From<kt::UnitArea> for crate::units::UnitArea {
49 fn from(value: kt::UnitArea) -> Self {
50 match value {
51 kt::UnitArea::Cm2 => Self::SquareCentimeters,
52 kt::UnitArea::Dm2 => Self::SquareDecimeters,
53 kt::UnitArea::Ft2 => Self::SquareFeet,
54 kt::UnitArea::In2 => Self::SquareInches,
55 kt::UnitArea::Km2 => Self::SquareKilometers,
56 kt::UnitArea::M2 => Self::SquareMeters,
57 kt::UnitArea::Mm2 => Self::SquareMillimeters,
58 kt::UnitArea::Yd2 => Self::SquareYards,
59 }
60 }
61}
62
63impl From<crate::units::UnitVolume> for kt::UnitVolume {
64 fn from(value: crate::units::UnitVolume) -> Self {
65 match value {
66 crate::units::UnitVolume::CubicCentimeters => kt::UnitVolume::Cm3,
67 crate::units::UnitVolume::CubicFeet => kt::UnitVolume::Ft3,
68 crate::units::UnitVolume::CubicInches => kt::UnitVolume::In3,
69 crate::units::UnitVolume::CubicMeters => kt::UnitVolume::M3,
70 crate::units::UnitVolume::CubicYards => kt::UnitVolume::Yd3,
71 crate::units::UnitVolume::FluidOunces => kt::UnitVolume::Usfloz,
72 crate::units::UnitVolume::Gallons => kt::UnitVolume::Usgal,
73 crate::units::UnitVolume::Liters => kt::UnitVolume::L,
74 crate::units::UnitVolume::Milliliters => kt::UnitVolume::Ml,
75 }
76 }
77}
78
79impl From<kt::UnitVolume> for crate::units::UnitVolume {
80 fn from(value: kt::UnitVolume) -> Self {
81 match value {
82 kt::UnitVolume::Cm3 => crate::units::UnitVolume::CubicCentimeters,
83 kt::UnitVolume::Ft3 => crate::units::UnitVolume::CubicFeet,
84 kt::UnitVolume::In3 => crate::units::UnitVolume::CubicInches,
85 kt::UnitVolume::M3 => crate::units::UnitVolume::CubicMeters,
86 kt::UnitVolume::Yd3 => crate::units::UnitVolume::CubicYards,
87 kt::UnitVolume::Usfloz => crate::units::UnitVolume::FluidOunces,
88 kt::UnitVolume::Usgal => crate::units::UnitVolume::Gallons,
89 kt::UnitVolume::L => crate::units::UnitVolume::Liters,
90 kt::UnitVolume::Ml => crate::units::UnitVolume::Milliliters,
91 }
92 }
93}
94
95mod format {
96 use crate::format::*;
97 use crate::shared::{FileExportFormat, FileImportFormat};
98 use kittycad::types as kt;
99
100 impl From<FileExportFormat> for kt::FileExportFormat {
101 fn from(format: FileExportFormat) -> kt::FileExportFormat {
102 match format {
103 FileExportFormat::Fbx => kt::FileExportFormat::Fbx,
104 FileExportFormat::Glb => kt::FileExportFormat::Glb,
105 FileExportFormat::Gltf => kt::FileExportFormat::Gltf,
106 FileExportFormat::Obj => kt::FileExportFormat::Obj,
107 FileExportFormat::Ply => kt::FileExportFormat::Ply,
108 FileExportFormat::Step => kt::FileExportFormat::Step,
109 FileExportFormat::Stl => kt::FileExportFormat::Stl,
110 }
111 }
112 }
113
114 impl From<FileImportFormat> for kt::FileImportFormat {
115 fn from(format: FileImportFormat) -> kt::FileImportFormat {
116 match format {
117 FileImportFormat::Fbx => kt::FileImportFormat::Fbx,
118 FileImportFormat::Gltf => kt::FileImportFormat::Gltf,
119 FileImportFormat::Obj => kt::FileImportFormat::Obj,
120 FileImportFormat::Ply => kt::FileImportFormat::Ply,
121 FileImportFormat::Step => kt::FileImportFormat::Step,
122 FileImportFormat::Stl => kt::FileImportFormat::Stl,
123 FileImportFormat::Sldprt => kt::FileImportFormat::Sldprt,
124 }
125 }
126 }
127
128 impl From<InputFormat3d> for kt::InputFormat3D {
129 fn from(format: InputFormat3d) -> kt::InputFormat3D {
130 match format {
131 InputFormat3d::Fbx(fbx::import::Options {}) => kt::InputFormat3D::Fbx {},
132 InputFormat3d::Gltf(gltf::import::Options {}) => kt::InputFormat3D::Gltf {},
133 InputFormat3d::Obj(obj::import::Options { coords, units }) => kt::InputFormat3D::Obj {
134 coords: coords.into(),
135 units: units.into(),
136 },
137 InputFormat3d::Ply(ply::import::Options { coords, units }) => kt::InputFormat3D::Ply {
138 coords: coords.into(),
139 units: units.into(),
140 },
141 InputFormat3d::Sldprt(sldprt::import::Options { split_closed_faces }) => {
142 kt::InputFormat3D::Sldprt { split_closed_faces }
143 }
144 InputFormat3d::Step(step::import::Options { split_closed_faces }) => {
145 kt::InputFormat3D::Step { split_closed_faces }
146 }
147 InputFormat3d::Stl(stl::import::Options { coords, units }) => kt::InputFormat3D::Stl {
148 coords: coords.into(),
149 units: units.into(),
150 },
151 }
152 }
153 }
154
155 impl From<kt::InputFormat3D> for InputFormat3d {
156 fn from(value: kt::InputFormat3D) -> Self {
157 match value {
158 kt::InputFormat3D::Fbx {} => Self::Fbx(Default::default()),
159 kt::InputFormat3D::Gltf {} => Self::Gltf(Default::default()),
160 kt::InputFormat3D::Obj { coords, units } => Self::Obj(crate::format::obj::import::Options {
161 coords: coords.into(),
162 units: units.into(),
163 }),
164 kt::InputFormat3D::Ply { coords, units } => Self::Ply(crate::format::ply::import::Options {
165 coords: coords.into(),
166 units: units.into(),
167 }),
168 kt::InputFormat3D::Sldprt { split_closed_faces } => {
169 Self::Sldprt(crate::format::sldprt::import::Options { split_closed_faces })
170 }
171 kt::InputFormat3D::Step { split_closed_faces } => {
172 Self::Step(crate::format::step::import::Options { split_closed_faces })
173 }
174 kt::InputFormat3D::Stl { coords, units } => Self::Stl(crate::format::stl::import::Options {
175 coords: coords.into(),
176 units: units.into(),
177 }),
178 }
179 }
180 }
181
182 impl From<crate::units::UnitLength> for kt::UnitLength {
183 fn from(input: crate::units::UnitLength) -> Self {
184 match input {
185 crate::units::UnitLength::Centimeters => kt::UnitLength::Cm,
186 crate::units::UnitLength::Feet => kt::UnitLength::Ft,
187 crate::units::UnitLength::Inches => kt::UnitLength::In,
188 crate::units::UnitLength::Meters => kt::UnitLength::M,
189 crate::units::UnitLength::Millimeters => kt::UnitLength::Mm,
190 crate::units::UnitLength::Yards => kt::UnitLength::Yd,
191 }
192 }
193 }
194 impl From<kt::UnitLength> for crate::units::UnitLength {
195 fn from(input: kt::UnitLength) -> Self {
196 match input {
197 kt::UnitLength::Cm => Self::Centimeters,
198 kt::UnitLength::Ft => Self::Feet,
199 kt::UnitLength::In => Self::Inches,
200 kt::UnitLength::M => Self::Meters,
201 kt::UnitLength::Mm => Self::Millimeters,
202 kt::UnitLength::Yd => Self::Yards,
203 }
204 }
205 }
206
207 impl From<crate::coord::AxisDirectionPair> for kt::AxisDirectionPair {
208 fn from(input: crate::coord::AxisDirectionPair) -> kt::AxisDirectionPair {
209 let axis = match input.axis {
210 crate::coord::Axis::Y => kt::Axis::Y,
211 crate::coord::Axis::Z => kt::Axis::Z,
212 };
213 let direction = match input.direction {
214 crate::coord::Direction::Positive => kt::Direction::Positive,
215 crate::coord::Direction::Negative => kt::Direction::Negative,
216 };
217 kt::AxisDirectionPair { axis, direction }
218 }
219 }
220 impl From<kt::AxisDirectionPair> for crate::coord::AxisDirectionPair {
221 fn from(input: kt::AxisDirectionPair) -> Self {
222 let axis = match input.axis {
223 kt::Axis::Y => crate::coord::Axis::Y,
224 kt::Axis::Z => crate::coord::Axis::Z,
225 };
226 let direction = match input.direction {
227 kt::Direction::Positive => crate::coord::Direction::Positive,
228 kt::Direction::Negative => crate::coord::Direction::Negative,
229 };
230 Self { axis, direction }
231 }
232 }
233
234 impl From<crate::coord::System> for kt::System {
235 fn from(crate::coord::System { forward, up }: crate::coord::System) -> kt::System {
236 kt::System {
237 forward: forward.into(),
238 up: up.into(),
239 }
240 }
241 }
242
243 impl From<kt::System> for crate::coord::System {
244 fn from(kt::System { forward, up }: kt::System) -> Self {
245 Self {
246 forward: forward.into(),
247 up: up.into(),
248 }
249 }
250 }
251
252 impl From<crate::ImageFormat> for kt::ImageFormat {
253 fn from(format: crate::ImageFormat) -> kt::ImageFormat {
254 match format {
255 crate::ImageFormat::Png => kt::ImageFormat::Png,
256 crate::ImageFormat::Jpeg => kt::ImageFormat::Jpeg,
257 }
258 }
259 }
260}