mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 09:32:37 +00:00
Feature to calculate required resources
This commit is contained in:
@@ -41,6 +41,7 @@ classes = (
|
|||||||
operator.EnableEditingResourceBaseQuantity,
|
operator.EnableEditingResourceBaseQuantity,
|
||||||
operator.EnableEditingResourceCosts,
|
operator.EnableEditingResourceCosts,
|
||||||
operator.EnableEditingResourceCostValue,
|
operator.EnableEditingResourceCostValue,
|
||||||
|
operator.CalculateResourceUsage,
|
||||||
operator.EnableEditingResourceCostValueFormula,
|
operator.EnableEditingResourceCostValueFormula,
|
||||||
operator.EnableEditingResourceQuantity,
|
operator.EnableEditingResourceQuantity,
|
||||||
operator.EnableEditingResourceTime,
|
operator.EnableEditingResourceTime,
|
||||||
|
|||||||
@@ -80,10 +80,10 @@ class ResourceData:
|
|||||||
results[resource.id()]["ScheduleWork"] = (
|
results[resource.id()]["ScheduleWork"] = (
|
||||||
ifcopenshell.util.date.readable_ifc_duration(resource.Usage.ScheduleWork)
|
ifcopenshell.util.date.readable_ifc_duration(resource.Usage.ScheduleWork)
|
||||||
if resource.Usage.ScheduleWork
|
if resource.Usage.ScheduleWork
|
||||||
else "Calculate",
|
else None
|
||||||
)
|
)
|
||||||
results[resource.id()]["ScheduleUsage"] = (
|
results[resource.id()]["ScheduleUsage"] = (
|
||||||
resource.Usage.ScheduleUsage if resource.Usage.ScheduleUsage else ""
|
resource.Usage.ScheduleUsage if resource.Usage.ScheduleUsage else None
|
||||||
)
|
)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|||||||
@@ -401,3 +401,23 @@ class GoToResource(bpy.types.Operator):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
core.go_to_resource(tool.Resource, resource=tool.Ifc.get().by_id(self.resource))
|
core.go_to_resource(tool.Resource, resource=tool.Ifc.get().by_id(self.resource))
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class CalculateResourceUsage(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
|
bl_idname = "bim.calculate_resource_usage"
|
||||||
|
bl_label = "Calculate Resource Usage"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
resource: bpy.props.IntProperty()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
active_resource = tool.Resource.get_highlighted_resource()
|
||||||
|
if active_resource:
|
||||||
|
if active_resource.Usage and active_resource.Usage.ScheduleWork:
|
||||||
|
task = tool.Resource.get_task_assignments(active_resource)
|
||||||
|
if task and tool.Sequence.has_duration(task):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
core.calculate_resource_usage(tool.Ifc, tool.Resource, resource=tool.Ifc.get().by_id(self.resource))
|
||||||
|
|||||||
@@ -88,9 +88,7 @@ def updateResourceUsage(self, context):
|
|||||||
if self.schedule_usage == "":
|
if self.schedule_usage == "":
|
||||||
return
|
return
|
||||||
resource = tool.Ifc.get().by_id(self.ifc_definition_id)
|
resource = tool.Ifc.get().by_id(self.ifc_definition_id)
|
||||||
tool.Resource.run_edit_resource_time(resource, attributes={
|
tool.Resource.run_edit_resource_time(resource, attributes={"ScheduleUsage": self.schedule_usage})
|
||||||
"ScheduleUsage": self.schedule_usage
|
|
||||||
})
|
|
||||||
tool.Resource.load_resource_properties()
|
tool.Resource.load_resource_properties()
|
||||||
tool.Sequence.load_task_properties()
|
tool.Sequence.load_task_properties()
|
||||||
blenderbim.bim.module.resource.data.refresh()
|
blenderbim.bim.module.resource.data.refresh()
|
||||||
@@ -98,6 +96,7 @@ def updateResourceUsage(self, context):
|
|||||||
tool.Sequence.refresh_task_resources()
|
tool.Sequence.refresh_task_resources()
|
||||||
blenderbim.bim.module.pset.data.refresh()
|
blenderbim.bim.module.pset.data.refresh()
|
||||||
|
|
||||||
|
|
||||||
class ISODuration(PropertyGroup):
|
class ISODuration(PropertyGroup):
|
||||||
name: StringProperty(name="Name")
|
name: StringProperty(name="Name")
|
||||||
years: IntProperty(name="Years", default=0)
|
years: IntProperty(name="Years", default=0)
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ class BIM_PT_resources(Panel):
|
|||||||
self.draw_editable_resource_time_attributes_ui()
|
self.draw_editable_resource_time_attributes_ui()
|
||||||
|
|
||||||
def draw_productivity_ui(self, context):
|
def draw_productivity_ui(self, context):
|
||||||
|
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
row.alignment = "RIGHT"
|
row.alignment = "RIGHT"
|
||||||
row.prop(self.props, "should_show_resource_tools", text="Resource Tools",icon="RECOVER_LAST")
|
row.prop(self.props, "should_show_resource_tools", text="Resource Tools",icon="RECOVER_LAST")
|
||||||
@@ -137,6 +136,7 @@ class BIM_PT_resources(Panel):
|
|||||||
row2col2 = col2.row()
|
row2col2 = col2.row()
|
||||||
row2col2.prop(self.tprops.resources[self.props.active_resource_index], "schedule_usage", text="")
|
row2col2.prop(self.tprops.resources[self.props.active_resource_index], "schedule_usage", text="")
|
||||||
row2col3 = col3.row()
|
row2col3 = col3.row()
|
||||||
|
row2col3.operator("bim.calculate_resource_usage", text="", icon="TEMP").resource = ifc_definition_id
|
||||||
op = row2col3.operator(
|
op = row2col3.operator(
|
||||||
"bim.add_usage_constraint" if not is_usage_locked else "bim.remove_usage_constraint",
|
"bim.add_usage_constraint" if not is_usage_locked else "bim.remove_usage_constraint",
|
||||||
text="",
|
text="",
|
||||||
|
|||||||
@@ -217,3 +217,8 @@ def remove_usage_constraint(ifc, resource_tool, resource, reference_path):
|
|||||||
|
|
||||||
def go_to_resource(resource_tool, resource):
|
def go_to_resource(resource_tool, resource):
|
||||||
resource_tool.go_to_resource(resource)
|
resource_tool.go_to_resource(resource)
|
||||||
|
|
||||||
|
def calculate_resource_usage(ifc, resource_tool, resource):
|
||||||
|
ifc.run("resource.calculate_resource_usage", resource=resource)
|
||||||
|
resource_tool.load_resources()
|
||||||
|
resource_tool.load_resource_properties()
|
||||||
@@ -435,3 +435,12 @@ class Resource(blenderbim.core.tool.Resource):
|
|||||||
resource_props = bpy.context.scene.BIMResourceTreeProperties
|
resource_props = bpy.context.scene.BIMResourceTreeProperties
|
||||||
expanded_resources = [item.ifc_definition_id for item in resource_props.resources]
|
expanded_resources = [item.ifc_definition_id for item in resource_props.resources]
|
||||||
bpy.context.scene.BIMResourceProperties.active_resource_index = expanded_resources.index(resource.id())
|
bpy.context.scene.BIMResourceProperties.active_resource_index = expanded_resources.index(resource.id())
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def run_calculate_resource_usage(cls, resource):
|
||||||
|
tool.Ifc.run("resource.calculate_resource_usage", resource=resource)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_task_assignments(cls, resource):
|
||||||
|
return ifcopenshell.util.resource.get_task_assignments(resource)
|
||||||
|
|||||||
@@ -1683,3 +1683,9 @@ class Sequence(blenderbim.core.tool.Sequence):
|
|||||||
if not task:
|
if not task:
|
||||||
return
|
return
|
||||||
cls.load_task_resources(cls.get_task_resources(task))
|
cls.load_task_resources(cls.get_task_resources(task))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def has_duration(cls, task):
|
||||||
|
if task.TaskTime and task.TaskTime.ScheduleDuration:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user