You can now generate gantt charts from work schedules

This commit is contained in:
Dion Moult
2021-04-21 12:57:31 +10:00
parent 9b855bed2d
commit e7b153cbf6
6 changed files with 62 additions and 33 deletions
+7
View File
@@ -184,6 +184,13 @@ endif
cp -r dist/working/python-dateutil-2.8.1/dateutil dist/blenderbim/libs/site/packages/ cp -r dist/working/python-dateutil-2.8.1/dateutil dist/blenderbim/libs/site/packages/
rm -rf dist/working rm -rf dist/working
# Provides jsgantt-improved supports for web-based construction sequencing gantt charts
mkdir dist/working
cd dist/working && wget https://raw.githubusercontent.com/jsGanttImproved/jsgantt-improved/master/dist/jsgantt.js
cd dist/working && wget https://raw.githubusercontent.com/jsGanttImproved/jsgantt-improved/master/dist/jsgantt.css
cd dist/working && mv jsgantt* dist/blenderbim/bim/data/gantt/
rm -rf dist/working
# Required by IFCDiff # Required by IFCDiff
mkdir dist/working mkdir dist/working
cd dist/working && wget https://github.com/Moult/deepdiff/archive/master.zip cd dist/working && wget https://github.com/Moult/deepdiff/archive/master.zip
@@ -0,0 +1,11 @@
<link href="jsgantt.css" rel="stylesheet" type="text/css"/>
<script src="jsgantt.js" type="text/javascript"></script>
<div style="position:relative" class="gantt" id="GanttChartDIV"></div>
<script type="text/javascript">
var g = new JSGantt.GanttChart(document.getElementById('GanttChartDIV'), 'day');
var json_data = `
{{{json_data}}}
`;
JSGantt.parseJSONString(json_data, g);
g.Draw();
</script>
@@ -41,6 +41,7 @@ classes = (
operator.EditTaskTime, operator.EditTaskTime,
operator.AssignProduct, operator.AssignProduct,
operator.UnassignProduct, operator.UnassignProduct,
operator.GenerateGanttChart,
prop.WorkPlan, prop.WorkPlan,
prop.BIMWorkPlanProperties, prop.BIMWorkPlanProperties,
prop.Task, prop.Task,
@@ -1,5 +1,8 @@
import os
import bpy import bpy
import json import json
import pystache
import webbrowser
import ifcopenshell.api import ifcopenshell.api
from datetime import datetime from datetime import datetime
from dateutil import parser from dateutil import parser
@@ -783,3 +786,42 @@ class UnassignProduct(bpy.types.Operator):
) )
Data.load(self.file) Data.load(self.file)
return {"FINISHED"} return {"FINISHED"}
class GenerateGanttChart(bpy.types.Operator):
bl_idname = "bim.generate_gantt_chart"
bl_label = "Generate Gantt Chart"
work_schedule: bpy.props.IntProperty()
def execute(self, context):
self.file = IfcStore.get_file()
self.json = []
for task_id in Data.work_schedules[self.work_schedule]["RelatedObjects"]:
self.create_new_task_json(task_id)
with open(os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.html"), "w") as f:
with open(os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.mustache"), "r") as t:
f.write(pystache.render(t.read(), {"json_data": json.dumps(self.json)}))
webbrowser.open("file://" + os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.html"))
return {"FINISHED"}
def create_new_task_json(self, task_id):
task = self.file.by_id(task_id)
self.json.append(
{
"pID": task.id(),
"pName": task.Name,
"pStart": task.TaskTime.ScheduleStart if task.TaskTime else "",
"pEnd": task.TaskTime.ScheduleFinish if task.TaskTime else "",
"pPlanStart": task.TaskTime.ScheduleStart if task.TaskTime else "",
"pPlanEnd": task.TaskTime.ScheduleFinish if task.TaskTime else "",
"pClass": "ggroupblack",
"pMile": 1 if task.IsMilestone else 0,
"pComp": 0,
"pGroup": 1,
"pParent": task.Nests[0].RelatingObject.id() if task.Nests else 0,
"pOpen": 1,
"pCost": 1,
}
)
for task_id in Data.tasks[task_id]["RelatedObjects"]:
self.create_new_task_json(task_id)
@@ -100,6 +100,7 @@ class BIM_PT_work_schedules(Panel):
row.operator("bim.edit_work_schedule", text="", icon="CHECKMARK") row.operator("bim.edit_work_schedule", text="", icon="CHECKMARK")
elif self.props.is_editing == "TASKS": elif self.props.is_editing == "TASKS":
row.prop(self.props, "should_show_times", text="", icon="TIME") row.prop(self.props, "should_show_times", text="", icon="TIME")
row.operator("bim.generate_gantt_chart", text="", icon="NLA").work_schedule = work_schedule_id
row.operator("bim.add_summary_task", text="", icon="ADD").work_schedule = work_schedule_id row.operator("bim.add_summary_task", text="", icon="ADD").work_schedule = work_schedule_id
row.operator("bim.disable_editing_work_schedule", text="", icon="CANCEL") row.operator("bim.disable_editing_work_schedule", text="", icon="CANCEL")
elif self.props.active_work_schedule_id: elif self.props.active_work_schedule_id:
-33
View File
@@ -1,33 +0,0 @@
import json
import ifcopenshell
class IfcToGantt:
def __init__(self):
self.json = []
def execute(self):
self.file = ifcopenshell.open("p6.ifc")
self.root = self.file.by_type("IfcTask")[0]
task = self.root
for task in self.file.by_type("IfcTask"):
self.json.append({
"pID": task.id(),
"pName": task.Name,
"pStart": task.TaskTime.ScheduleStart if task.TaskTime else "",
"pEnd": task.TaskTime.ScheduleFinish if task.TaskTime else "",
"pPlanStart": task.TaskTime.ScheduleStart if task.TaskTime else "",
"pPlanEnd": task.TaskTime.ScheduleFinish if task.TaskTime else "",
"pClass": "ggroupblack",
"pMile": 1 if task.IsMilestone else 0,
"pComp": 0,
"pGroup": 1,
"pParent": task.Nests[0].RelatingObject.id() if task.Nests else 0,
"pOpen": 1,
"pCost": 1
})
with open("p6.json", "w") as f:
json.dump(self.json, f)
ifc_to_gantt = IfcToGantt()
ifc_to_gantt.execute()