mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 13:46:54 +00:00
New IfcOpenShell placement utility module
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import ifcopenshell.util.geolocation
|
import ifcopenshell.util.geolocation
|
||||||
import numpy as np
|
import ifcopenshell.util.placement
|
||||||
from behave import step
|
from behave import step
|
||||||
|
|
||||||
from utils import assert_number
|
from utils import assert_number
|
||||||
@@ -7,31 +7,6 @@ from utils import assert_type
|
|||||||
from utils import IfcFile
|
from utils import IfcFile
|
||||||
|
|
||||||
|
|
||||||
def a2p(o, z, x):
|
|
||||||
y = np.cross(z, x)
|
|
||||||
r = np.eye(4)
|
|
||||||
r[:-1, :-1] = x, y, z
|
|
||||||
r[-1, :-1] = o
|
|
||||||
return r.T
|
|
||||||
|
|
||||||
|
|
||||||
def get_axis2placement(plc):
|
|
||||||
z = np.array(plc.Axis.DirectionRatios if plc.Axis else (0, 0, 1))
|
|
||||||
x = np.array(plc.RefDirection.DirectionRatios if plc.RefDirection else (1, 0, 0))
|
|
||||||
o = plc.Location.Coordinates
|
|
||||||
return a2p(o, z, x)
|
|
||||||
|
|
||||||
|
|
||||||
def get_local_placement(plc):
|
|
||||||
if plc is None:
|
|
||||||
return np.eye(4)
|
|
||||||
if plc.PlacementRelTo is None:
|
|
||||||
parent = np.eye(4)
|
|
||||||
else:
|
|
||||||
parent = get_local_placement(plc.PlacementRelTo)
|
|
||||||
return np.dot(get_axis2placement(plc.RelativePlacement), parent)
|
|
||||||
|
|
||||||
|
|
||||||
def get_decimal_points(value):
|
def get_decimal_points(value):
|
||||||
try:
|
try:
|
||||||
return len(value.split(".")[1])
|
return len(value.split(".")[1])
|
||||||
@@ -83,7 +58,7 @@ def step_impl(context, guid, easting, northing, elevation):
|
|||||||
element = IfcFile.by_guid(guid)
|
element = IfcFile.by_guid(guid)
|
||||||
if not element.ObjectPlacement:
|
if not element.ObjectPlacement:
|
||||||
assert False, "The element does not have an object placement: {}".format(element)
|
assert False, "The element does not have an object placement: {}".format(element)
|
||||||
m = get_local_placement(element.ObjectPlacement)
|
m = ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement)
|
||||||
e, n, h = ifcopenshell.util.geolocation.xyz2enh(
|
e, n, h = ifcopenshell.util.geolocation.xyz2enh(
|
||||||
m[0][3],
|
m[0][3],
|
||||||
m[1][3],
|
m[1][3],
|
||||||
@@ -110,7 +85,7 @@ def step_impl(context, guid, x, y, z):
|
|||||||
element = IfcFile.by_guid(guid)
|
element = IfcFile.by_guid(guid)
|
||||||
if not element.ObjectPlacement:
|
if not element.ObjectPlacement:
|
||||||
assert False, "The element does not have an object placement: {}".format(element)
|
assert False, "The element does not have an object placement: {}".format(element)
|
||||||
m = get_local_placement(element.ObjectPlacement)
|
m = ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement)
|
||||||
element_x = round(m[0][3], get_decimal_points(x))
|
element_x = round(m[0][3], get_decimal_points(x))
|
||||||
element_y = round(m[1][3], get_decimal_points(y))
|
element_y = round(m[1][3], get_decimal_points(y))
|
||||||
element_z = round(m[2][3], get_decimal_points(z))
|
element_z = round(m[2][3], get_decimal_points(z))
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def a2p(o, z, x):
|
||||||
|
y = np.cross(z, x)
|
||||||
|
r = np.eye(4)
|
||||||
|
r[:-1, :-1] = x, y, z
|
||||||
|
r[-1, :-1] = o
|
||||||
|
return r.T
|
||||||
|
|
||||||
|
|
||||||
|
def get_axis2placement(plc):
|
||||||
|
z = np.array(plc.Axis.DirectionRatios if plc.Axis else (0, 0, 1))
|
||||||
|
x = np.array(plc.RefDirection.DirectionRatios if plc.RefDirection else (1, 0, 0))
|
||||||
|
o = plc.Location.Coordinates
|
||||||
|
return a2p(o, z, x)
|
||||||
|
|
||||||
|
|
||||||
|
def get_local_placement(plc):
|
||||||
|
if plc is None:
|
||||||
|
return np.eye(4)
|
||||||
|
if plc.PlacementRelTo is None:
|
||||||
|
parent = np.eye(4)
|
||||||
|
else:
|
||||||
|
parent = get_local_placement(plc.PlacementRelTo)
|
||||||
|
return np.dot(get_axis2placement(plc.RelativePlacement), parent)
|
||||||
Reference in New Issue
Block a user