mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
cleanup and black .
This commit is contained in:
@@ -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,12 +198,9 @@ 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):
|
||||
connected_port = tool.System.get_connected_port(port)
|
||||
if connected_port:
|
||||
@@ -260,37 +256,39 @@ 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):
|
||||
bl_idname = "bim.add_related_port_connection"
|
||||
bl_label = "Connect Port"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
|
||||
relating_port_id: bpy.props.IntProperty()
|
||||
|
||||
|
||||
def invoke(self, context, event):
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
|
||||
def draw(self, context):
|
||||
props = tool.System.get_system_props()
|
||||
self.layout.prop(props, "related_port", text="Select Port")
|
||||
|
||||
|
||||
def _execute(self, context):
|
||||
props = tool.System.get_system_props()
|
||||
|
||||
|
||||
if not props.related_port or props.related_port == "NONE":
|
||||
return {"CANCELLED"}
|
||||
|
||||
|
||||
port_obj = bpy.data.objects.get(props.related_port)
|
||||
related_port = tool.Ifc.get_entity(port_obj)
|
||||
relating_port = tool.Ifc.get().by_id(self.relating_port_id)
|
||||
|
||||
|
||||
direction = relating_port.FlowDirection or "NOTDEFINED"
|
||||
core.connect_port(tool.Ifc, port1=relating_port, port2=related_port, direction=direction)
|
||||
PortData.is_loaded = False
|
||||
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -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):
|
||||
@@ -451,30 +446,32 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
|
||||
return {"CANCELLED"}
|
||||
|
||||
current_direction = port.FlowDirection or "NOTDEFINED"
|
||||
|
||||
|
||||
flow_cycle_map = {
|
||||
"SOURCE": "SINK",
|
||||
"SINK": "SOURCEANDSINK",
|
||||
"SOURCEANDSINK": "NOTDEFINED",
|
||||
"NOTDEFINED": "SOURCE"
|
||||
"NOTDEFINED": "SOURCE",
|
||||
}
|
||||
next_direction = flow_cycle_map.get(current_direction, "SOURCE")
|
||||
|
||||
tool.Ifc.run("attribute.edit_attributes", product=port, attributes={"FlowDirection": next_direction})
|
||||
|
||||
|
||||
connected_port = tool.System.get_connected_port(port)
|
||||
if connected_port:
|
||||
connected_direction_map = {
|
||||
"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
|
||||
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
|
||||
@@ -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,23 +92,25 @@ 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)))
|
||||
|
||||
|
||||
ifc_file = tool.Ifc.get()
|
||||
for ifc_port in ifc_file.by_type("IfcDistributionPort"):
|
||||
port = tool.Ifc.get_object(ifc_port)
|
||||
if not port:
|
||||
continue
|
||||
|
||||
|
||||
if tool.System.get_connected_port(ifc_port) is not None or ifc_port in active_object_ports:
|
||||
continue
|
||||
|
||||
|
||||
port_object = tool.Ifc.get_object(tool.System.get_port_relating_element(ifc_port))
|
||||
suggestion = f"{port_object.name} > {port.name}"
|
||||
items.append((port.name, suggestion, ""))
|
||||
|
||||
|
||||
return items if items else [("NONE", "Ports are hidden or not available", "")]
|
||||
|
||||
|
||||
|
||||
@@ -162,11 +162,9 @@ 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)]
|
||||
cols[3].scale_x = 1.0
|
||||
@@ -175,18 +173,17 @@ class BIM_PT_ports(Panel):
|
||||
|
||||
for port_data in PortData.data["located_ports_data"]:
|
||||
flow_direction_icon = FLOW_DIRECTION_TO_ICON[port_data["FlowDirection"] or "NOTDEFINED"]
|
||||
|
||||
|
||||
if port_data["connected_obj_name"]:
|
||||
cols[0].operator("bim.disconnect_port", text="", icon="UNLINKED").element_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"]
|
||||
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"])
|
||||
@@ -196,16 +193,20 @@ class BIM_PT_ports(Panel):
|
||||
|
||||
if port_data["connected_obj_name"]:
|
||||
connected_obj = bpy.data.objects[port_data["connected_obj_name"]]
|
||||
|
||||
|
||||
port = tool.Ifc.get().by_id(port_data["id"])
|
||||
connected_port = tool.System.get_connected_port(port)
|
||||
if connected_port:
|
||||
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)
|
||||
@@ -223,7 +224,7 @@ class BIM_PT_ports(Panel):
|
||||
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"])
|
||||
@@ -234,9 +235,9 @@ class BIM_PT_ports(Panel):
|
||||
blank5 = cols[5].column(align=True)
|
||||
blank5.scale_x = 0.1
|
||||
blank5.label(text="", icon="BLANK1")
|
||||
|
||||
|
||||
cols[6].label(text="Port is disconnected")
|
||||
|
||||
|
||||
blank7 = cols[7].column(align=True)
|
||||
blank7.scale_x = 0.1
|
||||
blank7.label(text="", icon="BLANK1")
|
||||
@@ -265,17 +266,8 @@ 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()
|
||||
@@ -283,18 +275,21 @@ class BIM_PT_port(Panel):
|
||||
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)]
|
||||
cols[3].scale_x = 1.0
|
||||
cols[6].scale_x = 1.0
|
||||
cols[8].scale_x = 1.33
|
||||
|
||||
|
||||
flow_direction_icon = FLOW_DIRECTION_TO_ICON[element.FlowDirection or "NOTDEFINED"]
|
||||
connected_port = tool.System.get_connected_port(element)
|
||||
|
||||
|
||||
if connected_port:
|
||||
cols[0].operator("bim.disconnect_port", text="", icon="UNLINKED")
|
||||
op = cols[1].operator("bim.cycle_flow_direction", text="", icon=flow_direction_icon, emboss=True)
|
||||
@@ -303,10 +298,10 @@ class BIM_PT_port(Panel):
|
||||
cols[0].operator("bim.connect_port", icon="PLUGIN", text="")
|
||||
op = cols[1].operator("bim.cycle_flow_direction", text="", icon=flow_direction_icon, emboss=True)
|
||||
op.port_id = element.id()
|
||||
|
||||
|
||||
cols[2].operator("bim.select_entity", text="", icon="RESTRICT_SELECT_OFF").ifc_id = element.id()
|
||||
cols[3].label(text=context.active_object.name)
|
||||
|
||||
|
||||
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)
|
||||
@@ -314,7 +309,7 @@ class BIM_PT_port(Panel):
|
||||
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")
|
||||
|
||||
|
||||
connected_object_name = PortData.data["port_connected_object_name"]
|
||||
if connected_object_name:
|
||||
connected_obj = bpy.data.objects[connected_object_name]
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user