@ -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.system import System
|
||||
from ..models.unit_length import UnitLength
|
||||
@ -62,15 +60,8 @@ class stl(BaseModel):
|
||||
units: UnitLength
|
||||
|
||||
|
||||
GY = TypeVar("GY", bound="InputFormat")
|
||||
|
||||
|
||||
@attr.s(auto_attribs=True)
|
||||
class InputFormat:
|
||||
|
||||
"""Input format specifier."""
|
||||
|
||||
type: Union[
|
||||
InputFormat = RootModel[
|
||||
Union[
|
||||
fbx,
|
||||
gltf,
|
||||
obj,
|
||||
@ -79,87 +70,4 @@ class InputFormat:
|
||||
step,
|
||||
stl,
|
||||
]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
type: Union[
|
||||
fbx,
|
||||
gltf,
|
||||
obj,
|
||||
ply,
|
||||
sldprt,
|
||||
step,
|
||||
stl,
|
||||
],
|
||||
):
|
||||
self.type = type
|
||||
|
||||
def model_dump(self) -> Dict[str, Any]:
|
||||
if isinstance(self.type, fbx):
|
||||
JV: fbx = self.type
|
||||
return JV.model_dump()
|
||||
elif isinstance(self.type, gltf):
|
||||
FV: gltf = self.type
|
||||
return FV.model_dump()
|
||||
elif isinstance(self.type, obj):
|
||||
OY: obj = self.type
|
||||
return OY.model_dump()
|
||||
elif isinstance(self.type, ply):
|
||||
TM: ply = self.type
|
||||
return TM.model_dump()
|
||||
elif isinstance(self.type, sldprt):
|
||||
AH: sldprt = self.type
|
||||
return AH.model_dump()
|
||||
elif isinstance(self.type, step):
|
||||
JR: step = self.type
|
||||
return JR.model_dump()
|
||||
elif isinstance(self.type, stl):
|
||||
HK: stl = self.type
|
||||
return HK.model_dump()
|
||||
|
||||
raise Exception("Unknown type")
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls: Type[GY], d: Dict[str, Any]) -> GY:
|
||||
if d.get("type") == "fbx":
|
||||
IO: fbx = fbx(**d)
|
||||
return cls(type=IO)
|
||||
elif d.get("type") == "gltf":
|
||||
LE: gltf = gltf(**d)
|
||||
return cls(type=LE)
|
||||
elif d.get("type") == "obj":
|
||||
HO: obj = obj(**d)
|
||||
return cls(type=HO)
|
||||
elif d.get("type") == "ply":
|
||||
BS: ply = ply(**d)
|
||||
return cls(type=BS)
|
||||
elif d.get("type") == "sldprt":
|
||||
EG: sldprt = sldprt(**d)
|
||||
return cls(type=EG)
|
||||
elif d.get("type") == "step":
|
||||
LY: step = step(**d)
|
||||
return cls(type=LY)
|
||||
elif d.get("type") == "stl":
|
||||
VR: stl = stl(**d)
|
||||
return cls(type=VR)
|
||||
|
||||
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[
|
||||
fbx,
|
||||
gltf,
|
||||
obj,
|
||||
ply,
|
||||
sldprt,
|
||||
step,
|
||||
stl,
|
||||
]
|
||||
),
|
||||
)
|
||||
]
|
||||
|
Reference in New Issue
Block a user