1#![allow(async_fn_in_trait)]
2
3use serde::{Deserialize, Serialize};
4
5use crate::*;
6
7pub trait SketchApi {
8 async fn new_sketch(
9 &self,
10 project: ProjectId,
11 file: FileId,
12 version: Version,
13 args: SketchArgs,
14 ) -> Result<(SourceDelta, SceneGraphDelta, ObjectId)>;
15
16 async fn edit_sketch(
18 &self,
19 project: ProjectId,
20 file: FileId,
21 version: Version,
22 sketch: ObjectId,
23 ) -> Result<SceneGraphDelta>;
24
25 async fn exit_sketch(&self, version: Version, sketch: ObjectId) -> Result<SceneGraph>;
26
27 async fn add_segment(
28 &self,
29 version: Version,
30 sketch: ObjectId,
31 segment: SegmentArgs<Expr>,
32 ) -> Result<SceneGraphDelta>;
33
34 async fn edit_segment(
35 &self,
36 version: Version,
37 sketch: ObjectId,
38 segment_id: ObjectId,
39 segment: SegmentArgs<Expr>,
40 ) -> Result<SceneGraphDelta>;
41
42 async fn delete_segment(&self, version: Version, sketch: ObjectId, segment_id: ObjectId)
43 -> Result<SceneGraphDelta>;
44
45 async fn add_constraint(
46 &self,
47 version: Version,
48 sketch: ObjectId,
49 constraint: ConstraintArgs,
50 ) -> Result<SceneGraphDelta>;
51
52 async fn edit_constraint(
53 &self,
54 version: Version,
55 sketch: ObjectId,
56 constraint_id: ObjectId,
57 constraint: ConstraintArgs,
58 ) -> Result<SceneGraphDelta>;
59
60 async fn delete_constraint(
61 &self,
62 version: Version,
63 sketch: ObjectId,
64 constraint_id: ObjectId,
65 ) -> Result<SceneGraphDelta>;
66}
67
68#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
69#[ts(export)]
70pub enum Segment {
71 Line(Line),
72 Arc(Arc),
73}
74
75#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
76#[ts(export)]
77pub enum SegmentArgs<U: std::fmt::Debug + Clone + ts_rs::TS> {
78 Line(LineArgs<U>),
79 Arc(ArcArgs<U>),
80}
81
82#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
83#[ts(export, rename = "ApiLine")]
84pub struct Line {
85 pub args: LineArgs<SolvedExpr>,
86 pub start: Point2d<Number>,
87 pub end: Point2d<Number>,
88}
89
90#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
91#[ts(export, rename = "ApiArc")]
92pub struct Arc {
93 pub args: ArcArgs<SolvedExpr>,
94 }
96
97#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
98#[ts(export)]
99pub enum ConstraintArgs {
100 Coincident(CoincidentArgs),
101 Parallel(ParallelArgs),
102}
103
104#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
105#[ts(export, rename = "ApiPoint2d")]
106pub struct Point2d<U: std::fmt::Debug + Clone + ts_rs::TS> {
107 pub x: U,
108 pub y: U,
109}
110
111#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
112pub struct Sketch {
113 pub args: SketchArgs,
114 pub items: Vec<ObjectId>,
115}
116
117#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
118pub struct SketchArgs {
119 pub on: Plane,
120}
121
122#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
123#[ts(export, optional_fields)]
124pub struct LineArgs<U: std::fmt::Debug + Clone + ts_rs::TS> {
125 pub start: Option<Point2d<U>>,
126 pub end: Option<Point2d<U>>,
127 pub angle: Option<U>,
128 pub length: Option<U>,
129 pub x_length: Option<U>,
130 pub y_length: Option<U>,
131}
132
133#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
134#[ts(export, optional_fields)]
135pub struct ArcArgs<U: std::fmt::Debug + Clone + ts_rs::TS> {
136 pub start: Option<Point2d<U>>,
137 pub end: Option<Point2d<U>>,
138 pub center: Option<Point2d<U>>,
139 pub radius: Option<U>,
140 pub start_angle: Option<U>,
141 pub end_angle: Option<U>,
142}
143
144#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
145#[ts(export)]
146pub struct CoincidentArgs {
147 points: Vec<String>,
148}
149
150#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
151#[ts(export, optional_fields)]
152pub struct ParallelArgs {
153 lines: Vec<String>,
154 distance: Option<Number>,
155}
156
157#[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)]
158#[ts(export)]
159pub struct SolvedExpr {
160 expr: Expr,
161 value: Number,
162}
163
164impl Kind for SolvedExpr {}