mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-06 07:51:47 +00:00
Add copy attribute to selection for boundaries
Add a paste button to IfcRelSpaceBoundary specific attributes (RelatingSpace, RelatedBuildingElement, ParentBoundary, CorrespondingBoundary, PhysicalOrVirtualBoundary, InternalOrExternalBoundary) reusing the existing copy_attribute_to_selection core function. The core function value type hint is broadened from Union[str, None] to Any since boundary relation attributes pass IFC entity instances. Generated with the assistance of an AI coding tool.
This commit is contained in:
@@ -23,6 +23,7 @@ from . import operator, prop, ui
|
||||
classes = (
|
||||
operator.AddBoundary,
|
||||
operator.ColourByRelatedBuildingElement,
|
||||
operator.CopyBoundaryAttributeToSelection,
|
||||
operator.DecorateBoundaries,
|
||||
operator.DisableEditingBoundary,
|
||||
operator.DisableEditingBoundaryGeometry,
|
||||
|
||||
@@ -39,6 +39,7 @@ from ifcopenshell.util.shape_builder import ShapeBuilder
|
||||
from mathutils import Matrix, Vector
|
||||
|
||||
import bonsai.bim.import_ifc as import_ifc
|
||||
import bonsai.core.attribute as core
|
||||
import bonsai.core.geometry
|
||||
import bonsai.tool as tool
|
||||
from bonsai.bim.ifc import IfcStore
|
||||
@@ -422,6 +423,32 @@ class EditBoundaryAttributes(bpy.types.Operator, tool.Ifc.Operator):
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class CopyBoundaryAttributeToSelection(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.copy_boundary_attribute_to_selection"
|
||||
bl_label = "Copy Boundary Attribute To Selection"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
name: bpy.props.StringProperty()
|
||||
|
||||
def _execute(self, context):
|
||||
obj = tool.Blender.get_active_object()
|
||||
assert obj
|
||||
bprops = tool.Boundary.get_object_boundary_props(obj)
|
||||
if self.name in EDITABLE_ATTRIBUTES:
|
||||
blender_prop = EDITABLE_ATTRIBUTES[self.name]
|
||||
blender_obj = getattr(bprops, blender_prop, None)
|
||||
value = tool.Ifc.get_entity(blender_obj) if blender_obj else None
|
||||
elif self.name == "PhysicalOrVirtualBoundary":
|
||||
value = bprops.physical_or_virtual
|
||||
elif self.name == "InternalOrExternalBoundary":
|
||||
value = bprops.internal_or_external
|
||||
else:
|
||||
return
|
||||
total = core.copy_attribute_to_selection(
|
||||
tool.Ifc, tool.Blender, tool.Root, tool.Spatial, name=self.name, value=value
|
||||
)
|
||||
self.report({"INFO"}, f"Attribute was successfully copied to {total} elements.")
|
||||
|
||||
|
||||
class UpdateBoundaryGeometry(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.update_boundary_geometry"
|
||||
bl_label = "Update Boundary Geometry"
|
||||
|
||||
@@ -77,10 +77,14 @@ class BIM_PT_Boundary(Panel):
|
||||
self.draw_relation_editor(boundary, "RelatedBuildingElement", "related_building_element")
|
||||
self.draw_relation_editor(boundary, "ParentBoundary", "parent_boundary")
|
||||
self.draw_relation_editor(boundary, "CorrespondingBoundary", "corresponding_boundary")
|
||||
row = self.layout.row()
|
||||
row = self.layout.row(align=True)
|
||||
row.prop(self.bprops, "physical_or_virtual")
|
||||
row = self.layout.row()
|
||||
op = row.operator("bim.copy_boundary_attribute_to_selection", text="", icon="COPYDOWN")
|
||||
op.name = "PhysicalOrVirtualBoundary"
|
||||
row = self.layout.row(align=True)
|
||||
row.prop(self.bprops, "internal_or_external")
|
||||
op = row.operator("bim.copy_boundary_attribute_to_selection", text="", icon="COPYDOWN")
|
||||
op.name = "InternalOrExternalBoundary"
|
||||
else:
|
||||
row = self.layout.row()
|
||||
row.operator("bim.enable_editing_boundary", icon="GREASEPENCIL", text="Edit")
|
||||
@@ -125,6 +129,8 @@ class BIM_PT_Boundary(Panel):
|
||||
if hasattr(boundary, ifc_attribute):
|
||||
row = self.layout.row(align=True)
|
||||
row.prop(self.bprops, blender_property)
|
||||
op = row.operator("bim.copy_boundary_attribute_to_selection", text="", icon="COPYDOWN")
|
||||
op.name = ifc_attribute
|
||||
|
||||
|
||||
class BIM_PT_SpaceBoundaries(Panel):
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Union
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
@@ -31,7 +31,7 @@ def copy_attribute_to_selection(
|
||||
root: type[tool.Root],
|
||||
spatial: type[tool.Spatial],
|
||||
name: str,
|
||||
value: Union[str, None],
|
||||
value: Any,
|
||||
) -> int:
|
||||
total_changed = 0
|
||||
has_edited_spatial_name = False
|
||||
|
||||
Reference in New Issue
Block a user