Skip to content

CURA-13049 process the end variable replacement in the engine#2313

Open
wawanbreton wants to merge 22 commits intomainfrom
CURA-13049_process-the-end-variable-replacement-in-the-engine
Open

CURA-13049 process the end variable replacement in the engine#2313
wawanbreton wants to merge 22 commits intomainfrom
CURA-13049_process-the-end-variable-replacement-in-the-engine

Conversation

@wawanbreton
Copy link
Copy Markdown
Contributor

@wawanbreton wawanbreton commented Mar 27, 2026

This PR proposes a few changes to process the end-of-line variables replacement in the engine. It implements the following changes:

  • When writing a piece of fixed GCode, instead of sending it to the buffer immediatly, it is kept in a FixedGCodePart instance
  • When writing a piece of to-be-resolved GCode, instead of resolving it now and writing it, it is kept in a ResolvedGCodePart instance
  • At the end of the slicing phase, the GCode parts are resolved and send to the front-end in a row.
  • The initial extruder number can now be calculated just before resolving the GCode parts, so that we can use the actual one instead of the supposed one. The value is then sent back to the front-end.
  • The GCode export now calls the Communication object to send the different pieces of information at the proper times, so that the proces is more repeateable across different implementations, and this also removes some facade code in the FffProcessor and FffGCodeWriter.
  • We receive from the front-end some information about the material (density, spool cost and spool weight) so that we can calculate the filament usage stats, which are then inserted in to the resolved GCode, and send back to the front-end for display.

ℹ️ Some technical notes:

  • Since we now store the whole GCode in memory before sending it, the amout of memory used by the engine can possibly be much larger. If this is an issue with very large models, we will have to find a strategy to reduce it.
  • The EmscriptenCommunication has been updated to reach feature parity. However it is to note that the Communication::beginGCode method has been removed, and its content has been placed in the constructor instead. The previous behavior can be restored if necessary.
  • Since the whole GCode is resolved and sent at the end in all cases, this behavior could also be applied to the GCode header by creating the proper variables. This would avoid having a partial-resolved header in some cases and handling the sequential/non-sequential communications separately. I suggest creating a follow-up ticket.

Since this is now easily possible, it also adds a few useful variables to the resolvable GCode:

  • initial_layer_bb_{min_x, max_x, min_y, max_y, width, height} containing the 2D bounding box of the effective print on the first layer (this includes every helper e.g. brim, skirt, prime tower, ...)
  • total_bb_{min_x, max_x, min_y, max_y, min_z, max_y, width, depth, height} containing the 3D bounding box of the models to be printed
  • is_extruder_used containing a list of 16 booleans, indicating which extruder is effectively used during the print

Requires Ultimaker/Cura#21500
Requires Ultimaker/CuraFormulaeEngine#2
CURA-13049

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 27, 2026

Test Results

0 tests   - 31   0 ✅  - 30   0s ⏱️ -4s
0 suites  -  1   0 💤 ± 0 
0 files    -  1   0 ❌  -  1 

Results for commit ecd268a. ± Comparison against base commit eb2e612.

♻️ This comment has been updated with latest results.

wawanbreton and others added 7 commits March 29, 2026 21:57
CURA-13049
Calculating the initial extruder number on engine side allows fixing a
few issues where the pre-supposed initial extruder ended up not being
the same as actually generated by the engine. Now we calculate it after
slicing, so we are really sure this is the correct one, then send it to
the front-end.
CURA-13049
Code was already correct regarding previous behavior, see https://
github.com/Ultimaker/Cura/blob/2cb536439c84ec5f4169008c5682a75d7d6db11a/
plugins/CuraEngineBackend/CuraEngineBackend.py#L876
CURA-13049
In a worst-case-ish scenario, in debug mode, I measured a total
resolving time of 600ms. This time was cut down by half with the multi-
threading, so good to take. The GCodeTemplateResolver has been designed
so that the resolving is a const method, that can be safely be called in
parallel.
@wawanbreton wawanbreton marked this pull request as ready for review April 2, 2026 20:16
@wawanbreton wawanbreton force-pushed the CURA-13049_process-the-end-variable-replacement-in-the-engine branch from 9c354e8 to b45f19f Compare April 16, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant