mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
refactor BBIM sequence module - workplans (add, edit, delete)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2020, 2021 Dion Moult <dion@thinkmoult.com>
|
||||
# Copyright (C) 2020, 2021 Dion Moult <dion@thinkmoult.com>, 2022 Yassine Oualid <yassine@sigmadimensions.com>
|
||||
#
|
||||
# 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)
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>, 2022 Yassine Oualid <yassine@sigmadimensions.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
# 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()
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>, 2022 Yassine Oualid <yassine@sigmadimensions.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user