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
@@ -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,
)