22import os
33import xml .etree .ElementTree as ET
44import flask
5-
65from src .opengeodeweb_back import geode_functions , utils_functions
6+ from opengeode import model
77
88routes = flask .Blueprint ("models" , __name__ )
99
@@ -23,13 +23,13 @@ def teardown_request(exception):
2323
2424schemas = os .path .join (os .path .dirname (__file__ ), "schemas" )
2525
26- with open (os .path .join (schemas , "components .json" ), "r" ) as file :
27- components_json = json .load (file )
26+ with open (os .path .join (schemas , "mesh_components .json" ), "r" ) as file :
27+ mesh_components_json = json .load (file )
2828
2929
30- @routes .route (components_json ["route" ], methods = components_json ["methods" ])
31- def print_vtm_file ():
32- utils_functions .validate_request (flask .request , components_json )
30+ @routes .route (mesh_components_json ["route" ], methods = mesh_components_json ["methods" ])
31+ def uuid_to_flat_index ():
32+ utils_functions .validate_request (flask .request , mesh_components_json )
3333 vtm_file_path = os .path .join (
3434 flask .current_app .config ["DATA_FOLDER_PATH" ], flask .request .json ["id" ] + ".vtm"
3535 )
@@ -50,3 +50,45 @@ def print_vtm_file():
5050 {"uuid_to_flat_index" : uuid_to_flat_index },
5151 200 ,
5252 )
53+
54+
55+ def extract_model_uuids (geode_object , file_path ):
56+ model = geode_functions .load (geode_object , file_path )
57+ components = {
58+ "blocks" : getattr (model , "blocks" , lambda : [])(),
59+ "lines" : getattr (model , "lines" , lambda : [])(),
60+ "surfaces" : getattr (model , "surfaces" , lambda : [])(),
61+ "corners" : getattr (model , "corners" , lambda : [])(),
62+ }
63+
64+ uuid_dict = {
65+ key : [
66+ component .id ().string ()
67+ for component in components [key ]
68+ if hasattr (component , "id" )
69+ ]
70+ for key in components
71+ if components [key ]
72+ }
73+
74+ print (f"{ uuid_dict = } " , flush = True )
75+ return uuid_dict
76+
77+
78+ with open (os .path .join (schemas , "components_types.json" ), "r" ) as file :
79+ components_types_json = json .load (file )
80+
81+
82+ @routes .route (components_types_json ["route" ], methods = components_types_json ["methods" ])
83+ def extract_uuids_endpoint ():
84+ utils_functions .validate_request (flask .request , components_types_json )
85+
86+ file_path = os .path .join (
87+ flask .current_app .config ["DATA_FOLDER_PATH" ], flask .request .json ["filename" ]
88+ )
89+
90+ if not os .path .exists (file_path ):
91+ return flask .make_response ({"error" : "File not found" }, 404 )
92+
93+ uuid_dict = extract_model_uuids (flask .request .json ["geode_object" ], file_path )
94+ return flask .make_response (uuid_dict , 200 )
0 commit comments