2022-01-19 12:18:33 +11:00
|
|
|
# IfcOpenShell - IFC toolkit and geometry engine
|
|
|
|
|
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.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/>.
|
|
|
|
|
|
2024-05-15 10:55:29 +05:00
|
|
|
from __future__ import annotations
|
2021-02-20 17:13:36 +11:00
|
|
|
import ifcopenshell
|
2024-05-15 10:55:29 +05:00
|
|
|
import ifcopenshell.util.element
|
2021-02-20 17:13:36 +11:00
|
|
|
import ifcopenshell.util.unit
|
|
|
|
|
import ifcopenshell.util.placement
|
2025-02-16 08:20:59 +11:00
|
|
|
import numpy as np
|
2021-02-20 17:13:36 +11:00
|
|
|
|
|
|
|
|
|
2024-05-15 10:55:29 +05:00
|
|
|
def create_axis_curve(
|
2025-02-16 08:20:59 +11:00
|
|
|
file: ifcopenshell.file,
|
|
|
|
|
*,
|
|
|
|
|
p1: np.ndarray,
|
|
|
|
|
p2: np.ndarray,
|
|
|
|
|
grid_axis: ifcopenshell.entity_instance,
|
|
|
|
|
is_si: bool = True,
|
2024-05-15 10:55:29 +05:00
|
|
|
) -> None:
|
2024-05-06 14:35:39 +10:00
|
|
|
"""Adds curve geometry to a grid axis to represent the axis extents
|
|
|
|
|
|
|
|
|
|
An IFC grid will have a minimum of two axes (typically perpendicular). Each
|
|
|
|
|
axis will then have a line which represents the extents of the axis.
|
2022-12-05 17:10:22 +11:00
|
|
|
|
2025-02-16 08:20:59 +11:00
|
|
|
:param p1: The first point of the grid axis
|
|
|
|
|
:param p2: The second point of the grid axis
|
2024-05-06 14:35:39 +10:00
|
|
|
:param grid_axis: The IfcGridAxis element to add geometry to.
|
2025-02-16 08:20:59 +11:00
|
|
|
:param is_si: If true, the points are in meters, not project units
|
2022-12-05 17:10:22 +11:00
|
|
|
|
2024-05-06 14:35:39 +10:00
|
|
|
Example:
|
2022-12-05 17:10:22 +11:00
|
|
|
|
2024-05-06 14:35:39 +10:00
|
|
|
.. code:: python
|
2023-01-10 10:16:28 +11:00
|
|
|
|
2024-05-06 14:35:39 +10:00
|
|
|
# A pretty standard rectangular grid, with only two axes.
|
2024-06-28 12:36:31 +10:00
|
|
|
grid = ifcopenshell.api.root.create_entity(model, ifc_class="IfcGrid")
|
|
|
|
|
axis_a = ifcopenshell.api.grid.create_grid_axis(model,
|
2024-05-06 14:35:39 +10:00
|
|
|
axis_tag="A", uvw_axes="UAxes", grid=grid)
|
2024-06-28 12:36:31 +10:00
|
|
|
axis_1 = ifcopenshell.api.grid.create_grid_axis(model,
|
2024-05-06 14:35:39 +10:00
|
|
|
axis_tag="1", uvw_axes="VAxes", grid=grid)
|
2022-12-05 17:10:22 +11:00
|
|
|
|
2025-02-16 08:20:59 +11:00
|
|
|
# By convention, alphabetic grids are horizontal, and numeric are vertical
|
|
|
|
|
ifcopenshell.api.grid.create_axis_curve(
|
|
|
|
|
model, p1=np.array((0., 0., 0.)), p2=np.array((10., 0., 0.)), grid_axis=axis_a)
|
|
|
|
|
ifcopenshell.api.grid.create_axis_curve(
|
|
|
|
|
model, p1=np.array((0., 0., 0.)), p2=np.array((0., 10., 0.)), grid_axis=axis_1)
|
2024-05-06 14:35:39 +10:00
|
|
|
"""
|
2025-02-16 08:20:59 +11:00
|
|
|
existing_curve = grid_axis.AxisCurve
|
|
|
|
|
|
|
|
|
|
if is_si:
|
|
|
|
|
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(file)
|
|
|
|
|
p1 /= unit_scale
|
|
|
|
|
p2 /= unit_scale
|
|
|
|
|
|
|
|
|
|
grid = [i for i in file.get_inverse(grid_axis) if i.is_a("IfcGrid")][0]
|
|
|
|
|
grid_matrix_i = np.linalg.inv(ifcopenshell.util.placement.get_local_placement(grid.ObjectPlacement))
|
|
|
|
|
grid_axis.AxisCurve = file.createIfcPolyline(
|
|
|
|
|
(
|
|
|
|
|
file.createIfcCartesianPoint((grid_matrix_i @ p1).tolist()),
|
|
|
|
|
file.createIfcCartesianPoint((grid_matrix_i @ p2).tolist()),
|
2021-02-20 17:13:36 +11:00
|
|
|
)
|
2025-02-16 08:20:59 +11:00
|
|
|
)
|
2021-02-20 17:13:36 +11:00
|
|
|
|
2025-02-16 08:20:59 +11:00
|
|
|
if existing_curve:
|
|
|
|
|
ifcopenshell.util.element.remove_deep2(file, existing_curve)
|