Skip to content

Commit 9036f0b

Browse files
committed
fix(Schemas): add types
1 parent b96a8e5 commit 9036f0b

18 files changed

+180
-243
lines changed

src/opengeodeweb_viewer/rpc/generic/generic_protocols.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515

1616
class VtkGenericView(VtkView):
17-
prefix = "opengeodeweb_viewer.generic."
18-
schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas"))
17+
generic_prefix = "opengeodeweb_viewer.generic."
18+
generic_schemas_dict = get_schemas_dict(
19+
os.path.join(os.path.dirname(__file__), "schemas")
20+
)
1921

2022
def __init__(
2123
self, mesh_protocols: VtkMeshView, model_protocols: VtkModelView
@@ -24,9 +26,11 @@ def __init__(
2426
self.mesh_protocols = mesh_protocols
2527
self.model_protocols = model_protocols
2628

27-
@exportRpc(prefix + schemas_dict["register"]["rpc"])
29+
@exportRpc(generic_prefix + generic_schemas_dict["register"]["rpc"])
2830
def register(self, params):
29-
validate_schema(params, self.schemas_dict["register"], self.prefix)
31+
validate_schema(
32+
params, self.generic_schemas_dict["register"], self.generic_prefix
33+
)
3034
params = schemas.Register.from_dict(params)
3135
data_id = params.id
3236
specific_params = {"id": data_id}
@@ -37,9 +41,11 @@ def register(self, params):
3741
elif viewer_object == "model":
3842
self.model_protocols.registerModel(specific_params)
3943

40-
@exportRpc(prefix + schemas_dict["deregister"]["rpc"])
44+
@exportRpc(generic_prefix + generic_schemas_dict["deregister"]["rpc"])
4145
def deregister(self, params):
42-
validate_schema(params, self.schemas_dict["deregister"], self.prefix)
46+
validate_schema(
47+
params, self.generic_schemas_dict["deregister"], self.generic_prefix
48+
)
4349
params = schemas.Deregister.from_dict(params)
4450
data_id = params.id
4551
specific_params = {"id": data_id}

src/opengeodeweb_viewer/rpc/mesh/edges/mesh_edges_protocols.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Local application imports
88
from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema
99
from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView
10+
from . import schemas
1011

1112

1213
class VtkMeshEdgesView(VtkMeshView):
@@ -15,34 +16,30 @@ class VtkMeshEdgesView(VtkMeshView):
1516
os.path.join(os.path.dirname(__file__), "schemas")
1617
)
1718

18-
def __init__(self):
19+
def __init__(self) -> None:
1920
super().__init__()
2021

2122
@exportRpc(mesh_edges_prefix + mesh_edges_schemas_dict["visibility"]["rpc"])
2223
def setMeshEdgesVisibility(self, params):
2324
validate_schema(
2425
params, self.mesh_edges_schemas_dict["visibility"], self.mesh_edges_prefix
2526
)
26-
id, visibility = params["id"], params["visibility"]
27-
self.SetEdgesVisibility(id, visibility)
27+
params = schemas.Visibility.from_dict(params)
28+
self.SetEdgesVisibility(params.id, params.visibility)
2829

2930
@exportRpc(mesh_edges_prefix + mesh_edges_schemas_dict["color"]["rpc"])
3031
def setMeshEdgesColor(self, params):
3132
validate_schema(
3233
params, self.mesh_edges_schemas_dict["color"], self.mesh_edges_prefix
3334
)
34-
id, red, green, blue = (
35-
params["id"],
36-
params["color"]["r"],
37-
params["color"]["g"],
38-
params["color"]["b"],
39-
)
40-
self.SetEdgesColor(id, red, green, blue)
35+
params = schemas.Color.from_dict(params)
36+
color = params.color
37+
self.SetEdgesColor(params.id, color.r, color.g, color.b)
4138

4239
@exportRpc(mesh_edges_prefix + mesh_edges_schemas_dict["width"]["rpc"])
4340
def setMeshEdgesWidth(self, params):
4441
validate_schema(
4542
params, self.mesh_edges_schemas_dict["width"], self.mesh_edges_prefix
4643
)
47-
id, size = params["id"], params["width"]
48-
self.SetEdgesWidth(id, width)
44+
params = schemas.Color.from_dict(params)
45+
self.SetEdgesWidth(params.id, params.width)

src/opengeodeweb_viewer/rpc/mesh/mesh_protocols.py

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
RpcParamsWithColor,
1616
)
1717
from opengeodeweb_viewer.object.object_methods import VtkObjectView
18+
from . import schemas
1819

1920

2021
class VtkMeshView(VtkObjectView):
@@ -30,7 +31,8 @@ def __init__(self) -> None:
3031
def registerMesh(self, params: RpcParams) -> None:
3132
print(f"{self.mesh_schemas_dict["register"]}", flush=True)
3233
validate_schema(params, self.mesh_schemas_dict["register"], self.mesh_prefix)
33-
data_id = str(params["id"])
34+
params = schemas.Register.from_dict(params)
35+
data_id = params.id
3436
try:
3537
data = self.get_data(data_id)
3638
file_name = str(data["viewable_file_name"])
@@ -70,52 +72,41 @@ def registerMesh(self, params: RpcParams) -> None:
7072
@exportRpc(mesh_prefix + mesh_schemas_dict["deregister"]["rpc"])
7173
def deregisterMesh(self, params: RpcParams) -> None:
7274
validate_schema(params, self.mesh_schemas_dict["deregister"], self.mesh_prefix)
73-
data_id = str(params["id"])
74-
self.deregisterObject(data_id)
75+
params = schemas.Deregister.from_dict(params)
76+
self.deregisterObject(params.id)
7577

7678
@exportRpc(mesh_prefix + mesh_schemas_dict["visibility"]["rpc"])
7779
def SetMeshVisibility(self, params: RpcParams) -> None:
7880
validate_schema(params, self.mesh_schemas_dict["visibility"], self.mesh_prefix)
79-
data_id, visibility = str(params["id"]), bool(params["visibility"])
80-
self.SetVisibility(data_id, visibility)
81+
params = schemas.Visibility.from_dict(params)
82+
self.SetVisibility(params.id, parmas.visibility)
8183

8284
@exportRpc(mesh_prefix + mesh_schemas_dict["opacity"]["rpc"])
8385
def setMeshOpacity(self, params: RpcParams) -> None:
8486
validate_schema(params, self.mesh_schemas_dict["opacity"], self.mesh_prefix)
85-
data_id, opacity = str(params["id"]), float(
86-
cast(int | float, params["opacity"])
87-
)
88-
self.SetOpacity(data_id, opacity)
87+
params = schemas.Opacity.from_dict(params)
88+
self.SetOpacity(params.id, params.opacity)
8989

9090
@exportRpc(mesh_prefix + mesh_schemas_dict["color"]["rpc"])
9191
def setMeshColor(self, params: RpcParamsWithColor) -> None:
9292
validate_schema(params, self.mesh_schemas_dict["color"], self.mesh_prefix)
93-
color_dict = cast(dict[str, int], params["color"])
94-
data_id, red, green, blue = (
95-
str(params["id"]),
96-
int(color_dict["r"]),
97-
int(color_dict["g"]),
98-
int(color_dict["b"]),
99-
)
100-
self.SetColor(data_id, red, green, blue)
93+
params = schemas.Color.from_dict(params)
94+
color = params.color
95+
self.SetColor(params.id, color.r, color.g, color.b)
10196

10297
@exportRpc(mesh_prefix + mesh_schemas_dict["apply_textures"]["rpc"])
10398
def meshApplyTextures(self, params: RpcParams) -> None:
10499
validate_schema(
105100
params, self.mesh_schemas_dict["apply_textures"], self.mesh_prefix
106101
)
107-
data_id = str(params["id"])
108-
textures_info = cast(list[dict[str, str]], params["textures"])
109-
self.applyTextures(data_id, textures_info)
110-
111-
def applyTextures(self, mesh_id: str, textures_info: list[dict[str, str]]) -> None:
112-
for tex_info in textures_info:
113-
texture_id = tex_info["id"]
114-
texture_name = tex_info["texture_name"]
102+
params = schemas.ApplyTextures.from_dict(params)
103+
mesh_id = params.id
104+
for tex_info in params.textures:
105+
texture_id = tex_info.id
115106
texture_data = Data.get(texture_id)
116-
if not texture_data:
107+
if texture_data is None:
117108
continue
118-
texture_file = str(texture_data.viewable_file_name)
109+
texture_file = texture_data.viewable_file_name
119110
if not texture_file.lower().endswith(".vti"):
120111
continue
121112
texture_file_path = self.get_data_file_path(texture_id)
@@ -130,7 +121,7 @@ def applyTextures(self, mesh_id: str, textures_info: list[dict[str, str]]) -> No
130121
point_data = output.GetPointData()
131122
for i in range(point_data.GetNumberOfArrays()):
132123
array = point_data.GetArray(i)
133-
if array.GetName() == texture_name:
124+
if array.GetName() == tex_info.texture_name:
134125
point_data.SetTCoords(array)
135126
break
136127
actor = cast(vtk.vtkActor, self.get_object(mesh_id)["actor"])

src/opengeodeweb_viewer/rpc/mesh/points/mesh_points_protocols.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
RpcParamsWithColor,
1313
)
1414
from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView
15+
from . import schemas
1516

1617

1718
class VtkMeshPointsView(VtkMeshView):
@@ -28,29 +29,25 @@ def setMeshPointsVisibility(self, params: RpcParams) -> None:
2829
validate_schema(
2930
params, self.mesh_points_schemas_dict["visibility"], self.mesh_points_prefix
3031
)
31-
id, visibility = params["id"], params["visibility"]
32-
self.SetPointsVisibility(id, visibility)
32+
params = schemas.Visibility.from_dict(params)
33+
self.SetPointsVisibility(params.id, params.visibility)
3334

3435
@exportRpc(mesh_points_prefix + mesh_points_schemas_dict["color"]["rpc"])
3536
def setMeshPointsColor(self, params: RpcParamsWithColor) -> None:
3637
validate_schema(
3738
params, self.mesh_points_schemas_dict["color"], self.mesh_points_prefix
3839
)
39-
id, red, green, blue = (
40-
params["id"],
41-
params["color"]["r"],
42-
params["color"]["g"],
43-
params["color"]["b"],
44-
)
45-
self.SetPointsColor(id, red, green, blue)
40+
params = schemas.Color.from_dict(params)
41+
color = params.color
42+
self.SetPointsColor(params.id, color.r, color.g, color.b)
4643

4744
@exportRpc(mesh_points_prefix + mesh_points_schemas_dict["size"]["rpc"])
4845
def setMeshPointsSize(self, params: RpcParams) -> None:
4946
validate_schema(
5047
params, self.mesh_points_schemas_dict["size"], self.mesh_points_prefix
5148
)
52-
id, size = params["id"], params["size"]
53-
self.SetPointsSize(id, size)
49+
params = schemas.Size.from_dict(params)
50+
self.SetPointsSize(params.id, params.size)
5451

5552
@exportRpc(mesh_points_prefix + mesh_points_schemas_dict["vertex_attribute"]["rpc"])
5653
def setMeshPointsVertexAttribute(self, params: RpcParams) -> None:
@@ -59,5 +56,5 @@ def setMeshPointsVertexAttribute(self, params: RpcParams) -> None:
5956
self.mesh_points_schemas_dict["vertex_attribute"],
6057
self.mesh_points_prefix,
6158
)
62-
id, name = params["id"], params["name"]
63-
self.displayAttributeOnVertices(id, name)
59+
params = schemas.VertexAttribute.from_dict(params)
60+
self.displayAttributeOnVertices(params.id, pramas.name)

src/opengeodeweb_viewer/rpc/mesh/polygons/polygons_protocols.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Local application imports
88
from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema
99
from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView
10+
from . import schemas
1011

1112

1213
class VtkMeshPolygonsView(VtkMeshView):
@@ -25,8 +26,8 @@ def setMeshPolygonsVisibility(self, params):
2526
self.mesh_polygons_schemas_dict["visibility"],
2627
self.mesh_polygons_prefix,
2728
)
28-
id, visibility = params["id"], params["visibility"]
29-
self.SetVisibility(id, visibility)
29+
params = schemas.Visibility.from_dict(params)
30+
self.SetVisibility(params.id, params.visibility)
3031

3132
@exportRpc(mesh_polygons_prefix + mesh_polygons_schemas_dict["color"]["rpc"])
3233
def setMeshPolygonsColor(self, params):
@@ -35,13 +36,9 @@ def setMeshPolygonsColor(self, params):
3536
self.mesh_polygons_schemas_dict["color"],
3637
self.mesh_polygons_prefix,
3738
)
38-
id, red, green, blue = (
39-
params["id"],
40-
params["color"]["r"],
41-
params["color"]["g"],
42-
params["color"]["b"],
43-
)
44-
self.SetColor(id, red, green, blue)
39+
params = schemas.Color.from_dict(params)
40+
color = params.color
41+
self.SetColor(params.id, color.r, color.g, color.b)
4542

4643
@exportRpc(
4744
mesh_polygons_prefix + mesh_polygons_schemas_dict["vertex_attribute"]["rpc"]
@@ -52,8 +49,8 @@ def setMeshPolygonsVertexAttribute(self, params):
5249
self.mesh_polygons_schemas_dict["vertex_attribute"],
5350
self.mesh_polygons_prefix,
5451
)
55-
id, name = params["id"], params["name"]
56-
self.displayAttributeOnVertices(id, name)
52+
params = schemas.Color.from_dict(params)
53+
self.displayAttributeOnVertices(params.id, params.name)
5754

5855
@exportRpc(
5956
mesh_polygons_prefix + mesh_polygons_schemas_dict["polygon_attribute"]["rpc"]
@@ -64,5 +61,5 @@ def setMeshPolygonsPolygonAttribute(self, params):
6461
self.mesh_polygons_schemas_dict["polygon_attribute"],
6562
self.mesh_polygons_prefix,
6663
)
67-
id, name = params["id"], params["name"]
68-
self.displayAttributeOnCells(id, name)
64+
params = schemas.Color.from_dict(params)
65+
self.displayAttributeOnCells(params.id, params.name)

src/opengeodeweb_viewer/rpc/mesh/polyhedra/polyhedra_protocols.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Local application imports
88
from opengeodeweb_viewer.utils_functions import get_schemas_dict, validate_schema
99
from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView
10+
from . import schemas
1011

1112

1213
class VtkMeshPolyhedraView(VtkMeshView):
@@ -25,8 +26,8 @@ def setMeshPolyhedraVisibility(self, params):
2526
self.mesh_polyhedra_schemas_dict["visibility"],
2627
self.mesh_polyhedra_prefix,
2728
)
28-
id, visibility = params["id"], params["visibility"]
29-
self.SetVisibility(id, visibility)
29+
params = schemas.Visibility.from_dict(params)
30+
self.SetVisibility(params.id, params.visibility)
3031

3132
@exportRpc(mesh_polyhedra_prefix + mesh_polyhedra_schemas_dict["color"]["rpc"])
3233
def setMeshPolyhedraColor(self, params):
@@ -35,13 +36,9 @@ def setMeshPolyhedraColor(self, params):
3536
self.mesh_polyhedra_schemas_dict["color"],
3637
self.mesh_polyhedra_prefix,
3738
)
38-
id, red, green, blue = (
39-
params["id"],
40-
params["color"]["r"],
41-
params["color"]["g"],
42-
params["color"]["b"],
43-
)
44-
self.SetColor(id, red, green, blue)
39+
params = schemas.Color.from_dict(params)
40+
color = params.color
41+
self.SetColor(params.id, color.r, color.g, color.b)
4542

4643
@exportRpc(
4744
mesh_polyhedra_prefix + mesh_polyhedra_schemas_dict["vertex_attribute"]["rpc"]
@@ -52,8 +49,8 @@ def setMeshPolyhedraVertexAttribute(self, params):
5249
self.mesh_polyhedra_schemas_dict["vertex_attribute"],
5350
self.mesh_polyhedra_prefix,
5451
)
55-
id, name = params["id"], params["name"]
56-
self.displayAttributeOnVertices(id, name)
52+
params = schemas.VertexAttribute.from_dict(params)
53+
self.displayAttributeOnVertices(params.id, params.name)
5754

5855
@exportRpc(
5956
mesh_polyhedra_prefix
@@ -65,5 +62,5 @@ def setMeshPolyhedraPolyhedronAttribute(self, params):
6562
self.mesh_polyhedra_schemas_dict["polyhedron_attribute"],
6663
self.mesh_polyhedra_prefix,
6764
)
68-
id, name = params["id"], params["name"]
69-
self.displayAttributeOnCells(id, name)
65+
params = schemas.Color.from_dict(params)
66+
self.displayAttributeOnCells(params.id, params.name)

src/opengeodeweb_viewer/rpc/mesh/schemas/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
from .register import *
33
from .opacity import *
44
from .deregister import *
5+
from .color import *
56
from .apply_textures import *

0 commit comments

Comments
 (0)