mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
Implement auto and manual refresh of the Brick model navigator
This commit is contained in:
@@ -28,6 +28,7 @@ classes = (
|
|||||||
operator.ConvertIfcToBrick,
|
operator.ConvertIfcToBrick,
|
||||||
operator.LoadBrickProject,
|
operator.LoadBrickProject,
|
||||||
operator.NewBrickFile,
|
operator.NewBrickFile,
|
||||||
|
operator.RefreshBrickViewer,
|
||||||
operator.RewindBrickClass,
|
operator.RewindBrickClass,
|
||||||
operator.ViewBrickClass,
|
operator.ViewBrickClass,
|
||||||
operator.ViewBrickItem,
|
operator.ViewBrickItem,
|
||||||
|
|||||||
@@ -163,3 +163,12 @@ class NewBrickFile(bpy.types.Operator, Operator):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
core.new_brick_file(tool.Brick)
|
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):
|
if len(self.props.brick_breadcrumbs):
|
||||||
row.operator("bim.rewind_brick_class", text="", icon="FRAME_PREV")
|
row.operator("bim.rewind_brick_class", text="", icon="FRAME_PREV")
|
||||||
row.label(text=self.props.active_brick_class)
|
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.operator("bim.close_brick_project", text="", icon="CANCEL")
|
||||||
|
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
|
|||||||
@@ -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)
|
brick_uri = brick.add_brick(product, namespace, brick_class)
|
||||||
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()
|
||||||
|
|
||||||
|
|
||||||
def add_brick_feed(ifc, brick, source=None, destination=None):
|
def add_brick_feed(ifc, brick, source=None, destination=None):
|
||||||
source_element = ifc.get_entity(source)
|
source_element = ifc.get_entity(source)
|
||||||
destination_element = ifc.get_entity(destination)
|
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_element), brick.get_brick(destination_element))
|
||||||
|
brick.run_refresh_brick_viewer()
|
||||||
|
|
||||||
|
|
||||||
def convert_ifc_to_brick(brick, namespace=None, library=None):
|
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)
|
brick_class = brick.get_brick_class(element)
|
||||||
if not brick_class:
|
if not brick_class:
|
||||||
continue
|
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):
|
def new_brick_file(brick):
|
||||||
brick.new_brick_file()
|
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()
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ class Brick:
|
|||||||
def clear_brick_browser(cls): pass
|
def clear_brick_browser(cls): pass
|
||||||
def clear_project(cls): pass
|
def clear_project(cls): pass
|
||||||
def export_brick_attributes(cls, brick_uri): 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(cls, element): pass
|
||||||
def get_brick_class(cls, element): pass
|
def get_brick_class(cls, element): pass
|
||||||
def get_brick_path(cls): pass
|
def get_brick_path(cls): pass
|
||||||
@@ -65,8 +66,9 @@ class Brick:
|
|||||||
def load_brick_file(cls, filepath): pass
|
def load_brick_file(cls, filepath): pass
|
||||||
def new_brick_file(cls): pass
|
def new_brick_file(cls): pass
|
||||||
def pop_brick_breadcrumb(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_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 select_browser_item(cls, item): pass
|
||||||
def set_active_brick_class(cls, brick_class): pass
|
def set_active_brick_class(cls, brick_class): pass
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ class Brick(blenderbim.core.tool.Brick):
|
|||||||
else:
|
else:
|
||||||
return {"Identification": brick_uri, "Name": brick_uri.split("#")[-1]}
|
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
|
@classmethod
|
||||||
def get_brick(cls, element):
|
def get_brick(cls, element):
|
||||||
for rel in element.HasAssociations:
|
for rel in element.HasAssociations:
|
||||||
@@ -122,7 +126,9 @@ class Brick(blenderbim.core.tool.Brick):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_brick_path_name(cls):
|
def get_brick_path_name(cls):
|
||||||
return os.path.basename(BrickStore.path)
|
if BrickStore.path:
|
||||||
|
return os.path.basename(BrickStore.path)
|
||||||
|
return "Unnamed"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_brickifc_project(cls):
|
def get_brickifc_project(cls):
|
||||||
@@ -266,18 +272,20 @@ class Brick(blenderbim.core.tool.Brick):
|
|||||||
bpy.context.scene.BIMBrickProperties.brick_breadcrumbs.remove(last_index)
|
bpy.context.scene.BIMBrickProperties.brick_breadcrumbs.remove(last_index)
|
||||||
return name
|
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
|
@classmethod
|
||||||
def run_assign_brick_reference(cls, obj=None, library=None, brick_uri=None):
|
def run_assign_brick_reference(cls, obj=None, library=None, brick_uri=None):
|
||||||
return blenderbim.core.brick.assign_brick_reference(
|
return blenderbim.core.brick.assign_brick_reference(
|
||||||
tool.Ifc, tool.Brick, obj=obj, library=library, brick_uri=brick_uri
|
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
|
@classmethod
|
||||||
def select_browser_item(cls, item):
|
def select_browser_item(cls, item):
|
||||||
name = item.split("#")[-1]
|
name = item.split("#")[-1]
|
||||||
|
|||||||
@@ -109,3 +109,14 @@ Scenario: Convert IFC to brick
|
|||||||
And I press "bim.assign_class"
|
And I press "bim.assign_class"
|
||||||
When I press "bim.convert_ifc_to_brick"
|
When I press "bim.convert_ifc_to_brick"
|
||||||
Then nothing happens
|
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
|
||||||
|
|||||||
@@ -119,12 +119,14 @@ class TestAddBrick:
|
|||||||
def test_adding_a_brick(self, ifc, brick):
|
def test_adding_a_brick(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("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)
|
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("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()
|
||||||
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")
|
||||||
|
|
||||||
|
|
||||||
@@ -135,6 +137,7 @@ class TestAddBrickFeed:
|
|||||||
brick.get_brick("source_element").should_be_called().will_return("source_brick")
|
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("destination_element").should_be_called().will_return("destination_brick")
|
||||||
brick.add_feed("source_brick", "destination_brick").should_be_called()
|
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")
|
subject.add_brick_feed(ifc, brick, source="source", destination="destination")
|
||||||
|
|
||||||
|
|
||||||
@@ -142,18 +145,29 @@ 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.run_add_brick(
|
brick.add_brick("element", "namespace", "brick_class").should_be_called().will_return("brick_uri")
|
||||||
obj="obj", namespace="namespace", brick_class="brick_class", library="library"
|
brick.run_assign_brick_reference(obj="obj", library="library", brick_uri="brick_uri").should_be_called()
|
||||||
).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")
|
||||||
|
|
||||||
def test_not_converting_an_element_where_we_cannot_find_the_corresponding_brick_class(self, brick):
|
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_convertable_brick_objects_and_elements().should_be_called().will_return([("obj", "element")])
|
||||||
brick.get_brick_class("element").should_be_called().will_return(None)
|
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")
|
subject.convert_ifc_to_brick(brick, namespace="namespace", library="library")
|
||||||
|
|
||||||
|
|
||||||
class TestNewBrickFile:
|
class TestNewBrickFile:
|
||||||
def test_run(self, brick):
|
def test_run(self, brick):
|
||||||
brick.new_brick_file().should_be_called()
|
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)
|
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)
|
||||||
|
|||||||
@@ -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):
|
class TestGetBrick(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
ifc = ifcopenshell.file()
|
ifc = ifcopenshell.file()
|
||||||
@@ -326,12 +332,17 @@ class TestPopBrickBreadcrumb(NewFile):
|
|||||||
assert bpy.context.scene.BIMBrickProperties.brick_breadcrumbs[0].name == "foo"
|
assert bpy.context.scene.BIMBrickProperties.brick_breadcrumbs[0].name == "foo"
|
||||||
|
|
||||||
|
|
||||||
class TestRunAddBrick(NewFile):
|
class TestRunAssignBrickReference(NewFile):
|
||||||
def test_nothing(self):
|
def test_nothing(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestRunAssignBrickReference(NewFile):
|
class TestRunRefreshBrickViewer(NewFile):
|
||||||
|
def test_nothing(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TestViewBrickClass(NewFile):
|
||||||
def test_nothing(self):
|
def test_nothing(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user