mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Enhance show_ports (also shows ports of connected objects) and refine UI layout
This commit is contained in:
@@ -186,6 +186,7 @@ class ShowPorts(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.show_ports"
|
||||
bl_label = "Show Ports"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
element_id: bpy.props.IntProperty(default=0, options={"SKIP_SAVE"})
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
@@ -198,7 +199,19 @@ class ShowPorts(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
def _execute(self, context):
|
||||
# Ifc.Operator - as operator will sync object's position with IFC.
|
||||
core.show_ports(tool.Ifc, tool.System, tool.Spatial, element=tool.Ifc.get_entity(context.active_object))
|
||||
if self.element_id != 0:
|
||||
element = tool.Ifc.get().by_id(self.element_id)
|
||||
else:
|
||||
element = tool.Ifc.get_entity(context.active_object)
|
||||
core.show_ports(tool.Ifc, tool.System, tool.Spatial, element=element)
|
||||
|
||||
for port in tool.System.get_ports(element):
|
||||
connected_port = tool.System.get_connected_port(port)
|
||||
if connected_port:
|
||||
connected_port_obj = tool.Ifc.get_object(connected_port)
|
||||
if not connected_port_obj:
|
||||
parent_element = tool.System.get_port_relating_element(connected_port)
|
||||
core.show_ports(tool.Ifc, tool.System, tool.Spatial, element=parent_element)
|
||||
|
||||
|
||||
class HidePorts(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
@@ -121,11 +121,9 @@ def update_related_port_object(self: "BIMSystemProperties", context: bpy.types.C
|
||||
target_element = tool.Ifc.get_entity(self.related_port_object)
|
||||
|
||||
if not source_element or not target_element:
|
||||
self.related_port_object = None
|
||||
return
|
||||
|
||||
if not target_element.is_a("IfcDistributionPort"):
|
||||
self.related_port_object = None
|
||||
return
|
||||
|
||||
source_port = None
|
||||
@@ -135,11 +133,9 @@ def update_related_port_object(self: "BIMSystemProperties", context: bpy.types.C
|
||||
break
|
||||
|
||||
if not source_port:
|
||||
self.related_port_object = None
|
||||
return
|
||||
|
||||
core.connect_port(tool.Ifc, port1=source_port, port2=target_element)
|
||||
self.related_port_object = None
|
||||
PortData.is_loaded = False
|
||||
|
||||
|
||||
@@ -161,8 +157,9 @@ class BIMSystemProperties(PropertyGroup):
|
||||
related_port_object: PointerProperty(
|
||||
type=bpy.types.Object,
|
||||
name="Connect To Port",
|
||||
update=update_related_port_object,
|
||||
description="Select a port to connect to. Use eyedropper to pick a port object",
|
||||
poll=is_port_available_for_connection,
|
||||
update=update_related_port_object,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
@@ -169,6 +169,9 @@ class BIM_PT_ports(Panel):
|
||||
|
||||
row = self.layout.row(align=True)
|
||||
cols = [row.column(align=True) for i in range(9)]
|
||||
cols[3].scale_x = 1.0
|
||||
cols[6].scale_x = 1.0
|
||||
cols[8].scale_x = 1.33
|
||||
|
||||
for port_data in PortData.data["located_ports_data"]:
|
||||
flow_direction_icon = FLOW_DIRECTION_TO_ICON[port_data["FlowDirection"] or "NOTDEFINED"]
|
||||
@@ -178,7 +181,9 @@ class BIM_PT_ports(Panel):
|
||||
op = cols[1].operator("bim.cycle_flow_direction", text="", icon=flow_direction_icon, emboss=True)
|
||||
op.port_id = port_data["id"]
|
||||
else:
|
||||
cols[0].label(text="", icon="BLANK1")
|
||||
blank0 = cols[0].column(align=True)
|
||||
blank0.scale_x = 0.1
|
||||
blank0.label(text="", icon="BLANK1")
|
||||
op = cols[1].operator("bim.cycle_flow_direction", text="", icon=flow_direction_icon, emboss=True)
|
||||
op.port_id = port_data["id"]
|
||||
|
||||
@@ -196,26 +201,49 @@ class BIM_PT_ports(Panel):
|
||||
port = tool.Ifc.get().by_id(port_data["id"])
|
||||
connected_port = tool.System.get_connected_port(port)
|
||||
if connected_port:
|
||||
connected_port_flow_dir = FLOW_DIRECTION_TO_ICON[connected_port.FlowDirection or "NOTDEFINED"]
|
||||
op = cols[4].operator("bim.cycle_flow_direction", text="", icon=connected_port_flow_dir, emboss=True)
|
||||
op.port_id = connected_port.id()
|
||||
cols[5].operator("bim.select_entity", text="", icon="RESTRICT_SELECT_OFF").ifc_id = connected_port.id()
|
||||
connected_port_obj = tool.Ifc.get_object(connected_port)
|
||||
cols[6].label(text=connected_port_obj.name if connected_port_obj else "Hidden Port")
|
||||
if connected_port_obj:
|
||||
connected_port_flow_dir = FLOW_DIRECTION_TO_ICON[connected_port.FlowDirection or "NOTDEFINED"]
|
||||
op = cols[4].operator("bim.cycle_flow_direction", text="", icon=connected_port_flow_dir, emboss=True)
|
||||
op.port_id = connected_port.id()
|
||||
cols[5].operator("bim.select_entity", text="", icon="RESTRICT_SELECT_OFF").ifc_id = connected_port.id()
|
||||
cols[6].label(text=connected_port_obj.name)
|
||||
else:
|
||||
blank4 = cols[4].column(align=True)
|
||||
blank4.scale_x = 0.1
|
||||
blank4.label(text="", icon="BLANK1")
|
||||
blank5 = cols[5].column(align=True)
|
||||
blank5.scale_x = 0.1
|
||||
blank5.label(text="", icon="BLANK1")
|
||||
cols[6].label(text="Port is hidden")
|
||||
else:
|
||||
cols[4].label(text="", icon="BLANK1")
|
||||
cols[5].label(text="", icon="BLANK1")
|
||||
blank4 = cols[4].column(align=True)
|
||||
blank4.scale_x = 0.1
|
||||
blank4.label(text="", icon="BLANK1")
|
||||
blank5 = cols[5].column(align=True)
|
||||
blank5.scale_x = 0.1
|
||||
blank5.label(text="", icon="BLANK1")
|
||||
cols[6].label(text="")
|
||||
|
||||
ifc_id = tool.Blender.get_ifc_definition_id(connected_obj)
|
||||
cols[7].operator("bim.select_entity", text="", icon="RESTRICT_SELECT_OFF").ifc_id = ifc_id
|
||||
cols[8].label(text=port_data["connected_obj_name"])
|
||||
else:
|
||||
cols[4].label(text="", icon="BLANK1")
|
||||
cols[5].label(text="", icon="BLANK1")
|
||||
cols[6].alignment = 'LEFT'
|
||||
cols[6].prop(props, "related_port_object", text="")
|
||||
cols[7].label(text="", icon="BLANK1")
|
||||
blank4 = cols[4].column(align=True)
|
||||
blank4.scale_x = 0.1
|
||||
blank4.label(text="", icon="BLANK1")
|
||||
blank5 = cols[5].column(align=True)
|
||||
blank5.scale_x = 0.1
|
||||
blank5.label(text="", icon="BLANK1")
|
||||
|
||||
col6_row = cols[6].row(align=True)
|
||||
col6_row.alignment = 'LEFT'
|
||||
col6_row.prop(props, "related_port_object", text="", icon='OBJECT_DATA')
|
||||
col6_row.scale_x = 0.35
|
||||
|
||||
blank7 = cols[7].column(align=True)
|
||||
blank7.scale_x = 0.1
|
||||
blank7.label(text="", icon="BLANK1")
|
||||
cols[8].label(text="Port is disconnected")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user