mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Ports UI - cache instead of accesing IFC on draw calls
This commit is contained in:
@@ -168,7 +168,7 @@ class PortData:
|
||||
return tool.Ifc.get_object(connected_element).name
|
||||
|
||||
@classmethod
|
||||
def located_ports_data(cls):
|
||||
def located_ports_data(cls) -> list[dict[str, Any]]:
|
||||
ports = ifcopenshell.util.system.get_ports(cls.element)
|
||||
|
||||
data = []
|
||||
@@ -181,17 +181,24 @@ class PortData:
|
||||
else:
|
||||
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
|
||||
|
||||
@classmethod
|
||||
def selected_objects_flow_direction(cls):
|
||||
for port, _, connected_obj_name in cls.data["located_ports_data"]:
|
||||
if connected_obj_name is None:
|
||||
def selected_objects_flow_direction(cls) -> Union[str, None]:
|
||||
for port_data in cls.data["located_ports_data"]:
|
||||
if port_data["connected_obj_name"] is None:
|
||||
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:
|
||||
return port.FlowDirection
|
||||
return port_data["FlowDirection"]
|
||||
|
||||
|
||||
class SystemDecorationData:
|
||||
|
||||
@@ -186,24 +186,23 @@ class BIM_PT_ports(Panel):
|
||||
row = self.layout.row(align=True)
|
||||
cols = [row.column(align=True) for i in range(6)]
|
||||
|
||||
for i, port_data in enumerate(PortData.data["located_ports_data"]):
|
||||
port, port_obj_name, connected_obj_name = port_data
|
||||
flow_direction_icon = FLOW_DIRECTION_TO_ICON[port.FlowDirection or "NOTDEFINED"]
|
||||
if port_obj_name:
|
||||
for port_data in PortData.data["located_ports_data"]:
|
||||
flow_direction_icon = FLOW_DIRECTION_TO_ICON[port_data["FlowDirection"] or "NOTDEFINED"]
|
||||
if port_data["port_obj_name"]:
|
||||
cols[0].label(text="", icon=flow_direction_icon)
|
||||
cols[1].operator("bim.select_entity", text="", icon="RESTRICT_SELECT_OFF").ifc_id = port.id()
|
||||
cols[2].label(text=port_obj_name)
|
||||
cols[1].operator("bim.select_entity", text="", icon="RESTRICT_SELECT_OFF").ifc_id = port_data["id"]
|
||||
cols[2].label(text=port_data["port_obj_name"])
|
||||
else:
|
||||
cols[0].label(text="", icon=flow_direction_icon)
|
||||
cols[1].label(text="", icon="HIDE_ON")
|
||||
cols[2].label(text="Port is hidden")
|
||||
|
||||
if connected_obj_name:
|
||||
connected_obj = bpy.data.objects[connected_obj_name]
|
||||
cols[3].operator("bim.disconnect_port", text="", icon="UNLINKED").element_id = port.id()
|
||||
if port_data["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_data["id"]
|
||||
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[5].label(text=connected_obj_name)
|
||||
cols[5].label(text=port_data["connected_obj_name"])
|
||||
else:
|
||||
cols[3].label(text="", icon="UNLINKED")
|
||||
cols[4].label(text="", icon="BLANK1")
|
||||
|
||||
Reference in New Issue
Block a user