mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 19:02:26 +00:00
bim.show_booleans - not to load same booleans multiple twice #5800
Now it's checking whether they were reloaded before and removing previous instances.
This commit is contained in:
@@ -593,6 +593,7 @@ class AddBoolean(Operator, tool.Ifc.Operator):
|
|||||||
class ShowBooleans(Operator, tool.Ifc.Operator, AddObjectHelper):
|
class ShowBooleans(Operator, tool.Ifc.Operator, AddObjectHelper):
|
||||||
bl_idname = "bim.show_booleans"
|
bl_idname = "bim.show_booleans"
|
||||||
bl_label = "Show Booleans"
|
bl_label = "Show Booleans"
|
||||||
|
bl_description = "Show active object booleans.\nCan be used to reset booleans positions"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -616,16 +617,28 @@ class ShowBooleans(Operator, tool.Ifc.Operator, AddObjectHelper):
|
|||||||
props = bpy.context.scene.BIMModelProperties
|
props = bpy.context.scene.BIMModelProperties
|
||||||
tool.Model.clear_scene_openings()
|
tool.Model.clear_scene_openings()
|
||||||
|
|
||||||
|
existing_booleans = {
|
||||||
|
boolean_obj.data.BIMMeshProperties.ifc_boolean_id: boolean_obj
|
||||||
|
for opening in props.openings
|
||||||
|
if (boolean_obj := opening.obj).data.BIMMeshProperties.obj == obj
|
||||||
|
}
|
||||||
|
|
||||||
for boolean in booleans:
|
for boolean in booleans:
|
||||||
boolean_obj = None
|
boolean_obj = None
|
||||||
|
|
||||||
if boolean.is_a() == "IfcHalfSpaceSolid":
|
if boolean.is_a() == "IfcHalfSpaceSolid":
|
||||||
if boolean.BaseSurface.is_a("IfcPlane"):
|
surface = boolean.BaseSurface
|
||||||
|
if surface.is_a("IfcPlane"):
|
||||||
boolean_obj = self.create_half_space_solid()
|
boolean_obj = self.create_half_space_solid()
|
||||||
position = boolean.BaseSurface.Position
|
position = surface.Position
|
||||||
position = Matrix(ifcopenshell.util.placement.get_axis2placement(position).tolist())
|
position = Matrix(ifcopenshell.util.placement.get_axis2placement(position).tolist())
|
||||||
position.translation *= unit_scale
|
position.translation *= unit_scale
|
||||||
boolean_obj.matrix_world = obj.matrix_world @ position
|
boolean_obj.matrix_world = obj.matrix_world @ position
|
||||||
|
else:
|
||||||
|
self.report(
|
||||||
|
{"INFO"},
|
||||||
|
f"Showing boolean using non-IfcPlane IfcSurface ({surface.is_a()}) is not supported.",
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
settings = ifcopenshell.geom.settings()
|
settings = ifcopenshell.geom.settings()
|
||||||
logger = logging.getLogger("ImportIFC")
|
logger = logging.getLogger("ImportIFC")
|
||||||
@@ -642,7 +655,11 @@ class ShowBooleans(Operator, tool.Ifc.Operator, AddObjectHelper):
|
|||||||
boolean_obj.matrix_world = obj.matrix_world
|
boolean_obj.matrix_world = obj.matrix_world
|
||||||
|
|
||||||
if boolean_obj:
|
if boolean_obj:
|
||||||
boolean_obj.data.BIMMeshProperties.ifc_boolean_id = boolean.id()
|
boolean_id = boolean.id()
|
||||||
|
# Remove existing boolean as it will be reloaded.
|
||||||
|
if boolean_id in existing_booleans:
|
||||||
|
bpy.data.objects.remove(existing_booleans[boolean_id])
|
||||||
|
boolean_obj.data.BIMMeshProperties.ifc_boolean_id = boolean_id
|
||||||
boolean_obj.data.BIMMeshProperties.obj = obj
|
boolean_obj.data.BIMMeshProperties.obj = obj
|
||||||
new = props.openings.add()
|
new = props.openings.add()
|
||||||
new.obj = boolean_obj
|
new.obj = boolean_obj
|
||||||
|
|||||||
Reference in New Issue
Block a user