Implement adding plain bricks not based on IFC

This commit is contained in:
Dion Moult
2022-01-12 16:22:32 +11:00
parent 39960998de
commit 5ba542488a
6 changed files with 67 additions and 31 deletions
+9 -4
View File
@@ -116,19 +116,24 @@ class TestAssignBrickReference:
class TestAddBrick:
def test_adding_a_brick(self, ifc, brick):
def test_adding_a_brick_from_an_element(self, ifc, brick):
ifc.get_entity("obj").should_be_called().will_return("product")
brick.add_brick("product", "namespace", "brick_class").should_be_called().will_return("brick_uri")
brick.add_brick_from_element("product", "namespace", "brick_class").should_be_called().will_return("brick_uri")
brick.run_refresh_brick_viewer().should_be_called()
subject.add_brick(ifc, brick, obj="obj", namespace="namespace", brick_class="brick_class", library=None)
def test_adding_a_brick_an_auto_assigning_it_to_the_ifc_element(self, ifc, brick):
ifc.get_entity("obj").should_be_called().will_return("product")
brick.add_brick("product", "namespace", "brick_class").should_be_called().will_return("brick_uri")
brick.add_brick_from_element("product", "namespace", "brick_class").should_be_called().will_return("brick_uri")
brick.run_assign_brick_reference(obj="obj", library="library", brick_uri="brick_uri").should_be_called()
brick.run_refresh_brick_viewer().should_be_called()
subject.add_brick(ifc, brick, obj="obj", namespace="namespace", brick_class="brick_class", library="library")
def test_adding_a_plain_brick(self, ifc, brick):
brick.add_brick("namespace", "brick_class").should_be_called()
brick.run_refresh_brick_viewer().should_be_called()
subject.add_brick(ifc, brick, obj=None, namespace="namespace", brick_class="brick_class", library=None)
class TestAddBrickFeed:
def test_run(self, ifc, brick):
@@ -145,7 +150,7 @@ class TestConvertIfcToBrick:
def test_run(self, brick):
brick.get_convertable_brick_objects_and_elements().should_be_called().will_return([("obj", "element")])
brick.get_brick_class("element").should_be_called().will_return("brick_class")
brick.add_brick("element", "namespace", "brick_class").should_be_called().will_return("brick_uri")
brick.add_brick_from_element("element", "namespace", "brick_class").should_be_called().will_return("brick_uri")
brick.run_assign_brick_reference(obj="obj", library="library", brick_uri="brick_uri").should_be_called()
brick.run_refresh_brick_viewer().should_be_called()
subject.convert_ifc_to_brick(brick, namespace="namespace", library="library")
+31 -16
View File
@@ -35,13 +35,39 @@ class TestImplementsTool(NewFile):
class TestAddBrick(NewFile):
def test_run(self):
BrickStore.graph = brickschema.Graph()
result = subject.add_brick(
"http://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment"
)
assert "http://example.org/digitaltwin#" in result
assert list(
BrickStore.graph.triples((URIRef(result), RDF.type, URIRef("https://brickschema.org/schema/Brick#Equipment")))
)
assert list(
BrickStore.graph.triples(
(URIRef(result), URIRef("http://www.w3.org/2000/01/rdf-schema#label"), Literal("Unnamed"))
)
)
class TestAddBrickBreadcrumb(NewFile):
def test_run(self):
subject.set_active_brick_class("brick_class")
subject.add_brick_breadcrumb()
assert bpy.context.scene.BIMBrickProperties.brick_breadcrumbs[0].name == "brick_class"
subject.add_brick_breadcrumb()
assert bpy.context.scene.BIMBrickProperties.brick_breadcrumbs[1].name == "brick_class"
class TestAddBrickFromElement(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
element = ifc.createIfcChiller()
element.Name = "Chiller"
element.GlobalId = ifcopenshell.guid.new()
BrickStore.graph = brickschema.Graph()
result = subject.add_brick(
result = subject.add_brick_from_element(
element, "http://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment"
)
uri = f"http://example.org/digitaltwin#{element.GlobalId}"
@@ -56,15 +82,6 @@ class TestAddBrick(NewFile):
)
class TestAddBrickBreadcrumb(NewFile):
def test_run(self):
subject.set_active_brick_class("brick_class")
subject.add_brick_breadcrumb()
assert bpy.context.scene.BIMBrickProperties.brick_breadcrumbs[0].name == "brick_class"
subject.add_brick_breadcrumb()
assert bpy.context.scene.BIMBrickProperties.brick_breadcrumbs[1].name == "brick_class"
class TestAddBrickifcProject(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
@@ -313,14 +330,12 @@ class TestNewBrickFile(NewFile):
BrickStore.schema.load_file(schema_path)
# This is the actual test
ns_alias = "digitaltwin"
ns_uri = "https://example.org/digitaltwin#"
subject.new_brick_file()
assert BrickStore.graph
for ns in BrickStore.graph.namespaces():
if ns[0] == ns_alias and ns[1].toPython() == ns_uri:
return
assert False
namespaces = [(ns[0], ns[1].toPython()) for ns in BrickStore.graph.namespaces()]
assert ("digitaltwin", "https://example.org/digitaltwin#") in namespaces
assert ("brick", "https://brickschema.org/schema/Brick#") in namespaces
assert ("rdfs", "http://www.w3.org/2000/01/rdf-schema#") in namespaces
class TestPopBrickBreadcrumb(NewFile):