You can now delete unit assignments

This commit is contained in:
Dion Moult
2021-08-06 14:11:08 +10:00
parent 4ccadc4f36
commit 326e7e591f
5 changed files with 53 additions and 2 deletions
@@ -4,6 +4,8 @@ from . import ui, prop, operator
classes = (
operator.AssignUnit,
operator.LoadUnits,
operator.DisableUnitEditingUI,
operator.RemoveUnit,
prop.Unit,
prop.BIMUnitProperties,
ui.BIM_PT_units,
@@ -88,3 +88,31 @@ class LoadUnits(bpy.types.Operator):
props.is_editing = True
# bpy.ops.bim.disable_editing_unit()
return {"FINISHED"}
class DisableUnitEditingUI(bpy.types.Operator):
bl_idname = "bim.disable_unit_editing_ui"
bl_label = "Disable Unit Editing UI"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
context.scene.BIMUnitProperties.is_editing = False
return {"FINISHED"}
class RemoveUnit(bpy.types.Operator):
bl_idname = "bim.remove_unit"
bl_label = "Remove Unit"
bl_options = {"REGISTER", "UNDO"}
unit: bpy.props.IntProperty()
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context):
props = context.scene.BIMUnitProperties
self.file = IfcStore.get_file()
ifcopenshell.api.run("unit.remove_unit", self.file, **{"unit": self.file.by_id(self.unit)})
Data.load(self.file)
bpy.ops.bim.load_units()
return {"FINISHED"}
@@ -26,8 +26,8 @@ class BIM_PT_units(Panel):
row = self.layout.row(align=True)
row.label(text="{} Units Found".format(len(Data.unit_assignment)), icon="SNAP_GRID")
if self.props.is_editing:
row.operator("bim.add_group", text="", icon="ADD")
row.operator("bim.disable_group_editing_ui", text="", icon="CANCEL")
# row.operator("bim.add_unit", text="", icon="ADD")
row.operator("bim.disable_unit_editing_ui", text="", icon="CANCEL")
else:
row.operator("bim.load_units", text="", icon="GREASEPENCIL")
@@ -49,3 +49,4 @@ class BIM_UL_units(UIList):
row = layout.row(align=True)
row.label(text=item.unit_type or "No Type", icon=item.icon)
row.label(text=item.name or "Unnamed")
row.operator("bim.remove_unit", text="", icon="X").unit = item.ifc_definition_id
@@ -17,6 +17,8 @@ class Data:
if not file:
return
cls.file = file
cls.unit_assignment = []
cls.units = {}
unit_assignment = cls.file.by_type("IfcUnitAssignment")
if not unit_assignment:
return
@@ -0,0 +1,18 @@
import ifcopenshell.util.element
class Usecase():
def __init__(self, file, **settings):
self.file = file
self.settings = {"unit": None}
for key, value in settings.items():
self.settings[key] = value
def execute(self):
unit_assignment = self.file.by_type("IfcUnitAssignment")[0]
units = list(unit_assignment.Units)
units.remove(self.settings["unit"])
if not units:
return
unit_assignment.Units = units
ifcopenshell.util.element.remove_deep(self.file, self.settings["unit"])