diff --git a/src/bonsai/bonsai/bim/module/drawing/__init__.py b/src/bonsai/bonsai/bim/module/drawing/__init__.py index c010e644eb..7ca0e4bd93 100644 --- a/src/bonsai/bonsai/bim/module/drawing/__init__.py +++ b/src/bonsai/bonsai/bim/module/drawing/__init__.py @@ -40,7 +40,6 @@ classes = ( operator.BuildSchedule, operator.CleanWireframes, operator.ContractSheet, - operator.ContractTargetView, operator.ConvertSVGToDXF, operator.CreateDrawing, operator.CreateSheets, @@ -63,7 +62,6 @@ classes = ( operator.EnableEditingElementFilter, operator.EnableEditingText, operator.ExpandSheet, - operator.ExpandTargetView, operator.LoadDrawings, operator.LoadReferences, operator.LoadSchedules, @@ -88,6 +86,7 @@ classes = ( operator.SelectAllDrawings, operator.SelectAllSheets, operator.SelectAssignedProduct, + operator.ToggleTargetView, operator.OpenDocumentationWebUi, prop.Variable, prop.Drawing, diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index 7cf48ddc75..697670780d 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -51,7 +51,7 @@ import bonsai.bim.export_ifc from bpy_extras.io_utils import ImportHelper from bonsai.bim.module.drawing.decoration import CutDecorator from bonsai.bim.module.drawing.data import DecoratorData -from typing import NamedTuple, Union, Optional, Literal, TYPE_CHECKING, Any, TypedDict +from typing import NamedTuple, Union, Optional, Literal, TYPE_CHECKING, Any, TypedDict, get_args from lxml import etree from math import radians from mathutils import Vector, Color, Matrix @@ -3363,50 +3363,51 @@ class DisableEditingDrawings(bpy.types.Operator, tool.Ifc.Operator): core.disable_editing_drawings(tool.Drawing) -class ExpandTargetView(bpy.types.Operator): - bl_idname = "bim.expand_target_view" - bl_label = "Expand Target View" - bl_description = "\nSHIFT+CLICK to expand all view categories" +ToggleOption = Literal["EXPAND", "CONTRACT"] + +class ToggleTargetView(bpy.types.Operator): + bl_idname = "bim.toggle_target_view" + bl_label = "Toggle Target View" bl_options = {"REGISTER", "UNDO"} - target_view: bpy.props.StringProperty() - expand_all: bpy.props.BoolProperty(name="Expand All", default=False, options={"SKIP_SAVE"}) + + target_view: bpy.props.StringProperty() # pyright: ignore[reportRedeclaration] + toggle_all: bpy.props.BoolProperty( # pyright: ignore[reportRedeclaration] + default=False, + options={"SKIP_SAVE"}, + ) + option: bpy.props.EnumProperty( # pyright: ignore[reportRedeclaration] + items=[(i, i, "") for i in get_args(ToggleOption)] + ) + + if TYPE_CHECKING: + target_view: str + toggle_all: bool + option: ToggleOption + + @classmethod + def description(cls, context, properties) -> str: + option: ToggleOption = properties.option + if option == "EXPAND": + return "Expand target view.\n\nSHIFT+CLICK to expand all view categories." + else: + return "Contract target view.\n\nSHIFT+CLICK to contract all view categories." def invoke(self, context, event): - # Expanding all categories on shift+click. + # Toggling all categories on shift+click. # Make sure to use SKIP_SAVE on property, otherwise it might get stuck (copied from #4771). if event.type == "LEFTMOUSE" and event.shift: - self.expand_all = True + self.toggle_all = True return self.execute(context) def execute(self, context): props = tool.Drawing.get_document_props() - for drawing in [d for d in props.drawings if self.expand_all or d.target_view == self.target_view]: - drawing.is_expanded = True - core.load_drawings(tool.Drawing) - return {"FINISHED"} - - -class ContractTargetView(bpy.types.Operator): - bl_idname = "bim.contract_target_view" - bl_label = "Contract Target View" - bl_description = "\n\nSHIFT+CLICK to hide all view categories" - - bl_options = {"REGISTER", "UNDO"} - target_view: bpy.props.StringProperty() - contract_all: bpy.props.BoolProperty(name="Contract All", default=False, options={"SKIP_SAVE"}) - - def invoke(self, context, event): - # Contracting all categories on shift+click. - # Make sure to use SKIP_SAVE on property, otherwise it might get stuck (copied from #4771). - if event.type == "LEFTMOUSE" and event.shift: - self.contract_all = True - return self.execute(context) - - def execute(self, context): - props = tool.Drawing.get_document_props() - for drawing in [d for d in props.drawings if self.contract_all or d.target_view == self.target_view]: - drawing.is_expanded = False + expanded = self.option == "EXPAND" + for drawing in props.drawings: + if drawing.is_drawing: + continue + if self.toggle_all or drawing.target_view == self.target_view: + drawing.is_expanded = expanded core.load_drawings(tool.Drawing) return {"FINISHED"} diff --git a/src/bonsai/bonsai/bim/module/drawing/ui.py b/src/bonsai/bonsai/bim/module/drawing/ui.py index 675684f6c7..767eb07bce 100644 --- a/src/bonsai/bonsai/bim/module/drawing/ui.py +++ b/src/bonsai/bonsai/bim/module/drawing/ui.py @@ -667,13 +667,13 @@ class BIM_UL_drawinglist(bpy.types.UIList): else: icon = "CLIPUV_HLT" if item.is_expanded: - row.operator( - "bim.contract_target_view", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN" - ).target_view = item.target_view + op = row.operator("bim.toggle_target_view", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN") + op.target_view = item.target_view + op.option = "CONTRACT" else: - row.operator( - "bim.expand_target_view", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT" - ).target_view = item.target_view + op = row.operator("bim.toggle_target_view", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT") + op.target_view = item.target_view + op.option = "EXPAND" row.prop(item, "name", text="", icon=icon, emboss=False) diff --git a/src/bonsai/test/bim/feature/drawing.feature b/src/bonsai/test/bim/feature/drawing.feature index ea7126cb54..7a4d59c9d5 100644 --- a/src/bonsai/test/bim/feature/drawing.feature +++ b/src/bonsai/test/bim/feature/drawing.feature @@ -13,7 +13,7 @@ Scenario: Duplicate drawing And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" When I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" When I press "bim.duplicate_drawing(drawing={drawing})" @@ -31,7 +31,7 @@ Scenario: Duplicate drawing - without duplicating annotations And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list And I click "VIEW_CAMERA_UNSELECTED" in the row where I see "PLAN_VIEW" in the "1st" list And I press "bim.add_annotation" @@ -54,7 +54,7 @@ Scenario: Duplicate drawing - with duplicating annotations And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list And I click "VIEW_CAMERA_UNSELECTED" in the row where I see "PLAN_VIEW" in the "1st" list And I press "bim.add_annotation" @@ -77,7 +77,7 @@ Scenario: Create drawing And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" When I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list And I click "VIEW_CAMERA_UNSELECTED" in the row where I see "PLAN_VIEW" in the "1st" list And I click "OUTPUT" @@ -97,7 +97,7 @@ Scenario: Create drawing after deleting a duplicated object And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list And I click "VIEW_CAMERA_UNSELECTED" in the row where I see "PLAN_VIEW" in the "1st" list And I click "OUTPUT" @@ -116,7 +116,7 @@ Scenario: Activate drawing preserves visibility for non-ifc objects And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list And I click "VIEW_CAMERA_UNSELECTED" in the row where I see "PLAN_VIEW" in the "1st" list Then the object "Cube" is visible @@ -130,7 +130,7 @@ Scenario: Activate drawing preserves selection And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list When I click "VIEW_CAMERA_UNSELECTED" in the row where I see "PLAN_VIEW" in the "1st" list Then the object "Cube" is selected @@ -147,7 +147,7 @@ Scenario: Remove drawing And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list When I click "VIEW_CAMERA_UNSELECTED" in the row where I see "PLAN_VIEW" in the "1st" list Then the collection "IfcAnnotation/PLAN_VIEW" exists @@ -181,7 +181,7 @@ Scenario: Remove drawing - deleting active drawing And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list And I click "VIEW_CAMERA_UNSELECTED" in the row where I see "PLAN_VIEW" in the "1st" list When the object "IfcAnnotation/PLAN_VIEW" is selected @@ -196,7 +196,7 @@ Scenario: Add annotation - text And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list And I click "VIEW_CAMERA_UNSELECTED" in the row where I see "PLAN_VIEW" in the "1st" list When I press "bim.add_annotation" @@ -213,7 +213,7 @@ Scenario: Add annotation - auto create context if it doesn't exist And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list And I click "VIEW_CAMERA_UNSELECTED" in the row where I see "PLAN_VIEW" in the "1st" list When I press "bim.add_annotation" @@ -232,7 +232,7 @@ Scenario: Create drawing - using shapely fill mode And I click "IMPORT" And I set the "location_hint" property to "My Storey" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" When I select the "MY STOREY PLAN" item in the "BIM_UL_drawinglist" list And I click "VIEW_CAMERA_UNSELECTED" in the row where I see "MY STOREY PLAN" in the "1st" list And I look at the "Active Drawing" panel @@ -273,7 +273,7 @@ Scenario: Add drawing to sheet And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list And I click "VIEW_CAMERA_UNSELECTED" in the row where I see "PLAN_VIEW" in the "1st" list And I click "OUTPUT" @@ -298,7 +298,7 @@ Scenario: Create sheet - with a drawing added to it And I look at the "Drawings" panel And I click "IMPORT" And I click "ADD" - And I press "bim.expand_target_view(target_view='PLAN_VIEW')" + And I press "bim.toggle_target_view(option="EXPAND", target_view='PLAN_VIEW')" And I select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list And I click "VIEW_CAMERA_UNSELECTED" in the row where I see "PLAN_VIEW" in the "1st" list And I click "OUTPUT" diff --git a/src/bonsai/test/tool/test_drawing.py b/src/bonsai/test/tool/test_drawing.py index f006e5ce2c..2e4fde3fd4 100644 --- a/src/bonsai/test/tool/test_drawing.py +++ b/src/bonsai/test/tool/test_drawing.py @@ -887,7 +887,7 @@ class TestDrawingStyles(NewFile): bpy.ops.bim.add_drawing() ifc = tool.Ifc.get() drawing = ifc.by_type("IfcAnnotation")[0] - bpy.ops.bim.expand_target_view(target_view="PLAN_VIEW") + bpy.ops.bim.toggle_target_view(option="EXPAND", target_view="PLAN_VIEW") props = tool.Drawing.get_document_props() props.active_drawing_index = 2 bpy.ops.bim.activate_drawing(drawing=drawing.id())