-
Notifications
You must be signed in to change notification settings - Fork 89
Sketch 2.0 WIP: add_segment stub #8594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ | |
| sketch: ObjectId, | ||
| segment: SegmentCtor, | ||
| label: Option<String>, | ||
| ) -> Result<(SourceDelta, SceneGraphDelta)>; | ||
| ) -> Result<(KclSource, SketchExecOutcome)>; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should discuss this in our next call. I have a clearer understanding of it all now that I've implemented some of it, but I'm still on the fence about which way we should go.
|
||
|
|
||
| async fn edit_segment( | ||
| &self, | ||
|
|
@@ -114,7 +114,7 @@ | |
| #[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)] | ||
| #[ts(export)] | ||
| pub enum SegmentCtor { | ||
| Point(Point2d<Expr>), | ||
| Point(PointCtor), | ||
| Line(LineCtor), | ||
| MidPointLine(MidPointLineCtor), | ||
| Arc(ArcCtor), | ||
|
|
@@ -124,6 +124,12 @@ | |
| ThreePointCircle(ThreePointCircleCtor), | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)] | ||
| #[ts(export)] | ||
| pub struct PointCtor { | ||
| pub position: Point2d<Expr>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)] | ||
| #[ts(export, rename = "ApiPoint2d")] | ||
| pub struct Point2d<U: std::fmt::Debug + Clone + ts_rs::TS> { | ||
|
|
@@ -246,3 +252,166 @@ | |
| lines: Vec<ObjectId>, | ||
| distance: Option<Number>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)] | ||
| #[ts(export)] | ||
| pub struct SketchExecOutcome { | ||
| // The solved segments, including their locations so that they can be drawn. | ||
| pub segments: Vec<SolveSegment>, | ||
| // The interpreted constraints. | ||
| pub constraints: Vec<SolveConstraint>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)] | ||
| #[ts(export)] | ||
| pub enum SolveSegment { | ||
| Point(SolvePointSegment), | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)] | ||
| #[ts(export)] | ||
| pub struct SolvePointSegment { | ||
| pub object_id: String, | ||
| pub constrained_status: ConstrainedStatus, | ||
| pub handles: Vec<PointHandle>, | ||
| pub position: Point2d<Number>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)] | ||
| #[ts(export)] | ||
| pub enum ConstrainedStatus { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This type is redundant/should be merged with |
||
| None, | ||
| Partial, | ||
| Full, | ||
| } | ||
|
|
||
| // Handles, i.e. UI elements that the user can interact with. | ||
| #[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)] | ||
| #[ts(export)] | ||
| pub struct PointHandle { | ||
| pub position: Point2d<Number>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)] | ||
| #[ts(export)] | ||
| pub enum SolveConstraint { | ||
| // e.g. Make these things coincident. | ||
| Relation { kind: RelationKind, segment_ids: Vec<String> }, | ||
| // If segment2 is given, it's the perpendicular distance between them. | ||
| Dimension { | ||
| segment1_id: String, | ||
| segment2_id: Option<String>, | ||
| value: Number, | ||
| }, | ||
| Angle { | ||
| segment1_id: String, | ||
| segment2_id: Option<String>, | ||
| value: Number, | ||
| }, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, Serialize, ts_rs::TS)] | ||
| #[ts(export)] | ||
| pub enum RelationKind { | ||
| Coincidence, | ||
| Horizontal, | ||
| Vertical, | ||
| Tangent, | ||
| Equal, | ||
| Fixed, | ||
| } | ||
|
|
||
| // Stub implementation of SketchApi for testing/development | ||
| pub struct SketchApiStub; | ||
|
|
||
| impl SketchApi for SketchApiStub { | ||
| async fn new_sketch( | ||
| &self, | ||
| _project: ProjectId, | ||
| _file: FileId, | ||
| _version: Version, | ||
| _args: SketchArgs, | ||
| ) -> Result<(SourceDelta, SceneGraphDelta, ObjectId)> { | ||
| todo!("new_sketch not implemented") | ||
| } | ||
|
|
||
| async fn edit_sketch( | ||
| &self, | ||
| _project: ProjectId, | ||
| _file: FileId, | ||
| _version: Version, | ||
| _sketch: ObjectId, | ||
| ) -> Result<SceneGraphDelta> { | ||
| todo!("edit_sketch not implemented") | ||
| } | ||
|
|
||
| async fn exit_sketch(&self, _version: Version, _sketch: ObjectId) -> Result<SceneGraph> { | ||
| todo!("exit_sketch not implemented") | ||
| } | ||
|
|
||
| async fn add_segment( | ||
| &self, | ||
| _version: Version, | ||
| _sketch: ObjectId, | ||
| _segment: SegmentCtor, | ||
| _label: Option<String>, | ||
| ) -> Result<(KclSource, SketchExecOutcome)> { | ||
| // Return empty stub data | ||
| Ok(( | ||
| KclSource { | ||
| text: String::new(), | ||
| }, | ||
| SketchExecOutcome { | ||
| segments: Vec::new(), | ||
| constraints: Vec::new(), | ||
| }, | ||
| )) | ||
| } | ||
|
|
||
| async fn edit_segment( | ||
| &self, | ||
| _version: Version, | ||
| _sketch: ObjectId, | ||
| _segment_id: ObjectId, | ||
| _segment: SegmentCtor, | ||
| ) -> Result<(SourceDelta, SceneGraphDelta)> { | ||
| todo!("edit_segment not implemented") | ||
| } | ||
|
|
||
| async fn delete_segment( | ||
| &self, | ||
| _version: Version, | ||
| _sketch: ObjectId, | ||
| _segment_id: ObjectId, | ||
| ) -> Result<(SourceDelta, SceneGraphDelta)> { | ||
| todo!("delete_segment not implemented") | ||
| } | ||
|
|
||
| async fn add_constraint( | ||
| &self, | ||
| _version: Version, | ||
| _sketch: ObjectId, | ||
| _constraint: Constraint, | ||
| ) -> Result<(SourceDelta, SceneGraphDelta)> { | ||
| todo!("add_constraint not implemented") | ||
| } | ||
|
|
||
| async fn edit_constraint( | ||
| &self, | ||
| _version: Version, | ||
| _sketch: ObjectId, | ||
| _constraint_id: ObjectId, | ||
| _constraint: Constraint, | ||
| ) -> Result<(SourceDelta, SceneGraphDelta)> { | ||
| todo!("edit_constraint not implemented") | ||
| } | ||
|
|
||
| async fn delete_constraint( | ||
| &self, | ||
| _version: Version, | ||
| _sketch: ObjectId, | ||
| _constraint_id: ObjectId, | ||
| ) -> Result<(SourceDelta, SceneGraphDelta)> { | ||
| todo!("delete_constraint not implemented") | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,14 @@ set -euo pipefail | |
| rm -rf rust/kcl-wasm-lib/pkg | ||
| mkdir -p rust/kcl-wasm-lib/pkg | ||
| rm -rf rust/kcl-lib/bindings | ||
| rm -rf rust/kcl-api/bindings | ||
|
|
||
| cd rust | ||
| export RUSTFLAGS='--cfg getrandom_backend="wasm_js"' | ||
| wasm-pack build kcl-wasm-lib --release --target web --out-dir pkg | ||
| export RUSTFLAGS='' | ||
| cargo test -p kcl-lib --features artifact-graph export_bindings | ||
| cargo test -p kcl-api export_bindings | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to do this for |
||
| cd .. | ||
|
|
||
| cp rust/kcl-wasm-lib/pkg/kcl_wasm_lib_bg.wasm public | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the TODO, this is probably fine for now. We can't code-mod or refactor in imported files yet.
But the way I see it, this type and
SourceDeltaare redundant. They're the same and should be merged into one. I don't really care what we name it. Since this is thekcl-apicrate, it seems a little redundant to call it "KCL source". But I get that the prefix probably makes it easier in TypeScript so that you don't need to alias it.