Skip to main content

kittycad_modeling_cmds/
shared.rs

1use bon::Builder;
2use enum_iterator::Sequence;
3pub use kittycad_point::{Point2d, Point3d, Point4d, Quaternion};
4use parse_display_derive::{Display, FromStr};
5use schemars::{schema::SchemaObject, JsonSchema};
6use serde::{Deserialize, Serialize};
7use uuid::Uuid;
8
9#[cfg(feature = "cxx")]
10use crate::impl_extern_type;
11use crate::{
12    def_enum::negative_one,
13    id::ModelingCmdId,
14    length_unit::LengthUnit,
15    output::ExtrusionFaceInfo,
16    units::{self, UnitAngle},
17};
18
19pub mod safe_filepath;
20
21pub use crate::kcl_project::{KclFile, KclFileBuilder, KclProject, KclProjectBuilder};
22
23/// Compression requested for a binary command response. Small or incompressible responses may remain uncompressed.
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
25#[serde(rename_all = "snake_case")]
26#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
27#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
28#[cfg_attr(feature = "ts-rs", ts(export_to = "Compression.ts"))]
29#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
30pub enum CompressionType {
31    /// Zstandard framing, detected by magic bytes `28 b5 2f fd`, around the complete MessagePack response.
32    Zstd,
33}
34
35/// Default tolerance values for modeling operations.
36#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
37#[serde(rename_all = "snake_case")]
38#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
39#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
40#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
41#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
42pub struct Tolerance {
43    /// The distance tolerance for 2D point-point coincidence.
44    pub point_point_2d_coincident: LengthUnit,
45}
46
47/// An edge can be referenced by its uuid or by the faces that uniquely define it.
48#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
49#[serde(rename_all = "snake_case")]
50#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
51#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
52#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
53#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
54pub struct EdgeSpecifier {
55    /// Side face ids that uniquely identify the edge.
56    pub side_faces: Vec<Uuid>,
57    /// Optional end face ids for ambiguous edge matches.
58    #[serde(default, skip_serializing_if = "Vec::is_empty")]
59    #[builder(default)]
60    pub end_faces: Vec<Uuid>,
61    /// Optional index for disambiguation when multiple edges share the same faces.
62    /// If not provided (None), all matching edges will be used.
63    /// If provided (Some(n)), only the edge at index n will be used.
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub index: Option<u32>,
66}
67
68/// Optional fallback when primary UUIDs are missing from the client artifact graph (e.g. stale or
69/// engine-only ids). Identifies the same topology via a **parent** entity UUID and a **primitive
70/// index** on that parent.
71///
72/// Semantics by selection kind (aligned with engine BREP topology):
73///
74/// - **Face / Edge (3D)**: `parent_id` is the owning [`EntityType::Solid3D`] body UUID; `primitive_index`
75///   matches the index returned by **EntityGetPrimitiveIndex** for that face or edge (and matches
76///   **EntityGetParentId** → parent + **EntityGetPrimitiveIndex** → index).
77/// - **Vertex (3D)**: same `parent_id` (solid); `primitive_index` is the BREP vertex index on that solid.
78/// - **Solid2dEdge**: `parent_id` is the **Solid2D** profile UUID; `primitive_index` is the curve index
79///   within that profile.
80/// - **Segment**: `parent_id` is the **Path** UUID; `primitive_index` is the curve index within that path.
81///
82/// Other [`EntityReference`] variants may omit this field or leave it unset when not applicable.
83#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
84#[serde(rename_all = "snake_case")]
85#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
86#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
87#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
88#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
89pub struct PrimitiveTopologyFallback {
90    /// UUID of the parent entity that owns the primitive (solid3d, solid2d, or path).
91    pub parent_id: Uuid,
92    /// Index of the face, edge, vertex, profile curve, or path segment on `parent_id`.
93    pub primitive_index: u32,
94}
95
96/// A reference identifying a selectable scene entity.
97#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
98#[serde(tag = "type", rename_all = "snake_case")]
99#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
100#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
101#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
102pub enum EntityReference {
103    /// A uuid referencing an annotation.
104    Annotation {
105        /// Id of the annotation object being referenced.
106        annotation_id: Uuid,
107    },
108    /// A uuid referencing a plane.
109    Plane {
110        /// Id of the plane being referenced.
111        plane_id: Uuid,
112        /// Optional primitive topology on a parent (not used for planes today).
113        #[serde(default, skip_serializing_if = "Option::is_none")]
114        topology_fallback: Option<PrimitiveTopologyFallback>,
115    },
116    /// A uuid referencing a face.
117    Face {
118        /// Id of the face being referenced.
119        face_id: Uuid,
120        /// Fallback: solid3d UUID + face index on that body when `face_id` cannot be resolved client-side.
121        #[serde(default, skip_serializing_if = "Option::is_none")]
122        topology_fallback: Option<PrimitiveTopologyFallback>,
123    },
124    /// A collection of ids that uniquely identify an edge.
125    Edge {
126        /// Flattened edge reference (side_faces, end_faces, index).
127        #[serde(flatten)]
128        inner: EdgeSpecifier,
129        /// Fallback: solid3d UUID + edge index on that body for 3D BREP edges (distinct from `inner.index`).
130        #[serde(default, skip_serializing_if = "Option::is_none")]
131        topology_fallback: Option<PrimitiveTopologyFallback>,
132    },
133    /// A collection of ids that uniquely identify an vertex.
134    Vertex {
135        /// Side face ids that identify the vertex.
136        side_faces: Vec<Uuid>,
137        /// Optional index among the filtered candidates.
138        #[serde(skip_serializing_if = "Option::is_none")]
139        index: Option<u32>,
140        /// Fallback: solid3d UUID + vertex index on that body.
141        #[serde(default, skip_serializing_if = "Option::is_none")]
142        topology_fallback: Option<PrimitiveTopologyFallback>,
143    },
144    /// A uuid referencing a solid2d (profile).
145    Solid2d {
146        /// Id of the solid2d being referenced.
147        solid2d_id: Uuid,
148        /// Typically omitted: `solid2d_id` is already the owning profile. Present for schema parity with other variants.
149        #[serde(default, skip_serializing_if = "Option::is_none")]
150        topology_fallback: Option<PrimitiveTopologyFallback>,
151    },
152    /// A uuid referencing a solid3d (body).
153    Solid3d {
154        /// Id of the solid3d being referenced.
155        solid3d_id: Uuid,
156        /// Typically omitted: `solid3d_id` is already the owning body. Present for schema parity with other variants.
157        #[serde(default, skip_serializing_if = "Option::is_none")]
158        topology_fallback: Option<PrimitiveTopologyFallback>,
159    },
160    /// A uuid referencing a helix.
161    Helix {
162        /// Id of the helix object.
163        helix_id: Uuid,
164    },
165    /// A uuid referencing an edge on a solid2d (profile) - used for raw sketch/profile edges.
166    /// This is distinct from the face-based Edge reference which is used for BRep/swept body edges.
167    Solid2dEdge {
168        /// Id of the edge being referenced.
169        edge_id: Uuid,
170        /// Fallback: solid2d UUID + curve index in that profile.
171        #[serde(default, skip_serializing_if = "Option::is_none")]
172        topology_fallback: Option<PrimitiveTopologyFallback>,
173    },
174    /// A single segment (curve) within a path.
175    Segment {
176        /// Id of the path containing the segment.
177        path_id: Uuid,
178        /// Id of the segment (curve) being referenced.
179        segment_id: Uuid,
180        /// Fallback: path UUID + segment curve index.
181        #[serde(default, skip_serializing_if = "Option::is_none")]
182        topology_fallback: Option<PrimitiveTopologyFallback>,
183    },
184    /// A closed sketch region/profile area.
185    Region {
186        /// Id of the region being referenced.
187        region_id: Uuid,
188        /// Fallback: path UUID + region index on that path.
189        #[serde(default, skip_serializing_if = "Option::is_none")]
190        topology_fallback: Option<PrimitiveTopologyFallback>,
191    },
192}
193
194/// An oriented planar coordinate frame in model space.
195///
196/// The axes must be finite, orthogonal unit vectors. The right-handed normal is
197/// `x_axis × y_axis`. A world point `p` has planar coordinates
198/// `(dot(p - origin, x_axis), dot(p - origin, y_axis))`.
199#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
200#[serde(rename_all = "snake_case")]
201#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
202#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
203#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
204#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
205pub struct PlanarFrame {
206    /// Finite origin in the session's current length unit.
207    pub origin: Point3d<LengthUnit>,
208    /// Dimensionless unit vector for the frame's positive X direction.
209    pub x_axis: Point3d<f64>,
210    /// Dimensionless unit vector for the frame's positive Y direction.
211    pub y_axis: Point3d<f64>,
212}
213
214/// Controls whether hidden projected curves are included in a projection response.
215#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
216#[serde(rename_all = "snake_case")]
217#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
218#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
219#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
220#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
221pub enum ProjectionHiddenLineMode {
222    /// Return only visible projected curves.
223    VisibleOnly,
224    /// Return visible and hidden projected curves.
225    #[default]
226    IncludeHidden,
227}
228
229/// Visibility classification for a projected drawing curve.
230#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
231#[serde(rename_all = "snake_case")]
232#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
233#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
234#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
235#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
236pub enum ProjectionCurveVisibility {
237    /// Visible in the requested projection.
238    Visible,
239    /// Hidden behind other projected model geometry.
240    Hidden,
241}
242
243/// Source topology and projection-local identification of a curve.
244///
245/// Topology indices address the body in the request, using the same BREP indices
246/// as `EntityGetPrimitiveIndex`. UUIDs identify topology in the current execution;
247/// clients use the artifact graph and KCL Face/Edge APIs to author references.
248/// Section, silhouette, and segment indices distinguish derived geometry within
249/// this projection result. They are not guaranteed stable after model/view edits
250/// or across engine versions, and must not be persisted as durable selectors.
251#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
252#[serde(tag = "type", rename_all = "snake_case")]
253#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
254#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
255#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
256#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
257pub enum ProjectionCurveSource {
258    /// Projection of a BREP edge.
259    Edge {
260        /// Source edge UUID when available in the current execution.
261        #[serde(default, skip_serializing_if = "Option::is_none")]
262        edge_id: Option<Uuid>,
263        /// Source edge index on the requested body; always available.
264        edge_index: u32,
265        /// Section of this edge split where it crosses the view tangent condition.
266        section_index: u32,
267    },
268    /// View-dependent silhouette generated from a BREP face.
269    Silhouette {
270        /// Source face UUID when available in the current execution.
271        #[serde(default, skip_serializing_if = "Option::is_none")]
272        face_id: Option<Uuid>,
273        /// Source face index on the requested body; always available.
274        face_index: u32,
275        /// Distinct silhouette component of this face in this projection.
276        silhouette_index: u32,
277    },
278}
279
280/// A bounded 2D line segment.
281///
282/// The consuming command defines the coordinate frame and length unit.
283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
284#[serde(rename_all = "snake_case")]
285#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
286#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
287#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
288#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
289pub struct LineSegment2d {
290    /// Start point in local 2D coordinates.
291    pub start: Point2d<f64>,
292    /// End point in local 2D coordinates.
293    pub end: Point2d<f64>,
294}
295
296/// Direction of traversal around a planar curve, viewed from its positive normal.
297#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
298#[serde(rename_all = "snake_case")]
299#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
300#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
301#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
302#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
303pub enum Winding {
304    /// Traverse counterclockwise, from local +X towards +Y.
305    #[default]
306    Counterclockwise,
307    /// Traverse clockwise, from local +X towards -Y.
308    Clockwise,
309}
310
311/// A bounded 2D circular arc.
312///
313/// The consuming command defines the coordinate frame and length unit.
314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
315#[serde(rename_all = "snake_case")]
316#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
317#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
318#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
319#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
320pub struct CircularArc2d {
321    /// Arc center in local 2D coordinates.
322    pub origin: Point2d<f64>,
323    /// Positive arc radius in the same length unit as the center.
324    pub radius: f64,
325    /// Start angle in radians measured from local +X towards +Y.
326    pub start_angle: f64,
327    /// End angle in radians measured from local +X towards +Y.
328    pub end_angle: f64,
329    /// Direction of traversal from start_angle to end_angle. Defaults to counterclockwise.
330    /// A full circle has an angular sweep of 2 pi; equal angles mean zero sweep.
331    #[serde(default)]
332    #[builder(default)]
333    pub winding: Winding,
334}
335
336/// A bounded 2D NURBS curve.
337///
338/// The consuming command defines the coordinate frame and length unit.
339#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
340#[serde(rename_all = "snake_case")]
341#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
342#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
343#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
344#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
345pub struct Nurbs2d {
346    /// Non-homogeneous control points in local 2D coordinates.
347    pub control_points: Vec<Point2d<f64>>,
348    /// Positive weights, one per control point. Empty means all weights are 1.
349    #[serde(default, skip_serializing_if = "Vec::is_empty")]
350    pub weights: Vec<f64>,
351    /// Full nondecreasing knot vector, with `control_points.len() + order` entries.
352    /// The active domain is `[knot_vector[order - 1], knot_vector[control_points.len()]]`.
353    pub knot_vector: Vec<f64>,
354    /// NURBS order (degree + 1), at least 2 and at most the control point count.
355    pub order: u32,
356}
357
358/// Bounded 2D geometry of a projected curve.
359#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
360#[serde(tag = "type", rename_all = "snake_case")]
361#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
362#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
363#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
364#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
365pub enum ProjectionCurveGeometry {
366    /// Bounded line segment.
367    Line {
368        /// Line segment data.
369        #[serde(flatten)]
370        data: LineSegment2d,
371    },
372    /// Bounded circular arc.
373    CircularArc {
374        /// Circular arc data.
375        #[serde(flatten)]
376        data: CircularArc2d,
377    },
378    /// Bounded NURBS curve.
379    Nurbs {
380        /// NURBS curve data.
381        #[serde(flatten)]
382        data: Nurbs2d,
383    },
384}
385
386/// A projected curve with geometry, visibility, and source provenance.
387#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
388#[serde(rename_all = "snake_case")]
389#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
390#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
391#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
392#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
393pub struct ProjectionCurve {
394    /// Index of the split segment within its source section or silhouette.
395    /// Response-local only; clients can use array positions for picking IDs.
396    pub segment_index: u32,
397    /// Bounded 2D geometry.
398    pub geometry: ProjectionCurveGeometry,
399    /// Visible or hidden line classification.
400    pub visibility: ProjectionCurveVisibility,
401    /// Source topology/provenance.
402    pub source: ProjectionCurveSource,
403}
404
405/// What kind of cut to do
406#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
407#[serde(rename_all = "snake_case")]
408#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
409#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
410#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
411pub enum CutType {
412    /// Round off an edge.
413    #[default]
414    Fillet,
415    /// Cut away an edge.
416    Chamfer,
417}
418
419/// What to use as a direction when one is needed (e.g. for an extrusion).
420#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
421#[serde(rename_all = "snake_case")]
422#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
423#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
424#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
425pub enum DirectionType {
426    /// Uses the direction of an edge, if linear
427    Edge {
428        /// Edge ID.
429        id: Uuid,
430    },
431    /// Uses the provided vector as the direction.
432    Axis {
433        /// Direction.
434        direction: Point3d<f64>,
435    },
436}
437
438/// What to reflect mirrored geometry across
439#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
440#[serde(rename_all = "snake_case")]
441#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
442#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
443#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
444pub enum MirrorAcross {
445    /// Reflect across an edge
446    /// If used with a 3D mirror, the edge will define the normal of the mirror plane.
447    Edge {
448        /// Edge ID.
449        id: Uuid,
450    },
451    /// Reflect across an edge identified by its adjacent faces.
452    /// If used with a 3D mirror, the edge will define the normal of the mirror plane.
453    EdgeReference {
454        /// Stable edge reference.
455        reference: EdgeSpecifier,
456    },
457    /// Reflect across an axis (that goes through a point)
458    /// If used with a 3D mirror, the axis will define the normal of the mirror plane.
459    Axis {
460        /// Axis to use as mirror.
461        axis: Point3d<f64>,
462        /// Point through which the mirror axis passes.
463        point: Point3d<LengthUnit>,
464    },
465    /// Reflect across a plane (which gives two axes)
466    /// Cannot be used with 2D mirrors.
467    Plane {
468        /// Plane ID.
469        id: Uuid,
470    },
471}
472
473/// What kind of cut to perform when cutting an edge.
474#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
475#[serde(rename_all = "snake_case")]
476#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
477#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
478#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
479#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
480pub enum CutTypeV2 {
481    /// Round off an edge.
482    Fillet {
483        /// The radius of the fillet.
484        radius: LengthUnit,
485        /// The second length affects the edge length of the second face of the cut. This will
486        /// cause the fillet to take on the shape of a conic section, instead of an arc.
487        second_length: Option<LengthUnit>,
488    },
489    /// Cut away an edge.
490    Chamfer {
491        /// The distance from the edge to cut on each face.
492        distance: LengthUnit,
493        /// The second distance affects the edge length of the second face of the cut.
494        second_distance: Option<LengthUnit>,
495        /// The angle of the chamfer, default is 45deg.
496        angle: Option<Angle>,
497        /// If true, the second distance or angle is applied to the other face of the cut.
498        swap: bool,
499    },
500    /// A custom cut profile.
501    Custom {
502        /// The path that will be used for the custom profile.
503        path: Uuid,
504    },
505}
506
507/// A rotation defined by an axis, origin of rotation, and an angle.
508#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
509#[serde(rename_all = "snake_case")]
510#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
511#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
512#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
513#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
514pub struct Rotation {
515    /// Rotation axis.
516    /// Defaults to (0, 0, 1) (i.e. the Z axis).
517    pub axis: Point3d<f64>,
518    /// Rotate this far about the rotation axis.
519    /// Defaults to zero (i.e. no rotation).
520    pub angle: Angle,
521    /// Origin of the rotation. If one isn't provided, the object will rotate about its own bounding box center.
522    pub origin: OriginType,
523}
524
525impl Default for Rotation {
526    /// z-axis, 0 degree angle, and local origin.
527    fn default() -> Self {
528        Self {
529            axis: z_axis(),
530            angle: Angle::default(),
531            origin: OriginType::Local,
532        }
533    }
534}
535
536/// Ways to transform each solid being replicated in a repeating pattern.
537#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
538#[serde(rename_all = "snake_case")]
539#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
540#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
541#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
542#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
543pub struct Transform {
544    /// Translate the replica this far along each dimension.
545    /// Defaults to zero vector (i.e. same position as the original).
546    #[serde(default)]
547    #[builder(default)]
548    pub translate: Point3d<LengthUnit>,
549    /// Scale the replica's size along each axis.
550    /// Defaults to (1, 1, 1) (i.e. the same size as the original).
551    #[serde(default = "same_scale")]
552    #[builder(default = same_scale())]
553    pub scale: Point3d<f64>,
554    /// Rotate the replica about the specified rotation axis and origin.
555    /// Defaults to no rotation.
556    #[serde(default)]
557    #[builder(default)]
558    pub rotation: Rotation,
559    /// Whether to replicate the original solid in this instance.
560    #[serde(default = "bool_true")]
561    #[builder(default = bool_true())]
562    pub replicate: bool,
563}
564
565impl Default for Transform {
566    fn default() -> Self {
567        Self {
568            scale: same_scale(),
569            replicate: true,
570            translate: Default::default(),
571            rotation: Rotation::default(),
572        }
573    }
574}
575
576/// Options for annotations
577#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
578#[serde(rename_all = "snake_case")]
579#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
580#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
581#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
582#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
583pub struct AnnotationOptions {
584    /// Text displayed on the annotation
585    pub text: Option<AnnotationTextOptions>,
586    /// How to style the start and end of the line
587    pub line_ends: Option<AnnotationLineEndOptions>,
588    /// Width of the annotation's line
589    pub line_width: Option<f32>,
590    /// Color to render the annotation
591    pub color: Option<Color>,
592    /// Position to put the annotation
593    pub position: Option<Point3d<f32>>,
594    /// Length Units to use for this individual annotation.  If not provided, the units set by SetSceneUnits will be used.
595    #[serde(default, skip_serializing_if = "Option::is_none")]
596    pub units: Option<units::UnitLength>,
597    /// Set as an MBD measured basic dimension annotation
598    pub dimension: Option<AnnotationBasicDimension>,
599    /// Set as an MBD Feature control annotation
600    pub feature_control: Option<AnnotationFeatureControl>,
601    /// Set as a feature tag annotation
602    pub feature_tag: Option<AnnotationFeatureTag>,
603    /// Human-friendly identifier for this annotation.
604    /// Included in some exports and metadata of the model.
605    /// This is _not_ displayed visually in, the annotation,
606    /// it's only metadata.
607    #[serde(default, skip_serializing_if = "Option::is_none")]
608    pub name: Option<String>,
609}
610
611/// Options for annotation text
612#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
613#[serde(rename_all = "snake_case")]
614#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
615#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
616#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
617#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
618pub struct AnnotationLineEndOptions {
619    /// How to style the start of the annotation line.
620    pub start: AnnotationLineEnd,
621    /// How to style the end of the annotation line.
622    pub end: AnnotationLineEnd,
623}
624
625/// Options for annotation text
626#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
627#[serde(rename_all = "snake_case")]
628#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
629#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
630#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
631#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
632pub struct AnnotationTextOptions {
633    /// Alignment along the X axis
634    pub x: AnnotationTextAlignmentX,
635    /// Alignment along the Y axis
636    pub y: AnnotationTextAlignmentY,
637    /// Text displayed on the annotation
638    pub text: String,
639    /// Text font's point size
640    pub point_size: u32,
641}
642
643/// Parameters for defining a specific MBD Leader Position within an Entity
644#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
645#[serde(rename_all = "snake_case")]
646#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
647#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
648#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
649#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
650pub enum AnnotationMbdLeaderPosition {
651    /// Normalized position within the entity to position the annotation leader from
652    NormalizedPos {
653        /// The position
654        pos: Point2d<f64>,
655    },
656
657    /// Geometric Center of the entity (such as on the center axis for a cylinder)
658    Centroid {},
659
660    /// Used in dimension measurements for the to_entity_leader_pos field.
661    /// Determines the position using the previous "from" position stepped back (projected) onto the
662    /// planar entity (via planar projection or vector dot product)
663    StepFrom {},
664
665    /// Used in dimension measurements for the to_entity_leader_pos field.
666    /// Automatically determines which type of leader position to use.
667    /// If the entity is planar and this is a to_entity_leader_pos dimension field, then StepFrom is used.
668    /// If the entity is circular or cylindrical, Centroid is used.
669    /// If the entity is a linear edge NormalizedPos { 0.5, N/A } is used
670    /// If no other cases apply, then NormalizedPos { 0.5, 0.5 } is used
671    Auto {},
672}
673
674/// Parameters for defining an MBD Geometric control frame
675#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
676#[serde(rename_all = "snake_case")]
677#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
678#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
679#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
680#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
681pub struct AnnotationMbdControlFrame {
682    ///Geometric symbol, the type of geometric control specified
683    pub symbol: MbdSymbol,
684    /// Diameter symbol (if required) whether the geometric control requires a cylindrical or diameter tolerance
685    pub diameter_symbol: Option<MbdSymbol>,
686    /// Tolerance value - the total tolerance of the geometric control.
687    /// The unit is based on the drawing standard.
688    pub tolerance: f64,
689    /// Feature of size or tolerance modifiers
690    pub modifier: Option<MbdSymbol>,
691    /// Primary datum
692    pub primary_datum: Option<char>,
693    /// Secondary datum
694    pub secondary_datum: Option<char>,
695    /// Tertiary datum
696    pub tertiary_datum: Option<char>,
697}
698
699/// Parameters for defining an MBD basic dimension
700#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
701#[serde(rename_all = "snake_case")]
702#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
703#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
704#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
705#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
706pub struct AnnotationMbdBasicDimension {
707    /// Type of symbol to use for this dimension (if required)
708    pub symbol: Option<MbdSymbol>,
709    /// The explicitly defined dimension.
710    /// Only required if the measurement is not automatically calculated.
711    pub dimension: Option<f64>,
712    /// The tolerance of the dimension
713    #[serde(default, skip_serializing_if = "Option::is_none")]
714    pub tolerance: Option<f64>,
715}
716
717/// Parameters for defining an MBD Basic Dimension Annotation state which is measured between two positions in 3D
718#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
719#[serde(rename_all = "snake_case")]
720#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
721#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
722#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
723#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
724pub struct AnnotationBasicDimension {
725    /// Entity to measure the dimension from
726    #[serde(default, skip_serializing_if = "Option::is_none")]
727    pub from_entity_id: Option<Uuid>,
728
729    /// Edge reference to use to measure the dimension from
730    /// If both `from_entity_id` and `from_edge_reference` are provided, `from_edge_reference` takes precedence.
731    #[serde(default, skip_serializing_if = "Option::is_none")]
732    pub from_edge_reference: Option<EdgeSpecifier>,
733
734    /// Position within the entity to position the dimension leader from
735    #[serde(default, skip_serializing_if = "Option::is_none")]
736    pub from_entity_leader_pos: Option<AnnotationMbdLeaderPosition>,
737
738    /// Normalized position within the entity to position the dimension from
739    /// Deprecated; please use `from_entity_leader_pos`
740    #[serde(default, skip_serializing_if = "Option::is_none")]
741    pub from_entity_pos: Option<Point2d<f64>>,
742
743    /// Entity to measure the dimension to
744    #[serde(default, skip_serializing_if = "Option::is_none")]
745    pub to_entity_id: Option<Uuid>,
746
747    /// Edge reference to use to measure the dimension to
748    /// If both `to_entity_id` and `to_edge_reference` are provided, `to_edge_reference` takes precedence.
749    /// Note - If no "to" entity is provided, then a single leader is used to annotate the dimension.
750    #[serde(default, skip_serializing_if = "Option::is_none")]
751    pub to_edge_reference: Option<EdgeSpecifier>,
752
753    /// Position within the entity to position the dimension leader to
754    #[serde(default, skip_serializing_if = "Option::is_none")]
755    pub to_entity_leader_pos: Option<AnnotationMbdLeaderPosition>,
756
757    /// Normalized position within the entity to position the dimension to
758    /// Deprecated; please use `to_entity_leader_pos`
759    #[serde(default, skip_serializing_if = "Option::is_none")]
760    pub to_entity_pos: Option<Point2d<f64>>,
761
762    /// Basic dimension parameters (symbol and tolerance)
763    pub dimension: AnnotationMbdBasicDimension,
764
765    /// Orientation plane.  The annotation will lie in this plane which is positioned about the leader position as its origin.
766    pub plane_id: Uuid,
767
768    /// 2D Position offset of the annotation within the plane.
769    pub offset: Point2d<f64>,
770
771    /// Number of decimal places to use when displaying tolerance and dimension values
772    pub precision: u32,
773
774    /// The scale of the font label in 3D space
775    pub font_scale: f32,
776
777    /// The point size of the fonts used to generate the annotation label.  Very large values can negatively affect performance.
778    pub font_point_size: u32,
779
780    /// The scale of the dimension arrows. Defaults to 1.
781    #[serde(default = "one")]
782    pub arrow_scale: f32,
783}
784
785/// Parameters for defining an MBD Feature Control Annotation state
786#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
787#[serde(rename_all = "snake_case")]
788#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
789#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
790#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
791#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
792pub struct AnnotationFeatureControl {
793    /// Entity to place the annotation leader from
794    #[serde(default, skip_serializing_if = "Option::is_none")]
795    pub entity_id: Option<Uuid>,
796
797    /// Edge reference to use to place the annotation leader from
798    /// If both `entity_id` and `edge_reference` are provided, `edge_reference` takes precedence.
799    #[serde(default, skip_serializing_if = "Option::is_none")]
800    pub edge_reference: Option<EdgeSpecifier>,
801
802    /// Position within the entity to position the annotation leader from
803    #[serde(default, skip_serializing_if = "Option::is_none")]
804    pub entity_leader_pos: Option<AnnotationMbdLeaderPosition>,
805
806    /// Normalized position within the entity to position the annotation leader from
807    /// Deprecated; please use `entity_leader_pos`
808    #[serde(default, skip_serializing_if = "Option::is_none")]
809    pub entity_pos: Option<Point2d<f64>>,
810
811    /// Type of leader to use
812    pub leader_type: AnnotationLineEnd,
813
814    /// Basic dimensions
815    pub dimension: Option<AnnotationMbdBasicDimension>,
816
817    /// MBD Control frame for geometric control
818    pub control_frame: Option<AnnotationMbdControlFrame>,
819
820    /// Set if this annotation is defining a datum
821    pub defined_datum: Option<char>,
822
823    /// Prefix text which will appear before the basic dimension
824    pub prefix: Option<String>,
825
826    /// Suffix text which will appear after the basic dimension
827    pub suffix: Option<String>,
828
829    /// Orientation plane.  The annotation will lie in this plane which is positioned about the leader position as its origin.
830    pub plane_id: Uuid,
831
832    /// 2D Position offset of the annotation within the plane.
833    pub offset: Point2d<f64>,
834
835    /// Number of decimal places to use when displaying tolerance and dimension values
836    pub precision: u32,
837
838    /// The scale of the font label in 3D space
839    pub font_scale: f32,
840
841    /// The point size of the fonts used to generate the annotation label.  Very large values can negatively affect performance.
842    pub font_point_size: u32,
843
844    /// The scale of the leader (dot or arrow). Defaults to 1.
845    #[serde(default = "one")]
846    pub leader_scale: f32,
847}
848
849/// Parameters for defining an MBD Feature Tag Annotation state
850#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
851#[serde(rename_all = "snake_case")]
852#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
853#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
854#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
855#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
856pub struct AnnotationFeatureTag {
857    /// Entity to place the annotation leader from
858    #[serde(default, skip_serializing_if = "Option::is_none")]
859    pub entity_id: Option<Uuid>,
860
861    /// Edge reference to use to place the annotation leader from
862    /// If both `entity_id` and `edge_reference` are provided, `edge_reference` takes precedence.
863    #[serde(default, skip_serializing_if = "Option::is_none")]
864    pub edge_reference: Option<EdgeSpecifier>,
865
866    /// Position within the entity to position the annotation leader from
867    #[serde(default, skip_serializing_if = "Option::is_none")]
868    pub entity_leader_pos: Option<AnnotationMbdLeaderPosition>,
869
870    /// Normalized position within the entity to position the annotation leader from
871    /// Deprecated; please use `entity_leader_pos`
872    #[serde(default, skip_serializing_if = "Option::is_none")]
873    pub entity_pos: Option<Point2d<f64>>,
874
875    /// Type of leader to use
876    pub leader_type: AnnotationLineEnd,
877
878    /// Tag key
879    pub key: String,
880
881    /// Tag value
882    pub value: String,
883
884    /// Whether or not to display the key on the annotation label
885    pub show_key: bool,
886
887    /// Orientation plane.  The annotation will lie in this plane which is positioned about the leader position as its origin.
888    pub plane_id: Uuid,
889
890    /// 2D Position offset of the annotation within the plane.
891    pub offset: Point2d<f64>,
892
893    /// The scale of the font label in 3D space
894    pub font_scale: f32,
895
896    /// The point size of the fonts used to generate the annotation label.  Very large values can negatively affect performance.
897    pub font_point_size: u32,
898
899    /// The scale of the leader (dot or arrow). Defaults to 1.
900    #[serde(default = "one")]
901    pub leader_scale: f32,
902}
903
904/// The type of distance
905/// Distances can vary depending on
906/// the objects used as input.
907#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
908#[serde(rename_all = "snake_case", tag = "type")]
909#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
910#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
911#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
912#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
913pub enum DistanceType {
914    /// Euclidean Distance.
915    Euclidean {},
916    /// The distance between objects along the specified axis
917    OnAxis {
918        /// Global axis
919        axis: GlobalAxis,
920    },
921}
922
923/// The type of origin
924#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
925#[serde(rename_all = "snake_case", tag = "type")]
926#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
927#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
928#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
929#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
930pub enum OriginType {
931    /// Local Origin ([0, 0, 0] in object space).
932    #[default]
933    Local,
934    /// Global Origin ([0, 0, 0] in world space).
935    Global,
936    /// Custom Origin (user specified point in world space).
937    Custom {
938        /// Custom origin point.
939        origin: Point3d<f64>,
940    },
941}
942
943/// An RGBA color
944#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
945#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
946#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
947#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
948#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
949pub struct Color {
950    /// Red
951    pub r: f32,
952    /// Green
953    pub g: f32,
954    /// Blue
955    pub b: f32,
956    /// Alpha
957    pub a: f32,
958}
959
960impl Color {
961    /// Assign the red, green, blue and alpha (transparency) channels.
962    pub fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Self {
963        Self { r, g, b, a }
964    }
965}
966
967/// Horizontal Text alignment
968#[allow(missing_docs)]
969#[derive(
970    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
971)]
972#[serde(rename_all = "lowercase")]
973#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
974#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
975#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
976#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
977pub enum AnnotationTextAlignmentX {
978    Left,
979    Center,
980    Right,
981}
982
983/// Vertical Text alignment
984#[allow(missing_docs)]
985#[derive(
986    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
987)]
988#[serde(rename_all = "lowercase")]
989#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
990#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
991#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
992#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
993pub enum AnnotationTextAlignmentY {
994    Bottom,
995    Center,
996    Top,
997}
998
999/// Annotation line end type
1000#[allow(missing_docs)]
1001#[derive(
1002    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
1003)]
1004#[serde(rename_all = "lowercase")]
1005#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1006#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1007#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1008#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1009pub enum AnnotationLineEnd {
1010    None,
1011    Arrow,
1012    Dot,
1013}
1014
1015/// The type of annotation
1016#[derive(
1017    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
1018)]
1019#[serde(rename_all = "lowercase")]
1020#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1021#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1022#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1023#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1024pub enum AnnotationType {
1025    /// 2D annotation type (screen or planar space)
1026    T2D,
1027    /// 3D annotation type
1028    T3D,
1029}
1030
1031/// MBD standard
1032#[derive(
1033    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
1034)]
1035#[serde(rename_all = "lowercase")]
1036#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1037#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1038#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1039#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1040pub enum MbdStandard {
1041    /// ASME Y14.5 GD&T
1042    AsmeY14_5,
1043}
1044
1045//SEE MIKE BEFORE MAKING ANY CHANGES TO THIS ENUM
1046/// MBD symbol type
1047#[allow(missing_docs)]
1048#[derive(
1049    Default,
1050    Display,
1051    FromStr,
1052    Copy,
1053    Eq,
1054    PartialEq,
1055    Debug,
1056    JsonSchema,
1057    Deserialize,
1058    Serialize,
1059    Sequence,
1060    Clone,
1061    Ord,
1062    PartialOrd,
1063)]
1064#[serde(rename_all = "lowercase")]
1065#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1066#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1067#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1068#[repr(u16)]
1069#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1070pub enum MbdSymbol {
1071    #[default]
1072    None = 0,
1073    ArcLength = 174,
1074    Between = 175,
1075    Degrees = 176,
1076    PlusMinus = 177,
1077    Angularity = 178,
1078    Cylindricity = 179,
1079    Roundness = 180,
1080    Concentricity = 181,
1081    Straightness = 182,
1082    Parallelism = 183,
1083    Flatness = 184,
1084    ProfileOfLine = 185,
1085    SurfaceProfile = 186,
1086    Symmetry = 187,
1087    Perpendicularity = 188,
1088    Runout = 189,
1089    TotalRunout = 190,
1090    Position = 191,
1091    CenterLine = 192,
1092    PartingLine = 193,
1093    IsoEnvelope = 195,
1094    IsoEnvelopeNonY145M = 196,
1095    FreeState = 197,
1096    StatisticalTolerance = 198,
1097    ContinuousFeature = 199,
1098    Independency = 200,
1099    Depth = 201,
1100    Start = 202,
1101    LeastCondition = 203,
1102    MaxCondition = 204,
1103    ConicalTaper = 205,
1104    Projected = 206,
1105    Slope = 207,
1106    Micro = 208,
1107    TangentPlane = 210,
1108    Unilateral = 211,
1109    SquareFeature = 212,
1110    Countersink = 213,
1111    SpotFace = 214,
1112    Target = 215,
1113    Diameter = 216,
1114    Radius = 217,
1115    SphericalRadius = 218,
1116    SphericalDiameter = 219,
1117    ControlledRadius = 220,
1118    BoxStart = 123,
1119    BoxBar = 162,
1120    BoxBarBetween = 124,
1121    LetterBackwardUnderline = 95,
1122    PunctuationBackwardUnderline = 92,
1123    ModifierBackwardUnderline = 126,
1124    NumericBackwardUnderline = 96,
1125    BoxEnd = 125,
1126    DatumUp = 166,
1127    DatumLeft = 168,
1128    DatumRight = 167,
1129    DatumDown = 165,
1130    DatumTriangle = 295,
1131    HalfSpace = 236,
1132    QuarterSpace = 237,
1133    EighthSpace = 238,
1134    ModifierSpace = 239,
1135}
1136
1137/// The type of camera drag interaction.
1138#[derive(
1139    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
1140)]
1141#[serde(rename_all = "lowercase")]
1142#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1143#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1144#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1145#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1146pub enum CameraDragInteractionType {
1147    /// Camera pan
1148    Pan,
1149    /// Camera rotate (spherical camera revolve/orbit)
1150    Rotate,
1151    /// Camera rotate (trackball with 3 degrees of freedom)
1152    RotateTrackball,
1153    /// Camera zoom (increase or decrease distance to reference point center)
1154    Zoom,
1155}
1156
1157/// A segment of a path.
1158/// Paths are composed of many segments.
1159#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq)]
1160#[serde(rename_all = "snake_case", tag = "type")]
1161#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1162#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1163#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1164#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1165pub enum PathSegment {
1166    /// A straight line segment.
1167    /// Goes from the current path "pen" to the given endpoint.
1168    Line {
1169        /// End point of the line.
1170        end: Point3d<LengthUnit>,
1171        ///Whether or not this line is a relative offset
1172        relative: bool,
1173    },
1174    /// A circular arc segment.
1175    /// Arcs can be drawn clockwise when start > end.
1176    Arc {
1177        /// Center of the circle
1178        center: Point2d<LengthUnit>,
1179        /// Radius of the circle
1180        radius: LengthUnit,
1181        /// Start of the arc along circle's perimeter.
1182        start: Angle,
1183        /// End of the arc along circle's perimeter.
1184        end: Angle,
1185        ///Whether or not this arc is a relative offset
1186        relative: bool,
1187    },
1188    /// A cubic bezier curve segment.
1189    /// Start at the end of the current line, go through control point 1 and 2, then end at a
1190    /// given point.
1191    Bezier {
1192        /// First control point.
1193        control1: Point3d<LengthUnit>,
1194        /// Second control point.
1195        control2: Point3d<LengthUnit>,
1196        /// Final control point.
1197        end: Point3d<LengthUnit>,
1198        ///Whether or not this bezier is a relative offset
1199        relative: bool,
1200    },
1201    /// Adds a tangent arc from current pen position with the given radius and angle.
1202    TangentialArc {
1203        /// Radius of the arc.
1204        /// Not to be confused with Raiders of the Lost Ark.
1205        radius: LengthUnit,
1206        /// Offset of the arc. Negative values will arc clockwise.
1207        offset: Angle,
1208    },
1209    /// Adds a tangent arc from current pen position to the new position.
1210    /// Arcs will choose a clockwise or counter-clockwise direction based on the arc end position.
1211    TangentialArcTo {
1212        /// Where the arc should end.
1213        /// Must lie in the same plane as the current path pen position.
1214        /// Must not be colinear with current path pen position.
1215        to: Point3d<LengthUnit>,
1216        /// 0 will be interpreted as none/null.
1217        angle_snap_increment: Option<Angle>,
1218    },
1219    ///Adds an arc from the current position that goes through the given interior point and ends at the given end position
1220    ArcTo {
1221        /// Interior point of the arc.
1222        interior: Point3d<LengthUnit>,
1223        /// End point of the arc.
1224        end: Point3d<LengthUnit>,
1225        ///Whether or not interior and end are relative to the previous path position
1226        relative: bool,
1227    },
1228    ///Adds a circular involute from the current position that goes through the given end_radius
1229    ///and is rotated around the current point by angle.
1230    CircularInvolute {
1231        ///The involute is described between two circles, start_radius is the radius of the inner
1232        ///circle.
1233        start_radius: LengthUnit,
1234        ///The involute is described between two circles, end_radius is the radius of the outer
1235        ///circle.
1236        end_radius: LengthUnit,
1237        ///The angle to rotate the involute by. A value of zero will produce a curve with a tangent
1238        ///along the x-axis at the start point of the curve.
1239        angle: Angle,
1240        ///If reverse is true, the segment will start
1241        ///from the end of the involute, otherwise it will start from that start.
1242        reverse: bool,
1243    },
1244    ///Adds an elliptical arc segment.
1245    Ellipse {
1246        /// The center point of the ellipse.
1247        center: Point2d<LengthUnit>,
1248        /// Major axis of the ellipse.
1249        major_axis: Point2d<LengthUnit>,
1250        /// Minor radius of the ellipse.
1251        minor_radius: LengthUnit,
1252        /// Start of the path along the perimeter of the ellipse.
1253        start_angle: Angle,
1254        /// End of the path along the perimeter of the ellipse.
1255        end_angle: Angle,
1256    },
1257    ///Adds a generic conic section specified by the end point, interior point and tangents at the
1258    ///start and end of the section.
1259    ConicTo {
1260        /// Interior point that lies on the conic.
1261        interior: Point2d<LengthUnit>,
1262        /// End point of the conic.
1263        end: Point2d<LengthUnit>,
1264        /// Tangent at the start of the conic.
1265        start_tangent: Point2d<LengthUnit>,
1266        /// Tangent at the end of the conic.
1267        end_tangent: Point2d<LengthUnit>,
1268        /// Whether or not the interior and end points are relative to the previous path position.
1269        relative: bool,
1270    },
1271}
1272
1273/// An angle, with a specific unit.
1274#[derive(Clone, Copy, PartialEq, Debug, JsonSchema, Deserialize, Serialize)]
1275#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1276#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1277#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1278#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1279pub struct Angle {
1280    /// What unit is the measurement?
1281    pub unit: UnitAngle,
1282    /// The size of the angle, measured in the chosen unit.
1283    pub value: f64,
1284}
1285
1286impl Angle {
1287    /// Converts a given angle to degrees.
1288    pub fn to_degrees(self) -> f64 {
1289        match self.unit {
1290            UnitAngle::Degrees => self.value,
1291            UnitAngle::Radians => self.value.to_degrees(),
1292        }
1293    }
1294    /// Converts a given angle to radians.
1295    pub fn to_radians(self) -> f64 {
1296        match self.unit {
1297            UnitAngle::Degrees => self.value.to_radians(),
1298            UnitAngle::Radians => self.value,
1299        }
1300    }
1301    /// Create an angle in degrees.
1302    pub const fn from_degrees(value: f64) -> Self {
1303        Self {
1304            unit: UnitAngle::Degrees,
1305            value,
1306        }
1307    }
1308    /// Create an angle in radians.
1309    pub const fn from_radians(value: f64) -> Self {
1310        Self {
1311            unit: UnitAngle::Radians,
1312            value,
1313        }
1314    }
1315    /// 360 degrees.
1316    pub const fn turn() -> Self {
1317        Self::from_degrees(360.0)
1318    }
1319    /// 180 degrees.
1320    pub const fn half_circle() -> Self {
1321        Self::from_degrees(180.0)
1322    }
1323    /// 90 degrees.
1324    pub const fn quarter_circle() -> Self {
1325        Self::from_degrees(90.0)
1326    }
1327    /// 0 degrees.
1328    pub const fn zero() -> Self {
1329        Self::from_degrees(0.0)
1330    }
1331}
1332
1333/// 0 degrees.
1334impl Default for Angle {
1335    /// 0 degrees.
1336    fn default() -> Self {
1337        Self::zero()
1338    }
1339}
1340
1341impl PartialOrd for Angle {
1342    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
1343        match (self.unit, other.unit) {
1344            // Avoid unnecessary floating point operations.
1345            (UnitAngle::Degrees, UnitAngle::Degrees) => self.value.partial_cmp(&other.value),
1346            (UnitAngle::Radians, UnitAngle::Radians) => self.value.partial_cmp(&other.value),
1347            _ => self.to_degrees().partial_cmp(&other.to_degrees()),
1348        }
1349    }
1350}
1351
1352impl std::ops::Add for Angle {
1353    type Output = Self;
1354
1355    fn add(self, rhs: Self) -> Self::Output {
1356        Self {
1357            unit: UnitAngle::Degrees,
1358            value: self.to_degrees() + rhs.to_degrees(),
1359        }
1360    }
1361}
1362
1363impl std::ops::AddAssign for Angle {
1364    fn add_assign(&mut self, rhs: Self) {
1365        match self.unit {
1366            UnitAngle::Degrees => {
1367                self.value += rhs.to_degrees();
1368            }
1369            UnitAngle::Radians => {
1370                self.value += rhs.to_radians();
1371            }
1372        }
1373    }
1374}
1375
1376/// The type of scene selection change
1377#[derive(
1378    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
1379)]
1380#[serde(rename_all = "lowercase")]
1381#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1382#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1383#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1384#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1385pub enum SceneSelectionType {
1386    /// Replaces the selection
1387    Replace,
1388    /// Adds to the selection
1389    Add,
1390    /// Removes from the selection
1391    Remove,
1392}
1393
1394/// The type of scene's active tool
1395#[allow(missing_docs)]
1396#[derive(
1397    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
1398)]
1399#[serde(rename_all = "snake_case")]
1400#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1401#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1402#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1403#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1404pub enum SceneToolType {
1405    CameraRevolve,
1406    Select,
1407    Move,
1408    SketchLine,
1409    SketchTangentialArc,
1410    SketchCurve,
1411    SketchCurveMod,
1412}
1413
1414/// The path component constraint bounds type
1415#[allow(missing_docs)]
1416#[derive(
1417    Display,
1418    FromStr,
1419    Copy,
1420    Eq,
1421    PartialEq,
1422    Debug,
1423    JsonSchema,
1424    Deserialize,
1425    Serialize,
1426    Sequence,
1427    Clone,
1428    Ord,
1429    PartialOrd,
1430    Default,
1431)]
1432#[serde(rename_all = "snake_case")]
1433#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1434#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1435#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1436#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1437pub enum PathComponentConstraintBound {
1438    #[default]
1439    Unconstrained,
1440    PartiallyConstrained,
1441    FullyConstrained,
1442}
1443
1444/// The path component constraint type
1445#[allow(missing_docs)]
1446#[derive(
1447    Display,
1448    FromStr,
1449    Copy,
1450    Eq,
1451    PartialEq,
1452    Debug,
1453    JsonSchema,
1454    Deserialize,
1455    Serialize,
1456    Sequence,
1457    Clone,
1458    Ord,
1459    PartialOrd,
1460    Default,
1461)]
1462#[serde(rename_all = "snake_case")]
1463#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1464#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1465#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1466#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1467pub enum PathComponentConstraintType {
1468    #[default]
1469    Unconstrained,
1470    Vertical,
1471    Horizontal,
1472    EqualLength,
1473    Parallel,
1474    AngleBetween,
1475}
1476
1477/// The path component command type (within a Path)
1478#[allow(missing_docs)]
1479#[derive(
1480    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
1481)]
1482#[serde(rename_all = "snake_case")]
1483#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1484#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1485#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1486#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1487pub enum PathCommand {
1488    MoveTo,
1489    LineTo,
1490    BezCurveTo,
1491    NurbsCurveTo,
1492    AddArc,
1493}
1494
1495/// The type of entity
1496#[allow(missing_docs)]
1497#[derive(
1498    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
1499)]
1500#[serde(rename_all = "lowercase")]
1501#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1502#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1503#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1504#[repr(u8)]
1505#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1506pub enum EntityType {
1507    Entity,
1508    Object,
1509    Path,
1510    Segment,
1511    Curve,
1512    Solid2D,
1513    Solid3D,
1514    Edge,
1515    Face,
1516    Plane,
1517    Vertex,
1518    Region,
1519    PatternGroup,
1520    Annotation,
1521}
1522
1523/// Visibility of an object, or whether the requested object does not exist.
1524#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
1525#[serde(rename_all = "snake_case")]
1526#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1527#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1528#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1529#[repr(u8)]
1530#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1531pub enum HiddenState {
1532    /// The object exists and is hidden.
1533    Hidden = 0,
1534    /// The object exists and is visible.
1535    Visible = 1,
1536    /// No object exists for the requested UUID.
1537    NoSuchObject = 2,
1538}
1539
1540/// The type of Curve (embedded within path)
1541#[allow(missing_docs)]
1542#[derive(
1543    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
1544)]
1545#[serde(rename_all = "snake_case")]
1546#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1547#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1548#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1549#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1550pub enum CurveType {
1551    Line,
1552    Arc,
1553    Nurbs,
1554}
1555
1556/// A file to be exported to the client.
1557#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, PartialEq, Builder)]
1558#[cfg_attr(
1559    feature = "python",
1560    pyo3::pyclass(from_py_object),
1561    pyo3_stub_gen::derive::gen_stub_pyclass
1562)]
1563#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1564pub struct ExportFile {
1565    /// The name of the file.
1566    pub name: String,
1567    /// The contents of the file, base64 encoded.
1568    pub contents: crate::base64::Base64Data,
1569}
1570
1571#[cfg(feature = "python")]
1572#[pyo3_stub_gen::derive::gen_stub_pymethods]
1573#[pyo3::pymethods]
1574impl ExportFile {
1575    #[getter]
1576    fn contents(&self) -> Vec<u8> {
1577        self.contents.0.clone()
1578    }
1579
1580    #[getter]
1581    fn name(&self) -> String {
1582        self.name.clone()
1583    }
1584}
1585
1586/// The valid types of output file formats.
1587#[derive(
1588    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd, Sequence,
1589)]
1590#[serde(rename_all = "lowercase")]
1591#[display(style = "lowercase")]
1592#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1593#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1594#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1595#[cfg_attr(
1596    feature = "python",
1597    pyo3::pyclass(from_py_object),
1598    pyo3_stub_gen::derive::gen_stub_pyclass_enum
1599)]
1600#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1601pub enum FileExportFormat {
1602    /// Autodesk Filmbox (FBX) format. <https://en.wikipedia.org/wiki/FBX>
1603    Fbx,
1604    /// Binary glTF 2.0.
1605    ///
1606    /// This is a single binary with .glb extension.
1607    ///
1608    /// This is better if you want a compressed format as opposed to the human readable
1609    /// glTF that lacks compression.
1610    Glb,
1611    /// glTF 2.0.
1612    /// Embedded glTF 2.0 (pretty printed).
1613    ///
1614    /// Single JSON file with .gltf extension binary data encoded as
1615    /// base64 data URIs.
1616    ///
1617    /// The JSON contents are pretty printed.
1618    ///
1619    /// It is human readable, single file, and you can view the
1620    /// diff easily in a git commit.
1621    Gltf,
1622    /// The OBJ file format. <https://en.wikipedia.org/wiki/Wavefront_.obj_file>
1623    /// It may or may not have an an attached material (mtl // mtllib) within the file,
1624    /// but we interact with it as if it does not.
1625    Obj,
1626    /// The PLY file format. <https://en.wikipedia.org/wiki/PLY_(file_format)>
1627    Ply,
1628    /// The STEP file format. <https://en.wikipedia.org/wiki/ISO_10303-21>
1629    Step,
1630    /// The STL file format. <https://en.wikipedia.org/wiki/STL_(file_format)>
1631    Stl,
1632    /// The 3DM file format. <https://deepwiki.com/mcneel/rhino3dm/6.1-3dm-file-format>
1633    Rhino,
1634}
1635
1636/// The valid types of 2D output file formats.
1637#[derive(
1638    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd, Sequence,
1639)]
1640#[serde(rename_all = "lowercase")]
1641#[display(style = "lowercase")]
1642#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1643#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1644#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1645#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1646pub enum FileExportFormat2d {
1647    /// AutoCAD drawing interchange format.
1648    Dxf,
1649}
1650
1651/// The valid types of source file formats.
1652#[derive(
1653    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd, Sequence,
1654)]
1655#[serde(rename_all = "lowercase")]
1656#[display(style = "lowercase")]
1657#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1658#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1659#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1660#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1661pub enum FileImportFormat {
1662    /// ACIS part format.
1663    Acis,
1664    /// CATIA part format.
1665    Catia,
1666    /// PTC Creo part format.
1667    Creo,
1668    /// Autodesk Filmbox (FBX) format. <https://en.wikipedia.org/wiki/FBX>
1669    Fbx,
1670    /// glTF 2.0.
1671    Gltf,
1672    /// Autodesk Inventor part format.
1673    Inventor,
1674    /// Siemens NX part format.
1675    Nx,
1676    /// The OBJ file format. <https://en.wikipedia.org/wiki/Wavefront_.obj_file>
1677    /// It may or may not have an an attached material (mtl // mtllib) within the file,
1678    /// but we interact with it as if it does not.
1679    Obj,
1680    /// Parasolid part format.
1681    Parasolid,
1682    /// The PLY file format. <https://en.wikipedia.org/wiki/PLY_(file_format)>
1683    Ply,
1684    /// SolidWorks part (SLDPRT) format.
1685    Sldprt,
1686    /// The STEP file format. <https://en.wikipedia.org/wiki/ISO_10303-21>
1687    Step,
1688    /// The STL file format. <https://en.wikipedia.org/wiki/STL_(file_format)>
1689    Stl,
1690    /// The 3DM file format. <https://deepwiki.com/mcneel/rhino3dm/6.1-3dm-file-format>
1691    Rhino,
1692}
1693
1694/// The type of error sent by the KittyCAD graphics engine.
1695#[derive(Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd)]
1696#[serde(rename_all = "snake_case")]
1697#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1698#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1699#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1700#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1701pub enum EngineErrorCode {
1702    /// User requested something geometrically or graphically impossible.
1703    /// Don't retry this request, as it's inherently impossible. Instead, read the error message
1704    /// and change your request.
1705    BadRequest = 1,
1706    /// Graphics engine failed to complete request, consider retrying
1707    InternalEngine,
1708}
1709
1710impl From<EngineErrorCode> for http::StatusCode {
1711    fn from(e: EngineErrorCode) -> Self {
1712        match e {
1713            EngineErrorCode::BadRequest => Self::BAD_REQUEST,
1714            EngineErrorCode::InternalEngine => Self::INTERNAL_SERVER_ERROR,
1715        }
1716    }
1717}
1718
1719/// What kind of blend to do
1720#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
1721#[serde(rename_all = "snake_case")]
1722#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1723#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1724#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1725pub enum BlendType {
1726    /// Use the tangent of the surfaces to calculate the blend.
1727    #[default]
1728    Tangent,
1729}
1730
1731/// Body type determining if the operation will create a manifold (solid) body or a non-manifold collection of surfaces.
1732#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
1733#[serde(rename_all = "snake_case")]
1734#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1735#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1736#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1737#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1738pub enum BodyType {
1739    ///Defines a body that is manifold.
1740    #[default]
1741    Solid,
1742    ///Defines a body that is non-manifold (an open collection of connected surfaces).
1743    Surface,
1744}
1745
1746/// Extrusion method determining if the extrusion will be part of the existing object or an
1747/// entirely new object.
1748#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
1749#[serde(rename_all = "snake_case")]
1750#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1751#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1752#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1753#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1754pub enum ExtrudeMethod {
1755    /// Create a new object that is not connected to the object it is extruded from. This will
1756    /// result in two objects after the operation.
1757    New,
1758    /// This extrusion will be part of object it is extruded from. This will result in one object
1759    /// after the operation.
1760    #[default]
1761    Merge,
1762}
1763
1764/// Type of reference geometry to extrude to.
1765#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
1766#[serde(rename_all = "snake_case")]
1767#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1768#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1769#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1770#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1771pub enum ExtrudeReference {
1772    /// Extrudes along the normal of the top face until it is as close to the entity as possible.
1773    /// An entity can be a solid, a path, a face, an edge (via `entity_reference`), etc.
1774    EntityReference {
1775        /// Legacy UUID of the entity to extrude to. If both `entity_id` and `entity_reference` are provided, `entity_reference` takes precedence.
1776        #[serde(default, skip_serializing_if = "Option::is_none")]
1777        entity_id: Option<Uuid>,
1778        /// Entity reference (e.g. edge by side_faces). If both `entity_id` and `entity_reference` are provided, `entity_reference` takes precedence.
1779        #[serde(default, skip_serializing_if = "Option::is_none")]
1780        entity_reference: Option<EntityReference>,
1781    },
1782    /// Extrudes until the top face is as close as possible to this given axis.
1783    Axis {
1784        /// The axis to extrude to.
1785        axis: Point3d<f64>,
1786        /// Point the axis goes through.
1787        /// Defaults to (0, 0, 0).
1788        #[serde(default)]
1789        point: Point3d<LengthUnit>,
1790    },
1791    /// Extrudes until the top face is as close as possible to this given point.
1792    Point {
1793        /// The point to extrude to.
1794        point: Point3d<LengthUnit>,
1795    },
1796}
1797
1798/// IDs for the extruded faces.
1799#[derive(Debug, PartialEq, Serialize, Deserialize, JsonSchema, Clone, Builder)]
1800#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1801#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1802#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1803#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1804pub struct ExtrudedFaceInfo {
1805    /// The face made from the original 2D shape being extruded.
1806    /// If the solid is extruded from a shape which already has an ID
1807    /// (e.g. extruding something which was sketched on a face), this
1808    /// doesn't need to be sent.
1809    pub bottom: Option<Uuid>,
1810    /// Top face of the extrusion (parallel and further away from the original 2D shape being extruded).
1811    pub top: Uuid,
1812    /// Any intermediate sides between the top and bottom.
1813    pub sides: Vec<SideFace>,
1814}
1815
1816/// IDs for a side face, extruded from the path of some sketch/2D shape.
1817#[derive(Debug, PartialEq, Serialize, Deserialize, JsonSchema, Clone, Builder)]
1818#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1819#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1820#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1821#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1822pub struct SideFace {
1823    /// ID of the path this face is being extruded from.
1824    pub path_id: Uuid,
1825    /// Desired ID for the resulting face.
1826    pub face_id: Uuid,
1827}
1828
1829/// Camera settings including position, center, fov etc
1830#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, PartialEq, Builder)]
1831#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1832#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1833#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1834#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1835pub struct CameraSettings {
1836    ///Camera position (vantage)
1837    pub pos: Point3d,
1838
1839    ///Camera's look-at center (center-pos gives viewing vector)
1840    pub center: Point3d,
1841
1842    ///Camera's world-space up vector
1843    pub up: Point3d,
1844
1845    ///The Camera's orientation (in the form of a quaternion)
1846    pub orientation: Quaternion,
1847
1848    ///Camera's field-of-view angle (if ortho is false)
1849    pub fov_y: Option<f32>,
1850
1851    ///The camera's ortho scale (derived from viewing distance if ortho is true)
1852    pub ortho_scale: Option<f32>,
1853
1854    ///Whether or not the camera is in ortho mode
1855    pub ortho: bool,
1856}
1857
1858#[allow(missing_docs)]
1859#[repr(u8)]
1860#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
1861#[serde(rename_all = "snake_case")]
1862#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1863#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1864#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1865#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1866pub enum WorldCoordinateSystem {
1867    #[default]
1868    RightHandedUpZ,
1869    RightHandedUpY,
1870}
1871
1872#[allow(missing_docs)]
1873#[repr(C)]
1874#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
1875#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1876#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1877#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1878#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1879pub struct CameraViewState {
1880    pub pivot_rotation: Quaternion,
1881    pub pivot_position: Point3d,
1882    pub eye_offset: f32,
1883    pub fov_y: f32,
1884    pub ortho_scale_factor: f32,
1885    pub is_ortho: bool,
1886    pub ortho_scale_enabled: bool,
1887    pub world_coord_system: WorldCoordinateSystem,
1888}
1889
1890impl Default for CameraViewState {
1891    fn default() -> Self {
1892        CameraViewState {
1893            pivot_rotation: Default::default(),
1894            pivot_position: Default::default(),
1895            eye_offset: 10.0,
1896            fov_y: 45.0,
1897            ortho_scale_factor: 1.6,
1898            is_ortho: false,
1899            ortho_scale_enabled: true,
1900            world_coord_system: Default::default(),
1901        }
1902    }
1903}
1904
1905#[cfg(feature = "cxx")]
1906impl_extern_type! {
1907    [Trivial]
1908    CameraViewState = "Endpoints::CameraViewState"
1909}
1910
1911impl From<CameraSettings> for crate::output::DefaultCameraZoom {
1912    fn from(settings: CameraSettings) -> Self {
1913        Self { settings }
1914    }
1915}
1916impl From<CameraSettings> for crate::output::CameraDragMove {
1917    fn from(settings: CameraSettings) -> Self {
1918        Self { settings }
1919    }
1920}
1921impl From<CameraSettings> for crate::output::CameraDragEnd {
1922    fn from(settings: CameraSettings) -> Self {
1923        Self { settings }
1924    }
1925}
1926impl From<CameraSettings> for crate::output::DefaultCameraGetSettings {
1927    fn from(settings: CameraSettings) -> Self {
1928        Self { settings }
1929    }
1930}
1931impl From<CameraSettings> for crate::output::ZoomToFit {
1932    fn from(settings: CameraSettings) -> Self {
1933        Self { settings }
1934    }
1935}
1936impl From<CameraSettings> for crate::output::OrientToFace {
1937    fn from(settings: CameraSettings) -> Self {
1938        Self { settings }
1939    }
1940}
1941impl From<CameraSettings> for crate::output::ViewIsometric {
1942    fn from(settings: CameraSettings) -> Self {
1943        Self { settings }
1944    }
1945}
1946
1947/// Defines a perspective view.
1948#[derive(Copy, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, PartialOrd, Default, Builder)]
1949#[serde(rename_all = "snake_case")]
1950#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1951#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1952#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1953#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1954pub struct PerspectiveCameraParameters {
1955    /// Camera frustum vertical field of view.
1956    pub fov_y: Option<f32>,
1957    /// Camera frustum near plane.
1958    pub z_near: Option<f32>,
1959    /// Camera frustum far plane.
1960    pub z_far: Option<f32>,
1961}
1962
1963/// A type of camera movement applied after certain camera operations
1964#[derive(
1965    Default,
1966    Display,
1967    FromStr,
1968    Copy,
1969    Eq,
1970    PartialEq,
1971    Debug,
1972    JsonSchema,
1973    Deserialize,
1974    Serialize,
1975    Sequence,
1976    Clone,
1977    Ord,
1978    PartialOrd,
1979)]
1980#[serde(rename_all = "snake_case")]
1981#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1982#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1983#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1984#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
1985pub enum CameraMovement {
1986    /// Adjusts the camera position during the camera operation
1987    #[default]
1988    Vantage,
1989    /// Keeps the camera position in place
1990    None,
1991}
1992
1993/// The global axes.
1994#[derive(
1995    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
1996)]
1997#[serde(rename_all = "lowercase")]
1998#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
1999#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2000#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2001#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2002pub enum GlobalAxis {
2003    /// The X axis
2004    X,
2005    /// The Y axis
2006    Y,
2007    /// The Z axis
2008    Z,
2009}
2010
2011/// Possible types of faces which can be extruded from a 3D solid.
2012#[derive(
2013    Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
2014)]
2015#[serde(rename_all = "snake_case")]
2016#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2017#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2018#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2019#[repr(u8)]
2020#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2021pub enum ExtrusionFaceCapType {
2022    /// Uncapped.
2023    None,
2024    /// Capped on top.
2025    Top,
2026    /// Capped below.
2027    Bottom,
2028    /// Capped on both ends.
2029    Both,
2030}
2031
2032/// Post effect type
2033#[allow(missing_docs)]
2034#[derive(
2035    Display,
2036    FromStr,
2037    Copy,
2038    Eq,
2039    PartialEq,
2040    Debug,
2041    JsonSchema,
2042    Deserialize,
2043    Serialize,
2044    Sequence,
2045    Clone,
2046    Ord,
2047    PartialOrd,
2048    Default,
2049)]
2050#[serde(rename_all = "lowercase")]
2051#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2052#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2053#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2054#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2055pub enum PostEffectType {
2056    Phosphor,
2057    Ssao,
2058    RetroCad,
2059    #[default]
2060    NoEffect,
2061}
2062
2063// Enum: Connect Rust Enums to Cpp
2064// add our native c++ names for our cxx::ExternType implementation
2065#[cfg(feature = "cxx")]
2066impl_extern_type! {
2067    [Trivial]
2068    // File
2069    FileImportFormat = "Enums::_FileImportFormat"
2070    FileExportFormat = "Enums::_FileExportFormat"
2071    // Camera
2072    CameraDragInteractionType = "Enums::_CameraDragInteractionType"
2073    // Scene
2074    SceneSelectionType = "Enums::_SceneSelectionType"
2075    SceneToolType = "Enums::_SceneToolType"
2076    BlendType = "Enums::_BlendType"
2077    BodyType = "Enums::_BodyType"
2078    EntityType = "Enums::_EntityType"
2079    HiddenState = "Enums::_HiddenState"
2080    AnnotationType = "Enums::_AnnotationType"
2081    AnnotationTextAlignmentX = "Enums::_AnnotationTextAlignmentX"
2082    AnnotationTextAlignmentY = "Enums::_AnnotationTextAlignmentY"
2083    AnnotationLineEnd = "Enums::_AnnotationLineEnd"
2084    MbdStandard = "Enums::_MBDStandard"
2085    MbdSymbol = "Enums::_MBDSymbol"
2086
2087    CurveType = "Enums::_CurveType"
2088    PathCommand = "Enums::_PathCommand"
2089    PathComponentConstraintBound = "Enums::_PathComponentConstraintBound"
2090    PathComponentConstraintType = "Enums::_PathComponentConstraintType"
2091    ExtrusionFaceCapType  = "Enums::_ExtrusionFaceCapType"
2092
2093    // Utils
2094    EngineErrorCode = "Enums::_ErrorCode"
2095    GlobalAxis = "Enums::_GlobalAxis"
2096    OriginType = "Enums::_OriginType"
2097
2098    // Graphics engine
2099    PostEffectType = "Enums::_PostEffectType"
2100}
2101
2102fn bool_true() -> bool {
2103    true
2104}
2105fn same_scale() -> Point3d<f64> {
2106    Point3d::uniform(1.0)
2107}
2108
2109fn z_axis() -> Point3d<f64> {
2110    Point3d { x: 0.0, y: 0.0, z: 1.0 }
2111}
2112
2113impl ExtrudedFaceInfo {
2114    /// Converts from the representation used in the Extrude modeling command,
2115    /// to a flat representation.
2116    pub fn list_faces(self) -> Vec<ExtrusionFaceInfo> {
2117        let mut face_infos: Vec<_> = self
2118            .sides
2119            .into_iter()
2120            .map(|side| ExtrusionFaceInfo {
2121                curve_id: Some(side.path_id),
2122                face_id: Some(side.face_id),
2123                cap: ExtrusionFaceCapType::None,
2124            })
2125            .collect();
2126        face_infos.push(ExtrusionFaceInfo {
2127            curve_id: None,
2128            face_id: Some(self.top),
2129            cap: ExtrusionFaceCapType::Top,
2130        });
2131        if let Some(bottom) = self.bottom {
2132            face_infos.push(ExtrusionFaceInfo {
2133                curve_id: None,
2134                face_id: Some(bottom),
2135                cap: ExtrusionFaceCapType::Bottom,
2136            });
2137        }
2138        face_infos
2139    }
2140}
2141
2142#[cfg(test)]
2143mod tests {
2144    use super::*;
2145    use serde_json::json;
2146
2147    #[test]
2148    fn circular_arc_winding_defaults_to_counterclockwise() {
2149        let wire = json!({"origin": {"x": 0.0, "y": 0.0}, "radius": 5.0,
2150            "start_angle": 0.0, "end_angle": std::f64::consts::FRAC_PI_2});
2151        let arc: CircularArc2d = serde_json::from_value(wire).unwrap();
2152        assert_eq!(arc.winding, Winding::Counterclockwise);
2153
2154        let built = CircularArc2d::builder()
2155            .origin(arc.origin)
2156            .radius(arc.radius)
2157            .start_angle(arc.start_angle)
2158            .end_angle(arc.end_angle)
2159            .build();
2160        assert_eq!(built.winding, Winding::Counterclockwise);
2161        assert_eq!(serde_json::to_value(built).unwrap()["winding"], "counterclockwise");
2162    }
2163
2164    #[test]
2165    fn orthographic_projection_non_rational_nurbs_omits_weights() {
2166        let wire = json!({"type": "nurbs", "control_points": [{"x": 0.0, "y": 0.0}, {"x": 1.0, "y": 0.0}],
2167            "knot_vector": [0.0, 0.0, 1.0, 1.0], "order": 2});
2168        let parsed: crate::shared::ProjectionCurveGeometry = serde_json::from_value(wire.clone()).unwrap();
2169        assert_eq!(serde_json::to_value(parsed).unwrap(), wire);
2170    }
2171
2172    #[test]
2173    fn orthographic_projection_source_requires_topology_and_component_identity() {
2174        for source in [
2175            json!({"type": "edge", "section_index": 0}),
2176            json!({"type": "edge", "edge_index": 2}),
2177            json!({"type": "silhouette", "face_index": 2}),
2178            json!({"type": "silhouette", "edge_index": 2, "silhouette_index": 0}),
2179        ] {
2180            assert!(serde_json::from_value::<ProjectionCurveSource>(source).is_err());
2181        }
2182    }
2183
2184    #[test]
2185    fn test_angle_comparison() {
2186        let a = Angle::from_degrees(90.0);
2187        assert!(a < Angle::from_degrees(91.0));
2188        assert!(a > Angle::from_degrees(89.0));
2189        assert!(a <= Angle::from_degrees(90.0));
2190        assert!(a >= Angle::from_degrees(90.0));
2191        let b = Angle::from_radians(std::f64::consts::FRAC_PI_4);
2192        assert!(b < Angle::from_radians(std::f64::consts::FRAC_PI_2));
2193        assert!(b > Angle::from_radians(std::f64::consts::FRAC_PI_8));
2194        assert!(b <= Angle::from_radians(std::f64::consts::FRAC_PI_4));
2195        assert!(b >= Angle::from_radians(std::f64::consts::FRAC_PI_4));
2196        // Mixed units.
2197        assert!(a > b);
2198        assert!(a >= b);
2199        assert!(b < a);
2200        assert!(b <= a);
2201        let c = Angle::from_radians(std::f64::consts::FRAC_PI_2 * 3.0);
2202        assert!(a < c);
2203        assert!(a <= c);
2204        assert!(c > a);
2205        assert!(c >= a);
2206    }
2207}
2208
2209/// How a property of an object should be transformed.
2210#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, JsonSchema, Builder)]
2211#[schemars(rename = "TransformByFor{T}")]
2212#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2213#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2214#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2215#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2216pub struct TransformBy<T> {
2217    /// The scale, or rotation, or translation.
2218    pub property: T,
2219    /// If true, overwrite the previous value with this.
2220    /// If false, the previous value will be modified.
2221    /// E.g. when translating, `set=true` will set a new location,
2222    /// and `set=false` will translate the current location by the given X/Y/Z.
2223    pub set: bool,
2224    /// What to use as the origin for the transformation.
2225    #[serde(default)]
2226    #[builder(default)]
2227    pub origin: OriginType,
2228}
2229
2230impl<T> TransformBy<T> {
2231    /// Get the origin of this transformation.
2232    /// Reads from the `origin` field.
2233    pub fn get_origin(&self) -> OriginType {
2234        self.origin
2235    }
2236}
2237
2238/// Container that holds a translate, rotate and scale.
2239/// Defaults to no change, everything stays the same (i.e. the identity function).
2240#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize, Default, Builder)]
2241#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2242#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2243#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2244#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2245pub struct ComponentTransform {
2246    /// Translate component of the transform.
2247    pub translate: Option<TransformBy<Point3d<LengthUnit>>>,
2248    /// Rotate component of the transform.
2249    /// The rotation is specified as a roll, pitch, yaw.
2250    pub rotate_rpy: Option<TransformBy<Point3d<f64>>>,
2251    /// Rotate component of the transform.
2252    /// The rotation is specified as an axis and an angle (xyz are the components of the axis, w is
2253    /// the angle in degrees).
2254    pub rotate_angle_axis: Option<TransformBy<Point4d<f64>>>,
2255    /// Scale component of the transform.
2256    pub scale: Option<TransformBy<Point3d<f64>>>,
2257}
2258
2259///If bidirectional or symmetric operations are needed this enum encapsulates the required
2260///information.
2261#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
2262#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2263#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2264#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2265#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2266pub enum Opposite<T> {
2267    /// No opposite. The operation will only occur on one side.
2268    #[default]
2269    None,
2270    /// Operation will occur from both sides, with the same value.
2271    Symmetric,
2272    /// Operation will occur from both sides, with this value for the opposite.
2273    Other(T),
2274}
2275
2276impl<T: JsonSchema> JsonSchema for Opposite<T> {
2277    fn schema_name() -> String {
2278        format!("OppositeFor{}", T::schema_name())
2279    }
2280
2281    fn schema_id() -> std::borrow::Cow<'static, str> {
2282        std::borrow::Cow::Owned(format!("{}::Opposite<{}>", module_path!(), T::schema_id()))
2283    }
2284
2285    fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
2286        SchemaObject {
2287            instance_type: Some(schemars::schema::InstanceType::String.into()),
2288            ..Default::default()
2289        }
2290        .into()
2291    }
2292}
2293
2294/// What strategy (algorithm) should be used for cutting?
2295/// Defaults to Automatic.
2296#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
2297#[serde(rename_all = "snake_case")]
2298#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2299#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2300#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2301#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2302pub enum CutStrategy {
2303    /// Basic fillet cut. This has limitations, like the filletted edges
2304    /// can't touch each other. But it's very fast and simple.
2305    Basic,
2306    /// More complicated fillet cut. It works for more use-cases, like
2307    /// edges that touch each other. But it's slower than the Basic method.
2308    Csg,
2309    /// Tries the Basic method, and if that doesn't work, tries the CSG strategy.
2310    #[default]
2311    Automatic,
2312}
2313
2314/// What is the given geometry relative to?
2315#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
2316#[serde(rename_all = "snake_case")]
2317#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2318#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2319#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2320#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2321pub enum RelativeTo {
2322    /// Local/relative to a position centered within the plane being sketched on
2323    #[default]
2324    SketchPlane,
2325    /// Local/relative to the trajectory curve
2326    TrajectoryCurve,
2327}
2328
2329/// The region a user clicked on.
2330#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
2331#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2332#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2333#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2334pub struct SelectedRegion {
2335    /// First segment to follow to find the region.
2336    pub segment: Uuid,
2337    /// Second segment to follow to find the region.
2338    /// Intersects the first segment.
2339    pub intersection_segment: Uuid,
2340    /// At which intersection between `segment` and `intersection_segment`
2341    /// should we stop following the `segment` and start following `intersection_segment`?
2342    /// Defaults to -1, which means the last intersection.
2343    #[serde(default = "negative_one")]
2344    pub intersection_index: i32,
2345    /// By default (when this is false), curve counterclockwise at intersections.
2346    /// If this is true, instead curve clockwise.
2347    #[serde(default)]
2348    pub curve_clockwise: bool,
2349}
2350
2351impl Default for SelectedRegion {
2352    fn default() -> Self {
2353        Self {
2354            segment: Default::default(),
2355            intersection_segment: Default::default(),
2356            intersection_index: -1,
2357            curve_clockwise: Default::default(),
2358        }
2359    }
2360}
2361
2362/// An edge id and an upper and lower percentage bound of the edge.
2363#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
2364#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2365#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2366#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2367#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2368pub struct FractionOfEdge {
2369    /// The id of the edge (legacy). If both `edge_id` and `edge_specifier` are provided, `edge_specifier` takes precedence.
2370    #[serde(default, skip_serializing_if = "Option::is_none")]
2371    pub edge_id: Option<Uuid>,
2372    /// Edge specifier (side_faces, end_faces, index) identifying the edge. If both `edge_id` and `edge_specifier` are provided, `edge_specifier` takes precedence.
2373    #[serde(default, skip_serializing_if = "Option::is_none")]
2374    pub edge_specifier: Option<EdgeSpecifier>,
2375    /// A value between [0.0, 1.0] (default 0.0) that is a percentage along the edge. This bound
2376    /// will control how much of the edge is used during the blend.
2377    /// If lower_bound is larger than upper_bound, the edge is effectively "flipped".
2378    #[serde(default)]
2379    #[builder(default)]
2380    #[schemars(range(min = 0, max = 1))]
2381    pub lower_bound: f32,
2382    /// A value between [0.0, 1.0] (default 1.0) that is a percentage along the edge. This bound
2383    /// will control how much of the edge is used during the blend.
2384    /// If lower_bound is larger than upper_bound, the edge is effectively "flipped".
2385    #[serde(default = "one")]
2386    #[builder(default = one())]
2387    #[schemars(range(min = 0, max = 1))]
2388    pub upper_bound: f32,
2389}
2390
2391/// An object id, that corresponds to a surface body, and a list of edges of the surface.
2392#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
2393#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2394#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2395#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2396#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2397pub struct SurfaceEdgeReference {
2398    /// The id of the body.
2399    pub object_id: Uuid,
2400    /// A list of the edge ids that belong to the body.
2401    pub edges: Vec<FractionOfEdge>,
2402}
2403
2404/// List of bodies that were created by an operation.
2405#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
2406#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2407#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2408#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2409#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2410pub struct BodiesCreated {
2411    /// All bodies created by this operation.
2412    pub bodies: Vec<BodyCreated>,
2413}
2414
2415impl BodiesCreated {
2416    /// Are there any bodies in this list?
2417    pub fn is_empty(&self) -> bool {
2418        self.bodies.is_empty()
2419    }
2420}
2421
2422/// List of bodies that were updated by an operation.
2423#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
2424#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2425#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2426#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2427#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2428pub struct BodiesUpdated {
2429    /// All bodies created by this operation.
2430    pub bodies: Vec<BodyUpdated>,
2431}
2432
2433impl BodiesUpdated {
2434    /// Are there any bodies in this list?
2435    pub fn is_empty(&self) -> bool {
2436        self.bodies.is_empty()
2437    }
2438}
2439
2440/// Details of a body that was created.
2441#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
2442#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2443#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2444#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2445#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2446pub struct BodyCreated {
2447    /// The body's ID.
2448    pub id: Uuid,
2449    /// Surfaces this body contains.
2450    pub surfaces: Vec<SurfaceCreated>,
2451}
2452
2453/// Details of a body that was updated.
2454#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
2455#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2456#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2457#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2458#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2459pub struct BodyUpdated {
2460    /// The body's ID.
2461    pub id: Uuid,
2462    /// Surfaces added to this body.
2463    pub surfaces: Vec<SurfaceCreated>,
2464}
2465
2466/// Details of a surface that was created under some body.
2467#[derive(Builder, Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
2468#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2469#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2470#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2471#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2472pub struct SurfaceCreated {
2473    /// The surface's ID.
2474    pub id: Uuid,
2475    /// Which number face of the parent body is this?
2476    pub primitive_face_index: u32,
2477    /// Which segment IDs was this surface swept from?
2478    pub from_segments: Vec<Uuid>,
2479}
2480
2481/// Region-creation algorithm version.
2482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
2483#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2484#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2485#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2486#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2487pub enum RegionVersion {
2488    /// The original region creation method. This should NOT be used anymore,
2489    /// but is maintained to avoid breaking old models.
2490    #[default]
2491    V0,
2492    /// Fixes the bug in V0 where creating a region would shuffle the mapping
2493    /// from segment names/IDs to actual segment geometry.
2494    V1,
2495}
2496
2497/// Edge cut algorithm version.
2498#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Copy)]
2499#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
2500#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
2501#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2502#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
2503#[serde(rename_all = "snake_case")]
2504pub enum EdgeCutVersion {
2505    /// Let the engine choose whichever version it wants.
2506    V0,
2507    /// The original fillet algorithm Zoo 1.0 shipped with.
2508    /// Limitations: doesn't support rolling ball fillets, has several bugs
2509    /// that will not be fixed.
2510    V1,
2511    /// Adds support for rolling ball fillets.
2512    /// Fixes bugs from V1.
2513    /// Still experimental.
2514    V2,
2515}
2516
2517const DEFAULT_EDGE_CUT_VERSION: EdgeCutVersion = EdgeCutVersion::V1;
2518
2519impl EdgeCutVersion {
2520    /// Is this the default edge cut algorithm version?
2521    pub fn is_default(&self) -> bool {
2522        self == &DEFAULT_EDGE_CUT_VERSION
2523    }
2524}
2525
2526impl Default for EdgeCutVersion {
2527    fn default() -> Self {
2528        DEFAULT_EDGE_CUT_VERSION
2529    }
2530}
2531
2532/// Try to match an integer to a version number.
2533impl TryFrom<u32> for EdgeCutVersion {
2534    type Error = ();
2535
2536    fn try_from(version: u32) -> Result<Self, Self::Error> {
2537        match version {
2538            0 => Ok(Self::V0),
2539            1 => Ok(Self::V1),
2540            2 => Ok(Self::V2),
2541            _ => Err(()),
2542        }
2543    }
2544}
2545
2546impl RegionVersion {
2547    /// Is the version V0?
2548    pub fn is_zero(&self) -> bool {
2549        matches!(self, Self::V0)
2550    }
2551}
2552
2553impl From<BodyCreated> for BodyUpdated {
2554    fn from(body: BodyCreated) -> Self {
2555        Self {
2556            id: body.id,
2557            surfaces: body.surfaces,
2558        }
2559    }
2560}
2561
2562impl From<BodyUpdated> for BodyCreated {
2563    fn from(body: BodyUpdated) -> Self {
2564        Self {
2565            id: body.id,
2566            surfaces: body.surfaces,
2567        }
2568    }
2569}
2570
2571impl From<BodiesCreated> for BodiesUpdated {
2572    fn from(bodies: BodiesCreated) -> Self {
2573        Self {
2574            bodies: bodies.bodies.into_iter().map(Into::into).collect(),
2575        }
2576    }
2577}
2578
2579impl From<BodiesUpdated> for BodiesCreated {
2580    fn from(bodies: BodiesUpdated) -> Self {
2581        Self {
2582            bodies: bodies.bodies.into_iter().map(Into::into).collect(),
2583        }
2584    }
2585}
2586
2587fn one() -> f32 {
2588    1.0
2589}
2590
2591/// A debug-view of the segment of a curve.
2592#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, JsonSchema, Builder)]
2593pub struct CurveDebug {
2594    /// Start point of segment or circle.
2595    pub start: Option<Point2d<f64>>,
2596    /// End point of segment.
2597    pub end: Option<Point2d<f64>>,
2598    /// Center point of segment.
2599    pub center: Option<Point2d<f64>>,
2600    /// Midpoint on a three point arc
2601    pub mid: Option<Point2d<f64>>,
2602    /// What kind of segment is it (line, arc, etc)
2603    pub segment_type: CurveTypeDebug,
2604    /// ID for this segment.
2605    pub id: ModelingCmdId,
2606}
2607
2608/// What type of curve is being viewed?
2609#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
2610#[serde(rename_all = "snake_case")]
2611pub enum CurveTypeDebug {
2612    /// Line with a start and end.
2613    Line,
2614    /// Arc with a start, end and center.
2615    ThreePointArc,
2616    /// Circle with a center and radius.
2617    Circle,
2618}