Skip to content

Commit 01bd424

Browse files
authored
Merge pull request #220 from Geode-solutions/fix/collection_components
Fix/collection components
2 parents b626d17 + 04f0e79 commit 01bd424

10 files changed

Lines changed: 94 additions & 18 deletions

File tree

opengeodeweb_back_schemas.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
}
3434
},
3535
"models": {
36-
"mesh_components": {
37-
"$id": "opengeodeweb_back/models/mesh_components",
38-
"route": "/mesh_components",
36+
"model_components": {
37+
"$id": "opengeodeweb_back/models/model_components",
38+
"route": "/model_components",
3939
"methods": [
4040
"POST"
4141
],

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ werkzeug==3.1.2
6060
# flask
6161
# flask-cors
6262

63-
opengeodeweb-microservice==1.*,>=1.0.14

src/opengeodeweb_back/geode_objects/geode_brep.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ def save_light_viewable(self, filename_without_extension: str) -> str:
7676
def mesh_components(self) -> ComponentRegistry:
7777
return self.brep.mesh_components()
7878

79+
def collection_components(self) -> ComponentRegistry:
80+
return self.brep.collection_components()
81+
82+
def boundaries(self, id: og.uuid) -> list[og.ComponentID]:
83+
return self.brep.boundaries(id)
84+
85+
def internals(self, id: og.uuid) -> list[og.ComponentID]:
86+
return self.brep.internals(id)
87+
88+
def items(self, id: og.uuid) -> list[og.ComponentID]:
89+
return self.brep.items(id)
90+
7991
def inspect(self) -> og_inspector.BRepInspectionResult:
8092
return og_inspector.inspect_brep(self.brep)
8193

src/opengeodeweb_back/geode_objects/geode_model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,15 @@ def viewer_elements_type(cls) -> ViewerElementsType:
2323

2424
@abstractmethod
2525
def mesh_components(self) -> ComponentRegistry: ...
26+
27+
@abstractmethod
28+
def collection_components(self) -> ComponentRegistry: ...
29+
30+
@abstractmethod
31+
def boundaries(self, id: og.uuid) -> list[og.ComponentID]: ...
32+
33+
@abstractmethod
34+
def internals(self, id: og.uuid) -> list[og.ComponentID]: ...
35+
36+
@abstractmethod
37+
def items(self, id: og.uuid) -> list[og.ComponentID]: ...

src/opengeodeweb_back/geode_objects/geode_section.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ def save_light_viewable(self, filename_without_extension: str) -> str:
7878
def mesh_components(self) -> ComponentRegistry:
7979
return self.section.mesh_components()
8080

81+
def collection_components(self) -> ComponentRegistry:
82+
return self.section.collection_components()
83+
84+
def boundaries(self, id: og.uuid) -> list[og.ComponentID]:
85+
return self.section.boundaries(id)
86+
87+
def internals(self, id: og.uuid) -> list[og.ComponentID]:
88+
return self.section.internals(id)
89+
90+
def items(self, id: og.uuid) -> list[og.ComponentID]:
91+
return self.section.items(id)
92+
8193
def inspect(self) -> og_inspector.SectionInspectionResult:
8294
return og_inspector.inspect_section(self.section)
8395

src/opengeodeweb_back/routes/models/blueprint_models.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313

1414
@routes.route(
15-
schemas_dict["mesh_components"]["route"],
16-
methods=schemas_dict["mesh_components"]["methods"],
15+
schemas_dict["model_components"]["route"],
16+
methods=schemas_dict["model_components"]["methods"],
1717
)
18-
def mesh_components() -> flask.Response:
18+
def model_components() -> flask.Response:
1919
json_data = utils_functions.validate_request(
20-
flask.request, schemas_dict["mesh_components"]
20+
flask.request, schemas_dict["model_components"]
2121
)
22-
params = schemas.MeshComponents.from_dict(json_data)
22+
params = schemas.ModelComponents.from_dict(json_data)
2323
model = geode_functions.load_geode_object(params.id)
2424
if not isinstance(model, GeodeModel):
2525
flask.abort(400, f"{params.id} is not a GeodeModel")
@@ -44,14 +44,40 @@ def mesh_components() -> flask.Response:
4444
geode_id = id.string()
4545
component_name = geode_id
4646
viewer_id = uuid_to_flat_index[geode_id]
47-
47+
boundaries = model.boundaries(id)
48+
boundaries_uuid = [boundary.id().string() for boundary in boundaries]
49+
internals = model.internals(id)
50+
internals_uuid = [internal.id().string() for internal in internals]
4851
mesh_component_object = {
49-
"id": params.id,
5052
"viewer_id": viewer_id,
5153
"geode_id": geode_id,
5254
"name": component_name,
5355
"type": component_type,
56+
"boundaries": boundaries_uuid,
57+
"internals": internals_uuid,
5458
}
5559
mesh_components.append(mesh_component_object)
5660

57-
return flask.make_response({"mesh_components": mesh_components}, 200)
61+
model_collection_components = model.collection_components()
62+
collection_components = []
63+
for collection_component, ids in model_collection_components.items():
64+
component_type = collection_component.get()
65+
for id in ids:
66+
geode_id = id.string()
67+
items = model.items(id)
68+
items_uuid = [item.id().string() for item in items]
69+
collection_component_object = {
70+
"geode_id": geode_id,
71+
"name": geode_id,
72+
"type": component_type,
73+
"items": items_uuid,
74+
}
75+
collection_components.append(collection_component_object)
76+
77+
return flask.make_response(
78+
{
79+
"mesh_components": mesh_components,
80+
"collection_components": collection_components,
81+
},
82+
200,
83+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .mesh_components import *
1+
from .model_components import *

src/opengeodeweb_back/routes/models/schemas/mesh_components.json renamed to src/opengeodeweb_back/routes/models/schemas/model_components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"route": "/mesh_components",
2+
"route": "/model_components",
33
"methods": [
44
"POST"
55
],

src/opengeodeweb_back/routes/models/schemas/mesh_components.py renamed to src/opengeodeweb_back/routes/models/schemas/model_components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
@dataclass
6-
class MeshComponents(DataClassJsonMixin):
6+
class ModelComponents(DataClassJsonMixin):
77
def __post_init__(self) -> None:
88
print(self, flush=True)
99

tests/test_models_routes.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
data_dir = os.path.join(base_dir, "data")
1919

2020

21-
def test_mesh_components(client: FlaskClient) -> None:
21+
def test_model_components(client: FlaskClient) -> None:
2222
geode_object_type = "BRep"
2323
filename = "cube.og_brep"
2424
response = test_save_viewable_file(client, geode_object_type, filename)
2525

26-
route = "/opengeodeweb_back/models/mesh_components"
26+
route = "/opengeodeweb_back/models/model_components"
2727
brep_filename = os.path.join(data_dir, "cube.og_brep")
2828

2929
response = client.post(route, json={"id": response.get_json()["id"]})
@@ -34,11 +34,26 @@ def test_mesh_components(client: FlaskClient) -> None:
3434
assert len(mesh_components) > 0
3535
for mesh_component in mesh_components:
3636
assert isinstance(mesh_component, object)
37-
assert isinstance(mesh_component["id"], str)
3837
assert isinstance(mesh_component["geode_id"], str)
3938
assert isinstance(mesh_component["viewer_id"], int)
4039
assert isinstance(mesh_component["name"], str)
4140
assert isinstance(mesh_component["type"], str)
41+
assert isinstance(mesh_component["boundaries"], list)
42+
for boundary_uuid in mesh_component["boundaries"]:
43+
assert isinstance(boundary_uuid, str)
44+
assert isinstance(mesh_component["internals"], list)
45+
for internal_uuid in mesh_component["internals"]:
46+
assert isinstance(internal_uuid, str)
47+
assert "collection_components" in response.get_json()
48+
collection_components = response.get_json()["collection_components"]
49+
assert isinstance(collection_components, list)
50+
for collection_component in collection_components:
51+
assert isinstance(collection_component, object)
52+
assert isinstance(collection_component["geode_id"], str)
53+
assert isinstance(collection_component["name"], str)
54+
assert isinstance(collection_component["items"], list)
55+
for item_uuid in collection_component["items"]:
56+
assert isinstance(item_uuid, str)
4257

4358

4459
def test_export_project_route(client: FlaskClient, tmp_path: Path) -> None:

0 commit comments

Comments
 (0)