This commit is contained in:
Richard Brice
2026-02-24 08:58:00 -08:00
parent 9041857277
commit 5066fc5a29
6 changed files with 15 additions and 14 deletions
@@ -152,10 +152,7 @@ def _add_segment_to_curve(file: ifcopenshell.file, segment: entity_instance, cur
axis_geom_subcontext = ifcopenshell.api.alignment.get_axis_subcontext(file) axis_geom_subcontext = ifcopenshell.api.alignment.get_axis_subcontext(file)
axis_representation = file.createIfcShapeRepresentation( axis_representation = file.createIfcShapeRepresentation(
ContextOfItems=axis_geom_subcontext, ContextOfItems=axis_geom_subcontext, RepresentationIdentifier="Axis", RepresentationType="Segment", Items=items
RepresentationIdentifier="Axis",
RepresentationType="Segment",
Items = items
) )
product = file.createIfcProductDefinitionShape(Representations=(axis_representation,)) product = file.createIfcProductDefinitionShape(Representations=(axis_representation,))
@@ -36,7 +36,7 @@ def _create_offset_curve_representation(
expected_type = "IfcAlignment" expected_type = "IfcAlignment"
if not alignment.is_a(expected_type): if not alignment.is_a(expected_type):
raise TypeError(f"Expected {expected_type} but got {alignment.is_a()}") raise TypeError(f"Expected {expected_type} but got {alignment.is_a()}")
expected_type = "IfcPointByDistanceExpression" expected_type = "IfcPointByDistanceExpression"
for offset in offsets: for offset in offsets:
if not offset.is_a(expected_type): if not offset.is_a(expected_type):
@@ -71,9 +71,7 @@ def clear_layout_segments(file: ifcopenshell.file, layout: entity_instance) -> N
""" """
expected_types = ["IfcAlignmentHorizontal", "IfcAlignmentVertical", "IfcAlignmentCant"] expected_types = ["IfcAlignmentHorizontal", "IfcAlignmentVertical", "IfcAlignmentCant"]
if layout.is_a() not in expected_types: if layout.is_a() not in expected_types:
raise TypeError( raise TypeError(f"Expected entity type to be one of {expected_types}, instead received {layout.is_a()}")
f"Expected entity type to be one of {expected_types}, instead received {layout.is_a()}"
)
# Get the geometric curve for this layout # Get the geometric curve for this layout
curve = ifcopenshell.api.alignment.get_layout_curve(layout) curve = ifcopenshell.api.alignment.get_layout_curve(layout)
@@ -32,7 +32,7 @@ def get_alignment_layout(segment: entity_instance) -> entity_instance:
) )
layout = None layout = None
layouts=["IfcAlignmentHorizontal","IfcAlignmentVertical","IfcAlignmentCant"] layouts = ["IfcAlignmentHorizontal", "IfcAlignmentVertical", "IfcAlignmentCant"]
for nest in segment.Nests: for nest in segment.Nests:
if nest.RelatingObject.is_a() in layouts: if nest.RelatingObject.is_a() in layouts:
layout = nest.RelatingObject layout = nest.RelatingObject
@@ -63,15 +63,21 @@ def evaluate_segment(segment: entity_instance, dist_along: float) -> np.ndarray:
# Validate dist_along is within segment bounds # Validate dist_along is within segment bounds
# SegmentLength can be negative (indicates curve direction), so we need to handle both cases # SegmentLength can be negative (indicates curve direction), so we need to handle both cases
seg_len = segment.SegmentLength.wrappedValue if hasattr(segment.SegmentLength, 'wrappedValue') else segment.SegmentLength seg_len = (
segment.SegmentLength.wrappedValue if hasattr(segment.SegmentLength, "wrappedValue") else segment.SegmentLength
)
if seg_len >= 0: if seg_len >= 0:
# Positive length: valid range is 0 to seg_len # Positive length: valid range is 0 to seg_len
if dist_along < 0 or dist_along > seg_len: if dist_along < 0 or dist_along > seg_len:
raise ValueError(f"Provided value {dist_along=} is beyond the end of the segment ({segment.SegmentLength}).") raise ValueError(
f"Provided value {dist_along=} is beyond the end of the segment ({segment.SegmentLength})."
)
else: else:
# Negative length: valid range is seg_len to 0 # Negative length: valid range is seg_len to 0
if dist_along > 0 or dist_along < seg_len: if dist_along > 0 or dist_along < seg_len:
raise ValueError(f"Provided value {dist_along=} is beyond the end of the segment ({segment.SegmentLength}).") raise ValueError(
f"Provided value {dist_along=} is beyond the end of the segment ({segment.SegmentLength})."
)
s = ifcopenshell.geom.settings() s = ifcopenshell.geom.settings()
function_item = ifcopenshell_wrapper.map_shape(s, segment.wrapped_data) function_item = ifcopenshell_wrapper.map_shape(s, segment.wrapped_data)
@@ -36,7 +36,7 @@ def test_get_alignment_layout():
parent=geometric_representation_context, parent=geometric_representation_context,
) )
alignment = ifcopenshell.api.alignment.create(file,"Test",include_vertical=True,include_cant=True) alignment = ifcopenshell.api.alignment.create(file, "Test", include_vertical=True, include_cant=True)
horiz = ifcopenshell.api.alignment.get_horizontal_layout(alignment) horiz = ifcopenshell.api.alignment.get_horizontal_layout(alignment)
vert = ifcopenshell.api.alignment.get_vertical_layout(alignment) vert = ifcopenshell.api.alignment.get_vertical_layout(alignment)
cant = ifcopenshell.api.alignment.get_cant_layout(alignment) cant = ifcopenshell.api.alignment.get_cant_layout(alignment)
@@ -46,4 +46,4 @@ def test_get_alignment_layout():
assert cant == ifcopenshell.api.alignment.get_alignment_layout(cant.IsNestedBy[0].RelatedObjects[0]) assert cant == ifcopenshell.api.alignment.get_alignment_layout(cant.IsNestedBy[0].RelatedObjects[0])
test_get_alignment_layout() test_get_alignment_layout()