mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
New feature to toggle default project unit assignment
This commit is contained in:
@@ -38,6 +38,7 @@ def import_attributes(ifc_class, props, data, callback=None):
|
|||||||
for attribute in IfcStore.get_schema().declaration_by_name(ifc_class).all_attributes():
|
for attribute in IfcStore.get_schema().declaration_by_name(ifc_class).all_attributes():
|
||||||
data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
|
data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
|
||||||
if data_type == "entity" or (isinstance(data_type, tuple) and "entity" in ".".join(data_type)):
|
if data_type == "entity" or (isinstance(data_type, tuple) and "entity" in ".".join(data_type)):
|
||||||
|
callback(attribute.name(), None, data) if callback else None
|
||||||
continue
|
continue
|
||||||
new = props.add()
|
new = props.add()
|
||||||
new.name = attribute.name()
|
new.name = attribute.name()
|
||||||
@@ -65,20 +66,21 @@ def import_attributes(ifc_class, props, data, callback=None):
|
|||||||
|
|
||||||
def export_attributes(props, callback=None):
|
def export_attributes(props, callback=None):
|
||||||
attributes = {}
|
attributes = {}
|
||||||
for attribute in props:
|
for prop in props:
|
||||||
is_handled_by_callback = callback(attributes, attribute) if callback else False
|
is_handled_by_callback = callback(attributes, prop) if callback else False
|
||||||
if attribute.is_null:
|
if is_handled_by_callback:
|
||||||
attributes[attribute.name] = None
|
continue # Our job is done
|
||||||
elif is_handled_by_callback:
|
|
||||||
pass # Our job is done
|
if prop.is_null:
|
||||||
elif attribute.data_type == "string":
|
attributes[prop.name] = None
|
||||||
attributes[attribute.name] = attribute.string_value
|
elif prop.data_type == "string":
|
||||||
elif attribute.data_type == "boolean":
|
attributes[prop.name] = prop.string_value
|
||||||
attributes[attribute.name] = attribute.bool_value
|
elif prop.data_type == "boolean":
|
||||||
elif attribute.data_type == "integer":
|
attributes[prop.name] = prop.bool_value
|
||||||
attributes[attribute.name] = attribute.int_value
|
elif prop.data_type == "integer":
|
||||||
elif attribute.data_type == "float":
|
attributes[prop.name] = prop.int_value
|
||||||
attributes[attribute.name] = attribute.float_value
|
elif prop.data_type == "float":
|
||||||
elif attribute.data_type == "enum":
|
attributes[prop.name] = prop.float_value
|
||||||
attributes[attribute.name] = attribute.enum_value
|
elif prop.data_type == "enum":
|
||||||
|
attributes[prop.name] = prop.enum_value
|
||||||
return attributes
|
return attributes
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from . import ui, prop, operator
|
|||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
operator.AssignUnit,
|
operator.AssignUnit,
|
||||||
|
operator.UnassignUnit,
|
||||||
operator.LoadUnits,
|
operator.LoadUnits,
|
||||||
operator.DisableUnitEditingUI,
|
operator.DisableUnitEditingUI,
|
||||||
operator.RemoveUnit,
|
operator.RemoveUnit,
|
||||||
|
|||||||
@@ -9,13 +9,20 @@ class AssignUnit(bpy.types.Operator):
|
|||||||
bl_idname = "bim.assign_unit"
|
bl_idname = "bim.assign_unit"
|
||||||
bl_label = "Assign Unit"
|
bl_label = "Assign Unit"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
unit: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
return IfcStore.execute_ifc_operator(self, context)
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
ifcopenshell.api.run("unit.assign_unit", IfcStore.get_file(), **self.get_units(context))
|
self.file = IfcStore.get_file()
|
||||||
Data.load(IfcStore.get_file())
|
if self.unit:
|
||||||
|
ifcopenshell.api.run("unit.assign_unit", self.file, units=[self.file.by_id(self.unit)])
|
||||||
|
else:
|
||||||
|
ifcopenshell.api.run("unit.assign_unit", self.file, **self.get_units(context))
|
||||||
|
Data.load(self.file)
|
||||||
|
if self.unit:
|
||||||
|
bpy.ops.bim.load_units()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def get_units(self, context):
|
def get_units(self, context):
|
||||||
@@ -46,6 +53,23 @@ class AssignUnit(bpy.types.Operator):
|
|||||||
return units
|
return units
|
||||||
|
|
||||||
|
|
||||||
|
class UnassignUnit(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.unassign_unit"
|
||||||
|
bl_label = "Unassign Unit"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
unit: bpy.props.IntProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
return IfcStore.execute_ifc_operator(self, context)
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
self.file = IfcStore.get_file()
|
||||||
|
ifcopenshell.api.run("unit.unassign_unit", IfcStore.get_file(), units=[self.file.by_id(self.unit)])
|
||||||
|
Data.load(self.file)
|
||||||
|
bpy.ops.bim.load_units()
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class LoadUnits(bpy.types.Operator):
|
class LoadUnits(bpy.types.Operator):
|
||||||
bl_idname = "bim.load_units"
|
bl_idname = "bim.load_units"
|
||||||
bl_label = "Load Units"
|
bl_label = "Load Units"
|
||||||
@@ -56,8 +80,7 @@ class LoadUnits(bpy.types.Operator):
|
|||||||
while len(props.units) > 0:
|
while len(props.units) > 0:
|
||||||
props.units.remove(0)
|
props.units.remove(0)
|
||||||
|
|
||||||
for ifc_definition_id in Data.unit_assignment:
|
for ifc_definition_id, unit in Data.units.items():
|
||||||
unit = Data.units[ifc_definition_id]
|
|
||||||
name = unit.get("Name", "")
|
name = unit.get("Name", "")
|
||||||
|
|
||||||
if unit["type"] == "IfcMonetaryUnit":
|
if unit["type"] == "IfcMonetaryUnit":
|
||||||
@@ -86,6 +109,7 @@ class LoadUnits(bpy.types.Operator):
|
|||||||
new.ifc_definition_id = ifc_definition_id
|
new.ifc_definition_id = ifc_definition_id
|
||||||
new.name = name
|
new.name = name
|
||||||
new.unit_type = unit_type
|
new.unit_type = unit_type
|
||||||
|
new.is_assigned = ifc_definition_id in Data.unit_assignment
|
||||||
new.icon = icon
|
new.icon = icon
|
||||||
|
|
||||||
props.is_editing = True
|
props.is_editing = True
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ def getUnitClasses(self, context):
|
|||||||
class Unit(PropertyGroup):
|
class Unit(PropertyGroup):
|
||||||
name: StringProperty(name="Name")
|
name: StringProperty(name="Name")
|
||||||
unit_type: StringProperty(name="Unit Type")
|
unit_type: StringProperty(name="Unit Type")
|
||||||
|
is_assigned: BoolProperty(name="Is Assigned")
|
||||||
icon: StringProperty(name="Icon")
|
icon: StringProperty(name="Icon")
|
||||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,13 @@ class BIM_UL_units(UIList):
|
|||||||
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")
|
||||||
|
|
||||||
|
if item.is_assigned:
|
||||||
|
op = row.operator("bim.unassign_unit", text="", icon="KEYFRAME_HLT", emboss=False)
|
||||||
|
op.unit = item.ifc_definition_id
|
||||||
|
else:
|
||||||
|
op = row.operator("bim.assign_unit", text="", icon="KEYFRAME", emboss=False)
|
||||||
|
op.unit = item.ifc_definition_id
|
||||||
|
|
||||||
if props.active_unit_id == item.ifc_definition_id:
|
if props.active_unit_id == item.ifc_definition_id:
|
||||||
row.operator("bim.edit_unit", text="", icon="CHECKMARK")
|
row.operator("bim.edit_unit", text="", icon="CHECKMARK")
|
||||||
row.operator("bim.disable_editing_unit", text="", icon="CANCEL")
|
row.operator("bim.disable_editing_unit", text="", icon="CANCEL")
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ class Data:
|
|||||||
return
|
return
|
||||||
for unit in unit_assignment[0].Units:
|
for unit in unit_assignment[0].Units:
|
||||||
cls.unit_assignment.append(unit.id())
|
cls.unit_assignment.append(unit.id())
|
||||||
|
for unit in (
|
||||||
|
cls.file.by_type("IfcDerivedUnit") + cls.file.by_type("IfcNamedUnit") + cls.file.by_type("IfcMonetaryUnit")
|
||||||
|
):
|
||||||
cls.load_unit(unit)
|
cls.load_unit(unit)
|
||||||
cls.is_loaded = True
|
cls.is_loaded = True
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
class Usecase:
|
||||||
|
def __init__(self, file, **settings):
|
||||||
|
self.file = file
|
||||||
|
self.settings = {"units": None}
|
||||||
|
for key, value in settings.items():
|
||||||
|
self.settings[key] = value
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
unit_assignment = self.file.by_type("IfcUnitAssignment")
|
||||||
|
if not unit_assignment:
|
||||||
|
return
|
||||||
|
unit_assignment = unit_assignment[0]
|
||||||
|
units = set(unit_assignment.Units or [])
|
||||||
|
units = units - set(self.settings["units"])
|
||||||
|
if units:
|
||||||
|
unit_assignment.Units = list(units)
|
||||||
|
return unit_assignment
|
||||||
@@ -29,6 +29,8 @@ class Patcher:
|
|||||||
self.args = args
|
self.args = args
|
||||||
|
|
||||||
def patch(self):
|
def patch(self):
|
||||||
|
if self.file.schema == "IFC2X3":
|
||||||
|
return
|
||||||
curve_map = {}
|
curve_map = {}
|
||||||
|
|
||||||
for curve in self.file.by_type("IfcIndexedPolyCurve"):
|
for curve in self.file.by_type("IfcIndexedPolyCurve"):
|
||||||
|
|||||||
Reference in New Issue
Block a user