2024-07-28 15:21:51 -07:00
from typing import Literal , Optional , Union
2023-07-07 18:03:18 -07:00
2024-07-28 15:21:51 -07: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
2024-09-10 15:24:19 -07:00
class OptionLine ( 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
2024-09-10 15:24:19 -07:00
class OptionArc ( BaseModel ) :
2024-05-02 14:03:09 -07:00
""" A circular arc segment. Arcs can be drawn clockwise when start > end. """
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
2024-09-10 15:24:19 -07:00
class OptionBezier ( BaseModel ) :
2023-11-28 23:50:50 -08:00
""" 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
2024-09-10 15:24:19 -07:00
class OptionTangentialArc ( BaseModel ) :
2023-11-28 23:50:50 -08:00
""" 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
2024-09-10 15:24:19 -07:00
class OptionTangentialArcTo ( BaseModel ) :
2024-05-02 14:03:09 -07:00
""" Adds a tangent arc from current pen position to the new position. Arcs will choose a clockwise or counter-clockwise direction based on the arc end 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
2024-10-29 17:42:26 -07:00
class OptionArcTo ( BaseModel ) :
""" Adds an arc from the current position that goes through the given interior point and ends at the given end position """
end : Point3d
interior : Point3d
relative : bool
type : Literal [ " arc_to " ] = " arc_to "
model_config = ConfigDict ( protected_namespaces = ( ) )
2025-04-01 15:08:02 -07:00
class OptionCircularInvolute ( BaseModel ) :
""" Adds a circular involute from the current position that goes through the given end_radius and is rotated around the current point by angle. """
angle : Angle
end_radius : LengthUnit
reverse : bool
start_radius : LengthUnit
type : Literal [ " circular_involute " ] = " circular_involute "
model_config = ConfigDict ( protected_namespaces = ( ) )
2023-11-29 00:39:14 -08:00
PathSegment = RootModel [
2023-11-29 10:32:31 -08:00
Annotated [
Union [
2024-09-10 15:24:19 -07:00
OptionLine ,
OptionArc ,
OptionBezier ,
OptionTangentialArc ,
OptionTangentialArcTo ,
2024-10-29 17:42:26 -07:00
OptionArcTo ,
2025-04-01 15:08:02 -07:00
OptionCircularInvolute ,
2023-11-29 10:32:31 -08:00
] ,
Field ( discriminator = " type " ) ,
2023-11-28 14:29:16 -08:00
]
2023-11-29 00:39:14 -08:00
]