1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
use kittycad_execution_plan_macros::ExecutionPlanValue;
use kittycad_modeling_cmds_macros::define_ok_modeling_cmd_response_enum;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

impl crate::ModelingCmdOutput for () {}

define_ok_modeling_cmd_response_enum! {
    /// Output from Modeling API commands.
    pub mod output {
        use kittycad_execution_plan_macros::ExecutionPlanValue;
        use kittycad_modeling_cmds_macros::ModelingCmdOutput;
        use schemars::JsonSchema;
        use serde::{Deserialize, Serialize};
        use uuid::Uuid;
        use crate::shared::CameraSettings;

        use crate::{self as kittycad_modeling_cmds};
        use crate::{
            base64::Base64Data,
            id::ModelingCmdId,
            length_unit::LengthUnit,
            shared::{CurveType, EntityType, ExportFile, ExtrusionFaceCapType, PathCommand, Point2d, Point3d},
            units,
        };

        /// The response from the `Export` endpoint.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct Export {
            /// The files that were exported.
            pub files: Vec<ExportFile>,
        }
        /// The response from the `SelectWithPoint` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct SelectWithPoint {
            /// The UUID of the entity that was selected.
            pub entity_id: Option<Uuid>,
        }
        /// The response from the `HighlightSetEntity` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct HighlightSetEntity {
            /// The UUID of the entity that was highlighted.
            pub entity_id: Option<Uuid>,
            /// If the client sent a sequence ID with its request, the backend sends it back.
            pub sequence: Option<u32>,
        }
        /// The response from the `EntityGetChildUuid` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct EntityGetChildUuid {
            /// The UUID of the child entity.
            pub entity_id: Uuid,
        }
        /// The response from the `EntityGetNumChildren` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct EntityGetNumChildren {
            /// The number of children the entity has.
            pub num: u32,
        }
        /// The response from the `EntityGetParentId` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct EntityGetParentId {
            /// The UUID of the parent entity.
            pub entity_id: Uuid,
        }
        /// The response from the `EntityGetAllChildUuids` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct EntityGetAllChildUuids {
            /// The UUIDs of the child entities.
            pub entity_ids: Vec<Uuid>,
        }

        /// The response from the `CameraDragMove` command.
        /// Note this is an "unreliable" channel message, so this data may need more data like a "sequence"
        //  to work properly
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct CameraDragMove {
            /// Camera settings
            pub settings: CameraSettings
        }

        /// The response from the `CameraDragEnd` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct CameraDragEnd {
            /// Camera settings
            pub settings: CameraSettings
        }

        /// The response from the `DefaultCameraGetSettings` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct DefaultCameraGetSettings {
            /// Camera settings
            pub settings: CameraSettings
        }

        /// The response from the `DefaultCameraZoom` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct DefaultCameraZoom {
            /// Camera settings
            pub settings: CameraSettings
        }

        /// The response from the `GetNumObjects` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct GetNumObjects {
            /// The number of objects in the scene.
            pub num_objects: u32,
        }
        /// The response from the `DefaultCameraFocusOn` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct DefaultCameraFocusOn { }

        /// The response from the `SelectGet` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct SelectGet {
            /// The UUIDs of the selected entities.
            pub entity_ids: Vec<Uuid>,
        }

        /// The response from the `Solid3dGetAllEdgeFaces` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct Solid3dGetAllEdgeFaces {
            /// The UUIDs of the faces.
            pub faces: Vec<Uuid>,
        }

        /// The response from the `Solid3dGetAllOppositeEdges` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct Solid3dGetAllOppositeEdges {
            /// The UUIDs of the edges.
            pub edges: Vec<Uuid>,
        }

        /// The response from the `Solid3dGetOppositeEdge` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct Solid3dGetOppositeEdge {
            /// The UUID of the edge.
            pub edge: Uuid,
        }

        /// The response from the `Solid3dGetNextAdjacentEdge` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct Solid3dGetNextAdjacentEdge {
            /// The UUID of the edge.
            pub edge: Option<Uuid>,
        }

        /// The response from the `Solid3dGetPrevAdjacentEdge` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct Solid3dGetPrevAdjacentEdge {
            /// The UUID of the edge.
            pub edge: Option<Uuid>,
        }

        /// The response from the `GetEntityType` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct GetEntityType {
            /// The type of the entity.
            pub entity_type: EntityType,
        }
        /// The response from the `CurveGetControlPoints` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct CurveGetControlPoints {
            /// Control points in the curve.
            pub control_points: Vec<Point3d>,
        }

        /// The response from the `CurveGetType` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, Eq, PartialEq, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct CurveGetType {
            /// Curve type
            pub curve_type: CurveType,
        }

        /// The response from the `MouseClick` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct MouseClick {
            /// Entities that are modified.
            pub entities_modified: Vec<Uuid>,
            /// Entities that are selected.
            pub entities_selected: Vec<Uuid>,
        }

        /// The response from the `TakeSnapshot` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct TakeSnapshot {
            /// Contents of the image.
            pub contents: Base64Data,
        }

        /// The response from the `PathGetInfo` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct PathGetInfo {
            /// All segments in the path, in the order they were added.
            pub segments: Vec<PathSegmentInfo>,
        }

        /// Info about a path segment
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct PathSegmentInfo {
            /// Which command created this path?
            /// This field is absent if the path command is not actually creating a path segment,
            /// e.g. moving the pen doesn't create a path segment.
            pub command_id: Option<ModelingCmdId>,
            /// What is the path segment?
            pub command: PathCommand,
            ///Whether or not this segment is a relative offset
            pub relative: bool,
        }

        /// The response from the `PathGetCurveUuidsForVertices` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct PathGetCurveUuidsForVertices {
            /// The UUIDs of the curve entities.
            pub curve_ids: Vec<Uuid>,
        }

        /// The response from the `PathGetVertexUuids` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct PathGetVertexUuids {
            /// The UUIDs of the vertex entities.
            pub vertex_ids: Vec<Uuid>,
        }

        /// Endpoints of a curve
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct CurveGetEndPoints {
            /// Start
            pub start: Point3d<LengthUnit>,
            /// End
            pub end: Point3d<LengthUnit>,
        }

        /// Surface-local planar axes (if available)
        #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct FaceIsPlanar {
            /// plane's origin
            pub origin: Option<Point3d<f64>>,

            /// plane's local x-axis
            pub x_axis: Option<Point3d<f64>>,

            /// plane's local y-axis
            pub y_axis: Option<Point3d<f64>>,

            /// plane's local z-axis (normal)
            pub z_axis: Option<Point3d<f64>>,
        }

        /// The 3D position on the surface that was evaluated
        #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct FaceGetPosition {
            /// The 3D position on the surface that was evaluated
            pub pos: Point3d<f64>,
        }

        /// The gradient (dFdu, dFdv) + normal vector on a brep face
        #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct FaceGetGradient {
            /// dFdu
            pub df_du: Point3d<f64>,

            /// dFdv
            pub df_dv: Point3d<f64>,

            /// Normal (||dFdu x dFdv||)
            pub normal: Point3d<f64>,
        }

        /// Corresponding coordinates of given window coordinates, intersected on given plane.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct PlaneIntersectAndProject {
            /// Corresponding coordinates of given window coordinates, intersected on given plane.
            pub plane_coordinates: Option<Point2d<LengthUnit>>,
        }

        /// Data from importing the files
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct ImportFiles {
            /// ID of the imported 3D models within the scene.
            pub object_id: Uuid,
        }

        /// Data from importing the files
        #[derive(Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct ImportedGeometry {
            /// ID of the imported 3D models within the scene.
            pub id: Uuid,
            /// The original file paths that held the geometry.
            pub value: Vec<String>,
        }

        /// The mass response.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct Mass {
            /// The mass.
            pub mass: f64,
            /// The output unit for the mass.
            pub output_unit: units::UnitMass,
        }

        /// The volume response.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct Volume {
            /// The volume.
            pub volume: f64,
            /// The output unit for the volume.
            pub output_unit: units::UnitVolume,
        }

        /// The density response.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct Density {
            /// The density.
            pub density: f64,
            /// The output unit for the density.
            pub output_unit: units::UnitDensity,
        }

        /// The surface area response.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct SurfaceArea {
            /// The surface area.
            pub surface_area: f64,
            /// The output unit for the surface area.
            pub output_unit: units::UnitArea,
        }

        /// The center of mass response.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct CenterOfMass {
            /// The center of mass.
            pub center_of_mass: Point3d<f64>,
            /// The output unit for the center of mass.
            pub output_unit: units::UnitLength,
        }

        /// The plane for sketch mode.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct GetSketchModePlane {
            /// The x axis.
            pub x_axis: Point3d<f64>,
            /// The y axis.
            pub y_axis: Point3d<f64>,
            /// The z axis (normal).
            pub z_axis: Point3d<f64>,
        }

        /// The response from the `EntitiesGetDistance` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct EntityGetDistance {
            /// The minimum distance between the input entities.
            pub min_distance: LengthUnit,
            /// The maximum distance between the input entities.
            pub max_distance: LengthUnit,
        }

        /// The response from the `EntityLinearPattern` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct EntityLinearPattern {
            /// The UUIDs of the entities that were created.
            pub entity_ids: Vec<Uuid>,
        }

        /// The response from the `EntityCircularPattern` command.
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct EntityCircularPattern {
            /// The UUIDs of the entities that were created.
            pub entity_ids: Vec<Uuid>,
        }

        /// Extrusion face info struct (useful for maintaining mappings between source path segment ids and extrusion faces)
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct Solid3dGetExtrusionFaceInfo {
            /// Details of each face.
            pub faces: Vec<ExtrusionFaceInfo>,
        }

        /// Extrusion face info struct (useful for maintaining mappings between source path segment ids and extrusion faces)
        #[derive(Debug, Serialize, Deserialize, JsonSchema, ExecutionPlanValue, ModelingCmdOutput)]
        pub struct ExtrusionFaceInfo {
            /// Path component (curve) UUID.
            pub curve_id: Option<Uuid>,

            /// Face uuid.
            pub face_id: Option<Uuid>,

            /// Whether or not this extrusion face is a top/bottom cap face or not.
            /// Note that top/bottom cap faces will not have associated curve IDs.
            pub cap: ExtrusionFaceCapType,
        }

    }
}