Files
IfcOpenShell/src/ifcopenshell-python/ifcopenshell/api/alignment/update_end_point.py
T
Stephen Boddy d5e890bccd Fix ty-ios type-check errors (ifcopenshell-python side)
poe ty's sequence only reaches ty-ios once ty-bonsai passes, so these
never surfaced until now:

- util/alignment.py: drop the stale `include_referent=False` kwarg from
  add_zero_length_segment() - that parameter was removed from the function's
  signature in 45ea5eb07 but this caller in a different file was missed,
  leaving a latent TypeError if this code path is ever exercised.
- ifcopenshell_wrapper.pyi: add the optional trailing `logger` parameter to
  parse_ifcxml/open/construct_iterator*, matching the real SWIG signatures
  in src/ifcwrap/*.i (all declare `Logger& logger = Logger::Root()`) that
  the hand-maintained stub never picked up.
- ifcopenshell/__init__.py: remove a stale `ty: ignore[unknown-argument]`
  comment that ty confirms is no longer suppressing anything.
- assign_cost_item_quantity.py: OPERATORS mixes 2-arg binary operators with
  the 1-arg `operator.neg` (for ast.USub), but FormulaEvaluator has no
  visit_UnaryOp so USub can never reach this lookup via visit_BinOp.
  Suppressed at the call site rather than touching the dict, since this
  looks like scaffolding for unary-minus support rather than dead code.
- Explicit submodule imports (ifcopenshell.geom / api.alignment / util.unit
  / api.aggregate / api.context / api.spatial) added where accessed but
  only reachable by accident of import order.
2026-07-10 22:19:56 +01:00

92 lines
3.3 KiB
Python

# 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 numpy as np
import ifcopenshell
import ifcopenshell.api.alignment
import ifcopenshell.util.placement
from ifcopenshell import entity_instance
def update_end_point(file: ifcopenshell.file, curve: entity_instance):
"""
Updates the IfcGradientCurve.EndPoint and IfcSegmentedReferenceCurve.EndPoint.
If the curve does not have a zero length segment, one is added. The EndPoint is then updated to match the placement of the zero length segment.
:param curve: The gradient curve or segmented reference curve
:return: None
"""
expected_types = ["IfcGradientCurve", "IfcSegmentedReferenceCurve"]
if not curve.is_a() in expected_types:
raise TypeError(
f"Expected entity type to be one of {[_ for _ in expected_types]}, instead received '{curve.is_a()}"
)
if not ifcopenshell.api.alignment.has_zero_length_segment(curve):
ifcopenshell.api.alignment.add_zero_length_segment(file, curve)
zero_length_segment = curve.Segments[-1]
if not curve.EndPoint:
if curve.is_a("IfcGradientCurve"):
curve.EndPoint = file.createIfcAxis2Placement2D(
Location=file.createIfcCartesianPoint((0.0, 0.0)),
RefDirection=file.createIfcDirection((1.0, 0.0)),
)
else:
curve.EndPoint = file.createIfcAxis2Placement3D(
Location=file.createIfcCartesianPoint((0.0, 0.0, 0.0)),
RefDirection=file.createIfcDirection((1.0, 0.0, 0.0)),
Axis=file.createIfcDirection((0.0, 0.0, 1.0)),
)
p = np.array(ifcopenshell.util.placement.get_axis2placement(zero_length_segment.Placement))
x = float(p[0, 3])
y = float(p[1, 3])
z = float(p[2, 3])
rx = float(p[0, 0])
ry = float(p[1, 0])
rz = float(p[2, 0])
ax = float(p[0, 2])
ay = float(p[1, 2])
az = float(p[2, 2])
if curve.is_a("IfcGradientCurve"):
curve.EndPoint.Location.Coordinates = (x, y)
if not curve.EndPoint.RefDirection:
curve.EndPoint.RefDirection = file.createIfcDirection((1.0, 0.0))
curve.EndPoint.RefDirection.DirectionRatios = (rx, ry)
else:
curve.EndPoint.Location.Coordinates = (x, y, z)
if not curve.EndPoint.RefDirection:
curve.EndPoint.RefDirection = file.createIfcDirection((1.0, 0.0, 0.0))
if not curve.EndPoint.Axis:
curve.EndPoint.Axis = file.createIfcDirection((0.0, 0.0, 1.0))
curve.EndPoint.RefDirection.DirectionRatios = (rx, ry, rz)
curve.EndPoint.Axis.DirectionRatios = (ax, ay, az)