mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
Experimental code for serialising API settings
This commit is contained in:
@@ -170,31 +170,6 @@ def run(
|
|||||||
for listener in pre_listeners.get(usecase_path, {}).values():
|
for listener in pre_listeners.get(usecase_path, {}).values():
|
||||||
listener(usecase_path, ifc_file, settings)
|
listener(usecase_path, ifc_file, settings)
|
||||||
|
|
||||||
|
|
||||||
# TODO: settings serialization for client-server systems
|
|
||||||
# def serialise_entity_instance(entity):
|
|
||||||
# return {"cast_type": "entity_instance", "value": entity.id(), "Name": getattr(entity, "Name", None)}
|
|
||||||
# vcs_settings = settings.copy()
|
|
||||||
# for key, value in settings.items():
|
|
||||||
# if isinstance(value, ifcopenshell.entity_instance):
|
|
||||||
# vcs_settings[key] = serialise_entity_instance(value)
|
|
||||||
# elif isinstance(value, numpy.ndarray):
|
|
||||||
# vcs_settings[key] = {"cast_type": "ndarray", "value": value.tolist()}
|
|
||||||
# elif isinstance(value, list) and value and isinstance(value[0], ifcopenshell.entity_instance):
|
|
||||||
# vcs_settings[key] = [serialise_entity_instance(i) for i in value]
|
|
||||||
if "add_representation" in usecase_path:
|
|
||||||
pass
|
|
||||||
# print(usecase_path, "{ ... settings too complex right now ... }")
|
|
||||||
elif "owner." in usecase_path:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
# print(vcs_settings)
|
|
||||||
# try:
|
|
||||||
# print(usecase_path, json.dumps(vcs_settings))
|
|
||||||
# except:
|
|
||||||
# print(usecase_path, vcs_settings)
|
|
||||||
|
|
||||||
usecase_class = CACHED_USECASE_CLASSES.get(usecase_path)
|
usecase_class = CACHED_USECASE_CLASSES.get(usecase_path)
|
||||||
if usecase_class is None:
|
if usecase_class is None:
|
||||||
importlib.import_module(f"ifcopenshell.api.{usecase_path}")
|
importlib.import_module(f"ifcopenshell.api.{usecase_path}")
|
||||||
@@ -308,6 +283,28 @@ def extract_docs(module, usecase):
|
|||||||
return node_data
|
return node_data
|
||||||
|
|
||||||
|
|
||||||
|
def serialise_settings(settings):
|
||||||
|
def serialise_entity_instance(entity):
|
||||||
|
return {"cast_type": "entity_instance", "value": entity.id(), "Name": getattr(entity, "Name", None)}
|
||||||
|
|
||||||
|
vcs_settings = settings.copy()
|
||||||
|
for key, value in settings.items():
|
||||||
|
if isinstance(value, ifcopenshell.entity_instance):
|
||||||
|
vcs_settings[key] = serialise_entity_instance(value)
|
||||||
|
elif isinstance(value, numpy.ndarray):
|
||||||
|
vcs_settings[key] = {"cast_type": "ndarray", "value": value.tolist()}
|
||||||
|
elif isinstance(value, list) and value and isinstance(value[0], ifcopenshell.entity_instance):
|
||||||
|
vcs_settings[key] = [serialise_entity_instance(i) for i in value]
|
||||||
|
if "add_representation" in usecase_path:
|
||||||
|
return ""
|
||||||
|
elif "owner." in usecase_path:
|
||||||
|
return ""
|
||||||
|
try:
|
||||||
|
return json.dumps(vcs_settings)
|
||||||
|
except:
|
||||||
|
return str(vcs_settings)
|
||||||
|
|
||||||
|
|
||||||
def wrap_usecase(usecase_path, usecase):
|
def wrap_usecase(usecase_path, usecase):
|
||||||
"""Wraps an API function in pre/post listeners."""
|
"""Wraps an API function in pre/post listeners."""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user