mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 14:02:27 +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):
|
def execute(self, context):
|
||||||
core.set_default_container(tool.Spatial, container=tool.Ifc.get().by_id(self.container))
|
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"}
|
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:
|
def create_orientation_slots(ifc: tool.Ifc, spatial: tool.Spatial) -> None:
|
||||||
elements = ifc.get().by_type("IfcSpatialElement")
|
products = ifc.get().by_type("IfcSpatialElement")
|
||||||
spatial.create_orientation_slots(elements, use=False)
|
spatial.create_orientation_slots(products, use=False)
|
||||||
|
|
||||||
|
|
||||||
def set_orientation_slot(spatial: tool.Spatial, element: ifcopenshell.entity_instance) -> None:
|
def set_orientation_slot(spatial: tool.Spatial, product: ifcopenshell.entity_instance) -> None:
|
||||||
spatial.create_orientation_slots([element], use=True)
|
spatial.create_orientation_slots([product], use=True)
|
||||||
|
|
||||||
|
|
||||||
def edit_container_attributes(spatial: tool.Spatial, entity: ifcopenshell.entity_instance) -> None:
|
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)
|
cls.import_spatial_element(child, level_index + 1)
|
||||||
|
|
||||||
@classmethod
|
@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]
|
active_slot = bpy.context.scene.transform_orientation_slots[0]
|
||||||
initial_orientation = active_slot.type
|
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.transform.create_orientation() requires a dummy object
|
||||||
bpy.ops.object.empty_add(type="PLAIN_AXES")
|
bpy.ops.object.empty_add(type="PLAIN_AXES")
|
||||||
|
|
||||||
for element in elements:
|
for product in products:
|
||||||
placement = element.ObjectPlacement
|
placement = product.ObjectPlacement
|
||||||
combined_matrix = ifcopenshell.util.placement.get_local_placement(placement)[:3, :3]
|
combined_matrix = ifcopenshell.util.placement.get_local_placement(placement)[:3, :3]
|
||||||
if np.allclose(combined_matrix, np.eye(3), atol=1e-6):
|
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"
|
active_slot.type = "GLOBAL"
|
||||||
continue
|
continue
|
||||||
elif element.Decomposes and hasattr(element.Decomposes[0].RelatingObject, "ObjectPlacement"):
|
elif product.Decomposes and hasattr(product.Decomposes[0].RelatingObject, "ObjectPlacement"):
|
||||||
# this element is part of a decomposition
|
# this product is part of a decomposition
|
||||||
parent_placement = element.Decomposes[0].RelatingObject.ObjectPlacement
|
parent_placement = product.Decomposes[0].RelatingObject.ObjectPlacement
|
||||||
parent_matrix = ifcopenshell.util.placement.get_local_placement(parent_placement)[:3, :3]
|
parent_matrix = ifcopenshell.util.placement.get_local_placement(parent_placement)[:3, :3]
|
||||||
if np.allclose(combined_matrix, parent_matrix, atol=1e-6):
|
if np.allclose(combined_matrix, parent_matrix, atol=1e-6):
|
||||||
# this element has the same orientation as its parent
|
# this product has the same orientation as its parent
|
||||||
cls.create_orientation_slots(elements=[element.Decomposes[0].RelatingObject], use=use)
|
cls.create_orientation_slots(products=[product.Decomposes[0].RelatingObject], use=use)
|
||||||
continue
|
continue
|
||||||
# this element has a unique orientation
|
# this product has a unique orientation
|
||||||
orientation_name = element.is_a() + "/" + element.Name
|
orientation_name = product.is_a() + "/" + product.Name
|
||||||
bpy.ops.transform.create_orientation(name=orientation_name, overwrite=True)
|
bpy.ops.transform.create_orientation(name=orientation_name, overwrite=True)
|
||||||
active_slot.type = orientation_name
|
active_slot.type = orientation_name
|
||||||
active_slot.custom_orientation.matrix = np.linalg.inv(combined_matrix)
|
active_slot.custom_orientation.matrix = np.linalg.inv(combined_matrix)
|
||||||
|
|||||||
Reference in New Issue
Block a user