Ports UI - cache instead of accesing IFC on draw calls

This commit is contained in:
Andrej730
2025-03-12 12:15:13 +05:00
parent ffc6c6a7ad
commit dccfb634d9
2 changed files with 23 additions and 17 deletions
+14 -7
View File
@@ -168,7 +168,7 @@ class PortData:
return tool.Ifc.get_object(connected_element).name return tool.Ifc.get_object(connected_element).name
@classmethod @classmethod
def located_ports_data(cls): def located_ports_data(cls) -> list[dict[str, Any]]:
ports = ifcopenshell.util.system.get_ports(cls.element) ports = ifcopenshell.util.system.get_ports(cls.element)
data = [] data = []
@@ -181,17 +181,24 @@ class PortData:
else: else:
connected_obj_name = None connected_obj_name = None
data.append((port, port_obj_name, connected_obj_name)) data.append(
{
"id": port.id(),
"FlowDirection": port.FlowDirection,
"port_obj_name": port_obj_name,
"connected_obj_name": connected_obj_name,
}
)
return data return data
@classmethod @classmethod
def selected_objects_flow_direction(cls): def selected_objects_flow_direction(cls) -> Union[str, None]:
for port, _, connected_obj_name in cls.data["located_ports_data"]: for port_data in cls.data["located_ports_data"]:
if connected_obj_name is None: if port_data["connected_obj_name"] is None:
continue continue
connected_obj = bpy.data.objects[connected_obj_name] connected_obj = bpy.data.objects[port_data["connected_obj_name"]]
if connected_obj in bpy.context.selected_objects: if connected_obj in bpy.context.selected_objects:
return port.FlowDirection return port_data["FlowDirection"]
class SystemDecorationData: class SystemDecorationData:
+9 -10
View File
@@ -186,24 +186,23 @@ class BIM_PT_ports(Panel):
row = self.layout.row(align=True) row = self.layout.row(align=True)
cols = [row.column(align=True) for i in range(6)] cols = [row.column(align=True) for i in range(6)]
for i, port_data in enumerate(PortData.data["located_ports_data"]): for port_data in PortData.data["located_ports_data"]:
port, port_obj_name, connected_obj_name = port_data flow_direction_icon = FLOW_DIRECTION_TO_ICON[port_data["FlowDirection"] or "NOTDEFINED"]
flow_direction_icon = FLOW_DIRECTION_TO_ICON[port.FlowDirection or "NOTDEFINED"] if port_data["port_obj_name"]:
if port_obj_name:
cols[0].label(text="", icon=flow_direction_icon) cols[0].label(text="", icon=flow_direction_icon)
cols[1].operator("bim.select_entity", text="", icon="RESTRICT_SELECT_OFF").ifc_id = port.id() cols[1].operator("bim.select_entity", text="", icon="RESTRICT_SELECT_OFF").ifc_id = port_data["id"]
cols[2].label(text=port_obj_name) cols[2].label(text=port_data["port_obj_name"])
else: else:
cols[0].label(text="", icon=flow_direction_icon) cols[0].label(text="", icon=flow_direction_icon)
cols[1].label(text="", icon="HIDE_ON") cols[1].label(text="", icon="HIDE_ON")
cols[2].label(text="Port is hidden") cols[2].label(text="Port is hidden")
if connected_obj_name: if port_data["connected_obj_name"]:
connected_obj = bpy.data.objects[connected_obj_name] connected_obj = bpy.data.objects[port_data["connected_obj_name"]]
cols[3].operator("bim.disconnect_port", text="", icon="UNLINKED").element_id = port.id() cols[3].operator("bim.disconnect_port", text="", icon="UNLINKED").element_id = port_data["id"]
ifc_id = tool.Blender.get_ifc_definition_id(connected_obj) ifc_id = tool.Blender.get_ifc_definition_id(connected_obj)
cols[4].operator("bim.select_entity", text="", icon="RESTRICT_SELECT_OFF").ifc_id = ifc_id cols[4].operator("bim.select_entity", text="", icon="RESTRICT_SELECT_OFF").ifc_id = ifc_id
cols[5].label(text=connected_obj_name) cols[5].label(text=port_data["connected_obj_name"])
else: else:
cols[3].label(text="", icon="UNLINKED") cols[3].label(text="", icon="UNLINKED")
cols[4].label(text="", icon="BLANK1") cols[4].label(text="", icon="BLANK1")