Skip to content

Commit af6aea4

Browse files
committed
feat(CollectionComponents): add collection_components to model_components
1 parent a078183 commit af6aea4

9 files changed

Lines changed: 46 additions & 14 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
],

src/opengeodeweb_back/geode_objects/geode_brep.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ 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+
7982
def inspect(self) -> og_inspector.BRepInspectionResult:
8083
return og_inspector.inspect_brep(self.brep)
8184

src/opengeodeweb_back/geode_objects/geode_model.py

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

2424
@abstractmethod
2525
def mesh_components(self) -> ComponentRegistry: ...
26+
27+
@abstractmethod
28+
def collection_components(self) -> ComponentRegistry: ...

src/opengeodeweb_back/geode_objects/geode_section.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ 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+
8184
def inspect(self) -> og_inspector.SectionInspectionResult:
8285
return og_inspector.inspect_section(self.section)
8386

src/opengeodeweb_back/routes/models/blueprint_models.py

Lines changed: 26 additions & 6 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")
@@ -54,4 +54,24 @@ def mesh_components() -> flask.Response:
5454
}
5555
mesh_components.append(mesh_component_object)
5656

57-
return flask.make_response({"mesh_components": mesh_components}, 200)
57+
model_collection_components = model.collection_components()
58+
collection_components = []
59+
for collection_component, ids in model_collection_components.items():
60+
component_type = collection_component.get()
61+
for id in ids:
62+
geode_id = id.string()
63+
collection_component_object = {
64+
"id": params.id,
65+
"geode_id": geode_id,
66+
"name": geode_id,
67+
"type": component_type,
68+
}
69+
collection_components.append(collection_component_object)
70+
71+
return flask.make_response(
72+
{
73+
"mesh_components": mesh_components,
74+
"collection_components": collection_components,
75+
},
76+
200,
77+
)
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: 5 additions & 2 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"]})
@@ -39,6 +39,9 @@ def test_mesh_components(client: FlaskClient) -> None:
3939
assert isinstance(mesh_component["viewer_id"], int)
4040
assert isinstance(mesh_component["name"], str)
4141
assert isinstance(mesh_component["type"], str)
42+
assert "collection_components" in response.get_json()
43+
collection_components = response.get_json()["collection_components"]
44+
assert isinstance(collection_components, list)
4245

4346

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

0 commit comments

Comments
 (0)