Skip to content

Commit c8142ad

Browse files
merge next into branch
1 parent ced3b8d commit c8142ad

File tree

5 files changed

+105
-2
lines changed

5 files changed

+105
-2
lines changed

src/opengeodeweb_back/geode_functions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def geode_object_value(geode_object: str):
1515
return geode_objects_dict()[geode_object]
1616

1717

18+
def geode_object_class(geode_object: str):
19+
return geode_object_value(geode_object)["class"]
20+
21+
1822
def input_factory(geode_object: str):
1923
return geode_object_value(geode_object)["input_factory"]
2024

src/opengeodeweb_back/geode_objects.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
def geode_objects_dict():
1414
return {
1515
"BRep": {
16+
"class": og.BRep,
1617
"input_factory": og.BRepInputFactory,
1718
"output_factory": og.BRepOutputFactory,
1819
"missing_files": og.check_brep_missing_files,
@@ -34,6 +35,7 @@ def geode_objects_dict():
3435
},
3536
"CrossSection": {
3637
"parent": "Section",
38+
"class": og_gs.CrossSection,
3739
"input_factory": og_gs.CrossSectionInputFactory,
3840
"output_factory": og_gs.CrossSectionOutputFactory,
3941
"missing_files": og_gs.check_cross_section_missing_files,
@@ -54,6 +56,7 @@ def geode_objects_dict():
5456
"inspector": og_inspector.inspect_section,
5557
},
5658
"EdgedCurve2D": {
59+
"class": og.EdgedCurve2D,
5760
"input_factory": og.EdgedCurveInputFactory2D,
5861
"output_factory": og.EdgedCurveOutputFactory2D,
5962
"missing_files": og.check_edged_curve_missing_files2D,
@@ -74,6 +77,7 @@ def geode_objects_dict():
7477
"inspector": og_inspector.inspect_edged_curve2D,
7578
},
7679
"EdgedCurve3D": {
80+
"class": og.EdgedCurve3D,
7781
"input_factory": og.EdgedCurveInputFactory3D,
7882
"output_factory": og.EdgedCurveOutputFactory3D,
7983
"missing_files": og.check_edged_curve_missing_files3D,
@@ -94,6 +98,7 @@ def geode_objects_dict():
9498
"inspector": og_inspector.inspect_edged_curve3D,
9599
},
96100
"Graph": {
101+
"class": og.Graph,
97102
"input_factory": og.GraphInputFactory,
98103
"output_factory": og.GraphOutputFactory,
99104
"missing_files": og.check_graph_missing_files,
@@ -107,6 +112,7 @@ def geode_objects_dict():
107112
"is_viewable": True,
108113
},
109114
"HybridSolid3D": {
115+
"class": og.HybridSolid3D,
110116
"input_factory": og.HybridSolidInputFactory3D,
111117
"output_factory": og.HybridSolidOutputFactory3D,
112118
"missing_files": og.check_hybrid_solid_missing_files3D,
@@ -128,6 +134,7 @@ def geode_objects_dict():
128134
},
129135
"ImplicitCrossSection": {
130136
"parent": "CrossSection",
137+
"class": og_gs.ImplicitCrossSection,
131138
"input_factory": og_gs.ImplicitCrossSectionInputFactory,
132139
"output_factory": og_gs.ImplicitCrossSectionOutputFactory,
133140
"missing_files": og_gs.check_implicit_cross_section_missing_files,
@@ -149,6 +156,7 @@ def geode_objects_dict():
149156
},
150157
"ImplicitStructuralModel": {
151158
"parent": "StructuralModel",
159+
"class": og_gs.ImplicitStructuralModel,
152160
"input_factory": og_gs.ImplicitStructuralModelInputFactory,
153161
"output_factory": og_gs.ImplicitStructuralModelOutputFactory,
154162
"missing_files": og_gs.check_implicit_structural_model_missing_files,
@@ -169,6 +177,7 @@ def geode_objects_dict():
169177
"inspector": og_inspector.inspect_brep,
170178
},
171179
"LightRegularGrid2D": {
180+
"class": og.LightRegularGrid2D,
172181
"input_factory": og.LightRegularGridInputFactory2D,
173182
"output_factory": og.LightRegularGridOutputFactory2D,
174183
"missing_files": og.check_light_regular_grid_missing_files2D,
@@ -182,6 +191,7 @@ def geode_objects_dict():
182191
"save_viewable": g_v.save_viewable_light_regular_grid2D,
183192
},
184193
"LightRegularGrid3D": {
194+
"class": og.LightRegularGrid3D,
185195
"input_factory": og.LightRegularGridInputFactory3D,
186196
"output_factory": og.LightRegularGridOutputFactory3D,
187197
"missing_files": og.check_light_regular_grid_missing_files3D,
@@ -195,6 +205,7 @@ def geode_objects_dict():
195205
"save_viewable": g_v.save_viewable_light_regular_grid3D,
196206
},
197207
"PointSet2D": {
208+
"class": og.PointSet2D,
198209
"input_factory": og.PointSetInputFactory2D,
199210
"output_factory": og.PointSetOutputFactory2D,
200211
"missing_files": og.check_point_set_missing_files2D,
@@ -215,6 +226,7 @@ def geode_objects_dict():
215226
"inspector": og_inspector.inspect_point_set2D,
216227
},
217228
"PointSet3D": {
229+
"class": og.PointSet3D,
218230
"input_factory": og.PointSetInputFactory3D,
219231
"output_factory": og.PointSetOutputFactory3D,
220232
"missing_files": og.check_point_set_missing_files3D,
@@ -235,6 +247,7 @@ def geode_objects_dict():
235247
"inspector": og_inspector.inspect_point_set3D,
236248
},
237249
"PolygonalSurface2D": {
250+
"class": og.PolygonalSurface2D,
238251
"input_factory": og.PolygonalSurfaceInputFactory2D,
239252
"output_factory": og.PolygonalSurfaceOutputFactory2D,
240253
"missing_files": og.check_polygonal_surface_missing_files2D,
@@ -255,6 +268,7 @@ def geode_objects_dict():
255268
"inspector": og_inspector.inspect_surface2D,
256269
},
257270
"PolygonalSurface3D": {
271+
"class": og.PolygonalSurface3D,
258272
"input_factory": og.PolygonalSurfaceInputFactory3D,
259273
"output_factory": og.PolygonalSurfaceOutputFactory3D,
260274
"missing_files": og.check_polygonal_surface_missing_files3D,
@@ -275,6 +289,7 @@ def geode_objects_dict():
275289
"inspector": og_inspector.inspect_surface3D,
276290
},
277291
"PolyhedralSolid3D": {
292+
"class": og.PolyhedralSolid3D,
278293
"input_factory": og.PolyhedralSolidInputFactory3D,
279294
"output_factory": og.PolyhedralSolidOutputFactory3D,
280295
"missing_files": og.check_polyhedral_solid_missing_files3D,
@@ -295,6 +310,7 @@ def geode_objects_dict():
295310
"inspector": og_inspector.inspect_solid3D,
296311
},
297312
"RasterImage2D": {
313+
"class": og.RasterImage2D,
298314
"input_factory": og.RasterImageInputFactory2D,
299315
"output_factory": og.RasterImageOutputFactory2D,
300316
"missing_files": og.check_raster_image_missing_files2D,
@@ -308,6 +324,7 @@ def geode_objects_dict():
308324
"save_viewable": g_v.save_viewable_raster_image2D,
309325
},
310326
"RasterImage3D": {
327+
"class": og.RasterImage3D,
311328
"input_factory": og.RasterImageInputFactory3D,
312329
"output_factory": og.RasterImageOutputFactory3D,
313330
"missing_files": og.check_raster_image_missing_files3D,
@@ -321,6 +338,7 @@ def geode_objects_dict():
321338
"save_viewable": g_v.save_viewable_raster_image3D,
322339
},
323340
"RegularGrid2D": {
341+
"class": og.RegularGrid2D,
324342
"input_factory": og.RegularGridInputFactory2D,
325343
"output_factory": og.RegularGridOutputFactory2D,
326344
"missing_files": og.check_regular_grid_missing_files2D,
@@ -340,6 +358,7 @@ def geode_objects_dict():
340358
"save_viewable": g_v.save_viewable_regular_grid2D,
341359
},
342360
"RegularGrid3D": {
361+
"class": og.RegularGrid3D,
343362
"input_factory": og.RegularGridInputFactory3D,
344363
"output_factory": og.RegularGridOutputFactory3D,
345364
"missing_files": og.check_regular_grid_missing_files3D,
@@ -359,6 +378,7 @@ def geode_objects_dict():
359378
"save_viewable": g_v.save_viewable_regular_grid3D,
360379
},
361380
"Section": {
381+
"class": og.Section,
362382
"input_factory": og.SectionInputFactory,
363383
"output_factory": og.SectionOutputFactory,
364384
"missing_files": og.check_section_missing_files,
@@ -380,6 +400,7 @@ def geode_objects_dict():
380400
},
381401
"StructuralModel": {
382402
"parent": "BRep",
403+
"class": og_gs.StructuralModel,
383404
"input_factory": og_gs.StructuralModelInputFactory,
384405
"output_factory": og_gs.StructuralModelOutputFactory,
385406
"missing_files": og_gs.check_structural_model_missing_files,
@@ -400,6 +421,7 @@ def geode_objects_dict():
400421
"inspector": og_inspector.inspect_brep,
401422
},
402423
"TetrahedralSolid3D": {
424+
"class": og.TetrahedralSolid3D,
403425
"input_factory": og.TetrahedralSolidInputFactory3D,
404426
"output_factory": og.TetrahedralSolidOutputFactory3D,
405427
"missing_files": og.check_tetrahedral_solid_missing_files3D,
@@ -420,6 +442,7 @@ def geode_objects_dict():
420442
"inspector": og_inspector.inspect_solid3D,
421443
},
422444
"TriangulatedSurface2D": {
445+
"class": og.TriangulatedSurface2D,
423446
"input_factory": og.TriangulatedSurfaceInputFactory2D,
424447
"output_factory": og.TriangulatedSurfaceOutputFactory2D,
425448
"missing_files": og.check_triangulated_surface_missing_files2D,
@@ -440,6 +463,7 @@ def geode_objects_dict():
440463
"inspector": og_inspector.inspect_surface2D,
441464
},
442465
"TriangulatedSurface3D": {
466+
"class": og.TriangulatedSurface3D,
443467
"input_factory": og.TriangulatedSurfaceInputFactory3D,
444468
"output_factory": og.TriangulatedSurfaceOutputFactory3D,
445469
"missing_files": og.check_triangulated_surface_missing_files3D,
@@ -460,6 +484,7 @@ def geode_objects_dict():
460484
"inspector": og_inspector.inspect_surface3D,
461485
},
462486
"VertexSet": {
487+
"class": og.VertexSet,
463488
"input_factory": og.VertexSetInputFactory,
464489
"output_factory": og.VertexSetOutputFactory,
465490
"missing_files": og.check_vertex_set_missing_files,

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
# Third party imports
77
import flask
8-
from .. import geode_functions, utils_functions
9-
import werkzeug
8+
import opengeode
109
import uuid
10+
import werkzeug
11+
12+
# Local application imports
13+
from .. import geode_functions, utils_functions
1114

1215
routes = flask.Blueprint("routes", __name__)
1316

@@ -271,6 +274,36 @@ def save_viewable_file():
271274
)
272275

273276

277+
with open(os.path.join(schemas, "create_point.json"), "r") as file:
278+
create_point_json = json.load(file)
279+
280+
281+
@routes.route(create_point_json["route"], methods=create_point_json["methods"])
282+
def create_point():
283+
utils_functions.validate_request(flask.request, create_point_json)
284+
DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"]
285+
x = flask.request.json["x"]
286+
y = flask.request.json["y"]
287+
z = flask.request.json["z"]
288+
class_ = geode_functions.geode_object_class("PointSet3D")
289+
PointSet3D = class_.create()
290+
builder = geode_functions.create_builder("PointSet3D", PointSet3D)
291+
builder.create_point(opengeode.Point3D([x, y, z]))
292+
293+
generated_id = str(uuid.uuid4()).replace("-", "")
294+
saved_viewable_file_path = geode_functions.save_viewable(
295+
"PointSet3D", PointSet3D, DATA_FOLDER_PATH, generated_id
296+
)
297+
298+
return flask.make_response(
299+
{
300+
"viewable_file_name": os.path.basename(saved_viewable_file_path),
301+
"id": generated_id,
302+
},
303+
200,
304+
)
305+
306+
274307
with open(
275308
os.path.join(schemas, "vertex_attribute_names.json"),
276309
"r",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"route": "/create_point",
3+
"methods": [
4+
"POST"
5+
],
6+
"type": "object",
7+
"properties": {
8+
"x": {
9+
"type": "number"
10+
},
11+
"y": {
12+
"type": "number"
13+
},
14+
"z": {
15+
"type": "number"
16+
}
17+
},
18+
"required": [
19+
"x",
20+
"y",
21+
"z"
22+
],
23+
"additionalProperties": false
24+
}

tests/test_routes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def get_full_data():
156156
id = response.json["id"]
157157
assert type(id) is str
158158

159+
# Test all params
159160
test_utils.test_route_wrong_params(client, route, get_full_data)
160161

161162
def test_vertex_attribute_names(client):
@@ -181,4 +182,20 @@ def get_full_data():
181182
for vertex_attribute_name in vertex_attribute_names:
182183
assert type(vertex_attribute_name) is str
183184

185+
test_utils.test_route_wrong_params(client, route, get_full_data)
186+
187+
188+
def test_create_point(client):
189+
route = f"/create_point"
190+
get_full_data = lambda: {"x": 1, "y": 2, "z": 3}
191+
192+
# Normal test with all keys
193+
response = client.post(route, json=get_full_data())
194+
assert response.status_code == 200
195+
viewable_file_name = response.json["viewable_file_name"]
196+
assert type(viewable_file_name) is str
197+
id = response.json["id"]
198+
assert type(id) is str
199+
200+
# Test all params
184201
test_utils.test_route_wrong_params(client, route, get_full_data)

0 commit comments

Comments
 (0)