mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
Support type-based class checking for converting IFC2X3 models to Brickschema
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import os
|
||||
import json
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||
@@ -11,22 +13,27 @@ with open(os.path.join(cwd, "ifc4_to_brick.json")) as f:
|
||||
|
||||
|
||||
def get_brick_type(element):
|
||||
predefined_type = getattr(element, "PredefinedType", None)
|
||||
result = None
|
||||
predefined_type = ifcopenshell.util.element.get_predefined_type(element)
|
||||
if predefined_type:
|
||||
result = ifc4_to_brick_map.get(f"{element.is_a()}.{predefined_type}", None)
|
||||
if not result:
|
||||
result = ifc4_to_brick_map.get(element.is_a(), None)
|
||||
if not result:
|
||||
element_type = ifcopenshell.util.element.get_type(element)
|
||||
if element_type:
|
||||
ifc_type_class = element_type.is_a().replace("Type", "")
|
||||
result = ifc4_to_brick_map.get(f"{ifc_type_class}.{predefined_type}", None)
|
||||
if not result:
|
||||
result = ifc4_to_brick_map.get(ifc_type_class, None)
|
||||
if result:
|
||||
return f"https://brickschema.org/schema/Brick#{result}"
|
||||
# We choose equipment as a generic fallback
|
||||
return f"https://brickschema.org/schema/Brick#Equipment"
|
||||
|
||||
|
||||
def get_brick_elements(ifc_file):
|
||||
classes = {c.split(".")[0] for c in ifc4_to_brick_map.keys()}
|
||||
elements = []
|
||||
for ifc_class in classes:
|
||||
try:
|
||||
elements += ifc_file.by_type(ifc_class)
|
||||
except:
|
||||
pass
|
||||
elements = set(ifc_file.by_type("IfcDistributionElement"))
|
||||
elements = elements.difference(ifc_file.by_type("IfcFlowSegment"))
|
||||
elements = elements.difference(ifc_file.by_type("IfcFlowFitting"))
|
||||
return elements
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import pytest
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.brick as subject
|
||||
|
||||
|
||||
@@ -9,10 +10,20 @@ class TestGetBrickTypeIFC4(test.bootstrap.IFC4):
|
||||
assert subject.get_brick_type(element) == "https://brickschema.org/schema/Brick#TerminalUnit"
|
||||
element.PredefinedType = "CONSTANTFLOW"
|
||||
assert subject.get_brick_type(element) == "https://brickschema.org/schema/Brick#CAV"
|
||||
element = self.file.createIfcEngine()
|
||||
assert subject.get_brick_type(element) == "https://brickschema.org/schema/Brick#Equipment"
|
||||
|
||||
|
||||
class TestGetBrickTypeIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_run(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowController")
|
||||
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcAirTerminalBoxType")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=type_element)
|
||||
assert subject.get_brick_type(element) == "https://brickschema.org/schema/Brick#TerminalUnit"
|
||||
|
||||
|
||||
class TestGetBrickElementsIFC4(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
element = self.file.createIfcAirTerminalBox()
|
||||
self.file.createIfcWall()
|
||||
assert subject.get_brick_elements(self.file) == [element]
|
||||
assert subject.get_brick_elements(self.file) == {element}
|
||||
|
||||
Reference in New Issue
Block a user