diff --git a/src/blenderbim/blenderbim/bim/module/structural/operator.py b/src/blenderbim/blenderbim/bim/module/structural/operator.py index 5d60ef6e40..aca1df208c 100644 --- a/src/blenderbim/blenderbim/bim/module/structural/operator.py +++ b/src/blenderbim/blenderbim/bim/module/structural/operator.py @@ -21,6 +21,8 @@ import json import ifcopenshell import ifcopenshell.api import blenderbim.bim.helper +import blenderbim.tool as tool +import blenderbim.core.context from math import degrees from mathutils import Vector, Matrix from blenderbim.bim.ifc import IfcStore @@ -269,15 +271,16 @@ class AddStructuralAnalysisModel(bpy.types.Operator): def _execute(self, context): result = ifcopenshell.api.run("structural.add_structural_analysis_model", IfcStore.get_file()) - has_context = False - ContextData.load(IfcStore.get_file()) - for context in ContextData.contexts.values(): - if context["ContextType"] == "Model": - for subcontext in context["HasSubContexts"].values(): - if subcontext["ContextIdentifier"] == "Reference" and subcontext["TargetView"] == "GRAPH_VIEW": - has_context = True - if not has_context: - bpy.ops.bim.add_subcontext(context="Model", subcontext="Reference", target_view="GRAPH_VIEW") + model = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model") + if not model: + model = blenderbim.core.context.add_context( + tool.Ifc, context_type="Model", context_identifier="", target_view="", parent=0 + ) + graph = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Reference", "GRAPH_VIEW") + if not graph: + model = blenderbim.core.context.add_context( + tool.Ifc, context_type="Model", context_identifier="Reference", target_view="GRAPH_VIEW", parent=model + ) Data.load(IfcStore.get_file()) bpy.ops.bim.load_structural_analysis_models() diff --git a/src/blenderbim/blenderbim/bim/module/structural/ui.py b/src/blenderbim/blenderbim/bim/module/structural/ui.py index 498a651749..07b1cfbcf9 100644 --- a/src/blenderbim/blenderbim/bim/module/structural/ui.py +++ b/src/blenderbim/blenderbim/bim/module/structural/ui.py @@ -154,7 +154,7 @@ class BIM_PT_connected_structural_members(Panel): row = self.layout.row(align=True) row.label(text=f"To Member #{IfcStore.get_file().by_id(rel['RelatingStructuralMember']).Name}") if self.props.active_connects_structural_member and self.props.active_connects_structural_member == rel_id: - row.operator("bim.disable_editing_structural_connection_condition", text="", icon="CHECKMARK") + row.operator("bim.disable_editing_structural_connection_condition", text="", icon="CANCEL") row.enabled = self.props.active_boundary_condition != rel["AppliedCondition"] self.draw_editable_ui(context, self.layout, rel) elif self.props.active_connects_structural_member: @@ -294,7 +294,7 @@ class BIM_PT_structural_analysis_models(Panel): ) if self.props.is_editing: row.operator("bim.add_structural_analysis_model", text="", icon="ADD") - row.operator("bim.disable_structural_analysis_model_editing_ui", text="", icon="CHECKMARK") + row.operator("bim.disable_structural_analysis_model_editing_ui", text="", icon="CANCEL") else: row.operator("bim.load_structural_analysis_models", text="", icon="GREASEPENCIL") diff --git a/src/blenderbim/pytest.ini b/src/blenderbim/pytest.ini index d8e06d2763..d66974581a 100644 --- a/src/blenderbim/pytest.ini +++ b/src/blenderbim/pytest.ini @@ -20,6 +20,7 @@ markers = root sequence spatial + structural style type unit diff --git a/src/blenderbim/test/bim/feature/root.feature b/src/blenderbim/test/bim/feature/root.feature index 760db8be98..3be9cb5285 100644 --- a/src/blenderbim/test/bim/feature/root.feature +++ b/src/blenderbim/test/bim/feature/root.feature @@ -1,6 +1,5 @@ @root Feature: Root - Covers IFC class operations on Blender objects Scenario: Reassign class Given an empty IFC project diff --git a/src/blenderbim/test/bim/feature/structural.feature b/src/blenderbim/test/bim/feature/structural.feature new file mode 100644 index 0000000000..feb62a3475 --- /dev/null +++ b/src/blenderbim/test/bim/feature/structural.feature @@ -0,0 +1,19 @@ +@structural +Feature: Structural + +Scenario: Load structural analysis models + Given an empty IFC project + When I press "bim.load_structural_analysis_models" + Then nothing happens + +Scenario: Add structural analysis model + Given an empty IFC project + And I press "bim.load_structural_analysis_models" + When I press "bim.add_structural_analysis_model" + Then nothing happens + +Scenario: Disable structural analysis model editing UI + Given an empty IFC project + And I press "bim.load_structural_analysis_models" + When I press "bim.disable_structural_analysis_model_editing_ui" + Then nothing happens