#!/usr/bin/env python3
# Test stand-in for PrusaSlicer: 20 layers of 0.2 mm with ;Z: markers, like the real one.
# With more than one extruder (nozzle_diameter = a,b) it switches tools every 5 layers, like a multi-color print.
import sys
a=sys.argv[1:]; out=a[a.index("--output")+1]
ini=open(a[a.index("--load")+1]).read()
tools=1
for ln in ini.splitlines():
    if ln.startswith("nozzle_diameter"):
        tools=len(ln.split("=",1)[1].split(","))
L=["G90","M83","M140 S60","M104 S150","G28","M190 S60","M109 S205","G1 X5 Y5 E2 F1000"]
for i in range(20):
    z=round(0.2*(i+1),2)
    L+=[";LAYER_CHANGE",f";Z:{z}",";HEIGHT:0.2"]
    if tools>1 and i%5==0: L.append(f"T{(i//5)%tools}")
    L+=["G92 E0",f"G1 Z{z} F720",f"G1 X{100+i} Y100 E0.5 F1200","G1 X120 Y110 E0.5"]
dens = "filament_density = 1.24" in ini
L+=["M104 S0","M140 S0","; estimated printing time (normal mode) = 42m 10s",
    "; filament used [g] = " + ("7.31" if dens else "0.00")]
if tools>1 and dens: L.append("; total filament used [g] = 7.31")
open(out,"w").write("\n".join(L)+"\n")
