Skip to content

Commit 5a47786

Browse files
committed
test and adds a visibility_component rpc
1 parent 42b7ab8 commit 5a47786

8 files changed

Lines changed: 91 additions & 12 deletions

File tree

src/opengeodeweb_viewer/rpc/model/model_protocols.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,13 @@ def setModelComponentsColor(self, rpc_params: RpcParams) -> None:
9090
params = schemas.ComponentsColor.from_dict(rpc_params)
9191
color = params.color
9292
self.SetBlocksColor(params.id, params.block_ids, color.r, color.g, color.b)
93+
94+
@exportRpc(model_prefix + model_schemas_dict["components_visibility"]["rpc"])
95+
def setModelComponentsVisibility(self, rpc_params: RpcParams) -> None:
96+
validate_schema(
97+
rpc_params,
98+
self.model_schemas_dict["components_visibility"],
99+
self.model_prefix,
100+
)
101+
params = schemas.ComponentsVisibility.from_dict(rpc_params)
102+
self.SetBlocksVisibility(params.id, params.block_ids, params.visibility)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
from .register import *
33
from .deregister import *
44
from .components_color import *
5+
from .components_visibility import *
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
from dataclasses_json import DataClassJsonMixin
12
from dataclasses import dataclass
2-
from opengeodeweb_microservice.schemas import Color
3+
from typing import Optional, List
34

45

56
@dataclass
6-
class ComponentsColor:
7-
id: str
8-
block_ids: list[int]
9-
color: Color
7+
class ColorClass(DataClassJsonMixin):
8+
b: int
9+
g: int
10+
r: int
11+
a: Optional[float] = None
12+
1013

11-
@classmethod
12-
def from_dict(cls, data: dict) -> "ComponentsColor":
13-
return cls(
14-
id=data["id"],
15-
block_ids=data["block_ids"],
16-
color=Color(**data["color"]),
17-
)
14+
@dataclass
15+
class ComponentsColor(DataClassJsonMixin):
16+
block_ids: List[int]
17+
color: ColorClass
18+
id: str
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"rpc": "components_visibility",
3+
"type": "object",
4+
"properties": {
5+
"id": {
6+
"type": "string",
7+
"minLength": 1
8+
},
9+
"block_ids": {
10+
"type": "array",
11+
"items": {
12+
"type": "integer"
13+
},
14+
"minItems": 1
15+
},
16+
"visibility": {
17+
"type": "boolean"
18+
}
19+
},
20+
"required": [
21+
"id",
22+
"block_ids",
23+
"visibility"
24+
],
25+
"additionalProperties": false
26+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from dataclasses_json import DataClassJsonMixin
2+
from dataclasses import dataclass
3+
from typing import List
4+
5+
6+
@dataclass
7+
class ComponentsVisibility(DataClassJsonMixin):
8+
block_ids: List[int]
9+
id: str
10+
visibility: bool
3.99 KB
Loading
4.11 KB
Loading

tests/model/test_model_protocols.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,34 @@ def test_deregister_model(
5353
[{"id": "123456789"}],
5454
)
5555
assert server.compare_image("model/deregister.jpeg") == True
56+
57+
58+
def test_components_color_model(
59+
server: ServerMonitor, dataset_factory: Callable[..., str]
60+
) -> None:
61+
62+
test_register_model_cube(server, dataset_factory)
63+
64+
server.call(
65+
VtkModelView.model_prefix
66+
+ VtkModelView.model_schemas_dict["components_color"]["rpc"],
67+
[{"id": "123456789", "block_ids": [48, 49], "color": {"r": 255, "g": 0, "b": 0}}],
68+
)
69+
assert server.compare_image("model/components_color.jpeg") == True
70+
71+
72+
def test_components_visibility_color_model(
73+
server: ServerMonitor, dataset_factory: Callable[..., str]
74+
) -> None:
75+
test_register_model_cube(server, dataset_factory)
76+
77+
server.call(
78+
VtkModelView.model_prefix + "components_visibility",
79+
[{"id": "123456789", "block_ids": [48, 49], "visibility": False}],
80+
)
81+
82+
server.call(
83+
VtkModelView.model_prefix + "components_color",
84+
[{"id": "123456789", "block_ids": list(range(36, 47)), "color": {"r": 0, "g": 255, "b": 0}}],
85+
)
86+
assert server.compare_image("model/components_visibility_color.jpeg") == True

0 commit comments

Comments
 (0)