|
| 1 | +from typing import Literal, get_args, cast |
| 2 | + |
| 3 | +GeodePointMeshType = Literal[ |
| 4 | + "PointSet2D", |
| 5 | + "PointSet3D", |
| 6 | +] |
| 7 | +GeodeEdgeMeshType = Literal[ |
| 8 | + "EdgedCurve2D", |
| 9 | + "EdgedCurve3D", |
| 10 | +] |
| 11 | +GeodePolygonMeshType = Literal[ |
| 12 | + "RasterImage2D", |
| 13 | + "PolygonalSurface2D", |
| 14 | + "PolygonalSurface3D", |
| 15 | + "TriangulatedSurface2D", |
| 16 | + "TriangulatedSurface3D", |
| 17 | + "RegularGrid2D", |
| 18 | + "LightRegularGrid2D", |
| 19 | +] |
| 20 | +GeodePolyhedronMeshType = Literal[ |
| 21 | + "RasterImage3D", |
| 22 | + "PolyhedralSolid3D", |
| 23 | + "TetrahedralSolid3D", |
| 24 | + "HybridSolid3D", |
| 25 | + "RegularGrid3D", |
| 26 | + "LightRegularGrid3D", |
| 27 | +] |
| 28 | +GeodeMeshType = ( |
| 29 | + Literal[ |
| 30 | + "VertexSet", |
| 31 | + "Graph", |
| 32 | + ] |
| 33 | + | GeodePointMeshType |
| 34 | + | GeodeEdgeMeshType |
| 35 | + | GeodePolygonMeshType |
| 36 | + | GeodePolyhedronMeshType |
| 37 | +) |
| 38 | +GeodeModelType = Literal[ |
| 39 | + "BRep", |
| 40 | + "Section", |
| 41 | + "StructuralModel", |
| 42 | + "CrossSection", |
| 43 | + "ImplicitStructuralModel", |
| 44 | + "ImplicitCrossSection", |
| 45 | +] |
| 46 | +GeodeObjectType = GeodeMeshType | GeodeModelType |
| 47 | + |
| 48 | + |
| 49 | +def _flatten_literal_args(literal: object) -> tuple[str, ...]: |
| 50 | + flattened: list[str] = [] |
| 51 | + for arg in get_args(literal): |
| 52 | + if isinstance(arg, str): |
| 53 | + flattened.append(arg) |
| 54 | + else: |
| 55 | + flattened.extend(_flatten_literal_args(arg)) |
| 56 | + return tuple(flattened) |
| 57 | + |
| 58 | + |
| 59 | +GeodeObjectType_values = _flatten_literal_args(GeodeObjectType) |
| 60 | + |
| 61 | + |
| 62 | +def geode_object_type(value: str) -> GeodeObjectType: |
| 63 | + if value not in GeodeObjectType_values: |
| 64 | + raise ValueError( |
| 65 | + f"Invalid GeodeObjectType: {value!r}. Must be one of {GeodeObjectType_values}" |
| 66 | + ) |
| 67 | + return cast(GeodeObjectType, value) |
| 68 | + |
| 69 | + |
| 70 | +ViewerType = Literal["mesh", "model"] |
| 71 | + |
| 72 | +ViewerElementsType = Literal["points", "edges", "polygons", "polyhedra", "default"] |
0 commit comments