mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
Merge pull request #7611 from falken10vdl/connect-ports-for-cable-polyline-operator
connect the ports when creating several conected IfcFlowSegment with polyline
This commit is contained in:
@@ -1131,8 +1131,14 @@ class DrawPolylineProfile(bpy.types.Operator, PolylineOperator, tool.Ifc.Operato
|
|||||||
|
|
||||||
MEPGenerator().setup_ports(profile1["obj"])
|
MEPGenerator().setup_ports(profile1["obj"])
|
||||||
else:
|
else:
|
||||||
|
connect_IfcFlowSegments = tool.Ifc.get_entity(profiles[0]["obj"]).is_a("IfcFlowSegment")
|
||||||
for profile1, profile2 in zip(profiles[:-1], profiles[1:]):
|
for profile1, profile2 in zip(profiles[:-1], profiles[1:]):
|
||||||
DumbProfileJoiner().join_V(profile2["obj"], profile1["obj"])
|
DumbProfileJoiner().join_V(profile2["obj"], profile1["obj"])
|
||||||
|
if connect_IfcFlowSegments:
|
||||||
|
bpy.ops.bim.mep_connect_elements(
|
||||||
|
obj1_name=profile1["obj"].name,
|
||||||
|
obj2_name=profile2["obj"].name
|
||||||
|
)
|
||||||
|
|
||||||
def modal(self, context, event):
|
def modal(self, context, event):
|
||||||
return IfcStore.execute_ifc_operator(self, context, event, method="MODAL")
|
return IfcStore.execute_ifc_operator(self, context, event, method="MODAL")
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ classes = (
|
|||||||
operator.EditZone,
|
operator.EditZone,
|
||||||
operator.EnableEditingSystem,
|
operator.EnableEditingSystem,
|
||||||
operator.EnableEditingZone,
|
operator.EnableEditingZone,
|
||||||
|
operator.EstablishPathDirection,
|
||||||
operator.HidePorts,
|
operator.HidePorts,
|
||||||
operator.LoadSystems,
|
operator.LoadSystems,
|
||||||
operator.LoadZones,
|
operator.LoadZones,
|
||||||
|
|||||||
@@ -317,17 +317,19 @@ class MEPConnectElements(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_label = "Connect MEP Elements"
|
bl_label = "Connect MEP Elements"
|
||||||
bl_description = "Connects two selected elements by their closest located ports and adjusts them"
|
bl_description = "Connects two selected elements by their closest located ports and adjusts them"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
obj1_name: bpy.props.StringProperty(name="Object 1")
|
||||||
@classmethod
|
obj2_name: bpy.props.StringProperty(name="Object 2")
|
||||||
def poll(cls, context):
|
|
||||||
if not len(context.selected_objects) == 2:
|
|
||||||
cls.poll_message_set("Need to select 2 objects.")
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
obj1 = context.active_object
|
if self.obj1_name and self.obj2_name:
|
||||||
obj2 = next(o for o in context.selected_objects if o != obj1)
|
obj1 = bpy.data.objects.get(self.obj1_name)
|
||||||
|
obj2 = bpy.data.objects.get(self.obj2_name)
|
||||||
|
else:
|
||||||
|
if not context.selected_objects or len(context.selected_objects) != 2:
|
||||||
|
self.report({"ERROR"}, "Need to select 2 objects.")
|
||||||
|
return {"CANCELLED"}
|
||||||
|
obj1 = context.active_object
|
||||||
|
obj2 = next(o for o in context.selected_objects if o != obj1)
|
||||||
|
|
||||||
tool.Model.sync_object_ifc_position(obj1)
|
tool.Model.sync_object_ifc_position(obj1)
|
||||||
tool.Model.sync_object_ifc_position(obj2)
|
tool.Model.sync_object_ifc_position(obj2)
|
||||||
@@ -477,6 +479,56 @@ class CycleFlowDirection(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class EstablishPathDirection(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
|
bl_idname = "bim.establish_path_direction"
|
||||||
|
bl_label = "Establish Path Direction"
|
||||||
|
bl_description = "Propagates flow direction through connected flow segments with two ports"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
port_id: bpy.props.IntProperty()
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
connected_port = tool.Ifc.get().by_id(self.port_id)
|
||||||
|
|
||||||
|
|
||||||
|
if not connected_port or not connected_port.is_a("IfcDistributionPort"):
|
||||||
|
self.report({"ERROR"}, "Invalid port specified.")
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
direction_map = {
|
||||||
|
"SOURCE": "SINK",
|
||||||
|
"SINK": "SOURCE",
|
||||||
|
"SOURCEANDSINK": "SOURCEANDSINK",
|
||||||
|
"NOTDEFINED": "NOTDEFINED",
|
||||||
|
}
|
||||||
|
next_element = tool.System.get_port_relating_element(connected_port)
|
||||||
|
ports = tool.System.get_ports(next_element)
|
||||||
|
segments_processed = 0
|
||||||
|
while (len(ports) == 2):
|
||||||
|
if ports[0].id() == connected_port.id():
|
||||||
|
other_port = ports[1]
|
||||||
|
else:
|
||||||
|
other_port = ports[0]
|
||||||
|
|
||||||
|
new_direction = direction_map.get(connected_port.FlowDirection, "NOTDEFINED")
|
||||||
|
other_port.FlowDirection = new_direction
|
||||||
|
segments_processed += 1
|
||||||
|
|
||||||
|
connected_port = tool.System.get_connected_port(other_port)
|
||||||
|
if not connected_port:
|
||||||
|
break
|
||||||
|
connected_port.FlowDirection = direction_map.get(other_port.FlowDirection, "NOTDEFINED")
|
||||||
|
next_element = tool.System.get_port_relating_element(connected_port)
|
||||||
|
|
||||||
|
if not next_element.is_a("IfcFlowSegment"):
|
||||||
|
print(f"DEBUG: next_element is not IfcFlowSegment, stopping")
|
||||||
|
break
|
||||||
|
|
||||||
|
ports = tool.System.get_ports(next_element)
|
||||||
|
|
||||||
|
self.report({"INFO"}, f"Established path direction through {segments_processed} flow segment(s).")
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class LoadZones(bpy.types.Operator):
|
class LoadZones(bpy.types.Operator):
|
||||||
bl_idname = "bim.load_zones"
|
bl_idname = "bim.load_zones"
|
||||||
bl_label = "Load Zones"
|
bl_label = "Load Zones"
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ class BIM_PT_port(Panel):
|
|||||||
element = tool.Ifc.get_entity(context.active_object)
|
element = tool.Ifc.get_entity(context.active_object)
|
||||||
|
|
||||||
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(10)]
|
||||||
cols[3].scale_x = 1.0
|
cols[3].scale_x = 1.0
|
||||||
cols[6].scale_x = 1.0
|
cols[6].scale_x = 1.0
|
||||||
cols[8].scale_x = 1.33
|
cols[8].scale_x = 1.33
|
||||||
@@ -333,12 +333,14 @@ class BIM_PT_port(Panel):
|
|||||||
else:
|
else:
|
||||||
cols[7].label(text="", icon="BLANK1")
|
cols[7].label(text="", icon="BLANK1")
|
||||||
cols[8].label(text="")
|
cols[8].label(text="")
|
||||||
|
cols[9].operator("bim.establish_path_direction", text="", icon="CON_FOLLOWPATH").port_id = connected_port.id()
|
||||||
else:
|
else:
|
||||||
cols[4].label(text="", icon="BLANK1")
|
cols[4].label(text="", icon="BLANK1")
|
||||||
cols[5].label(text="", icon="BLANK1")
|
cols[5].label(text="", icon="BLANK1")
|
||||||
cols[6].label(text="Port is disconnected")
|
cols[6].label(text="Port is disconnected")
|
||||||
cols[7].label(text="", icon="BLANK1")
|
cols[7].label(text="", icon="BLANK1")
|
||||||
cols[8].label(text="")
|
cols[8].label(text="")
|
||||||
|
cols[9].label(text="", icon="BLANK1")
|
||||||
|
|
||||||
|
|
||||||
class BIM_PT_flow_controls(Panel):
|
class BIM_PT_flow_controls(Panel):
|
||||||
|
|||||||
Reference in New Issue
Block a user