mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
black .
This commit is contained in:
@@ -30,7 +30,7 @@ from ifcopenshell.api.alignment._map_alignment_horizontal_segment import _map_al
|
||||
from ifcopenshell.api.alignment._update_curve_segment_transition_code import _update_curve_segment_transition_code
|
||||
|
||||
|
||||
def add_zero_length_segment(file: ifcopenshell.file, layout: entity_instance, include_referent : bool = True) -> bool:
|
||||
def add_zero_length_segment(file: ifcopenshell.file, layout: entity_instance, include_referent: bool = True) -> bool:
|
||||
"""
|
||||
Adds a zero length segment to the end of a layout.
|
||||
|
||||
@@ -40,27 +40,33 @@ def add_zero_length_segment(file: ifcopenshell.file, layout: entity_instance, in
|
||||
:param include_referent: If True, an IfcReferent representing the ending point of the layout is included for IfcLinearElement layouts (i.e. business logic)
|
||||
:return: True if segment is added
|
||||
"""
|
||||
|
||||
|
||||
# These are valid curve types for alignment, but don't have the zero-length segment
|
||||
if layout.is_a("IfcOffsetCurveByDistances") or layout.is_a("IfcPolyline") or layout.is_a("IfcIndexedPolyCurve"):
|
||||
return
|
||||
|
||||
expected_types = ["IfcAlignmentHorizontal", "IfcAlignmentVertical", "IfcAlignmentCant","IfcCompositeCurve","IfcGradientCurve","IfcSegmentedReferenceCurve"]
|
||||
|
||||
expected_types = [
|
||||
"IfcAlignmentHorizontal",
|
||||
"IfcAlignmentVertical",
|
||||
"IfcAlignmentCant",
|
||||
"IfcCompositeCurve",
|
||||
"IfcGradientCurve",
|
||||
"IfcSegmentedReferenceCurve",
|
||||
]
|
||||
if not layout.is_a() in expected_types:
|
||||
raise TypeError(
|
||||
f"Expected layout type to be one of {[_ for _ in expected_types]}, instead received {layout.is_a()}"
|
||||
)
|
||||
|
||||
|
||||
if ifcopenshell.api.alignment.has_zero_length_segment(layout):
|
||||
return False
|
||||
|
||||
|
||||
if layout.is_a("IfcCompositeCurve") or layout.is_a("IfcGradientCurve") or layout.is_a("IfcSegmentedReferenceCurve"):
|
||||
x = 0.
|
||||
y = 0.
|
||||
dx = 1.
|
||||
dy = 0.
|
||||
segment_start = 0.
|
||||
x = 0.0
|
||||
y = 0.0
|
||||
dx = 1.0
|
||||
dy = 0.0
|
||||
segment_start = 0.0
|
||||
|
||||
last_segment = None
|
||||
if layout.Segments and 0 < len(layout.Segments):
|
||||
@@ -68,15 +74,15 @@ def add_zero_length_segment(file: ifcopenshell.file, layout: entity_instance, in
|
||||
# because this becomes of placement of the zero length segment
|
||||
last_segment = layout.Segments[-1]
|
||||
settings = ifcopenshell.geom.settings()
|
||||
fn = wrapper.map_shape(settings,last_segment.wrapped_data)
|
||||
eval = wrapper.function_item_evaluator(settings,fn)
|
||||
fn = wrapper.map_shape(settings, last_segment.wrapped_data)
|
||||
eval = wrapper.function_item_evaluator(settings, fn)
|
||||
e = np.array(eval.evaluate(fn.end()))
|
||||
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(file)
|
||||
e[:3,3] /= unit_scale
|
||||
x = float(e[0,3])
|
||||
y = float(e[1,3])
|
||||
dx = float(e[0,0])
|
||||
dy = float(e[1,0])
|
||||
e[:3, 3] /= unit_scale
|
||||
x = float(e[0, 3])
|
||||
y = float(e[1, 3])
|
||||
dx = float(e[0, 0])
|
||||
dy = float(e[1, 0])
|
||||
|
||||
parent_curve = file.createIfcLine(
|
||||
Pnt=file.createIfcCartesianPoint(Coordinates=((0.0, 0.0))),
|
||||
@@ -99,21 +105,21 @@ def add_zero_length_segment(file: ifcopenshell.file, layout: entity_instance, in
|
||||
layout.Segments += (zero_length_curve_segment,)
|
||||
|
||||
if last_segment:
|
||||
_update_curve_segment_transition_code(last_segment,zero_length_curve_segment)
|
||||
_update_curve_segment_transition_code(last_segment, zero_length_curve_segment)
|
||||
|
||||
# add zero length segments to base curves
|
||||
if layout.is_a("IfcSegmentedReferenceCurve"):
|
||||
ifcopenshell.api.alignment.add_zero_length_segment(file,layout.BaseCurve)
|
||||
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)
|
||||
ifcopenshell.api.alignment.add_zero_length_segment(file, layout.BaseCurve)
|
||||
|
||||
else:
|
||||
zero_length_curve_segment = None
|
||||
if layout.is_a("IfcAlignmentHorizontal"):
|
||||
x = 0.
|
||||
y = 0.
|
||||
dx = 1.
|
||||
dy = 0.
|
||||
x = 0.0
|
||||
y = 0.0
|
||||
dx = 1.0
|
||||
dy = 0.0
|
||||
last_segment = None
|
||||
for rel in layout.IsNestedBy:
|
||||
if 0 < len(rel.RelatedObjects):
|
||||
@@ -121,35 +127,34 @@ def add_zero_length_segment(file: ifcopenshell.file, layout: entity_instance, in
|
||||
break
|
||||
|
||||
if last_segment:
|
||||
file.begin_transaction() # use a transaction so we can discard any temporary IFC entities created
|
||||
file.begin_transaction() # use a transaction so we can discard any temporary IFC entities created
|
||||
|
||||
settings = ifcopenshell.geom.settings()
|
||||
mapped_segments = _map_alignment_horizontal_segment(file,last_segment)
|
||||
mapped_segments = _map_alignment_horizontal_segment(file, last_segment)
|
||||
geometry_segment = mapped_segments[0] if mapped_segments[1] == None else mapped_segments[1]
|
||||
fn = wrapper.map_shape(settings,geometry_segment.wrapped_data)
|
||||
eval = wrapper.function_item_evaluator(settings,fn)
|
||||
fn = wrapper.map_shape(settings, geometry_segment.wrapped_data)
|
||||
eval = wrapper.function_item_evaluator(settings, fn)
|
||||
e = np.array(eval.evaluate(fn.end()))
|
||||
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(file)
|
||||
x = float(e[0,3]) / unit_scale
|
||||
y = float(e[1,3]) / unit_scale
|
||||
dx = float(e[0,0])
|
||||
dy = float(e[1,0])
|
||||
x = float(e[0, 3]) / unit_scale
|
||||
y = float(e[1, 3]) / unit_scale
|
||||
dx = float(e[0, 0])
|
||||
dy = float(e[1, 0])
|
||||
|
||||
file.discard_transaction()
|
||||
|
||||
|
||||
angle_unit_scale = ifcopenshell.util.unit.calculate_unit_scale(file,'PLANEANGLEUNIT')
|
||||
angle_unit_scale = ifcopenshell.util.unit.calculate_unit_scale(file, "PLANEANGLEUNIT")
|
||||
design_parameters = file.createIfcAlignmentHorizontalSegment(
|
||||
StartPoint=file.createIfcCartesianPoint(
|
||||
(x,y)
|
||||
),
|
||||
StartDirection=math.atan2(dy,dx) / angle_unit_scale,
|
||||
StartPoint=file.createIfcCartesianPoint((x, y)),
|
||||
StartDirection=math.atan2(dy, dx) / angle_unit_scale,
|
||||
StartRadiusOfCurvature=0.0,
|
||||
EndRadiusOfCurvature=0.0,
|
||||
SegmentLength=0.0,
|
||||
PredefinedType="LINE",
|
||||
)
|
||||
zero_length_curve_segment = file.createIfcAlignmentSegment(GlobalId=ifcopenshell.guid.new(), DesignParameters=design_parameters)
|
||||
zero_length_curve_segment = file.createIfcAlignmentSegment(
|
||||
GlobalId=ifcopenshell.guid.new(), DesignParameters=design_parameters
|
||||
)
|
||||
elif layout.is_a("IfcAlignmentVertical"):
|
||||
last_segment_dist_along = 0.0
|
||||
last_segment_end_gradient = 0.0
|
||||
@@ -170,7 +175,9 @@ def add_zero_length_segment(file: ifcopenshell.file, layout: entity_instance, in
|
||||
EndGradient=last_segment_end_gradient,
|
||||
PredefinedType="CONSTANTGRADIENT",
|
||||
)
|
||||
zero_length_curve_segment = file.createIfcAlignmentSegment(GlobalId=ifcopenshell.guid.new(), DesignParameters=design_parameters)
|
||||
zero_length_curve_segment = file.createIfcAlignmentSegment(
|
||||
GlobalId=ifcopenshell.guid.new(), DesignParameters=design_parameters
|
||||
)
|
||||
elif layout.is_a("IfcAlignmentCant"):
|
||||
last_segment_dist_along = 0.0
|
||||
last_segment_cant_left = 0.0
|
||||
@@ -200,14 +207,16 @@ def add_zero_length_segment(file: ifcopenshell.file, layout: entity_instance, in
|
||||
StartCantRight=last_segment_cant_right,
|
||||
PredefinedType="CONSTANTCANT",
|
||||
)
|
||||
zero_length_curve_segment = file.createIfcAlignmentSegment(GlobalId=ifcopenshell.guid.new(), DesignParameters=design_parameters)
|
||||
zero_length_curve_segment = file.createIfcAlignmentSegment(
|
||||
GlobalId=ifcopenshell.guid.new(), DesignParameters=design_parameters
|
||||
)
|
||||
|
||||
ifcopenshell.api.nest.assign_object(file, related_objects=[zero_length_curve_segment], relating_object=layout)
|
||||
|
||||
if include_referent:
|
||||
alignment = ifcopenshell.api.alignment.get_alignment(layout)
|
||||
station = ifcopenshell.api.alignment.get_alignment_station(file,alignment)
|
||||
station = ifcopenshell.api.alignment.get_alignment_station(file, alignment)
|
||||
name = f"{_get_segment_start_point_label(zero_length_curve_segment,None)} ({ifcopenshell.util.alignment.station_as_string(file,station)})"
|
||||
ifcopenshell.api.alignment.add_stationing_referent(file, zero_length_curve_segment, 0.0, station, name=name)
|
||||
|
||||
return True
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user