Files
IfcOpenShell/src/ifcopenshell-python/test/api/alignment/test_add_vertical_alignment.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
3.7 KiB
Python
Raw Normal View History

2025-03-14 07:31:50 -07:00
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2025 Thomas Krijnen <thomas@aecgeeks.com>
#
# This file is part of IfcOpenShell.
#
# IfcOpenShell is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IfcOpenShell is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import pytest
import ifcopenshell.api.alignment
import ifcopenshell.api.context
2025-07-10 11:30:09 +05:00
import ifcopenshell.api.unit
2025-03-14 07:31:50 -07:00
2025-07-08 10:09:14 -07:00
def test_add_vertical_alignment():
file = ifcopenshell.file(schema="IFC4X3")
2025-07-09 13:47:32 +05:00
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])
2025-03-14 07:31:50 -07:00
geometric_representation_context = ifcopenshell.api.context.add_context(file, context_type="Model")
2025-07-09 13:47:32 +05:00
alignment = ifcopenshell.api.alignment.create(file, "A1", include_vertical=False)
2025-03-14 07:31:50 -07:00
assert len(alignment.IsDecomposedBy) == 0 # no child alignments
2025-07-08 10:09:14 -07:00
assert len(alignment.IsNestedBy) == 1 # one nest
assert len(alignment.IsNestedBy[0].RelatedObjects) == 2 # nesting IfcReferent, IfcAlignmentHorizontal
assert alignment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent")
assert alignment.IsNestedBy[0].RelatedObjects[1].is_a("IfcAlignmentHorizontal")
curve = ifcopenshell.api.alignment.get_curve(alignment)
assert curve.is_a("IfcCompositeCurve")
2025-07-09 13:47:32 +05:00
vertical_layout = ifcopenshell.api.alignment.add_vertical_layout(file, alignment)
2025-03-14 07:31:50 -07:00
assert len(alignment.IsDecomposedBy) == 0 # no child alignments
2025-07-08 10:09:14 -07:00
assert len(alignment.IsNestedBy) == 1 # one nest
2025-07-09 13:47:32 +05:00
assert (
len(alignment.IsNestedBy[0].RelatedObjects) == 3
) # nesting IfcReferent, IfcAlignmentHorizontal, IfcAlignmentVertical
2025-07-08 10:09:14 -07:00
assert alignment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent")
assert alignment.IsNestedBy[0].RelatedObjects[1].is_a("IfcAlignmentHorizontal")
assert alignment.IsNestedBy[0].RelatedObjects[2].is_a("IfcAlignmentVertical")
curve = ifcopenshell.api.alignment.get_curve(alignment)
assert curve.is_a("IfcGradientCurve")
# add a second vertical alignment
2025-07-09 13:47:32 +05:00
vertical_layout = ifcopenshell.api.alignment.add_vertical_layout(file, alignment)
2025-03-14 07:31:50 -07:00
assert len(alignment.IsDecomposedBy) == 1 # 1 IfcRelAggreates relationship for the child algiments
assert (
len(alignment.IsDecomposedBy[0].RelatedObjects) == 2
) # two child alignments, one for the first vertical and one for the vertical just added
2025-07-08 10:09:14 -07:00
2025-03-14 07:31:50 -07:00
for child_alignment in alignment.IsDecomposedBy[0].RelatedObjects:
assert child_alignment.is_a("IfcAlignment")
assert len(child_alignment.IsNestedBy) == 1 # one nesting relationship for the IfcAlignmentVertical
assert len(child_alignment.IsNestedBy[0].RelatedObjects) == 1 # The IfcAlignmentVertical
assert child_alignment.IsNestedBy[0].RelatedObjects[0].is_a("IfcAlignmentVertical")
2025-07-08 10:09:14 -07:00
2025-03-14 07:31:50 -07:00
assert len(alignment.IsNestedBy) == 1 # 1 nesting relationsip for the alignments
2025-07-08 10:09:14 -07:00
assert len(alignment.IsNestedBy[0].RelatedObjects) == 2 # nesting IfcReferent and IfcAlignmentHorizontal
assert alignment.IsNestedBy[0].RelatedObjects[0].is_a("IfcReferent")
assert alignment.IsNestedBy[0].RelatedObjects[1].is_a("IfcAlignmentHorizontal")
2025-07-09 13:47:32 +05:00
test_add_vertical_alignment()