Assigning a brick reference now adds a 2-way IFC reference in the Brick model

This commit is contained in:
Dion Moult
2021-12-09 17:45:08 +11:00
parent 78a36ab429
commit 2ef1f4d812
7 changed files with 203 additions and 6 deletions
@@ -30,3 +30,22 @@ Scenario: Close Brick project
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
When I press "bim.close_brick_project"
Then nothing happens
Scenario: Convert brick project
Given an empty IFC project
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
When I press "bim.convert_brick_project"
Then nothing happens
Scenario: Assign brick reference
Given an empty IFC project
And I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
And I press "bim.view_brick_item(item='https://brickschema.org/schema/Brick#Chiller')"
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_class" to "IfcChiller"
And I press "bim.assign_class"
And the object "IfcChiller/Cube" is selected
And I press "bim.convert_brick_project"
When I press "bim.assign_brick_reference"
Then nothing happens
+14
View File
@@ -92,10 +92,24 @@ class TestAssignBrickReference:
ifc.run("library.edit_reference", reference="reference", attributes="attributes").should_be_called()
ifc.get_entity("obj").should_be_called().will_return("product")
ifc.run("library.assign_reference", product="product", reference="reference").should_be_called()
brick.get_brickifc_project().should_be_called().will_return("project")
brick.add_brickifc_reference("brick", "product", "project").should_be_called()
subject.assign_brick_reference(ifc, brick, obj="obj", library="library", brick_uri="brick")
def test_assigning_to_an_existing_reference(self, ifc, brick):
brick.get_library_brick_reference("library", "brick").should_be_called().will_return("reference")
ifc.get_entity("obj").should_be_called().will_return("product")
ifc.run("library.assign_reference", product="product", reference="reference").should_be_called()
brick.get_brickifc_project().should_be_called().will_return("project")
brick.add_brickifc_reference("brick", "product", "project").should_be_called()
subject.assign_brick_reference(ifc, brick, obj="obj", library="library", brick_uri="brick")
def test_adding_a_brickifc_project_if_it_doesnt_exist(self, ifc, brick):
brick.get_library_brick_reference("library", "brick").should_be_called().will_return("reference")
ifc.get_entity("obj").should_be_called().will_return("product")
ifc.run("library.assign_reference", product="product", reference="reference").should_be_called()
brick.get_brickifc_project().should_be_called().will_return(None)
brick.get_namespace("brick").should_be_called().will_return("namespace")
brick.add_brickifc_project("namespace").should_be_called().will_return("project")
brick.add_brickifc_reference("brick", "product", "project").should_be_called()
subject.assign_brick_reference(ifc, brick, obj="obj", library="library", brick_uri="brick")
+72
View File
@@ -22,6 +22,8 @@ import brickschema
import ifcopenshell
import blenderbim.core.tool
import blenderbim.tool as tool
from rdflib.namespace import RDF
from rdflib import Literal, URIRef, Namespace
from test.bim.bootstrap import NewFile
from blenderbim.tool.brick import Brick as subject
from blenderbim.tool.brick import BrickStore
@@ -41,6 +43,62 @@ class TestAddBrickBreadcrumb(NewFile):
assert bpy.context.scene.BIMBrickProperties.brick_breadcrumbs[1].name == "brick_class"
class TestAddBrickifcProject(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
project = ifc.createIfcProject(ifcopenshell.guid.new())
project.Name = "My Project"
BrickStore.graph = brickschema.Graph()
result = subject.add_brickifc_project("http://example.org/digitaltwin#")
assert result == f"http://example.org/digitaltwin#{project.GlobalId}"
brick = URIRef(result)
assert list(
BrickStore.graph.triples((brick, RDF.type, URIRef("https://brickschema.org/extension/ifc#Project")))
)
assert list(
BrickStore.graph.triples(
(brick, URIRef("http://www.w3.org/2000/01/rdf-schema#label"), Literal("My Project"))
)
)
assert list(
BrickStore.graph.triples(
(brick, URIRef("https://brickschema.org/extension/ifc#projectID"), Literal(project.GlobalId))
)
)
assert list(
BrickStore.graph.triples(
(
brick,
URIRef("https://brickschema.org/extension/ifc#fileLocation"),
Literal(bpy.context.scene.BIMProperties.ifc_file),
)
)
)
class TestAddBrickifcReference(NewFile):
def test_run(self):
TestAddBrickifcProject().test_run()
element = tool.Ifc.get().createIfcChiller(ifcopenshell.guid.new())
project = URIRef(f"http://example.org/digitaltwin#{tool.Ifc.get().by_type('IfcProject')[0].GlobalId}")
subject.add_brickifc_reference("http://example.org/digitaltwin#foo", element, project)
brick = URIRef("http://example.org/digitaltwin#foo")
bnode = list(
BrickStore.graph.triples((brick, URIRef("https://brickschema.org/extension/ifc#hasIFCReference"), None))
)[0][2]
assert list(
BrickStore.graph.triples(
(bnode, URIRef("https://brickschema.org/extension/ifc#hasProjectReference"), project)
)
)
assert list(
BrickStore.graph.triples(
(bnode, URIRef("https://brickschema.org/extension/ifc#globalID"), Literal(element.GlobalId))
)
)
class TestClearBrickBrowser(NewFile):
def test_run(self):
bpy.context.scene.BIMBrickProperties.bricks.add()
@@ -81,6 +139,15 @@ class TestGetBrickPathName(NewFile):
assert subject.get_brick_path_name() == "spaces.ttl"
class TestGetBrickifcProject(NewFile):
def test_run(self):
TestAddBrickifcProject().test_run()
assert (
subject.get_brickifc_project()
== f"http://example.org/digitaltwin#{tool.Ifc.get().by_type('IfcProject')[0].GlobalId}"
)
class TestGetItemClass(NewFile):
def test_run(self):
TestLoadBrickFile().test_run()
@@ -102,6 +169,11 @@ class TestGetLibraryBrickReference(NewFile):
assert subject.get_library_brick_reference(library, "ex:#floor") == reference
class TestGetNamespace(NewFile):
def test_run(self):
assert subject.get_namespace("http://example.org/digitaltwin#globalid") == "http://example.org/digitaltwin#"
class TestImportBrickClasses(NewFile):
def test_run(self):
TestLoadBrickFile().test_run()