cleanup and black .

This commit is contained in:
falken10vdl
2026-01-13 08:49:57 +01:00
parent 1eb2b65268
commit 791a41d649
6 changed files with 66 additions and 68 deletions
+13 -16
View File
@@ -186,7 +186,6 @@ 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):
@@ -199,10 +198,7 @@ class ShowPorts(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
# Ifc.Operator - as operator will sync object's position with IFC.
if self.element_id != 0:
element = tool.Ifc.get().by_id(self.element_id)
else:
element = tool.Ifc.get_entity(context.active_object)
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):
@@ -260,7 +256,9 @@ class ConnectPort(bpy.types.Operator, tool.Ifc.Operator):
obj1 = context.active_object
obj2 = context.selected_objects[0] if context.selected_objects[1] == obj1 else context.selected_objects[1]
direction = tool.Ifc.get_entity(obj1).FlowDirection or "NOTDEFINED"
core.connect_port(tool.Ifc, port1=tool.Ifc.get_entity(obj1), port2=tool.Ifc.get_entity(obj2), direction=direction)
core.connect_port(
tool.Ifc, port1=tool.Ifc.get_entity(obj1), port2=tool.Ifc.get_entity(obj2), direction=direction
)
class AddRelatedPortConnection(bpy.types.Operator, tool.Ifc.Operator):
@@ -436,13 +434,10 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
@classmethod
def description(cls, context, operator):
try:
port = tool.Ifc.get().by_id(operator.port_id)
if port and port.is_a("IfcDistributionPort"):
current_direction = port.FlowDirection or "NOTDEFINED"
return f"Current flow direction: {current_direction}. Click to cycle: SOURCE → SINK → SOURCEANDSINK → NOTDEFINED"
except:
pass
port = tool.Ifc.get().by_id(operator.port_id)
if port and port.is_a("IfcDistributionPort"):
current_direction = port.FlowDirection or "NOTDEFINED"
return f"Current flow direction: {current_direction}. Click to cycle: SOURCE → SINK → SOURCEANDSINK → NOTDEFINED"
return "Cycle through flow directions: SOURCE → SINK → SOURCEANDSINK → NOTDEFINED → SOURCE..."
def _execute(self, context):
@@ -456,7 +451,7 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
"SOURCE": "SINK",
"SINK": "SOURCEANDSINK",
"SOURCEANDSINK": "NOTDEFINED",
"NOTDEFINED": "SOURCE"
"NOTDEFINED": "SOURCE",
}
next_direction = flow_cycle_map.get(current_direction, "SOURCE")
@@ -468,10 +463,12 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
"SOURCE": "SINK",
"SINK": "SOURCE",
"SOURCEANDSINK": "SOURCEANDSINK",
"NOTDEFINED": "NOTDEFINED"
"NOTDEFINED": "NOTDEFINED",
}
connected_direction = connected_direction_map.get(next_direction, "NOTDEFINED")
tool.Ifc.run("attribute.edit_attributes", product=connected_port, attributes={"FlowDirection": connected_direction})
tool.Ifc.run(
"attribute.edit_attributes", product=connected_port, attributes={"FlowDirection": connected_direction}
)
PortData.is_loaded = False
+3 -2
View File
@@ -19,7 +19,6 @@
import bpy
import bonsai.bim.handler
import bonsai.tool as tool
import bonsai.core.system as core
from bonsai.bim.module.system.data import SystemData
import bonsai.bim.module.system.decorator as decorator
from bonsai.bim.prop import StrProperty, Attribute
@@ -93,7 +92,9 @@ def toggle_decorations(self: "BIMSystemProperties", context: bpy.types.Context)
decorator.SystemDecorator.uninstall()
def get_available_ports_for_connection(self: "BIMSystemProperties", context: bpy.types.Context) -> list[tuple[str, str, str]]:
def get_available_ports_for_connection(
self: "BIMSystemProperties", context: bpy.types.Context
) -> list[tuple[str, str, str]]:
items = []
active_object_ports = set(tool.System.get_ports(tool.Ifc.get_entity(context.active_object)))
+12 -17
View File
@@ -162,10 +162,8 @@ class BIM_PT_ports(Panel):
if total_ports == 0:
return
props = tool.System.get_system_props()
row = self.layout.row(align=True)
row.label(text="Ports located on object and connected Port/Objects:")
row.label(text=f"Ports located in: {context.active_object.name} and connected Port/Objects:")
row = self.layout.row(align=True)
cols = [row.column(align=True) for i in range(9)]
@@ -181,12 +179,11 @@ 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:
op = cols[0].operator("bim.add_related_port_connection", text="", icon='PLUGIN')
op = cols[0].operator("bim.add_related_port_connection", text="", icon="PLUGIN")
op.relating_port_id = port_data["id"]
op = cols[1].operator("bim.cycle_flow_direction", text="", icon=flow_direction_icon, emboss=True)
op.port_id = port_data["id"]
# Port information
if port_data["port_obj_name"]:
cols[2].operator("bim.select_entity", text="", icon="RESTRICT_SELECT_OFF").ifc_id = port_data["id"]
cols[3].label(text=port_data["port_obj_name"])
@@ -203,9 +200,13 @@ class BIM_PT_ports(Panel):
connected_port_obj = tool.Ifc.get_object(connected_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 = 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[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)
@@ -265,26 +266,20 @@ class BIM_PT_port(Panel):
return True
def draw(self, context):
self.props = tool.System.get_system_props()
layout = self.layout
row = layout.row(align=True)
if not PortData.is_loaded:
PortData.load()
relating_object_name = PortData.data["port_relating_object_name"] if PortData.data["is_port"] else ""
row.label(text=f"IfcDistributionPort located in: {relating_object_name}")
row.operator("bim.remove_port", icon="X", text="")
if not PortData.is_loaded:
PortData.load()
if not PortData.data["is_port"]:
return
relating_object_name = PortData.data["port_relating_object_name"]
row.label(text=f"IfcDistributionPort located in: {relating_object_name}")
row.operator("bim.remove_port", icon="X", text="")
element = tool.Ifc.get_entity(context.active_object)
props = tool.System.get_system_props()
row = layout.row(align=True)
cols = [row.column(align=True) for i in range(9)]
+6 -1
View File
@@ -132,7 +132,12 @@ def remove_port(ifc: type[tool.Ifc], system: type[tool.System], port: ifcopenshe
ifc.run("root.remove_product", product=port)
def connect_port(ifc: type[tool.Ifc], port1: ifcopenshell.entity_instance, port2: ifcopenshell.entity_instance, direction: str = "NOTDEFINED") -> None:
def connect_port(
ifc: type[tool.Ifc],
port1: ifcopenshell.entity_instance,
port2: ifcopenshell.entity_instance,
direction: str = "NOTDEFINED",
) -> None:
ifc.run("system.connect_port", port1=port1, port2=port2, direction=direction)
+1
View File
@@ -100,6 +100,7 @@ class System(bonsai.core.tool.System):
@classmethod
def create_empty_at_cursor_with_element_orientation(cls, element: ifcopenshell.entity_instance) -> bpy.types.Object:
# Is this necessary anymore?
element_obj = tool.Ifc.get_object(element)
obj = bpy.data.objects.new("Port", None)
obj.matrix_world = element_obj.matrix_world
@@ -490,8 +490,7 @@ class Usecase:
attribute_class = None
if "." in attribute:
attribute, attribute_class = attribute.split(".")
inverse_values = getattr(element, attribute, [])
for inverse in inverse_values:
for inverse in getattr(element, attribute, []):
if attribute_class and inverse.is_a(attribute_class):
self.add_inverse_element(inverse)
elif not attribute_class: