From an IFC element, you can now add a new Brick element in a Brick model

This commit is contained in:
Dion Moult
2021-12-09 17:48:47 +11:00
parent 2ef1f4d812
commit d156927e13
12 changed files with 183 additions and 24 deletions
@@ -49,3 +49,28 @@ Scenario: Assign brick reference
And I press "bim.convert_brick_project"
When I press "bim.assign_brick_reference"
Then nothing happens
Scenario: Add brick - without a brick IFC library
Given an empty IFC project
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 I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
And the object "IfcChiller/Cube" is selected
And I set "scene.BIMBrickProperties.namespace" to "http://example.org/digitaltwin#"
When I press "bim.add_brick"
Then nothing happens
Scenario: Add brick - with a brick IFC library
Given an empty IFC project
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 I press "bim.load_brick_project(filepath='{cwd}/test/files/spaces.ttl')"
And I press "bim.convert_brick_project"
And the object "IfcChiller/Cube" is selected
And I set "scene.BIMBrickProperties.namespace" to "http://example.org/digitaltwin#"
When I press "bim.add_brick"
Then nothing happens
+13
View File
@@ -113,3 +113,16 @@ class TestAssignBrickReference:
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")
class TestAddBrick:
def test_adding_a_brick(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")
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.run_assign_brick_reference(obj="obj", library="library", brick_uri="brick_uri").should_be_called()
subject.add_brick(ifc, brick, obj="obj", namespace="namespace", brick_class="brick_class", library="library")
+13 -13
View File
@@ -1,24 +1,24 @@
@prefix : <ex:#> .
@prefix digitaltwin: <http://example.org/digitaltwin#> .
@prefix brick: <https://brickschema.org/schema/Brick#> .
@prefix unit: <http://qudt.org/vocab/unit/> .
:site a brick:Site ;
digitaltwin:site a brick:Site ;
brick:buildingPrimaryFunction [ brick:value "Library" ] ;
brick:hasPart :bldg .
brick:hasPart digitaltwin:bldg .
:bldg a brick:Building ;
brick:hasPart :floor .
digitaltwin:bldg a brick:Building ;
brick:hasPart digitaltwin:floor .
:floor a brick:Floor ;
digitaltwin:floor a brick:Floor ;
brick:area [ brick:value 5000 ; brick:hasUnit unit:M_2 ] ;
brick:hasPart :space, :hvac_zone, :lighting_zone_1, :lighting_zone_2 .
brick:hasPart digitaltwin:space, digitaltwin:hvac_zone, digitaltwin:lighting_zone_1, digitaltwin:lighting_zone_2 .
:space a brick:Space ;
digitaltwin:space a brick:Space ;
brick:netArea [ brick:value 500 ; brick:hasUnit unit:M_2 ] ;
brick:grossArea [ brick:value 650 ; brick:hasUnit unit:M_2 ] ;
brick:isPartOf :hvac_zone ;
brick:hasPart :lighting_zone_1, :lighting_zone_2 .
brick:isPartOf digitaltwin:hvac_zone ;
brick:hasPart digitaltwin:lighting_zone_1, digitaltwin:lighting_zone_2 .
:hvac_zone a brick:HVAC_Zone .
:lighting_zone_1 a brick:Lighting_Zone .
:lighting_zone_2 a brick:Lighting_Zone .
digitaltwin:hvac_zone a brick:HVAC_Zone .
digitaltwin:lighting_zone_1 a brick:Lighting_Zone .
digitaltwin:lighting_zone_2 a brick:Lighting_Zone .
+35 -8
View File
@@ -34,6 +34,28 @@ class TestImplementsTool(NewFile):
assert isinstance(subject(), blenderbim.core.tool.Brick)
class TestAddBrick(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(
element, "http://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment"
)
uri = f"http://example.org/digitaltwin#{element.GlobalId}"
assert result == uri
assert list(
BrickStore.graph.triples((URIRef(uri), RDF.type, URIRef("https://brickschema.org/schema/Brick#Equipment")))
)
assert list(
BrickStore.graph.triples(
(URIRef(uri), URIRef("http://www.w3.org/2000/01/rdf-schema#label"), Literal("Chiller"))
)
)
class TestAddBrickBreadcrumb(NewFile):
def test_run(self):
subject.set_active_brick_class("brick_class")
@@ -119,11 +141,11 @@ class TestClearProject(NewFile):
class TestExportBrickAttributes(NewFile):
def test_run(self):
assert subject.export_brick_attributes("ex:#floor") == {"Identification": "ex:#floor", "Name": "floor"}
assert subject.export_brick_attributes("http://example.org/digitaltwin#floor") == {"Identification": "http://example.org/digitaltwin#floor", "Name": "floor"}
def test_run_ifc2x3(self):
tool.Ifc.set(ifcopenshell.file(schema="IFC2X3"))
assert subject.export_brick_attributes("ex:#floor") == {"ItemReference": "ex:#floor", "Name": "floor"}
assert subject.export_brick_attributes("http://example.org/digitaltwin#floor") == {"ItemReference": "http://example.org/digitaltwin#floor", "Name": "floor"}
class TestGetBrickPath(NewFile):
@@ -151,22 +173,22 @@ class TestGetBrickifcProject(NewFile):
class TestGetItemClass(NewFile):
def test_run(self):
TestLoadBrickFile().test_run()
assert subject.get_item_class("ex:#floor") == "Floor"
assert subject.get_item_class("http://example.org/digitaltwin#floor") == "Floor"
class TestGetLibraryBrickReference(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
library = ifc.createIfcLibraryInformation()
reference = ifc.createIfcLibraryReference(Identification="ex:#floor", ReferencedLibrary=library)
assert subject.get_library_brick_reference(library, "ex:#floor") == reference
reference = ifc.createIfcLibraryReference(Identification="http://example.org/digitaltwin#floor", ReferencedLibrary=library)
assert subject.get_library_brick_reference(library, "http://example.org/digitaltwin#floor") == reference
def test_run_ifc2x3(self):
ifc = ifcopenshell.file(schema="IFC2X3")
tool.Ifc.set(ifc)
reference = ifc.createIfcLibraryReference(ItemReference="ex:#floor")
reference = ifc.createIfcLibraryReference(ItemReference="http://example.org/digitaltwin#floor")
library = ifc.createIfcLibraryInformation(LibraryReference=[reference])
assert subject.get_library_brick_reference(library, "ex:#floor") == reference
assert subject.get_library_brick_reference(library, "http://example.org/digitaltwin#floor") == reference
class TestGetNamespace(NewFile):
@@ -196,7 +218,7 @@ class TestImportBrickItems(NewFile):
assert len(bpy.context.scene.BIMBrickProperties.bricks) == 1
brick = bpy.context.scene.BIMBrickProperties.bricks[0]
assert brick.name == "bldg"
assert brick.uri == "ex:#bldg"
assert brick.uri == "http://example.org/digitaltwin#bldg"
assert brick.total_items == 0
@@ -224,6 +246,11 @@ class TestPopBrickBreadcrumb(NewFile):
assert bpy.context.scene.BIMBrickProperties.brick_breadcrumbs[0].name == "foo"
class TestRunAssignBrickReference(NewFile):
def test_nothing(self):
pass
class TestSelectBrowserItem(NewFile):
def test_run(self):
subject.set_active_brick_class("brick_class")