Implement connection aware wall L-joints

This commit is contained in:
Dion Moult
2022-09-16 18:30:57 +10:00
parent d106b0e017
commit f93604d6b7
6 changed files with 289 additions and 111 deletions
@@ -33,27 +33,42 @@ class Usecase:
self.settings[key] = value
def execute(self):
existing_connection = [
r
for r in self.settings["relating_element"].ConnectedTo
if r.RelatedElement == self.settings["related_element"]
]
incompatible_connections = []
for rel in self.settings["relating_element"].ConnectedTo:
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)
if existing_connection:
existing_connection = existing_connection[0]
if existing_connection.RelatingConnectionType != self.settings["relating_connection"]:
existing_connection.RelatingConnectionType = self.settings["relating_connection"]
if existing_connection.RelatedConnectionType != self.settings["related_connection"]:
existing_connection.RelatedConnectionType = self.settings["related_connection"]
return existing_connection[0]
for rel in self.settings["relating_element"].ConnectedFrom:
if (
rel.RelatedConnectionType in ["ATSTART", "ATEND"]
and rel.RelatedConnectionType == self.settings["relating_connection"]
):
incompatible_connections.append(rel)
if [
r
for r in self.settings["related_element"].ConnectedTo
if r.RelatedElement == self.settings["relating_element"]
]:
# No cyclical connections allowed, I assume
return
for rel in self.settings["related_element"].ConnectedFrom:
if (
rel.RelatedConnectionType in ["ATSTART", "ATEND"]
and rel.RelatedConnectionType == self.settings["related_connection"]
):
incompatible_connections.append(rel)
for rel in self.settings["related_element"].ConnectedTo:
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)
if incompatible_connections:
for connection in set(incompatible_connections):
self.file.remove(connection)
return self.file.createIfcRelConnectsPathElements(
ifcopenshell.guid.new(),
@@ -26,16 +26,29 @@ class Usecase:
self.settings = {
"relating_element": None,
"related_element": None,
"element": None,
"connection_type": None,
}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
existing_connection = [
r
for r in self.settings["relating_element"].ConnectedTo
if r.RelatedElement == self.settings["related_element"]
]
if self.settings["connection_type"] and self.settings["element"]:
connections = [
r
for r in self.settings["element"].ConnectedTo
if r.RelatingConnectionType == self.settings["connection_type"]
] + [
r
for r in self.settings["element"].ConnectedFrom
if r.RelatedConnectionType == self.settings["connection_type"]
]
else:
connections = [
r
for r in self.settings["relating_element"].ConnectedTo
if r.RelatedElement == self.settings["related_element"]
]
if existing_connection:
self.file.remove(existing_connection[0])
for connection in set(connections):
self.file.remove(connection)
@@ -24,14 +24,7 @@ class TestConnectPath(test.bootstrap.IFC4):
def test_connecting_a_path(self):
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
rel = ifcopenshell.api.run(
"geometry.connect_path",
self.file,
relating_element=wall1,
related_element=wall2,
relating_connection="ATSTART",
related_connection="ATEND",
)
rel = self.connect_path(wall1, wall2, "ATSTART", "ATEND")
assert rel.is_a("IfcRelConnectsPathElements")
assert rel.RelatingElement == wall1
assert rel.RelatedElement == wall2
@@ -39,12 +32,21 @@ class TestConnectPath(test.bootstrap.IFC4):
assert rel.RelatedConnectionType == "ATEND"
def test_doing_nothing_if_the_element_is_already_connected(self):
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
self.connect_path(wall1, wall2)
total_elements = len([e for e in self.file])
self.connect_path(wall1, wall2)
assert len([e for e in self.file]) == total_elements
def test_updating_the_connection_type_if_already_connected(self):
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run("geometry.connect_path", self.file, relating_element=wall1, related_element=wall2)
total_elements = len([e for e in self.file])
ifcopenshell.api.run("geometry.connect_path", self.file, relating_element=wall1, related_element=wall2)
assert len([e for e in self.file]) == total_elements
rel = self.connect_path(wall1, wall2, "ATSTART")
assert rel.RelatingConnectionType == "ATSTART"
assert rel.RelatedConnectionType == "NOTDEFINED"
def test_preventing_cyclical_connections(self):
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
@@ -53,3 +55,87 @@ class TestConnectPath(test.bootstrap.IFC4):
total_elements = len([e for e in self.file])
ifcopenshell.api.run("geometry.connect_path", self.file, relating_element=wall2, related_element=wall1)
assert len([e for e in self.file]) == total_elements
def test_a_relating_element_can_have_multiple_path_connections(self):
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
rel1 = self.connect_path(wall1, wall2, "ATPATH", "ATEND")
rel2 = self.connect_path(wall1, wall3, "ATPATH", "ATSTART")
assert len(self.file.by_type("IfcRelConnectsPathElements")) == 2
assert rel1.RelatingElement == wall1
assert rel1.RelatedElement == wall2
assert rel1.RelatingConnectionType == "ATPATH"
assert rel1.RelatedConnectionType == "ATEND"
assert rel2.RelatingElement == wall1
assert rel2.RelatedElement == wall3
assert rel2.RelatingConnectionType == "ATPATH"
assert rel2.RelatedConnectionType == "ATSTART"
def test_a_element_can_only_have_up_to_one_start_or_end_connections(self):
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
rel1 = self.connect_path(wall1, wall2, "ATSTART", "ATEND")
rel2 = self.connect_path(wall1, wall3, "ATEND", "ATSTART")
assert len(self.file.by_type("IfcRelConnectsPathElements")) == 2
self.file = ifcopenshell.file()
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
rel1 = self.connect_path(wall1, wall2, "ATSTART", "ATEND")
rel2 = self.connect_path(wall1, wall3, "ATSTART", "ATSTART")
assert len(self.file.by_type("IfcRelConnectsPathElements")) == 1
self.file = ifcopenshell.file()
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
rel1 = self.connect_path(wall1, wall2, "ATEND", "ATEND")
rel2 = self.connect_path(wall1, wall3, "ATEND", "ATSTART")
assert len(self.file.by_type("IfcRelConnectsPathElements")) == 1
self.file = ifcopenshell.file()
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
rel1 = self.connect_path(wall1, wall2, "ATPATH", "ATEND")
rel2 = self.connect_path(wall1, wall3, "ATPATH", "ATSTART")
assert len(self.file.by_type("IfcRelConnectsPathElements")) == 2
self.file = ifcopenshell.file()
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
rel1 = self.connect_path(wall2, wall1, "ATPATH", "ATEND")
rel2 = self.connect_path(wall3, wall1, "ATPATH", "ATSTART")
assert len(self.file.by_type("IfcRelConnectsPathElements")) == 2
self.file = ifcopenshell.file()
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
rel1 = self.connect_path(wall2, wall1, "ATPATH", "ATSTART")
rel2 = self.connect_path(wall3, wall1, "ATPATH", "ATSTART")
assert len(self.file.by_type("IfcRelConnectsPathElements")) == 1
self.file = ifcopenshell.file()
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
rel1 = self.connect_path(wall2, wall1, "ATPATH", "ATEND")
rel2 = self.connect_path(wall3, wall1, "ATPATH", "ATEND")
assert len(self.file.by_type("IfcRelConnectsPathElements")) == 1
def connect_path(
self, relating_element, related_element, relating_connection="NOTDEFINED", related_connection="NOTDEFINED"
):
return ifcopenshell.api.run(
"geometry.connect_path",
self.file,
relating_element=relating_element,
related_element=related_element,
relating_connection=relating_connection,
related_connection=related_connection,
)
@@ -28,6 +28,32 @@ class TestDisconnectPath(test.bootstrap.IFC4):
ifcopenshell.api.run("geometry.disconnect_path", self.file, relating_element=wall1, related_element=wall2)
assert not self.file.by_type("IfcRelConnectsPathElements")
def test_disconnecting_by_connection_type(self):
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
ifcopenshell.api.run(
"geometry.connect_path",
self.file,
relating_element=wall1,
related_element=wall2,
relating_connection="ATSTART",
related_connection="ATEND",
)
ifcopenshell.api.run("geometry.disconnect_path", self.file, element=wall1, connection_type="ATEND")
assert self.file.by_type("IfcRelConnectsPathElements")
ifcopenshell.api.run("geometry.disconnect_path", self.file, element=wall1, connection_type="ATSTART")
assert not self.file.by_type("IfcRelConnectsPathElements")
ifcopenshell.api.run(
"geometry.connect_path",
self.file,
relating_element=wall1,
related_element=wall2,
relating_connection="ATSTART",
related_connection="ATEND",
)
ifcopenshell.api.run("geometry.disconnect_path", self.file, element=wall2, connection_type="ATEND")
assert not self.file.by_type("IfcRelConnectsPathElements")
def test_doing_nothing_if_there_is_no_connection(self):
wall1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
wall2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")