Skip to content

Commit 4d84dd1

Browse files
committed
wip
1 parent 31554d5 commit 4d84dd1

30 files changed

+365
-260
lines changed

opengeodeweb_back_schemas.json

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
],
214214
"type": "object",
215215
"properties": {
216-
"input_geode_object": {
216+
"geode_object_type": {
217217
"type": "string",
218218
"minLength": 1
219219
},
@@ -223,7 +223,7 @@
223223
}
224224
},
225225
"required": [
226-
"input_geode_object",
226+
"geode_object_type",
227227
"filename"
228228
],
229229
"additionalProperties": false
@@ -283,7 +283,7 @@
283283
],
284284
"type": "object",
285285
"properties": {
286-
"input_geode_object": {
286+
"geode_object_type": {
287287
"type": "string",
288288
"minLength": 1
289289
},
@@ -293,7 +293,7 @@
293293
}
294294
},
295295
"required": [
296-
"input_geode_object",
296+
"geode_object_type",
297297
"filename"
298298
],
299299
"additionalProperties": false
@@ -321,14 +321,14 @@
321321
"type": "string",
322322
"minLength": 1
323323
},
324-
"input_geode_object": {
324+
"geode_object_type": {
325325
"type": "string",
326326
"minLength": 1
327327
}
328328
},
329329
"required": [
330330
"filename",
331-
"input_geode_object"
331+
"geode_object_type"
332332
],
333333
"additionalProperties": false
334334
},
@@ -351,13 +351,13 @@
351351
],
352352
"type": "object",
353353
"properties": {
354-
"input_geode_object": {
354+
"geode_object_type": {
355355
"type": "string",
356356
"minLength": 1
357357
}
358358
},
359359
"required": [
360-
"input_geode_object"
360+
"geode_object_type"
361361
],
362362
"additionalProperties": false
363363
},
@@ -369,7 +369,7 @@
369369
],
370370
"type": "object",
371371
"properties": {
372-
"input_geode_object": {
372+
"geode_object_type": {
373373
"type": "string",
374374
"minLength": 1
375375
},
@@ -379,7 +379,7 @@
379379
}
380380
},
381381
"required": [
382-
"input_geode_object",
382+
"geode_object_type",
383383
"filename"
384384
],
385385
"additionalProperties": false
@@ -417,17 +417,10 @@
417417
"filename": {
418418
"type": "string",
419419
"minLength": 1
420-
},
421-
"supported_feature": {
422-
"type": [
423-
"string",
424-
"null"
425-
]
426420
}
427421
},
428422
"required": [
429-
"filename",
430-
"supported_feature"
423+
"filename"
431424
],
432425
"additionalProperties": false
433426
},
@@ -438,17 +431,8 @@
438431
"POST"
439432
],
440433
"type": "object",
441-
"properties": {
442-
"supported_feature": {
443-
"type": [
444-
"string",
445-
"null"
446-
]
447-
}
448-
},
449-
"required": [
450-
"supported_feature"
451-
],
434+
"properties": {},
435+
"required": [],
452436
"additionalProperties": false
453437
}
454438
}

src/opengeodeweb_back/geode_functions.py

Lines changed: 67 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,18 @@
99
from typing import Any
1010

1111
# Local application imports
12-
from .geode_objects import geode_objects
13-
from .geode_objects.geode_object import GeodeType, GeodeObject, to_geode_type
12+
from .geode_objects import geode_objects, geode_meshes, geode_models
13+
from .geode_objects.types import (
14+
GeodeObjectType,
15+
geode_object_type,
16+
GeodeMeshType,
17+
geode_mesh_type,
18+
GeodeModelType,
19+
geode_model_type,
20+
)
21+
from .geode_objects.geode_object import GeodeObject
22+
from .geode_objects.geode_mesh import GeodeMesh
23+
from .geode_objects.geode_model import GeodeModel
1424
from . import utils_functions
1525
from opengeodeweb_microservice.database.data import Data
1626
from opengeodeweb_microservice.database.connection import get_session
@@ -24,24 +34,56 @@ def data_file_path(data_id: str, filename: str | None) -> str:
2434
return data_path
2535

2636

27-
def load_data(data_id: str) -> GeodeObject:
28-
data_entry = Data.get(data_id)
29-
if not data_entry:
37+
def geode_object_from_string(value: str) -> type[GeodeObject]:
38+
return geode_objects[geode_object_type(value)]
39+
40+
41+
def geode_mesh_from_string(value: str) -> type[GeodeMesh]:
42+
return geode_meshes[geode_mesh_type(value)]
43+
44+
45+
def geode_model_from_string(value: str) -> type[GeodeModel]:
46+
return geode_models[geode_model_type(value)]
47+
48+
49+
def load_object_data(data_id: str) -> GeodeObject:
50+
data = Data.get(data_id)
51+
if not data:
52+
flask.abort(404, f"Data with id {data_id} not found")
53+
54+
file_absolute_path = data_file_path(data_id, data.native_file_name)
55+
print("Loading file: ", file_absolute_path)
56+
print("File exists: ", os.path.exists(file_absolute_path))
57+
return geode_object_from_string(data.geode_object).load(file_absolute_path)
58+
59+
60+
def load_mesh_data(data_id: str) -> GeodeMesh:
61+
data = Data.get(data_id)
62+
if not data:
63+
flask.abort(404, f"Data with id {data_id} not found")
64+
65+
file_absolute_path = data_file_path(data_id, data.native_file_name)
66+
print("Loading file: ", file_absolute_path)
67+
print("File exists: ", os.path.exists(file_absolute_path))
68+
return geode_mesh_from_string(data.geode_object).load_mesh(file_absolute_path)
69+
70+
71+
def load_model_data(data_id: str) -> GeodeModel:
72+
data = Data.get(data_id)
73+
if not data:
3074
flask.abort(404, f"Data with id {data_id} not found")
3175

32-
file_absolute_path = data_file_path(data_id, data_entry.native_file_name)
76+
file_absolute_path = data_file_path(data_id, data.native_file_name)
3377
print("Loading file: ", file_absolute_path)
3478
print("File exists: ", os.path.exists(file_absolute_path))
35-
return geode_objects[to_geode_type(data_entry.geode_object)].load(
36-
file_absolute_path
37-
)
79+
return geode_model_from_string(data.geode_object).load_model(file_absolute_path)
3880

3981

4082
def get_data_info(data_id: str) -> Data:
41-
data_entry = Data.get(data_id)
42-
if not data_entry:
83+
data = Data.get(data_id)
84+
if not data:
4385
flask.abort(404, f"Data with id {data_id} not found")
44-
return data_entry
86+
return data
4587

4688

4789
def upload_file_path(filename: str) -> str:
@@ -52,9 +94,9 @@ def upload_file_path(filename: str) -> str:
5294

5395
def geode_object_output_extensions(
5496
geode_object: GeodeObject,
55-
) -> dict[GeodeType, dict[str, bool]]:
56-
results: dict[GeodeType, dict[str, bool]] = {}
57-
for mixin_geode_object in geode_objects[geode_object.geode_type()].__mro__:
97+
) -> dict[GeodeObjectType, dict[str, bool]]:
98+
results: dict[GeodeObjectType, dict[str, bool]] = {}
99+
for mixin_geode_object in geode_objects[geode_object.geode_object_type()].__mro__:
58100
output_extensions_method = getattr(
59101
mixin_geode_object, "output_extensions", None
60102
)
@@ -70,23 +112,23 @@ def geode_object_output_extensions(
70112
geode_object, f"test.{output_extension}"
71113
)
72114
object_output_extensions[output_extension] = bool_is_saveable
73-
if hasattr(mixin_geode_object, "geode_type"):
74-
results[mixin_geode_object.geode_type()] = object_output_extensions
115+
if hasattr(mixin_geode_object, "geode_object_type"):
116+
results[mixin_geode_object.geode_object_type()] = object_output_extensions
75117
return results
76118

77119

78-
# def assign_crs(geode_type: GeodeType, data, crs_name: str, info):
120+
# def assign_crs(geode_type: GeodeObjectType, data, crs_name: str, info):
79121
# builder = create_builder(geode_object, data)
80122
# geode_objects[geode_type].["crs"]["assign"](data, builder, crs_name, info)
81123

82124

83-
# def convert_crs(geode_type: GeodeType, data, crs_name: str, info):
125+
# def convert_crs(geode_type: GeodeObjectType, data, crs_name: str, info):
84126
# builder = create_builder(geode_object, data)
85127
# geode_objects[geode_type].["crs"]["convert"](data, builder, crs_name, info)
86128

87129

88130
# def create_crs(
89-
# geode_type: GeodeType,
131+
# geode_type: GeodeObjectType,
90132
# data,
91133
# name: str,
92134
# input_coordiante_system,
@@ -98,7 +140,7 @@ def geode_object_output_extensions(
98140
# )
99141

100142

101-
# def geographic_coordinate_systems_info(geode_type: GeodeType, crs):
143+
# def geographic_coordinate_systems_info(geode_type: GeodeObjectType, crs):
102144
# if is_3D(geode_object):
103145
# return og_gs.GeographicCoordinateSystemInfo3D(
104146
# crs["authority"], crs["code"], crs["name"]
@@ -109,7 +151,7 @@ def geode_object_output_extensions(
109151
# )
110152

111153

112-
# def coordinate_system(geode_type: GeodeType, coordinate_system):
154+
# def coordinate_system(geode_type: GeodeObjectType, coordinate_system):
113155
# return og.CoordinateSystem2D(
114156
# [
115157
# og.Vector2D(
@@ -133,18 +175,18 @@ def geode_object_output_extensions(
133175
# )
134176

135177

136-
# def assign_geographic_coordinate_system_info(geode_type: GeodeType, data, input_crs):
178+
# def assign_geographic_coordinate_system_info(geode_type: GeodeObjectType, data, input_crs):
137179
# info = geographic_coordinate_systems_info(geode_object, input_crs)
138180
# assign_crs(geode_object, data, input_crs["name"], info)
139181

140182

141-
# def convert_geographic_coordinate_system_info(geode_type: GeodeType, data, output_crs):
183+
# def convert_geographic_coordinate_system_info(geode_type: GeodeObjectType, data, output_crs):
142184
# info = geographic_coordinate_systems_info(geode_object, output_crs)
143185
# convert_crs(geode_object, data, output_crs["name"], info)
144186

145187

146188
# def create_coordinate_system(
147-
# geode_type: GeodeType, data, name, input_coordinate_points, output_coordinate_points
189+
# geode_type: GeodeObjectType, data, name, input_coordinate_points, output_coordinate_points
148190
# ):
149191
# input_coordiante_system = coordinate_system(geode_object, input_coordinate_points)
150192
# output_coordiante_system = coordinate_system(geode_object, output_coordinate_points)

src/opengeodeweb_back/geode_objects/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,20 @@
1212
import geode_viewables as viewables
1313

1414
# Local application imports
15-
from .geode_object import GeodeType, GeodeObject
15+
from .types import GeodeObjectType, GeodeMeshType, GeodeModelType
16+
from .geode_object import GeodeObject
17+
from .geode_model import GeodeModel
18+
from .geode_mesh import GeodeMesh
1619
from .geode_brep import GeodeBRep
1720

1821

19-
geode_objects: dict[GeodeType, type[GeodeObject]] = {"BRep": GeodeBRep}
22+
geode_meshes: dict[GeodeMeshType, type[GeodeMesh]] = {}
23+
geode_models: dict[GeodeModelType, type[GeodeModel]] = {"BRep": GeodeBRep}
24+
25+
GeodeObjectsDict = dict[GeodeObjectType, type[GeodeObject]]
26+
geode_objects: GeodeObjectsDict = {}
27+
geode_objects.update(cast(GeodeObjectsDict, geode_meshes))
28+
geode_objects.update(cast(GeodeObjectsDict, geode_models))
2029

2130

2231
mesh = "mesh"

src/opengeodeweb_back/geode_objects/geode_brep.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1+
# Standard library imports
2+
from __future__ import annotations
3+
4+
# Third party imports
15
import opengeode as og
6+
import opengeode_inspector as og_inspector
27
import geode_viewables as viewables
38

4-
from .geode_object import GeodeObject, GeodeType, ViewerType
9+
# Local application imports
10+
from .types import GeodeModelType, ViewerType
11+
from .geode_model import GeodeModel, ComponentRegistry
512

613

7-
class GeodeBRep(GeodeObject):
14+
class GeodeBRep(GeodeModel):
815
brep: og.BRep
916

1017
def __init__(self, brep: og.BRep | None = None) -> None:
1118
self.brep = brep if brep is not None else og.BRep()
1219
super().__init__(self.brep)
1320

1421
@classmethod
15-
def geode_type(cls) -> GeodeType:
22+
def geode_model_type(cls) -> GeodeModelType:
1623
return "BRep"
1724

18-
@classmethod
19-
def viewer_type(cls) -> ViewerType:
20-
return "model"
21-
2225
def native_extension(self) -> str:
2326
return self.brep.native_extension()
2427

@@ -34,7 +37,7 @@ def builder(self) -> og.BRepBuilder:
3437
return og.BRepBuilder(self.brep)
3538

3639
@classmethod
37-
def load(self, filename: str) -> "GeodeBRep":
40+
def load_model(cls, filename: str) -> GeodeBRep:
3841
return GeodeBRep(og.load_brep(filename))
3942

4043
@classmethod
@@ -68,3 +71,9 @@ def save_viewable(self, filename_without_extension: str) -> str:
6871

6972
def save_light_viewable(self, filename_without_extension: str) -> str:
7073
return viewables.save_light_viewable_brep(self.brep, filename_without_extension)
74+
75+
def mesh_components(self) -> ComponentRegistry:
76+
return self.brep.mesh_components()
77+
78+
def inspect(self) -> og_inspector.BRepInspectionResult:
79+
return og_inspector.inspect_brep(self.brep)

0 commit comments

Comments
 (0)