Skip to content

Commit 87534ba

Browse files
wip cells protocols
1 parent 8763525 commit 87534ba

File tree

12 files changed

+343
-0
lines changed

12 files changed

+343
-0
lines changed

opengeodeweb_viewer_schemas.json

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,115 @@
3333
}
3434
},
3535
"mesh": {
36+
"cells": {
37+
"visibility": {
38+
"$id": "opengeodeweb_viewer.mesh.cells.visibility",
39+
"rpc": "visibility",
40+
"type": "object",
41+
"properties": {
42+
"id": {
43+
"type": "string",
44+
"minLength": 1
45+
},
46+
"visibility": {
47+
"type": "boolean"
48+
}
49+
},
50+
"required": [
51+
"id",
52+
"visibility"
53+
],
54+
"additionalProperties": false
55+
},
56+
"vertex_attribute": {
57+
"$id": "opengeodeweb_viewer.mesh.cells.vertex_attribute",
58+
"rpc": "vertex_attribute",
59+
"type": "object",
60+
"properties": {
61+
"id": {
62+
"type": "string",
63+
"minLength": 1
64+
},
65+
"name": {
66+
"type": "string",
67+
"minLength": 1
68+
}
69+
},
70+
"required": [
71+
"id",
72+
"name"
73+
],
74+
"additionalProperties": false
75+
},
76+
"color": {
77+
"$id": "opengeodeweb_viewer.mesh.cells.color",
78+
"rpc": "color",
79+
"type": "object",
80+
"properties": {
81+
"id": {
82+
"type": "string",
83+
"minLength": 1
84+
},
85+
"color": {
86+
"type": "object",
87+
"properties": {
88+
"r": {
89+
"type": "integer",
90+
"minimum": 0,
91+
"maximum": 255
92+
},
93+
"g": {
94+
"type": "integer",
95+
"minimum": 0,
96+
"maximum": 255
97+
},
98+
"b": {
99+
"type": "integer",
100+
"minimum": 0,
101+
"maximum": 255
102+
},
103+
"a": {
104+
"type": "number",
105+
"minimum": 0,
106+
"maximum": 1,
107+
"default": 1
108+
}
109+
},
110+
"required": [
111+
"r",
112+
"g",
113+
"b"
114+
],
115+
"additionalProperties": false
116+
}
117+
},
118+
"required": [
119+
"id",
120+
"color"
121+
],
122+
"additionalProperties": false
123+
},
124+
"cell_attribute": {
125+
"$id": "opengeodeweb_viewer.mesh.cells.polygon_attribute",
126+
"rpc": "polygon_attribute",
127+
"type": "object",
128+
"properties": {
129+
"id": {
130+
"type": "string",
131+
"minLength": 1
132+
},
133+
"name": {
134+
"type": "string",
135+
"minLength": 1
136+
}
137+
},
138+
"required": [
139+
"id",
140+
"name"
141+
],
142+
"additionalProperties": false
143+
}
144+
},
36145
"edges": {
37146
"width": {
38147
"$id": "opengeodeweb_viewer.mesh.edges.size",
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Standard library imports
2+
import os
3+
4+
# Third party imports
5+
from wslink import register as exportRpc # type: ignore
6+
from opengeodeweb_microservice.schemas import get_schemas_dict
7+
8+
# Local application imports
9+
from opengeodeweb_viewer.utils_functions import (
10+
validate_schema,
11+
RpcParams,
12+
)
13+
from opengeodeweb_viewer.rpc.mesh.mesh_protocols import VtkMeshView
14+
from . import schemas
15+
16+
17+
class VtkMeshCellsView(VtkMeshView):
18+
mesh_cells_prefix = "opengeodeweb_viewer.mesh.cells."
19+
mesh_cells_schemas_dict = get_schemas_dict(
20+
os.path.join(os.path.dirname(__file__), "schemas")
21+
)
22+
23+
def __init__(self):
24+
super().__init__()
25+
26+
@exportRpc(mesh_cells_prefix + mesh_cells_schemas_dict["visibility"]["rpc"])
27+
def setMeshCellsVisibility(self, rpc_params: RpcParams) -> None:
28+
validate_schema(
29+
rpc_params,
30+
self.mesh_cells_schemas_dict["visibility"],
31+
self.mesh_cells_prefix,
32+
)
33+
params = schemas.Visibility.from_dict(rpc_params)
34+
self.SetVisibility(params.id, params.visibility)
35+
36+
@exportRpc(mesh_cells_prefix + mesh_cells_schemas_dict["color"]["rpc"])
37+
def setMeshCellsColor(self, rpc_params: RpcParams) -> None:
38+
validate_schema(
39+
rpc_params,
40+
self.mesh_cells_schemas_dict["color"],
41+
self.mesh_cells_prefix,
42+
)
43+
params = schemas.Color.from_dict(rpc_params)
44+
color = params.color
45+
self.SetColor(params.id, color.r, color.g, color.b)
46+
47+
@exportRpc(
48+
mesh_cells_prefix + mesh_cells_schemas_dict["vertex_attribute"]["rpc"]
49+
)
50+
def setMeshCellsVertexAttribute(self, rpc_params: RpcParams) -> None:
51+
validate_schema(
52+
rpc_params,
53+
self.mesh_cells_schemas_dict["vertex_attribute"],
54+
self.mesh_cells_prefix,
55+
)
56+
params = schemas.VertexAttribute.from_dict(rpc_params)
57+
self.displayAttributeOnVertices(params.id, params.name)
58+
59+
@exportRpc(
60+
mesh_cells_prefix + mesh_cells_schemas_dict["cell_attribute"]["rpc"]
61+
)
62+
def setMeshCellsCellAttribute(self, rpc_params: RpcParams) -> None:
63+
validate_schema(
64+
rpc_params,
65+
self.mesh_cells_schemas_dict["cell_attribute"],
66+
self.mesh_cells_prefix,
67+
)
68+
params = schemas.CellAttribute.from_dict(rpc_params)
69+
self.displayAttributeOnCells(params.id, params.name)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .visibility import *
2+
from .vertex_attribute import *
3+
from .color import *
4+
from .cell_attribute import *
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"rpc": "polygon_attribute",
3+
"type": "object",
4+
"properties": {
5+
"id": {
6+
"type": "string",
7+
"minLength": 1
8+
},
9+
"name": {
10+
"type": "string",
11+
"minLength": 1
12+
}
13+
},
14+
"required": [
15+
"id",
16+
"name"
17+
],
18+
"additionalProperties": false
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from dataclasses_json import DataClassJsonMixin
2+
from dataclasses import dataclass
3+
4+
5+
@dataclass
6+
class CellAttribute(DataClassJsonMixin):
7+
def __post_init__(self) -> None:
8+
print(self, flush=True)
9+
10+
id: str
11+
name: str
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"rpc": "color",
3+
"type": "object",
4+
"properties": {
5+
"id": {
6+
"type": "string",
7+
"minLength": 1
8+
},
9+
"color": {
10+
"type": "object",
11+
"properties": {
12+
"r": {
13+
"type": "integer",
14+
"minimum": 0,
15+
"maximum": 255
16+
},
17+
"g": {
18+
"type": "integer",
19+
"minimum": 0,
20+
"maximum": 255
21+
},
22+
"b": {
23+
"type": "integer",
24+
"minimum": 0,
25+
"maximum": 255
26+
},
27+
"a": {
28+
"type": "number",
29+
"minimum": 0,
30+
"maximum": 1,
31+
"default": 1
32+
}
33+
},
34+
"required": [
35+
"r",
36+
"g",
37+
"b"
38+
],
39+
"additionalProperties": false
40+
}
41+
},
42+
"required": [
43+
"id",
44+
"color"
45+
],
46+
"additionalProperties": false
47+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from dataclasses_json import DataClassJsonMixin
2+
from dataclasses import dataclass
3+
from typing import Optional
4+
5+
6+
@dataclass
7+
class ColorClass(DataClassJsonMixin):
8+
def __post_init__(self) -> None:
9+
print(self, flush=True)
10+
11+
b: int
12+
g: int
13+
r: int
14+
a: Optional[float] = None
15+
16+
17+
@dataclass
18+
class Color(DataClassJsonMixin):
19+
def __post_init__(self) -> None:
20+
print(self, flush=True)
21+
22+
color: ColorClass
23+
id: str
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"rpc": "vertex_attribute",
3+
"type": "object",
4+
"properties": {
5+
"id": {
6+
"type": "string",
7+
"minLength": 1
8+
},
9+
"name": {
10+
"type": "string",
11+
"minLength": 1
12+
}
13+
},
14+
"required": [
15+
"id",
16+
"name"
17+
],
18+
"additionalProperties": false
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from dataclasses_json import DataClassJsonMixin
2+
from dataclasses import dataclass
3+
4+
5+
@dataclass
6+
class VertexAttribute(DataClassJsonMixin):
7+
def __post_init__(self) -> None:
8+
print(self, flush=True)
9+
10+
id: str
11+
name: str
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"rpc": "visibility",
3+
"type": "object",
4+
"properties": {
5+
"id": {
6+
"type": "string",
7+
"minLength": 1
8+
},
9+
"visibility": {
10+
"type": "boolean"
11+
}
12+
},
13+
"required": [
14+
"id",
15+
"visibility"
16+
],
17+
"additionalProperties": false
18+
}

0 commit comments

Comments
 (0)