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 kittycad::types as kt;
97
98 use crate::{
99 format::*,
100 shared::{FileExportFormat, FileImportFormat},
101 };
102
103 impl From<FileExportFormat> for kt::FileExportFormat {
104 fn from(format: FileExportFormat) -> kt::FileExportFormat {
105 match format {
106 FileExportFormat::Fbx => kt::FileExportFormat::Fbx,
107 FileExportFormat::Glb => kt::FileExportFormat::Glb,
108 FileExportFormat::Gltf => kt::FileExportFormat::Gltf,
109 FileExportFormat::Obj => kt::FileExportFormat::Obj,
110 FileExportFormat::Ply => kt::FileExportFormat::Ply,
111 FileExportFormat::Step => kt::FileExportFormat::Step,
112 FileExportFormat::Stl => kt::FileExportFormat::Stl,
113 }
114 }
115 }
116
117 impl From<FileImportFormat> for kt::FileImportFormat {
118 fn from(format: FileImportFormat) -> kt::FileImportFormat {
119 match format {
120 FileImportFormat::Fbx => kt::FileImportFormat::Fbx,
121 FileImportFormat::Gltf => kt::FileImportFormat::Gltf,
122 FileImportFormat::Obj => kt::FileImportFormat::Obj,
123 FileImportFormat::Ply => kt::FileImportFormat::Ply,
124 FileImportFormat::Step => kt::FileImportFormat::Step,
125 FileImportFormat::Stl => kt::FileImportFormat::Stl,
126 FileImportFormat::Sldprt => kt::FileImportFormat::Sldprt,
127 }
128 }
129 }
130
131 impl From<InputFormat3d> for kt::InputFormat3D {
132 fn from(format: InputFormat3d) -> kt::InputFormat3D {
133 match format {
134 InputFormat3d::Fbx(fbx::import::Options {}) => kt::InputFormat3D::Fbx {},
135 InputFormat3d::Gltf(gltf::import::Options {}) => kt::InputFormat3D::Gltf {},
136 InputFormat3d::Obj(obj::import::Options { coords, units }) => kt::InputFormat3D::Obj {
137 coords: coords.into(),
138 units: units.into(),
139 },
140 InputFormat3d::Ply(ply::import::Options { coords, units }) => kt::InputFormat3D::Ply {
141 coords: coords.into(),
142 units: units.into(),
143 },
144 InputFormat3d::Sldprt(sldprt::import::Options { split_closed_faces }) => {
145 kt::InputFormat3D::Sldprt { split_closed_faces }
146 }
147 InputFormat3d::Step(step::import::Options { split_closed_faces }) => {
148 kt::InputFormat3D::Step { split_closed_faces }
149 }
150 InputFormat3d::Stl(stl::import::Options { coords, units }) => kt::InputFormat3D::Stl {
151 coords: coords.into(),
152 units: units.into(),
153 },
154 }
155 }
156 }
157
158 impl From<kt::InputFormat3D> for InputFormat3d {
159 fn from(value: kt::InputFormat3D) -> Self {
160 match value {
161 kt::InputFormat3D::Fbx {} => Self::Fbx(Default::default()),
162 kt::InputFormat3D::Gltf {} => Self::Gltf(Default::default()),
163 kt::InputFormat3D::Obj { coords, units } => Self::Obj(crate::format::obj::import::Options {
164 coords: coords.into(),
165 units: units.into(),
166 }),
167 kt::InputFormat3D::Ply { coords, units } => Self::Ply(crate::format::ply::import::Options {
168 coords: coords.into(),
169 units: units.into(),
170 }),
171 kt::InputFormat3D::Sldprt { split_closed_faces } => {
172 Self::Sldprt(crate::format::sldprt::import::Options { split_closed_faces })
173 }
174 kt::InputFormat3D::Step { split_closed_faces } => {
175 Self::Step(crate::format::step::import::Options { split_closed_faces })
176 }
177 kt::InputFormat3D::Stl { coords, units } => Self::Stl(crate::format::stl::import::Options {
178 coords: coords.into(),
179 units: units.into(),
180 }),
181 }
182 }
183 }
184
185 impl From<crate::units::UnitLength> for kt::UnitLength {
186 fn from(input: crate::units::UnitLength) -> Self {
187 match input {
188 crate::units::UnitLength::Centimeters => kt::UnitLength::Cm,
189 crate::units::UnitLength::Feet => kt::UnitLength::Ft,
190 crate::units::UnitLength::Inches => kt::UnitLength::In,
191 crate::units::UnitLength::Meters => kt::UnitLength::M,
192 crate::units::UnitLength::Millimeters => kt::UnitLength::Mm,
193 crate::units::UnitLength::Yards => kt::UnitLength::Yd,
194 }
195 }
196 }
197 impl From<kt::UnitLength> for crate::units::UnitLength {
198 fn from(input: kt::UnitLength) -> Self {
199 match input {
200 kt::UnitLength::Cm => Self::Centimeters,
201 kt::UnitLength::Ft => Self::Feet,
202 kt::UnitLength::In => Self::Inches,
203 kt::UnitLength::M => Self::Meters,
204 kt::UnitLength::Mm => Self::Millimeters,
205 kt::UnitLength::Yd => Self::Yards,
206 }
207 }
208 }
209
210 impl From<crate::coord::AxisDirectionPair> for kt::AxisDirectionPair {
211 fn from(input: crate::coord::AxisDirectionPair) -> kt::AxisDirectionPair {
212 let axis = match input.axis {
213 crate::coord::Axis::Y => kt::Axis::Y,
214 crate::coord::Axis::Z => kt::Axis::Z,
215 };
216 let direction = match input.direction {
217 crate::coord::Direction::Positive => kt::Direction::Positive,
218 crate::coord::Direction::Negative => kt::Direction::Negative,
219 };
220 kt::AxisDirectionPair { axis, direction }
221 }
222 }
223 impl From<kt::AxisDirectionPair> for crate::coord::AxisDirectionPair {
224 fn from(input: kt::AxisDirectionPair) -> Self {
225 let axis = match input.axis {
226 kt::Axis::Y => crate::coord::Axis::Y,
227 kt::Axis::Z => crate::coord::Axis::Z,
228 };
229 let direction = match input.direction {
230 kt::Direction::Positive => crate::coord::Direction::Positive,
231 kt::Direction::Negative => crate::coord::Direction::Negative,
232 };
233 Self { axis, direction }
234 }
235 }
236
237 impl From<crate::coord::System> for kt::System {
238 fn from(crate::coord::System { forward, up }: crate::coord::System) -> kt::System {
239 kt::System {
240 forward: forward.into(),
241 up: up.into(),
242 }
243 }
244 }
245
246 impl From<kt::System> for crate::coord::System {
247 fn from(kt::System { forward, up }: kt::System) -> Self {
248 Self {
249 forward: forward.into(),
250 up: up.into(),
251 }
252 }
253 }
254
255 impl From<crate::ImageFormat> for kt::ImageFormat {
256 fn from(format: crate::ImageFormat) -> kt::ImageFormat {
257 match format {
258 crate::ImageFormat::Png => kt::ImageFormat::Png,
259 crate::ImageFormat::Jpeg => kt::ImageFormat::Jpeg,
260 }
261 }
262 }
263}