diff --git a/src/bonsai/bonsai/tool/drawing.py b/src/bonsai/bonsai/tool/drawing.py index 92f234f71d..3db1cf5851 100644 --- a/src/bonsai/bonsai/tool/drawing.py +++ b/src/bonsai/bonsai/tool/drawing.py @@ -456,11 +456,14 @@ class Drawing(bonsai.core.tool.Drawing): "PLAN_LEVEL", ): parent = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Plan") + if not parent: + parent = ifcopenshell.api.context.add_context(tool.Ifc.get(), context_type="Plan") else: parent = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model") + if not parent: + parent = ifcopenshell.api.context.add_context(tool.Ifc.get(), context_type="Model") - return ifcopenshell.api.run( - "context.add_context", + return ifcopenshell.api.context.add_context( tool.Ifc.get(), context_type=parent.ContextType, context_identifier="Annotation", diff --git a/src/bonsai/test/bim/feature/drawing.feature b/src/bonsai/test/bim/feature/drawing.feature index ea2acdbe44..e3053280fc 100644 --- a/src/bonsai/test/bim/feature/drawing.feature +++ b/src/bonsai/test/bim/feature/drawing.feature @@ -134,3 +134,34 @@ Scenario: Remove drawing - deleting active drawing When the object "IfcAnnotation/PLAN_VIEW" is selected And I delete the selected objects Then the collection "IfcAnnotation/PLAN_VIEW" does not exist + +Scenario: Add annotation - text + Given an empty IFC project + And I add a cube + And the object "Cube" is selected + And I save sample test files + 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 select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list + And I click "OUTLINER_OB_CAMERA" + When I press "bim.add_annotation" + Then the object "IfcAnnotation/TEXT" is selected + +Scenario: Add annotation - auto create context if it doesn't exist + Given an empty IFC project + And I add a cube + And the object "Cube" is selected + And I save sample test files + And I look at the "Geometric Representation Contexts" panel + And I see "Plan" + And I click the "X" after the text "Plan" + 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 select the "PLAN_VIEW" item in the "BIM_UL_drawinglist" list + And I click "OUTLINER_OB_CAMERA" + When I press "bim.add_annotation" + Then the object "IfcAnnotation/TEXT" is selected diff --git a/src/bonsai/test/bim/test_feature.py b/src/bonsai/test/bim/test_feature.py index a094f94d3d..929ccc8dfa 100644 --- a/src/bonsai/test/bim/test_feature.py +++ b/src/bonsai/test/bim/test_feature.py @@ -134,7 +134,10 @@ class PanelSpy: icon = kwargs.get("icon", None) if text: self.spied_labels.append(text) - spied_operator = {"operator": operator, "icon": icon, "text": text, "kwargs": {}} + after = "" + if self.spied_labels: + after = self.spied_labels[-1] + spied_operator = {"operator": operator, "icon": icon, "text": text, "kwargs": {}, "after": after} self.spied_operators.append(spied_operator) return OperatorSpy(spied_operator) else: @@ -570,6 +573,22 @@ def i_click_button(button): assert False, f"Could not find {button}:\n{debug}" +@given(parsers.parse('I click the "{button}" after the text "{text}"')) +@when(parsers.parse('I click the "{button}" after the text "{text}"')) +@then(parsers.parse('I click the "{button}" after the text "{text}"')) +def i_click_the_button_after_the_text_text(button, text): + panel_spy.refresh_spy() + for spied_operator in panel_spy.spied_operators: + if spied_operator["after"] == text: + if spied_operator["text"] == button or spied_operator["icon"] == button: + spied_operator["operator"]("INVOKE_DEFAULT", **spied_operator["kwargs"]) + panel_spy.is_spy_dirty = True + return + debug = "\n".join([f"{i} {v}" for i, v in enumerate(panel_spy.spied_operators)]) + debug += f"\nHere is the text we see: {panel_spy.spied_labels}" + assert False, f"Could not find {button}:\n{debug}" + + @given(parsers.parse('I click "{button}" and expect error "{error_msg}"')) @when(parsers.parse('I click "{button}" and expect error "{error_msg}"')) def i_click_button_and_expect_error_error_msg(button, error_msg):