mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-01 01:16:27 +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_idname = "bim.show_ports"
|
||||||
bl_label = "Show Ports"
|
bl_label = "Show Ports"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
element_id: bpy.props.IntProperty(default=0, options={"SKIP_SAVE"})
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
@@ -199,10 +198,7 @@ class ShowPorts(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
# Ifc.Operator - as operator will sync object's position with IFC.
|
# Ifc.Operator - as operator will sync object's position with IFC.
|
||||||
if self.element_id != 0:
|
element = tool.Ifc.get_entity(context.active_object)
|
||||||
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)
|
core.show_ports(tool.Ifc, tool.System, tool.Spatial, element=element)
|
||||||
|
|
||||||
for port in tool.System.get_ports(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
|
obj1 = context.active_object
|
||||||
obj2 = context.selected_objects[0] if context.selected_objects[1] == obj1 else context.selected_objects[1]
|
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"
|
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):
|
class AddRelatedPortConnection(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
@@ -436,13 +434,10 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def description(cls, context, operator):
|
def description(cls, context, operator):
|
||||||
try:
|
port = tool.Ifc.get().by_id(operator.port_id)
|
||||||
port = tool.Ifc.get().by_id(operator.port_id)
|
if port and port.is_a("IfcDistributionPort"):
|
||||||
if port and port.is_a("IfcDistributionPort"):
|
current_direction = port.FlowDirection or "NOTDEFINED"
|
||||||
current_direction = port.FlowDirection or "NOTDEFINED"
|
return f"Current flow direction: {current_direction}. Click to cycle: SOURCE → SINK → SOURCEANDSINK → NOTDEFINED"
|
||||||
return f"Current flow direction: {current_direction}. Click to cycle: SOURCE → SINK → SOURCEANDSINK → NOTDEFINED"
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return "Cycle through flow directions: SOURCE → SINK → SOURCEANDSINK → NOTDEFINED → SOURCE..."
|
return "Cycle through flow directions: SOURCE → SINK → SOURCEANDSINK → NOTDEFINED → SOURCE..."
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
@@ -456,7 +451,7 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
"SOURCE": "SINK",
|
"SOURCE": "SINK",
|
||||||
"SINK": "SOURCEANDSINK",
|
"SINK": "SOURCEANDSINK",
|
||||||
"SOURCEANDSINK": "NOTDEFINED",
|
"SOURCEANDSINK": "NOTDEFINED",
|
||||||
"NOTDEFINED": "SOURCE"
|
"NOTDEFINED": "SOURCE",
|
||||||
}
|
}
|
||||||
next_direction = flow_cycle_map.get(current_direction, "SOURCE")
|
next_direction = flow_cycle_map.get(current_direction, "SOURCE")
|
||||||
|
|
||||||
@@ -468,10 +463,12 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
"SOURCE": "SINK",
|
"SOURCE": "SINK",
|
||||||
"SINK": "SOURCE",
|
"SINK": "SOURCE",
|
||||||
"SOURCEANDSINK": "SOURCEANDSINK",
|
"SOURCEANDSINK": "SOURCEANDSINK",
|
||||||
"NOTDEFINED": "NOTDEFINED"
|
"NOTDEFINED": "NOTDEFINED",
|
||||||
}
|
}
|
||||||
connected_direction = connected_direction_map.get(next_direction, "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
|
PortData.is_loaded = False
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import bonsai.bim.handler
|
import bonsai.bim.handler
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
import bonsai.core.system as core
|
|
||||||
from bonsai.bim.module.system.data import SystemData
|
from bonsai.bim.module.system.data import SystemData
|
||||||
import bonsai.bim.module.system.decorator as decorator
|
import bonsai.bim.module.system.decorator as decorator
|
||||||
from bonsai.bim.prop import StrProperty, Attribute
|
from bonsai.bim.prop import StrProperty, Attribute
|
||||||
@@ -93,7 +92,9 @@ def toggle_decorations(self: "BIMSystemProperties", context: bpy.types.Context)
|
|||||||
decorator.SystemDecorator.uninstall()
|
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 = []
|
items = []
|
||||||
active_object_ports = set(tool.System.get_ports(tool.Ifc.get_entity(context.active_object)))
|
active_object_ports = set(tool.System.get_ports(tool.Ifc.get_entity(context.active_object)))
|
||||||
|
|
||||||
|
|||||||
@@ -162,10 +162,8 @@ class BIM_PT_ports(Panel):
|
|||||||
if total_ports == 0:
|
if total_ports == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
props = tool.System.get_system_props()
|
|
||||||
|
|
||||||
row = self.layout.row(align=True)
|
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)
|
row = self.layout.row(align=True)
|
||||||
cols = [row.column(align=True) for i in range(9)]
|
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 = cols[1].operator("bim.cycle_flow_direction", text="", icon=flow_direction_icon, emboss=True)
|
||||||
op.port_id = port_data["id"]
|
op.port_id = port_data["id"]
|
||||||
else:
|
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.relating_port_id = port_data["id"]
|
||||||
op = cols[1].operator("bim.cycle_flow_direction", text="", icon=flow_direction_icon, emboss=True)
|
op = cols[1].operator("bim.cycle_flow_direction", text="", icon=flow_direction_icon, emboss=True)
|
||||||
op.port_id = port_data["id"]
|
op.port_id = port_data["id"]
|
||||||
|
|
||||||
# Port information
|
|
||||||
if port_data["port_obj_name"]:
|
if port_data["port_obj_name"]:
|
||||||
cols[2].operator("bim.select_entity", text="", icon="RESTRICT_SELECT_OFF").ifc_id = port_data["id"]
|
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"])
|
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)
|
connected_port_obj = tool.Ifc.get_object(connected_port)
|
||||||
if connected_port_obj:
|
if connected_port_obj:
|
||||||
connected_port_flow_dir = FLOW_DIRECTION_TO_ICON[connected_port.FlowDirection or "NOTDEFINED"]
|
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()
|
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)
|
cols[6].label(text=connected_port_obj.name)
|
||||||
else:
|
else:
|
||||||
blank4 = cols[4].column(align=True)
|
blank4 = cols[4].column(align=True)
|
||||||
@@ -265,26 +266,20 @@ class BIM_PT_port(Panel):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
self.props = tool.System.get_system_props()
|
|
||||||
|
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
row = layout.row(align=True)
|
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:
|
if not PortData.is_loaded:
|
||||||
PortData.load()
|
PortData.load()
|
||||||
|
|
||||||
if not PortData.data["is_port"]:
|
if not PortData.data["is_port"]:
|
||||||
return
|
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)
|
element = tool.Ifc.get_entity(context.active_object)
|
||||||
props = tool.System.get_system_props()
|
|
||||||
|
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
cols = [row.column(align=True) for i in range(9)]
|
cols = [row.column(align=True) for i in range(9)]
|
||||||
|
|||||||
@@ -132,7 +132,12 @@ def remove_port(ifc: type[tool.Ifc], system: type[tool.System], port: ifcopenshe
|
|||||||
ifc.run("root.remove_product", product=port)
|
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)
|
ifc.run("system.connect_port", port1=port1, port2=port2, direction=direction)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ class System(bonsai.core.tool.System):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_empty_at_cursor_with_element_orientation(cls, element: ifcopenshell.entity_instance) -> bpy.types.Object:
|
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)
|
element_obj = tool.Ifc.get_object(element)
|
||||||
obj = bpy.data.objects.new("Port", None)
|
obj = bpy.data.objects.new("Port", None)
|
||||||
obj.matrix_world = element_obj.matrix_world
|
obj.matrix_world = element_obj.matrix_world
|
||||||
|
|||||||
@@ -490,8 +490,7 @@ class Usecase:
|
|||||||
attribute_class = None
|
attribute_class = None
|
||||||
if "." in attribute:
|
if "." in attribute:
|
||||||
attribute, attribute_class = attribute.split(".")
|
attribute, attribute_class = attribute.split(".")
|
||||||
inverse_values = getattr(element, attribute, [])
|
for inverse in getattr(element, attribute, []):
|
||||||
for inverse in inverse_values:
|
|
||||||
if attribute_class and inverse.is_a(attribute_class):
|
if attribute_class and inverse.is_a(attribute_class):
|
||||||
self.add_inverse_element(inverse)
|
self.add_inverse_element(inverse)
|
||||||
elif not attribute_class:
|
elif not attribute_class:
|
||||||
|
|||||||
Reference in New Issue
Block a user