mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
UI to remove representation items
example - https://i.imgur.com/jJDpIQP.png
This commit is contained in:
@@ -49,6 +49,7 @@ classes = (
|
||||
operator.SwitchRepresentation,
|
||||
operator.UpdateParametricRepresentation,
|
||||
operator.UpdateRepresentation,
|
||||
operator.RemoveRepresentationItem,
|
||||
operator.EnableEditingRepresentationItemStyle,
|
||||
operator.EditRepresentationItemStyle,
|
||||
operator.DisableEditingRepresentationItemStyle,
|
||||
|
||||
@@ -1609,6 +1609,35 @@ class DisableEditingRepresentationItems(bpy.types.Operator, Operator):
|
||||
obj.BIMGeometryProperties.is_editing = False
|
||||
|
||||
|
||||
class RemoveRepresentationItem(bpy.types.Operator, Operator):
|
||||
bl_idname = "bim.remove_representation_item"
|
||||
bl_label = "Remove Representation Item"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
if context.active_object is None or len(context.active_object.BIMGeometryProperties.items) <= 1:
|
||||
cls.poll_message_set(
|
||||
"Active object need to have more than 1 representation items to keep representation valid"
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
||||
def _execute(self, context):
|
||||
obj = context.active_object
|
||||
props = obj.BIMGeometryProperties
|
||||
ifc_file = tool.Ifc.get()
|
||||
|
||||
representation_item_id = props.items[props.active_item_index].ifc_definition_id
|
||||
representation_item = ifc_file.by_id(representation_item_id)
|
||||
tool.Geometry.remove_representation_item(representation_item)
|
||||
tool.Geometry.reload_representation(obj)
|
||||
|
||||
# reload style ui
|
||||
bpy.ops.bim.disable_editing_representation_items()
|
||||
bpy.ops.bim.enable_editing_representation_items()
|
||||
|
||||
|
||||
class EnableEditingRepresentationItemStyle(bpy.types.Operator, Operator):
|
||||
bl_idname = "bim.enable_editing_representation_item_style"
|
||||
bl_label = "Enable Editing Representation Item Style"
|
||||
@@ -1725,7 +1754,9 @@ class EditRepresentationItemShapeAspect(bpy.types.Operator, Operator):
|
||||
previous_shape_aspect_id = props.items[props.active_item_index].shape_aspect_id
|
||||
# will be None if item didn't had a shape aspect
|
||||
previous_shape_aspect = tool.Ifc.get_entity_by_id(previous_shape_aspect_id)
|
||||
shape_aspect = tool.Geometry.create_shape_aspect(product_shape, active_representation, [representation_item], previous_shape_aspect)
|
||||
shape_aspect = tool.Geometry.create_shape_aspect(
|
||||
product_shape, active_representation, [representation_item], previous_shape_aspect
|
||||
)
|
||||
else:
|
||||
shape_aspect = ifc_file.by_id(int(props.representation_item_shape_aspect))
|
||||
tool.Geometry.add_representation_item_to_shape_aspect([representation_item], shape_aspect)
|
||||
|
||||
@@ -496,3 +496,4 @@ class BIM_UL_representation_items(UIList):
|
||||
row.label(text=item.name, icon=icon)
|
||||
if item.layer:
|
||||
row.label(text="", icon="STICKY_UVS_LOC")
|
||||
row.operator("bim.remove_representation_item", icon="X", text="")
|
||||
|
||||
@@ -732,6 +732,45 @@ class Geometry(blenderbim.core.tool.Geometry):
|
||||
apply_openings=True,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def remove_representation_item(cls, representation_item):
|
||||
# NOTE: we assume it's not the last representation item
|
||||
# otherwise we probably would need to remove representation too
|
||||
# NOTE: a lot of shared code with `geometry.remove_representation`
|
||||
ifc_file = tool.Ifc.get()
|
||||
shape_aspects = []
|
||||
|
||||
consider_inverses = []
|
||||
styled_item, colour, texture, layer = None, None, None, None
|
||||
[consider_inverses.append(styled_item := t) for t in representation_item.StyledByItem]
|
||||
[consider_inverses.append(layer := t) for t in representation_item.LayerAssignment]
|
||||
# IfcTessellatedFaceSet
|
||||
[consider_inverses.append(colour := t) for t in getattr(representation_item, "HasColours", [])]
|
||||
[consider_inverses.append(texture := t) for t in getattr(representation_item, "HasTextures", [])]
|
||||
|
||||
for inverse in ifc_file.get_inverse(representation_item):
|
||||
if inverse.is_a("IfcShapeRepresentation"):
|
||||
if inverse.OfShapeAspect:
|
||||
shape_aspects.append(inverse.OfShapeAspect[0])
|
||||
else:
|
||||
representation = inverse
|
||||
|
||||
if styled_item:
|
||||
ifc_file.remove(styled_item)
|
||||
if layer and len(layer.Items) == 1:
|
||||
ifc_file.remove(styled_item)
|
||||
if colour:
|
||||
ifcopenshell.util.element.remove_deep2(ifc_file, colour)
|
||||
if texture:
|
||||
ifcopenshell.util.element.remove_deep2(ifc_file, texture)
|
||||
|
||||
for shape_aspect in shape_aspects:
|
||||
cls.remove_representation_items_from_shape_aspect([representation_item], shape_aspect)
|
||||
|
||||
representation.Items = tuple(set(representation.Items) - {representation_item})
|
||||
also_consider = list(consider_inverses)
|
||||
ifcopenshell.util.element.remove_deep2(ifc_file, representation_item, also_consider=also_consider)
|
||||
|
||||
@classmethod
|
||||
def get_shape_aspects(cls, element):
|
||||
# IfcProduct
|
||||
@@ -836,4 +875,3 @@ class Geometry(blenderbim.core.tool.Geometry):
|
||||
)
|
||||
shape_aspect.ShapeRepresentations = shape_aspect.ShapeRepresentations + (shape_aspect_representation,)
|
||||
return shape_aspect_representation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user