switch_representation to automatically switch to unresolved mapped representation

The cool thing about it now that it will automatically create a new mesh for "unresolved" representation if element has openings, otherwise it'll stick to the same mesh representation as the type object.

This fixed a few bugs:
- similar to b9a9abd but during extrusion profile edit
- applying void to the occurence used to remove the type and other occurences. Apparently it occured after 744c08e - previously we seems to rely on `ifcopenshell.geom.create_shape(settings, element)` to unresolve the representations. Though before 744c08e there still was an issue - it would apply the same opening to the all occurences and the type meshes but wasn't removing them.

Probably fixed a few other similar issues.
This commit is contained in:
Andrej730
2023-10-23 16:39:25 +05:00
parent 79b8125916
commit 746053eefb
2 changed files with 18 additions and 3 deletions
+6 -3
View File
@@ -106,10 +106,13 @@ def switch_representation(
entity = ifc.get_entity(obj)
current_obj_data = obj.data
# doesn't resolve mapped representations in case if it's going to have openings
# otherwise we would also add openings to the type and other occurences mesh data
has_openings = apply_openings and getattr(entity, "HasOpenings", None)
if not has_openings:
if has_openings:
# if it has openings make sure to switch to element's mapped representation
representation = geometry.unresolve_type_representation(representation, entity)
else:
# doesn't resolve mapped representations in case if it's going to have openings
# otherwise we would also add openings to the type and other occurences mesh data
representation = geometry.resolve_mapped_representation(representation)
old_repr_data = geometry.get_representation_data(representation)
@@ -631,6 +631,18 @@ class Geometry(blenderbim.core.tool.Geometry):
return cls.resolve_mapped_representation(representation.Items[0].MappingSource.MappedRepresentation)
return representation
@classmethod
def unresolve_type_representation(cls, representation, occurence):
if not ifcopenshell.util.element.get_type(occurence):
return representation
if representation.RepresentationType == "MappedRepresentation":
return representation
for mapped_representation in occurence.Representation.Representations:
if cls.resolve_mapped_representation(mapped_representation) == representation:
return mapped_representation
@classmethod
def run_geometry_update_representation(cls, obj=None):
bpy.ops.bim.update_representation(obj=obj.name, ifc_representation_class="")