mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Minor cleanup to Brick code after failed attempt to detect feed relationships.
This commit is contained in:
@@ -103,7 +103,7 @@ class AssignBrickReference(bpy.types.Operator, Operator):
|
||||
core.assign_brick_reference(
|
||||
tool.Ifc,
|
||||
tool.Brick,
|
||||
obj=context.active_object,
|
||||
element=tool.Ifc.get_entity(context.active_object),
|
||||
library=tool.Ifc.get().by_id(int(props.libraries)),
|
||||
brick_uri=props.bricks[props.active_brick_index].uri,
|
||||
)
|
||||
@@ -122,9 +122,7 @@ class AddBrick(bpy.types.Operator, Operator):
|
||||
core.add_brick(
|
||||
tool.Ifc,
|
||||
tool.Brick,
|
||||
obj=context.active_object
|
||||
if context.selected_objects and tool.Ifc.get_entity(context.active_object)
|
||||
else None,
|
||||
element=tool.Ifc.get_entity(context.active_object) if context.selected_objects else None,
|
||||
namespace=props.namespace,
|
||||
brick_class=props.brick_equipment_class,
|
||||
library=library,
|
||||
@@ -137,11 +135,13 @@ class AddBrickFeed(bpy.types.Operator, Operator):
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def _execute(self, context):
|
||||
source = tool.Ifc.get_entity([o for o in context.selected_objects if o != context.active_object][0])
|
||||
destination = tool.Ifc.get_entity(context.active_object)
|
||||
core.add_brick_feed(
|
||||
tool.Ifc,
|
||||
tool.Brick,
|
||||
source=[o for o in context.selected_objects if o != context.active_object][0],
|
||||
destination=context.active_object,
|
||||
source=source,
|
||||
destination=destination,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -55,42 +55,39 @@ def convert_brick_project(ifc, brick):
|
||||
ifc.run("library.edit_library", library=library, attributes={"Location": brick.get_brick_path()})
|
||||
|
||||
|
||||
def assign_brick_reference(ifc, brick, obj=None, library=None, brick_uri=None):
|
||||
def assign_brick_reference(ifc, brick, element=None, library=None, brick_uri=None):
|
||||
reference = brick.get_library_brick_reference(library, brick_uri)
|
||||
if not reference:
|
||||
reference = ifc.run("library.add_reference", library=library)
|
||||
ifc.run("library.edit_reference", reference=reference, attributes=brick.export_brick_attributes(brick_uri))
|
||||
product = ifc.get_entity(obj)
|
||||
ifc.run("library.assign_reference", product=product, reference=reference)
|
||||
ifc.run("library.assign_reference", product=element, reference=reference)
|
||||
project = brick.get_brickifc_project()
|
||||
if not project:
|
||||
project = brick.add_brickifc_project(brick.get_namespace(brick_uri))
|
||||
brick.add_brickifc_reference(brick_uri, product, project)
|
||||
brick.add_brickifc_reference(brick_uri, element, project)
|
||||
|
||||
|
||||
def add_brick(ifc, brick, obj=None, namespace=None, brick_class=None, library=None):
|
||||
if obj:
|
||||
product = ifc.get_entity(obj)
|
||||
brick_uri = brick.add_brick_from_element(product, namespace, brick_class)
|
||||
def add_brick(ifc, brick, element=None, namespace=None, brick_class=None, library=None):
|
||||
if element:
|
||||
brick_uri = brick.add_brick_from_element(element, namespace, brick_class)
|
||||
if library:
|
||||
brick.run_assign_brick_reference(obj=obj, library=library, brick_uri=brick_uri)
|
||||
brick.run_assign_brick_reference(element=element, library=library, brick_uri=brick_uri)
|
||||
else:
|
||||
brick_uri = brick.add_brick(namespace, brick_class)
|
||||
brick.run_refresh_brick_viewer()
|
||||
|
||||
|
||||
def add_brick_feed(ifc, brick, source=None, destination=None):
|
||||
source_element = ifc.get_entity(source)
|
||||
destination_element = ifc.get_entity(destination)
|
||||
brick.add_feed(brick.get_brick(source_element), brick.get_brick(destination_element))
|
||||
brick.add_feed(brick.get_brick(source), brick.get_brick(destination))
|
||||
brick.run_refresh_brick_viewer()
|
||||
|
||||
|
||||
def convert_ifc_to_brick(brick, namespace=None, library=None):
|
||||
for obj, element in brick.get_convertable_brick_objects_and_elements():
|
||||
distribution_elements = brick.get_convertable_brick_elements()
|
||||
for element in distribution_elements:
|
||||
brick_uri = brick.add_brick_from_element(element, namespace, brick.get_brick_class(element))
|
||||
if library:
|
||||
brick.run_assign_brick_reference(obj=obj, library=library, brick_uri=brick_uri)
|
||||
brick.run_assign_brick_reference(element=element, library=library, brick_uri=brick_uri)
|
||||
brick.run_refresh_brick_viewer()
|
||||
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class Brick:
|
||||
def get_brick_path(cls): pass
|
||||
def get_brick_path_name(cls): pass
|
||||
def get_brickifc_project(cls): pass
|
||||
def get_convertable_brick_objects_and_elements(cls): pass
|
||||
def get_convertable_brick_elements(cls): pass
|
||||
def get_item_class(cls, item): pass
|
||||
def get_library_brick_reference(cls, library, brick_uri): pass
|
||||
def get_namespace(cls, uri): pass
|
||||
@@ -67,7 +67,7 @@ class Brick:
|
||||
def load_brick_file(cls, filepath): pass
|
||||
def new_brick_file(cls): pass
|
||||
def pop_brick_breadcrumb(cls): pass
|
||||
def run_assign_brick_reference(cls, obj=None, library=None, brick_uri=None): pass
|
||||
def run_assign_brick_reference(cls, element=None, library=None, brick_uri=None): pass
|
||||
def run_refresh_brick_viewer(cls): pass
|
||||
def run_view_brick_class(cls, brick_class=None): pass
|
||||
def select_browser_item(cls, item): pass
|
||||
|
||||
@@ -20,6 +20,7 @@ import os
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.brick
|
||||
import ifcopenshell.util.system
|
||||
import blenderbim.core.tool
|
||||
import blenderbim.tool as tool
|
||||
|
||||
@@ -158,13 +159,8 @@ class Brick(blenderbim.core.tool.Brick):
|
||||
return results[0][0].toPython()
|
||||
|
||||
@classmethod
|
||||
def get_convertable_brick_objects_and_elements(cls):
|
||||
results = []
|
||||
for element in ifcopenshell.util.brick.get_brick_elements(tool.Ifc.get()):
|
||||
obj = tool.Ifc.get_object(element)
|
||||
if obj:
|
||||
results.append((obj, element))
|
||||
return results
|
||||
def get_convertable_brick_elements(cls):
|
||||
return ifcopenshell.util.brick.get_brick_elements(tool.Ifc.get())
|
||||
|
||||
@classmethod
|
||||
def get_item_class(cls, item):
|
||||
@@ -283,9 +279,13 @@ class Brick(blenderbim.core.tool.Brick):
|
||||
return name
|
||||
|
||||
@classmethod
|
||||
def run_assign_brick_reference(cls, obj=None, library=None, brick_uri=None):
|
||||
def run_add_brick_feed(source=None, destination=None):
|
||||
return blenderbim.core.brick.add_brick_feed(tool.Ifc, tool.Brick, source=source, destination=destination)
|
||||
|
||||
@classmethod
|
||||
def run_assign_brick_reference(cls, element=None, library=None, brick_uri=None):
|
||||
return blenderbim.core.brick.assign_brick_reference(
|
||||
tool.Ifc, tool.Brick, obj=obj, library=library, brick_uri=brick_uri
|
||||
tool.Ifc, tool.Brick, element=element, library=library, brick_uri=brick_uri
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -90,57 +90,50 @@ class TestAssignBrickReference:
|
||||
ifc.run("library.add_reference", library="library").should_be_called().will_return("reference")
|
||||
brick.export_brick_attributes("brick").should_be_called().will_return("attributes")
|
||||
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()
|
||||
ifc.run("library.assign_reference", product="element", 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")
|
||||
brick.add_brickifc_reference("brick", "element", "project").should_be_called()
|
||||
subject.assign_brick_reference(ifc, brick, element="element", 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()
|
||||
ifc.run("library.assign_reference", product="element", 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")
|
||||
brick.add_brickifc_reference("brick", "element", "project").should_be_called()
|
||||
subject.assign_brick_reference(ifc, brick, element="element", 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()
|
||||
ifc.run("library.assign_reference", product="element", 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")
|
||||
brick.add_brickifc_reference("brick", "element", "project").should_be_called()
|
||||
subject.assign_brick_reference(ifc, brick, element="element", library="library", brick_uri="brick")
|
||||
|
||||
|
||||
class TestAddBrick:
|
||||
def test_adding_a_brick_from_an_element(self, ifc, brick):
|
||||
ifc.get_entity("obj").should_be_called().will_return("product")
|
||||
brick.add_brick_from_element("product", "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_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, element="element", 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_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.add_brick_from_element("element", "namespace", "brick_class").should_be_called().will_return("brick_uri")
|
||||
brick.run_assign_brick_reference(element="element", 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")
|
||||
subject.add_brick(ifc, brick, element="element", 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)
|
||||
subject.add_brick(ifc, brick, element=None, namespace="namespace", brick_class="brick_class", library=None)
|
||||
|
||||
|
||||
class TestAddBrickFeed:
|
||||
def test_run(self, ifc, brick):
|
||||
ifc.get_entity("source").should_be_called().will_return("source_element")
|
||||
ifc.get_entity("destination").should_be_called().will_return("destination_element")
|
||||
brick.get_brick("source_element").should_be_called().will_return("source_brick")
|
||||
brick.get_brick("destination_element").should_be_called().will_return("destination_brick")
|
||||
brick.get_brick("source").should_be_called().will_return("source_brick")
|
||||
brick.get_brick("destination").should_be_called().will_return("destination_brick")
|
||||
brick.add_feed("source_brick", "destination_brick").should_be_called()
|
||||
brick.run_refresh_brick_viewer().should_be_called()
|
||||
subject.add_brick_feed(ifc, brick, source="source", destination="destination")
|
||||
@@ -148,10 +141,10 @@ class TestAddBrickFeed:
|
||||
|
||||
class TestConvertIfcToBrick:
|
||||
def test_run(self, brick):
|
||||
brick.get_convertable_brick_objects_and_elements().should_be_called().will_return([("obj", "element")])
|
||||
brick.get_convertable_brick_elements().should_be_called().will_return(["element"])
|
||||
brick.get_brick_class("element").should_be_called().will_return("brick_class")
|
||||
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(element="element", 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")
|
||||
|
||||
|
||||
@@ -238,15 +238,13 @@ class TestGetBrickifcProject(NewFile):
|
||||
)
|
||||
|
||||
|
||||
class TestGetConvertableBrickObjectsAndElements(NewFile):
|
||||
class TestGetConvertableBrickElements(NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
element = ifc.createIfcAirTerminalBox()
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(element, obj)
|
||||
ifc.createIfcWall()
|
||||
assert subject.get_convertable_brick_objects_and_elements() == [(obj, element)]
|
||||
assert subject.get_convertable_brick_elements() == {element}
|
||||
|
||||
|
||||
class TestGetItemClass(NewFile):
|
||||
|
||||
Reference in New Issue
Block a user