mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -15,3 +15,7 @@
|
||||
#
|
||||
# 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 .create_axis_curve import create_axis_curve
|
||||
from .create_grid_axis import create_grid_axis
|
||||
from .remove_grid_axis import remove_grid_axis
|
||||
|
||||
@@ -22,46 +22,49 @@ import ifcopenshell.util.placement
|
||||
from mathutils import Matrix # For now, we depend on Blender
|
||||
|
||||
|
||||
def create_axis_curve(file, axis_curve=None, grid_axis=None) -> 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
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
# 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)
|
||||
"""
|
||||
usecase = Usecase()
|
||||
usecase.file = file
|
||||
usecase.settings = {
|
||||
"axis_curve": axis_curve, # A Blender object
|
||||
"grid_axis": grid_axis,
|
||||
}
|
||||
return usecase.execute()
|
||||
|
||||
|
||||
class Usecase:
|
||||
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
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
# 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)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"axis_curve": axis_curve, # A Blender object
|
||||
"grid_axis": grid_axis,
|
||||
}
|
||||
|
||||
def execute(self):
|
||||
existing_curve = self.settings["grid_axis"].AxisCurve
|
||||
if existing_curve and len(self.file.get_inverse(existing_curve)) == 1:
|
||||
|
||||
@@ -17,69 +17,66 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, axis_tag=None, same_sense=None, uvw_axes=None, grid=None):
|
||||
"""Adds a new grid axis to a grid
|
||||
def create_grid_axis(file, axis_tag=None, same_sense=None, uvw_axes=None, grid=None) -> None:
|
||||
"""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).
|
||||
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 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 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.
|
||||
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".
|
||||
:type axis_tag: str, optional
|
||||
: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".
|
||||
:type same_sense: bool, optional
|
||||
: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".
|
||||
:type uvw_axes: str, optional
|
||||
:param grid: The IfcGrid you are adding the axis to.
|
||||
:type grid: ifcopenshell.entity_instance
|
||||
:return: The newly created IfcGridAxis
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
: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".
|
||||
:type axis_tag: str, optional
|
||||
: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".
|
||||
:type same_sense: bool, optional
|
||||
: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".
|
||||
:type uvw_axes: str, optional
|
||||
:param grid: The IfcGrid you are adding the axis to.
|
||||
:type grid: ifcopenshell.entity_instance
|
||||
:return: The newly created IfcGridAxis
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
# 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)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"axis_tag": axis_tag or "A",
|
||||
"same_sense": same_sense or True,
|
||||
"uvw_axes": uvw_axes or "UAxes", # Choose which axes
|
||||
"grid": grid,
|
||||
}
|
||||
# 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)
|
||||
"""
|
||||
settings = {
|
||||
"axis_tag": axis_tag or "A",
|
||||
"same_sense": same_sense or True,
|
||||
"uvw_axes": uvw_axes or "UAxes", # Choose which axes
|
||||
"grid": grid,
|
||||
}
|
||||
|
||||
def execute(self):
|
||||
element = self.file.create_entity(
|
||||
"IfcGridAxis", **{"AxisTag": self.settings["axis_tag"], "SameSense": self.settings["same_sense"]}
|
||||
)
|
||||
axes = list(getattr(self.settings["grid"], self.settings["uvw_axes"]) or [])
|
||||
axes.append(element)
|
||||
setattr(self.settings["grid"], self.settings["uvw_axes"], axes)
|
||||
return element
|
||||
element = file.create_entity(
|
||||
"IfcGridAxis", **{"AxisTag": settings["axis_tag"], "SameSense": settings["same_sense"]}
|
||||
)
|
||||
axes = list(getattr(settings["grid"], settings["uvw_axes"]) or [])
|
||||
axes.append(element)
|
||||
setattr(settings["grid"], settings["uvw_axes"], axes)
|
||||
return element
|
||||
|
||||
@@ -19,36 +19,33 @@
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, axis=None):
|
||||
"""Removes a grid axis from a grid
|
||||
def remove_grid_axis(file, axis=None) -> None:
|
||||
"""Removes a grid axis from a grid
|
||||
|
||||
:param axis: The IfcGridAxis you want to remove.
|
||||
:type axis: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
:param axis: The IfcGridAxis you want to remove.
|
||||
:type axis: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
# 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)
|
||||
# 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)
|
||||
|
||||
# Let's create a third so we can remove it later
|
||||
axis_2 = ifcopenshell.api.run("grid.create_grid_axis", model,
|
||||
axis_tag="2", uvw_axes="VAxes", grid=grid)
|
||||
# Let's create a third so we can remove it later
|
||||
axis_2 = ifcopenshell.api.run("grid.create_grid_axis", model,
|
||||
axis_tag="2", uvw_axes="VAxes", grid=grid)
|
||||
|
||||
# Let's remove it!
|
||||
ifcopenshell.api.run("grid.remove_grid_axis", model, axis=axis_2)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"axis": axis}
|
||||
# Let's remove it!
|
||||
ifcopenshell.api.run("grid.remove_grid_axis", model, axis=axis_2)
|
||||
"""
|
||||
settings = {"axis": axis}
|
||||
|
||||
def execute(self):
|
||||
if len(self.file.get_inverse(self.settings["axis"].AxisCurve)) == 1:
|
||||
ifcopenshell.util.element.remove_deep(self.file, self.settings["axis"].AxisCurve)
|
||||
self.file.remove(self.settings["axis"].AxisCurve)
|
||||
self.file.remove(self.settings["axis"])
|
||||
if len(file.get_inverse(settings["axis"].AxisCurve)) == 1:
|
||||
ifcopenshell.util.element.remove_deep(file, settings["axis"].AxisCurve)
|
||||
file.remove(settings["axis"].AxisCurve)
|
||||
file.remove(settings["axis"])
|
||||
|
||||
Reference in New Issue
Block a user