mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-29 08:13:14 +00:00
You can now add and edit monetary units, and basic editing of other unit types.
This commit is contained in:
@@ -236,7 +236,7 @@ class CreateDrawing(bpy.types.Operator):
|
||||
return svg_path
|
||||
# This is a work in progress. See #1153 and #1564.
|
||||
# Switch from old to new if you are testing v0.7.0
|
||||
self.generate_linework_old(svg_path)
|
||||
self.generate_linework_old(context, svg_path)
|
||||
# self.generate_linework_new(svg_path)
|
||||
return svg_path
|
||||
|
||||
@@ -266,7 +266,7 @@ class CreateDrawing(bpy.types.Operator):
|
||||
with open(svg_path, "w") as svg:
|
||||
svg.write(buffer.get_value())
|
||||
|
||||
def generate_linework_old(self, svg_path):
|
||||
def generate_linework_old(self, context, svg_path):
|
||||
ifcconvert_path = os.path.join(cwd, "..", "..", "..", "libs", "IfcConvert")
|
||||
subprocess.run(
|
||||
[
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.schema
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
from bpy.types import PropertyGroup
|
||||
from bpy.props import (
|
||||
@@ -82,17 +84,8 @@ def getIfcClasses(self, context):
|
||||
file = IfcStore.get_file()
|
||||
if len(classes_enum) < 1 and file:
|
||||
declaration = IfcStore.get_schema().declaration_by_name(context.scene.BIMRootProperties.ifc_product)
|
||||
|
||||
def get_classes(declaration):
|
||||
results = []
|
||||
if not declaration.is_abstract():
|
||||
results.append(declaration.name())
|
||||
for subtype in declaration.subtypes():
|
||||
results.extend(get_classes(subtype))
|
||||
return results
|
||||
|
||||
classes = get_classes(declaration)
|
||||
classes_enum.extend([(c, c, "") for c in sorted(classes)])
|
||||
declarations = ifcopenshell.util.schema.get_subtypes(declaration)
|
||||
classes_enum.extend([(c, c, "") for c in sorted([d.name() for d in declarations])])
|
||||
return classes_enum
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,10 @@ classes = (
|
||||
operator.LoadUnits,
|
||||
operator.DisableUnitEditingUI,
|
||||
operator.RemoveUnit,
|
||||
operator.AddMonetaryUnit,
|
||||
operator.EnableEditingUnit,
|
||||
operator.DisableEditingUnit,
|
||||
operator.EditUnit,
|
||||
prop.Unit,
|
||||
prop.BIMUnitProperties,
|
||||
ui.BIM_PT_units,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import bpy
|
||||
import ifcopenshell.api
|
||||
import blenderbim.bim.helper
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
from ifcopenshell.api.unit.data import Data
|
||||
|
||||
@@ -78,6 +79,8 @@ class LoadUnits(bpy.types.Operator):
|
||||
unit_type = unit.get("UserDefinedType", None)
|
||||
if not unit_type:
|
||||
unit_type = unit.get("UnitType", None)
|
||||
if unit["type"] == "IfcMonetaryUnit":
|
||||
unit_type = "CURRENCY"
|
||||
|
||||
new = props.units.add()
|
||||
new.ifc_definition_id = ifc_definition_id
|
||||
@@ -86,7 +89,7 @@ class LoadUnits(bpy.types.Operator):
|
||||
new.icon = icon
|
||||
|
||||
props.is_editing = True
|
||||
# bpy.ops.bim.disable_editing_unit()
|
||||
bpy.ops.bim.disable_editing_unit()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -116,3 +119,73 @@ class RemoveUnit(bpy.types.Operator):
|
||||
Data.load(self.file)
|
||||
bpy.ops.bim.load_units()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class AddMonetaryUnit(bpy.types.Operator):
|
||||
bl_idname = "bim.add_monetary_unit"
|
||||
bl_label = "Add Monetary Unit"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
return IfcStore.execute_ifc_operator(self, context)
|
||||
|
||||
def _execute(self, context):
|
||||
props = context.scene.BIMUnitProperties
|
||||
self.file = IfcStore.get_file()
|
||||
unit = ifcopenshell.api.run("unit.add_monetary_unit", self.file)
|
||||
ifcopenshell.api.run("unit.assign_unit", self.file, units=[unit])
|
||||
Data.load(self.file)
|
||||
bpy.ops.bim.load_units()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class EnableEditingUnit(bpy.types.Operator):
|
||||
bl_idname = "bim.enable_editing_unit"
|
||||
bl_label = "Enable Editing Unit"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
unit: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.BIMUnitProperties
|
||||
while len(props.unit_attributes) > 0:
|
||||
props.unit_attributes.remove(0)
|
||||
|
||||
data = Data.units[self.unit]
|
||||
|
||||
blenderbim.bim.helper.import_attributes(data["type"], props.unit_attributes, data)
|
||||
props.active_unit_id = self.unit
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class DisableEditingUnit(bpy.types.Operator):
|
||||
bl_idname = "bim.disable_editing_unit"
|
||||
bl_label = "Disable Editing Unit"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
context.scene.BIMUnitProperties.active_unit_id = 0
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class EditUnit(bpy.types.Operator):
|
||||
bl_idname = "bim.edit_unit"
|
||||
bl_label = "Edit Unit"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
return IfcStore.execute_ifc_operator(self, context)
|
||||
|
||||
def _execute(self, context):
|
||||
props = context.scene.BIMUnitProperties
|
||||
attributes = blenderbim.bim.helper.export_attributes(props.unit_attributes)
|
||||
self.file = IfcStore.get_file()
|
||||
unit = self.file.by_id(props.active_unit_id)
|
||||
if unit.is_a("IfcMonetaryUnit"):
|
||||
ifcopenshell.api.run("unit.edit_monetary_unit", self.file, **{"unit": unit, "attributes": attributes})
|
||||
elif unit.is_a("IfcDerivedUnit"):
|
||||
ifcopenshell.api.run("unit.edit_derived_unit", self.file, **{"unit": unit, "attributes": attributes})
|
||||
elif unit.is_a("IfcNamedUnit"):
|
||||
ifcopenshell.api.run("unit.edit_named_unit", self.file, **{"unit": unit, "attributes": attributes})
|
||||
Data.load(IfcStore.get_file())
|
||||
bpy.ops.bim.load_units()
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.schema
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
from blenderbim.bim.prop import StrProperty, Attribute
|
||||
from bpy.types import PropertyGroup
|
||||
from bpy.props import (
|
||||
@@ -13,6 +16,23 @@ from bpy.props import (
|
||||
)
|
||||
|
||||
|
||||
unitclasses_enum = []
|
||||
|
||||
|
||||
def purge():
|
||||
global unitclasses_enum
|
||||
unitclasses_enum = []
|
||||
|
||||
|
||||
def getUnitClasses(self, context):
|
||||
global unitclasses_enum
|
||||
if not len(unitclasses_enum) and IfcStore.get_file():
|
||||
declarations = ifcopenshell.util.schema.get_subtypes(IfcStore.get_schema().declaration_by_name("IfcNamedUnit"))
|
||||
unitclasses_enum.extend([(c, c, "") for c in sorted([d.name() for d in declarations])])
|
||||
unitclasses_enum.extend([("IfcDerivedUnit", "IfcDerivedUnit", ""), ("IfcMonetaryUnit", "IfcMonetaryUnit", "")])
|
||||
return unitclasses_enum
|
||||
|
||||
|
||||
class Unit(PropertyGroup):
|
||||
name: StringProperty(name="Name")
|
||||
unit_type: StringProperty(name="Unit Type")
|
||||
@@ -24,3 +44,6 @@ class BIMUnitProperties(PropertyGroup):
|
||||
is_editing: BoolProperty(name="Is Editing")
|
||||
units: CollectionProperty(name="Units", type=Unit)
|
||||
active_unit_index: IntProperty(name="Active Unit Index")
|
||||
active_unit_id: IntProperty(name="Active Unit Id")
|
||||
unit_classes: EnumProperty(items=getUnitClasses, name="Unit Classes")
|
||||
unit_attributes: CollectionProperty(name="Unit Attributes", type=Attribute)
|
||||
|
||||
@@ -26,20 +26,37 @@ 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_unit", text="", icon="ADD")
|
||||
row.operator("bim.disable_unit_editing_ui", text="", icon="CANCEL")
|
||||
else:
|
||||
row.operator("bim.load_units", text="", icon="GREASEPENCIL")
|
||||
|
||||
if self.props.is_editing:
|
||||
self.layout.template_list(
|
||||
"BIM_UL_units",
|
||||
"",
|
||||
self.props,
|
||||
"units",
|
||||
self.props,
|
||||
"active_unit_index",
|
||||
)
|
||||
if not self.props.is_editing:
|
||||
return
|
||||
|
||||
row = self.layout.row(align=True)
|
||||
row.prop(self.props, "unit_classes", text="")
|
||||
|
||||
if self.props.unit_classes == "IfcMonetaryUnit":
|
||||
row.operator("bim.add_monetary_unit", text="", icon="ADD")
|
||||
elif self.props.unit_classes == "IfcDerivedUnit":
|
||||
pass # TODO
|
||||
else:
|
||||
pass # TODO
|
||||
|
||||
self.layout.template_list(
|
||||
"BIM_UL_units",
|
||||
"",
|
||||
self.props,
|
||||
"units",
|
||||
self.props,
|
||||
"active_unit_index",
|
||||
)
|
||||
|
||||
if self.props.active_unit_id:
|
||||
self.draw_editable_ui(context)
|
||||
|
||||
def draw_editable_ui(self, context):
|
||||
blenderbim.bim.helper.draw_attributes(self.props.unit_attributes, self.layout)
|
||||
|
||||
|
||||
class BIM_UL_units(UIList):
|
||||
@@ -49,4 +66,13 @@ 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
|
||||
|
||||
if props.active_unit_id == item.ifc_definition_id:
|
||||
row.operator("bim.edit_unit", text="", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_unit", text="", icon="CANCEL")
|
||||
elif props.active_unit_id:
|
||||
row.operator("bim.remove_unit", text="", icon="X").unit = item.ifc_definition_id
|
||||
else:
|
||||
op = row.operator("bim.enable_editing_unit", text="", icon="GREASEPENCIL")
|
||||
op.unit = item.ifc_definition_id
|
||||
row.operator("bim.remove_unit", text="", icon="X").unit = item.ifc_definition_id
|
||||
|
||||
Reference in New Issue
Block a user