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/>.
|
|
|
|
|
|
2021-02-20 17:13:36 +11:00
|
|
|
import ifcopenshell
|
|
|
|
|
import ifcopenshell.util.unit
|
|
|
|
|
import ifcopenshell.util.placement
|
|
|
|
|
from mathutils import Matrix # For now, we depend on Blender
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Usecase:
|
2022-12-05 17:10:22 +11:00
|
|
|
def __init__(self, file, axis_curve=None, grid_axis=None):
|
|
|
|
|
"""Adds curve geometry to a grid axis to represent the axis extents
|
|
|
|
|
|
|
|
|
|
This currently depends on the Blender geometry kernel to function.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
:param axis_curve: The Blender object that contains a mesh data block with a
|
|
|
|
|
single edge.
|
|
|
|
|
:type axis_curve: bpy.types.Object
|
|
|
|
|
:param grid_axis: The IfcGridAxis element to add geometry to.
|
|
|
|
|
:type grid_axis: ifcopenshell.entity_instance.entity_instance
|
|
|
|
|
:return: None
|
|
|
|
|
:rtype: None
|
|
|
|
|
|
2023-01-10 10:16:28 +11:00
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code:: python
|
2022-12-05 17:10:22 +11:00
|
|
|
|
|
|
|
|
# A pretty standard rectangular grid, with only two axes.
|
|
|
|
|
grid = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcGrid")
|
|
|
|
|
axis_a = ifcopenshell.api.run("grid.create_grid_axis", model,
|
|
|
|
|
axis_tag="A", uvw_axes="UAxes", grid=grid)
|
|
|
|
|
axis_1 = ifcopenshell.api.run("grid.create_grid_axis", model,
|
|
|
|
|
axis_tag="1", uvw_axes="VAxes", grid=grid)
|
|
|
|
|
|
|
|
|
|
# Assume you have these Blender objects in your active Blender session
|
|
|
|
|
obj1 = bpy.data.objects.get("AxisA")
|
|
|
|
|
obj2 = bpy.data.objects.get("Axis1")
|
|
|
|
|
ifcopenshell.api.run("grid.create_axis_curve", model, axis_curve=obj1, grid_axis=axis_a)
|
|
|
|
|
ifcopenshell.api.run("grid.create_axis_curve", model, axis_curve=obj2, grid_axis=axis_1)
|
|
|
|
|
"""
|
2021-02-20 17:13:36 +11:00
|
|
|
self.file = file
|
|
|
|
|
self.settings = {
|
2022-12-05 17:10:22 +11:00
|
|
|
"axis_curve": axis_curve, # A Blender object
|
|
|
|
|
"grid_axis": grid_axis,
|
2021-02-20 17:13:36 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def execute(self):
|
2021-05-15 12:06:44 +10:00
|
|
|
existing_curve = self.settings["grid_axis"].AxisCurve
|
|
|
|
|
if existing_curve and len(self.file.get_inverse(existing_curve)) == 1:
|
|
|
|
|
ifcopenshell.util.element.remove_deep(self.file, existing_curve)
|
|
|
|
|
self.file.remove(existing_curve)
|
2021-02-20 17:13:36 +11:00
|
|
|
|
|
|
|
|
self.settings["unit_scale"] = ifcopenshell.util.unit.calculate_unit_scale(self.file)
|
|
|
|
|
grid = [i for i in self.file.get_inverse(self.settings["grid_axis"]) if i.is_a("IfcGrid")][0]
|
|
|
|
|
points = [
|
|
|
|
|
Matrix(ifcopenshell.util.placement.get_local_placement(grid.ObjectPlacement)).inverted()
|
2021-05-28 10:59:20 +10:00
|
|
|
@ (self.settings["axis_curve"].matrix_world @ v.co)
|
|
|
|
|
for v in self.settings["axis_curve"].data.vertices[0:2]
|
2021-02-20 17:13:36 +11:00
|
|
|
]
|
|
|
|
|
self.settings["grid_axis"].AxisCurve = self.file.createIfcPolyline(
|
|
|
|
|
[
|
2023-07-12 11:41:47 +10:00
|
|
|
self.create_cartesian_point(points[0][0], points[0][1]),
|
|
|
|
|
self.create_cartesian_point(points[1][0], points[1][1]),
|
2021-02-20 17:13:36 +11:00
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def create_cartesian_point(self, x, y, z=None):
|
|
|
|
|
x = self.convert_si_to_unit(x)
|
|
|
|
|
y = self.convert_si_to_unit(y)
|
|
|
|
|
if z is None:
|
|
|
|
|
return self.file.createIfcCartesianPoint((x, y))
|
|
|
|
|
z = self.convert_si_to_unit(z)
|
|
|
|
|
return self.file.createIfcCartesianPoint((x, y, z))
|
|
|
|
|
|
|
|
|
|
def convert_si_to_unit(self, co):
|
|
|
|
|
return co / self.settings["unit_scale"]
|