Implement add / remove load groups, and half implement structural activities. Thanks Jesusbill and ihabelaghoury

This commit is contained in:
Dion Moult
2021-05-07 18:41:03 +10:00
parent 15927dd501
commit f9b79b4beb
8 changed files with 281 additions and 26 deletions
@@ -0,0 +1,31 @@
import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {
"ifc_class": "IfcStructuralPlanarAction",
"predefined_type": "CONST",
"global_or_local": "GLOBAL_COORDS",
"applied_load": None,
"structural_member": None,
}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
activity = ifcopenshell.api.run(
"root.create_entity",
self.file,
ifc_class=self.settings["ifc_class"],
predefined_type=self.settings["predefined_type"],
)
# TODO
# activity.AppliedLoad = self.settings["applied_load"]
activity.GlobalOrLocal = self.settings["global_or_local"]
rel = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcRelConnectsStructuralActivity")
rel.RelatingElement = self.settings["structural_member"]
rel.RelatedStructuralActivity = activity
return activity
@@ -0,0 +1,26 @@
import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {
"name": "Unnamed",
"predefined_type": "LOAD_GROUP",
"action_type": "NOTDEFINED",
"action_source": "NOTDEFINED",
}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
load_group = ifcopenshell.api.run(
"root.create_entity",
self.file,
ifc_class="IfcStructuralLoadGroup",
predefined_type=self.settings["predefined_type"],
name=self.settings["name"],
)
load_group.ActionType = self.settings["action_type"]
load_group.ActionSource = self.settings["action_source"]
return load_group
@@ -48,6 +48,7 @@ class Data:
cls.load_structural_load_cases()
cls.load_structural_load_case_combinations()
cls.load_structural_load_groups()
cls.load_structural_activities()
cls.is_loaded = True
@classmethod
@@ -83,18 +84,12 @@ class Data:
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())
for rel in case.IsGroupedBy or []:
is_grouped_by.extend([o.id() for o in rel.RelatedObjects])
data["IsGroupedBy"] = is_grouped_by
cls.load_cases[case.id()] = data
@classmethod
@@ -121,20 +116,30 @@ class Data:
for case in cls._file.by_type("IfcStructuralLoadGroup", include_subtypes=False):
if case.PredefinedType == "LOAD_COMBINATION":
continue
# 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())
for rel in case.IsGroupedBy or []:
is_grouped_by.extend([o.id() for o in rel.RelatedObjects])
data["IsGroupedBy"] = is_grouped_by
cls.load_groups[case.id()] = data
@classmethod
def load_structural_activities(cls):
cls.structural_activities = {}
for activity in cls._file.by_type("IfcStructuralActivity"):
data = activity.get_info()
del data["OwnerHistory"]
del data["ObjectPlacement"]
del data["Representation"]
data["AppliedLoad"] = data["AppliedLoad"].id() if data["AppliedLoad"] else None
data["AssignedToStructuralItem"] = None
if activity.AssignedToStructuralItem:
data["AssignedToStructuralItem"] = activity.AssignedToStructuralItem[0].RelatingElement.id()
cls.structural_activities[activity.id()] = data
@classmethod
def load_structural_connection(cls, product_id):
# cls.connections = {}
@@ -0,0 +1,16 @@
import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
self.file = file
self.settings = {"load_group": None}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
# TODO: do a deep purge
for inverse in self.file.get_inverse(self.settings["load_group"]):
if inverse.is_a("IfcRelAssignsToGroup") and len(inverse.RelatedObjects) == 1:
self.file.remove(inverse)
self.file.remove(self.settings["load_group"])