Splitting by edge now resolved mapped representations, voided, and non-mesh geometries

This commit is contained in:
Dion Moult
2023-09-24 15:43:10 +10:00
parent 604373415f
commit f6cd6d2591
3 changed files with 46 additions and 17 deletions
@@ -22,6 +22,7 @@ import ifcopenshell
import blenderbim.bim.handler
import blenderbim.tool as tool
import blenderbim.core.misc as core
import blenderbim.core.geometry as core_geometry
from blenderbim.bim.ifc import IfcStore
from mathutils import Vector, Matrix, Euler
@@ -140,7 +141,51 @@ class SplitAlongEdge(bpy.types.Operator, Operator):
return context.selected_objects and tool.Ifc.get()
def _execute(self, context):
core.split_along_edge(tool.Misc, cutter=context.active_object, objs=context.selected_objects)
cutter = context.active_object
objs = [o for o in context.selected_objects if o != cutter]
# Splitting only works on meshes
for obj in objs:
# You cannot split meshes if the representation is mapped.
element = tool.Ifc.get_entity(obj)
if element:
relating_type = tool.Root.get_element_type(element)
if relating_type and tool.Root.does_type_have_representations(relating_type):
bpy.ops.bim.unassign_type(related_object=obj.name)
representation = tool.Geometry.get_active_representation(obj)
core_geometry.switch_representation(
tool.Ifc,
tool.Geometry,
obj=obj,
representation=representation,
should_reload=True,
is_global=True,
should_sync_changes_first=False,
apply_openings=False,
)
if not tool.Geometry.is_meshlike(representation):
bpy.ops.bim.update_representation(obj=obj.name, ifc_representation_class="IfcTessellatedFaceSet")
new_objs = tool.Misc.split_objects_with_cutter(objs, cutter)
for obj in new_objs:
blenderbim.core.root.copy_class(tool.Ifc, tool.Collector, tool.Geometry, tool.Root, obj=obj)
bpy.ops.bim.update_representation(obj=obj.name)
for obj in objs:
bpy.ops.bim.update_representation(obj=obj.name)
representation = tool.Geometry.get_active_representation(obj)
core_geometry.switch_representation(
tool.Ifc,
tool.Geometry,
obj=obj,
representation=representation,
should_reload=True,
is_global=True,
should_sync_changes_first=False,
apply_openings=True,
)
class GetConnectedSystemElements(bpy.types.Operator, Operator):
-8
View File
@@ -28,11 +28,3 @@ def resize_to_storey(misc, obj=None, total_storeys=None):
misc.move_object_to_elevation(obj, misc.get_storey_elevation_in_si(storey))
misc.scale_object_to_height(obj, height)
misc.mark_object_as_edited(obj)
def split_along_edge(misc, cutter=None, objs=None):
new_objs = misc.split_objects_with_cutter(objs, cutter)
for obj in new_objs:
misc.run_root_copy_class(obj=obj)
for obj in objs:
misc.mark_object_as_edited(obj)
-8
View File
@@ -39,11 +39,3 @@ class TestResizeToStorey:
misc.get_object_storey("obj").should_be_called().will_return("storey")
misc.get_storey_height_in_si("storey", 1).should_be_called().will_return(None)
subject.resize_to_storey(misc, obj="obj", total_storeys=1)
class TestSplitAlongEdge:
def test_run(self, misc):
misc.split_objects_with_cutter(["obj"], "cutter").should_be_called().will_return(["new_obj"])
misc.run_root_copy_class(obj="new_obj").should_be_called()
misc.mark_object_as_edited("obj").should_be_called()
subject.split_along_edge(misc, cutter="cutter", objs=["obj"])