you can now add, edit and remove structural load cases

This commit is contained in:
Jesusbill
2021-05-05 14:22:18 +02:00
parent 6ff792d75c
commit a031bffe6c
8 changed files with 282 additions and 0 deletions
@@ -23,6 +23,11 @@ classes = (
operator.EnableEditingStructuralMemberAxis,
operator.DisableEditingStructuralMemberAxis,
operator.EditStructuralMemberAxis,
operator.AddStructuralLoadCase,
operator.EditStructuralLoadCase,
operator.RemoveStructuralLoadCase,
operator.EnableEditingStructuralLoadCase,
operator.DisableEditingStructuralLoadCase,
prop.StructuralAnalysisModel,
prop.BIMStructuralProperties,
prop.BIMObjectStructuralProperties,
@@ -31,6 +36,7 @@ classes = (
ui.BIM_PT_connected_structural_members,
ui.BIM_PT_structural_member,
ui.BIM_UL_structural_analysis_models,
ui.BIM_PT_structural_load_cases,
)
@@ -436,3 +436,139 @@ class EditStructuralMemberAxis(bpy.types.Operator):
)
bpy.ops.bim.disable_editing_structural_member_axis()
return {"FINISHED"}
class AssignStructuralLoadCase(bpy.types.Operator):
bl_idname = "bim.assign_structural_load_case"
bl_label = "Assign Structural Load Case"
work_plan: bpy.props.IntProperty()
load_case: bpy.props.IntProperty()
def execute(self, context):
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"aggregate.assign_object",
self.file,
**{
"relating_object": self.file.by_id(self.work_plan),
"product": self.file.by_id(self.load_case),
},
)
Data.load(IfcStore.get_file())
return {"FINISHED"}
class UnassignStructuralLoadCase(bpy.types.Operator):
bl_idname = "bim.unassign_structural_load_case"
bl_label = "Unassign Structural Load Case"
work_plan: bpy.props.IntProperty()
load_case: bpy.props.IntProperty()
def execute(self, context):
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"aggregate.unassign_object",
self.file,
**{
"relating_object": self.file.by_id(self.work_plan),
"product": self.file.by_id(self.load_case),
},
)
Data.load(IfcStore.get_file())
return {"FINISHED"}
class AddStructuralLoadCase(bpy.types.Operator):
bl_idname = "bim.add_structural_load_case"
bl_label = "Add Structural Load Case"
def execute(self, context):
ifcopenshell.api.run("structural.add_structural_load_case", IfcStore.get_file())
Data.load(IfcStore.get_file())
return {"FINISHED"}
class EditStructuralLoadCase(bpy.types.Operator):
bl_idname = "bim.edit_structural_load_case"
bl_label = "Edit Structural Load Case"
def execute(self, context):
props = context.scene.BIMStructuralProperties
attributes = {}
for attribute in props.load_case_attributes:
if attribute.is_null:
attributes[attribute.name] = None
else:
if attribute.data_type == "string":
attributes[attribute.name] = attribute.string_value
elif attribute.data_type == "enum":
attributes[attribute.name] = attribute.enum_value
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"structural.edit_structural_load_case",
self.file,
**{"load_case": self.file.by_id(props.active_load_case_id), "attributes": attributes},
)
Data.load(IfcStore.get_file())
bpy.ops.bim.disable_editing_structural_load_case()
return {"FINISHED"}
class RemoveStructuralLoadCase(bpy.types.Operator):
bl_idname = "bim.remove_structural_load_case"
bl_label = "Remove Structural Load Case"
load_case: bpy.props.IntProperty()
def execute(self, context):
self.file = IfcStore.get_file()
ifcopenshell.api.run(
"structural.remove_structural_load_case", self.file, load_case=self.file.by_id(self.load_case)
)
Data.load(self.file)
return {"FINISHED"}
class EnableEditingStructuralLoadCase(bpy.types.Operator):
bl_idname = "bim.enable_editing_structural_load_case"
bl_label = "Enable Editing Structural Load Case"
load_case: bpy.props.IntProperty()
def execute(self, context):
self.props = context.scene.BIMStructuralProperties
self.props.active_load_case_id = self.load_case
while len(self.props.load_case_attributes) > 0:
self.props.load_case_attributes.remove(0)
self.enable_editing_structural_load_case()
return {"FINISHED"}
def enable_editing_structural_load_case(self):
data = Data.load_cases[self.load_case]
print(data)
for attribute in IfcStore.get_schema().declaration_by_name("IfcStructuralLoadCase").all_attributes():
if attribute.name() in ["SelfWeightCoefficients", "Coefficient"]:
continue
data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
if data_type == "entity":
continue
new = self.props.load_case_attributes.add()
new.name = attribute.name()
new.is_null = data[attribute.name()] is None
new.is_optional = attribute.optional()
print(data_type)
new.data_type = data_type
if data_type == "string":
new.string_value = "" if new.is_null else data[attribute.name()]
elif data_type == "enum":
new.enum_items = json.dumps(ifcopenshell.util.attribute.get_enum_items(attribute))
if data[attribute.name()]:
new.enum_value = data[attribute.name()]
class DisableEditingStructuralLoadCase(bpy.types.Operator):
bl_idname = "bim.disable_editing_structural_load_case"
bl_label = "Disable Editing Structural Load Case"
def execute(self, context):
context.scene.BIMStructuralProperties.active_load_case_id = 0
return {"FINISHED"}
@@ -41,6 +41,12 @@ class BIMStructuralProperties(PropertyGroup):
active_structural_analysis_model_index: IntProperty(name="Active Structural Analysis Model Index")
active_structural_analysis_model_id: IntProperty(name="Active Structural Analysis Model Id")
# editing_type: StringProperty(name="Editing Type")
# active_load_case_index: IntProperty(name="Active Work Schedules Index")
load_case_attributes: CollectionProperty(name="Load Case Attributes", type=Attribute)
active_load_case_id: IntProperty(name="Active Load Case Id")
class BIMObjectStructuralProperties(PropertyGroup):
boundary_condition_attributes: CollectionProperty(name="Boundary Condition Attributes", type=Attribute)
@@ -50,3 +56,5 @@ class BIMObjectStructuralProperties(PropertyGroup):
is_editing_axis: BoolProperty(name="Is Editing Axis", default=False)
axis_angle: FloatProperty(name="Axis Angle", update=updateAxisAngle)
axis_empty: PointerProperty(name="Axis Empty", type=bpy.types.Object)
# relating_structural_activity: PointerProperty(name="Relating Structural Activity", type=bpy.types.Object)
@@ -261,3 +261,56 @@ class BIM_UL_structural_analysis_models(UIList):
op.structural_analysis_model = item.ifc_definition_id
op = row.operator("bim.remove_structural_analysis_model", text="", icon="X")
op.structural_analysis_model = item.ifc_definition_id
class BIM_PT_structural_load_cases(Panel):
bl_label = "IFC Structural Load Cases"
bl_idname = "BIM_PT_structural_load_cases"
bl_options = {"DEFAULT_CLOSED"}
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "scene"
@classmethod
def poll(cls, context):
return IfcStore.get_file()
def draw(self, context):
self.props = context.scene.BIMStructuralProperties
if not Data.is_loaded:
Data.load(IfcStore.get_file())
row = self.layout.row()
row.operator("bim.add_structural_load_case", icon="ADD")
for load_case_id, load_case in Data.load_cases.items():
self.draw_load_case_ui(load_case_id, load_case)
def draw_load_case_ui(self, load_case_id, load_case):
row = self.layout.row(align=True)
row.label(text=load_case["Name"] or "Unnamed", icon="CON_CLAMPTO")
if self.props.active_load_case_id and self.props.active_load_case_id == load_case_id:
row.operator("bim.edit_structural_load_case", text="", icon="CHECKMARK")
row.operator("bim.disable_editing_structural_load_case", text="", icon="CANCEL")
elif self.props.active_load_case_id:
row.operator("bim.remove_structural_load_case", text="", icon="X").load_case = load_case_id
else:
row.operator(
"bim.enable_editing_structural_load_case", text="", icon="GREASEPENCIL"
).load_case = load_case_id
row.operator("bim.remove_structural_load_case", text="", icon="X").load_case = load_case_id
if self.props.active_load_case_id == load_case_id:
self.draw_editable_load_case_ui()
def draw_editable_load_case_ui(self):
for attribute in self.props.load_case_attributes:
row = self.layout.row(align=True)
if attribute.data_type == "string":
row.prop(attribute, "string_value", text=attribute.name)
elif attribute.data_type == "enum":
row.prop(attribute, "enum_value", text=attribute.name)
if attribute.is_optional:
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
@@ -0,0 +1,25 @@
import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {
"name": "Unnamed",
"predefined_type": "LOAD_CASE",
"action_type": "NOTDEFINED",
"action_source": "NOTDEFINED",
}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
load_case = ifcopenshell.api.run(
"root.create_entity",
self.file,
ifc_class="IfcStructuralLoadCase",
predefined_type=self.settings["predefined_type"],
action_type=self.settings["action_type"],
action_source=self.settings["action_source"],
name=self.settings["name"],
)
return load_case
@@ -6,6 +6,12 @@ class Data:
boundary_conditions = {}
connects_structural_members = {}
load_cases = {}
# load_case_combinations = {}
# load_groups = {}
# structural_activities = {}
# connects_structural_activities = {}
@classmethod
def purge(cls):
cls.is_loaded = False
@@ -14,6 +20,7 @@ class Data:
cls.connections = {}
cls.boundary_conditions = {}
cls.connects_structural_members = {}
cls.load_cases = {}
@classmethod
def load(cls, file, product_id=None):
@@ -23,6 +30,7 @@ class Data:
if product_id:
return cls.load_structural_connection(product_id)
cls.load_structural_analysis_models()
cls.load_structural_load_cases()
cls.is_loaded = True
@classmethod
@@ -53,6 +61,27 @@ class Data:
cls.structural_analysis_models[model.id()] = data
@classmethod
def load_structural_load_cases(cls):
cls.load_cases = {}
for case in cls._file.by_type("IfcStructuralLoadCase"):
# if case.IsGroupedBy:
# for rel in case.IsGroupedBy:
# for product in rel.RelatedObjects:
# cls.products.setdefault(product.id(), []).append(case.id())
data = case.get_info()
del data["OwnerHistory"]
is_grouped_by = []
for load_group in case.IsGroupedBy or []:
is_grouped_by.append(load_group.id())
data["IsGroupedBy"] = is_grouped_by
cls.load_cases[case.id()] = data
print(data)
@classmethod
def load_structural_connection(cls, product_id):
cls.connections = {}
@@ -0,0 +1,10 @@
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"load_case": None, "attributes": {}}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
for name, value in self.settings["attributes"].items():
setattr(self.settings["load_case"], name, value)
@@ -0,0 +1,15 @@
import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"load_case": None}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
# TODO: do a deep purge
for rel in self.settings["load_case"].IsGroupedBy or []:
self.file.remove(rel)
self.file.remove(self.settings["load_case"])