geometry.create_2p_wall - document

This commit is contained in:
Andrej730
2024-10-29 12:17:27 +05:00
parent 87d185fef1
commit af01f6b6c7
@@ -19,6 +19,7 @@
import numpy as np import numpy as np
import ifcopenshell.api.geometry import ifcopenshell.api.geometry
import ifcopenshell.util.unit import ifcopenshell.util.unit
from typing import Any
def create_2pt_wall( def create_2pt_wall(
@@ -32,57 +33,58 @@ def create_2pt_wall(
thickness: float, thickness: float,
is_si: bool = True, is_si: bool = True,
) -> ifcopenshell.entity_instance: ) -> ifcopenshell.entity_instance:
usecase = Usecase() """
usecase.file = file Create a wall between two points (p1 and p2).
usecase.settings = { A shortcut for geometry.add_wall_representation.
"element": element,
"context": context,
"p1": p1,
"p2": p2,
"elevation": elevation,
"height": height,
"thickness": thickness,
"is_si": is_si,
}
return usecase.execute()
:param element: Wall IFC element.
:param context: IfcGeometricRepresentationContext for the representation.
only Model/Body/MODEL_VIEW type of representations are currently supported.
:param p1: The starting point (x, y) of the wall.
:param p2: The ending point (x, y) of the wall.
:param elevation: The base elevation (z-coordinate) for the wall.
:param height: The height of the wall.
:param thickness: The thickness of the wall.
:param is_si: If True, provided arguments units are treated as SI (meters).
If False, values are converted from project units to SI.
:return: IfcShapeRepresentation.
"""
si_conversion = ifcopenshell.util.unit.calculate_unit_scale(file)
class Usecase: p1_ = np.array(p1).astype(float)
def execute(self): p2_ = np.array(p2).astype(float)
self.settings["unit_scale"] = ifcopenshell.util.unit.calculate_unit_scale(self.file)
self.settings["p1"] = np.array(self.settings["p1"]).astype(float) length = float(np.linalg.norm(p2_ - p1_))
self.settings["p2"] = np.array(self.settings["p2"]).astype(float)
length = float(np.linalg.norm(self.settings["p2"] - self.settings["p1"])) if not is_si:
length = convert_unit_to_si(length, si_conversion)
if not self.settings["is_si"]: height = convert_unit_to_si(height, si_conversion)
length = self.convert_unit_to_si(length) thickness = convert_unit_to_si(thickness, si_conversion)
self.settings["height"] = self.convert_unit_to_si(self.settings["height"]) # No need to convert p2 as length is already calculated.
self.settings["thickness"] = self.convert_unit_to_si(self.settings["thickness"]) p1_ = convert_unit_to_si(p1_, si_conversion)
self.settings["p1"][0] = self.convert_unit_to_si(self.settings["p1"][0]) elevation = convert_unit_to_si(elevation, si_conversion)
self.settings["p1"][1] = self.convert_unit_to_si(self.settings["p1"][1])
self.settings["elevation"] = self.convert_unit_to_si(self.settings["elevation"])
representation = ifcopenshell.api.geometry.add_wall_representation( representation = ifcopenshell.api.geometry.add_wall_representation(
self.file, file,
context=self.settings["context"], context=context,
length=length, length=length,
height=self.settings["height"], height=height,
thickness=self.settings["thickness"], thickness=thickness,
) )
v = self.settings["p2"] - self.settings["p1"]
v = p2_ - p1_
v /= float(np.linalg.norm(v)) v /= float(np.linalg.norm(v))
matrix = np.array( matrix = np.array(
[ [
[v[0], -v[1], 0, self.settings["p1"][0]], [v[0], -v[1], 0, p1_[0]],
[v[1], v[0], 0, self.settings["p1"][1]], [v[1], v[0], 0, p1_[1]],
[0, 0, 1, self.settings["elevation"]], [0, 0, 1, elevation],
[0, 0, 0, 1], [0, 0, 0, 1],
] ]
) )
ifcopenshell.api.geometry.edit_object_placement(self.file, product=self.settings["element"], matrix=matrix) ifcopenshell.api.geometry.edit_object_placement(file, product=element, matrix=matrix)
return representation return representation
def convert_unit_to_si(self, co):
return co * self.settings["unit_scale"] def convert_unit_to_si(co: Any, si_conversion: float) -> Any:
return co * si_conversion