Skip to content

Commit 3ef7f1c

Browse files
committed
Alignment API updates to support new patch recipes
1 parent 3e0ef46 commit 3ef7f1c

19 files changed

Lines changed: 481 additions & 160 deletions

src/ifcopenshell-python/ifcopenshell/api/alignment/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@
4949

5050
from .add_stationing_referent import add_stationing_referent
5151
from .add_vertical_layout import add_vertical_layout
52+
from .add_zero_length_segment import add_zero_length_segment
5253
from .create_layout_segment import create_layout_segment
5354
from .create import create
5455
from .create_as_offset_curve import create_as_offset_curve
5556
from .create_as_polyline import create_as_polyline
5657
from .create_by_pi_method import create_by_pi_method
5758
from .create_from_csv import create_from_csv
5859
from .create_segment_representations import create_segment_representations
60+
from .create_representation import create_representation
5961
from .distance_along_from_station import distance_along_from_station
6062
from .get_alignment import get_alignment
6163
from .get_alignment_station import get_alignment_station
@@ -69,25 +71,29 @@
6971
from .get_child_alignments import get_child_alignments
7072
from .get_curve import get_curve
7173
from .get_layout_curve import get_layout_curve
74+
from .get_mapped_segments import get_mapped_segments
7275
from .get_parent_alignment import get_parent_alignment
7376
from .has_zero_length_segment import has_zero_length_segment
7477
from .layout_horizontal_alignment_by_pi_method import layout_horizontal_alignment_by_pi_method
7578
from .layout_vertical_alignment_by_pi_method import layout_vertical_alignment_by_pi_method
7679
from .name_segments import name_segments
80+
from .update_fallback_position import update_fallback_position
7781
from .util import *
7882

7983
from ._get_segment_start_point_label import register_referent_name_callback
8084

8185
__all__ = [
8286
"add_stationing_referent",
8387
"add_vertical_layout",
88+
"add_zero_length_segment",
8489
"create_layout_segment",
8590
"create",
8691
"create_as_offset_curve",
8792
"create_as_polyline",
8893
"create_by_pi_method",
8994
"create_from_csv",
9095
"create_segment_representations",
96+
"create_representation",
9197
"distance_along_from_station",
9298
"get_alignment",
9399
"get_alignment_station",
@@ -105,6 +111,7 @@
105111
"has_zero_length_segment",
106112
"layout_horizontal_alignment_by_pi_method",
107113
"layout_vertical_alignment_by_pi_method",
114+
"update_fallback_position",
108115
"name_segments",
109116
"register_referent_name_callback",
110117
]

src/ifcopenshell-python/ifcopenshell/api/alignment/_add_segment_to_layout.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import ifcopenshell.api.alignment
2121
import ifcopenshell.api.nest
2222
import ifcopenshell.geom
23-
import ifcopenshell.util.stationing
23+
import ifcopenshell.util.alignment
2424
import ifcopenshell.util.unit
2525
from ifcopenshell import ifcopenshell_wrapper
2626
import numpy as np
@@ -29,7 +29,6 @@
2929
from collections.abc import Sequence
3030

3131
from ifcopenshell.api.alignment._add_segment_to_curve import _add_segment_to_curve
32-
from ifcopenshell.api.alignment._get_mapped_segments import _get_mapped_segments
3332
from ifcopenshell.api.alignment._get_segment_start_point_label import _get_segment_start_point_label
3433

3534

@@ -98,7 +97,7 @@ def _add_segment_to_layout(file: ifcopenshell.file, layout: entity_instance, seg
9897
"IfcAlignmentVerticalSegment"
9998
) or zero_length_segment.DesignParameters.is_a("IfcAlignmentCantSegment"):
10099
# get the geometric representation for the new segment
101-
mapped_segments = _get_mapped_segments(file, segment)
100+
mapped_segments = ifcopenshell.api.alignment.get_mapped_segments(segment)
102101
mapped_segment = mapped_segments[0] if mapped_segments[1] == None else mapped_segments[1]
103102

104103
# compute the end point matrix
@@ -137,7 +136,7 @@ def _add_segment_to_layout(file: ifcopenshell.file, layout: entity_instance, seg
137136
zero_length_segment.DesignParameters.StartDistAlong = start_dist_along
138137

139138
end_referent = zero_length_segment.IsNestedBy[0].RelatedObjects[0]
140-
end_referent.Name = f"{_get_segment_start_point_label(zero_length_segment,None)} ({ifcopenshell.util.stationing.station_as_string(file,start_station+start_dist_along)})"
139+
end_referent.Name = f"{_get_segment_start_point_label(zero_length_segment,None)} ({ifcopenshell.util.alignment.station_as_string(file,start_station+start_dist_along)})"
141140

142141
# update the referent's geometric representation's location
143142
end_referent.ObjectPlacement.RelativePlacement.Location.DistanceAlong.wrappedValue = start_dist_along
@@ -169,7 +168,7 @@ def _add_segment_to_layout(file: ifcopenshell.file, layout: entity_instance, seg
169168
# get the previous segment. Working from the end of the basis curve, -1 is zero length segment
170169
# -2 is the newly added segment, so -3 is the segment occuring just before the newly added segment
171170
prev_segment = layout.IsNestedBy[0].RelatedObjects[-3] if 2 < len(layout.IsNestedBy[0].RelatedObjects) else None
172-
name = f"{_get_segment_start_point_label(prev_segment,segment)} ({ifcopenshell.util.stationing.station_as_string(file,station)})"
171+
name = f"{_get_segment_start_point_label(prev_segment,segment)} ({ifcopenshell.util.alignment.station_as_string(file,station)})"
173172
referent = ifcopenshell.api.alignment.add_stationing_referent(
174173
file, segment, distance_along=dist_along, station=station, name=name
175174
)

src/ifcopenshell-python/ifcopenshell/api/alignment/_add_zero_length_segment.py

Lines changed: 13 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -18,128 +18,37 @@
1818

1919
import ifcopenshell
2020
import ifcopenshell.api.alignment
21-
import ifcopenshell.api.nest
22-
import ifcopenshell.util.stationing
2321
from ifcopenshell import entity_instance
2422

2523
from ifcopenshell.api.alignment._get_segment_start_point_label import _get_segment_start_point_label
2624

27-
2825
def _add_zero_length_segment(file: ifcopenshell.file, layout: entity_instance) -> None:
2926
"""
3027
Adds a zero length segment to the end of a layout. Also adds a zero length segment to the end of the corresponding geometric curve.
3128
32-
If the layout already has a zero length segment, nothing is changed
29+
This function depends on the assumptions made in ifcopenshell.api.alignment.create and is called by that function.
30+
This is not a general purpose function.
3331
3432
:param layout: An IfcAlignmentHorizontal, IfcAlignmentVertical, or IfcAlignmentCant
3533
:return: None
3634
"""
35+
3736
expected_types = ["IfcAlignmentHorizontal", "IfcAlignmentVertical", "IfcAlignmentCant"]
3837
if not layout.is_a() in expected_types:
3938
raise TypeError(
4039
f"Expected layout type to be one of {[_ for _ in expected_types]}, instead received {layout.is_a()}"
4140
)
42-
43-
if ifcopenshell.api.alignment.has_zero_length_segment(layout):
44-
return
45-
46-
segment = None
47-
if layout.is_a("IfcAlignmentHorizontal"):
48-
design_parameters = file.createIfcAlignmentHorizontalSegment(
49-
StartPoint=file.createIfcCartesianPoint(
50-
(0.0, 0.0)
51-
), # this is a little problematic. need to know the end point and tangent
52-
StartDirection=0.0, # of the previous segment, which requires geometry mapping
53-
StartRadiusOfCurvature=0.0,
54-
EndRadiusOfCurvature=0.0,
55-
SegmentLength=0.0,
56-
PredefinedType="LINE",
57-
)
58-
segment = file.createIfcAlignmentSegment(GlobalId=ifcopenshell.guid.new(), DesignParameters=design_parameters)
59-
elif layout.is_a("IfcAlignmentVertical"):
60-
last_segment_dist_along = 0.0
61-
last_segment_end_gradient = 0.0
62-
for rel in layout.IsNestedBy:
63-
if 0 < len(rel.RelatedObjects):
64-
last_segment = rel.RelatedObjects[1]
65-
last_segment_dist_along = (
66-
last_segment.DesignParameters.StartDistAlong + last_segment.DesignParameters.HorizontalLength
67-
)
68-
last_segment_end_gradient = last_segment.DesignParameters.EndGradient
69-
70-
design_parameters = file.createIfcAlignmentVerticalSegment(
71-
StartDistAlong=last_segment_dist_along,
72-
HorizontalLength=0.0,
73-
StartHeight=0.0,
74-
StartGradient=last_segment_end_gradient,
75-
EndGradient=last_segment_end_gradient,
76-
PredefinedType="CONSTANTGRADIENT",
77-
)
78-
segment = file.createIfcAlignmentSegment(GlobalId=ifcopenshell.guid.new(), DesignParameters=design_parameters)
79-
elif layout.is_a("IfcAlignmentCant"):
80-
last_segment_dist_along = 0.0
81-
last_segment_cant_left = 0.0
82-
last_segment_cant_right = 0.0
83-
for rel in layout.IsNestedBy:
84-
if 0 < len(rel.RelatedObjects):
85-
last_segment = rel.RelatedObjects[1]
86-
last_segment_dist_along = (
87-
last_segment.DesignParameters.StartDistAlong + last_segment.DesignParameters.HorizontalLength
88-
)
89-
last_segment_cant_left = (
90-
last_segment.DesignParameters.EndCantLeft
91-
if last_segment.DesignParameters.EndCantLeft != None
92-
else last_segment.DesignParameters.StartCantLeft
93-
)
94-
last_segment_cant_right = (
95-
last_segment.DesignParameters.EndCantRight
96-
if last_segment.DesignParameters.EndCantRight != None
97-
else last_segment.DesignParameters.StartCantRight
98-
)
99-
100-
design_parameters = file.createIfcAlignmentCantSegment(
101-
StartDistAlong=last_segment_dist_along,
102-
HorizontalLength=0.0,
103-
StartCantLeft=last_segment_cant_left,
104-
StartCantRight=last_segment_cant_right,
105-
PredefinedType="CONSTANTCANT",
106-
)
107-
segment = file.createIfcAlignmentSegment(GlobalId=ifcopenshell.guid.new(), DesignParameters=design_parameters)
108-
109-
ifcopenshell.api.nest.assign_object(file, related_objects=[segment], relating_object=layout)
41+
42+
if (not ifcopenshell.api.alignment.add_zero_length_segment(file,layout,include_referent=False)):
43+
return # zero length segment not added, probably because it already exists
11044

11145
curve = ifcopenshell.api.alignment.get_layout_curve(layout)
11246

113-
has_zero_length_segment = False
114-
if curve.Segments != None and 0 < len(curve.Segments):
115-
last_segment = curve.Segments[-1]
116-
has_zero_length_segment = (
117-
True
118-
if last_segment.Transition == "DISCONTINUOUS" and last_segment.SegmentLength.wrappedValue == 0.0
119-
else False
120-
)
121-
122-
if not has_zero_length_segment:
123-
parent_curve = file.createIfcLine(
124-
Pnt=file.createIfcCartesianPoint(Coordinates=((0.0, 0.0))),
125-
Dir=file.createIfcVector(
126-
Orientation=file.createIfcDirection(DirectionRatios=((1.0, 0.0))),
127-
Magnitude=1.0,
128-
),
129-
)
130-
curve_segment = file.createIfcCurveSegment(
131-
Transition="DISCONTINUOUS",
132-
Placement=file.createIfcAxis2Placement2D(
133-
Location=file.createIfcCartesianPoint((0.0, 0.0)),
134-
RefDirection=file.createIfcDirection((1.0, 0.0)),
135-
),
136-
SegmentStart=file.createIfcLengthMeasure(0.0),
137-
SegmentLength=file.createIfcLengthMeasure(0.0),
138-
ParentCurve=parent_curve,
139-
)
140-
curve.Segments = [
141-
curve_segment,
142-
]
47+
if curve:
48+
ifcopenshell.api.alignment.add_zero_length_segment(file,curve)
14349

144-
name = f"{_get_segment_start_point_label(segment,None)} {ifcopenshell.util.stationing.station_as_string(file,0.0)}"
145-
ifcopenshell.api.alignment.add_stationing_referent(file, segment, 0.0, 0.0, name=name)
50+
segment = layout.IsNestedBy[0].RelatedObjects[-1]
51+
alignment = ifcopenshell.api.alignment.get_alignment(layout)
52+
station = ifcopenshell.api.alignment.get_alignment_station(file,alignment)
53+
name = f"{_get_segment_start_point_label(segment,None)} {ifcopenshell.util.alignment.station_as_string(file,station)}"
54+
ifcopenshell.api.alignment.add_stationing_referent(file, segment, 0.0, station, name=name)

0 commit comments

Comments
 (0)