static ifcopenshell.geom.serializers and some typing for IDE code hints

code itself should work exactly the same way
This commit is contained in:
Andrej730
2024-01-22 14:24:15 +05:00
parent f2d19ab2c3
commit c3ded31a6a
@@ -31,6 +31,10 @@ from ..entity_instance import entity_instance
from . import has_occ from . import has_occ
from typing import TypeVar
T = TypeVar("T")
def wrap_shape_creation(settings, shape): def wrap_shape_creation(settings, shape):
return shape return shape
@@ -253,7 +257,7 @@ serialise = make_shape_function(ifcopenshell_wrapper.serialise)
tesselate = make_shape_function(ifcopenshell_wrapper.tesselate) tesselate = make_shape_function(ifcopenshell_wrapper.tesselate)
def wrap_buffer_creation(fn): def wrap_buffer_creation(fn: T):
""" """
Python does not have automatic casts. The C++ serializers accept a stream_or_filename Python does not have automatic casts. The C++ serializers accept a stream_or_filename
which in C++ can be automatically constructed from a filename string. In Python we which in C++ can be automatically constructed from a filename string. In Python we
@@ -266,28 +270,25 @@ def wrap_buffer_creation(fn):
else: else:
return v return v
def inner(*args): def inner(*args) -> T:
return fn(*map(transform_string, args)) return fn(*map(transform_string, args))
return inner return inner
# Hdf- Xml- and glTF- serializers don't support writing to a buffer, only to filename class serializers:
# so no wrap_buffer_creation() for these serializers obj = wrap_buffer_creation(ifcopenshell_wrapper.WaveFrontOBJSerializer)
serializer_dict = {} svg = wrap_buffer_creation(ifcopenshell_wrapper.SvgSerializer)
serializer_dict["obj"] = wrap_buffer_creation(ifcopenshell_wrapper.WaveFrontOBJSerializer) # Hdf- Xml- and glTF- serializers don't support writing to a buffer, only to filename
serializer_dict["svg"] = wrap_buffer_creation(ifcopenshell_wrapper.SvgSerializer) # so no wrap_buffer_creation() for these serializers
serializer_dict["xml"] = ifcopenshell_wrapper.XmlSerializer xml = ifcopenshell_wrapper.XmlSerializer
serializer_dict["buffer"] = ifcopenshell_wrapper.buffer buffer = ifcopenshell_wrapper.buffer
# gltf and hdf5 availability depend on IfcOpenShell configuration settings
# gltf and hdf5 availability depend on IfcOpenShell configuration settings try:
try: gtlf = ifcopenshell_wrapper.GltfSerializer
serializer_dict["gltf"] = ifcopenshell_wrapper.GltfSerializer except:
except: pass pass
try:
try: hdf5 = ifcopenshell_wrapper.HdfSerializer
serializer_dict["hdf5"] = ifcopenshell_wrapper.HdfSerializer except:
except: pass
pass
serializers = type("serializers", (), serializer_dict)