fix: Correct vertical/cant segment handling in alignment API

Two bugs prevented IfcAlignmentVertical segments from being added when
a geometric representation exists.

Bug 1 — _add_segment_to_curve.py:
Removed an unconditional `if not curve.is_a("IfcCompositeCurve")` guard
that was left over from when the function only supported horizontal
segments. The preceding if/elif/elif chain already validates the correct
curve type for each segment type; the redundant check always raised
TypeError for vertical (IfcGradientCurve) and cant
(IfcSegmentedReferenceCurve) segments.

Bug 2 — add_zero_length_segment.py:
Added a None guard before the recursive `add_zero_length_segment(file,
layout.BaseCurve)` call for IfcGradientCurve. When an IfcGradientCurve
is created without a BaseCurve (e.g. before a horizontal representation
exists), the recursive call previously crashed with AttributeError.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
DesertSpringsCivil
2026-03-12 16:56:33 -06:00
parent e09ce1bcd8
commit d2ee4f2f97
2 changed files with 2 additions and 5 deletions
@@ -128,10 +128,6 @@ def _add_segment_to_curve(file: ifcopenshell.file, segment: entity_instance, cur
elif segment.DesignParameters.is_a("IfcAlignmentCantSegment") and not curve.is_a("IfcSegmentedReferenceCurve"):
raise TypeError(f"Expected to see IfcSegmentedReferenceCurve, instead received '{curve.is_a()}'.")
expected_type = "IfcCompositeCurve"
if not curve.is_a(expected_type):
raise TypeError(f"Expected to see {expected_type}, instead received {curve.is_a()}.")
# map the IfcAlignmentSegment to an IfcCurveSegment (or two in the case of helmert curves)
if segment.DesignParameters.is_a("IfcAlignmentHorizontalSegment"):
mapped_segments = _map_alignment_horizontal_segment(file, segment)
@@ -123,7 +123,8 @@ def add_zero_length_segment(file: ifcopenshell.file, layout: entity_instance, in
if layout.is_a("IfcSegmentedReferenceCurve"):
ifcopenshell.api.alignment.add_zero_length_segment(file, layout.BaseCurve)
elif layout.is_a("IfcGradientCurve"):
ifcopenshell.api.alignment.add_zero_length_segment(file, layout.BaseCurve)
if layout.BaseCurve is not None:
ifcopenshell.api.alignment.add_zero_length_segment(file, layout.BaseCurve)
else:
zero_length_curve_segment = None