mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
You can now generate gantt charts from work schedules
This commit is contained in:
@@ -184,6 +184,13 @@ endif
|
||||
cp -r dist/working/python-dateutil-2.8.1/dateutil dist/blenderbim/libs/site/packages/
|
||||
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
|
||||
mkdir dist/working
|
||||
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.AssignProduct,
|
||||
operator.UnassignProduct,
|
||||
operator.GenerateGanttChart,
|
||||
prop.WorkPlan,
|
||||
prop.BIMWorkPlanProperties,
|
||||
prop.Task,
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import os
|
||||
import bpy
|
||||
import json
|
||||
import pystache
|
||||
import webbrowser
|
||||
import ifcopenshell.api
|
||||
from datetime import datetime
|
||||
from dateutil import parser
|
||||
@@ -783,3 +786,42 @@ class UnassignProduct(bpy.types.Operator):
|
||||
)
|
||||
Data.load(self.file)
|
||||
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")
|
||||
elif self.props.is_editing == "TASKS":
|
||||
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.disable_editing_work_schedule", text="", icon="CANCEL")
|
||||
elif self.props.active_work_schedule_id:
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user