diff --git a/src/blenderbim/blenderbim/bim/module/sequence/operator.py b/src/blenderbim/blenderbim/bim/module/sequence/operator.py index cd67c76fc3..84496df9f8 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/operator.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/operator.py @@ -1,5 +1,5 @@ # BlenderBIM Add-on - OpenBIM Blender Add-on -# Copyright (C) 2020, 2021 Dion Moult +# Copyright (C) 2020, 2021 Dion Moult , 2022 Yassine Oualid # # This file is part of BlenderBIM Add-on. # @@ -28,6 +28,8 @@ import webbrowser import ifcopenshell.api import ifcopenshell.util.date import ifcopenshell.util.sequence +import blenderbim.core.sequence as core +import blenderbim.tool as tool import blenderbim.bim.helper import blenderbim.bim.module.sequence.helper as helper from datetime import datetime @@ -52,7 +54,7 @@ def animate_text(scene, context): data.body = frame_date.date().isoformat() -class AddWorkPlan(bpy.types.Operator): +class AddWorkPlan(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.add_work_plan" bl_label = "Add Work Plan" bl_options = {"REGISTER", "UNDO"} @@ -61,12 +63,11 @@ class AddWorkPlan(bpy.types.Operator): return IfcStore.execute_ifc_operator(self, context) def _execute(self, context): - ifcopenshell.api.run("sequence.add_work_plan", IfcStore.get_file()) - Data.load(IfcStore.get_file()) + core.add_work_plan(tool.Ifc, tool.Sequence) return {"FINISHED"} -class EditWorkPlan(bpy.types.Operator): +class EditWorkPlan(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.edit_work_plan" bl_options = {"REGISTER", "UNDO"} bl_label = "Edit Work Plan" @@ -75,34 +76,11 @@ class EditWorkPlan(bpy.types.Operator): return IfcStore.execute_ifc_operator(self, context) def _execute(self, context): - props = context.scene.BIMWorkPlanProperties - attributes = blenderbim.bim.helper.export_attributes(props.work_plan_attributes, self.export_attributes) - self.file = IfcStore.get_file() - ifcopenshell.api.run( - "sequence.edit_work_plan", - self.file, - **{"work_plan": self.file.by_id(props.active_work_plan_id), "attributes": attributes}, - ) - Data.load(IfcStore.get_file()) - bpy.ops.bim.disable_editing_work_plan() + core.edit_work_plan(tool.Ifc, tool.Sequence) return {"FINISHED"} - def export_attributes(self, attributes, prop): - if "Date" in prop.name or "Time" in prop.name: - if prop.is_null: - attributes[prop.name] = None - return True - attributes[prop.name] = helper.parse_datetime(prop.string_value) - return True - elif prop.name == "Duration" or prop.name == "TotalFloat": - if prop.is_null: - attributes[prop.name] = None - return True - attributes[prop.name] = helper.parse_duration(prop.string_value) - return True - -class RemoveWorkPlan(bpy.types.Operator): +class RemoveWorkPlan(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.remove_work_plan" bl_label = "Remove Work Plan" bl_options = {"REGISTER", "UNDO"} @@ -112,9 +90,7 @@ class RemoveWorkPlan(bpy.types.Operator): return IfcStore.execute_ifc_operator(self, context) def _execute(self, context): - self.file = IfcStore.get_file() - ifcopenshell.api.run("sequence.remove_work_plan", self.file, **{"work_plan": self.file.by_id(self.work_plan)}) - Data.load(self.file) + core.remove_work_plan(tool.Ifc, tool.Sequence, work_plan=self.work_plan) return {"FINISHED"} @@ -125,22 +101,9 @@ class EnableEditingWorkPlan(bpy.types.Operator): work_plan: bpy.props.IntProperty() def execute(self, context): - props = context.scene.BIMWorkPlanProperties - props.work_plan_attributes.clear() - - data = Data.work_plans[self.work_plan] - - blenderbim.bim.helper.import_attributes("IfcWorkPlan", props.work_plan_attributes, data, self.import_attributes) - - props.active_work_plan_id = self.work_plan - props.editing_type = "ATTRIBUTES" + core.enable_editing_work_plan(tool.Sequence, work_plan=self.work_plan) return {"FINISHED"} - def import_attributes(self, name, prop, data): - if name in ["CreationDate", "StartTime", "FinishTime"]: - prop.string_value = "" if prop.is_null else data[name].isoformat() - return True - class DisableEditingWorkPlan(bpy.types.Operator): bl_idname = "bim.disable_editing_work_plan" @@ -148,7 +111,7 @@ class DisableEditingWorkPlan(bpy.types.Operator): bl_label = "Disable Editing Work Plan" def execute(self, context): - context.scene.BIMWorkPlanProperties.active_work_plan_id = 0 + core.disable_editing_work_plan(tool.Sequence) return {"FINISHED"} @@ -1886,6 +1849,8 @@ class VisualiseWorkScheduleDateRange(bpy.types.Operator): self.start_frame = 1 self.total_frames = self.calculate_total_frames(context) self.preprocess_tasks() + + for obj in bpy.data.objects: if not obj.BIMObjectProperties.ifc_definition_id: continue @@ -1897,6 +1862,7 @@ class VisualiseWorkScheduleDateRange(bpy.types.Operator): self.animate_output(obj, product_frame) self.add_text_animation_handler() + area = next(area for area in context.screen.areas if area.type == "VIEW_3D") area.spaces[0].shading.color_type = "OBJECT" context.scene.frame_start = self.start_frame @@ -1932,7 +1898,7 @@ class VisualiseWorkScheduleDateRange(bpy.types.Operator): self.animate_consumption(obj, product_frame) def animate_output(self, obj, product_frame): - if product_frame["type"] in ["CONSTRUCTION", "INSTALLATION"]: + if product_frame["type"] in ["CONSTRUCTION", "INSTALLATION", "NOTDEFINED"]: self.animate_creation(obj, product_frame) elif product_frame["type"] in ["DEMOLITION", "DISMANTLE", "DISPOSAL", "REMOVAL"]: self.animate_destruction(obj, product_frame) diff --git a/src/blenderbim/blenderbim/bim/module/sequence/ui.py b/src/blenderbim/blenderbim/bim/module/sequence/ui.py index 0368f7debc..ef2481323e 100644 --- a/src/blenderbim/blenderbim/bim/module/sequence/ui.py +++ b/src/blenderbim/blenderbim/bim/module/sequence/ui.py @@ -47,6 +47,10 @@ class BIM_PT_work_plans(Panel): self.props = context.scene.BIMWorkPlanProperties row = self.layout.row() + row.label( + text="{} Work Plans Found".format(len(Data.work_plans.items())), + icon="MOD_SIMPLIFY", + ) row.operator("bim.add_work_plan", icon="ADD") for work_plan_id, work_plan in Data.work_plans.items(): diff --git a/src/blenderbim/blenderbim/core/sequence.py b/src/blenderbim/blenderbim/core/sequence.py new file mode 100644 index 0000000000..2303494c4a --- /dev/null +++ b/src/blenderbim/blenderbim/core/sequence.py @@ -0,0 +1,51 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2021 Dion Moult , 2022 Yassine Oualid +# +# This file is part of BlenderBIM Add-on. +# +# BlenderBIM Add-on is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BlenderBIM Add-on is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BlenderBIM Add-on. If not, see . + + +# def load_work_plans(ifc, sequence): +# pass + +def add_work_plan(ifc, sequence): + ifc.run("sequence.add_work_plan") + sequence.load_sequence_data() + +def remove_work_plan(ifc, sequence, work_plan=None): + ifc.run("sequence.remove_work_plan",**{"work_plan": ifc.get().by_id(work_plan)}) + sequence.load_sequence_data() + +def load_work_plan_attributes(sequence, work_plan=None): + data = sequence.get_work_plan_attributes(work_plan) + sequence.load_work_plan_attributes(data) + +def enable_editing_work_plan(sequence, work_plan=None): + load_work_plan_attributes(sequence, work_plan) + sequence.enable_editing_work_plan(work_plan) + print("Yassine Is back in the game") + +def disable_editing_work_plan(sequence): + sequence.disable_editing_work_plan() + +def edit_work_plan(ifc, sequence): + work_plan = sequence.get_current_work_plan() + attributes = sequence.get_current_work_plan_attributes() + ifc.run("sequence.edit_work_plan",**{"work_plan": work_plan, "attributes": attributes}) + disable_editing_work_plan(sequence) + sequence.load_sequence_data() + + + \ No newline at end of file diff --git a/src/blenderbim/blenderbim/tool/__init__.py b/src/blenderbim/blenderbim/tool/__init__.py index 705120b4b6..261812284d 100644 --- a/src/blenderbim/blenderbim/tool/__init__.py +++ b/src/blenderbim/blenderbim/tool/__init__.py @@ -42,6 +42,7 @@ from blenderbim.tool.qto import Qto from blenderbim.tool.root import Root from blenderbim.tool.spatial import Spatial from blenderbim.tool.structural import Structural +from blenderbim.tool.sequence import Sequence from blenderbim.tool.style import Style from blenderbim.tool.surveyor import Surveyor from blenderbim.tool.system import System diff --git a/src/blenderbim/blenderbim/tool/sequence.py b/src/blenderbim/blenderbim/tool/sequence.py new file mode 100644 index 0000000000..da2e0c8b67 --- /dev/null +++ b/src/blenderbim/blenderbim/tool/sequence.py @@ -0,0 +1,94 @@ +# BlenderBIM Add-on - OpenBIM Blender Add-on +# Copyright (C) 2021 Dion Moult , 2022 Yassine Oualid +# +# This file is part of BlenderBIM Add-on. +# +# BlenderBIM Add-on is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# BlenderBIM Add-on is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with BlenderBIM Add-on. If not, see . + +import bpy +import ifcopenshell +import json +import blenderbim.core.tool +import blenderbim.tool as tool +import blenderbim.bim.helper +import blenderbim.bim.module.sequence.helper as helper +from ifcopenshell.api.sequence.data import Data + + +class Sequence(blenderbim.core.tool.Sequence): + @classmethod + def get_work_plans(cls): + work_plans = {} + for work_plan in tool.Ifc.get().by_type("IfcWorkPlan"): + work_plans[work_plan.id()] = {"Name": work_plan.Name} + return work_plans + + @classmethod + def load_sequence_data(cls): + Data.load(tool.Ifc.get()) + + @classmethod + def enable_editing_work_plan(cls, work_plan): + if work_plan: + bpy.context.scene.BIMWorkPlanProperties.active_work_plan_id = work_plan + bpy.context.scene.BIMWorkPlanProperties.editing_type = "ATTRIBUTES" + + @classmethod + def disable_editing_work_plan(cls): + bpy.context.scene.BIMWorkPlanProperties.active_work_plan_id = 0 + + @classmethod + def get_work_plan_attributes(cls, work_plan): + if Data.is_loaded: + return Data.work_plans[work_plan] + else: + Data.load(tool.Ifc.get()) + return Data.work_plans[work_plan] + + @classmethod + def load_work_plan_attributes(cls, data): + props = bpy.context.scene.BIMWorkPlanProperties + props.work_plan_attributes.clear() + blenderbim.bim.helper.import_attributes("IfcWorkPlan", props.work_plan_attributes, data, tool.Sequence.import_attributes) + + def import_attributes(name, prop, data): + if name in ["CreationDate", "StartTime", "FinishTime"]: + prop.string_value = "" if prop.is_null else data[name].isoformat() + return True + + @classmethod + def get_current_work_plan_attributes(cls): + props = bpy.context.scene.BIMWorkPlanProperties + attributes = blenderbim.bim.helper.export_attributes(props.work_plan_attributes, tool.Sequence.export_attributes) + return attributes + + @classmethod + def get_current_work_plan(cls): + active_work_plan = bpy.context.scene.BIMWorkPlanProperties.active_work_plan_id + ifc_work_plan = tool.Ifc.get().by_id(active_work_plan) + return ifc_work_plan + + def export_attributes(attributes, prop): + if "Date" in prop.name or "Time" in prop.name: + if prop.is_null: + attributes[prop.name] = None + return True + attributes[prop.name] = helper.parse_datetime(prop.string_value) + return True + elif prop.name == "Duration" or prop.name == "TotalFloat": + if prop.is_null: + attributes[prop.name] = None + return True + attributes[prop.name] = helper.parse_duration(prop.string_value) + return True \ No newline at end of file