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
@@ -22,11 +22,12 @@ import ifcopenshell.api.context
from ifcopenshell import entity_instance
import math
def _test_horizontal() -> ifcopenshell.file:
file = ifcopenshell.file(schema="IFC4X3_ADD2")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(),Name="Test")
length = ifcopenshell.api.unit.add_si_unit(file,unit_type="LENGTHUNIT")
ifcopenshell.api.unit.assign_unit(file,units=[length])
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
length = ifcopenshell.api.unit.add_si_unit(file, unit_type="LENGTHUNIT")
ifcopenshell.api.unit.assign_unit(file, units=[length])
geometric_representation_context = ifcopenshell.api.context.add_context(file, context_type="Model")
axis_model_representation_subcontext = ifcopenshell.api.context.add_context(
file,
@@ -37,13 +38,13 @@ def _test_horizontal() -> ifcopenshell.file:
)
# creates an IfcAlignment with an IfcAlignmentHorizontal layout containing only the zero length segment
ali = ifcopenshell.api.alignment.create(file,"A1")
ali = ifcopenshell.api.alignment.create(file, "A1")
# append a segment to the horizontal layout
horizontal_alignment = ifcopenshell.api.alignment.get_horizontal_layout(ali)
curve = ifcopenshell.api.alignment.get_curve(horizontal_alignment)
assert curve == None # for single horizontal, geometric representation is on IfcAlignment
assert curve == None # for single horizontal, geometric representation is on IfcAlignment
curve = ifcopenshell.api.alignment.get_curve(ali)
assert curve.is_a("IfcCompositeCurve")
assert len(curve.Segments) == 1
@@ -60,14 +61,14 @@ def _test_horizontal() -> ifcopenshell.file:
GravityCenterLineHeight=None,
PredefinedType="LINE",
)
end = ifcopenshell.api.alignment.create_layout_segment(file,horizontal_alignment,design_parameters)
end = ifcopenshell.api.alignment.create_layout_segment(file, horizontal_alignment, design_parameters)
assert len(horizontal_alignment.IsNestedBy[0].RelatedObjects) == 2
x = end[0,3]
y = end[1,3]
z = end[2,3]
x = end[0, 3]
y = end[1, 3]
z = end[2, 3]
assert x == 100.0
assert y == 0.0
assert z == 0.0
@@ -76,13 +77,12 @@ def _test_horizontal() -> ifcopenshell.file:
assert curve.is_a("IfcCompositeCurve")
assert len(curve.Segments) == 2
design_parameters = file.create_entity(
type="IfcAlignmentHorizontalSegment",
StartTag=None,
EndTag=None,
StartPoint=file.createIfcCartesianPoint(Coordinates=((x.item(), y.item()))),
StartDirection=math.pi/6,
StartDirection=math.pi / 6,
StartRadiusOfCurvature=0.0,
EndRadiusOfCurvature=0.0,
SegmentLength=50.0,
@@ -90,15 +90,15 @@ def _test_horizontal() -> ifcopenshell.file:
PredefinedType="LINE",
)
end = ifcopenshell.api.alignment.create_layout_segment(file,horizontal_alignment,design_parameters)
end = ifcopenshell.api.alignment.create_layout_segment(file, horizontal_alignment, design_parameters)
assert len(horizontal_alignment.IsNestedBy[0].RelatedObjects) == 3
x = end[0,3]
y = end[1,3]
z = end[2,3]
assert x == 100.0 + 50.0*math.cos(math.pi/6)
assert y == 50.0*math.sin(math.pi/6)
x = end[0, 3]
y = end[1, 3]
z = end[2, 3]
assert x == 100.0 + 50.0 * math.cos(math.pi / 6)
assert y == 50.0 * math.sin(math.pi / 6)
assert z == 0.0
curve = ifcopenshell.api.alignment.get_curve(ali)
@@ -110,9 +110,9 @@ def _test_horizontal() -> ifcopenshell.file:
def _test_horizontal_vertical():
file = ifcopenshell.file(schema="IFC4X3_ADD2")
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(),Name="Test")
length = ifcopenshell.api.unit.add_si_unit(file,unit_type="LENGTHUNIT")
ifcopenshell.api.unit.assign_unit(file,units=[length])
project = file.createIfcProject(GlobalId=ifcopenshell.guid.new(), Name="Test")
length = ifcopenshell.api.unit.add_si_unit(file, unit_type="LENGTHUNIT")
ifcopenshell.api.unit.assign_unit(file, units=[length])
geometric_representation_context = ifcopenshell.api.context.add_context(file, context_type="Model")
axis_model_representation_subcontext = ifcopenshell.api.context.add_context(
file,
@@ -123,7 +123,7 @@ def _test_horizontal_vertical():
)
# creates an IfcAlignment with an IfcAlignmentHorizontal layout containing only the zero length segment
ali = ifcopenshell.api.alignment.create(file,"A1",True)
ali = ifcopenshell.api.alignment.create(file, "A1", True)
# append a segment to the horizontal layout
horizontal_alignment = ifcopenshell.api.alignment.get_horizontal_layout(ali)
@@ -154,53 +154,53 @@ def _test_horizontal_vertical():
GravityCenterLineHeight=None,
PredefinedType="LINE",
)
end = ifcopenshell.api.alignment.create_layout_segment(file,horizontal_alignment,design_parameters)
end = ifcopenshell.api.alignment.create_layout_segment(file, horizontal_alignment, design_parameters)
basis_curve = ifcopenshell.api.alignment.get_basis_curve(ali)
assert basis_curve.is_a("IfcCompositeCurve")
assert len(basis_curve.Segments) == 2
design_parameters = file.createIfcAlignmentVerticalSegment(
StartDistAlong=0.0,
HorizontalLength=50.0,
StartHeight=20.0,
StartGradient = 1./100.,
EndGradient = 1./100.,
PredefinedType="CONSTANTGRADIENT"
)
end = ifcopenshell.api.alignment.create_layout_segment(file,vertical_alignment,design_parameters)
StartGradient=1.0 / 100.0,
EndGradient=1.0 / 100.0,
PredefinedType="CONSTANTGRADIENT",
)
end = ifcopenshell.api.alignment.create_layout_segment(file, vertical_alignment, design_parameters)
assert len(vertical_alignment.IsNestedBy[0].RelatedObjects) == 2
x = end[0,3]
y = end[1,3]
z = end[2,3]
assert x == 50.
x = end[0, 3]
y = end[1, 3]
z = end[2, 3]
assert x == 50.0
assert y == 20.5
assert z == 0.0
dx = end[0,0]
dy = end[1,0]
gradient = dy/dx
dx = end[0, 0]
dy = end[1, 0]
gradient = dy / dx
design_parameters = file.createIfcAlignmentVerticalSegment(
StartDistAlong=50.0,
HorizontalLength=50.0,
StartHeight=y.item(),
StartGradient = -gradient,
EndGradient = -gradient,
PredefinedType="CONSTANTGRADIENT"
)
end = ifcopenshell.api.alignment.create_layout_segment(file,vertical_alignment,design_parameters)
StartGradient=-gradient,
EndGradient=-gradient,
PredefinedType="CONSTANTGRADIENT",
)
end = ifcopenshell.api.alignment.create_layout_segment(file, vertical_alignment, design_parameters)
assert len(vertical_alignment.IsNestedBy[0].RelatedObjects) == 3
x = end[0,3]
y = end[1,3]
z = end[2,3]
assert x == 100.
assert y == 20.
x = end[0, 3]
y = end[1, 3]
z = end[2, 3]
assert x == 100.0
assert y == 20.0
assert z == 0.0
basis_curve = ifcopenshell.api.alignment.get_basis_curve(ali)
@@ -216,60 +216,62 @@ def _test_horizontal_vertical2(file: ifcopenshell.file):
vertical_alignment = ifcopenshell.api.alignment.get_vertical_layout(ali)
assert vertical_alignment == None
vertical_alignment = ifcopenshell.api.alignment.add_vertical_layout(file,ali)
vertical_alignment = ifcopenshell.api.alignment.add_vertical_layout(file, ali)
design_parameters = file.createIfcAlignmentVerticalSegment(
StartDistAlong=0.0,
HorizontalLength=50.0,
StartHeight=20.0,
StartGradient = 1./100.,
EndGradient = 1./100.,
PredefinedType="CONSTANTGRADIENT"
)
end = ifcopenshell.api.alignment.create_layout_segment(file,vertical_alignment,design_parameters)
StartGradient=1.0 / 100.0,
EndGradient=1.0 / 100.0,
PredefinedType="CONSTANTGRADIENT",
)
end = ifcopenshell.api.alignment.create_layout_segment(file, vertical_alignment, design_parameters)
assert len(vertical_alignment.IsNestedBy[0].RelatedObjects) == 2
x = end[0,3]
y = end[1,3]
z = end[2,3]
assert x == 50.
x = end[0, 3]
y = end[1, 3]
z = end[2, 3]
assert x == 50.0
assert y == 20.5
assert z == 0.0
dx = end[0,0]
dy = end[1,0]
gradient = dy/dx
dx = end[0, 0]
dy = end[1, 0]
gradient = dy / dx
design_parameters = file.createIfcAlignmentVerticalSegment(
StartDistAlong=50.0,
HorizontalLength=50.0,
StartHeight=y.item(),
StartGradient = -gradient,
EndGradient = -gradient,
PredefinedType="CONSTANTGRADIENT"
)
end = ifcopenshell.api.alignment.create_layout_segment(file,vertical_alignment,design_parameters)
StartGradient=-gradient,
EndGradient=-gradient,
PredefinedType="CONSTANTGRADIENT",
)
end = ifcopenshell.api.alignment.create_layout_segment(file, vertical_alignment, design_parameters)
assert len(vertical_alignment.IsNestedBy[0].RelatedObjects) == 3
x = end[0,3]
y = end[1,3]
z = end[2,3]
assert x == 100.
assert y == 20.
x = end[0, 3]
y = end[1, 3]
z = end[2, 3]
assert x == 100.0
assert y == 20.0
assert z == 0.0
curve = ifcopenshell.api.alignment.get_curve(ali)
assert curve.is_a("IfcGradientCurve")
assert len(curve.Segments) == 3
def test_append_segment():
file = _test_horizontal()
_test_horizontal_vertical()
_test_horizontal_vertical2(file)
test_append_segment()
test_append_segment()