Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2023-11-29 00:39:14 -08:00
parent bc3d698539
commit faaeb3a472
74 changed files with 496 additions and 1985 deletions

View File

@ -1,9 +1,7 @@
from typing import Any, Dict, List, Optional, Type, TypeVar, Union
from typing import List, Optional, Union
from uuid import UUID
import attr
from pydantic import BaseModel, GetCoreSchemaHandler
from pydantic_core import CoreSchema, core_schema
from pydantic import BaseModel, RootModel
from ..models.annotation_options import AnnotationOptions
from ..models.annotation_type import AnnotationType
@ -724,15 +722,8 @@ class curve_set_constraint(BaseModel):
type: str = "curve_set_constraint"
GY = TypeVar("GY", bound="ModelingCmd")
@attr.s(auto_attribs=True)
class ModelingCmd:
"""Commands that the KittyCAD engine can execute."""
type: Union[
ModelingCmd = RootModel[
Union[
start_path,
move_path_pen,
extend_path,
@ -805,605 +796,4 @@ class ModelingCmd:
get_sketch_mode_plane,
curve_set_constraint,
]
def __init__(
self,
type: Union[
start_path,
move_path_pen,
extend_path,
extrude,
close_path,
camera_drag_start,
camera_drag_move,
camera_drag_end,
default_camera_look_at,
default_camera_zoom,
default_camera_enable_sketch_mode,
default_camera_disable_sketch_mode,
default_camera_focus_on,
export,
entity_get_parent_id,
entity_get_num_children,
entity_get_child_uuid,
entity_get_all_child_uuids,
edit_mode_enter,
edit_mode_exit,
select_with_point,
select_clear,
select_add,
select_remove,
select_replace,
select_get,
highlight_set_entity,
highlight_set_entities,
new_annotation,
update_annotation,
object_visible,
object_bring_to_front,
get_entity_type,
solid2d_add_hole,
solid3d_get_all_edge_faces,
solid3d_get_all_opposite_edges,
solid3d_get_opposite_edge,
solid3d_get_next_adjacent_edge,
solid3d_get_prev_adjacent_edge,
send_object,
entity_set_opacity,
entity_fade,
make_plane,
plane_set_color,
set_tool,
mouse_move,
mouse_click,
sketch_mode_enable,
sketch_mode_disable,
curve_get_type,
curve_get_control_points,
take_snapshot,
make_axes_gizmo,
path_get_info,
path_get_curve_uuids_for_vertices,
path_get_vertex_uuids,
handle_mouse_drag_start,
handle_mouse_drag_move,
handle_mouse_drag_end,
remove_scene_objects,
plane_intersect_and_project,
curve_get_end_points,
reconfigure_stream,
import_files,
mass,
density,
volume,
center_of_mass,
surface_area,
get_sketch_mode_plane,
curve_set_constraint,
],
):
self.type = type
def model_dump(self) -> Dict[str, Any]:
if isinstance(self.type, start_path):
ON: start_path = self.type
return ON.model_dump()
elif isinstance(self.type, move_path_pen):
US: move_path_pen = self.type
return US.model_dump()
elif isinstance(self.type, extend_path):
FH: extend_path = self.type
return FH.model_dump()
elif isinstance(self.type, extrude):
BB: extrude = self.type
return BB.model_dump()
elif isinstance(self.type, close_path):
TV: close_path = self.type
return TV.model_dump()
elif isinstance(self.type, camera_drag_start):
CE: camera_drag_start = self.type
return CE.model_dump()
elif isinstance(self.type, camera_drag_move):
LT: camera_drag_move = self.type
return LT.model_dump()
elif isinstance(self.type, camera_drag_end):
YY: camera_drag_end = self.type
return YY.model_dump()
elif isinstance(self.type, default_camera_look_at):
FZ: default_camera_look_at = self.type
return FZ.model_dump()
elif isinstance(self.type, default_camera_zoom):
NN: default_camera_zoom = self.type
return NN.model_dump()
elif isinstance(self.type, default_camera_enable_sketch_mode):
VI: default_camera_enable_sketch_mode = self.type
return VI.model_dump()
elif isinstance(self.type, default_camera_disable_sketch_mode):
QF: default_camera_disable_sketch_mode = self.type
return QF.model_dump()
elif isinstance(self.type, default_camera_focus_on):
OJ: default_camera_focus_on = self.type
return OJ.model_dump()
elif isinstance(self.type, export):
YF: export = self.type
return YF.model_dump()
elif isinstance(self.type, entity_get_parent_id):
LK: entity_get_parent_id = self.type
return LK.model_dump()
elif isinstance(self.type, entity_get_num_children):
WB: entity_get_num_children = self.type
return WB.model_dump()
elif isinstance(self.type, entity_get_child_uuid):
HC: entity_get_child_uuid = self.type
return HC.model_dump()
elif isinstance(self.type, entity_get_all_child_uuids):
PV: entity_get_all_child_uuids = self.type
return PV.model_dump()
elif isinstance(self.type, edit_mode_enter):
TP: edit_mode_enter = self.type
return TP.model_dump()
elif isinstance(self.type, edit_mode_exit):
OM: edit_mode_exit = self.type
return OM.model_dump()
elif isinstance(self.type, select_with_point):
RS: select_with_point = self.type
return RS.model_dump()
elif isinstance(self.type, select_clear):
MP: select_clear = self.type
return MP.model_dump()
elif isinstance(self.type, select_add):
RO: select_add = self.type
return RO.model_dump()
elif isinstance(self.type, select_remove):
BA: select_remove = self.type
return BA.model_dump()
elif isinstance(self.type, select_replace):
CB: select_replace = self.type
return CB.model_dump()
elif isinstance(self.type, select_get):
TO: select_get = self.type
return TO.model_dump()
elif isinstance(self.type, highlight_set_entity):
EO: highlight_set_entity = self.type
return EO.model_dump()
elif isinstance(self.type, highlight_set_entities):
QO: highlight_set_entities = self.type
return QO.model_dump()
elif isinstance(self.type, new_annotation):
IZ: new_annotation = self.type
return IZ.model_dump()
elif isinstance(self.type, update_annotation):
NK: update_annotation = self.type
return NK.model_dump()
elif isinstance(self.type, object_visible):
QE: object_visible = self.type
return QE.model_dump()
elif isinstance(self.type, object_bring_to_front):
KT: object_bring_to_front = self.type
return KT.model_dump()
elif isinstance(self.type, get_entity_type):
GU: get_entity_type = self.type
return GU.model_dump()
elif isinstance(self.type, solid2d_add_hole):
UP: solid2d_add_hole = self.type
return UP.model_dump()
elif isinstance(self.type, solid3d_get_all_edge_faces):
DJ: solid3d_get_all_edge_faces = self.type
return DJ.model_dump()
elif isinstance(self.type, solid3d_get_all_opposite_edges):
TR: solid3d_get_all_opposite_edges = self.type
return TR.model_dump()
elif isinstance(self.type, solid3d_get_opposite_edge):
JF: solid3d_get_opposite_edge = self.type
return JF.model_dump()
elif isinstance(self.type, solid3d_get_next_adjacent_edge):
EL: solid3d_get_next_adjacent_edge = self.type
return EL.model_dump()
elif isinstance(self.type, solid3d_get_prev_adjacent_edge):
LF: solid3d_get_prev_adjacent_edge = self.type
return LF.model_dump()
elif isinstance(self.type, send_object):
GN: send_object = self.type
return GN.model_dump()
elif isinstance(self.type, entity_set_opacity):
VJ: entity_set_opacity = self.type
return VJ.model_dump()
elif isinstance(self.type, entity_fade):
YW: entity_fade = self.type
return YW.model_dump()
elif isinstance(self.type, make_plane):
NO: make_plane = self.type
return NO.model_dump()
elif isinstance(self.type, plane_set_color):
RG: plane_set_color = self.type
return RG.model_dump()
elif isinstance(self.type, set_tool):
LD: set_tool = self.type
return LD.model_dump()
elif isinstance(self.type, mouse_move):
TN: mouse_move = self.type
return TN.model_dump()
elif isinstance(self.type, mouse_click):
UG: mouse_click = self.type
return UG.model_dump()
elif isinstance(self.type, sketch_mode_enable):
NZ: sketch_mode_enable = self.type
return NZ.model_dump()
elif isinstance(self.type, sketch_mode_disable):
LO: sketch_mode_disable = self.type
return LO.model_dump()
elif isinstance(self.type, curve_get_type):
OW: curve_get_type = self.type
return OW.model_dump()
elif isinstance(self.type, curve_get_control_points):
PQ: curve_get_control_points = self.type
return PQ.model_dump()
elif isinstance(self.type, take_snapshot):
OU: take_snapshot = self.type
return OU.model_dump()
elif isinstance(self.type, make_axes_gizmo):
XI: make_axes_gizmo = self.type
return XI.model_dump()
elif isinstance(self.type, path_get_info):
PS: path_get_info = self.type
return PS.model_dump()
elif isinstance(self.type, path_get_curve_uuids_for_vertices):
XL: path_get_curve_uuids_for_vertices = self.type
return XL.model_dump()
elif isinstance(self.type, path_get_vertex_uuids):
FT: path_get_vertex_uuids = self.type
return FT.model_dump()
elif isinstance(self.type, handle_mouse_drag_start):
SC: handle_mouse_drag_start = self.type
return SC.model_dump()
elif isinstance(self.type, handle_mouse_drag_move):
JA: handle_mouse_drag_move = self.type
return JA.model_dump()
elif isinstance(self.type, handle_mouse_drag_end):
UK: handle_mouse_drag_end = self.type
return UK.model_dump()
elif isinstance(self.type, remove_scene_objects):
MT: remove_scene_objects = self.type
return MT.model_dump()
elif isinstance(self.type, plane_intersect_and_project):
TF: plane_intersect_and_project = self.type
return TF.model_dump()
elif isinstance(self.type, curve_get_end_points):
JD: curve_get_end_points = self.type
return JD.model_dump()
elif isinstance(self.type, reconfigure_stream):
BH: reconfigure_stream = self.type
return BH.model_dump()
elif isinstance(self.type, import_files):
CN: import_files = self.type
return CN.model_dump()
elif isinstance(self.type, mass):
SO: mass = self.type
return SO.model_dump()
elif isinstance(self.type, density):
AM: density = self.type
return AM.model_dump()
elif isinstance(self.type, volume):
SG: volume = self.type
return SG.model_dump()
elif isinstance(self.type, center_of_mass):
SY: center_of_mass = self.type
return SY.model_dump()
elif isinstance(self.type, surface_area):
WS: surface_area = self.type
return WS.model_dump()
elif isinstance(self.type, get_sketch_mode_plane):
MK: get_sketch_mode_plane = self.type
return MK.model_dump()
elif isinstance(self.type, curve_set_constraint):
FY: curve_set_constraint = self.type
return FY.model_dump()
raise Exception("Unknown type")
@classmethod
def from_dict(cls: Type[GY], d: Dict[str, Any]) -> GY:
if d.get("type") == "start_path":
PC: start_path = start_path(**d)
return cls(type=PC)
elif d.get("type") == "move_path_pen":
KQ: move_path_pen = move_path_pen(**d)
return cls(type=KQ)
elif d.get("type") == "extend_path":
NH: extend_path = extend_path(**d)
return cls(type=NH)
elif d.get("type") == "extrude":
PJ: extrude = extrude(**d)
return cls(type=PJ)
elif d.get("type") == "close_path":
CR: close_path = close_path(**d)
return cls(type=CR)
elif d.get("type") == "camera_drag_start":
MS: camera_drag_start = camera_drag_start(**d)
return cls(type=MS)
elif d.get("type") == "camera_drag_move":
ED: camera_drag_move = camera_drag_move(**d)
return cls(type=ED)
elif d.get("type") == "camera_drag_end":
DO: camera_drag_end = camera_drag_end(**d)
return cls(type=DO)
elif d.get("type") == "default_camera_look_at":
GL: default_camera_look_at = default_camera_look_at(**d)
return cls(type=GL)
elif d.get("type") == "default_camera_zoom":
OH: default_camera_zoom = default_camera_zoom(**d)
return cls(type=OH)
elif d.get("type") == "default_camera_enable_sketch_mode":
ET: default_camera_enable_sketch_mode = default_camera_enable_sketch_mode(
**d
)
return cls(type=ET)
elif d.get("type") == "default_camera_disable_sketch_mode":
DI: default_camera_disable_sketch_mode = default_camera_disable_sketch_mode(
**d
)
return cls(type=DI)
elif d.get("type") == "default_camera_focus_on":
UF: default_camera_focus_on = default_camera_focus_on(**d)
return cls(type=UF)
elif d.get("type") == "export":
PY: export = export(**d)
return cls(type=PY)
elif d.get("type") == "entity_get_parent_id":
AR: entity_get_parent_id = entity_get_parent_id(**d)
return cls(type=AR)
elif d.get("type") == "entity_get_num_children":
KK: entity_get_num_children = entity_get_num_children(**d)
return cls(type=KK)
elif d.get("type") == "entity_get_child_uuid":
FM: entity_get_child_uuid = entity_get_child_uuid(**d)
return cls(type=FM)
elif d.get("type") == "entity_get_all_child_uuids":
QI: entity_get_all_child_uuids = entity_get_all_child_uuids(**d)
return cls(type=QI)
elif d.get("type") == "edit_mode_enter":
CF: edit_mode_enter = edit_mode_enter(**d)
return cls(type=CF)
elif d.get("type") == "edit_mode_exit":
EN: edit_mode_exit = edit_mode_exit(**d)
return cls(type=EN)
elif d.get("type") == "select_with_point":
LR: select_with_point = select_with_point(**d)
return cls(type=LR)
elif d.get("type") == "select_clear":
WF: select_clear = select_clear(**d)
return cls(type=WF)
elif d.get("type") == "select_add":
DN: select_add = select_add(**d)
return cls(type=DN)
elif d.get("type") == "select_remove":
OR: select_remove = select_remove(**d)
return cls(type=OR)
elif d.get("type") == "select_replace":
LC: select_replace = select_replace(**d)
return cls(type=LC)
elif d.get("type") == "select_get":
ZP: select_get = select_get(**d)
return cls(type=ZP)
elif d.get("type") == "highlight_set_entity":
NY: highlight_set_entity = highlight_set_entity(**d)
return cls(type=NY)
elif d.get("type") == "highlight_set_entities":
KX: highlight_set_entities = highlight_set_entities(**d)
return cls(type=KX)
elif d.get("type") == "new_annotation":
WO: new_annotation = new_annotation(**d)
return cls(type=WO)
elif d.get("type") == "update_annotation":
UQ: update_annotation = update_annotation(**d)
return cls(type=UQ)
elif d.get("type") == "object_visible":
XH: object_visible = object_visible(**d)
return cls(type=XH)
elif d.get("type") == "object_bring_to_front":
BV: object_bring_to_front = object_bring_to_front(**d)
return cls(type=BV)
elif d.get("type") == "get_entity_type":
SS: get_entity_type = get_entity_type(**d)
return cls(type=SS)
elif d.get("type") == "solid2d_add_hole":
AZ: solid2d_add_hole = solid2d_add_hole(**d)
return cls(type=AZ)
elif d.get("type") == "solid3d_get_all_edge_faces":
WJ: solid3d_get_all_edge_faces = solid3d_get_all_edge_faces(**d)
return cls(type=WJ)
elif d.get("type") == "solid3d_get_all_opposite_edges":
YD: solid3d_get_all_opposite_edges = solid3d_get_all_opposite_edges(**d)
return cls(type=YD)
elif d.get("type") == "solid3d_get_opposite_edge":
VP: solid3d_get_opposite_edge = solid3d_get_opposite_edge(**d)
return cls(type=VP)
elif d.get("type") == "solid3d_get_next_adjacent_edge":
ZG: solid3d_get_next_adjacent_edge = solid3d_get_next_adjacent_edge(**d)
return cls(type=ZG)
elif d.get("type") == "solid3d_get_prev_adjacent_edge":
CS: solid3d_get_prev_adjacent_edge = solid3d_get_prev_adjacent_edge(**d)
return cls(type=CS)
elif d.get("type") == "send_object":
GD: send_object = send_object(**d)
return cls(type=GD)
elif d.get("type") == "entity_set_opacity":
OX: entity_set_opacity = entity_set_opacity(**d)
return cls(type=OX)
elif d.get("type") == "entity_fade":
QX: entity_fade = entity_fade(**d)
return cls(type=QX)
elif d.get("type") == "make_plane":
VX: make_plane = make_plane(**d)
return cls(type=VX)
elif d.get("type") == "plane_set_color":
IT: plane_set_color = plane_set_color(**d)
return cls(type=IT)
elif d.get("type") == "set_tool":
UA: set_tool = set_tool(**d)
return cls(type=UA)
elif d.get("type") == "mouse_move":
MZ: mouse_move = mouse_move(**d)
return cls(type=MZ)
elif d.get("type") == "mouse_click":
CY: mouse_click = mouse_click(**d)
return cls(type=CY)
elif d.get("type") == "sketch_mode_enable":
LI: sketch_mode_enable = sketch_mode_enable(**d)
return cls(type=LI)
elif d.get("type") == "sketch_mode_disable":
XJ: sketch_mode_disable = sketch_mode_disable(**d)
return cls(type=XJ)
elif d.get("type") == "curve_get_type":
JQ: curve_get_type = curve_get_type(**d)
return cls(type=JQ)
elif d.get("type") == "curve_get_control_points":
IM: curve_get_control_points = curve_get_control_points(**d)
return cls(type=IM)
elif d.get("type") == "take_snapshot":
KL: take_snapshot = take_snapshot(**d)
return cls(type=KL)
elif d.get("type") == "make_axes_gizmo":
PO: make_axes_gizmo = make_axes_gizmo(**d)
return cls(type=PO)
elif d.get("type") == "path_get_info":
WR: path_get_info = path_get_info(**d)
return cls(type=WR)
elif d.get("type") == "path_get_curve_uuids_for_vertices":
ZX: path_get_curve_uuids_for_vertices = path_get_curve_uuids_for_vertices(
**d
)
return cls(type=ZX)
elif d.get("type") == "path_get_vertex_uuids":
NX: path_get_vertex_uuids = path_get_vertex_uuids(**d)
return cls(type=NX)
elif d.get("type") == "handle_mouse_drag_start":
TX: handle_mouse_drag_start = handle_mouse_drag_start(**d)
return cls(type=TX)
elif d.get("type") == "handle_mouse_drag_move":
SK: handle_mouse_drag_move = handle_mouse_drag_move(**d)
return cls(type=SK)
elif d.get("type") == "handle_mouse_drag_end":
CX: handle_mouse_drag_end = handle_mouse_drag_end(**d)
return cls(type=CX)
elif d.get("type") == "remove_scene_objects":
LJ: remove_scene_objects = remove_scene_objects(**d)
return cls(type=LJ)
elif d.get("type") == "plane_intersect_and_project":
HF: plane_intersect_and_project = plane_intersect_and_project(**d)
return cls(type=HF)
elif d.get("type") == "curve_get_end_points":
RZ: curve_get_end_points = curve_get_end_points(**d)
return cls(type=RZ)
elif d.get("type") == "reconfigure_stream":
SX: reconfigure_stream = reconfigure_stream(**d)
return cls(type=SX)
elif d.get("type") == "import_files":
GS: import_files = import_files(**d)
return cls(type=GS)
elif d.get("type") == "mass":
ZS: mass = mass(**d)
return cls(type=ZS)
elif d.get("type") == "density":
GK: density = density(**d)
return cls(type=GK)
elif d.get("type") == "volume":
QZ: volume = volume(**d)
return cls(type=QZ)
elif d.get("type") == "center_of_mass":
YK: center_of_mass = center_of_mass(**d)
return cls(type=YK)
elif d.get("type") == "surface_area":
SL: surface_area = surface_area(**d)
return cls(type=SL)
elif d.get("type") == "get_sketch_mode_plane":
TU: get_sketch_mode_plane = get_sketch_mode_plane(**d)
return cls(type=TU)
elif d.get("type") == "curve_set_constraint":
FD: curve_set_constraint = curve_set_constraint(**d)
return cls(type=FD)
raise Exception("Unknown type")
@classmethod
def __get_pydantic_core_schema__(
cls, source_type: Any, handler: GetCoreSchemaHandler
) -> CoreSchema:
return core_schema.no_info_after_validator_function(
cls,
handler(
Union[
start_path,
move_path_pen,
extend_path,
extrude,
close_path,
camera_drag_start,
camera_drag_move,
camera_drag_end,
default_camera_look_at,
default_camera_zoom,
default_camera_enable_sketch_mode,
default_camera_disable_sketch_mode,
default_camera_focus_on,
export,
entity_get_parent_id,
entity_get_num_children,
entity_get_child_uuid,
entity_get_all_child_uuids,
edit_mode_enter,
edit_mode_exit,
select_with_point,
select_clear,
select_add,
select_remove,
select_replace,
select_get,
highlight_set_entity,
highlight_set_entities,
new_annotation,
update_annotation,
object_visible,
object_bring_to_front,
get_entity_type,
solid2d_add_hole,
solid3d_get_all_edge_faces,
solid3d_get_all_opposite_edges,
solid3d_get_opposite_edge,
solid3d_get_next_adjacent_edge,
solid3d_get_prev_adjacent_edge,
send_object,
entity_set_opacity,
entity_fade,
make_plane,
plane_set_color,
set_tool,
mouse_move,
mouse_click,
sketch_mode_enable,
sketch_mode_disable,
curve_get_type,
curve_get_control_points,
take_snapshot,
make_axes_gizmo,
path_get_info,
path_get_curve_uuids_for_vertices,
path_get_vertex_uuids,
handle_mouse_drag_start,
handle_mouse_drag_move,
handle_mouse_drag_end,
remove_scene_objects,
plane_intersect_and_project,
curve_get_end_points,
reconfigure_stream,
import_files,
mass,
density,
volume,
center_of_mass,
surface_area,
get_sketch_mode_plane,
curve_set_constraint,
]
),
)
]