diff --git a/src/blenderbim/blenderbim/bim/module/unit/__init__.py b/src/blenderbim/blenderbim/bim/module/unit/__init__.py index af935164c7..03a4a4e873 100644 --- a/src/blenderbim/blenderbim/bim/module/unit/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/unit/__init__.py @@ -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, diff --git a/src/blenderbim/blenderbim/bim/module/unit/operator.py b/src/blenderbim/blenderbim/bim/module/unit/operator.py index dd31ac289d..baae5ffab9 100644 --- a/src/blenderbim/blenderbim/bim/module/unit/operator.py +++ b/src/blenderbim/blenderbim/bim/module/unit/operator.py @@ -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"} diff --git a/src/blenderbim/blenderbim/bim/module/unit/ui.py b/src/blenderbim/blenderbim/bim/module/unit/ui.py index 943f20a08d..8e8ec3a3da 100644 --- a/src/blenderbim/blenderbim/bim/module/unit/ui.py +++ b/src/blenderbim/blenderbim/bim/module/unit/ui.py @@ -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 diff --git a/src/ifcopenshell-python/ifcopenshell/api/unit/data.py b/src/ifcopenshell-python/ifcopenshell/api/unit/data.py index e9959597f1..893b302cff 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/unit/data.py +++ b/src/ifcopenshell-python/ifcopenshell/api/unit/data.py @@ -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 diff --git a/src/ifcopenshell-python/ifcopenshell/api/unit/remove_unit.py b/src/ifcopenshell-python/ifcopenshell/api/unit/remove_unit.py new file mode 100644 index 0000000000..949bf919e5 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/unit/remove_unit.py @@ -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"])