mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 13:46:54 +00:00
Now horizontal alignments are created in IFC local coords, remove redundant PI calculation code
This commit is contained in:
@@ -997,7 +997,7 @@ class SAIKEI_OT_recalculate_pis(Operator):
|
|||||||
return {"CANCELLED"}
|
return {"CANCELLED"}
|
||||||
|
|
||||||
# Collect updated PI data
|
# Collect updated PI data
|
||||||
hpoints = [(float(pi.e), float(pi.n)) for pi in props.pis]
|
hpoints = [[float(o) for o in tool.Georeference.enh2xyz((float(pi.e), float(pi.n), 0.), to_blender=False)[:2]] for pi in props.pis]
|
||||||
radii = [pi.radius for pi in props.pis[1:-1]]
|
radii = [pi.radius for pi in props.pis[1:-1]]
|
||||||
|
|
||||||
# Remove Blender visualization for segments (not the whole hierarchy)
|
# Remove Blender visualization for segments (not the whole hierarchy)
|
||||||
@@ -1142,68 +1142,38 @@ class SAIKEI_OT_create_alignment_by_pi(Operator):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
ifc = tool.Ifc.get()
|
|
||||||
props = context.scene.SaikeiAlignmentProperties
|
props = context.scene.SaikeiAlignmentProperties
|
||||||
|
if not props.active_alignment_id:
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
# Collect PI data
|
hpoints = [[float(o) for o in tool.Georeference.enh2xyz((float(pi.e), float(pi.n), 0.), to_blender=False)[:2]] for pi in props.pis]
|
||||||
hpoints = [(float(pi.e), float(pi.n)) for pi in props.pis]
|
|
||||||
radii = [pi.radius for pi in props.pis[1:-1]]
|
radii = [pi.radius for pi in props.pis[1:-1]]
|
||||||
|
|
||||||
# Check if there's an active alignment we should add to instead of creating new
|
existing_alignment = get_alignment_by_id(tool.Ifc.get(), props.active_alignment_id)
|
||||||
if props.active_alignment_id != 0:
|
h_layout = ifcopenshell.api.alignment.get_horizontal_layout(existing_alignment)
|
||||||
existing_alignment = get_alignment_by_id(ifc, props.active_alignment_id)
|
if h_layout:
|
||||||
if existing_alignment:
|
# Check if horizontal layout is empty (only has zero-length terminal or no segments)
|
||||||
h_layout = ifcopenshell.api.alignment.get_horizontal_layout(existing_alignment)
|
segments = ifcopenshell.api.alignment.get_layout_segments(h_layout)
|
||||||
if h_layout:
|
has_real_segments = bool([s for s in segments if not tool.Alignment.is_zero_length_segment(seg)])
|
||||||
# Check if horizontal layout is empty (only has zero-length terminal or no segments)
|
|
||||||
segments = ifcopenshell.api.alignment.get_layout_segments(h_layout)
|
|
||||||
has_real_segments = False
|
|
||||||
for seg in segments:
|
|
||||||
if hasattr(seg, "DesignParameters") and seg.DesignParameters:
|
|
||||||
if seg.DesignParameters.SegmentLength > 0.0001:
|
|
||||||
has_real_segments = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if not has_real_segments:
|
if not has_real_segments:
|
||||||
# Use existing alignment - add segments to it
|
# Use existing alignment - add segments to it
|
||||||
# Use safe wrapper to validate layout has parent alignment
|
# Use safe wrapper to validate layout has parent alignment
|
||||||
tool.Alignment.safe_layout_horizontal_by_pi_method(ifc, h_layout, hpoints, radii)
|
tool.Alignment.safe_layout_horizontal_by_pi_method(tool.Ifc.get(), h_layout, hpoints, radii)
|
||||||
|
|
||||||
# Create/update Blender objects for the segments
|
# Create/update Blender objects for the segments
|
||||||
alignment_obj = tool.Ifc.get_object(existing_alignment)
|
alignment_obj = tool.Ifc.get_object(existing_alignment)
|
||||||
h_layout_obj = tool.Ifc.get_object(h_layout)
|
h_layout_obj = tool.Ifc.get_object(h_layout)
|
||||||
|
|
||||||
if not h_layout_obj and alignment_obj:
|
if not h_layout_obj and alignment_obj:
|
||||||
h_layout_obj = tool.Alignment.create_object_for_layout(h_layout, alignment_obj)
|
h_layout_obj = tool.Alignment.create_object_for_layout(h_layout, alignment_obj)
|
||||||
|
|
||||||
if h_layout_obj:
|
if h_layout_obj:
|
||||||
tool.Alignment.create_objects_for_layout_segments(h_layout, h_layout_obj)
|
tool.Alignment.create_objects_for_layout_segments(h_layout, h_layout_obj)
|
||||||
|
|
||||||
self.report(
|
self.report(
|
||||||
{"INFO"}, f"Added {len(hpoints)} PIs to existing alignment '{existing_alignment.Name}'"
|
{"INFO"}, f"Added {len(hpoints)} PIs to existing alignment '{existing_alignment.Name}'"
|
||||||
)
|
)
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
# No suitable existing alignment - create a new one
|
|
||||||
# Use safe wrapper to validate/cleanup before creating
|
|
||||||
alignment = tool.Alignment.safe_create_alignment_by_pi_method(
|
|
||||||
ifc,
|
|
||||||
name=props.new_alignment_name,
|
|
||||||
hpoints=hpoints,
|
|
||||||
radii=radii,
|
|
||||||
start_station=props.start_station,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create full Blender hierarchy (alignment + layouts + segments)
|
|
||||||
obj = tool.Alignment.create_hierarchy_for_alignment(alignment)
|
|
||||||
|
|
||||||
props.active_alignment_name = props.new_alignment_name
|
|
||||||
props.active_alignment_id = alignment.id()
|
|
||||||
|
|
||||||
if obj:
|
|
||||||
self.report({"INFO"}, f"Created new alignment '{props.new_alignment_name}' with {len(hpoints)} PIs")
|
|
||||||
else:
|
|
||||||
self.report({"WARNING"}, f"Created IFC alignment but could not create Blender object")
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user