mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
util.selector.set_element_value to work w/o preassigned placement #4439
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import lark
|
import lark
|
||||||
|
import numpy as np
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
import ifcopenshell.util
|
import ifcopenshell.util
|
||||||
import ifcopenshell.util.fm
|
import ifcopenshell.util.fm
|
||||||
@@ -362,13 +363,14 @@ def set_element_value(
|
|||||||
if key in ("easting", "northing", "elevation"):
|
if key in ("easting", "northing", "elevation"):
|
||||||
return
|
return
|
||||||
|
|
||||||
placement = getattr(element, "ObjectPlacement", None)
|
placement = element.ObjectPlacement
|
||||||
if not placement:
|
if placement is None:
|
||||||
return
|
matrix = np.eye(4)
|
||||||
matrix = ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement)
|
else:
|
||||||
coord_i = "xyz".index(key)
|
matrix = ifcopenshell.util.placement.get_local_placement(placement)
|
||||||
|
|
||||||
# check if value is within tolerance to avoid api calls
|
# check if value is within tolerance to avoid api calls
|
||||||
|
coord_i = "xyz".index(key)
|
||||||
prev_value = matrix[coord_i][3]
|
prev_value = matrix[coord_i][3]
|
||||||
new_value = float(value) if value else 0.0
|
new_value = float(value) if value else 0.0
|
||||||
TOLERANCE = 1.0e-5
|
TOLERANCE = 1.0e-5
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import pytest
|
|||||||
import test.bootstrap
|
import test.bootstrap
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
import ifcopenshell.util.selector as subject
|
import ifcopenshell.util.selector as subject
|
||||||
|
import ifcopenshell.util.placement
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
@@ -272,14 +273,24 @@ class TestSetElementValue(test.bootstrap.IFC4):
|
|||||||
def test_set_xyz_coordinates(self):
|
def test_set_xyz_coordinates(self):
|
||||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||||
ifcopenshell.api.run("unit.assign_unit", self.file)
|
ifcopenshell.api.run("unit.assign_unit", self.file)
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
|
||||||
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=element, is_si=False)
|
items = list(zip("xyz", ("5", "10", "15")))
|
||||||
for coord, value in zip("xyz", ("5", "10", "15")):
|
|
||||||
subject.set_element_value(self.file, element, coord, value)
|
|
||||||
matrix = np.eye(4)
|
matrix = np.eye(4)
|
||||||
matrix[:, 3] = (5, 10, 15, 1)
|
matrix[:, 3] = (5, 10, 15, 1)
|
||||||
|
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
|
ifcopenshell.api.run("geometry.edit_object_placement", self.file, product=element, is_si=False)
|
||||||
|
for coord, value in items:
|
||||||
|
subject.set_element_value(self.file, element, coord, value)
|
||||||
assert np.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), matrix)
|
assert np.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), matrix)
|
||||||
|
|
||||||
|
element_without_placement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
|
for coord, value in items:
|
||||||
|
subject.set_element_value(self.file, element_without_placement, coord, value)
|
||||||
|
assert np.array_equal(
|
||||||
|
ifcopenshell.util.placement.get_local_placement(element_without_placement.ObjectPlacement), matrix
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestSelector(test.bootstrap.IFC4):
|
class TestSelector(test.bootstrap.IFC4):
|
||||||
def test_selecting_by_class(self):
|
def test_selecting_by_class(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user