Compare commits

...

2 Commits

Author SHA1 Message Date
Andrej730 59eaa05a62 tests for system.get_connected_to / get_connected_from 2023-08-01 13:38:18 +05:00
Andrej730 99a3535959 error message on setting flow direction for disconnected port
previously it just did nothing which was a bit confusing
2023-08-01 13:17:35 +05:00
3 changed files with 33 additions and 2 deletions
@@ -201,6 +201,11 @@ class SetFlowDirection(bpy.types.Operator, Operator):
direction: bpy.props.StringProperty()
def _execute(self, context):
port = tool.Ifc.get_entity(context.active_object)
second_port = tool.System.get_connected_port(port)
if not second_port:
self.report({"ERROR"}, "To set flow direction port hast to be connected to another one.")
return
core.set_flow_direction(
tool.Ifc, tool.System, port=tool.Ifc.get_entity(context.active_object), direction=self.direction
)
@@ -84,7 +84,6 @@ def get_connected_port(port):
return rel.RelatingPort
# TODO: cover in tests
def get_connected_to(element):
results = []
for port in ifcopenshell.util.system.get_ports(element):
@@ -102,7 +101,6 @@ def get_connected_to(element):
return results
# TODO: cover in tests
def get_connected_from(element):
results = []
for port in ifcopenshell.util.system.get_ports(element):
@@ -79,3 +79,31 @@ class TestGetConnectedPort(test.bootstrap.IFC4):
ifcopenshell.api.run("system.connect_port", self.file, port1=port1, port2=port2)
assert subject.get_connected_port(port1) == port2
assert subject.get_connected_port(port2) == port1
class TestGetConnectedToFrom(test.bootstrap.IFC4):
def test_run(self):
port1 = ifcopenshell.api.run("system.add_port", self.file)
element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
ifcopenshell.api.run("system.assign_port", self.file, element=element1, port=port1)
port2 = ifcopenshell.api.run("system.add_port", self.file)
element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcFlowSegment")
ifcopenshell.api.run("system.assign_port", self.file, element=element2, port=port2)
ifcopenshell.api.run("system.connect_port", self.file, port1=port1, port2=port2, direction="SOURCE")
assert subject.get_connected_to(element1) == [element2]
assert subject.get_connected_from(element1) == []
assert subject.get_connected_to(element2) == []
assert subject.get_connected_from(element2) == [element1]
ifcopenshell.api.run("system.connect_port", self.file, port1=port1, port2=port2, direction="SINK")
assert subject.get_connected_to(element1) == []
assert subject.get_connected_from(element1) == [element2]
assert subject.get_connected_to(element2) == [element1]
assert subject.get_connected_from(element2) == []
class TestGetConnectedToFromIFC2X3(test.bootstrap.IFC2X3):
def test_run(self):
TestGetConnectedToFrom.test_run(self)