Skip to content

Commit ef2e68c

Browse files
cell attributes & tests
1 parent f420217 commit ef2e68c

File tree

11 files changed

+68
-33
lines changed

11 files changed

+68
-33
lines changed

src/opengeodeweb_back/app.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ def teardown_request(exception: BaseException | None) -> None:
7272

7373

7474
@app.errorhandler(HTTPException)
75-
def errorhandler(e: HTTPException) -> tuple[dict[str, Any], int] | Response:
76-
return utils_functions.handle_exception(e)
75+
def errorhandler(exception: HTTPException) -> tuple[dict[str, Any], int] | Response:
76+
return utils_functions.handle_exception(exception)
7777

7878

7979
@app.errorhandler(Exception)
80-
def handle_generic_exception(e: Exception) -> Response:
81-
print("handle_generic_exception:", str(e), flush=True)
82-
return flask.make_response({"error": str(e)}, 500)
80+
def handle_generic_exception(exception: Exception) -> Response:
81+
print("\033[91mError:\033[0m \033[91m" + str(exception) + "\033[0m", flush=True)
82+
return flask.make_response({"description": str(exception)}, 500)
8383

8484

8585
@app.route(

src/opengeodeweb_back/geode_objects/__init__.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
# Standard library imports
22
from __future__ import annotations
3-
from abc import ABC, abstractmethod
4-
from typing import Literal, Any, get_args, cast
53

64
# Third party imports
7-
import opengeode as og
8-
import opengeode_io as og_io
9-
import opengeode_inspector as og_inspector
10-
import opengeode_geosciences as og_gs
11-
import opengeode_geosciencesio as og_gs_io
12-
import geode_viewables as viewables
135

146
# Local application imports
15-
from .types import GeodeObjectType, GeodeMeshType, GeodeModelType
7+
from .types import GeodeObjectType
168
from .geode_object import GeodeObject
17-
from .geode_model import GeodeModel
18-
from .geode_mesh import GeodeMesh
199
from .geode_brep import GeodeBRep
2010
from .geode_vertex_set import GeodeVertexSet
2111
from .geode_graph import GeodeGraph
@@ -29,11 +19,11 @@
2919
from .geode_polygonal_surface3d import GeodePolygonalSurface3D
3020
from .geode_triangulated_surface2d import GeodeTriangulatedSurface2D
3121
from .geode_triangulated_surface3d import GeodeTriangulatedSurface3D
32-
from .geode_regulard_grid2d import GeodeRegularGrid2D
22+
from .geode_regular_grid2d import GeodeRegularGrid2D
3323
from .geode_polyhedral_solid3d import GeodePolyhedralSolid3D
3424
from .geode_tetrahedral_solid3d import GeodeTetrahedralSolid3D
3525
from .geode_hybrid_solid3d import GeodeHybridSolid3D
36-
from .geode_regulard_grid3d import GeodeRegularGrid3D
26+
from .geode_regular_grid3d import GeodeRegularGrid3D
3727
from .geode_light_regular_grid2d import GeodeLightRegularGrid2D
3828
from .geode_light_regular_grid3d import GeodeLightRegularGrid3D
3929
from .geode_section import GeodeSection

src/opengeodeweb_back/geode_objects/geode_grid2d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ def is_3D(cls) -> bool:
2020
def is_viewable(cls) -> bool:
2121
return True
2222

23-
def builder(self) -> None:
23+
def builder(self) -> object:
2424
return None
2525

26-
def inspect(self) -> None:
26+
def inspect(self) -> object:
2727
return None
2828

2929
@abstractmethod

src/opengeodeweb_back/geode_objects/geode_grid3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ def is_3D(cls) -> bool:
2020
def is_viewable(cls) -> bool:
2121
return True
2222

23-
def builder(self) -> None:
23+
def builder(self) -> object:
2424
return None
2525

26-
def inspect(self) -> None:
26+
def inspect(self) -> object:
2727
return None
2828

2929
@abstractmethod

src/opengeodeweb_back/geode_objects/geode_regulard_grid2d.py renamed to src/opengeodeweb_back/geode_objects/geode_regular_grid2d.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .geode_grid2d import GeodeGrid2D
1313

1414

15-
class GeodeRegularGrid2D(GeodeSurfaceMesh2D):
15+
class GeodeRegularGrid2D(GeodeSurfaceMesh2D, GeodeGrid2D):
1616
regular_grid: og.RegularGrid2D
1717

1818
def __init__(self, regular_grid: og.RegularGrid2D | None = None) -> None:
@@ -24,6 +24,9 @@ def __init__(self, regular_grid: og.RegularGrid2D | None = None) -> None:
2424
@classmethod
2525
def geode_object_type(cls) -> GeodeMeshType:
2626
return "RegularGrid2D"
27+
28+
def inspect(self) -> og_inspector.SurfaceInspectionResult:
29+
return super().inspect()
2730

2831
def native_extension(self) -> str:
2932
return self.regular_grid.native_extension()
@@ -70,3 +73,7 @@ def save_light_viewable(self, filename_without_extension: str) -> str:
7073
return viewables.save_light_viewable_regular_grid2D(
7174
self.regular_grid, filename_without_extension
7275
)
76+
77+
def cell_attribute_manager(self) -> og.AttributeManager:
78+
return self.regular_grid.cell_attribute_manager()
79+

src/opengeodeweb_back/geode_objects/geode_regulard_grid3d.py renamed to src/opengeodeweb_back/geode_objects/geode_regular_grid3d.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
# Local application imports
1010
from .types import GeodeMeshType
1111
from .geode_solid_mesh3d import GeodeSolidMesh3D
12+
from .geode_grid3d import GeodeGrid3D
1213

1314

14-
class GeodeRegularGrid3D(GeodeSolidMesh3D):
15+
class GeodeRegularGrid3D(GeodeSolidMesh3D, GeodeGrid3D):
1516
regular_grid: og.RegularGrid3D
1617

1718
def __init__(self, regular_grid: og.RegularGrid3D | None = None) -> None:
@@ -69,3 +70,9 @@ def save_light_viewable(self, filename_without_extension: str) -> str:
6970
return viewables.save_light_viewable_regular_grid3D(
7071
self.regular_grid, filename_without_extension
7172
)
73+
74+
def cell_attribute_manager(self) -> og.AttributeManager:
75+
return self.regular_grid.cell_attribute_manager()
76+
77+
def inspect(self) -> og_inspector.SolidInspectionResult:
78+
return super().inspect()

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def texture_coordinates() -> flask.Response:
254254
params = schemas.TextureCoordinates.from_dict(json_data)
255255
geode_object = geode_functions.load_geode_object(params.id)
256256
if not isinstance(geode_object, GeodeSurfaceMesh2D | GeodeSurfaceMesh3D):
257-
flask.abort(500, f"{params.id} is not a GeodeSurfaceMesh")
257+
flask.abort(400, f"{params.id} is not a GeodeSurfaceMesh")
258258
texture_coordinates = geode_object.texture_manager().texture_names()
259259
return flask.make_response({"texture_coordinates": texture_coordinates}, 200)
260260

@@ -270,7 +270,7 @@ def vertex_attribute_names() -> flask.Response:
270270
params = schemas.VertexAttributeNames.from_dict(json_data)
271271
geode_object = geode_functions.load_geode_object(params.id)
272272
if not isinstance(geode_object, GeodeMesh):
273-
flask.abort(500, f"{params.id} is not a GeodeMesh")
273+
flask.abort(400, f"{params.id} is not a GeodeMesh")
274274
vertex_attribute_names = geode_object.vertex_attribute_manager().attribute_names()
275275
return flask.make_response(
276276
{
@@ -290,7 +290,7 @@ def cell_attribute_names() -> flask.Response:
290290
params = schemas.PolygonAttributeNames.from_dict(json_data)
291291
geode_object = geode_functions.load_geode_object(params.id)
292292
if not isinstance(geode_object, GeodeGrid2D | GeodeGrid3D):
293-
flask.abort(500, f"{params.id} is not a GeodeGrid")
293+
flask.abort(400, f"{params.id} is not a GeodeGrid")
294294
cell_attribute_names = geode_object.cell_attribute_manager().attribute_names()
295295
return flask.make_response(
296296
{
@@ -310,7 +310,7 @@ def polygon_attribute_names() -> flask.Response:
310310
params = schemas.PolygonAttributeNames.from_dict(json_data)
311311
geode_object = geode_functions.load_geode_object(params.id)
312312
if not isinstance(geode_object, GeodeSurfaceMesh2D | GeodeSurfaceMesh3D):
313-
flask.abort(500, f"{params.id} is not a GeodeSurfaceMesh")
313+
flask.abort(400, f"{params.id} is not a GeodeSurfaceMesh")
314314
polygon_attribute_names = geode_object.polygon_attribute_manager().attribute_names()
315315
return flask.make_response(
316316
{
@@ -331,7 +331,7 @@ def polyhedron_attribute_names() -> flask.Response:
331331
params = schemas.PolyhedronAttributeNames.from_dict(json_data)
332332
geode_object = geode_functions.load_geode_object(params.id)
333333
if not isinstance(geode_object, GeodeSolidMesh3D):
334-
flask.abort(500, f"{params.id} is not a GeodeSolidMesh")
334+
flask.abort(400, f"{params.id} is not a GeodeSolidMesh")
335335
polyhedron_attribute_names = (
336336
geode_object.polyhedron_attribute_manager().attribute_names()
337337
)

src/opengeodeweb_back/routes/create/blueprint_create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ def create_voi() -> flask.Response:
8282

8383
aoi_data = geode_functions.get_data_info(params.aoi_id)
8484
if not aoi_data:
85-
flask.abort(500, f"AOI with id {params.aoi_id} not found")
85+
flask.abort(404, f"AOI with id {params.aoi_id} not found")
8686

8787
aoi_object = geode_functions.load_geode_object(params.aoi_id)
8888
if not isinstance(aoi_object, GeodeEdgedCurve3D):
89-
flask.abort(500, f"AOI with id {params.aoi_id} not a GeodeEdgedCurve3D")
89+
flask.abort(400, f"AOI with id {params.aoi_id} is not a GeodeEdgedCurve3D")
9090

9191
aoi_curve = aoi_object.edged_curve
9292
nb_points = aoi_curve.nb_vertices()

src/opengeodeweb_back/routes/models/blueprint_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def uuid_to_flat_index() -> flask.Response:
2424
tree = ET.parse(vtm_file_path)
2525
root = tree.find("vtkMultiBlockDataSet")
2626
if root is None:
27-
raise Exception("Failed to read viewable file")
27+
flask.abort(500, "Failed to read viewable file")
2828
uuid_to_flat_index = {}
2929
current_index = 0
3030
for elem in root.iter():
@@ -45,7 +45,7 @@ def extract_uuids_endpoint() -> flask.Response:
4545
params = schemas.MeshComponents.from_dict(json_data)
4646
model = geode_functions.load_geode_object(params.id)
4747
if not isinstance(model, GeodeModel):
48-
flask.abort(500, f"{params.id} is not a GeodeModel")
48+
flask.abort(400, f"{params.id} is not a GeodeModel")
4949
mesh_components = model.mesh_components()
5050
uuid_dict = {}
5151
for mesh_component, ids in mesh_components.items():

src/opengeodeweb_back/utils_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def send_file(
164164

165165

166166
def handle_exception(exception: HTTPException) -> flask.Response:
167+
print("\033[91mError:\033[0m \033[91m" + str(exception) + "\033[0m", flush=True)
167168
response = flask.jsonify(
168169
{
169170
"code": exception.code,

0 commit comments

Comments
 (0)