mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
util.schema: dedupe inline schema resolution logic
This commit is contained in:
@@ -305,12 +305,13 @@ def schema_by_name(
|
|||||||
you are testing non-ISO IFC releases.
|
you are testing non-ISO IFC releases.
|
||||||
:return: Schema definition object.
|
:return: Schema definition object.
|
||||||
"""
|
"""
|
||||||
|
import ifcopenshell.util.schema
|
||||||
|
|
||||||
assert schema_version or schema, "Either schema or schema_version must be specified."
|
assert schema_version or schema, "Either schema or schema_version must be specified."
|
||||||
if schema_version:
|
if schema_version:
|
||||||
prefixes = ("IFC", "X", "_ADD", "_TC")
|
schema = ifcopenshell.util.schema.get_schema_name_from_version(schema_version)
|
||||||
schema = "".join("".join(map(str, t)) if t[1] else "" for t in zip(prefixes, schema_version))
|
|
||||||
else:
|
else:
|
||||||
schema = {"IFC4X3": "IFC4X3_ADD2"}.get(schema, schema)
|
schema = ifcopenshell.util.schema.get_schema_identifier(schema)
|
||||||
return ifcopenshell_wrapper.schema_by_name(schema)
|
return ifcopenshell_wrapper.schema_by_name(schema)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -594,11 +594,12 @@ class file:
|
|||||||
# A poweruser testing out a particular version of IFC4X3
|
# A poweruser testing out a particular version of IFC4X3
|
||||||
model = ifcopenshell.file(schema_version=(4, 3, 0, 1))
|
model = ifcopenshell.file(schema_version=(4, 3, 0, 1))
|
||||||
"""
|
"""
|
||||||
|
import ifcopenshell.util.schema
|
||||||
|
|
||||||
if schema_version:
|
if schema_version:
|
||||||
prefixes = ("IFC", "X", "_ADD", "_TC")
|
schema = ifcopenshell.util.schema.get_schema_name_from_version(schema_version)
|
||||||
schema = "".join("".join(map(str, t)) if t[1] else "" for t in zip(prefixes, schema_version))
|
|
||||||
else:
|
else:
|
||||||
schema = {"IFC4X3": "IFC4X3_ADD2"}.get(schema, schema)
|
schema = ifcopenshell.util.schema.get_schema_identifier(schema)
|
||||||
if f is not None:
|
if f is not None:
|
||||||
self.wrapped_data = f
|
self.wrapped_data = f
|
||||||
if not f.good():
|
if not f.good():
|
||||||
|
|||||||
@@ -50,6 +50,21 @@ def get_fallback_schema(version: str) -> IFC_SCHEMA:
|
|||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
|
def get_schema_identifier(schema: IFC_SCHEMA) -> str:
|
||||||
|
"""Resolve a general schema name to the specific identifier used internally
|
||||||
|
(as in ``file.schema_identifier``).
|
||||||
|
|
||||||
|
E.g. ``IFC4X3`` -> ``IFC4X3_ADD2``.
|
||||||
|
"""
|
||||||
|
return {"IFC4X3": "IFC4X3_ADD2"}.get(schema, schema)
|
||||||
|
|
||||||
|
|
||||||
|
def get_schema_name_from_version(schema_version: tuple[int, ...]) -> str:
|
||||||
|
"""Build a schema name from a version tuple, e.g. (4, 3, 0, 1) -> "IFC4X3_TC1"."""
|
||||||
|
prefixes = ("IFC", "X", "_ADD", "_TC")
|
||||||
|
return "".join("".join(map(str, t)) if t[1] else "" for t in zip(prefixes, schema_version))
|
||||||
|
|
||||||
|
|
||||||
def get_declaration(element: ifcopenshell.entity_instance):
|
def get_declaration(element: ifcopenshell.entity_instance):
|
||||||
"""Get the schema declaration of an actively used entity instance
|
"""Get the schema declaration of an actively used entity instance
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user