mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 08:45:22 +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.EditCostSchedule,
|
||||||
operator.EnableEditingCostSchedule,
|
operator.EnableEditingCostSchedule,
|
||||||
operator.DisableEditingCostSchedule,
|
operator.DisableEditingCostSchedule,
|
||||||
|
operator.AddCostItem,
|
||||||
|
prop.CostItem,
|
||||||
prop.BIMCostProperties,
|
prop.BIMCostProperties,
|
||||||
ui.BIM_PT_cost_schedules,
|
ui.BIM_PT_cost_schedules,
|
||||||
|
ui.BIM_UL_cost_items,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,11 +36,11 @@ class EnableEditingCostSchedule(bpy.types.Operator):
|
|||||||
cost_schedule: bpy.props.IntProperty()
|
cost_schedule: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
props = context.scene.BIMCostProperties
|
self.props = context.scene.BIMCostProperties
|
||||||
props.active_cost_schedule_id = self.cost_schedule
|
self.props.active_cost_schedule_id = self.cost_schedule
|
||||||
|
|
||||||
while len(props.cost_schedule_attributes) > 0:
|
while len(self.props.cost_schedule_attributes) > 0:
|
||||||
props.cost_schedule_attributes.remove(0)
|
self.props.cost_schedule_attributes.remove(0)
|
||||||
|
|
||||||
data = Data.cost_schedules[self.cost_schedule]
|
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)
|
data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
|
||||||
if data_type == "entity":
|
if data_type == "entity":
|
||||||
continue
|
continue
|
||||||
new = props.cost_schedule_attributes.add()
|
new = self.props.cost_schedule_attributes.add()
|
||||||
new.name = attribute.name()
|
new.name = attribute.name()
|
||||||
new.is_null = data[attribute.name()] is None
|
new.is_null = data[attribute.name()] is None
|
||||||
new.is_optional = attribute.optional()
|
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))
|
new.enum_items = json.dumps(ifcopenshell.util.attribute.get_enum_items(attribute))
|
||||||
if data[attribute.name()]:
|
if data[attribute.name()]:
|
||||||
new.enum_value = 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"}
|
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):
|
class DisableEditingCostSchedule(bpy.types.Operator):
|
||||||
bl_idname = "bim.disable_editing_cost_schedule"
|
bl_idname = "bim.disable_editing_cost_schedule"
|
||||||
@@ -98,3 +116,21 @@ class EditCostSchedule(bpy.types.Operator):
|
|||||||
Data.load(IfcStore.get_file())
|
Data.load(IfcStore.get_file())
|
||||||
bpy.ops.bim.disable_editing_cost_schedule()
|
bpy.ops.bim.disable_editing_cost_schedule()
|
||||||
return {"FINISHED"}
|
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):
|
class BIMCostProperties(PropertyGroup):
|
||||||
cost_schedule_attributes: CollectionProperty(name="Cost Schedule Attributes", type=Attribute)
|
cost_schedule_attributes: CollectionProperty(name="Cost Schedule Attributes", type=Attribute)
|
||||||
active_cost_schedule_id: IntProperty(name="Active Cost Schedule Id")
|
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()
|
return IfcStore.get_file()
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
props = context.scene.BIMCostProperties
|
self.props = context.scene.BIMCostProperties
|
||||||
|
|
||||||
if not Data.is_loaded:
|
if not Data.is_loaded:
|
||||||
Data.load(IfcStore.get_file())
|
Data.load(IfcStore.get_file())
|
||||||
@@ -28,21 +28,53 @@ class BIM_PT_cost_schedules(Panel):
|
|||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
row.label(text=cost_schedule["Name"] or "Unnamed", icon="LINENUMBERS_ON")
|
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.edit_cost_schedule", text="", icon="CHECKMARK")
|
||||||
row.operator("bim.disable_editing_cost_schedule", text="", icon="X")
|
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
|
row.operator("bim.remove_cost_schedule", text="", icon="X").cost_schedule = cost_schedule_id
|
||||||
else:
|
else:
|
||||||
row.operator("bim.enable_editing_cost_schedule", text="", icon="GREASEPENCIL").cost_schedule = cost_schedule_id
|
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
|
row.operator("bim.remove_cost_schedule", text="", icon="X").cost_schedule = cost_schedule_id
|
||||||
|
|
||||||
if props.active_cost_schedule_id == cost_schedule_id:
|
if self.props.active_cost_schedule_id == cost_schedule_id:
|
||||||
for attribute in props.cost_schedule_attributes:
|
self.draw_editable_cost_schedule_ui(cost_schedule_id, cost_schedule)
|
||||||
row = self.layout.row(align=True)
|
|
||||||
if attribute.data_type == "string":
|
def draw_editable_cost_schedule_ui(self, cost_schedule_id, cost_schedule):
|
||||||
row.prop(attribute, "string_value", text=attribute.name)
|
for attribute in self.props.cost_schedule_attributes:
|
||||||
elif attribute.data_type == "enum":
|
row = self.layout.row(align=True)
|
||||||
row.prop(attribute, "enum_value", text=attribute.name)
|
if attribute.data_type == "string":
|
||||||
if attribute.is_optional:
|
row.prop(attribute, "string_value", text=attribute.name)
|
||||||
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
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)
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import ifcopenshell.api
|
||||||
|
|
||||||
|
|
||||||
|
class Usecase:
|
||||||
|
def __init__(self, file, **settings):
|
||||||
|
self.file = file
|
||||||
|
self.settings = {"cost_schedule": None, "cost_item": None}
|
||||||
|
for key, value in settings.items():
|
||||||
|
self.settings[key] = value
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
cost_item = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcCostItem")
|
||||||
|
|
||||||
|
if self.settings["cost_schedule"]:
|
||||||
|
self.file.create_entity(
|
||||||
|
"IfcRelAssignsToControl",
|
||||||
|
**{
|
||||||
|
"GlobalId": ifcopenshell.guid.new(),
|
||||||
|
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||||
|
"RelatedObjects": [cost_item],
|
||||||
|
"RelatingControl": self.settings["cost_schedule"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
elif self.settings["cost_item"]:
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"nest.assign_object", self.file, object=cost_item, relating_object=self.settings["cost_item"]
|
||||||
|
)
|
||||||
|
return cost_item
|
||||||
@@ -4,15 +4,19 @@ import ifcopenshell.util.date
|
|||||||
class Data:
|
class Data:
|
||||||
is_loaded = False
|
is_loaded = False
|
||||||
cost_schedules = {}
|
cost_schedules = {}
|
||||||
|
cost_items = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def purge(cls):
|
def purge(cls):
|
||||||
cls.is_loaded = False
|
cls.is_loaded = False
|
||||||
cls.cost_schedules = {}
|
cls.cost_schedules = {}
|
||||||
|
cls.cost_items = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, file):
|
def load(cls, file):
|
||||||
cls.cost_schedules = {}
|
cls.cost_schedules = {}
|
||||||
|
cls.cost_items = {}
|
||||||
|
|
||||||
for cost_schedule in file.by_type("IfcCostSchedule"):
|
for cost_schedule in file.by_type("IfcCostSchedule"):
|
||||||
data = cost_schedule.get_info()
|
data = cost_schedule.get_info()
|
||||||
del data["OwnerHistory"]
|
del data["OwnerHistory"]
|
||||||
@@ -20,5 +24,21 @@ class Data:
|
|||||||
data["SubmittedOn"] = ifcopenshell.util.date.ifc2datetime(data["SubmittedOn"])
|
data["SubmittedOn"] = ifcopenshell.util.date.ifc2datetime(data["SubmittedOn"])
|
||||||
if data["UpdateDate"]:
|
if data["UpdateDate"]:
|
||||||
data["UpdateDate"] = ifcopenshell.util.date.ifc2datetime(data["UpdateDate"])
|
data["UpdateDate"] = ifcopenshell.util.date.ifc2datetime(data["UpdateDate"])
|
||||||
|
data["RelatedObjects"] = []
|
||||||
|
for rel in cost_schedule.Controls:
|
||||||
|
for related_object in rel.RelatedObjects:
|
||||||
|
if related_object.is_a("IfcCostItem"):
|
||||||
|
data["RelatedObjects"].append(related_object.id())
|
||||||
|
break # We are only allowed one summary cost item
|
||||||
cls.cost_schedules[cost_schedule.id()] = data
|
cls.cost_schedules[cost_schedule.id()] = data
|
||||||
|
|
||||||
|
for cost_item in file.by_type("IfcCostItem"):
|
||||||
|
data = cost_item.get_info()
|
||||||
|
del data["OwnerHistory"]
|
||||||
|
del data["CostValues"]
|
||||||
|
del data["CostQuantities"]
|
||||||
|
data["RelatedObjects"] = []
|
||||||
|
for rel in cost_item.IsNestedBy:
|
||||||
|
[data["RelatedObjects"].append(o.id()) for o in rel.RelatedObjects if o.is_a("IfcCostItem")]
|
||||||
|
cls.cost_items[cost_item.id()] = data
|
||||||
cls.is_loaded=True
|
cls.is_loaded=True
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import ifcopenshell
|
||||||
|
import ifcopenshell.api
|
||||||
|
|
||||||
|
|
||||||
|
class Usecase:
|
||||||
|
def __init__(self, file, **settings):
|
||||||
|
self.file = file
|
||||||
|
self.settings = {
|
||||||
|
"object": None,
|
||||||
|
"relating_object": None,
|
||||||
|
}
|
||||||
|
for key, value in settings.items():
|
||||||
|
self.settings[key] = value
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
nests = None
|
||||||
|
if self.settings["object"].Nests:
|
||||||
|
nests = self.settings["object"].Nests[0]
|
||||||
|
|
||||||
|
is_nested_by = None
|
||||||
|
for rel in self.settings["relating_object"].IsNestedBy:
|
||||||
|
if rel.is_a("IfcRelNests"):
|
||||||
|
is_nested_by = rel
|
||||||
|
break
|
||||||
|
|
||||||
|
if nests and nests == is_nested_by:
|
||||||
|
return
|
||||||
|
|
||||||
|
if nests:
|
||||||
|
related_objects = list(nests.RelatedObjects)
|
||||||
|
related_objects.remove(self.settings["object"])
|
||||||
|
if related_objects:
|
||||||
|
nests.RelatedObjects = related_objects
|
||||||
|
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": nests})
|
||||||
|
else:
|
||||||
|
self.file.remove(nests)
|
||||||
|
|
||||||
|
if is_nested_by:
|
||||||
|
related_objects = list(is_nested_by.RelatedObjects)
|
||||||
|
related_objects.append(self.settings["object"])
|
||||||
|
is_nested_by.RelatedObjects = related_objects
|
||||||
|
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": is_nested_by})
|
||||||
|
else:
|
||||||
|
is_nested_by = self.file.create_entity(
|
||||||
|
"IfcRelNests",
|
||||||
|
**{
|
||||||
|
"GlobalId": ifcopenshell.guid.new(),
|
||||||
|
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||||
|
"RelatedObjects": [self.settings["object"]],
|
||||||
|
"RelatingObject": self.settings["relating_object"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return is_nested_by
|
||||||
Reference in New Issue
Block a user