2023-11-29 10:32:31 -08:00
|
|
|
from typing import Literal, Optional, Union
|
2023-07-07 18:03:18 -07:00
|
|
|
|
2024-01-06 18:32:21 -08:00
|
|
|
from pydantic import BaseModel, ConfigDict, Field, RootModel
|
2023-11-29 10:32:31 -08:00
|
|
|
from typing_extensions import Annotated
|
2023-07-07 18:03:18 -07:00
|
|
|
|
2023-09-29 15:51:03 -07:00
|
|
|
from ..models.angle import Angle
|
2024-02-24 17:03:55 -08:00
|
|
|
from ..models.length_unit import LengthUnit
|
2023-07-07 18:03:18 -07:00
|
|
|
from ..models.point2d import Point2d
|
|
|
|
from ..models.point3d import Point3d
|
|
|
|
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class line(BaseModel):
|
2024-03-04 12:53:31 -08:00
|
|
|
"""A straight line segment. Goes from the current path \"pen\" to the given endpoint."""
|
2023-07-07 18:03:18 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
end: Point3d
|
2023-07-07 18:03:18 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
relative: bool
|
2023-07-07 18:03:18 -07:00
|
|
|
|
2023-11-29 10:32:31 -08:00
|
|
|
type: Literal["line"] = "line"
|
2023-07-07 18:03:18 -07:00
|
|
|
|
2024-01-06 18:32:21 -08:00
|
|
|
model_config = ConfigDict(protected_namespaces=())
|
|
|
|
|
2023-07-07 18:03:18 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class arc(BaseModel):
|
|
|
|
"""A circular arc segment."""
|
2023-07-07 18:03:18 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
center: Point2d
|
2023-07-07 18:03:18 -07:00
|
|
|
|
2023-12-21 08:14:08 -08:00
|
|
|
end: Angle
|
2023-07-07 18:03:18 -07:00
|
|
|
|
2024-02-24 17:03:55 -08:00
|
|
|
radius: LengthUnit
|
2023-07-07 18:03:18 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
relative: bool
|
2023-07-07 18:03:18 -07:00
|
|
|
|
2023-12-21 08:14:08 -08:00
|
|
|
start: Angle
|
2023-09-29 16:05:40 -07:00
|
|
|
|
2023-11-29 10:32:31 -08:00
|
|
|
type: Literal["arc"] = "arc"
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2024-01-06 18:32:21 -08:00
|
|
|
model_config = ConfigDict(protected_namespaces=())
|
|
|
|
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class bezier(BaseModel):
|
|
|
|
"""A cubic bezier curve segment. Start at the end of the current line, go through control point 1 and 2, then end at a given point."""
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
control1: Point3d
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
control2: Point3d
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
end: Point3d
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
relative: bool
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2023-11-29 10:32:31 -08:00
|
|
|
type: Literal["bezier"] = "bezier"
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2024-01-06 18:32:21 -08:00
|
|
|
model_config = ConfigDict(protected_namespaces=())
|
|
|
|
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class tangential_arc(BaseModel):
|
|
|
|
"""Adds a tangent arc from current pen position with the given radius and angle."""
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
offset: Angle
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2024-02-24 17:03:55 -08:00
|
|
|
radius: LengthUnit
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2023-11-29 10:32:31 -08:00
|
|
|
type: Literal["tangential_arc"] = "tangential_arc"
|
2023-09-29 15:51:03 -07:00
|
|
|
|
2024-01-06 18:32:21 -08:00
|
|
|
model_config = ConfigDict(protected_namespaces=())
|
|
|
|
|
2023-09-29 15:51:03 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class tangential_arc_to(BaseModel):
|
|
|
|
"""Adds a tangent arc from current pen position to the new position."""
|
2023-09-29 15:51:03 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
angle_snap_increment: Optional[Angle] = None
|
2023-09-29 15:51:03 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
to: Point3d
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2023-11-29 10:32:31 -08:00
|
|
|
type: Literal["tangential_arc_to"] = "tangential_arc_to"
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2024-01-06 18:32:21 -08:00
|
|
|
model_config = ConfigDict(protected_namespaces=())
|
|
|
|
|
2023-09-29 15:51:03 -07:00
|
|
|
|
2023-11-29 00:39:14 -08:00
|
|
|
PathSegment = RootModel[
|
2023-11-29 10:32:31 -08:00
|
|
|
Annotated[
|
|
|
|
Union[
|
|
|
|
line,
|
|
|
|
arc,
|
|
|
|
bezier,
|
|
|
|
tangential_arc,
|
|
|
|
tangential_arc_to,
|
|
|
|
],
|
|
|
|
Field(discriminator="type"),
|
2023-11-28 14:29:16 -08:00
|
|
|
]
|
2023-11-29 00:39:14 -08:00
|
|
|
]
|