This commit is contained in:
Andrej730
2025-07-09 13:47:32 +05:00
parent 40f92d15c3
commit 5a4ad69bf7
30 changed files with 362 additions and 301 deletions
@@ -20,7 +20,10 @@ import ifcopenshell
from ifcopenshell import entity_instance from ifcopenshell import entity_instance
import typing import typing
def add_survey_point(file: ifcopenshell.file, survey_point: entity_instance, site:entity_instance = None) -> entity_instance:
def add_survey_point(
file: ifcopenshell.file, survey_point: entity_instance, site: entity_instance = None
) -> entity_instance:
""" """
Adds a single survey point to the model based on IFC Concept Template 4.1.7.1.2.5. Adds a single survey point to the model based on IFC Concept Template 4.1.7.1.2.5.
Survey points are located relative to IfcRepresentationContext.WorldCoordinateSystem Survey points are located relative to IfcRepresentationContext.WorldCoordinateSystem
@@ -35,11 +38,18 @@ def add_survey_point(file: ifcopenshell.file, survey_point: entity_instance, sit
annotation = ifcopenshell.api.cogo.add_survey_point(file,file.createIfcCartesianPoint(4000.0,3500.0))) annotation = ifcopenshell.api.cogo.add_survey_point(file,file.createIfcCartesianPoint(4000.0,3500.0)))
""" """
context = ifcopenshell.util.representation.get_context(file, "Model", "Annotation", "MODEL_VIEW") context = ifcopenshell.util.representation.get_context(file, "Model", "Annotation", "MODEL_VIEW")
shape_representation = file.createIfcShapeRepresentation(ContextOfItems=context,RepresentationIdentifier='Annotation',RepresentationType='Point',Items=[survey_point]) shape_representation = file.createIfcShapeRepresentation(
ContextOfItems=context, RepresentationIdentifier="Annotation", RepresentationType="Point", Items=[survey_point]
)
representation = file.createIfcProductDefinitionShape(Representations=[shape_representation]) representation = file.createIfcProductDefinitionShape(Representations=[shape_representation])
annotation = file.createIfcAnnotation(ifcopenshell.guid.new(),ObjectPlacement=context.WorldCoordinateSystem,Representation=representation,PredefinedType="SURVEY") annotation = file.createIfcAnnotation(
ifcopenshell.guid.new(),
ObjectPlacement=context.WorldCoordinateSystem,
Representation=representation,
PredefinedType="SURVEY",
)
if (site == None): if site == None:
site = file.by_type("IfcSite")[0] site = file.by_type("IfcSite")[0]
ifcopenshell.api.spatial.assign_container(file, relating_structure=site, products=[annotation]) ifcopenshell.api.spatial.assign_container(file, relating_structure=site, products=[annotation])
@@ -20,6 +20,7 @@ import ifcopenshell
from ifcopenshell import entity_instance from ifcopenshell import entity_instance
import typing import typing
def assign_survey_point(annotation: entity_instance, survey_point: entity_instance): def assign_survey_point(annotation: entity_instance, survey_point: entity_instance):
""" """
Assigns a coordinate point to a survey point annotation Assigns a coordinate point to a survey point annotation
@@ -18,6 +18,7 @@
import ifcopenshell.util.geolocation import ifcopenshell.util.geolocation
def bearing2dd(bearing: str) -> float: def bearing2dd(bearing: str) -> float:
""" """
Converts a quadrant bearing string to decimal degrees Converts a quadrant bearing string to decimal degrees
@@ -36,7 +37,7 @@ def bearing2dd(bearing: str)->float:
error_msg = "Invalid bearing string" error_msg = "Invalid bearing string"
bearing = bearing.strip() # trim external white space bearing = bearing.strip() # trim external white space
bearing = ' '.join(bearing.split()) # make sure all parts separated by a single space bearing = " ".join(bearing.split()) # make sure all parts separated by a single space
parts = bearing.split() parts = bearing.split()
nParts = len(parts) nParts = len(parts)
if nParts < 3 or 5 < nParts: if nParts < 3 or 5 < nParts:
@@ -44,17 +45,17 @@ def bearing2dd(bearing: str)->float:
cY = parts[0] cY = parts[0]
cY = cY.upper() cY = cY.upper()
if cY != 'N' and cY != 'S': if cY != "N" and cY != "S":
raise ValueError(error_msg) raise ValueError(error_msg)
cX = parts[-1] cX = parts[-1]
cX = cX.upper() cX = cX.upper()
if cX != 'E' and cX != 'W': if cX != "E" and cX != "W":
raise ValueError(error_msg) raise ValueError(error_msg)
d = 0 d = 0
m = 0 m = 0
s = 0. s = 0.0
ms = 0 ms = 0
if nParts == 3: if nParts == 3:
@@ -69,38 +70,37 @@ def bearing2dd(bearing: str)->float:
# s in a decimal number # s in a decimal number
# need to break it into whole seconds and milliseconds # need to break it into whole seconds and milliseconds
ms = 100.*(s - int(s)) ms = 100.0 * (s - int(s))
s = int(s) s = int(s)
if d < 0 or (m < 0 or 60 <= m) or (s < 0 or 60 <= s) or ms < 0: if d < 0 or (m < 0 or 60 <= m) or (s < 0 or 60 <= s) or ms < 0:
raise ValueError(error_msg) raise ValueError(error_msg)
if cY == 'N' and cX == 'E': if cY == "N" and cX == "E":
angle = 90. angle = 90.0
sign = -1. sign = -1.0
elif cY == 'N' and cX == 'W': elif cY == "N" and cX == "W":
angle = 90. angle = 90.0
sign = 1. sign = 1.0
elif cY == 'S' and cX == 'E': elif cY == "S" and cX == "E":
angle = 270. angle = 270.0
sign = 1. sign = 1.0
elif cY == 'S' and cX == 'W': elif cY == "S" and cX == "W":
angle = 270. angle = 270.0
sign = -1. sign = -1.0
try: try:
dms = ifcopenshell.util.geolocation.dms2dd(d, m, s, ms) dms = ifcopenshell.util.geolocation.dms2dd(d, m, s, ms)
except ValueError: except ValueError:
raise ValueError(error_msg) raise ValueError(error_msg)
if dms < 0. or 90. < dms: if dms < 0.0 or 90.0 < dms:
raise ValueError(error_msg) raise ValueError(error_msg)
angle += sign * dms angle += sign * dms
# S 90 E will evaluate to 360 # S 90 E will evaluate to 360
if angle == 360.: if angle == 360.0:
angle = 0. angle = 0.0
return angle return angle
@@ -20,6 +20,7 @@ import ifcopenshell
from ifcopenshell import entity_instance from ifcopenshell import entity_instance
import typing import typing
def edit_survey_point(annotation: entity_instance, x: float, y: float, z: float = 0.0): def edit_survey_point(annotation: entity_instance, x: float, y: float, z: float = 0.0):
""" """
Edits the location of a previously defined survey point Edits the location of a previously defined survey point
@@ -35,6 +36,6 @@ def edit_survey_point(annotation: entity_instance, x:float,y:float,z:float=0.0):
ifcopenshell.api.cogo.edit_surve_point(annotation,3500.0,2000.0) ifcopenshell.api.cogo.edit_surve_point(annotation,3500.0,2000.0)
""" """
if annotation.Representation.Representations[0].Items[0].Dim == 2: if annotation.Representation.Representations[0].Items[0].Dim == 2:
annotation.Representation.Representations[0].Items[0].Coordinates = ((x,y)) annotation.Representation.Representations[0].Items[0].Coordinates = (x, y)
else: else:
annotation.Representation.Representations[0].Items[0].Coordinates = ((x,y,z)) annotation.Representation.Representations[0].Items[0].Coordinates = (x, y, z)
@@ -20,6 +20,7 @@ import math
import ifcopenshell import ifcopenshell
import ifcopenshell.util.unit import ifcopenshell.util.unit
def station_as_string(file: ifcopenshell.file, sta: float): def station_as_string(file: ifcopenshell.file, sta: float):
""" """
Returns a stringized version of a station. Example 100.0 is 1+00.00 as a stationing string. Returns a stringized version of a station. Example 100.0 is 1+00.00 as a stationing string.
@@ -31,15 +32,18 @@ def station_as_string(file: ifcopenshell.file, sta: float):
unit_type = ifcopenshell.util.unit.get_project_unit(file, "LENGTHUNIT") unit_type = ifcopenshell.util.unit.get_project_unit(file, "LENGTHUNIT")
if unit_type.is_a("IfcConversionBasedUnit"): if unit_type.is_a("IfcConversionBasedUnit"):
station = ifcopenshell.util.unit.convert(sta,from_unit=unit_type.Name,from_prefix=None,to_unit="foot",to_prefix=None) station = ifcopenshell.util.unit.convert(
sta, from_unit=unit_type.Name, from_prefix=None, to_unit="foot", to_prefix=None
)
plus_seperator = 2 plus_seperator = 2
precision = 2 precision = 2
else: else:
station = ifcopenshell.util.unit.convert(sta,from_unit=unit_type.Name,from_prefix=unit_type.Prefix,to_unit="meter",to_prefix=None) station = ifcopenshell.util.unit.convert(
sta, from_unit=unit_type.Name, from_prefix=unit_type.Prefix, to_unit="meter", to_prefix=None
)
plus_seperator = 3 plus_seperator = 3
precision = 3 precision = 3
value = math.fabs(station) value = math.fabs(station)
shifter = math.pow(10.0, plus_seperator) shifter = math.pow(10.0, plus_seperator)
@@ -48,7 +52,7 @@ def station_as_string(file: ifcopenshell.file, sta: float):
# Check to make sure that v2 is not basically the same as shifter # Check to make sure that v2 is not basically the same as shifter
# If station = 69500.00000, we sometimes get 694+100.00 instead of 695+00.00 # If station = 69500.00000, we sometimes get 694+100.00 instead of 695+00.00
if math.isclose(v2-shifter, 0., abs_tol=5.0 * math.pow(10.0, -(precision + 1))): if math.isclose(v2 - shifter, 0.0, abs_tol=5.0 * math.pow(10.0, -(precision + 1))):
v2 = 0.0 v2 = 0.0
v1 += 1 v1 += 1
@@ -22,6 +22,7 @@ import ifcopenshell.api.context
from ifcopenshell.api.alignment._add_segment_to_layout import _add_segment_to_layout from ifcopenshell.api.alignment._add_segment_to_layout import _add_segment_to_layout
def test_add_segment_to_layout(): def test_add_segment_to_layout():
file = ifcopenshell.file(schema="IFC4X3") file = ifcopenshell.file(schema="IFC4X3")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
@@ -66,6 +67,10 @@ def test_add_segment_to_layout():
_add_segment_to_layout(file, horizontal_alignment, alignment_segment) _add_segment_to_layout(file, horizontal_alignment, alignment_segment)
assert len(horizontal_alignment.IsNestedBy) == 1 assert len(horizontal_alignment.IsNestedBy) == 1
assert len(horizontal_alignment.IsNestedBy[0].RelatedObjects) == 2 # The the segment we added and the automatically created zero length segment assert (
len(horizontal_alignment.IsNestedBy[0].RelatedObjects) == 2
) # The the segment we added and the automatically created zero length segment
assert horizontal_alignment.IsNestedBy[0].RelatedObjects[0] == alignment_segment assert horizontal_alignment.IsNestedBy[0].RelatedObjects[0] == alignment_segment
assert alignment_segment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent") # a referent is automatically added at the start of the segment assert (
alignment_segment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent")
) # a referent is automatically added at the start of the segment
@@ -21,6 +21,7 @@ import ifcopenshell.api.alignment
import ifcopenshell.api.context import ifcopenshell.api.context
import ifcopenshell.util.element import ifcopenshell.util.element
def test_add_stationing_to_alignment(): def test_add_stationing_to_alignment():
file = ifcopenshell.file(schema="IFC4X3") file = ifcopenshell.file(schema="IFC4X3")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
@@ -35,9 +36,7 @@ def test_add_stationing_to_alignment():
parent=geometric_representation_context, parent=geometric_representation_context,
) )
alignment = ifcopenshell.api.alignment.create( alignment = ifcopenshell.api.alignment.create(file, "TestAlignment", start_station=2000.0)
file, "TestAlignment", start_station=2000.
)
for rel in alignment.IsNestedBy: for rel in alignment.IsNestedBy:
for referent in rel.RelatedObjects: for referent in rel.RelatedObjects:
@@ -49,7 +49,9 @@ def test_add_vertical_alignment():
assert len(alignment.IsDecomposedBy) == 0 # no child alignments assert len(alignment.IsDecomposedBy) == 0 # no child alignments
assert len(alignment.IsNestedBy) == 1 # one nest assert len(alignment.IsNestedBy) == 1 # one nest
assert len(alignment.IsNestedBy[0].RelatedObjects) == 3 # nesting IfcReferent, IfcAlignmentHorizontal, IfcAlignmentVertical assert (
len(alignment.IsNestedBy[0].RelatedObjects) == 3
) # nesting IfcReferent, IfcAlignmentHorizontal, IfcAlignmentVertical
assert alignment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent") assert alignment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent")
assert alignment.IsNestedBy[0].RelatedObjects[1].is_a("IfcAlignmentHorizontal") assert alignment.IsNestedBy[0].RelatedObjects[1].is_a("IfcAlignmentHorizontal")
assert alignment.IsNestedBy[0].RelatedObjects[2].is_a("IfcAlignmentVertical") assert alignment.IsNestedBy[0].RelatedObjects[2].is_a("IfcAlignmentVertical")
@@ -75,4 +77,5 @@ def test_add_vertical_alignment():
assert alignment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent") assert alignment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent")
assert alignment.IsNestedBy[0].RelatedObjects[1].is_a("IfcAlignmentHorizontal") assert alignment.IsNestedBy[0].RelatedObjects[1].is_a("IfcAlignmentHorizontal")
test_add_vertical_alignment() test_add_vertical_alignment()
@@ -46,7 +46,7 @@ def test_create_alignment():
# verify the geometric representation was created # verify the geometric representation was created
curve = ifcopenshell.api.alignment.get_curve(ali) curve = ifcopenshell.api.alignment.get_curve(ali)
assert(curve.is_a() == expected_curve_type[i]) assert curve.is_a() == expected_curve_type[i]
assert len(curve.Segments) == 1 assert len(curve.Segments) == 1
horiz = ifcopenshell.api.alignment.get_horizontal_layout(ali) horiz = ifcopenshell.api.alignment.get_horizontal_layout(ali)
@@ -66,4 +66,6 @@ def test_create_alignment():
if a != None: if a != None:
segments = ifcopenshell.api.alignment.get_layout_segments(a) segments = ifcopenshell.api.alignment.get_layout_segments(a)
assert len(segments) == 1 assert len(segments) == 1
assert ifcopenshell.api.alignment.has_zero_length_segment(a) # there is a check in this function for the geometry curve assert ifcopenshell.api.alignment.has_zero_length_segment(
a
) # there is a check in this function for the geometry curve
@@ -40,18 +40,27 @@ def test_create_alignment_pi_method():
vpoints = [(0.0, 100.0), (2000.0, 135.0), (5000.0, 105.0), (7400.0, 153.0), (9800.0, 105.0), (12800.0, 90.0)] vpoints = [(0.0, 100.0), (2000.0, 135.0), (5000.0, 105.0), (7400.0, 153.0), (9800.0, 105.0), (12800.0, 90.0)]
lengths = [(1600.0), (1200.0), (2000.0), (800.0)] lengths = [(1600.0), (1200.0), (2000.0), (800.0)]
alignment = ifcopenshell.api.alignment.create_by_pi_method(file, "TestAlignment", coordinates, radii, vpoints, lengths) alignment = ifcopenshell.api.alignment.create_by_pi_method(
file, "TestAlignment", coordinates, radii, vpoints, lengths
)
assert len(alignment.IsDecomposedBy) == 0 # no child alignments assert len(alignment.IsDecomposedBy) == 0 # no child alignments
assert len(alignment.IsNestedBy) == 1 # one nest assert len(alignment.IsNestedBy) == 1 # one nest
assert len(alignment.IsNestedBy[0].RelatedObjects) == 3 # nesting IfcReferent, IfcAlignmentHorizontal, IfcAlignmentVertical assert (
len(alignment.IsNestedBy[0].RelatedObjects) == 3
) # nesting IfcReferent, IfcAlignmentHorizontal, IfcAlignmentVertical
assert alignment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent") assert alignment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent")
assert alignment.IsNestedBy[0].RelatedObjects[1].is_a("IfcAlignmentHorizontal") assert alignment.IsNestedBy[0].RelatedObjects[1].is_a("IfcAlignmentHorizontal")
assert alignment.IsNestedBy[0].RelatedObjects[2].is_a("IfcAlignmentVertical") assert alignment.IsNestedBy[0].RelatedObjects[2].is_a("IfcAlignmentVertical")
assert ( assert (
len(alignment.IsNestedBy[0].RelatedObjects[1].IsNestedBy) == 1 len(alignment.IsNestedBy[0].RelatedObjects[1].IsNestedBy) == 1
) # nesting of segments beneath IfcAlignmentHorizontal ) # nesting of segments beneath IfcAlignmentHorizontal
assert len(alignment.IsNestedBy[0].RelatedObjects[1].IsNestedBy[0].RelatedObjects) == 8 # segments in horizontal layout assert (
assert len(alignment.IsNestedBy[0].RelatedObjects[2].IsNestedBy[0].RelatedObjects) == 10 # segments in vertical layout len(alignment.IsNestedBy[0].RelatedObjects[1].IsNestedBy[0].RelatedObjects) == 8
) # segments in horizontal layout
assert (
len(alignment.IsNestedBy[0].RelatedObjects[2].IsNestedBy[0].RelatedObjects) == 10
) # segments in vertical layout
test_create_alignment_pi_method() test_create_alignment_pi_method()
@@ -22,6 +22,7 @@ import ifcopenshell.api.context
from ifcopenshell import entity_instance from ifcopenshell import entity_instance
import math import math
def _test_horizontal() -> ifcopenshell.file: def _test_horizontal() -> ifcopenshell.file:
file = ifcopenshell.file(schema="IFC4X3_ADD2") file = ifcopenshell.file(schema="IFC4X3_ADD2")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
@@ -76,7 +77,6 @@ def _test_horizontal() -> ifcopenshell.file:
assert curve.is_a("IfcCompositeCurve") assert curve.is_a("IfcCompositeCurve")
assert len(curve.Segments) == 2 assert len(curve.Segments) == 2
design_parameters = file.create_entity( design_parameters = file.create_entity(
type="IfcAlignmentHorizontalSegment", type="IfcAlignmentHorizontalSegment",
StartTag=None, StartTag=None,
@@ -163,9 +163,9 @@ def _test_horizontal_vertical():
StartDistAlong=0.0, StartDistAlong=0.0,
HorizontalLength=50.0, HorizontalLength=50.0,
StartHeight=20.0, StartHeight=20.0,
StartGradient = 1./100., StartGradient=1.0 / 100.0,
EndGradient = 1./100., EndGradient=1.0 / 100.0,
PredefinedType="CONSTANTGRADIENT" PredefinedType="CONSTANTGRADIENT",
) )
end = ifcopenshell.api.alignment.create_layout_segment(file, vertical_alignment, design_parameters) end = ifcopenshell.api.alignment.create_layout_segment(file, vertical_alignment, design_parameters)
@@ -175,7 +175,7 @@ def _test_horizontal_vertical():
y = end[1, 3] y = end[1, 3]
z = end[2, 3] z = end[2, 3]
assert x == 50. assert x == 50.0
assert y == 20.5 assert y == 20.5
assert z == 0.0 assert z == 0.0
@@ -189,7 +189,7 @@ def _test_horizontal_vertical():
StartHeight=y.item(), StartHeight=y.item(),
StartGradient=-gradient, StartGradient=-gradient,
EndGradient=-gradient, EndGradient=-gradient,
PredefinedType="CONSTANTGRADIENT" PredefinedType="CONSTANTGRADIENT",
) )
end = ifcopenshell.api.alignment.create_layout_segment(file, vertical_alignment, design_parameters) end = ifcopenshell.api.alignment.create_layout_segment(file, vertical_alignment, design_parameters)
@@ -199,8 +199,8 @@ def _test_horizontal_vertical():
y = end[1, 3] y = end[1, 3]
z = end[2, 3] z = end[2, 3]
assert x == 100. assert x == 100.0
assert y == 20. assert y == 20.0
assert z == 0.0 assert z == 0.0
basis_curve = ifcopenshell.api.alignment.get_basis_curve(ali) basis_curve = ifcopenshell.api.alignment.get_basis_curve(ali)
@@ -223,9 +223,9 @@ def _test_horizontal_vertical2(file: ifcopenshell.file):
StartDistAlong=0.0, StartDistAlong=0.0,
HorizontalLength=50.0, HorizontalLength=50.0,
StartHeight=20.0, StartHeight=20.0,
StartGradient = 1./100., StartGradient=1.0 / 100.0,
EndGradient = 1./100., EndGradient=1.0 / 100.0,
PredefinedType="CONSTANTGRADIENT" PredefinedType="CONSTANTGRADIENT",
) )
end = ifcopenshell.api.alignment.create_layout_segment(file, vertical_alignment, design_parameters) end = ifcopenshell.api.alignment.create_layout_segment(file, vertical_alignment, design_parameters)
@@ -235,7 +235,7 @@ def _test_horizontal_vertical2(file: ifcopenshell.file):
y = end[1, 3] y = end[1, 3]
z = end[2, 3] z = end[2, 3]
assert x == 50. assert x == 50.0
assert y == 20.5 assert y == 20.5
assert z == 0.0 assert z == 0.0
@@ -249,7 +249,7 @@ def _test_horizontal_vertical2(file: ifcopenshell.file):
StartHeight=y.item(), StartHeight=y.item(),
StartGradient=-gradient, StartGradient=-gradient,
EndGradient=-gradient, EndGradient=-gradient,
PredefinedType="CONSTANTGRADIENT" PredefinedType="CONSTANTGRADIENT",
) )
end = ifcopenshell.api.alignment.create_layout_segment(file, vertical_alignment, design_parameters) end = ifcopenshell.api.alignment.create_layout_segment(file, vertical_alignment, design_parameters)
@@ -259,17 +259,19 @@ def _test_horizontal_vertical2(file: ifcopenshell.file):
y = end[1, 3] y = end[1, 3]
z = end[2, 3] z = end[2, 3]
assert x == 100. assert x == 100.0
assert y == 20. assert y == 20.0
assert z == 0.0 assert z == 0.0
curve = ifcopenshell.api.alignment.get_curve(ali) curve = ifcopenshell.api.alignment.get_curve(ali)
assert curve.is_a("IfcGradientCurve") assert curve.is_a("IfcGradientCurve")
assert len(curve.Segments) == 3 assert len(curve.Segments) == 3
def test_append_segment(): def test_append_segment():
file = _test_horizontal() file = _test_horizontal()
_test_horizontal_vertical() _test_horizontal_vertical()
_test_horizontal_vertical2(file) _test_horizontal_vertical2(file)
test_append_segment() test_append_segment()
@@ -20,6 +20,7 @@ import pytest
import ifcopenshell.api.alignment import ifcopenshell.api.alignment
import ifcopenshell.api.context import ifcopenshell.api.context
def test_distance_along_from_station(): def test_distance_along_from_station():
file = ifcopenshell.file(schema="IFC4X3") file = ifcopenshell.file(schema="IFC4X3")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
@@ -55,12 +55,11 @@ def _test_horizontal_and_vertical():
parent=geometric_representation_context, parent=geometric_representation_context,
) )
alignment = ifcopenshell.api.alignment.create( alignment = ifcopenshell.api.alignment.create(file, "TestAlignment", include_vertical=True)
file, "TestAlignment", include_vertical=True
)
basis_curve = ifcopenshell.api.alignment.get_basis_curve(alignment) basis_curve = ifcopenshell.api.alignment.get_basis_curve(alignment)
assert basis_curve.is_a("IfcCompositeCurve") assert basis_curve.is_a("IfcCompositeCurve")
def _test_horizontal_and_vertical_and_cant(): def _test_horizontal_and_vertical_and_cant():
file = ifcopenshell.file(schema="IFC4X3") file = ifcopenshell.file(schema="IFC4X3")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
@@ -75,12 +74,11 @@ def _test_horizontal_and_vertical_and_cant():
parent=geometric_representation_context, parent=geometric_representation_context,
) )
alignment = ifcopenshell.api.alignment.create( alignment = ifcopenshell.api.alignment.create(file, "TestAlignment", include_vertical=True, include_cant=True)
file, "TestAlignment", include_vertical=True,include_cant=True
)
basis_curve = ifcopenshell.api.alignment.get_basis_curve(alignment) basis_curve = ifcopenshell.api.alignment.get_basis_curve(alignment)
assert basis_curve.is_a("IfcCompositeCurve") assert basis_curve.is_a("IfcCompositeCurve")
def test_get_basis_curve(): def test_get_basis_curve():
_test_horizontal() _test_horizontal()
_test_horizontal_and_vertical() _test_horizontal_and_vertical()
@@ -18,6 +18,7 @@
import ifcopenshell.api.alignment import ifcopenshell.api.alignment
def test_get_curve(): def test_get_curve():
file = ifcopenshell.file(schema="IFC4X3") file = ifcopenshell.file(schema="IFC4X3")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
@@ -18,6 +18,7 @@
import ifcopenshell.api.alignment import ifcopenshell.api.alignment
def test_get_layout_curve(): def test_get_layout_curve():
file = ifcopenshell.file(schema="IFC4X3") file = ifcopenshell.file(schema="IFC4X3")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
@@ -20,6 +20,7 @@ import ifcopenshell.api.alignment
import ifcopenshell.api.alignment.has_zero_length_segment import ifcopenshell.api.alignment.has_zero_length_segment
import ifcopenshell.api.context import ifcopenshell.api.context
def _test_horizontal(): def _test_horizontal():
file = ifcopenshell.file(schema="IFC4X3") file = ifcopenshell.file(schema="IFC4X3")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
@@ -38,6 +39,7 @@ def _test_horizontal():
horizontal = ifcopenshell.api.alignment.get_horizontal_layout(alignment) horizontal = ifcopenshell.api.alignment.get_horizontal_layout(alignment)
assert True == ifcopenshell.api.alignment.has_zero_length_segment(horizontal) assert True == ifcopenshell.api.alignment.has_zero_length_segment(horizontal)
def _test_horizontal_vertical(): def _test_horizontal_vertical():
file = ifcopenshell.file(schema="IFC4X3") file = ifcopenshell.file(schema="IFC4X3")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
@@ -58,6 +60,7 @@ def _test_horizontal_vertical():
vertical = ifcopenshell.api.alignment.get_vertical_layout(alignment) vertical = ifcopenshell.api.alignment.get_vertical_layout(alignment)
assert True == ifcopenshell.api.alignment.has_zero_length_segment(vertical) assert True == ifcopenshell.api.alignment.has_zero_length_segment(vertical)
def _test_horizontal_vertical_cant(): def _test_horizontal_vertical_cant():
file = ifcopenshell.file(schema="IFC4X3") file = ifcopenshell.file(schema="IFC4X3")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
@@ -80,6 +83,7 @@ def _test_horizontal_vertical_cant():
cant = ifcopenshell.api.alignment.get_cant_layout(alignment) cant = ifcopenshell.api.alignment.get_cant_layout(alignment)
assert True == ifcopenshell.api.alignment.has_zero_length_segment(cant) assert True == ifcopenshell.api.alignment.has_zero_length_segment(cant)
def test_has_zero_length_segment(): def test_has_zero_length_segment():
_test_horizontal() _test_horizontal()
_test_horizontal_vertical() _test_horizontal_vertical()
@@ -20,6 +20,7 @@ import pytest
import ifcopenshell.api.alignment import ifcopenshell.api.alignment
import ifcopenshell.api.context import ifcopenshell.api.context
# other test cases cover the typical vertical by PI method (test_create_alignment_by_pi_method) # other test cases cover the typical vertical by PI method (test_create_alignment_by_pi_method)
# this test will focus on the edge cases of no initial tangent run, no final tangent run, and # this test will focus on the edge cases of no initial tangent run, no final tangent run, and
# compound curve (no tangent between curves) # compound curve (no tangent between curves)
@@ -50,6 +51,9 @@ def test_horizontal_layout_by_pi_method():
assert ( assert (
len(alignment.IsNestedBy[0].RelatedObjects[1].IsNestedBy) == 1 len(alignment.IsNestedBy[0].RelatedObjects[1].IsNestedBy) == 1
) # nesting of segments beneath IfcAlignmentHorizontal ) # nesting of segments beneath IfcAlignmentHorizontal
assert len(alignment.IsNestedBy[0].RelatedObjects[1].IsNestedBy[0].RelatedObjects) == 3 # segments in horizontal layout assert (
len(alignment.IsNestedBy[0].RelatedObjects[1].IsNestedBy[0].RelatedObjects) == 3
) # segments in horizontal layout
test_horizontal_layout_by_pi_method() test_horizontal_layout_by_pi_method()
@@ -21,6 +21,7 @@ import ifcopenshell.api.alignment
import ifcopenshell.api.context import ifcopenshell.api.context
from ifcopenshell.api.alignment._map_alignment_cant_segment import _map_alignment_cant_segment from ifcopenshell.api.alignment._map_alignment_cant_segment import _map_alignment_cant_segment
def _BlossCurve_100_0_300_1000_1_Meter(file): def _BlossCurve_100_0_300_1000_1_Meter(file):
design_parameters = file.createIfcAlignmentCantSegment( design_parameters = file.createIfcAlignmentCantSegment(
StartDistAlong=0.0, StartDistAlong=0.0,
@@ -23,6 +23,7 @@ import pytest
import ifcopenshell.api.alignment import ifcopenshell.api.alignment
from ifcopenshell.api.alignment._map_alignment_horizontal_segment import __map_alignment_horizontal_segment from ifcopenshell.api.alignment._map_alignment_horizontal_segment import __map_alignment_horizontal_segment
def _BlossCurve_100_0_300_1000_1_Meter(file): def _BlossCurve_100_0_300_1000_1_Meter(file):
design_parameters = file.createIfcAlignmentHorizontalSegment( design_parameters = file.createIfcAlignmentHorizontalSegment(
StartPoint=file.createIfcCartesianPoint((0.0, 0.0)), StartPoint=file.createIfcCartesianPoint((0.0, 0.0)),
@@ -23,6 +23,7 @@ import pytest
import ifcopenshell.api.alignment import ifcopenshell.api.alignment
from ifcopenshell.api.alignment._map_alignment_vertical_segment import _map_alignment_vertical_segment from ifcopenshell.api.alignment._map_alignment_vertical_segment import _map_alignment_vertical_segment
def _CircularArc_100_0_10_0_0_0_0_5_1_Meter(file): def _CircularArc_100_0_10_0_0_0_0_5_1_Meter(file):
design_parameters = file.createIfcAlignmentVerticalSegment( design_parameters = file.createIfcAlignmentVerticalSegment(
StartDistAlong=0.0, StartDistAlong=0.0,
@@ -42,8 +42,9 @@ def default_names_alignment():
vpoints = [(0.0, 100.0), (2000.0, 135.0), (5000.0, 105.0), (7400.0, 153.0), (9800.0, 105.0), (12800.0, 90.0)] vpoints = [(0.0, 100.0), (2000.0, 135.0), (5000.0, 105.0), (7400.0, 153.0), (9800.0, 105.0), (12800.0, 90.0)]
lengths = [(1600.0), (1200.0), (2000.0), (800.0)] lengths = [(1600.0), (1200.0), (2000.0), (800.0)]
alignment = ifcopenshell.api.alignment.create_by_pi_method(file, "TestAlignment", coordinates, radii, vpoints, alignment = ifcopenshell.api.alignment.create_by_pi_method(
lengths) file, "TestAlignment", coordinates, radii, vpoints, lengths
)
yield alignment yield alignment
@@ -88,8 +89,9 @@ def callback_alignment():
vpoints = [(0.0, 100.0), (2000.0, 135.0), (5000.0, 105.0), (7400.0, 153.0), (9800.0, 105.0), (12800.0, 90.0)] vpoints = [(0.0, 100.0), (2000.0, 135.0), (5000.0, 105.0), (7400.0, 153.0), (9800.0, 105.0), (12800.0, 90.0)]
lengths = [(1600.0), (1200.0), (2000.0), (800.0)] lengths = [(1600.0), (1200.0), (2000.0), (800.0)]
alignment = ifcopenshell.api.alignment.create_by_pi_method(file, "TestAlignment", coordinates, radii, vpoints, alignment = ifcopenshell.api.alignment.create_by_pi_method(
lengths) file, "TestAlignment", coordinates, radii, vpoints, lengths
)
yield alignment yield alignment
@@ -108,6 +110,7 @@ def test_with_default_names(default_names_alignment):
assert "P.V.T." in vlayout.IsNestedBy[0].RelatedObjects[2].IsNestedBy[0].RelatedObjects[0].Name assert "P.V.T." in vlayout.IsNestedBy[0].RelatedObjects[2].IsNestedBy[0].RelatedObjects[0].Name
assert "V.P.O.E." in vlayout.IsNestedBy[0].RelatedObjects[-1].IsNestedBy[0].RelatedObjects[0].Name assert "V.P.O.E." in vlayout.IsNestedBy[0].RelatedObjects[-1].IsNestedBy[0].RelatedObjects[0].Name
def test_with_callbacks(callback_alignment): def test_with_callbacks(callback_alignment):
hlayout = ifcopenshell.api.alignment.get_horizontal_layout(callback_alignment) hlayout = ifcopenshell.api.alignment.get_horizontal_layout(callback_alignment)
@@ -223,7 +223,9 @@ def _test2():
), ),
) )
composite_curve = file.createIfcCompositeCurve(Segments=[line1,clothoid1,circular_arc,clothoid2,line2], SelfIntersect=False) composite_curve = file.createIfcCompositeCurve(
Segments=[line1, clothoid1, circular_arc, clothoid2, line2], SelfIntersect=False
)
_update_curve_segment_transition_code(line1, clothoid1) _update_curve_segment_transition_code(line1, clothoid1)
assert line1.Transition == "CONTSAMEGRADIENTSAMECURVATURE" assert line1.Transition == "CONTSAMEGRADIENTSAMECURVATURE"
@@ -242,4 +244,5 @@ def test_update_curve_segment_transition_code():
_test1() _test1()
_test2() _test2()
test_update_curve_segment_transition_code() test_update_curve_segment_transition_code()
@@ -20,6 +20,7 @@ import pytest
import ifcopenshell.api.alignment import ifcopenshell.api.alignment
import ifcopenshell.api.context import ifcopenshell.api.context
# other test cases cover the typical vertical by PI method (test_create_alignment_by_pi_method) # other test cases cover the typical vertical by PI method (test_create_alignment_by_pi_method)
# this test will focus on the edge cases of no initial gradient, no final gradient, and # this test will focus on the edge cases of no initial gradient, no final gradient, and
# compound vertical curve (no gradient between curves) # compound vertical curve (no gradient between curves)
@@ -37,16 +38,15 @@ def test_vertical_layout_by_pi_method():
parent=geometric_representation_context, parent=geometric_representation_context,
) )
alignment = ifcopenshell.api.alignment.create(file, "TestAlignment", include_vertical=True) alignment = ifcopenshell.api.alignment.create(file, "TestAlignment", include_vertical=True)
hlayout = ifcopenshell.api.alignment.get_horizontal_layout(alignment) hlayout = ifcopenshell.api.alignment.get_horizontal_layout(alignment)
segment1 = file.createIfcAlignmentHorizontalSegment( segment1 = file.createIfcAlignmentHorizontalSegment(
StartPoint=file.createIfcCartesianPoint(Coordinates=((0.,0.))), # Actual coordinate unknown StartPoint=file.createIfcCartesianPoint(Coordinates=((0.0, 0.0))), # Actual coordinate unknown
StartDirection=0.0, StartDirection=0.0,
StartRadiusOfCurvature=0.0, StartRadiusOfCurvature=0.0,
EndRadiusOfCurvature=0.0, EndRadiusOfCurvature=0.0,
SegmentLength=10000.0, SegmentLength=10000.0,
PredefinedType = "LINE" PredefinedType="LINE",
) )
ifcopenshell.api.alignment.create_layout_segment(file, hlayout, segment1) ifcopenshell.api.alignment.create_layout_segment(file, hlayout, segment1)
@@ -58,14 +58,21 @@ def test_vertical_layout_by_pi_method():
assert len(alignment.IsDecomposedBy) == 0 # no child alignments assert len(alignment.IsDecomposedBy) == 0 # no child alignments
assert len(alignment.IsNestedBy) == 1 # one nest assert len(alignment.IsNestedBy) == 1 # one nest
assert len(alignment.IsNestedBy[0].RelatedObjects) == 3 # nesting IfcReferent, IfcAlignmentHorizontal, IfcAlignmentVertical assert (
len(alignment.IsNestedBy[0].RelatedObjects) == 3
) # nesting IfcReferent, IfcAlignmentHorizontal, IfcAlignmentVertical
assert alignment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent") assert alignment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent")
assert alignment.IsNestedBy[0].RelatedObjects[1].is_a("IfcAlignmentHorizontal") assert alignment.IsNestedBy[0].RelatedObjects[1].is_a("IfcAlignmentHorizontal")
assert alignment.IsNestedBy[0].RelatedObjects[2].is_a("IfcAlignmentVertical") assert alignment.IsNestedBy[0].RelatedObjects[2].is_a("IfcAlignmentVertical")
assert ( assert (
len(alignment.IsNestedBy[0].RelatedObjects[1].IsNestedBy) == 1 len(alignment.IsNestedBy[0].RelatedObjects[1].IsNestedBy) == 1
) # nesting of segments beneath IfcAlignmentHorizontal ) # nesting of segments beneath IfcAlignmentHorizontal
assert len(alignment.IsNestedBy[0].RelatedObjects[1].IsNestedBy[0].RelatedObjects) == 2 # segments in horizontal layout assert (
assert len(alignment.IsNestedBy[0].RelatedObjects[2].IsNestedBy[0].RelatedObjects) == 3 # segments in vertical layout len(alignment.IsNestedBy[0].RelatedObjects[1].IsNestedBy[0].RelatedObjects) == 2
) # segments in horizontal layout
assert (
len(alignment.IsNestedBy[0].RelatedObjects[2].IsNestedBy[0].RelatedObjects) == 3
) # segments in vertical layout
test_vertical_layout_by_pi_method() test_vertical_layout_by_pi_method()
@@ -42,4 +42,3 @@ def test_add_survey_point():
assert annotation.Representation.Representations[0].RepresentationIdentifier == "Annotation" assert annotation.Representation.Representations[0].RepresentationIdentifier == "Annotation"
assert annotation.Representation.Representations[0].RepresentationType == "Point" assert annotation.Representation.Representations[0].RepresentationType == "Point"
assert annotation.Representation.Representations[0].Items[0].Coordinates == pytest.approx((50.0, 10.0)) assert annotation.Representation.Representations[0].Items[0].Coordinates == pytest.approx((50.0, 10.0))
@@ -45,4 +45,3 @@ def test_assign_survey_point():
ifcopenshell.api.cogo.assign_survey_point(annotation, file.createIfcCartesianPoint((20.0, 30.0, 40.0))) ifcopenshell.api.cogo.assign_survey_point(annotation, file.createIfcCartesianPoint((20.0, 30.0, 40.0)))
assert annotation.Representation.Representations[0].Items[0].Coordinates == pytest.approx((20.0, 30.0, 40.0)) assert annotation.Representation.Representations[0].Items[0].Coordinates == pytest.approx((20.0, 30.0, 40.0))
@@ -35,10 +35,10 @@ def test_bearing2dd():
assert 0.0 == pytest.approx(ifcopenshell.api.cogo.bearing2dd("N 90 E")) assert 0.0 == pytest.approx(ifcopenshell.api.cogo.bearing2dd("N 90 E"))
assert 0.0 == pytest.approx(ifcopenshell.api.cogo.bearing2dd("S 90 E")) assert 0.0 == pytest.approx(ifcopenshell.api.cogo.bearing2dd("S 90 E"))
assert 180. == pytest.approx(ifcopenshell.api.cogo.bearing2dd("N 90 W")) assert 180.0 == pytest.approx(ifcopenshell.api.cogo.bearing2dd("N 90 W"))
assert 180. == pytest.approx(ifcopenshell.api.cogo.bearing2dd("S 90 W")) assert 180.0 == pytest.approx(ifcopenshell.api.cogo.bearing2dd("S 90 W"))
assert 120. == pytest.approx(ifcopenshell.api.cogo.bearing2dd("N 30 W")) assert 120.0 == pytest.approx(ifcopenshell.api.cogo.bearing2dd("N 30 W"))
assert 120.16666666666667 == pytest.approx(ifcopenshell.api.cogo.bearing2dd("N 30 10 W")) assert 120.16666666666667 == pytest.approx(ifcopenshell.api.cogo.bearing2dd("N 30 10 W"))
assert 89.999722222222228 == pytest.approx(ifcopenshell.api.cogo.bearing2dd("N 00 00 1 E")) assert 89.999722222222228 == pytest.approx(ifcopenshell.api.cogo.bearing2dd("N 00 00 1 E"))
@@ -69,5 +69,5 @@ def test_bearing2dd():
with pytest.raises(ValueError, match="Invalid bearing string"): with pytest.raises(ValueError, match="Invalid bearing string"):
ifcopenshell.api.cogo.bearing2dd("N 45 15 99.5 E") ifcopenshell.api.cogo.bearing2dd("N 45 15 99.5 E")
test_bearing2dd()
test_bearing2dd()
@@ -45,4 +45,3 @@ def test_edit_survey_point():
ifcopenshell.api.cogo.edit_survey_point(annotation, 20.0, 30.0) ifcopenshell.api.cogo.edit_survey_point(annotation, 20.0, 30.0)
assert annotation.Representation.Representations[0].Items[0].Coordinates == pytest.approx((20.0, 30.0)) assert annotation.Representation.Representations[0].Items[0].Coordinates == pytest.approx((20.0, 30.0))
@@ -19,6 +19,7 @@
import ifcopenshell import ifcopenshell
import ifcopenshell.util.stationing as sta import ifcopenshell.util.stationing as sta
def _test_si_stations(): def _test_si_stations():
file = ifcopenshell.file(schema="IFC4X3_ADD2") file = ifcopenshell.file(schema="IFC4X3_ADD2")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
@@ -40,6 +41,7 @@ def _test_si_stations():
s = sta.station_as_string(file, -123456.789) s = sta.station_as_string(file, -123456.789)
assert s == "-123+456.789" assert s == "-123+456.789"
def _test_si_stations_millimeter(): def _test_si_stations_millimeter():
file = ifcopenshell.file(schema="IFC4X3_ADD2") file = ifcopenshell.file(schema="IFC4X3_ADD2")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
@@ -51,6 +53,7 @@ def _test_si_stations_millimeter():
s = sta.station_as_string(file, 1000.00) s = sta.station_as_string(file, 1000.00)
assert s == "0+001.000" assert s == "0+001.000"
def _test_us_stations(): def _test_us_stations():
file = ifcopenshell.file(schema="IFC4X3_ADD2") file = ifcopenshell.file(schema="IFC4X3_ADD2")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test") project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")