diff --git a/src/blenderbim/blenderbim/bim/module/drawing/operator.py b/src/blenderbim/blenderbim/bim/module/drawing/operator.py index 51d633da00..b7562030ff 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/operator.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/operator.py @@ -1299,9 +1299,13 @@ class ActivateModel(bpy.types.Operator): bl_description = "Activates the model view" def execute(self, context): + dprops = bpy.context.scene.DocProperties + dprops.active_drawing_id = 0 + CutDecorator.uninstall() - bpy.ops.object.hide_view_clear() + if not bpy.app.background: + bpy.ops.object.hide_view_clear() subcontext = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW") @@ -1411,15 +1415,11 @@ class RemoveDrawing(bpy.types.Operator, Operator): else: drawings = [tool.Ifc.get().by_id(self.drawing)] - print("Removing drawings: {}".format([d for d in drawings])) removed_drawings = [drawing.id() for drawing in drawings] for drawing in drawings: core.remove_drawing(tool.Ifc, tool.Drawing, drawing=drawing) - active_drawing_id = context.scene.DocProperties.active_drawing_id - if active_drawing_id in removed_drawings: - context.scene.DocProperties.active_drawing_id = 0 class ReloadDrawingStyles(bpy.types.Operator): bl_idname = "bim.reload_drawing_styles" diff --git a/src/blenderbim/blenderbim/core/drawing.py b/src/blenderbim/blenderbim/core/drawing.py index 873c554ba0..0fd08697ec 100644 --- a/src/blenderbim/blenderbim/core/drawing.py +++ b/src/blenderbim/blenderbim/core/drawing.py @@ -270,6 +270,9 @@ def duplicate_drawing(ifc, drawing_tool, drawing=None, should_duplicate_annotati def remove_drawing(ifc, drawing_tool, drawing=None): + if drawing_tool.is_active_drawing(drawing): + drawing_tool.run_drawing_activate_model() + collection = drawing_tool.get_drawing_collection(drawing) if collection: drawing_tool.delete_collection(collection) diff --git a/src/blenderbim/blenderbim/core/tool.py b/src/blenderbim/blenderbim/core/tool.py index 29eb554456..1a5dcefd5d 100644 --- a/src/blenderbim/blenderbim/core/tool.py +++ b/src/blenderbim/blenderbim/core/tool.py @@ -273,9 +273,8 @@ class Drawing: def get_body_context(cls): pass def get_default_drawing_path(cls, name): pass def get_default_drawing_resource_path(cls, resource): pass - def get_default_shading_style(cls): pass - def setup_shading_styles_path(cls, resource_path): pass def get_default_layout_path(cls, identification, name): pass + def get_default_shading_style(cls): pass def get_default_sheet_path(cls, identification, name): pass def get_default_sheet_path(cls, identification, name): pass def get_default_titleblock_path(cls, name): pass @@ -301,17 +300,20 @@ class Drawing: def import_schedules(cls): pass def import_sheets(cls): pass def import_text_attributes(cls, obj): pass + def is_active_drawing(cls, drawing): pass def is_camera_orthographic(cls): pass def is_drawing_active(cls): pass def move_file(cls, src, dest): pass def open_spreadsheet(cls, uri): pass def open_svg(cls, filepath): pass def remove_literal_from_annotation(cls, obj, literal): pass + def run_drawing_activate_model(cls): pass def run_root_assign_class(cls, obj=None, ifc_class=None, predefined_type=None, should_add_representation=True, context=None, ifc_representation_class=None): pass def select_assigned_product(cls, drawing): pass def set_drawing_collection_name(cls, group, collection): pass def set_name(cls, element, name): pass def setup_annotation_object(cls, obj, object_type): pass + def setup_shading_styles_path(cls, resource_path): pass def show_decorations(cls): pass def sync_object_placement(cls, obj): pass def synchronise_ifc_and_text_attributes(cls, obj): pass diff --git a/src/blenderbim/blenderbim/tool/drawing.py b/src/blenderbim/blenderbim/tool/drawing.py index 8abe940481..bd3a5b78b1 100644 --- a/src/blenderbim/blenderbim/tool/drawing.py +++ b/src/blenderbim/blenderbim/tool/drawing.py @@ -1442,6 +1442,14 @@ class Drawing(blenderbim.core.tool.Drawing): camera = bpy.context.scene.camera return True if (camera and camera.data.type == "ORTHO") else False + @classmethod + def is_active_drawing(cls, drawing): + return drawing.id() == bpy.context.scene.DocProperties.active_drawing_id + + @classmethod + def run_drawing_activate_model(cls): + bpy.ops.bim.activate_model() + @classmethod def activate_drawing(cls, camera): area = next(area for area in bpy.context.screen.areas if area.type == "VIEW_3D") diff --git a/src/blenderbim/test/bim/feature/drawing.feature b/src/blenderbim/test/bim/feature/drawing.feature index 012aafdc80..e2ca0a2b74 100644 --- a/src/blenderbim/test/bim/feature/drawing.feature +++ b/src/blenderbim/test/bim/feature/drawing.feature @@ -74,6 +74,21 @@ Scenario: Remove drawing - via object deletion When I press "bim.override_object_delete" Then the collection "IfcGroup/PLAN_VIEW" does not exist +Scenario: Remove drawing - deleting active drawing + Given an empty IFC project + And I add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" + And I press "bim.assign_class" + And the variable "wall1" is "IfcStore.get_file().by_type('IfcWall')[-1].id()" + And I press "bim.add_drawing" + And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" + And I set "scene.DocProperties.active_drawing_index" to "0" + And I press "bim.activate_drawing(drawing={drawing})" + And the object "IfcAnnotation/PLAN_VIEW" is selected + When I press "bim.override_object_delete" + Then the collection "IfcGroup/PLAN_VIEW" does not exist + Scenario: Reproducing freeze on generating drawing - Issue 3169 Given an empty IFC project And I add a cube diff --git a/src/blenderbim/test/core/test_drawing.py b/src/blenderbim/test/core/test_drawing.py index e35be93fe0..4f901d7a62 100644 --- a/src/blenderbim/test/core/test_drawing.py +++ b/src/blenderbim/test/core/test_drawing.py @@ -345,6 +345,8 @@ class TestDuplicateDrawing: class TestRemoveDrawing: def test_run(self, ifc, drawing): + drawing.is_active_drawing("drawing").should_be_called().will_return(True) + drawing.run_drawing_activate_model().should_be_called() drawing.get_drawing_collection("drawing").should_be_called().will_return("collection") drawing.get_drawing_group("drawing").should_be_called().will_return("group") drawing.get_group_elements("group").should_be_called().will_return("elements")