mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
updating a duration will not auto update schedule usage
This commit is contained in:
@@ -424,7 +424,6 @@ class CalculateResourceUsage(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_idname = "bim.calculate_resource_usage"
|
bl_idname = "bim.calculate_resource_usage"
|
||||||
bl_label = "Calculate Resource Usage"
|
bl_label = "Calculate Resource Usage"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
resource: bpy.props.IntProperty()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
@@ -434,7 +433,8 @@ class CalculateResourceUsage(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
task = tool.Resource.get_task_assignments(active_resource)
|
task = tool.Resource.get_task_assignments(active_resource)
|
||||||
if task and tool.Sequence.has_duration(task):
|
if task and tool.Sequence.has_duration(task):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
core.calculate_resource_usage(tool.Ifc, tool.Resource, resource=tool.Ifc.get().by_id(self.resource))
|
core.calculate_resource_usage(tool.Ifc, tool.Resource, resource=tool.Ifc.get().by_id(tool.Resource.get_highlighted_resource()))
|
||||||
|
|||||||
@@ -84,16 +84,19 @@ def updateResourceUsage(self, context):
|
|||||||
props = context.scene.BIMResourceProperties
|
props = context.scene.BIMResourceProperties
|
||||||
if not props.is_resource_update_enabled:
|
if not props.is_resource_update_enabled:
|
||||||
return
|
return
|
||||||
|
if not 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={"ScheduleUsage": self.schedule_usage})
|
if resource.Usage and resource.Usage.ScheduleUsage == self.schedule_usage:
|
||||||
tool.Resource.load_resource_properties()
|
return
|
||||||
|
tool.Resource.run_edit_resource_time(resource, attributes={
|
||||||
|
"ScheduleUsage": self.schedule_usage
|
||||||
|
})
|
||||||
tool.Sequence.load_task_properties()
|
tool.Sequence.load_task_properties()
|
||||||
|
tool.Resource.load_resource_properties()
|
||||||
|
tool.Sequence.refresh_task_resources()
|
||||||
blenderbim.bim.module.resource.data.refresh()
|
blenderbim.bim.module.resource.data.refresh()
|
||||||
blenderbim.bim.module.sequence.data.refresh()
|
blenderbim.bim.module.sequence.data.refresh()
|
||||||
tool.Sequence.refresh_task_resources()
|
|
||||||
blenderbim.bim.module.pset.data.refresh()
|
blenderbim.bim.module.pset.data.refresh()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -142,7 +142,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
|
row2col3.operator("bim.calculate_resource_usage", text="", icon="TEMP")
|
||||||
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="",
|
||||||
|
|||||||
@@ -225,7 +225,9 @@ def updateTaskDuration(self, context):
|
|||||||
task_time = tool.Ifc.run("sequence.add_task_time", task=task)
|
task_time = tool.Ifc.run("sequence.add_task_time", task=task)
|
||||||
tool.Ifc.run("sequence.edit_task_time", task_time=task_time, attributes={"ScheduleDuration": duration})
|
tool.Ifc.run("sequence.edit_task_time", task_time=task_time, attributes={"ScheduleDuration": duration})
|
||||||
SequenceData.load()
|
SequenceData.load()
|
||||||
|
blenderbim.core.sequence.load_task_properties(tool.Sequence)
|
||||||
bpy.ops.bim.load_task_properties()
|
bpy.ops.bim.load_task_properties()
|
||||||
|
tool.Sequence.load_resources()
|
||||||
|
|
||||||
|
|
||||||
def get_schedule_predefined_types(self, context):
|
def get_schedule_predefined_types(self, context):
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ def load_resources(resource):
|
|||||||
resource.load_resources()
|
resource.load_resources()
|
||||||
resource.load_resource_properties()
|
resource.load_resource_properties()
|
||||||
|
|
||||||
|
|
||||||
def add_resource(tool_ifc, resource_tool, ifc_class, parent_resource=None):
|
def add_resource(tool_ifc, resource_tool, ifc_class, parent_resource=None):
|
||||||
tool_ifc.run("resource.add_resource", ifc_class=ifc_class, parent_resource=parent_resource)
|
tool_ifc.run("resource.add_resource", ifc_class=ifc_class, parent_resource=parent_resource)
|
||||||
load_resources(resource_tool)
|
load_resources(resource_tool)
|
||||||
@@ -184,7 +183,7 @@ def edit_productivity_pset(ifc, resource_tool):
|
|||||||
|
|
||||||
|
|
||||||
def add_usage_constraint(ifc, resource_tool, resource=None, reference_path=None):
|
def add_usage_constraint(ifc, resource_tool, resource=None, reference_path=None):
|
||||||
metric = resource_tool.has_usage_metric(resource)
|
metric = resource_tool.has_metric_constraint(resource, "Usage")
|
||||||
if metric:
|
if metric:
|
||||||
return print("Must remove existing metric first")
|
return print("Must remove existing metric first")
|
||||||
|
|
||||||
|
|||||||
@@ -193,6 +193,7 @@ def edit_task_time(ifc, sequence, task_time=None):
|
|||||||
task = sequence.get_active_task()
|
task = sequence.get_active_task()
|
||||||
sequence.load_task_properties(task=task)
|
sequence.load_task_properties(task=task)
|
||||||
sequence.disable_editing_task_time()
|
sequence.disable_editing_task_time()
|
||||||
|
sequence.load_resources()
|
||||||
|
|
||||||
|
|
||||||
def assign_predecessor(ifc, sequence, task=None):
|
def assign_predecessor(ifc, sequence, task=None):
|
||||||
|
|||||||
@@ -615,8 +615,7 @@ class Resource:
|
|||||||
def get_resource_time_attributes(cls): pass
|
def get_resource_time_attributes(cls): pass
|
||||||
def get_resource_time(cls, resource): pass
|
def get_resource_time(cls, resource): pass
|
||||||
def go_to_resource(cls, resource): pass
|
def go_to_resource(cls, resource): pass
|
||||||
def has_metric_constraint(cls, resource, attribute): pass
|
def has_metric_constraint(cls, resource): pass
|
||||||
def has_usage_metric(cls, resource): pass
|
|
||||||
def import_resources(cls, file_path): pass
|
def import_resources(cls, file_path): pass
|
||||||
def load_cost_value_attributes(cls, cost_value): pass
|
def load_cost_value_attributes(cls, cost_value): pass
|
||||||
def load_productivity_data(cls): pass
|
def load_productivity_data(cls): pass
|
||||||
|
|||||||
@@ -397,12 +397,8 @@ class Resource(blenderbim.core.tool.Resource):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def has_metric_constraint(cls, resource, attribute):
|
def has_metric_constraint(cls, resource, attribute):
|
||||||
metrics = ifcopenshell.util.constraint.has_metric_constraints(resource, attribute)
|
metrics = ifcopenshell.util.constraint.get_metric_constraints(resource, attribute)
|
||||||
return metrics[0] if metrics else None
|
return True if metrics else False
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def has_usage_metric(cls, resource):
|
|
||||||
return cls.has_metric_constraint(resource, "Usage")
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run_edit_resource_time(cls, resource, attributes):
|
def run_edit_resource_time(cls, resource, attributes):
|
||||||
@@ -446,4 +442,8 @@ class Resource(blenderbim.core.tool.Resource):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_nested_resources(cls, resource):
|
def get_nested_resources(cls, resource):
|
||||||
return ifcopenshell.util.resource.get_nested_resources(resource)
|
return ifcopenshell.util.resource.get_nested_resources(resource)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def is_attribute_locked(cls, resource, attribute):
|
||||||
|
return ifcopenshell.util.constraint.is_attribute_locked(resource, attribute)
|
||||||
@@ -421,6 +421,7 @@ class Sequence(blenderbim.core.tool.Sequence):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def load_resources(cls):
|
def load_resources(cls):
|
||||||
blenderbim.core.resource.load_resources(tool.Resource)
|
blenderbim.core.resource.load_resources(tool.Resource)
|
||||||
|
cls.refresh_task_resources
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_task_inputs(cls, task):
|
def get_task_inputs(cls, task):
|
||||||
|
|||||||
@@ -31,14 +31,7 @@ class Usecase:
|
|||||||
self.settings = {"resource": resource}
|
self.settings = {"resource": resource}
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
metrics = ifcopenshell.util.constraint.has_metric_constraints(
|
if ifcopenshell.util.constraint.is_attribute_locked(self.settings["resource"], "Usage.ScheduleUsage"):
|
||||||
self.settings["resource"], "Usage.ScheduleUsage"
|
|
||||||
)
|
|
||||||
if (
|
|
||||||
metrics
|
|
||||||
and metrics[0].ConstraintGrade == "HARD"
|
|
||||||
and metrics[0].Benchmark == "EQUALTO"
|
|
||||||
):
|
|
||||||
return
|
return
|
||||||
if (
|
if (
|
||||||
not self.settings["resource"].Usage
|
not self.settings["resource"].Usage
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class Usecase:
|
|||||||
self.settings = {"resource": resource}
|
self.settings = {"resource": resource}
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
if self.has_hard_constraint():
|
if ifcopenshell.util.constraint.is_attribute_locked(self.settings["resource"], "Usage.ScheduleWork"):
|
||||||
return
|
return
|
||||||
amount_worked = ifcopenshell.util.resource.get_resource_required_work(
|
amount_worked = ifcopenshell.util.resource.get_resource_required_work(
|
||||||
self.settings["resource"]
|
self.settings["resource"]
|
||||||
@@ -74,15 +74,3 @@ class Usecase:
|
|||||||
resource=self.settings["resource"],
|
resource=self.settings["resource"],
|
||||||
)
|
)
|
||||||
self.settings["resource"].Usage.ScheduleWork = amount_worked
|
self.settings["resource"].Usage.ScheduleWork = amount_worked
|
||||||
|
|
||||||
def has_hard_constraint(self):
|
|
||||||
metrics = ifcopenshell.util.constraint.has_metric_constraints(
|
|
||||||
self.settings["resource"], "Usage.ScheduleWork"
|
|
||||||
)
|
|
||||||
if (
|
|
||||||
metrics
|
|
||||||
and metrics[0].ConstraintGrade == "HARD"
|
|
||||||
and metrics[0].Benchmark == "EQUALTO"
|
|
||||||
):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|||||||
@@ -77,10 +77,10 @@ class Usecase:
|
|||||||
del self.settings["attributes"]["ActualFinish"]
|
del self.settings["attributes"]["ActualFinish"]
|
||||||
|
|
||||||
for name, value in self.settings["attributes"].items():
|
for name, value in self.settings["attributes"].items():
|
||||||
metrics = ifcopenshell.util.constraint.has_metric_constraints(
|
metrics = ifcopenshell.util.constraint.get_metric_constraints(
|
||||||
self.resource, "Usage." + name
|
self.resource, "Usage." + name
|
||||||
)
|
)
|
||||||
if metrics and self.is_hard_constraint(metrics[0]):
|
if metrics and ifcopenshell.util.constraint.is_hard_constraint(metrics[0]):
|
||||||
continue
|
continue
|
||||||
if value:
|
if value:
|
||||||
if "Start" in name or "Finish" in name or name == "StatusTime":
|
if "Start" in name or "Finish" in name or name == "StatusTime":
|
||||||
@@ -94,7 +94,7 @@ class Usecase:
|
|||||||
setattr(self.settings["resource_time"], name, value)
|
setattr(self.settings["resource_time"], name, value)
|
||||||
if (
|
if (
|
||||||
name == "ScheduleUsage"
|
name == "ScheduleUsage"
|
||||||
and ifcopenshell.util.constraint.has_metric_constraints(
|
and ifcopenshell.util.constraint.get_metric_constraints(
|
||||||
self.resource, "Usage.ScheduleWork"
|
self.resource, "Usage.ScheduleWork"
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
@@ -104,9 +104,6 @@ class Usecase:
|
|||||||
"sequence.calculate_task_duration", self.file, task=task
|
"sequence.calculate_task_duration", self.file, task=task
|
||||||
)
|
)
|
||||||
|
|
||||||
def is_hard_constraint(self, metric):
|
|
||||||
return bool(metric.ConstraintGrade == "HARD" and metric.Benchmark == "EQUALTO")
|
|
||||||
|
|
||||||
def get_resource(self):
|
def get_resource(self):
|
||||||
return [
|
return [
|
||||||
e
|
e
|
||||||
|
|||||||
@@ -125,6 +125,8 @@ class Usecase:
|
|||||||
or "ScheduleDuration" in self.settings["attributes"].keys()
|
or "ScheduleDuration" in self.settings["attributes"].keys()
|
||||||
):
|
):
|
||||||
ifcopenshell.api.run("sequence.cascade_schedule", self.file, task=self.task)
|
ifcopenshell.api.run("sequence.cascade_schedule", self.file, task=self.task)
|
||||||
|
if self.settings["task_time"].ScheduleDuration:
|
||||||
|
self.handle_resource_calculation()
|
||||||
|
|
||||||
def calculate_finish(self):
|
def calculate_finish(self):
|
||||||
finish = ifcopenshell.util.sequence.get_start_or_finish_date(
|
finish = ifcopenshell.util.sequence.get_start_or_finish_date(
|
||||||
@@ -173,3 +175,12 @@ class Usecase:
|
|||||||
for e in self.file.get_inverse(self.settings["task_time"])
|
for e in self.file.get_inverse(self.settings["task_time"])
|
||||||
if e.is_a("IfcTask")
|
if e.is_a("IfcTask")
|
||||||
][0]
|
][0]
|
||||||
|
|
||||||
|
def handle_resource_calculation(self):
|
||||||
|
resources = ifcopenshell.util.sequence.get_task_resources(self.task, is_deep=False)
|
||||||
|
for resource in resources:
|
||||||
|
if ifcopenshell.util.constraint.is_attribute_locked(resource, "Usage.ScheduleWork"):
|
||||||
|
ifcopenshell.api.run("resource.calculate_resource_usage", self.file, resource=resource)
|
||||||
|
#TODO: If the duration changes, this implies the productivity rate must change to accomModate the new Schedule Work to be calculated.
|
||||||
|
# elif ifcopenshell.util.constraint.is_attribute_locked(resource, "Usage.ScheduleUsage"):
|
||||||
|
# ifcopenshell.api.run("resource.calculate_resource_work", self.file, resource=resource)
|
||||||
|
|||||||
@@ -20,10 +20,9 @@
|
|||||||
|
|
||||||
def get_constraints(product):
|
def get_constraints(product):
|
||||||
constraints = []
|
constraints = []
|
||||||
if product.HasAssociations:
|
for rel in product.HasAssociations or []:
|
||||||
for rel in product.HasAssociations:
|
if rel.is_a("IfcRelAssociatesConstraint"):
|
||||||
if rel.is_a("IfcRelAssociatesConstraint"):
|
constraints.append(rel.RelatingConstraint)
|
||||||
constraints.append(rel.RelatingConstraint)
|
|
||||||
return constraints
|
return constraints
|
||||||
|
|
||||||
def get_metrics(constraint):
|
def get_metrics(constraint):
|
||||||
@@ -48,7 +47,7 @@ def get_metric_reference(metric, is_deep=True):
|
|||||||
reference = metric.ReferencePath
|
reference = metric.ReferencePath
|
||||||
return get_reference_Attribute(reference, "")
|
return get_reference_Attribute(reference, "")
|
||||||
|
|
||||||
def has_metric_constraints(resource, attribute):
|
def get_metric_constraints(resource, attribute):
|
||||||
metrics = []
|
metrics = []
|
||||||
for constraint in get_constraints(resource) or []:
|
for constraint in get_constraints(resource) or []:
|
||||||
for metric in get_metrics(constraint) or []:
|
for metric in get_metrics(constraint) or []:
|
||||||
@@ -59,4 +58,18 @@ def has_metric_constraints(resource, attribute):
|
|||||||
metrics.append(metric)
|
metrics.append(metric)
|
||||||
if metrics:
|
if metrics:
|
||||||
return metrics
|
return metrics
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def is_hard_constraint(metric):
|
||||||
|
if metric.ConstraintGrade == "HARD" and metric.Benchmark == "EQUALTO":
|
||||||
|
return True
|
||||||
|
|
||||||
|
def is_attribute_locked(product, attribute):
|
||||||
|
is_locked = False
|
||||||
|
metrics = get_metric_constraints(
|
||||||
|
product, attribute
|
||||||
|
)
|
||||||
|
for metric in metrics or []:
|
||||||
|
if is_hard_constraint(metric):
|
||||||
|
is_locked = True
|
||||||
|
return is_locked
|
||||||
|
|||||||
@@ -114,4 +114,4 @@ def get_resource_required_work(resource):
|
|||||||
return iso_string
|
return iso_string
|
||||||
|
|
||||||
def get_nested_resources(resource):
|
def get_nested_resources(resource):
|
||||||
return [object for rel in resource.IsNestedBy or [] for object in rel.RelatedObjects]
|
return [object for rel in resource.IsNestedBy or [] for object in rel.RelatedObjects]
|
||||||
|
|||||||
Reference in New Issue
Block a user