mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-10-03 13:28:19 +00:00
Implement adding plain bricks not based on IFC
This commit is contained in:
@@ -122,7 +122,9 @@ class AddBrick(bpy.types.Operator, Operator):
|
|||||||
core.add_brick(
|
core.add_brick(
|
||||||
tool.Ifc,
|
tool.Ifc,
|
||||||
tool.Brick,
|
tool.Brick,
|
||||||
obj=context.active_object,
|
obj=context.active_object
|
||||||
|
if context.selected_objects and tool.Ifc.get_entity(context.active_object)
|
||||||
|
else None,
|
||||||
namespace=props.namespace,
|
namespace=props.namespace,
|
||||||
brick_class=props.brick_equipment_class,
|
brick_class=props.brick_equipment_class,
|
||||||
library=library,
|
library=library,
|
||||||
|
|||||||
@@ -69,10 +69,13 @@ def assign_brick_reference(ifc, brick, obj=None, library=None, brick_uri=None):
|
|||||||
|
|
||||||
|
|
||||||
def add_brick(ifc, brick, obj=None, namespace=None, brick_class=None, library=None):
|
def add_brick(ifc, brick, obj=None, namespace=None, brick_class=None, library=None):
|
||||||
product = ifc.get_entity(obj)
|
if obj:
|
||||||
brick_uri = brick.add_brick(product, namespace, brick_class)
|
product = ifc.get_entity(obj)
|
||||||
if library:
|
brick_uri = brick.add_brick_from_element(product, namespace, brick_class)
|
||||||
brick.run_assign_brick_reference(obj=obj, library=library, brick_uri=brick_uri)
|
if library:
|
||||||
|
brick.run_assign_brick_reference(obj=obj, library=library, brick_uri=brick_uri)
|
||||||
|
else:
|
||||||
|
brick_uri = brick.add_brick(namespace, brick_class)
|
||||||
brick.run_refresh_brick_viewer()
|
brick.run_refresh_brick_viewer()
|
||||||
|
|
||||||
|
|
||||||
@@ -85,7 +88,7 @@ def add_brick_feed(ifc, brick, source=None, destination=None):
|
|||||||
|
|
||||||
def convert_ifc_to_brick(brick, namespace=None, library=None):
|
def convert_ifc_to_brick(brick, namespace=None, library=None):
|
||||||
for obj, element in brick.get_convertable_brick_objects_and_elements():
|
for obj, element in brick.get_convertable_brick_objects_and_elements():
|
||||||
brick_uri = brick.add_brick(element, namespace, brick.get_brick_class(element))
|
brick_uri = brick.add_brick_from_element(element, namespace, brick.get_brick_class(element))
|
||||||
if library:
|
if library:
|
||||||
brick.run_assign_brick_reference(obj=obj, library=library, brick_uri=brick_uri)
|
brick.run_assign_brick_reference(obj=obj, library=library, brick_uri=brick_uri)
|
||||||
brick.run_refresh_brick_viewer()
|
brick.run_refresh_brick_viewer()
|
||||||
|
|||||||
@@ -43,8 +43,9 @@ class Blender: pass
|
|||||||
|
|
||||||
@interface
|
@interface
|
||||||
class Brick:
|
class Brick:
|
||||||
def add_brick(cls, element, namespace, brick_class): pass
|
def add_brick(cls, namespace, brick_class): pass
|
||||||
def add_brick_breadcrumb(cls): pass
|
def add_brick_breadcrumb(cls): pass
|
||||||
|
def add_brick_from_element(cls, element, namespace, brick_class): pass
|
||||||
def add_brickifc_project(cls, namespace): pass
|
def add_brickifc_project(cls, namespace): pass
|
||||||
def add_brickifc_reference(cls, brick, element, project): pass
|
def add_brickifc_reference(cls, brick, element, project): pass
|
||||||
def add_feed(cls, source, destination): pass
|
def add_feed(cls, source, destination): pass
|
||||||
|
|||||||
@@ -35,12 +35,11 @@ except:
|
|||||||
|
|
||||||
class Brick(blenderbim.core.tool.Brick):
|
class Brick(blenderbim.core.tool.Brick):
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_brick(cls, element, namespace, brick_class):
|
def add_brick(cls, namespace, brick_class):
|
||||||
ns = Namespace(namespace)
|
ns = Namespace(namespace)
|
||||||
brick = ns[element.GlobalId]
|
brick = ns[ifcopenshell.guid.expand(ifcopenshell.guid.new())]
|
||||||
BrickStore.graph.add((brick, RDF.type, URIRef(brick_class)))
|
BrickStore.graph.add((brick, RDF.type, URIRef(brick_class)))
|
||||||
if element.Name:
|
BrickStore.graph.add((brick, URIRef("http://www.w3.org/2000/01/rdf-schema#label"), Literal("Unnamed")))
|
||||||
BrickStore.graph.add((brick, URIRef("http://www.w3.org/2000/01/rdf-schema#label"), Literal(element.Name)))
|
|
||||||
return str(brick)
|
return str(brick)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -48,6 +47,15 @@ class Brick(blenderbim.core.tool.Brick):
|
|||||||
new = bpy.context.scene.BIMBrickProperties.brick_breadcrumbs.add()
|
new = bpy.context.scene.BIMBrickProperties.brick_breadcrumbs.add()
|
||||||
new.name = bpy.context.scene.BIMBrickProperties.active_brick_class
|
new.name = bpy.context.scene.BIMBrickProperties.active_brick_class
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def add_brick_from_element(cls, element, namespace, brick_class):
|
||||||
|
ns = Namespace(namespace)
|
||||||
|
brick = ns[element.GlobalId]
|
||||||
|
BrickStore.graph.add((brick, RDF.type, URIRef(brick_class)))
|
||||||
|
if element.Name:
|
||||||
|
BrickStore.graph.add((brick, URIRef("http://www.w3.org/2000/01/rdf-schema#label"), Literal(element.Name)))
|
||||||
|
return str(brick)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_brickifc_project(cls, namespace):
|
def add_brickifc_project(cls, namespace):
|
||||||
project = tool.Ifc.get().by_type("IfcProject")[0]
|
project = tool.Ifc.get().by_type("IfcProject")[0]
|
||||||
@@ -263,6 +271,8 @@ class Brick(blenderbim.core.tool.Brick):
|
|||||||
BrickStore.schema.load_file(schema_path)
|
BrickStore.schema.load_file(schema_path)
|
||||||
BrickStore.graph = brickschema.Graph() + BrickStore.schema
|
BrickStore.graph = brickschema.Graph() + BrickStore.schema
|
||||||
BrickStore.graph.bind("digitaltwin", Namespace("https://example.org/digitaltwin#"))
|
BrickStore.graph.bind("digitaltwin", Namespace("https://example.org/digitaltwin#"))
|
||||||
|
BrickStore.graph.bind("brick", Namespace("https://brickschema.org/schema/Brick#"))
|
||||||
|
BrickStore.graph.bind("rdfs", Namespace("http://www.w3.org/2000/01/rdf-schema#"))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pop_brick_breadcrumb(cls):
|
def pop_brick_breadcrumb(cls):
|
||||||
|
|||||||
@@ -116,19 +116,24 @@ class TestAssignBrickReference:
|
|||||||
|
|
||||||
|
|
||||||
class TestAddBrick:
|
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")
|
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()
|
brick.run_refresh_brick_viewer().should_be_called()
|
||||||
subject.add_brick(ifc, brick, obj="obj", namespace="namespace", brick_class="brick_class", library=None)
|
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):
|
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")
|
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_assign_brick_reference(obj="obj", library="library", brick_uri="brick_uri").should_be_called()
|
||||||
brick.run_refresh_brick_viewer().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")
|
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:
|
class TestAddBrickFeed:
|
||||||
def test_run(self, ifc, brick):
|
def test_run(self, ifc, brick):
|
||||||
@@ -145,7 +150,7 @@ class TestConvertIfcToBrick:
|
|||||||
def test_run(self, brick):
|
def test_run(self, brick):
|
||||||
brick.get_convertable_brick_objects_and_elements().should_be_called().will_return([("obj", "element")])
|
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.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_assign_brick_reference(obj="obj", library="library", brick_uri="brick_uri").should_be_called()
|
||||||
brick.run_refresh_brick_viewer().should_be_called()
|
brick.run_refresh_brick_viewer().should_be_called()
|
||||||
subject.convert_ifc_to_brick(brick, namespace="namespace", library="library")
|
subject.convert_ifc_to_brick(brick, namespace="namespace", library="library")
|
||||||
|
|||||||
@@ -35,13 +35,39 @@ class TestImplementsTool(NewFile):
|
|||||||
|
|
||||||
|
|
||||||
class TestAddBrick(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):
|
def test_run(self):
|
||||||
ifc = ifcopenshell.file()
|
ifc = ifcopenshell.file()
|
||||||
element = ifc.createIfcChiller()
|
element = ifc.createIfcChiller()
|
||||||
element.Name = "Chiller"
|
element.Name = "Chiller"
|
||||||
element.GlobalId = ifcopenshell.guid.new()
|
element.GlobalId = ifcopenshell.guid.new()
|
||||||
BrickStore.graph = brickschema.Graph()
|
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"
|
element, "http://example.org/digitaltwin#", "https://brickschema.org/schema/Brick#Equipment"
|
||||||
)
|
)
|
||||||
uri = f"http://example.org/digitaltwin#{element.GlobalId}"
|
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):
|
class TestAddBrickifcProject(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
ifc = ifcopenshell.file()
|
ifc = ifcopenshell.file()
|
||||||
@@ -313,14 +330,12 @@ class TestNewBrickFile(NewFile):
|
|||||||
BrickStore.schema.load_file(schema_path)
|
BrickStore.schema.load_file(schema_path)
|
||||||
|
|
||||||
# This is the actual test
|
# This is the actual test
|
||||||
ns_alias = "digitaltwin"
|
|
||||||
ns_uri = "https://example.org/digitaltwin#"
|
|
||||||
subject.new_brick_file()
|
subject.new_brick_file()
|
||||||
assert BrickStore.graph
|
assert BrickStore.graph
|
||||||
for ns in BrickStore.graph.namespaces():
|
namespaces = [(ns[0], ns[1].toPython()) for ns in BrickStore.graph.namespaces()]
|
||||||
if ns[0] == ns_alias and ns[1].toPython() == ns_uri:
|
assert ("digitaltwin", "https://example.org/digitaltwin#") in namespaces
|
||||||
return
|
assert ("brick", "https://brickschema.org/schema/Brick#") in namespaces
|
||||||
assert False
|
assert ("rdfs", "http://www.w3.org/2000/01/rdf-schema#") in namespaces
|
||||||
|
|
||||||
|
|
||||||
class TestPopBrickBreadcrumb(NewFile):
|
class TestPopBrickBreadcrumb(NewFile):
|
||||||
|
|||||||
Reference in New Issue
Block a user