Fix #1923. Fix bug where creating a new structural analysis model broke.

This commit is contained in:
Dion Moult
2021-12-10 10:58:06 +11:00
parent ce5db914db
commit 62236c44ae
5 changed files with 34 additions and 12 deletions
@@ -21,6 +21,8 @@ import json
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import blenderbim.bim.helper import blenderbim.bim.helper
import blenderbim.tool as tool
import blenderbim.core.context
from math import degrees from math import degrees
from mathutils import Vector, Matrix from mathutils import Vector, Matrix
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
@@ -269,15 +271,16 @@ class AddStructuralAnalysisModel(bpy.types.Operator):
def _execute(self, context): def _execute(self, context):
result = ifcopenshell.api.run("structural.add_structural_analysis_model", IfcStore.get_file()) result = ifcopenshell.api.run("structural.add_structural_analysis_model", IfcStore.get_file())
has_context = False model = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model")
ContextData.load(IfcStore.get_file()) if not model:
for context in ContextData.contexts.values(): model = blenderbim.core.context.add_context(
if context["ContextType"] == "Model": tool.Ifc, context_type="Model", context_identifier="", target_view="", parent=0
for subcontext in context["HasSubContexts"].values(): )
if subcontext["ContextIdentifier"] == "Reference" and subcontext["TargetView"] == "GRAPH_VIEW": graph = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Reference", "GRAPH_VIEW")
has_context = True if not graph:
if not has_context: model = blenderbim.core.context.add_context(
bpy.ops.bim.add_subcontext(context="Model", subcontext="Reference", target_view="GRAPH_VIEW") tool.Ifc, context_type="Model", context_identifier="Reference", target_view="GRAPH_VIEW", parent=model
)
Data.load(IfcStore.get_file()) Data.load(IfcStore.get_file())
bpy.ops.bim.load_structural_analysis_models() bpy.ops.bim.load_structural_analysis_models()
@@ -154,7 +154,7 @@ class BIM_PT_connected_structural_members(Panel):
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.label(text=f"To Member #{IfcStore.get_file().by_id(rel['RelatingStructuralMember']).Name}") 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: 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"] row.enabled = self.props.active_boundary_condition != rel["AppliedCondition"]
self.draw_editable_ui(context, self.layout, rel) self.draw_editable_ui(context, self.layout, rel)
elif self.props.active_connects_structural_member: elif self.props.active_connects_structural_member:
@@ -294,7 +294,7 @@ class BIM_PT_structural_analysis_models(Panel):
) )
if self.props.is_editing: if self.props.is_editing:
row.operator("bim.add_structural_analysis_model", text="", icon="ADD") 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: else:
row.operator("bim.load_structural_analysis_models", text="", icon="GREASEPENCIL") row.operator("bim.load_structural_analysis_models", text="", icon="GREASEPENCIL")
+1
View File
@@ -20,6 +20,7 @@ markers =
root root
sequence sequence
spatial spatial
structural
style style
type type
unit unit
@@ -1,6 +1,5 @@
@root @root
Feature: Root Feature: Root
Covers IFC class operations on Blender objects
Scenario: Reassign class Scenario: Reassign class
Given an empty IFC project Given an empty IFC project
@@ -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