mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-07 12:56:26 +00:00
You can now add cost items into a cost schedule, and as sub items to a parent cost item. Thanks myoualid and Jesusbill!
This commit is contained in:
@@ -7,8 +7,11 @@ classes = (
|
||||
operator.EditCostSchedule,
|
||||
operator.EnableEditingCostSchedule,
|
||||
operator.DisableEditingCostSchedule,
|
||||
operator.AddCostItem,
|
||||
prop.CostItem,
|
||||
prop.BIMCostProperties,
|
||||
ui.BIM_PT_cost_schedules,
|
||||
ui.BIM_UL_cost_items,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -36,11 +36,11 @@ class EnableEditingCostSchedule(bpy.types.Operator):
|
||||
cost_schedule: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.BIMCostProperties
|
||||
props.active_cost_schedule_id = self.cost_schedule
|
||||
self.props = context.scene.BIMCostProperties
|
||||
self.props.active_cost_schedule_id = self.cost_schedule
|
||||
|
||||
while len(props.cost_schedule_attributes) > 0:
|
||||
props.cost_schedule_attributes.remove(0)
|
||||
while len(self.props.cost_schedule_attributes) > 0:
|
||||
self.props.cost_schedule_attributes.remove(0)
|
||||
|
||||
data = Data.cost_schedules[self.cost_schedule]
|
||||
|
||||
@@ -48,7 +48,7 @@ class EnableEditingCostSchedule(bpy.types.Operator):
|
||||
data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
|
||||
if data_type == "entity":
|
||||
continue
|
||||
new = props.cost_schedule_attributes.add()
|
||||
new = self.props.cost_schedule_attributes.add()
|
||||
new.name = attribute.name()
|
||||
new.is_null = data[attribute.name()] is None
|
||||
new.is_optional = attribute.optional()
|
||||
@@ -61,8 +61,26 @@ class EnableEditingCostSchedule(bpy.types.Operator):
|
||||
new.enum_items = json.dumps(ifcopenshell.util.attribute.get_enum_items(attribute))
|
||||
if data[attribute.name()]:
|
||||
new.enum_value = data[attribute.name()]
|
||||
|
||||
while len(self.props.cost_items) > 0:
|
||||
self.props.cost_items.remove(0)
|
||||
|
||||
for related_object_id in Data.cost_schedules[self.cost_schedule]["RelatedObjects"]:
|
||||
self.create_new_cost_item_li(related_object_id, 0)
|
||||
return {"FINISHED"}
|
||||
|
||||
def create_new_cost_item_li(self, related_object_id, level_index):
|
||||
cost_item = Data.cost_items[related_object_id]
|
||||
new = self.props.cost_items.add()
|
||||
new.name = cost_item["Name"] or "Unnamed"
|
||||
new.ifc_definition_id = related_object_id
|
||||
new.is_expanded = False
|
||||
new.level_index = level_index
|
||||
if cost_item["RelatedObjects"]:
|
||||
new.has_children = True
|
||||
for related_object_id in cost_item["RelatedObjects"]:
|
||||
self.create_new_cost_item_li(related_object_id, level_index + 1)
|
||||
|
||||
|
||||
class DisableEditingCostSchedule(bpy.types.Operator):
|
||||
bl_idname = "bim.disable_editing_cost_schedule"
|
||||
@@ -98,3 +116,21 @@ class EditCostSchedule(bpy.types.Operator):
|
||||
Data.load(IfcStore.get_file())
|
||||
bpy.ops.bim.disable_editing_cost_schedule()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class AddCostItem(bpy.types.Operator):
|
||||
bl_idname = "bim.add_cost_item"
|
||||
bl_label = "Add Cost Item"
|
||||
cost_schedule: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.BIMCostProperties
|
||||
self.file = IfcStore.get_file()
|
||||
if len(props.cost_items):
|
||||
data = {"cost_item": self.file.by_id(props.cost_items[props.active_cost_item_index].ifc_definition_id)}
|
||||
else:
|
||||
data = {"cost_schedule": self.file.by_id(self.cost_schedule)}
|
||||
ifcopenshell.api.run("cost.add_cost_item", self.file, **data)
|
||||
Data.load(self.file)
|
||||
bpy.ops.bim.enable_editing_cost_schedule(cost_schedule = self.cost_schedule)
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -13,6 +13,16 @@ from bpy.props import (
|
||||
)
|
||||
|
||||
|
||||
class CostItem(PropertyGroup):
|
||||
name: StringProperty(name="Name")
|
||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||
has_children: BoolProperty(name="Has Children")
|
||||
is_expanded: BoolProperty(name="Is Expanded")
|
||||
level_index: IntProperty(name="Level Index")
|
||||
|
||||
|
||||
class BIMCostProperties(PropertyGroup):
|
||||
cost_schedule_attributes: CollectionProperty(name="Cost Schedule Attributes", type=Attribute)
|
||||
active_cost_schedule_id: IntProperty(name="Active Cost Schedule Id")
|
||||
cost_items: CollectionProperty(name="Work Calendar", type=CostItem)
|
||||
active_cost_item_index: IntProperty(name="Active Cost Item Index")
|
||||
|
||||
@@ -16,7 +16,7 @@ class BIM_PT_cost_schedules(Panel):
|
||||
return IfcStore.get_file()
|
||||
|
||||
def draw(self, context):
|
||||
props = context.scene.BIMCostProperties
|
||||
self.props = context.scene.BIMCostProperties
|
||||
|
||||
if not Data.is_loaded:
|
||||
Data.load(IfcStore.get_file())
|
||||
@@ -28,21 +28,53 @@ class BIM_PT_cost_schedules(Panel):
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text=cost_schedule["Name"] or "Unnamed", icon="LINENUMBERS_ON")
|
||||
|
||||
if props.active_cost_schedule_id and props.active_cost_schedule_id == cost_schedule_id:
|
||||
if self.props.active_cost_schedule_id and self.props.active_cost_schedule_id == cost_schedule_id:
|
||||
row.operator("bim.edit_cost_schedule", text="", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_cost_schedule", text="", icon="X")
|
||||
elif props.active_cost_schedule_id:
|
||||
elif self.props.active_cost_schedule_id:
|
||||
row.operator("bim.remove_cost_schedule", text="", icon="X").cost_schedule = cost_schedule_id
|
||||
else:
|
||||
row.operator("bim.enable_editing_cost_schedule", text="", icon="GREASEPENCIL").cost_schedule = cost_schedule_id
|
||||
row.operator("bim.remove_cost_schedule", text="", icon="X").cost_schedule = cost_schedule_id
|
||||
|
||||
if props.active_cost_schedule_id == cost_schedule_id:
|
||||
for attribute in props.cost_schedule_attributes:
|
||||
row = self.layout.row(align=True)
|
||||
if attribute.data_type == "string":
|
||||
row.prop(attribute, "string_value", text=attribute.name)
|
||||
elif attribute.data_type == "enum":
|
||||
row.prop(attribute, "enum_value", text=attribute.name)
|
||||
if attribute.is_optional:
|
||||
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
||||
if self.props.active_cost_schedule_id == cost_schedule_id:
|
||||
self.draw_editable_cost_schedule_ui(cost_schedule_id, cost_schedule)
|
||||
|
||||
def draw_editable_cost_schedule_ui(self, cost_schedule_id, cost_schedule):
|
||||
for attribute in self.props.cost_schedule_attributes:
|
||||
row = self.layout.row(align=True)
|
||||
if attribute.data_type == "string":
|
||||
row.prop(attribute, "string_value", text=attribute.name)
|
||||
elif attribute.data_type == "enum":
|
||||
row.prop(attribute, "enum_value", text=attribute.name)
|
||||
if attribute.is_optional:
|
||||
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
||||
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text="X Cost Items")
|
||||
row.operator("bim.add_cost_item", text="", icon="ADD").cost_schedule = cost_schedule_id
|
||||
|
||||
self.layout.template_list(
|
||||
"BIM_UL_cost_items",
|
||||
"",
|
||||
self.props,
|
||||
"cost_items",
|
||||
self.props,
|
||||
"active_cost_item_index",
|
||||
)
|
||||
|
||||
|
||||
class BIM_UL_cost_items(UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||
if item:
|
||||
row = layout.row(align=True)
|
||||
for i in range(0, item.level_index):
|
||||
row.label(text="", icon="BLANK1")
|
||||
if item.has_children:
|
||||
if item.is_expanded:
|
||||
row.operator("bim.edit_work_calendar", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN")
|
||||
else:
|
||||
row.operator("bim.edit_work_calendar", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT")
|
||||
else:
|
||||
row.label(text="", icon="DOT")
|
||||
row.label(text=item.name)
|
||||
|
||||
Reference in New Issue
Block a user