diff --git a/src/blenderbim/blenderbim/bim/module/resource/__init__.py b/src/blenderbim/blenderbim/bim/module/resource/__init__.py index 8512a370dd..8ab1410e3f 100644 --- a/src/blenderbim/blenderbim/bim/module/resource/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/resource/__init__.py @@ -49,7 +49,6 @@ classes = ( operator.ExpandResource, operator.GoToResource, operator.ImportResources, - operator.LoadResourceProperties, operator.LoadResources, operator.RemoveResource, operator.RemoveResourceQuantity, diff --git a/src/blenderbim/blenderbim/bim/module/resource/operator.py b/src/blenderbim/blenderbim/bim/module/resource/operator.py index 068212f68c..9d64cdb0dd 100644 --- a/src/blenderbim/blenderbim/bim/module/resource/operator.py +++ b/src/blenderbim/blenderbim/bim/module/resource/operator.py @@ -33,19 +33,6 @@ class LoadResources(bpy.types.Operator): return {"FINISHED"} -class LoadResourceProperties(bpy.types.Operator): - bl_idname = "bim.load_resource_properties" - bl_label = "Load Resource Properties" - bl_options = {"REGISTER", "UNDO"} - resource: bpy.props.IntProperty() - - def execute(self, context): - core.load_resource_properties( - tool.Resource, resource=tool.Ifc.get().by_id(self.resource) if self.resource else None - ) - return {"FINISHED"} - - class AddResource(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.add_resource" bl_label = "Add Resource" diff --git a/src/blenderbim/blenderbim/bim/module/resource/prop.py b/src/blenderbim/blenderbim/bim/module/resource/prop.py index 9ea20d446c..2f7e539eb9 100644 --- a/src/blenderbim/blenderbim/bim/module/resource/prop.py +++ b/src/blenderbim/blenderbim/bim/module/resource/prop.py @@ -81,8 +81,7 @@ def update_active_resource_index(self, context): def updateResourceUsage(self, context): - props = context.scene.BIMResourceProperties - if not props.is_resource_update_enabled: + if not context.scene.BIMResourceProperties.is_resource_update_enabled: return if not self.schedule_usage: return diff --git a/src/blenderbim/blenderbim/bim/module/sequence/operator.py b/src/blenderbim/blenderbim/bim/module/sequence/operator.py index e66d492f3a..a7e6e1ea97 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/operator.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/operator.py @@ -372,6 +372,7 @@ class EditTaskTime(bpy.types.Operator, tool.Ifc.Operator): core.edit_task_time( tool.Ifc, tool.Sequence, + tool.Resource, task_time=tool.Ifc.get().by_id(context.scene.BIMWorkScheduleProperties.active_task_time_id), ) @@ -508,7 +509,7 @@ class AssignProcess(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): if self.related_object_type == "RESOURCE": - core.assign_resource(tool.Ifc, tool.Sequence, task=tool.Ifc.get().by_id(self.task)) + core.assign_resource(tool.Ifc, tool.Sequence, tool.Resource, task=tool.Ifc.get().by_id(self.task)) elif self.related_object_type == "PRODUCT": if self.related_object: core.assign_input_products( @@ -541,6 +542,7 @@ class UnassignProcess(bpy.types.Operator): core.unassign_resource( tool.Ifc, tool.Sequence, + tool.Resource, task=tool.Ifc.get().by_id(self.task), resource=tool.Ifc.get().by_id(self.resource), ) diff --git a/src/blenderbim/blenderbim/bim/module/sequence/prop.py b/src/blenderbim/blenderbim/bim/module/sequence/prop.py index 629dd214f3..30dc776cf7 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/prop.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/prop.py @@ -329,17 +329,16 @@ def get_saved_color_schemes(self, context): def updateAssignedResourceName(self, context): pass + def updateAssignedResourceUsage(self, context): - if not bpy.context.scene.BIMResourceProperties.is_resource_update_enabled: + if not context.scene.BIMResourceProperties.is_resource_update_enabled: return if not self.schedule_usage: return resource = tool.Ifc.get().by_id(self.ifc_definition_id) if resource.Usage and resource.Usage.ScheduleUsage == self.schedule_usage: return - tool.Resource.run_edit_resource_time(resource, attributes={ - "ScheduleUsage": self.schedule_usage - }) + tool.Resource.run_edit_resource_time(resource, attributes={"ScheduleUsage": self.schedule_usage}) tool.Sequence.load_task_properties() tool.Resource.load_resource_properties() tool.Sequence.refresh_task_resources() @@ -347,6 +346,7 @@ def updateAssignedResourceUsage(self, context): refresh_sequence_data() blenderbim.bim.module.pset.data.refresh() + class Task(PropertyGroup): name: StringProperty(name="Name", update=updateTaskName) identification: StringProperty(name="Identification", update=updateTaskIdentification) diff --git a/src/blenderbim/blenderbim/bim/module/sequence/ui.py b/src/blenderbim/blenderbim/bim/module/sequence/ui.py index 50542ffb19..850f507785 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/ui.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/ui.py @@ -727,7 +727,11 @@ class BIM_PT_task_icom(Panel): if total_task_outputs: op = row2.operator("bim.unassign_product", icon="REMOVE", text="") op.task = task.ifc_definition_id - if not context.selected_objects and self.props.active_task_output_index < total_task_outputs: + if ( + total_task_outputs + and not context.selected_objects + and self.props.active_task_output_index < total_task_outputs + ): output_id = self.props.task_outputs[self.props.active_task_output_index].ifc_definition_id op.relating_product = output_id @@ -770,6 +774,7 @@ class BIM_UL_task_resources(UIList): row.prop(item, "name", emboss=False, text="") row.prop(item, "schedule_usage", emboss=False, text="") + class BIM_UL_animation_colors(UIList): def draw_item(self, context, layout, data, item, icon, active_data, active_propname): if item: diff --git a/src/blenderbim/blenderbim/core/cost.py b/src/blenderbim/blenderbim/core/cost.py index d8f5d9166b..19bf23f02a 100644 --- a/src/blenderbim/blenderbim/core/cost.py +++ b/src/blenderbim/blenderbim/core/cost.py @@ -1,4 +1,4 @@ -def add_cost_schedule(ifc, name, predefined_type,object_type): +def add_cost_schedule(ifc, name, predefined_type, object_type): ifc.run("cost.add_cost_schedule", name=name, predefined_type=predefined_type, object_type=object_type) @@ -112,70 +112,89 @@ def assign_cost_item_quantity(ifc, cost, cost_item, related_object_type, prop_na ifc.run("cost.assign_cost_item_quantity", cost_item=cost_item, products=products, prop_name=prop_name) cost.load_cost_item_quantity_assignments(cost_item, related_object_type=related_object_type) + def load_cost_item_quantities(cost): cost.load_cost_item_quantities() + def load_cost_item_element_quantities(cost): cost_item = cost.get_highlighted_cost_item() cost.load_cost_item_quantity_assignments(cost_item, related_object_type="PRODUCT") + def load_cost_item_task_quantities(cost): cost_item = cost.get_highlighted_cost_item() cost.load_cost_item_quantity_assignments(cost_item, related_object_type="PROCESS") + def load_cost_item_resource_quantities(cost): cost_item = cost.get_highlighted_cost_item() cost.load_cost_item_quantity_assignments(cost_item, related_object_type="RESOURCE") + def assign_cost_value(ifc, cost_item, cost_rate): ifc.run("cost.assign_cost_value", cost_item=cost_item, cost_rate=cost_rate) + def load_schedule_of_rates(cost, schedule_of_rates): cost.load_schedule_of_rates_tree(schedule_of_rates) + def unassign_cost_item_quantity(ifc, cost, cost_item, products): ifc.run("cost.unassign_cost_item_quantity", cost_item=cost_item, products=products) cost.load_cost_item_quantities() + def enable_editing_cost_item_quantities(cost, cost_item): cost.enable_editing_cost_item_quantities(cost_item) + def enable_editing_cost_item_values(cost, cost_item): cost.enable_editing_cost_item_values(cost_item) + def add_cost_item_quantity(ifc, cost_item, ifc_class): ifc.run("cost.add_cost_item_quantity", cost_item=cost_item, ifc_class=ifc_class) + def remove_cost_item_quantity(ifc, cost_item, physical_quantity): ifc.run("cost.remove_cost_item_quantity", cost_item=cost_item, physical_quantity=physical_quantity) - + + def enable_editing_cost_item_quantity(cost, physical_quantity): cost.load_cost_item_quantity_attributes(physical_quantity) cost.enable_editing_cost_item_quantity(physical_quantity) + def disable_editing_cost_item_quantity(cost): cost.disable_editing_cost_item_quantity() + def edit_cost_item_quantity(ifc, cost, physical_quantity): attributes = cost.get_cost_item_quantity_attributes() ifc.run("cost.edit_cost_item_quantity", physical_quantity=physical_quantity, attributes=attributes) cost.disable_editing_cost_item_quantity() cost.load_cost_item_quantities() + def add_cost_value(ifc, cost, parent, cost_type, cost_category): value = ifc.run("cost.add_cost_value", parent=parent) ifc.run( "cost.edit_cost_value", cost_value=value, - attributes=cost.get_attributes_for_cost_value(cost_type, cost_category)) + attributes=cost.get_attributes_for_cost_value(cost_type, cost_category), + ) + def remove_cost_value(ifc, parent, cost_value): ifc.run("cost.remove_cost_value", parent=parent, cost_value=cost_value) + def enable_editing_cost_item_value(cost, cost_value): cost.load_cost_item_value_attributes(cost_value) cost.enable_editing_cost_item_value(cost_value) + def disable_editing_cost_item_value(cost): cost.disable_editing_cost_item_value() @@ -195,7 +214,7 @@ def edit_cost_value(ifc, cost, cost_value): attributes = cost.get_cost_value_attributes() ifc.run("cost.edit_cost_value", cost_value=cost_value, attributes=attributes) cost.disable_editing_cost_item_value() - #cost.load_cost_item_values(cost.get_highlighted_cost_item()) + # cost.load_cost_item_values(cost.get_highlighted_cost_item()) def copy_cost_item_values(ifc, cost, source, destination): @@ -275,11 +294,12 @@ def change_parent_cost_item(ifc, cost, new_parent): cost_item = cost.get_active_cost_item() if cost_item and cost.is_root_cost_item(cost_item): return "Cannot change root cost item" - if cost_item : + if cost_item: ifc.run("nest.change_nest", item=cost_item, new_parent=new_parent) cost.disable_editing_cost_item_parent() cost.load_cost_schedule_tree() + def copy_cost_item(ifc, cost): cost_item = cost.get_highlighted_cost_item() if cost_item: @@ -287,9 +307,10 @@ def copy_cost_item(ifc, cost): cost.disable_editing_cost_item_parent() cost.load_cost_schedule_tree() + def add_currency(ifc, cost): unit = ifc.run("unit.add_monetary_unit") attributes = cost.get_currency_attributes() ifc.run("unit.edit_monetary_unit", unit=unit, attributes=attributes) ifc.run("unit.assign_unit", units=[unit]) - return unit \ No newline at end of file + return unit diff --git a/src/blenderbim/blenderbim/core/resource.py b/src/blenderbim/blenderbim/core/resource.py index c026139446..dd3875a04f 100644 --- a/src/blenderbim/blenderbim/core/resource.py +++ b/src/blenderbim/blenderbim/core/resource.py @@ -21,15 +21,11 @@ def load_resources(resource): resource.load_resources() - resource.load_resource_properties() + 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) - load_resources(resource_tool) - - -def load_resource_properties(resource_tool, resource=None): - resource_tool.load_resource_properties() + resource_tool.load_resources() def disable_editing_resource(resource_tool): @@ -54,7 +50,7 @@ def edit_resource(ifc, resource_tool, resource): def remove_resource(ifc, resource_tool, resource=None): ifc.run("resource.remove_resource", resource=resource) - load_resources(resource_tool) + resource_tool.load_resources() def enable_editing_resource_time(ifc_tool, resource_tool, resource): @@ -82,7 +78,7 @@ def calculate_resource_work(ifc, resource_tool, resource): nested_resources = resource_tool.get_nested_resources(resource) for nested_resource in nested_resources or []: ifc.run("resource.calculate_resource_work", resource=nested_resource) - load_resources(resource_tool) + resource_tool.load_resources() def enable_editing_resource_costs(resource_tool, resource): @@ -143,17 +139,17 @@ def edit_resource_quantity(resource_tool, ifc, physical_quantity=None): def import_resources(resource_tool, file_path): resource_tool.import_resources(file_path) - load_resources(resource_tool) + resource_tool.load_resources() def expand_resource(resource_tool, resource): resource_tool.expand_resource(resource) - load_resources(resource_tool) + resource_tool.load_resources() def contract_resource(resource_tool, resource): resource_tool.contract_resource(resource) - load_resources(resource_tool) + resource_tool.load_resources() def assign_resource(ifc, spatial, resource=None, products=None): @@ -213,9 +209,11 @@ def remove_usage_constraint(ifc, resource_tool, resource, reference_path): ifc.run("constraint.unassign_constraint", product=resource, constraint=constraint) ifc.run("constraint.remove_constraint", constraint=constraint) + def go_to_resource(resource_tool, resource): resource_tool.go_to_resource(resource) + def calculate_resource_usage(ifc, resource_tool, resource): ifc.run("resource.calculate_resource_usage", resource=resource) - load_resources(resource_tool) \ No newline at end of file + resource_tool.load_resources() diff --git a/src/blenderbim/blenderbim/core/sequence.py b/src/blenderbim/blenderbim/core/sequence.py index 2321796783..d4ecd2bb72 100644 --- a/src/blenderbim/blenderbim/core/sequence.py +++ b/src/blenderbim/blenderbim/core/sequence.py @@ -186,14 +186,14 @@ def enable_editing_task_time(ifc, sequence, task=None): sequence.enable_editing_task_time(task) -def edit_task_time(ifc, sequence, task_time=None): +def edit_task_time(ifc, sequence, resource, task_time=None): attributes = sequence.get_task_time_attributes() # TODO: nasty loop goes on when calendar props are messed up ifc.run("sequence.edit_task_time", task_time=task_time, attributes=attributes) task = sequence.get_active_task() sequence.load_task_properties(task=task) sequence.disable_editing_task_time() - sequence.load_resources() + resource.load_resource_properties() def assign_predecessor(ifc, sequence, task=None): @@ -248,8 +248,8 @@ def unassign_input_products(ifc, sequence, spatial, task=None, products=None): sequence.load_task_inputs(inputs) -def assign_resource(ifc, sequence, task=None): - resource = sequence.get_selected_resource() +def assign_resource(ifc, sequence, resource_tool, task=None): + resource = resource_tool.get_highlighted_resource() sub_resource = ifc.run( "resource.add_resource", parent_resource=resource, @@ -257,17 +257,15 @@ def assign_resource(ifc, sequence, task=None): name="{}/{}".format(resource.Name or "Unnamed", task.Name or ""), ) ifc.run("sequence.assign_process", relating_process=task, related_object=sub_resource) - resources = sequence.get_task_resources(task) - sequence.load_task_resources(resources) - sequence.load_resources() + sequence.load_task_resources(task) + resource_tool.load_resources() -def unassign_resource(ifc, sequence, task=None, resource=None): +def unassign_resource(ifc, sequence, resource_tool, task=None, resource=None): ifc.run("sequence.unassign_process", relating_process=task, related_object=resource) ifc.run("resource.remove_resource", resource=resource) - resources = sequence.get_task_resources(task) - sequence.load_task_resources(resources) - sequence.load_resources() + sequence.load_task_resources(task) + resource_tool.load_resources() def remove_work_calendar(ifc, work_calendar=None): diff --git a/src/blenderbim/blenderbim/core/tool.py b/src/blenderbim/blenderbim/core/tool.py index f0f168a7ba..7e769df9dc 100644 --- a/src/blenderbim/blenderbim/core/tool.py +++ b/src/blenderbim/blenderbim/core/tool.py @@ -726,7 +726,6 @@ class Sequence: def get_recurrence_pattern_attributes(cls, recurrence_pattern): pass def get_recurrence_pattern_times(cls): pass def get_rel_sequence_attributes(cls): pass - def get_selected_resource(cls): pass def get_start_date(cls): pass def get_task_attribute_value(cls, attribute_name): pass def get_task_attributes(cls): pass @@ -758,7 +757,7 @@ class Sequence: def load_task_inputs(cls, inputs): pass def load_task_outputs(cls, outputs): pass def load_task_properties(cls, task): pass - def load_task_resources(cls,resources): pass + def load_task_resources(cls, task): pass def load_task_time_attributes(cls, task_time): pass def load_task_tree(cls, work_schedule): pass def load_work_calendar_attributes(cls, work_calendar): pass diff --git a/src/blenderbim/blenderbim/tool/cost.py b/src/blenderbim/blenderbim/tool/cost.py index 698625bc33..f51d157862 100644 --- a/src/blenderbim/blenderbim/tool/cost.py +++ b/src/blenderbim/blenderbim/tool/cost.py @@ -234,7 +234,6 @@ class Cost(blenderbim.core.tool.Cost): @classmethod def get_products(cls, related_object_type=None): - props = bpy.context.scene.BIMCostProperties if related_object_type == "PRODUCT": products = tool.Spatial.get_selected_products() elif related_object_type == "PROCESS": diff --git a/src/blenderbim/blenderbim/tool/resource.py b/src/blenderbim/blenderbim/tool/resource.py index 3c5698505d..99293fcbc9 100644 --- a/src/blenderbim/blenderbim/tool/resource.py +++ b/src/blenderbim/blenderbim/tool/resource.py @@ -61,6 +61,7 @@ class Resource(blenderbim.core.tool.Resource): continue create_new_resource_li(resource, 0) cls.load_productivity_data() + cls.load_resource_properties() props.is_resource_update_enabled = True props.is_editing = True @@ -425,7 +426,7 @@ class Resource(blenderbim.core.tool.Resource): contracted_resources.remove(ancestor) bpy.context.scene.BIMResourceProperties.contracted_resources = json.dumps(contracted_resources) cls.load_resources() - cls.load_resource_properties() + resource_props = bpy.context.scene.BIMResourceTreeProperties expanded_resources = [item.ifc_definition_id for item in resource_props.resources] diff --git a/src/blenderbim/blenderbim/tool/sequence.py b/src/blenderbim/blenderbim/tool/sequence.py index 038a95473f..c197d7799b 100644 --- a/src/blenderbim/blenderbim/tool/sequence.py +++ b/src/blenderbim/blenderbim/tool/sequence.py @@ -254,14 +254,6 @@ class Sequence(blenderbim.core.tool.Sequence): return None return tool.Ifc.get().by_id(bpy.context.scene.BIMWorkScheduleProperties.active_work_schedule_id) - @classmethod - def get_selected_resource(cls): - if bpy.context.scene.BIMResourceTreeProperties.resources: - selected_resource_id = bpy.context.scene.BIMResourceTreeProperties.resources[ - bpy.context.scene.BIMResourceProperties.active_resource_index - ].ifc_definition_id - return tool.Ifc.get().by_id(selected_resource_id) - @classmethod def expand_task(cls, task): props = bpy.context.scene.BIMWorkScheduleProperties @@ -410,20 +402,16 @@ class Sequence(blenderbim.core.tool.Sequence): @classmethod def load_task_resources(cls, task): - resources = cls.get_task_resources(task) props = bpy.context.scene.BIMWorkScheduleProperties + rprops = bpy.context.scene.BIMResourceProperties props.task_resources.clear() - bpy.context.scene.BIMResourceProperties.is_resource_update_enabled = False - for resource in resources or []: + rprops.is_resource_update_enabled = False + for resource in cls.get_task_resources(task) or []: new = props.task_resources.add() new.ifc_definition_id = resource.id() new.name = resource.Name or "Unnamed" new.schedule_usage = resource.Usage.ScheduleUsage or 0 if resource.Usage else 0 - bpy.context.scene.BIMResourceProperties.is_resource_update_enabled = True - - @classmethod - def load_resources(cls): - blenderbim.core.resource.load_resources(tool.Resource) + rprops.is_resource_update_enabled = True @classmethod def get_task_inputs(cls, task): @@ -449,6 +437,8 @@ class Sequence(blenderbim.core.tool.Sequence): @classmethod def get_task_resources(cls, task): + if not task: + return is_deep = bpy.context.scene.BIMWorkScheduleProperties.show_nested_resources return ifcopenshell.util.sequence.get_task_resources(task, is_deep)