mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
s/element/product/ in create_orientation_slots()
This method should work with anything that has an ObjectPlacement, ie. an IfcProduct
This commit is contained in:
@@ -346,7 +346,7 @@ class SetDefaultContainer(bpy.types.Operator):
|
||||
|
||||
def execute(self, context):
|
||||
core.set_default_container(tool.Spatial, container=tool.Ifc.get().by_id(self.container))
|
||||
core.set_orientation_slot(spatial=tool.Spatial, element=tool.Ifc.get().by_id(self.container))
|
||||
core.set_orientation_slot(spatial=tool.Spatial, product=tool.Ifc.get().by_id(self.container))
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
|
||||
@@ -122,12 +122,12 @@ def import_spatial_decomposition(spatial: tool.Spatial) -> None:
|
||||
|
||||
|
||||
def create_orientation_slots(ifc: tool.Ifc, spatial: tool.Spatial) -> None:
|
||||
elements = ifc.get().by_type("IfcSpatialElement")
|
||||
spatial.create_orientation_slots(elements, use=False)
|
||||
products = ifc.get().by_type("IfcSpatialElement")
|
||||
spatial.create_orientation_slots(products, use=False)
|
||||
|
||||
|
||||
def set_orientation_slot(spatial: tool.Spatial, element: ifcopenshell.entity_instance) -> None:
|
||||
spatial.create_orientation_slots([element], use=True)
|
||||
def set_orientation_slot(spatial: tool.Spatial, product: ifcopenshell.entity_instance) -> None:
|
||||
spatial.create_orientation_slots([product], use=True)
|
||||
|
||||
|
||||
def edit_container_attributes(spatial: tool.Spatial, entity: ifcopenshell.entity_instance) -> None:
|
||||
|
||||
@@ -481,7 +481,7 @@ class Spatial(bonsai.core.tool.Spatial):
|
||||
cls.import_spatial_element(child, level_index + 1)
|
||||
|
||||
@classmethod
|
||||
def create_orientation_slots(cls, elements: list[ifcopenshell.entity_instance], use: bool = False) -> None:
|
||||
def create_orientation_slots(cls, products: list[ifcopenshell.entity_instance], use: bool = False) -> None:
|
||||
active_slot = bpy.context.scene.transform_orientation_slots[0]
|
||||
initial_orientation = active_slot.type
|
||||
|
||||
@@ -492,23 +492,23 @@ class Spatial(bonsai.core.tool.Spatial):
|
||||
# bpy.ops.transform.create_orientation() requires a dummy object
|
||||
bpy.ops.object.empty_add(type="PLAIN_AXES")
|
||||
|
||||
for element in elements:
|
||||
placement = element.ObjectPlacement
|
||||
for product in products:
|
||||
placement = product.ObjectPlacement
|
||||
combined_matrix = ifcopenshell.util.placement.get_local_placement(placement)[:3, :3]
|
||||
if np.allclose(combined_matrix, np.eye(3), atol=1e-6):
|
||||
# this element has global orientation
|
||||
# this product has global orientation
|
||||
active_slot.type = "GLOBAL"
|
||||
continue
|
||||
elif element.Decomposes and hasattr(element.Decomposes[0].RelatingObject, "ObjectPlacement"):
|
||||
# this element is part of a decomposition
|
||||
parent_placement = element.Decomposes[0].RelatingObject.ObjectPlacement
|
||||
elif product.Decomposes and hasattr(product.Decomposes[0].RelatingObject, "ObjectPlacement"):
|
||||
# this product is part of a decomposition
|
||||
parent_placement = product.Decomposes[0].RelatingObject.ObjectPlacement
|
||||
parent_matrix = ifcopenshell.util.placement.get_local_placement(parent_placement)[:3, :3]
|
||||
if np.allclose(combined_matrix, parent_matrix, atol=1e-6):
|
||||
# this element has the same orientation as its parent
|
||||
cls.create_orientation_slots(elements=[element.Decomposes[0].RelatingObject], use=use)
|
||||
# this product has the same orientation as its parent
|
||||
cls.create_orientation_slots(products=[product.Decomposes[0].RelatingObject], use=use)
|
||||
continue
|
||||
# this element has a unique orientation
|
||||
orientation_name = element.is_a() + "/" + element.Name
|
||||
# this product has a unique orientation
|
||||
orientation_name = product.is_a() + "/" + product.Name
|
||||
bpy.ops.transform.create_orientation(name=orientation_name, overwrite=True)
|
||||
active_slot.type = orientation_name
|
||||
active_slot.custom_orientation.matrix = np.linalg.inv(combined_matrix)
|
||||
|
||||
Reference in New Issue
Block a user