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,8 +1,6 @@
from typing import Any, Dict, Type, TypeVar, Union
from typing import Union
import attr
from pydantic import BaseModel, GetCoreSchemaHandler
from pydantic_core import CoreSchema, core_schema
from pydantic import BaseModel, RootModel
from ..models.center_of_mass import CenterOfMass
from ..models.curve_get_control_points import CurveGetControlPoints
@ -282,15 +280,8 @@ class get_sketch_mode_plane(BaseModel):
type: str = "get_sketch_mode_plane"
GY = TypeVar("GY", bound="OkModelingCmdResponse")
@attr.s(auto_attribs=True)
class OkModelingCmdResponse:
"""A successful response from a modeling command. This can be one of several types of responses, depending on the command."""
type: Union[
OkModelingCmdResponse = RootModel[
Union[
empty,
export,
select_with_point,
@ -323,281 +314,4 @@ class OkModelingCmdResponse:
center_of_mass,
get_sketch_mode_plane,
]
def __init__(
self,
type: Union[
empty,
export,
select_with_point,
highlight_set_entity,
entity_get_child_uuid,
entity_get_num_children,
entity_get_parent_id,
entity_get_all_child_uuids,
select_get,
get_entity_type,
solid3d_get_all_edge_faces,
solid3d_get_all_opposite_edges,
solid3d_get_opposite_edge,
solid3d_get_prev_adjacent_edge,
solid3d_get_next_adjacent_edge,
mouse_click,
curve_get_type,
curve_get_control_points,
take_snapshot,
path_get_info,
path_get_curve_uuids_for_vertices,
path_get_vertex_uuids,
plane_intersect_and_project,
curve_get_end_points,
import_files,
mass,
volume,
density,
surface_area,
center_of_mass,
get_sketch_mode_plane,
],
):
self.type = type
def model_dump(self) -> Dict[str, Any]:
if isinstance(self.type, empty):
TZ: empty = self.type
return TZ.model_dump()
elif isinstance(self.type, export):
RQ: export = self.type
return RQ.model_dump()
elif isinstance(self.type, select_with_point):
CM: select_with_point = self.type
return CM.model_dump()
elif isinstance(self.type, highlight_set_entity):
WP: highlight_set_entity = self.type
return WP.model_dump()
elif isinstance(self.type, entity_get_child_uuid):
LN: entity_get_child_uuid = self.type
return LN.model_dump()
elif isinstance(self.type, entity_get_num_children):
MG: entity_get_num_children = self.type
return MG.model_dump()
elif isinstance(self.type, entity_get_parent_id):
BF: entity_get_parent_id = self.type
return BF.model_dump()
elif isinstance(self.type, entity_get_all_child_uuids):
MB: entity_get_all_child_uuids = self.type
return MB.model_dump()
elif isinstance(self.type, select_get):
FJ: select_get = self.type
return FJ.model_dump()
elif isinstance(self.type, get_entity_type):
SF: get_entity_type = self.type
return SF.model_dump()
elif isinstance(self.type, solid3d_get_all_edge_faces):
BM: solid3d_get_all_edge_faces = self.type
return BM.model_dump()
elif isinstance(self.type, solid3d_get_all_opposite_edges):
NC: solid3d_get_all_opposite_edges = self.type
return NC.model_dump()
elif isinstance(self.type, solid3d_get_opposite_edge):
FF: solid3d_get_opposite_edge = self.type
return FF.model_dump()
elif isinstance(self.type, solid3d_get_prev_adjacent_edge):
FS: solid3d_get_prev_adjacent_edge = self.type
return FS.model_dump()
elif isinstance(self.type, solid3d_get_next_adjacent_edge):
EQ: solid3d_get_next_adjacent_edge = self.type
return EQ.model_dump()
elif isinstance(self.type, mouse_click):
MD: mouse_click = self.type
return MD.model_dump()
elif isinstance(self.type, curve_get_type):
UJ: curve_get_type = self.type
return UJ.model_dump()
elif isinstance(self.type, curve_get_control_points):
DL: curve_get_control_points = self.type
return DL.model_dump()
elif isinstance(self.type, take_snapshot):
PT: take_snapshot = self.type
return PT.model_dump()
elif isinstance(self.type, path_get_info):
VF: path_get_info = self.type
return VF.model_dump()
elif isinstance(self.type, path_get_curve_uuids_for_vertices):
WH: path_get_curve_uuids_for_vertices = self.type
return WH.model_dump()
elif isinstance(self.type, path_get_vertex_uuids):
UY: path_get_vertex_uuids = self.type
return UY.model_dump()
elif isinstance(self.type, plane_intersect_and_project):
SM: plane_intersect_and_project = self.type
return SM.model_dump()
elif isinstance(self.type, curve_get_end_points):
CG: curve_get_end_points = self.type
return CG.model_dump()
elif isinstance(self.type, import_files):
ZB: import_files = self.type
return ZB.model_dump()
elif isinstance(self.type, mass):
FX: mass = self.type
return FX.model_dump()
elif isinstance(self.type, volume):
KU: volume = self.type
return KU.model_dump()
elif isinstance(self.type, density):
FA: density = self.type
return FA.model_dump()
elif isinstance(self.type, surface_area):
JG: surface_area = self.type
return JG.model_dump()
elif isinstance(self.type, center_of_mass):
RY: center_of_mass = self.type
return RY.model_dump()
elif isinstance(self.type, get_sketch_mode_plane):
AD: get_sketch_mode_plane = self.type
return AD.model_dump()
raise Exception("Unknown type")
@classmethod
def from_dict(cls: Type[GY], d: Dict[str, Any]) -> GY:
if d.get("type") == "empty":
AX: empty = empty(**d)
return cls(type=AX)
elif d.get("type") == "export":
ZL: export = export(**d)
return cls(type=ZL)
elif d.get("type") == "select_with_point":
OS: select_with_point = select_with_point(**d)
return cls(type=OS)
elif d.get("type") == "highlight_set_entity":
XO: highlight_set_entity = highlight_set_entity(**d)
return cls(type=XO)
elif d.get("type") == "entity_get_child_uuid":
KR: entity_get_child_uuid = entity_get_child_uuid(**d)
return cls(type=KR)
elif d.get("type") == "entity_get_num_children":
UE: entity_get_num_children = entity_get_num_children(**d)
return cls(type=UE)
elif d.get("type") == "entity_get_parent_id":
UU: entity_get_parent_id = entity_get_parent_id(**d)
return cls(type=UU)
elif d.get("type") == "entity_get_all_child_uuids":
TB: entity_get_all_child_uuids = entity_get_all_child_uuids(**d)
return cls(type=TB)
elif d.get("type") == "select_get":
HB: select_get = select_get(**d)
return cls(type=HB)
elif d.get("type") == "get_entity_type":
DU: get_entity_type = get_entity_type(**d)
return cls(type=DU)
elif d.get("type") == "solid3d_get_all_edge_faces":
TY: solid3d_get_all_edge_faces = solid3d_get_all_edge_faces(**d)
return cls(type=TY)
elif d.get("type") == "solid3d_get_all_opposite_edges":
GP: solid3d_get_all_opposite_edges = solid3d_get_all_opposite_edges(**d)
return cls(type=GP)
elif d.get("type") == "solid3d_get_opposite_edge":
YO: solid3d_get_opposite_edge = solid3d_get_opposite_edge(**d)
return cls(type=YO)
elif d.get("type") == "solid3d_get_prev_adjacent_edge":
WN: solid3d_get_prev_adjacent_edge = solid3d_get_prev_adjacent_edge(**d)
return cls(type=WN)
elif d.get("type") == "solid3d_get_next_adjacent_edge":
UW: solid3d_get_next_adjacent_edge = solid3d_get_next_adjacent_edge(**d)
return cls(type=UW)
elif d.get("type") == "mouse_click":
HD: mouse_click = mouse_click(**d)
return cls(type=HD)
elif d.get("type") == "curve_get_type":
RU: curve_get_type = curve_get_type(**d)
return cls(type=RU)
elif d.get("type") == "curve_get_control_points":
QT: curve_get_control_points = curve_get_control_points(**d)
return cls(type=QT)
elif d.get("type") == "take_snapshot":
HR: take_snapshot = take_snapshot(**d)
return cls(type=HR)
elif d.get("type") == "path_get_info":
VM: path_get_info = path_get_info(**d)
return cls(type=VM)
elif d.get("type") == "path_get_curve_uuids_for_vertices":
DQ: path_get_curve_uuids_for_vertices = path_get_curve_uuids_for_vertices(
**d
)
return cls(type=DQ)
elif d.get("type") == "path_get_vertex_uuids":
PD: path_get_vertex_uuids = path_get_vertex_uuids(**d)
return cls(type=PD)
elif d.get("type") == "plane_intersect_and_project":
JL: plane_intersect_and_project = plane_intersect_and_project(**d)
return cls(type=JL)
elif d.get("type") == "curve_get_end_points":
QA: curve_get_end_points = curve_get_end_points(**d)
return cls(type=QA)
elif d.get("type") == "import_files":
AU: import_files = import_files(**d)
return cls(type=AU)
elif d.get("type") == "mass":
BL: mass = mass(**d)
return cls(type=BL)
elif d.get("type") == "volume":
PZ: volume = volume(**d)
return cls(type=PZ)
elif d.get("type") == "density":
GE: density = density(**d)
return cls(type=GE)
elif d.get("type") == "surface_area":
HH: surface_area = surface_area(**d)
return cls(type=HH)
elif d.get("type") == "center_of_mass":
AE: center_of_mass = center_of_mass(**d)
return cls(type=AE)
elif d.get("type") == "get_sketch_mode_plane":
AB: get_sketch_mode_plane = get_sketch_mode_plane(**d)
return cls(type=AB)
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[
empty,
export,
select_with_point,
highlight_set_entity,
entity_get_child_uuid,
entity_get_num_children,
entity_get_parent_id,
entity_get_all_child_uuids,
select_get,
get_entity_type,
solid3d_get_all_edge_faces,
solid3d_get_all_opposite_edges,
solid3d_get_opposite_edge,
solid3d_get_prev_adjacent_edge,
solid3d_get_next_adjacent_edge,
mouse_click,
curve_get_type,
curve_get_control_points,
take_snapshot,
path_get_info,
path_get_curve_uuids_for_vertices,
path_get_vertex_uuids,
plane_intersect_and_project,
curve_get_end_points,
import_files,
mass,
volume,
density,
surface_area,
center_of_mass,
get_sketch_mode_plane,
]
),
)
]