Implement auto and manual refresh of the Brick model navigator

This commit is contained in:
Dion Moult
2022-01-11 14:46:58 +11:00
parent c6966f9b39
commit 49221739cf
9 changed files with 83 additions and 14 deletions
@@ -28,6 +28,7 @@ classes = (
operator.ConvertIfcToBrick,
operator.LoadBrickProject,
operator.NewBrickFile,
operator.RefreshBrickViewer,
operator.RewindBrickClass,
operator.ViewBrickClass,
operator.ViewBrickItem,
@@ -163,3 +163,12 @@ class NewBrickFile(bpy.types.Operator, Operator):
def _execute(self, context):
core.new_brick_file(tool.Brick)
class RefreshBrickViewer(bpy.types.Operator, Operator):
bl_idname = "bim.refresh_brick_viewer"
bl_label = "Refresh Brick Viewer"
bl_options = {"REGISTER", "UNDO"}
def _execute(self, context):
core.refresh_brick_viewer(tool.Brick)
@@ -44,6 +44,7 @@ class BIM_PT_brickschema(Panel):
if len(self.props.brick_breadcrumbs):
row.operator("bim.rewind_brick_class", text="", icon="FRAME_PREV")
row.label(text=self.props.active_brick_class)
row.operator("bim.refresh_brick_viewer", text="", icon="FILE_REFRESH")
row.operator("bim.close_brick_project", text="", icon="CANCEL")
row = self.layout.row(align=True)
+13 -1
View File
@@ -73,12 +73,14 @@ def add_brick(ifc, brick, obj=None, namespace=None, brick_class=None, library=No
brick_uri = brick.add_brick(product, namespace, brick_class)
if library:
brick.run_assign_brick_reference(obj=obj, library=library, brick_uri=brick_uri)
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.run_refresh_brick_viewer()
def convert_ifc_to_brick(brick, namespace=None, library=None):
@@ -86,8 +88,18 @@ def convert_ifc_to_brick(brick, namespace=None, library=None):
brick_class = brick.get_brick_class(element)
if not brick_class:
continue
brick.run_add_brick(obj=obj, namespace=namespace, brick_class=brick_class, library=library)
brick_uri = brick.add_brick(element, namespace, brick_class)
if library:
brick.run_assign_brick_reference(obj=obj, library=library, brick_uri=brick_uri)
brick.run_refresh_brick_viewer()
def new_brick_file(brick):
brick.new_brick_file()
brick.import_brick_classes("Class")
brick.set_active_brick_class("Class")
def refresh_brick_viewer(brick):
brick.run_view_brick_class(brick_class=brick.get_active_brick_class())
brick.pop_brick_breadcrumb()
+3 -1
View File
@@ -51,6 +51,7 @@ class Brick:
def clear_brick_browser(cls): pass
def clear_project(cls): pass
def export_brick_attributes(cls, brick_uri): pass
def get_active_brick_class(cls): pass
def get_brick(cls, element): pass
def get_brick_class(cls, element): pass
def get_brick_path(cls): pass
@@ -65,8 +66,9 @@ class Brick:
def load_brick_file(cls, filepath): pass
def new_brick_file(cls): pass
def pop_brick_breadcrumb(cls): pass
def run_add_brick(cls, obj=None, namespace=None, brick_class=None, library=None): pass
def run_assign_brick_reference(cls, obj=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
def set_active_brick_class(cls, brick_class): pass
+15 -7
View File
@@ -103,6 +103,10 @@ class Brick(blenderbim.core.tool.Brick):
else:
return {"Identification": brick_uri, "Name": brick_uri.split("#")[-1]}
@classmethod
def get_active_brick_class(cls):
return bpy.context.scene.BIMBrickProperties.active_brick_class
@classmethod
def get_brick(cls, element):
for rel in element.HasAssociations:
@@ -122,7 +126,9 @@ class Brick(blenderbim.core.tool.Brick):
@classmethod
def get_brick_path_name(cls):
return os.path.basename(BrickStore.path)
if BrickStore.path:
return os.path.basename(BrickStore.path)
return "Unnamed"
@classmethod
def get_brickifc_project(cls):
@@ -266,18 +272,20 @@ class Brick(blenderbim.core.tool.Brick):
bpy.context.scene.BIMBrickProperties.brick_breadcrumbs.remove(last_index)
return name
@classmethod
def run_add_brick(cls, obj=None, namespace=None, brick_class=None, library=None):
return blenderbim.core.brick.add_brick(
tool.Ifc, tool.Brick, obj=obj, namespace=namespace, brick_class=brick_class, library=library
)
@classmethod
def run_assign_brick_reference(cls, obj=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
)
@classmethod
def run_refresh_brick_viewer(cls):
return blenderbim.core.brick.refresh_brick_viewer(tool.Brick)
@classmethod
def run_view_brick_class(cls, brick_class=None):
return blenderbim.core.brick.view_brick_class(tool.Brick, brick_class=brick_class)
@classmethod
def select_browser_item(cls, item):
name = item.split("#")[-1]
@@ -109,3 +109,14 @@ Scenario: Convert IFC to brick
And I press "bim.assign_class"
When I press "bim.convert_ifc_to_brick"
Then nothing happens
Scenario: New brick file
Given an empty Blender session
When I press "bim.new_brick_file"
Then nothing happens
Scenario: Refresh brick viewer
Given an empty Blender session
And I press "bim.new_brick_file"
When I press "bim.refresh_brick_viewer"
Then nothing happens
+17 -3
View File
@@ -119,12 +119,14 @@ 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")
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.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")
@@ -135,6 +137,7 @@ class TestAddBrickFeed:
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.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")
@@ -142,18 +145,29 @@ 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.run_add_brick(
obj="obj", namespace="namespace", brick_class="brick_class", library="library"
).should_be_called()
brick.add_brick("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")
def test_not_converting_an_element_where_we_cannot_find_the_corresponding_brick_class(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(None)
brick.run_refresh_brick_viewer().should_be_called()
subject.convert_ifc_to_brick(brick, namespace="namespace", library="library")
class TestNewBrickFile:
def test_run(self, brick):
brick.new_brick_file().should_be_called()
brick.import_brick_classes("Class").should_be_called()
brick.set_active_brick_class("Class").should_be_called()
subject.new_brick_file(brick)
class TestRefreshBrickViewer:
def test_run(self, brick):
brick.get_active_brick_class().should_be_called().will_return("class")
brick.run_view_brick_class(brick_class="class").should_be_called()
brick.pop_brick_breadcrumb().should_be_called()
subject.refresh_brick_viewer(brick)
+13 -2
View File
@@ -169,6 +169,12 @@ class TestExportBrickAttributes(NewFile):
}
class TestGetActiveBrickClass(NewFile):
def test_run(self):
subject.set_active_brick_class("brick_class")
assert subject.get_active_brick_class() == "brick_class"
class TestGetBrick(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
@@ -326,12 +332,17 @@ class TestPopBrickBreadcrumb(NewFile):
assert bpy.context.scene.BIMBrickProperties.brick_breadcrumbs[0].name == "foo"
class TestRunAddBrick(NewFile):
class TestRunAssignBrickReference(NewFile):
def test_nothing(self):
pass
class TestRunAssignBrickReference(NewFile):
class TestRunRefreshBrickViewer(NewFile):
def test_nothing(self):
pass
class TestViewBrickClass(NewFile):
def test_nothing(self):
pass