mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +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
|
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:
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user