mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -21,76 +21,73 @@ import ifcopenshell.api
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, **settings):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"relating_element": None,
|
||||
"related_element": None,
|
||||
"relating_connection": "NOTDEFINED",
|
||||
"related_connection": "NOTDEFINED",
|
||||
"description": None,
|
||||
}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
def connect_path(file, **usecase_settings) -> None:
|
||||
settings = {
|
||||
"relating_element": None,
|
||||
"related_element": None,
|
||||
"relating_connection": "NOTDEFINED",
|
||||
"related_connection": "NOTDEFINED",
|
||||
"description": None,
|
||||
}
|
||||
for key, value in usecase_settings.items():
|
||||
settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
incompatible_connections = []
|
||||
for rel in self.settings["relating_element"].ConnectedTo:
|
||||
if not rel.is_a("IfcRelConnectsPathElements"):
|
||||
continue
|
||||
if rel.RelatedElement == self.settings["related_element"]:
|
||||
incompatible_connections.append(rel)
|
||||
elif (
|
||||
rel.RelatingConnectionType in ["ATSTART", "ATEND"]
|
||||
and rel.RelatingConnectionType == self.settings["relating_connection"]
|
||||
):
|
||||
incompatible_connections.append(rel)
|
||||
incompatible_connections = []
|
||||
for rel in settings["relating_element"].ConnectedTo:
|
||||
if not rel.is_a("IfcRelConnectsPathElements"):
|
||||
continue
|
||||
if rel.RelatedElement == settings["related_element"]:
|
||||
incompatible_connections.append(rel)
|
||||
elif (
|
||||
rel.RelatingConnectionType in ["ATSTART", "ATEND"]
|
||||
and rel.RelatingConnectionType == settings["relating_connection"]
|
||||
):
|
||||
incompatible_connections.append(rel)
|
||||
|
||||
for rel in self.settings["relating_element"].ConnectedFrom:
|
||||
if not rel.is_a("IfcRelConnectsPathElements"):
|
||||
continue
|
||||
if (
|
||||
rel.RelatedConnectionType in ["ATSTART", "ATEND"]
|
||||
and rel.RelatedConnectionType == self.settings["relating_connection"]
|
||||
):
|
||||
incompatible_connections.append(rel)
|
||||
for rel in settings["relating_element"].ConnectedFrom:
|
||||
if not rel.is_a("IfcRelConnectsPathElements"):
|
||||
continue
|
||||
if (
|
||||
rel.RelatedConnectionType in ["ATSTART", "ATEND"]
|
||||
and rel.RelatedConnectionType == settings["relating_connection"]
|
||||
):
|
||||
incompatible_connections.append(rel)
|
||||
|
||||
for rel in self.settings["related_element"].ConnectedFrom:
|
||||
if not rel.is_a("IfcRelConnectsPathElements"):
|
||||
continue
|
||||
if (
|
||||
rel.RelatedConnectionType in ["ATSTART", "ATEND"]
|
||||
and rel.RelatedConnectionType == self.settings["related_connection"]
|
||||
):
|
||||
incompatible_connections.append(rel)
|
||||
for rel in settings["related_element"].ConnectedFrom:
|
||||
if not rel.is_a("IfcRelConnectsPathElements"):
|
||||
continue
|
||||
if (
|
||||
rel.RelatedConnectionType in ["ATSTART", "ATEND"]
|
||||
and rel.RelatedConnectionType == settings["related_connection"]
|
||||
):
|
||||
incompatible_connections.append(rel)
|
||||
|
||||
for rel in self.settings["related_element"].ConnectedTo:
|
||||
if not rel.is_a("IfcRelConnectsPathElements"):
|
||||
continue
|
||||
if rel.RelatedElement == self.settings["relating_element"]:
|
||||
incompatible_connections.append(rel)
|
||||
elif (
|
||||
rel.RelatingConnectionType in ["ATSTART", "ATEND"]
|
||||
and rel.RelatingConnectionType == self.settings["related_connection"]
|
||||
):
|
||||
incompatible_connections.append(rel)
|
||||
for rel in settings["related_element"].ConnectedTo:
|
||||
if not rel.is_a("IfcRelConnectsPathElements"):
|
||||
continue
|
||||
if rel.RelatedElement == settings["relating_element"]:
|
||||
incompatible_connections.append(rel)
|
||||
elif (
|
||||
rel.RelatingConnectionType in ["ATSTART", "ATEND"]
|
||||
and rel.RelatingConnectionType == settings["related_connection"]
|
||||
):
|
||||
incompatible_connections.append(rel)
|
||||
|
||||
if incompatible_connections:
|
||||
for connection in set(incompatible_connections):
|
||||
history = connection.OwnerHistory
|
||||
self.file.remove(connection)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(self.file, history)
|
||||
if incompatible_connections:
|
||||
for connection in set(incompatible_connections):
|
||||
history = connection.OwnerHistory
|
||||
file.remove(connection)
|
||||
if history:
|
||||
ifcopenshell.util.element.remove_deep2(file, history)
|
||||
|
||||
return self.file.createIfcRelConnectsPathElements(
|
||||
ifcopenshell.guid.new(),
|
||||
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
Description=self.settings["description"],
|
||||
RelatingElement=self.settings["relating_element"],
|
||||
RelatedElement=self.settings["related_element"],
|
||||
RelatingConnectionType=self.settings["relating_connection"],
|
||||
RelatedConnectionType=self.settings["related_connection"],
|
||||
RelatingPriorities=[],
|
||||
RelatedPriorities=[],
|
||||
)
|
||||
return file.createIfcRelConnectsPathElements(
|
||||
ifcopenshell.guid.new(),
|
||||
OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", file),
|
||||
Description=settings["description"],
|
||||
RelatingElement=settings["relating_element"],
|
||||
RelatedElement=settings["related_element"],
|
||||
RelatingConnectionType=settings["relating_connection"],
|
||||
RelatedConnectionType=settings["related_connection"],
|
||||
RelatingPriorities=[],
|
||||
RelatedPriorities=[],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user