See #4838. Consistently use schema_identifiers throughout the code instead of schema to be more explicit.

This also means in the future we are better shaped to be a prototyping platform for future IFC versions.
This commit is contained in:
Dion Moult
2024-06-15 14:05:37 +10:00
parent 9f356542bc
commit cad7db0162
5 changed files with 16 additions and 17 deletions
+2 -2
View File
@@ -74,7 +74,7 @@ class IfcStore:
last_transaction = ""
history: list[TransactionStep] = []
future: list[TransactionStep] = []
schema_identifiers = ["IFC4", "IFC2X3", "IFC4X3"]
schema_identifiers = ["IFC4", "IFC2X3", "IFC4X3_ADD2"]
session_files: dict[str, ifcopenshell.file] = {}
@staticmethod
@@ -94,7 +94,7 @@ class IfcStore:
IfcStore.last_transaction = ""
IfcStore.history = []
IfcStore.future = []
IfcStore.schema_identifiers = ["IFC4", "IFC2X3", "IFC4X3"]
IfcStore.schema_identifiers = ["IFC4", "IFC2X3", "IFC4X3_ADD2"]
IfcStore.session_files = {}
@staticmethod
@@ -43,7 +43,7 @@ class ProjectData:
@classmethod
def get_export_schema(cls):
return [(s, s, "") for s in IfcStore.schema_identifiers]
return [(s, "IFC4X3" if s == "IFC4X3_ADD2" else s, "") for s in IfcStore.schema_identifiers]
@classmethod
def library_file(cls):
@@ -116,7 +116,6 @@ class CreateProject(bpy.types.Operator):
def _execute(self, context):
props = context.scene.BIMProjectProperties
template = None if props.template_file == "0" else props.template_file
blenderbim.bim.schema.reload(props.export_schema)
if tool.Blender.is_default_scene():
for obj in bpy.data.objects:
bpy.data.objects.remove(obj)
@@ -125,6 +124,7 @@ class CreateProject(bpy.types.Operator):
for mat in bpy.data.materials:
bpy.data.materials.remove(mat)
core.create_project(tool.Ifc, tool.Project, tool.Spatial, schema=props.export_schema, template=template)
blenderbim.bim.schema.reload(tool.Ifc.get().schema_identifier)
tool.Blender.register_toolbar()
def rollback(self, data):
+7 -8
View File
@@ -27,11 +27,10 @@ cwd = os.path.dirname(os.path.realpath(__file__))
class IfcSchema:
def __init__(self, schema_name="IFC4"):
schema_name = schema_name.upper()
if schema_name not in ("IFC2X3", "IFC4", "IFC4X3"):
schema_name = "IFC4"
self.schema_name = schema_name
def __init__(self, schema_identifier="IFC4"):
if schema_identifier not in ("IFC2X3", "IFC4", "IFC4X3_ADD2"):
schema_identifier = "IFC4"
self.schema_identifier = schema_identifier
self.schema_dir = Path(cwd).joinpath("schema")
self.data_dir = Path(cwd).joinpath("data")
@@ -55,7 +54,7 @@ class IfcSchema:
def load_pset_templates(self):
property_paths = self.data_dir.joinpath("pset").glob("*.ifc")
self.psetqto = ifcopenshell.util.pset.get_template(self.schema_name)
self.psetqto = ifcopenshell.util.pset.get_template(self.schema_identifier)
# Keep only the first template, which is the official buildingSMART one
self.psetqto.templates = self.psetqto.templates[0:1]
self.psetqto.get_applicable.cache_clear()
@@ -96,6 +95,6 @@ class IfcSchema:
ifc = IfcSchema()
def reload(schema_name):
def reload(schema_identifier):
global ifc
ifc = IfcSchema(schema_name)
ifc = IfcSchema(schema_identifier)
@@ -40,19 +40,19 @@ class PsetQto:
templates_path = {
"IFC2X3": "Pset_IFC2X3.ifc",
"IFC4": "Pset_IFC4_ADD2.ifc",
"IFC4X3": "Pset_IFC4X3.ifc"
"IFC4X3_ADD2": "Pset_IFC4X3.ifc"
}
# fmt: on
def __init__(self, schema: str, templates=None) -> None:
self.schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(schema)
def __init__(self, schema_identifier: str, templates=None) -> None:
self.schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(schema_identifier)
if not templates:
folder_path = pathlib.Path(__file__).parent.absolute()
path = str(folder_path.joinpath("schema", self.templates_path[schema]))
path = str(folder_path.joinpath("schema", self.templates_path[schema_identifier]))
templates = [ifcopenshell.open(path)]
# See bug 3583. We backport this change from IFC4X3 because it just makes sense.
# Users aren't forced to use it.
if schema == "IFC4":
if schema_identifier == "IFC4":
for element in templates[0].by_type("IfcPropertySetTemplate"):
if element.TemplateType == "QTO_OCCURRENCEDRIVEN":
element.TemplateType = "QTO_TYPEDRIVENOVERRIDE"