mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 22:50:21 +00:00
bim.draw_system_arrows updated for ifc4
This commit is contained in:
@@ -205,46 +205,50 @@ class DrawSystemArrows(bpy.types.Operator, Operator):
|
|||||||
return context.selected_objects and tool.Ifc.get()
|
return context.selected_objects and tool.Ifc.get()
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
sinks = []
|
||||||
curve = bpy.data.objects.new("System Arrows", bpy.data.curves.new("System Arrows", "CURVE"))
|
sources = []
|
||||||
curve.data.dimensions = "3D"
|
|
||||||
context.scene.collection.objects.link(curve)
|
|
||||||
for obj in bpy.context.selected_objects:
|
for obj in bpy.context.selected_objects:
|
||||||
if not obj.BIMObjectProperties.ifc_definition_id:
|
if not obj.BIMObjectProperties.ifc_definition_id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
sources = []
|
sources_current = []
|
||||||
sinks = []
|
sinks_current = []
|
||||||
for rel in getattr(element, "HasPorts", []) or []:
|
|
||||||
if rel.RelatingPort.FlowDirection == "SOURCE":
|
for port in tool.System.get_ports(element):
|
||||||
sources.append(
|
local_placement = ifcopenshell.util.placement.get_local_placement(port.ObjectPlacement)
|
||||||
self.get_absolute_matrix(
|
m = self.get_absolute_matrix(local_placement)
|
||||||
ifcopenshell.util.placement.get_local_placement(rel.RelatingPort.ObjectPlacement)
|
if port.FlowDirection == "SOURCE":
|
||||||
)
|
sources_current.append(m)
|
||||||
)
|
elif port.FlowDirection == "SINK":
|
||||||
elif rel.RelatingPort.FlowDirection == "SINK":
|
sinks_current.append(m)
|
||||||
sinks.append(
|
|
||||||
self.get_absolute_matrix(
|
|
||||||
ifcopenshell.util.placement.get_local_placement(rel.RelatingPort.ObjectPlacement)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
sources.append(
|
sources_current.append(m)
|
||||||
self.get_absolute_matrix(
|
sinks_current.append(m)
|
||||||
ifcopenshell.util.placement.get_local_placement(rel.RelatingPort.ObjectPlacement)
|
|
||||||
)
|
if sinks_current or sources_current:
|
||||||
)
|
sinks.append(sinks_current)
|
||||||
sinks.append(
|
sources.append(sources_current)
|
||||||
self.get_absolute_matrix(
|
|
||||||
ifcopenshell.util.placement.get_local_placement(rel.RelatingPort.ObjectPlacement)
|
if not sinks:
|
||||||
)
|
self.report({"INFO"}, "No sinks/sources found for selected objects.")
|
||||||
)
|
return {"FINISHED"}
|
||||||
for sink in sinks:
|
|
||||||
for source in sources:
|
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
||||||
|
curve = bpy.data.objects.new("System Arrows", bpy.data.curves.new("System Arrows", "CURVE"))
|
||||||
|
curve.data.dimensions = "3D"
|
||||||
|
curve.show_in_front = True
|
||||||
|
context.scene.collection.objects.link(curve)
|
||||||
|
|
||||||
|
for i in range(len(sinks)):
|
||||||
|
for sink in sinks[i]:
|
||||||
|
for source in sources[i]:
|
||||||
polyline = curve.data.splines.new("POLY")
|
polyline = curve.data.splines.new("POLY")
|
||||||
polyline.points.add(1)
|
polyline.points.add(1)
|
||||||
polyline.points[0].co = (Matrix(sink).translation * unit_scale).to_4d()
|
polyline.points[0].co = (Matrix(sink).translation * unit_scale).to_4d()
|
||||||
polyline.points[1].co = (Matrix(source).translation * unit_scale).to_4d()
|
polyline.points[1].co = (Matrix(source).translation * unit_scale).to_4d()
|
||||||
|
tool.Blender.select_and_activate_single_object(context, curve)
|
||||||
|
|
||||||
def get_absolute_matrix(self, matrix):
|
def get_absolute_matrix(self, matrix):
|
||||||
props = bpy.context.scene.BIMGeoreferenceProperties
|
props = bpy.context.scene.BIMGeoreferenceProperties
|
||||||
|
|||||||
Reference in New Issue
Block a user