mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
ifc join to show error message if joining is not supported
Example - https://i.imgur.com/5vsmJN8.png
This commit is contained in:
@@ -1482,7 +1482,8 @@ class OverrideJoin(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
builder = ShapeBuilder(ifc_file)
|
builder = ShapeBuilder(ifc_file)
|
||||||
si_conversion = ifcopenshell.util.unit.calculate_unit_scale(ifc_file)
|
si_conversion = ifcopenshell.util.unit.calculate_unit_scale(ifc_file)
|
||||||
representation = ifc_file.by_id(self.target.data.BIMMeshProperties.ifc_definition_id)
|
representation = ifc_file.by_id(self.target.data.BIMMeshProperties.ifc_definition_id)
|
||||||
if representation.RepresentationType in ("Tessellation", "Brep"):
|
representation_type = representation.RepresentationType
|
||||||
|
if representation_type in ("Tessellation", "Brep"):
|
||||||
for obj in bpy.context.selected_objects:
|
for obj in bpy.context.selected_objects:
|
||||||
if obj == self.target:
|
if obj == self.target:
|
||||||
continue
|
continue
|
||||||
@@ -1491,7 +1492,7 @@ class OverrideJoin(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
ifcopenshell.api.run("root.remove_product", ifc_file, product=element)
|
ifcopenshell.api.run("root.remove_product", ifc_file, product=element)
|
||||||
bpy.ops.object.join()
|
bpy.ops.object.join()
|
||||||
bpy.ops.bim.update_representation(obj=self.target.name, ifc_representation_class="")
|
bpy.ops.bim.update_representation(obj=self.target.name, ifc_representation_class="")
|
||||||
elif representation.RepresentationType == "SweptSolid":
|
else:
|
||||||
target_placement = np.array(self.target.matrix_world)
|
target_placement = np.array(self.target.matrix_world)
|
||||||
target_placement[:, 3][:3] /= si_conversion
|
target_placement[:, 3][:3] /= si_conversion
|
||||||
|
|
||||||
@@ -1508,25 +1509,37 @@ class OverrideJoin(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
# Only objects of the same representation type can be joined
|
# Only objects of the same representation type can be joined
|
||||||
obj_rep = ifc_file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
obj_rep = ifc_file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
||||||
if obj_rep.RepresentationType != "SweptSolid":
|
if obj_rep.RepresentationType != representation_type:
|
||||||
obj.select_set(False)
|
obj.select_set(False)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
placement = np.array(obj.matrix_world)
|
placement = np.array(obj.matrix_world)
|
||||||
placement[:, 3][:3] /= si_conversion
|
placement[:, 3][:3] /= si_conversion
|
||||||
|
|
||||||
for item in obj_rep.Items:
|
supported_item_types = ("IfcSweptAreaSolid",)
|
||||||
|
rep_items = obj_rep.Items
|
||||||
|
for item in rep_items:
|
||||||
|
if not any(item.is_a(ifc_class) for ifc_class in supported_item_types):
|
||||||
|
self.report({"ERROR"}, f"Unsupported representation item type for joining: {item.is_a()}.")
|
||||||
|
return
|
||||||
|
|
||||||
|
for item in rep_items:
|
||||||
copied_item = ifcopenshell.util.element.copy_deep(ifc_file, item)
|
copied_item = ifcopenshell.util.element.copy_deep(ifc_file, item)
|
||||||
for style in item.StyledByItem:
|
for style in item.StyledByItem:
|
||||||
copied_style = ifcopenshell.util.element.copy(ifc_file, style)
|
copied_style = ifcopenshell.util.element.copy(ifc_file, style)
|
||||||
copied_style.Item = copied_item
|
copied_style.Item = copied_item
|
||||||
if copied_item.Position:
|
|
||||||
position = ifcopenshell.util.placement.get_axis2placement(copied_item.Position)
|
if item.is_a("IfcSweptAreaSolid"):
|
||||||
|
if copied_item.Position:
|
||||||
|
position = ifcopenshell.util.placement.get_axis2placement(copied_item.Position)
|
||||||
|
else:
|
||||||
|
position = np.eye(4, dtype=float)
|
||||||
|
position = placement @ position
|
||||||
|
position = np.linalg.inv(target_placement) @ position
|
||||||
|
copied_item.Position = builder.create_axis2_placement_3d_from_matrix(position)
|
||||||
else:
|
else:
|
||||||
position = np.eye(4, dtype=float)
|
assert False, f"Unexpected item type: {item.is_a()}. This is a bug."
|
||||||
position = placement @ position
|
|
||||||
position = np.linalg.inv(target_placement) @ position
|
|
||||||
copied_item.Position = builder.create_axis2_placement_3d_from_matrix(position)
|
|
||||||
items.append(copied_item)
|
items.append(copied_item)
|
||||||
ifcopenshell.api.run("root.remove_product", ifc_file, product=element)
|
ifcopenshell.api.run("root.remove_product", ifc_file, product=element)
|
||||||
representation.Items = items
|
representation.Items = items
|
||||||
|
|||||||
Reference in New Issue
Block a user