Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit e7b153c

Browse files
committed
You can now generate gantt charts from work schedules
1 parent 9b855be commit e7b153c

6 files changed

Lines changed: 62 additions & 33 deletions

File tree

src/blenderbim/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ endif
184184
cp -r dist/working/python-dateutil-2.8.1/dateutil dist/blenderbim/libs/site/packages/
185185
rm -rf dist/working
186186

187+
# Provides jsgantt-improved supports for web-based construction sequencing gantt charts
188+
mkdir dist/working
189+
cd dist/working && wget https://raw.githubusercontent.com/jsGanttImproved/jsgantt-improved/master/dist/jsgantt.js
190+
cd dist/working && wget https://raw.githubusercontent.com/jsGanttImproved/jsgantt-improved/master/dist/jsgantt.css
191+
cd dist/working && mv jsgantt* dist/blenderbim/bim/data/gantt/
192+
rm -rf dist/working
193+
187194
# Required by IFCDiff
188195
mkdir dist/working
189196
cd dist/working && wget https://github.com/Moult/deepdiff/archive/master.zip
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<link href="jsgantt.css" rel="stylesheet" type="text/css"/>
2+
<script src="jsgantt.js" type="text/javascript"></script>
3+
<div style="position:relative" class="gantt" id="GanttChartDIV"></div>
4+
<script type="text/javascript">
5+
var g = new JSGantt.GanttChart(document.getElementById('GanttChartDIV'), 'day');
6+
var json_data = `
7+
{{{json_data}}}
8+
`;
9+
JSGantt.parseJSONString(json_data, g);
10+
g.Draw();
11+
</script>

src/blenderbim/blenderbim/bim/module/sequence/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
operator.EditTaskTime,
4242
operator.AssignProduct,
4343
operator.UnassignProduct,
44+
operator.GenerateGanttChart,
4445
prop.WorkPlan,
4546
prop.BIMWorkPlanProperties,
4647
prop.Task,

src/blenderbim/blenderbim/bim/module/sequence/operator.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import os
12
import bpy
23
import json
4+
import pystache
5+
import webbrowser
36
import ifcopenshell.api
47
from datetime import datetime
58
from dateutil import parser
@@ -783,3 +786,42 @@ def execute(self, context):
783786
)
784787
Data.load(self.file)
785788
return {"FINISHED"}
789+
790+
791+
class GenerateGanttChart(bpy.types.Operator):
792+
bl_idname = "bim.generate_gantt_chart"
793+
bl_label = "Generate Gantt Chart"
794+
work_schedule: bpy.props.IntProperty()
795+
796+
def execute(self, context):
797+
self.file = IfcStore.get_file()
798+
self.json = []
799+
for task_id in Data.work_schedules[self.work_schedule]["RelatedObjects"]:
800+
self.create_new_task_json(task_id)
801+
with open(os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.html"), "w") as f:
802+
with open(os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.mustache"), "r") as t:
803+
f.write(pystache.render(t.read(), {"json_data": json.dumps(self.json)}))
804+
webbrowser.open("file://" + os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.html"))
805+
return {"FINISHED"}
806+
807+
def create_new_task_json(self, task_id):
808+
task = self.file.by_id(task_id)
809+
self.json.append(
810+
{
811+
"pID": task.id(),
812+
"pName": task.Name,
813+
"pStart": task.TaskTime.ScheduleStart if task.TaskTime else "",
814+
"pEnd": task.TaskTime.ScheduleFinish if task.TaskTime else "",
815+
"pPlanStart": task.TaskTime.ScheduleStart if task.TaskTime else "",
816+
"pPlanEnd": task.TaskTime.ScheduleFinish if task.TaskTime else "",
817+
"pClass": "ggroupblack",
818+
"pMile": 1 if task.IsMilestone else 0,
819+
"pComp": 0,
820+
"pGroup": 1,
821+
"pParent": task.Nests[0].RelatingObject.id() if task.Nests else 0,
822+
"pOpen": 1,
823+
"pCost": 1,
824+
}
825+
)
826+
for task_id in Data.tasks[task_id]["RelatedObjects"]:
827+
self.create_new_task_json(task_id)

src/blenderbim/blenderbim/bim/module/sequence/ui.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def draw_work_schedule_ui(self, work_schedule_id, work_schedule):
100100
row.operator("bim.edit_work_schedule", text="", icon="CHECKMARK")
101101
elif self.props.is_editing == "TASKS":
102102
row.prop(self.props, "should_show_times", text="", icon="TIME")
103+
row.operator("bim.generate_gantt_chart", text="", icon="NLA").work_schedule = work_schedule_id
103104
row.operator("bim.add_summary_task", text="", icon="ADD").work_schedule = work_schedule_id
104105
row.operator("bim.disable_editing_work_schedule", text="", icon="CANCEL")
105106
elif self.props.active_work_schedule_id:

src/blenderbim/ifc_to_gantt.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)