Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions modeling-cmds/openapi/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -6388,6 +6388,68 @@
"required": [
"type"
]
},
{
"description": "Create a region bounded by the intersection of various paths. The region should have an ID taken from the ID of the 'CreateRegion' modeling command.",
"type": "object",
"properties": {
"curve_clockwise": {
"description": "By default, curve counterclockwise at intersections. If this is true, instead curve clockwise.",
"default": false,
"type": "boolean"
},
"intersection_index": {
"description": "At which intersection between `segment` and `intersection_segment` should we stop following the `segment` and start following `intersection_segment`? Defaults to -1, which means the last intersection.",
"default": -1,
"type": "integer",
"format": "int32"
},
"intersection_segment": {
"description": "Second segment to follow to find the region. Intersects the first segment.",
"type": "string",
"format": "uuid"
},
"segment": {
"description": "First segment to follow to find the region.",
"type": "string",
"format": "uuid"
},
"type": {
"type": "string",
"enum": [
"create_region"
]
}
},
"required": [
"intersection_segment",
"segment",
"type"
]
},
{
"description": "The user clicked on a point in the window, returns the region the user clicked on, if any.",
"type": "object",
"properties": {
"selected_at_window": {
"description": "Where in the window was selected",
"allOf": [
{
"$ref": "#/components/schemas/Point2d"
}
]
},
"type": {
"type": "string",
"enum": [
"select_region_from_point"
]
}
},
"required": [
"selected_at_window",
"type"
]
}
]
},
Expand Down
37 changes: 37 additions & 0 deletions modeling-cmds/src/def_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2158,9 +2158,46 @@ define_modeling_cmd_enum! {
/// If not given, toggles it.
pub enabled: Option<bool>,
}

/// Create a region bounded by the intersection of various paths.
/// The region should have an ID taken from the ID of the
/// 'CreateRegion' modeling command.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant, Builder)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct CreateRegion {
/// First segment to follow to find the region.
pub segment: Uuid,
/// Second segment to follow to find the region.
/// Intersects the first segment.
pub intersection_segment: Uuid,
/// At which intersection between `segment` and `intersection_segment`
/// should we stop following the `segment` and start following `intersection_segment`?
/// Defaults to -1, which means the last intersection.
#[serde(default = "super::negative_one")]
pub intersection_index: i32,
/// By default, curve counterclockwise at intersections.
/// If this is true, instead curve clockwise.
#[serde(default)]
pub curve_clockwise: bool,
}

/// The user clicked on a point in the window,
/// returns the region the user clicked on, if any.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct SelectRegionFromPoint {
/// Where in the window was selected
pub selected_at_window: Point2d,
}
}
}

pub(crate) fn negative_one() -> i32 {
-1
}

impl ModelingCmd {
/// Is this command safe to run in an engine batch?
pub fn is_safe_to_batch(&self) -> bool {
Expand Down
18 changes: 18 additions & 0 deletions modeling-cmds/src/ok_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ define_ok_modeling_cmd_response_enum! {
/// The UUID of the entity that was selected.
pub entity_id: Option<Uuid>,
}

/// The response from the `HighlightSetEntity` command.
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
pub struct HighlightSetEntity {
Expand Down Expand Up @@ -1048,5 +1049,22 @@ define_ok_modeling_cmd_response_enum! {
pub enabled: bool,
}

/// The response from the 'CreateRegion'.
/// The region should have an ID taken from the ID of the
/// 'CreateRegion' modeling command.
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
pub struct CreateRegion {
}

/// The response from the 'SelectRegionFromPoint'.
/// If there are multiple ways to construct this region, this chooses arbitrarily.
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
pub struct SelectRegionFromPoint {
/// The region the user clicked on.
/// If they clicked an open space which isn't a region,
/// this returns None.
pub region: Option<crate::shared::SelectedRegion>,
}

}
}
33 changes: 33 additions & 0 deletions modeling-cmds/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::def_enum::negative_one;
use enum_iterator::Sequence;
use parse_display_derive::{Display, FromStr};
pub use point::{Point2d, Point3d, Point4d, Quaternion};
Expand Down Expand Up @@ -1626,3 +1627,35 @@ pub enum RelativeTo {
/// Local/relative to the trajectory curve
TrajectoryCurve,
}

/// The region a user clicked on.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, JsonSchema)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct SelectedRegion {
/// First segment to follow to find the region.
pub segment: Uuid,
/// Second segment to follow to find the region.
/// Intersects the first segment.
pub intersection_segment: Uuid,
/// At which intersection between `segment` and `intersection_segment`
/// should we stop following the `segment` and start following `intersection_segment`?
/// Defaults to -1, which means the last intersection.
#[serde(default = "negative_one")]
pub intersection_index: i32,
/// By default (when this is false), curve counterclockwise at intersections.
/// If this is true, instead curve clockwise.
#[serde(default)]
pub curve_clockwise: bool,
}

impl Default for SelectedRegion {
fn default() -> Self {
Self {
segment: Default::default(),
intersection_segment: Default::default(),
intersection_index: -1,
curve_clockwise: Default::default(),
}
}
}