Expand description
What the slicer planned to print at each height, indexed once per print from the print’s own G-code.
A supervising agent judging a frame needs to know what should be there:
a support tower, a bridge or an overhang the slicer planned looks, to a
camera, much like a defect. The slicer wrote that plan into the file, and
this module reads it: one streamed pass over the whole file builds a
GcodeIndex, and every check after that reads the plan at the print’s
current file position from the index rather than from the file. The agent
is handed only what is derived — a SlicerPlan — and never a line of
G-code.
§What is read
;LAYER_CHANGEstarts a layer and the;Z:after it is its height: the markersPrusaSlicerwrites. The last layer’s height is the final one.;TYPE:<name>names what the moves after it extrude —Perimeter,Support material,Bridge infill— and a layer’s types are those under which any move of that layer laid material.Customis left out: it labels the slicer’s own start and end G-code rather than the part.M73 P<percent> R<minutes>is the slicer’s own estimate of the time left, in the normal mode. The silent mode’sM73 Q<percent> S<minutes>is ignored.M221 S<percent>sets the flow factor andM106 S<0–255>the part cooling fan, whichM107turns off; a fan named by aPother than0is not the part-cooling fan.M486 S<n>starts laying down objectnandM486 S-1stops; anM486 A<name>labels the file’s objects too, though no name is kept. An object’s bed area is the rectangle every move laying material for it reached — an arc’s the extremes of the part of its circle it sweeps, so a footprint is never smaller than what was laid and a nearly straight arc about a far centre is no larger than the line it nearly is — read to the nearest tenth of a millimetre and then widened to whole millimetres.
Everything else is a move or nothing to this reader: G0–G3 with
G90/G91, M82/M83, G92 and G28 are followed so that what laid
material, and where, is known; a comment is not a command, a leading
N<line number> is not a word, and *<checksum> ends the line.
§The planned geometry
The same read records each object’s outline, where each object’s labelled
block starts and each layer’s byte range, and — when the supervisor is
given a spool directory — copies the file’s bytes to a per-print spool, so
a layer’s toolpath (crate::toolpath) is read back from the spool rather
than from a second read of the printer’s file. The spool is deleted when
the print closes, and at start-up for any print no longer open.
§Where a position falls
A line counts when every byte of it, its newline included, lies before the
position — OctoPrint’s file position is the offset after the last line it
read. So a marker the printer has read is in force, and one it is part-way
through is not yet.
§Once per print
GcodeIndexes holds each print’s index in memory for as long as this
process runs. The first check or context read after a print starts builds
it; a read arriving while it is being built waits for that build rather
than starting a second, and no read after it touches the file. A read that
failed builds nothing, so the next one tries again; a file whose markers
are missing builds an index that says so (PlanFact), which is not a
failure.
Structs§
- Build
Claim - The one caller building a print’s index. Dropping it unfinished hands the build to whoever asks next, and wakes everyone waiting.
- Claim
- The future
GcodeIndexes::claimanswers. - Gcode
Index - One file’s slicer plan, by file position.
- Gcode
Indexes - Every print’s index, held for as long as this process runs.
- Index
Builder - Builds a
GcodeIndexfrom a file streamed into it, a piece at a time, in one pass: theGcodeSinkthe printer port’s whole-file read feeds. - Rise
- How far the plan has risen since one earlier frame of this print that was seen: the height a camera should show the parts to have gained since then.
- SetIn
File - What a file set one adjustable to, as of a file position: the value, and the offset just past the line that set it.
- SetValue
- One adjustable as the print’s file set it at the current position, and as a change made through this program since then left it.
- Slicer
Plan - What the slicer planned at the print’s current file position: the shape and place of what should be printing, read from the print’s own G-code.
Enums§
- Claimed
- What asking for one print’s index answered.
- Plan
Fact - A fact of the plan the print’s file does not state.
- Plan
Mismatch - A setting in force that the plan at this height says is wrong for what is being laid.
Functions§
- index_
of - Build one file’s index from its pieces, in order — what the whole-file read does with the pieces it is handed.
Type Aliases§
- BedArea
- The bed area one object of the print covers: the rectangle
[x_min, y_min, x_max, y_max]its material reaches, in whole millimetres — each edge read to the nearest tenth, then each least edge rounded down and each most edge up, so that it holds every move laying that object down.