Skip to content

Commit c551095

Browse files
feat(routes): create point3D route
1 parent cd5597a commit c551095

File tree

5 files changed

+114
-2
lines changed

5 files changed

+114
-2
lines changed

src/opengeodeweb_back/geode_functions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ 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"]
1820
def input_factory(geode_object: str):
1921
return geode_object_value(geode_object)["input_factory"]
2022

@@ -256,3 +258,4 @@ def create_coordinate_system(
256258
create_crs(
257259
geode_object, data, name, input_coordiante_system, output_coordiante_system
258260
)
261+

src/opengeodeweb_back/geode_objects.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
def geode_objects_dict():
1010
return {
1111
"BRep": {
12+
"class": og.BRep,
1213
"input_factory": og.BRepInputFactory,
1314
"output_factory": og.BRepOutputFactory,
1415
"missing_files": og.check_brep_missing_files,
@@ -30,6 +31,7 @@ def geode_objects_dict():
3031
},
3132
"CrossSection": {
3233
"parent": "Section",
34+
"class": og_gs.CrossSection,
3335
"input_factory": og_gs.CrossSectionInputFactory,
3436
"output_factory": og_gs.CrossSectionOutputFactory,
3537
"missing_files": og_gs.check_cross_section_missing_files,
@@ -50,6 +52,7 @@ def geode_objects_dict():
5052
"inspector": og_inspector.inspect_section,
5153
},
5254
"EdgedCurve2D": {
55+
"class": og.EdgedCurve2D,
5356
"input_factory": og.EdgedCurveInputFactory2D,
5457
"output_factory": og.EdgedCurveOutputFactory2D,
5558
"missing_files": og.check_edged_curve_missing_files2D,
@@ -70,6 +73,7 @@ def geode_objects_dict():
7073
"inspector": og_inspector.inspect_edged_curve2D,
7174
},
7275
"EdgedCurve3D": {
76+
"class": og.EdgedCurve3D,
7377
"input_factory": og.EdgedCurveInputFactory3D,
7478
"output_factory": og.EdgedCurveOutputFactory3D,
7579
"missing_files": og.check_edged_curve_missing_files3D,
@@ -90,6 +94,7 @@ def geode_objects_dict():
9094
"inspector": og_inspector.inspect_edged_curve3D,
9195
},
9296
"Graph": {
97+
"class": og.Graph,
9398
"input_factory": og.GraphInputFactory,
9499
"output_factory": og.GraphOutputFactory,
95100
"missing_files": og.check_graph_missing_files,
@@ -103,6 +108,7 @@ def geode_objects_dict():
103108
"is_viewable": True,
104109
},
105110
"HybridSolid3D": {
111+
"class": og.HybridSolid3D,
106112
"input_factory": og.HybridSolidInputFactory3D,
107113
"output_factory": og.HybridSolidOutputFactory3D,
108114
"missing_files": og.check_hybrid_solid_missing_files3D,
@@ -124,6 +130,7 @@ def geode_objects_dict():
124130
},
125131
"ImplicitCrossSection": {
126132
"parent": "CrossSection",
133+
"class": og_gs.ImplicitCrossSection,
127134
"input_factory": og_gs.ImplicitCrossSectionInputFactory,
128135
"output_factory": og_gs.ImplicitCrossSectionOutputFactory,
129136
"missing_files": og_gs.check_implicit_cross_section_missing_files,
@@ -145,6 +152,7 @@ def geode_objects_dict():
145152
},
146153
"ImplicitStructuralModel": {
147154
"parent": "StructuralModel",
155+
"class": og_gs.ImplicitStructuralModel,
148156
"input_factory": og_gs.ImplicitStructuralModelInputFactory,
149157
"output_factory": og_gs.ImplicitStructuralModelOutputFactory,
150158
"missing_files": og_gs.check_implicit_structural_model_missing_files,
@@ -165,6 +173,7 @@ def geode_objects_dict():
165173
"inspector": og_inspector.inspect_brep,
166174
},
167175
"LightRegularGrid2D": {
176+
"class": og.LightRegularGrid2D,
168177
"input_factory": og.LightRegularGridInputFactory2D,
169178
"output_factory": og.LightRegularGridOutputFactory2D,
170179
"missing_files": og.check_light_regular_grid_missing_files2D,
@@ -178,6 +187,7 @@ def geode_objects_dict():
178187
"save_viewable": g_v.save_viewable_light_regular_grid2D,
179188
},
180189
"LightRegularGrid3D": {
190+
"class": og.LightRegularGrid3D,
181191
"input_factory": og.LightRegularGridInputFactory3D,
182192
"output_factory": og.LightRegularGridOutputFactory3D,
183193
"missing_files": og.check_light_regular_grid_missing_files3D,
@@ -191,6 +201,7 @@ def geode_objects_dict():
191201
"save_viewable": g_v.save_viewable_light_regular_grid3D,
192202
},
193203
"PointSet2D": {
204+
"class": og.PointSet2D,
194205
"input_factory": og.PointSetInputFactory2D,
195206
"output_factory": og.PointSetOutputFactory2D,
196207
"missing_files": og.check_point_set_missing_files2D,
@@ -211,6 +222,7 @@ def geode_objects_dict():
211222
"inspector": og_inspector.inspect_point_set2D,
212223
},
213224
"PointSet3D": {
225+
"class": og.PointSet3D,
214226
"input_factory": og.PointSetInputFactory3D,
215227
"output_factory": og.PointSetOutputFactory3D,
216228
"missing_files": og.check_point_set_missing_files3D,
@@ -231,6 +243,7 @@ def geode_objects_dict():
231243
"inspector": og_inspector.inspect_point_set3D,
232244
},
233245
"PolygonalSurface2D": {
246+
"class": og.PolygonalSurface2D,
234247
"input_factory": og.PolygonalSurfaceInputFactory2D,
235248
"output_factory": og.PolygonalSurfaceOutputFactory2D,
236249
"missing_files": og.check_polygonal_surface_missing_files2D,
@@ -251,6 +264,7 @@ def geode_objects_dict():
251264
"inspector": og_inspector.inspect_surface2D,
252265
},
253266
"PolygonalSurface3D": {
267+
"class": og.PolygonalSurface3D,
254268
"input_factory": og.PolygonalSurfaceInputFactory3D,
255269
"output_factory": og.PolygonalSurfaceOutputFactory3D,
256270
"missing_files": og.check_polygonal_surface_missing_files3D,
@@ -271,6 +285,7 @@ def geode_objects_dict():
271285
"inspector": og_inspector.inspect_surface3D,
272286
},
273287
"PolyhedralSolid3D": {
288+
"class": og.PolyhedralSolid3D,
274289
"input_factory": og.PolyhedralSolidInputFactory3D,
275290
"output_factory": og.PolyhedralSolidOutputFactory3D,
276291
"missing_files": og.check_polyhedral_solid_missing_files3D,
@@ -291,6 +306,7 @@ def geode_objects_dict():
291306
"inspector": og_inspector.inspect_solid3D,
292307
},
293308
"RasterImage2D": {
309+
"class": og.RasterImage2D,
294310
"input_factory": og.RasterImageInputFactory2D,
295311
"output_factory": og.RasterImageOutputFactory2D,
296312
"missing_files": og.check_raster_image_missing_files2D,
@@ -304,6 +320,7 @@ def geode_objects_dict():
304320
"save_viewable": g_v.save_viewable_raster_image2D,
305321
},
306322
"RasterImage3D": {
323+
"class": og.RasterImage3D,
307324
"input_factory": og.RasterImageInputFactory3D,
308325
"output_factory": og.RasterImageOutputFactory3D,
309326
"missing_files": og.check_raster_image_missing_files3D,
@@ -317,6 +334,7 @@ def geode_objects_dict():
317334
"save_viewable": g_v.save_viewable_raster_image3D,
318335
},
319336
"RegularGrid2D": {
337+
"class": og.RegularGrid2D,
320338
"input_factory": og.RegularGridInputFactory2D,
321339
"output_factory": og.RegularGridOutputFactory2D,
322340
"missing_files": og.check_regular_grid_missing_files2D,
@@ -336,6 +354,7 @@ def geode_objects_dict():
336354
"save_viewable": g_v.save_viewable_regular_grid2D,
337355
},
338356
"RegularGrid3D": {
357+
"class": og.RegularGrid3D,
339358
"input_factory": og.RegularGridInputFactory3D,
340359
"output_factory": og.RegularGridOutputFactory3D,
341360
"missing_files": og.check_regular_grid_missing_files3D,
@@ -355,6 +374,7 @@ def geode_objects_dict():
355374
"save_viewable": g_v.save_viewable_regular_grid3D,
356375
},
357376
"Section": {
377+
"class": og.Section,
358378
"input_factory": og.SectionInputFactory,
359379
"output_factory": og.SectionOutputFactory,
360380
"missing_files": og.check_section_missing_files,
@@ -376,6 +396,7 @@ def geode_objects_dict():
376396
},
377397
"StructuralModel": {
378398
"parent": "BRep",
399+
"class": og.StructuralModel,
379400
"input_factory": og_gs.StructuralModelInputFactory,
380401
"output_factory": og_gs.StructuralModelOutputFactory,
381402
"missing_files": og_gs.check_structural_model_missing_files,
@@ -396,6 +417,7 @@ def geode_objects_dict():
396417
"inspector": og_inspector.inspect_brep,
397418
},
398419
"TetrahedralSolid3D": {
420+
"class": og.TetrahedralSolid3D,
399421
"input_factory": og.TetrahedralSolidInputFactory3D,
400422
"output_factory": og.TetrahedralSolidOutputFactory3D,
401423
"missing_files": og.check_tetrahedral_solid_missing_files3D,
@@ -416,6 +438,7 @@ def geode_objects_dict():
416438
"inspector": og_inspector.inspect_solid3D,
417439
},
418440
"TriangulatedSurface2D": {
441+
"class": og.TriangulatedSurface2D,
419442
"input_factory": og.TriangulatedSurfaceInputFactory2D,
420443
"output_factory": og.TriangulatedSurfaceOutputFactory2D,
421444
"missing_files": og.check_triangulated_surface_missing_files2D,
@@ -436,6 +459,7 @@ def geode_objects_dict():
436459
"inspector": og_inspector.inspect_surface2D,
437460
},
438461
"TriangulatedSurface3D": {
462+
"class": og.TriangulatedSurface3D,
439463
"input_factory": og.TriangulatedSurfaceInputFactory3D,
440464
"output_factory": og.TriangulatedSurfaceOutputFactory3D,
441465
"missing_files": og.check_triangulated_surface_missing_files3D,
@@ -456,6 +480,7 @@ def geode_objects_dict():
456480
"inspector": og_inspector.inspect_surface3D,
457481
},
458482
"VertexSet": {
483+
"class": og.VertexSet,
459484
"input_factory": og.VertexSetInputFactory,
460485
"output_factory": og.VertexSetOutputFactory,
461486
"missing_files": og.check_vertex_set_missing_files,

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 33 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,34 @@ 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("PointSet3D", PointSet3D, DATA_FOLDER_PATH, generated_id)
295+
296+
return flask.make_response(
297+
{
298+
"viewable_file_name": os.path.basename(saved_viewable_file_path),
299+
"id": generated_id,
300+
},
301+
200,
302+
)
303+
304+
274305
with open(
275306
os.path.join(schemas, "ping.json"),
276307
"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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,32 @@ def get_full_data():
185185
assert response.status_code == 400
186186
error_description = response.json["description"]
187187
assert error_description == f"Validation error: '{key}' is a required property"
188+
189+
def test_create_point(client):
190+
route = f"/create_point"
191+
192+
def get_full_data():
193+
return {
194+
"x": 1,
195+
"y": 2,
196+
"z": 3
197+
}
198+
# Normal test with all keys
199+
response = client.post(route, json=get_full_data())
200+
assert response.status_code == 200
201+
viewable_file_name = response.json["viewable_file_name"]
202+
assert type(viewable_file_name) is str
203+
id = response.json["id"]
204+
assert type(id) is str
205+
206+
207+
for key, value in get_full_data().items():
208+
json = get_full_data()
209+
json.pop(key)
210+
response = client.post(route, json=json)
211+
assert response.status_code == 400
212+
error_description = response.json["description"]
213+
assert error_description == f"Validation error: '{key}' is a required property"
214+
215+
216+

0 commit comments

Comments
 (0)