First Commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
# IfcOpenShell - IFC toolkit and geometry engine
|
||||
# Copyright (C) 2022 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/>.
|
||||
|
||||
"""Manages grid and grid axes
|
||||
|
||||
A grid in IFC may contain two or more axes running in two or more directions.
|
||||
"""
|
||||
|
||||
from .. import wrap_usecases
|
||||
from .create_axis_curve import create_axis_curve
|
||||
from .create_grid_axis import create_grid_axis
|
||||
from .remove_grid_axis import remove_grid_axis
|
||||
|
||||
wrap_usecases(__path__, __name__)
|
||||
|
||||
__all__ = [
|
||||
"create_axis_curve",
|
||||
"create_grid_axis",
|
||||
"remove_grid_axis",
|
||||
]
|
||||
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,92 @@
|
||||
# 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/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import numpy as np
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.util.placement
|
||||
import ifcopenshell.util.unit
|
||||
from ifcopenshell.util.shape_builder import (
|
||||
V,
|
||||
VectorType,
|
||||
ifc_safe_vector_type,
|
||||
np_apply_matrix,
|
||||
)
|
||||
|
||||
|
||||
def create_axis_curve(
|
||||
file: ifcopenshell.file,
|
||||
*,
|
||||
p1: VectorType,
|
||||
p2: VectorType,
|
||||
grid_axis: ifcopenshell.entity_instance,
|
||||
is_si: bool = True,
|
||||
) -> None:
|
||||
"""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.
|
||||
|
||||
Points are provided as 3D coordinates in world space.
|
||||
During axis creation, the coordinates will be localized relative to IfcGrid
|
||||
and saved as 2D.
|
||||
|
||||
:param p1: The first point of the grid axis
|
||||
:param p2: The second point of the grid axis
|
||||
:param grid_axis: The IfcGridAxis element to add geometry to.
|
||||
:param is_si: If true, the points are in meters, not project units
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
# A pretty standard rectangular grid, with only two axes.
|
||||
grid = ifcopenshell.api.root.create_entity(model, ifc_class="IfcGrid")
|
||||
axis_a = ifcopenshell.api.grid.create_grid_axis(model,
|
||||
axis_tag="A", uvw_axes="UAxes", grid=grid)
|
||||
axis_1 = ifcopenshell.api.grid.create_grid_axis(model,
|
||||
axis_tag="1", uvw_axes="VAxes", grid=grid)
|
||||
|
||||
# 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)
|
||||
"""
|
||||
existing_curve = grid_axis.AxisCurve
|
||||
points = V([p1, p2])
|
||||
if is_si:
|
||||
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(file)
|
||||
points /= unit_scale
|
||||
|
||||
grid = next(i for i in file.get_inverse(grid_axis) if i.is_a("IfcGrid"))
|
||||
grid_matrix_i = np.linalg.inv(ifcopenshell.util.placement.get_local_placement(grid.ObjectPlacement))
|
||||
p1, p2 = ifc_safe_vector_type(np_apply_matrix(points, grid_matrix_i))
|
||||
grid_axis.AxisCurve = file.create_entity(
|
||||
"IfcPolyline",
|
||||
(
|
||||
file.create_entity("IfcCartesianPoint", p1[:2]),
|
||||
file.create_entity("IfcCartesianPoint", p2[:2]),
|
||||
),
|
||||
)
|
||||
|
||||
if existing_curve:
|
||||
ifcopenshell.util.element.remove_deep2(file, existing_curve)
|
||||
@@ -0,0 +1,78 @@
|
||||
# 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/>.
|
||||
from typing import Literal
|
||||
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
def create_grid_axis(
|
||||
file: ifcopenshell.file,
|
||||
grid: ifcopenshell.entity_instance,
|
||||
axis_tag: str = "A",
|
||||
same_sense: bool = True,
|
||||
uvw_axes: Literal["UAxes", "VAxes", "WAxes"] = "UAxes",
|
||||
) -> ifcopenshell.entity_instance:
|
||||
"""Adds a new grid axis to a grid
|
||||
|
||||
An IFC grid will typically have a minimum of two axes which will be
|
||||
perpendicular to one another. Grids may be rectangular (typically
|
||||
perpendicular lines), radial (where one set of axes is a circle and the
|
||||
other is a line), or triangular (three sets of axes, each at a different
|
||||
angle to one another).
|
||||
|
||||
For a simple rectangular grid, the "UAxes" are a set of one or more
|
||||
horizontal axes, which are typically labeled with the convention of A,
|
||||
B, C, etc. The "VAxes" is another set of one or more vertical axes,
|
||||
typically labeled with the convention of 1, 2, 3, etc. These axes are
|
||||
horizontal or vertical relative to project north.
|
||||
|
||||
For a radial grid, the "UAxes" are straight lines, typically radiating
|
||||
from a central point. The "VAxes" are circular perimeters, with the
|
||||
center of these circles being the same central point.
|
||||
|
||||
For a triangular grid, the UAxes, VAxes, and WAxes are all sets of one
|
||||
or more straight lines.
|
||||
|
||||
:param axis_tag: The name of the axis, that would typically be labeled
|
||||
on drawings or described on site during coordination, such as A, B,
|
||||
C, 1, 2, 3, etc. Defaults to "A".
|
||||
:param same_sense: Determines whether the direction of the axis's line
|
||||
is reversed. True means the direction the geometry is defined in
|
||||
represents the direction of the axis. False means the direction is
|
||||
reversed. Leave as True if unsure. Defaults to "True".
|
||||
:param uvw_axes: Choose from "UAxes", "VAxes" or "WAxes" depending on
|
||||
which set of axes the new axis you are adding should belong to.
|
||||
Defaults to "UAxes".
|
||||
:param grid: The IfcGrid you are adding the axis to.
|
||||
:return: The newly created IfcGridAxis
|
||||
|
||||
Example:
|
||||
|
||||
# A pretty standard rectangular grid, with only two axes.
|
||||
grid = ifcopenshell.api.root.create_entity(model, ifc_class="IfcGrid")
|
||||
axis_a = ifcopenshell.api.grid.create_grid_axis(model,
|
||||
axis_tag="A", uvw_axes="UAxes", grid=grid)
|
||||
axis_1 = ifcopenshell.api.grid.create_grid_axis(model,
|
||||
axis_tag="1", uvw_axes="VAxes", grid=grid)
|
||||
"""
|
||||
|
||||
element = file.create_entity("IfcGridAxis", **{"AxisTag": axis_tag, "SameSense": same_sense})
|
||||
axes = list(getattr(grid, uvw_axes) or [])
|
||||
axes.append(element)
|
||||
setattr(grid, uvw_axes, axes)
|
||||
return element
|
||||
@@ -0,0 +1,46 @@
|
||||
# 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/>.
|
||||
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
def remove_grid_axis(file: ifcopenshell.file, axis: ifcopenshell.entity_instance) -> None:
|
||||
"""Removes a grid axis from a grid
|
||||
|
||||
:param axis: The IfcGridAxis you want to remove.
|
||||
:return: None
|
||||
|
||||
Example:
|
||||
|
||||
# A pretty standard rectangular grid, with only two axes.
|
||||
grid = ifcopenshell.api.root.create_entity(model, ifc_class="IfcGrid")
|
||||
axis_a = ifcopenshell.api.grid.create_grid_axis(model,
|
||||
axis_tag="A", uvw_axes="UAxes", grid=grid)
|
||||
axis_1 = ifcopenshell.api.grid.create_grid_axis(model,
|
||||
axis_tag="1", uvw_axes="VAxes", grid=grid)
|
||||
|
||||
# Let's create a third so we can remove it later
|
||||
axis_2 = ifcopenshell.api.grid.create_grid_axis(model,
|
||||
axis_tag="2", uvw_axes="VAxes", grid=grid)
|
||||
|
||||
# Let's remove it!
|
||||
ifcopenshell.api.grid.remove_grid_axis(model, axis=axis_2)
|
||||
"""
|
||||
axis_curve = axis.AxisCurve
|
||||
file.remove(axis)
|
||||
ifcopenshell.util.element.remove_deep2(file, axis_curve)
|
||||
Reference in New Issue
Block a user