add editing of gantt chart from webui

This commit is contained in:
Ziad-I
2024-07-02 22:22:55 +03:00
committed by Dion Moult
parent 01c7be2b48
commit 166e75db3f
2 changed files with 46 additions and 9 deletions
@@ -1,5 +1,5 @@
// keeps track of blenders connected in form of // keeps track of blenders connected in form of
// shown:bool, work_schedule: {}, task_json: {}, // shown:bool, workSchedule: {}, ganttTasks: {},
const connectedClients = {}; const connectedClients = {};
let socket; let socket;
@@ -40,8 +40,8 @@ function handleBlenderConnect(blenderId) {
if (!connectedClients.hasOwnProperty(blenderId)) { if (!connectedClients.hasOwnProperty(blenderId)) {
connectedClients[blenderId] = { connectedClients[blenderId] = {
shown: false, shown: false,
work_schedule: {}, workSchedule: {},
task_json: {}, ganttTasks: {},
}; };
} }
} }
@@ -70,18 +70,20 @@ function handleGanttData(data) {
if (!connectedClients[blenderId].shown) { if (!connectedClients[blenderId].shown) {
connectedClients[blenderId] = { connectedClients[blenderId] = {
shown: true, shown: true,
task_json: ganttTasks, ganttTasks: ganttTasks,
work_schedule: ganttWorkSched, workSchedule: ganttWorkSched,
}; };
addGanttElement(blenderId, ganttTasks, ganttWorkSched, filename); addGanttElement(blenderId, ganttTasks, ganttWorkSched, filename);
} else { } else {
updateGanttElement(blenderId, ganttTasks, ganttWorkSched, filename); updateGanttElement(blenderId, ganttTasks, ganttWorkSched, filename);
connectedClients[blenderId].workSchedule = ganttWorkSched;
connectedClients[blenderId].ganttTasks = ganttTasks;
} }
} else { } else {
connectedClients[blenderId] = { connectedClients[blenderId] = {
shown: true, shown: true,
task_json: ganttTasks, ganttTasks: ganttTasks,
work_schedule: ganttWorkSched, workSchedule: ganttWorkSched,
}; };
addGanttElement(blenderId, ganttTasks, ganttWorkSched, filename); addGanttElement(blenderId, ganttTasks, ganttWorkSched, filename);
} }
@@ -208,6 +210,10 @@ function addGanttElement(blenderId, tasks, workSched, filename) {
// Function to update gantt and filename // Function to update gantt and filename
function updateGanttElement(blenderId, tasks, workSched, filename) { function updateGanttElement(blenderId, tasks, workSched, filename) {
if (workSched != undefined) {
//TODO: handle updating work schedule table
}
let g = connectedClients[blenderId]["gantt"]; let g = connectedClients[blenderId]["gantt"];
g.ClearTasks(); g.ClearTasks();
g.Draw(); g.Draw();
@@ -250,7 +256,7 @@ function editValue(list, task, event, cell, column) {
const ganttId = task.getGantt()["vDiv"].id; const ganttId = task.getGantt()["vDiv"].id;
const index = ganttId.indexOf("-") + 1; const index = ganttId.indexOf("-") + 1;
const blenderId = ganttId.substring(index); const blenderId = ganttId.substring(index);
const workSchedId = connectedClients[blenderId].work_schedule.id; const workSchedId = connectedClients[blenderId].workSchedule.id;
// update data object reprsenting the task // update data object reprsenting the task
const dataObj = task.getDataObject(); const dataObj = task.getDataObject();
+32 -1
View File
@@ -20,6 +20,7 @@ import bpy
from blenderbim.bim.module.web.data import WebData from blenderbim.bim.module.web.data import WebData
import blenderbim.core.tool import blenderbim.core.tool
import blenderbim.tool as tool import blenderbim.tool as tool
import ifcopenshell.api.sequence
import socket import socket
import os import os
import subprocess import subprocess
@@ -35,6 +36,13 @@ ws_process = None
ws_thread = None ws_thread = None
web_operator_queue = queue.Queue() web_operator_queue = queue.Queue()
IFC_TASK_ATTRIBUTE_MAP = {
"pStart": "ScheduleStart",
"pEnd": "ScheduleFinish",
"pName": "",
"pRes": "",
}
class Web(blenderbim.core.tool.Web): class Web(blenderbim.core.tool.Web):
@classmethod @classmethod
@@ -164,7 +172,30 @@ class Web(blenderbim.core.tool.Web):
@classmethod @classmethod
def handle_gantt_operator(cls, operator_data): def handle_gantt_operator(cls, operator_data):
print(operator_data) ifc_file = tool.Ifc.get()
if operator_data["type"] == "editTask":
task_id = int(operator_data["taskId"])
task_time = ifc_file.by_id(task_id).TaskTime
column = operator_data["column"]
new_value = operator_data["value"]
# editing a parent task time will throw an exception
try:
ifcopenshell.api.sequence.edit_task_time(
ifc_file, task_time=task_time, attributes={IFC_TASK_ATTRIBUTE_MAP[column]: str(new_value)}
)
except AttributeError:
pass
bpy.ops.bim.load_task_properties()
# after updating, send new gantt data to handle the case where
# changing a task cascades and changes other tasks. as this wouldn't
# be reflected in the web ui
work_schedule = ifc_file.by_id(operator_data["workScheduleId"])
task_json = tool.Sequence.create_tasks_json(work_schedule)
gantt_data = {"tasks": task_json, "work_schedule": work_schedule.get_info(recursive=True)}
cls.send_webui_data(extra_data=gantt_data, extra_data_key="gantt_data", event="gantt_data")
@classmethod @classmethod
def open_web_browser(cls, port): def open_web_browser(cls, port):