Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions opengeodeweb_back_schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
}
},
"models": {
"mesh_components": {
"$id": "opengeodeweb_back/models/mesh_components",
"route": "/mesh_components",
"model_components": {
"$id": "opengeodeweb_back/models/model_components",
"route": "/model_components",
"methods": [
"POST"
],
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ werkzeug==3.1.2
# flask
# flask-cors

opengeodeweb-microservice==1.*,>=1.0.14
12 changes: 12 additions & 0 deletions src/opengeodeweb_back/geode_objects/geode_brep.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ def save_light_viewable(self, filename_without_extension: str) -> str:
def mesh_components(self) -> ComponentRegistry:
return self.brep.mesh_components()

def collection_components(self) -> ComponentRegistry:
return self.brep.collection_components()

def boundaries(self, id: og.uuid) -> list[og.ComponentID]:
return self.brep.boundaries(id)

def internals(self, id: og.uuid) -> list[og.ComponentID]:
return self.brep.internals(id)

def items(self, id: og.uuid) -> list[og.ComponentID]:
return self.brep.items(id)

def inspect(self) -> og_inspector.BRepInspectionResult:
return og_inspector.inspect_brep(self.brep)

Expand Down
12 changes: 12 additions & 0 deletions src/opengeodeweb_back/geode_objects/geode_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@ def viewer_elements_type(cls) -> ViewerElementsType:

@abstractmethod
def mesh_components(self) -> ComponentRegistry: ...

@abstractmethod
def collection_components(self) -> ComponentRegistry: ...

@abstractmethod
def boundaries(self, id: og.uuid) -> list[og.ComponentID]: ...

@abstractmethod
def internals(self, id: og.uuid) -> list[og.ComponentID]: ...

@abstractmethod
def items(self, id: og.uuid) -> list[og.ComponentID]: ...
12 changes: 12 additions & 0 deletions src/opengeodeweb_back/geode_objects/geode_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ def save_light_viewable(self, filename_without_extension: str) -> str:
def mesh_components(self) -> ComponentRegistry:
return self.section.mesh_components()

def collection_components(self) -> ComponentRegistry:
return self.section.collection_components()

def boundaries(self, id: og.uuid) -> list[og.ComponentID]:
return self.section.boundaries(id)

def internals(self, id: og.uuid) -> list[og.ComponentID]:
return self.section.internals(id)

def items(self, id: og.uuid) -> list[og.ComponentID]:
return self.section.items(id)

def inspect(self) -> og_inspector.SectionInspectionResult:
return og_inspector.inspect_section(self.section)

Expand Down
42 changes: 34 additions & 8 deletions src/opengeodeweb_back/routes/models/blueprint_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@


@routes.route(
schemas_dict["mesh_components"]["route"],
methods=schemas_dict["mesh_components"]["methods"],
schemas_dict["model_components"]["route"],
methods=schemas_dict["model_components"]["methods"],
)
def mesh_components() -> flask.Response:
def model_components() -> flask.Response:
json_data = utils_functions.validate_request(
flask.request, schemas_dict["mesh_components"]
flask.request, schemas_dict["model_components"]
)
params = schemas.MeshComponents.from_dict(json_data)
params = schemas.ModelComponents.from_dict(json_data)
model = geode_functions.load_geode_object(params.id)
if not isinstance(model, GeodeModel):
flask.abort(400, f"{params.id} is not a GeodeModel")
Expand All @@ -44,14 +44,40 @@ def mesh_components() -> flask.Response:
geode_id = id.string()
component_name = geode_id
viewer_id = uuid_to_flat_index[geode_id]

boundaries = model.boundaries(id)
boundaries_uuid = [boundary.id().string() for boundary in boundaries]
internals = model.internals(id)
internals_uuid = [internal.id().string() for internal in internals]
mesh_component_object = {
"id": params.id,
"viewer_id": viewer_id,
"geode_id": geode_id,
"name": component_name,
"type": component_type,
"boundaries": boundaries_uuid,
"internals": internals_uuid,
}
mesh_components.append(mesh_component_object)

return flask.make_response({"mesh_components": mesh_components}, 200)
model_collection_components = model.collection_components()
collection_components = []
for collection_component, ids in model_collection_components.items():
component_type = collection_component.get()
for id in ids:
geode_id = id.string()
items = model.items(id)
items_uuid = [item.id().string() for item in items]
collection_component_object = {
"geode_id": geode_id,
"name": geode_id,
"type": component_type,
"items": items_uuid,
}
collection_components.append(collection_component_object)

return flask.make_response(
{
"mesh_components": mesh_components,
"collection_components": collection_components,
},
200,
)
2 changes: 1 addition & 1 deletion src/opengeodeweb_back/routes/models/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .mesh_components import *
from .model_components import *
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"route": "/mesh_components",
"route": "/model_components",
"methods": [
"POST"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


@dataclass
class MeshComponents(DataClassJsonMixin):
class ModelComponents(DataClassJsonMixin):
def __post_init__(self) -> None:
print(self, flush=True)

Expand Down
21 changes: 18 additions & 3 deletions tests/test_models_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
data_dir = os.path.join(base_dir, "data")


def test_mesh_components(client: FlaskClient) -> None:
def test_model_components(client: FlaskClient) -> None:
geode_object_type = "BRep"
filename = "cube.og_brep"
response = test_save_viewable_file(client, geode_object_type, filename)

route = "/opengeodeweb_back/models/mesh_components"
route = "/opengeodeweb_back/models/model_components"
brep_filename = os.path.join(data_dir, "cube.og_brep")

response = client.post(route, json={"id": response.get_json()["id"]})
Expand All @@ -34,11 +34,26 @@ def test_mesh_components(client: FlaskClient) -> None:
assert len(mesh_components) > 0
for mesh_component in mesh_components:
assert isinstance(mesh_component, object)
assert isinstance(mesh_component["id"], str)
assert isinstance(mesh_component["geode_id"], str)
assert isinstance(mesh_component["viewer_id"], int)
assert isinstance(mesh_component["name"], str)
assert isinstance(mesh_component["type"], str)
assert isinstance(mesh_component["boundaries"], list)
for boundary_uuid in mesh_component["boundaries"]:
assert isinstance(boundary_uuid, str)
assert isinstance(mesh_component["internals"], list)
for internal_uuid in mesh_component["internals"]:
assert isinstance(internal_uuid, str)
assert "collection_components" in response.get_json()
collection_components = response.get_json()["collection_components"]
assert isinstance(collection_components, list)
for collection_component in collection_components:
assert isinstance(collection_component, object)
assert isinstance(collection_component["geode_id"], str)
assert isinstance(collection_component["name"], str)
assert isinstance(collection_component["items"], list)
for item_uuid in collection_component["items"]:
assert isinstance(item_uuid, str)


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