mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
handle header entity string reversal
This commit is contained in:
committed by
Thomas Krijnen
parent
689289bb60
commit
5eb9cdf40d
@@ -597,6 +597,25 @@ def validate_guid(guid: str) -> Union[str, None]:
|
||||
return "Couldn't decompress guid, it's not base64 encoded."
|
||||
return None
|
||||
|
||||
def to_string_header_entity(header_entity):
|
||||
"""Recreate IFC header string representation, like FILE_NAME(...)"""
|
||||
def format_value(val):
|
||||
if isinstance(val, str):
|
||||
return f"'{val}'"
|
||||
elif isinstance(val, tuple):
|
||||
return "(" + ",".join(format_value(v) for v in val) + ")"
|
||||
return str(val)
|
||||
|
||||
# Prefer native .toString() if available (native IfcOpenShell wrapper)
|
||||
if hasattr(header_entity, 'toString'):
|
||||
return header_entity.toString()
|
||||
|
||||
if hasattr(header_entity, '_fields'):
|
||||
values = [format_value(getattr(header_entity, f)) for f in header_entity._fields]
|
||||
else:
|
||||
raise TypeError(f"Cannot stringify header_entity of type {type(header_entity)}")
|
||||
|
||||
return f"{type(header_entity).__name__.upper()}({','.join(values)})"
|
||||
|
||||
def validate_ifc_header(f: Union[ifcopenshell.file, ifcopenshell.simple_spf.file], logger: Logger) -> None:
|
||||
if type(f) is ifcopenshell.file:
|
||||
@@ -613,7 +632,7 @@ def validate_ifc_header(f: Union[ifcopenshell.file, ifcopenshell.simple_spf.file
|
||||
"Attribute '%s' has invalid type:\n"
|
||||
" Expected: %s\n Current value type: %s\n"
|
||||
),
|
||||
(s := header_entity.toString()),
|
||||
(s := to_string_header_entity(header_entity)),
|
||||
annotate_inst_attr_pos(header_entity, index, s),
|
||||
name,
|
||||
expected_type,
|
||||
|
||||
Reference in New Issue
Block a user