use enum_iterator::Sequence;
use parse_display_derive::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[cfg(feature = "cxx")]
use crate::impl_extern_type;
use crate::{length_unit::LengthUnit, units::UnitAngle};
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub enum CutType {
#[default]
Fillet,
Chamfer,
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub struct LinearTransform {
#[serde(default)]
pub translate: Point3d<LengthUnit>,
#[serde(default = "same_scale")]
pub scale: Point3d<LengthUnit>,
#[serde(default = "bool_true")]
pub replicate: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct AnnotationOptions {
pub text: Option<AnnotationTextOptions>,
pub line_ends: Option<AnnotationLineEndOptions>,
pub line_width: Option<f32>,
pub color: Option<Color>,
pub position: Option<Point3d<f32>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct AnnotationLineEndOptions {
pub start: AnnotationLineEnd,
pub end: AnnotationLineEnd,
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct AnnotationTextOptions {
pub x: AnnotationTextAlignmentX,
pub y: AnnotationTextAlignmentY,
pub text: String,
pub point_size: u32,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum DistanceType {
Euclidean {},
OnAxis {
axis: GlobalAxis,
},
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
#[allow(missing_docs)]
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
pub enum AnnotationTextAlignmentX {
Left,
Center,
Right,
}
#[allow(missing_docs)]
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
pub enum AnnotationTextAlignmentY {
Bottom,
Center,
Top,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq, Default)]
#[serde(rename = "Point3d")]
#[serde(rename_all = "snake_case")]
pub struct Point3d<T = f32> {
#[allow(missing_docs)]
pub x: T,
#[allow(missing_docs)]
pub y: T,
#[allow(missing_docs)]
pub z: T,
}
impl<T> Point3d<T> {
pub fn from_2d(Point2d { x, y }: Point2d<T>, z: T) -> Self {
Self { x, y, z }
}
}
#[allow(missing_docs)]
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
pub enum AnnotationLineEnd {
None,
Arrow,
}
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
pub enum AnnotationType {
T2D,
T3D,
}
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
pub enum CameraDragInteractionType {
Pan,
Rotate,
Zoom,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum PathSegment {
Line {
end: Point3d<LengthUnit>,
relative: bool,
},
Arc {
center: Point2d<LengthUnit>,
radius: LengthUnit,
start: Angle,
end: Angle,
relative: bool,
},
Bezier {
control1: Point3d<LengthUnit>,
control2: Point3d<LengthUnit>,
end: Point3d<LengthUnit>,
relative: bool,
},
TangentialArc {
radius: LengthUnit,
offset: Angle,
},
TangentialArcTo {
to: Point3d<LengthUnit>,
angle_snap_increment: Option<Angle>,
},
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
#[serde(rename = "Point4d")]
#[serde(rename_all = "snake_case")]
pub struct Point4d<T = f32> {
#[allow(missing_docs)]
pub x: T,
#[allow(missing_docs)]
pub y: T,
#[allow(missing_docs)]
pub z: T,
#[allow(missing_docs)]
pub w: T,
}
impl From<euler::Vec3> for Point3d<f32> {
fn from(v: euler::Vec3) -> Self {
Self { x: v.x, y: v.y, z: v.z }
}
}
impl<T: PartialEq> PartialEq for Point4d<T> {
fn eq(&self, other: &Self) -> bool {
self.x == other.x && self.y == other.y && self.z == other.z && self.w == other.w
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename = "Point2d")]
#[serde(rename_all = "snake_case")]
pub struct Point2d<T = f32> {
#[allow(missing_docs)]
pub x: T,
#[allow(missing_docs)]
pub y: T,
}
impl<T: PartialEq> PartialEq for Point2d<T> {
fn eq(&self, other: &Self) -> bool {
self.x == other.x && self.y == other.y
}
}
impl<T> Point2d<T> {
pub fn with_z(self, z: T) -> Point3d<T> {
let Self { x, y } = self;
Point3d { x, y, z }
}
}
pub type Quaternion = Point4d;
impl Default for Quaternion {
fn default() -> Self {
Self {
x: 0.0,
y: 0.0,
z: 0.0,
w: 1.0,
}
}
}
#[derive(Clone, Copy, PartialEq, Debug, JsonSchema, Deserialize, Serialize)]
pub struct Angle {
pub unit: UnitAngle,
pub value: f64,
}
impl Angle {
pub fn to_degrees(self) -> f64 {
match self.unit {
UnitAngle::Degrees => self.value,
UnitAngle::Radians => self.value.to_degrees(),
}
}
pub fn to_radians(self) -> f64 {
match self.unit {
UnitAngle::Degrees => self.value.to_radians(),
UnitAngle::Radians => self.value,
}
}
pub fn from_degrees(value: f64) -> Self {
Self {
unit: UnitAngle::Degrees,
value,
}
}
pub fn from_radians(value: f64) -> Self {
Self {
unit: UnitAngle::Radians,
value,
}
}
}
impl Angle {
pub fn turn() -> Self {
Self::from_degrees(360.0)
}
pub fn half_circle() -> Self {
Self::from_degrees(180.0)
}
pub fn quarter_circle() -> Self {
Self::from_degrees(90.0)
}
}
impl Default for Angle {
fn default() -> Self {
Self::from_degrees(0.0)
}
}
impl std::ops::Add for Angle {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self {
unit: UnitAngle::Degrees,
value: self.to_degrees() + rhs.to_degrees(),
}
}
}
impl std::ops::AddAssign for Angle {
fn add_assign(&mut self, rhs: Self) {
match self.unit {
UnitAngle::Degrees => {
self.value += rhs.to_degrees();
}
UnitAngle::Radians => {
self.value += rhs.to_radians();
}
}
}
}
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
pub enum SceneSelectionType {
Replace,
Add,
Remove,
}
#[allow(missing_docs)]
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "snake_case")]
pub enum SceneToolType {
CameraRevolve,
Select,
Move,
SketchLine,
SketchTangentialArc,
SketchCurve,
SketchCurveMod,
}
#[allow(missing_docs)]
#[derive(
Display,
FromStr,
Copy,
Eq,
PartialEq,
Debug,
JsonSchema,
Deserialize,
Serialize,
Sequence,
Clone,
Ord,
PartialOrd,
Default,
)]
#[serde(rename_all = "snake_case")]
pub enum PathComponentConstraintBound {
#[default]
Unconstrained,
PartiallyConstrained,
FullyConstrained,
}
#[allow(missing_docs)]
#[derive(
Display,
FromStr,
Copy,
Eq,
PartialEq,
Debug,
JsonSchema,
Deserialize,
Serialize,
Sequence,
Clone,
Ord,
PartialOrd,
Default,
)]
#[serde(rename_all = "snake_case")]
pub enum PathComponentConstraintType {
#[default]
Unconstrained,
Vertical,
Horizontal,
EqualLength,
Parallel,
AngleBetween,
}
#[allow(missing_docs)]
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "snake_case")]
pub enum PathCommand {
MoveTo,
LineTo,
BezCurveTo,
NurbsCurveTo,
AddArc,
}
#[allow(missing_docs)]
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
#[repr(u8)]
pub enum EntityType {
Entity,
Object,
Path,
Curve,
Solid2D,
Solid3D,
Edge,
Face,
Plane,
Vertex,
}
#[allow(missing_docs)]
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "snake_case")]
pub enum CurveType {
Line,
Arc,
Nurbs,
}
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct ExportFile {
pub name: String,
pub contents: crate::base64::Base64Data,
}
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd, Sequence,
)]
#[serde(rename_all = "lowercase")]
#[display(style = "lowercase")]
pub enum FileExportFormat {
Fbx,
Glb,
Gltf,
Obj,
Ply,
Step,
Stl,
}
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd, Sequence,
)]
#[serde(rename_all = "lowercase")]
#[display(style = "lowercase")]
pub enum FileImportFormat {
Fbx,
Gltf,
Obj,
Ply,
Sldprt,
Step,
Stl,
}
#[derive(Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, Ord, PartialOrd)]
#[serde(rename_all = "snake_case")]
pub enum EngineErrorCode {
BadRequest = 1,
InternalEngine,
}
impl From<EngineErrorCode> for http::StatusCode {
fn from(e: EngineErrorCode) -> Self {
match e {
EngineErrorCode::BadRequest => Self::BAD_REQUEST,
EngineErrorCode::InternalEngine => Self::INTERNAL_SERVER_ERROR,
}
}
}
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct CameraSettings {
pub pos: Point3d,
pub center: Point3d,
pub up: Point3d,
pub orientation: Quaternion,
pub fov_y: Option<f32>,
pub ortho_scale: Option<f32>,
pub ortho: bool,
}
impl From<CameraSettings> for crate::output::DefaultCameraZoom {
fn from(settings: CameraSettings) -> Self {
Self { settings }
}
}
impl From<CameraSettings> for crate::output::CameraDragMove {
fn from(settings: CameraSettings) -> Self {
Self { settings }
}
}
impl From<CameraSettings> for crate::output::CameraDragEnd {
fn from(settings: CameraSettings) -> Self {
Self { settings }
}
}
impl From<CameraSettings> for crate::output::DefaultCameraGetSettings {
fn from(settings: CameraSettings) -> Self {
Self { settings }
}
}
impl From<CameraSettings> for crate::output::ZoomToFit {
fn from(settings: CameraSettings) -> Self {
Self { settings }
}
}
impl From<CameraSettings> for crate::output::ViewIsometric {
fn from(settings: CameraSettings) -> Self {
Self { settings }
}
}
#[derive(Copy, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Clone, PartialOrd)]
#[serde(rename_all = "snake_case")]
pub struct PerspectiveCameraParameters {
pub fov_y: f32,
pub z_near: f32,
pub z_far: f32,
}
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "lowercase")]
pub enum GlobalAxis {
X,
Y,
Z,
}
#[derive(
Display, FromStr, Copy, Eq, PartialEq, Debug, JsonSchema, Deserialize, Serialize, Sequence, Clone, Ord, PartialOrd,
)]
#[serde(rename_all = "snake_case")]
#[repr(u8)]
pub enum ExtrusionFaceCapType {
None,
Top,
Bottom,
}
#[allow(missing_docs)]
#[derive(
Display,
FromStr,
Copy,
Eq,
PartialEq,
Debug,
JsonSchema,
Deserialize,
Serialize,
Sequence,
Clone,
Ord,
PartialOrd,
Default,
)]
#[serde(rename_all = "lowercase")]
pub enum PostEffectType {
Phosphor,
Ssao,
#[default]
NoEffect,
}
#[cfg(feature = "cxx")]
impl_extern_type! {
[Trivial]
FileImportFormat = "Enums::_FileImportFormat"
FileExportFormat = "Enums::_FileExportFormat"
CameraDragInteractionType = "Enums::_CameraDragInteractionType"
SceneSelectionType = "Enums::_SceneSelectionType"
SceneToolType = "Enums::_SceneToolType"
EntityType = "Enums::_EntityType"
AnnotationType = "Enums::_AnnotationType"
AnnotationTextAlignmentX = "Enums::_AnnotationTextAlignmentX"
AnnotationTextAlignmentY = "Enums::_AnnotationTextAlignmentY"
AnnotationLineEnd = "Enums::_AnnotationLineEnd"
CurveType = "Enums::_CurveType"
PathCommand = "Enums::_PathCommand"
PathComponentConstraintBound = "Enums::_PathComponentConstraintBound"
PathComponentConstraintType = "Enums::_PathComponentConstraintType"
ExtrusionFaceCapType = "Enums::_ExtrusionFaceCapType"
EngineErrorCode = "Enums::_ErrorCode"
GlobalAxis = "Enums::_GlobalAxis"
PostEffectType = "Enums::_PostEffectType"
}
fn bool_true() -> bool {
true
}
fn same_scale() -> Point3d<LengthUnit> {
let p = 1.0.into();
Point3d { x: p, y: p, z: p }
}