mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
First attempt at ripping out agnostic code into ifcopenshell.api namespace. See #1399.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import ifcopenshell
|
||||
from ifcopenshell.api.owner.api import create_owner_history
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, settings={}):
|
||||
self.file = file
|
||||
self.settings = {}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
return self.file.create_entity("IfcStructuralAnalysisModel", **{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": create_owner_history(),
|
||||
"Name": "Unnamed",
|
||||
"PredefinedType": "LOADING_3D"
|
||||
})
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings={}):
|
||||
self.file = file
|
||||
self.settings = {"connection": None}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
if self.settings["connection"].is_a("IfcStructuralPointConnection"):
|
||||
boundary_class = "IfcBoundaryNodeCondition"
|
||||
elif self.settings["connection"].is_a("IfcStructuralCurveConnection"):
|
||||
boundary_class = "IfcBoundaryEdgeCondition"
|
||||
elif self.settings["connection"].is_a("IfcStructuralSurfaceConnection"):
|
||||
boundary_class = "IfcBoundaryFaceCondition"
|
||||
self.settings["connection"].AppliedCondition = self.file.create_entity(boundary_class)
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import ifcopenshell
|
||||
from ifcopenshell.api.owner.api import create_owner_history
|
||||
from ifcopenshell.api.owner.api import update_owner_history
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, settings={}):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"product": None,
|
||||
"structural_analysis_model": None,
|
||||
}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
if not self.settings["structural_analysis_model"].IsGroupedBy:
|
||||
return self.file.create_entity("IfcRelAssignsToGroup", **{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": create_owner_history(),
|
||||
"RelatedObjects": [self.settings["product"]],
|
||||
"RelatingGroup": self.settings["structural_analysis_model"]
|
||||
})
|
||||
rel = self.settings["structural_analysis_model"].IsGroupedBy[0]
|
||||
related_objects = set(rel.RelatedObjects) or set()
|
||||
related_objects.add(self.settings["product"])
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
update_owner_history(rel)
|
||||
@@ -0,0 +1,66 @@
|
||||
class Data:
|
||||
is_loaded = False
|
||||
products = {}
|
||||
boundary_conditions = {}
|
||||
structural_analysis_models = {}
|
||||
|
||||
@classmethod
|
||||
def purge(cls):
|
||||
cls.is_loaded = False
|
||||
cls.products = {}
|
||||
cls.boundary_conditions = {}
|
||||
cls.connected_structural_members = {}
|
||||
cls.structural_analysis_models = {}
|
||||
|
||||
@classmethod
|
||||
def load(cls, file, product_id=None):
|
||||
cls._file = file
|
||||
if product_id:
|
||||
cls.boundary_conditions = {}
|
||||
return cls.load_structural_connection(product_id)
|
||||
cls.products = {}
|
||||
cls.structural_analysis_models = {}
|
||||
cls.load_structural_analysis_models()
|
||||
cls.is_loaded = True
|
||||
|
||||
@classmethod
|
||||
def load_structural_analysis_models(cls):
|
||||
for model in cls._file.by_type("IfcStructuralAnalysisModel"):
|
||||
if model.IsGroupedBy:
|
||||
for rel in model.IsGroupedBy:
|
||||
for product in rel.RelatedObjects:
|
||||
cls.products.setdefault(product.id(), []).append(model.id())
|
||||
data = model.get_info()
|
||||
del data["OwnerHistory"]
|
||||
del data["OrientationOf2DPlane"]
|
||||
|
||||
loaded_by = []
|
||||
for load_group in model.LoadedBy or []:
|
||||
loaded_by.append(load_group.id())
|
||||
data["LoadedBy"] = loaded_by
|
||||
|
||||
has_results = []
|
||||
for result_group in model.HasResults or []:
|
||||
has_results.append(result_group.id())
|
||||
data["HasResults"] = has_results
|
||||
|
||||
cls.structural_analysis_models[model.id()] = data
|
||||
|
||||
@classmethod
|
||||
def load_structural_connection(cls, product_id):
|
||||
connection = cls._file.by_id(product_id)
|
||||
if connection.AppliedCondition:
|
||||
data = connection.AppliedCondition.get_info()
|
||||
for key, value in data.items():
|
||||
if not value or key in ["Name", "type", "id"]:
|
||||
continue
|
||||
data[key] = value.wrappedValue
|
||||
else:
|
||||
data = {}
|
||||
cls.boundary_conditions[connection.id()] = data
|
||||
|
||||
cls.connected_structural_members[connection.id()] = [
|
||||
rel.RelatingStructuralMember.id()
|
||||
for rel in connection.ConnectsStructuralMembers or []
|
||||
]
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings={}):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"structural_analysis_model": 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["structural_analysis_model"], name, value)
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings={}):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"condition": None,
|
||||
"attributes": {}
|
||||
}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
for name, data in self.settings["attributes"].items():
|
||||
if data["type"] == "string" or data["type"] == "null":
|
||||
value = data["value"]
|
||||
elif data["type"] == "IfcBoolean":
|
||||
value = self.file.createIfcBoolean(data["value"])
|
||||
else:
|
||||
value = self.file.create_entity(data["type"], data["value"])
|
||||
setattr(self.settings["condition"], name, value)
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings={}):
|
||||
self.file = file
|
||||
self.settings = {"structural_analysis_model": None}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
for rel in self.settings["structural_analysis_model"].IsGroupedBy or []:
|
||||
self.file.remove(rel)
|
||||
self.file.remove(self.settings["structural_analysis_model"])
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings={}):
|
||||
self.file = file
|
||||
self.settings = {"connection": None}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
if not self.settings["connection"].AppliedCondition:
|
||||
return
|
||||
if len(self.file.get_inverse(self.settings["connection"].AppliedCondition)) > 1:
|
||||
self.settings["connection"].AppliedCondition = None
|
||||
else:
|
||||
self.file.remove(self.settings["connection"].AppliedCondition)
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import ifcopenshell
|
||||
from ifcopenshell.api.owner.api import update_owner_history
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, settings={}):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"product": None,
|
||||
"structural_analysis_model": None,
|
||||
}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
if not self.settings["structural_analysis_model"].IsGroupedBy:
|
||||
return
|
||||
rel = self.settings["structural_analysis_model"].IsGroupedBy[0]
|
||||
related_objects = set(rel.RelatedObjects) or set()
|
||||
related_objects.remove(self.settings["product"])
|
||||
if len(related_objects):
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
update_owner_history(rel)
|
||||
else:
|
||||
self.file.remove(rel)
|
||||
Reference in New Issue
Block a user