mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
You can now delete unit assignments
This commit is contained in:
@@ -4,6 +4,8 @@ from . import ui, prop, operator
|
|||||||
classes = (
|
classes = (
|
||||||
operator.AssignUnit,
|
operator.AssignUnit,
|
||||||
operator.LoadUnits,
|
operator.LoadUnits,
|
||||||
|
operator.DisableUnitEditingUI,
|
||||||
|
operator.RemoveUnit,
|
||||||
prop.Unit,
|
prop.Unit,
|
||||||
prop.BIMUnitProperties,
|
prop.BIMUnitProperties,
|
||||||
ui.BIM_PT_units,
|
ui.BIM_PT_units,
|
||||||
|
|||||||
@@ -88,3 +88,31 @@ class LoadUnits(bpy.types.Operator):
|
|||||||
props.is_editing = True
|
props.is_editing = True
|
||||||
# bpy.ops.bim.disable_editing_unit()
|
# bpy.ops.bim.disable_editing_unit()
|
||||||
return {"FINISHED"}
|
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 = self.layout.row(align=True)
|
||||||
row.label(text="{} Units Found".format(len(Data.unit_assignment)), icon="SNAP_GRID")
|
row.label(text="{} Units Found".format(len(Data.unit_assignment)), icon="SNAP_GRID")
|
||||||
if self.props.is_editing:
|
if self.props.is_editing:
|
||||||
row.operator("bim.add_group", text="", icon="ADD")
|
# row.operator("bim.add_unit", text="", icon="ADD")
|
||||||
row.operator("bim.disable_group_editing_ui", text="", icon="CANCEL")
|
row.operator("bim.disable_unit_editing_ui", text="", icon="CANCEL")
|
||||||
else:
|
else:
|
||||||
row.operator("bim.load_units", text="", icon="GREASEPENCIL")
|
row.operator("bim.load_units", text="", icon="GREASEPENCIL")
|
||||||
|
|
||||||
@@ -49,3 +49,4 @@ class BIM_UL_units(UIList):
|
|||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.label(text=item.unit_type or "No Type", icon=item.icon)
|
row.label(text=item.unit_type or "No Type", icon=item.icon)
|
||||||
row.label(text=item.name or "Unnamed")
|
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:
|
if not file:
|
||||||
return
|
return
|
||||||
cls.file = file
|
cls.file = file
|
||||||
|
cls.unit_assignment = []
|
||||||
|
cls.units = {}
|
||||||
unit_assignment = cls.file.by_type("IfcUnitAssignment")
|
unit_assignment = cls.file.by_type("IfcUnitAssignment")
|
||||||
if not unit_assignment:
|
if not unit_assignment:
|
||||||
return
|
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"])
|
||||||
Reference in New Issue
Block a user