Skip to content

CURA- 12556 formula parser in cura engine#2274

Open
wawanbreton wants to merge 29 commits intomainfrom
CURA-12556_formula-parser-in-CuraEngine
Open

CURA- 12556 formula parser in cura engine#2274
wawanbreton wants to merge 29 commits intomainfrom
CURA-12556_formula-parser-in-CuraEngine

Conversation

@wawanbreton
Copy link
Contributor

@wawanbreton wawanbreton commented Jan 16, 2026

This PR moves the GCode-template replacement algorithm from the Cura front-end to the engine. This allows for more flexibility because the engine has more information when resolving the templates. Especially for the extruders start/end GCodes, which can now be different between each layer.

It also introduces 2 new variables that can be used in the exutrders GCode:

  • previous_extruder_nr in the extruder start/prestart GCode, that contains the ID of the extruder we are switching from
  • next_extruder_nr in the extruder end GCode, that contains the ID of the extruder we are switching to

ℹ️ It was also discussed to replace the final substitution that is done in the front-end, to the engine. This is done once the whole GCode has been generated, to insert e.g. the total duration of the print. However, the GCode content is sent to the front-end immediatly after each layer is completed, at which point some layers are still to be processed. So given this process, it is currently impossible to make this change. It would require to send the whole GCode at once, which has other implications and may reduce global performance. This will be discussed further in a other ticket.

Ultimaker/Cura#21306
CURA-12556

CURA-12556
Although this is quite counter-intuitive, it is how the front-end currently works, so we want to keep the same behavior
CURA-12556
This requires using boost::regex instead of std::regex which doesn't support named capture groups. In this context, they are useful to allow some groups to be present or not and knowing what the expression is actually composed of. Index-based capture groups don't allow that.
CURA-12556
Ported from frontend StartSliceJob.py:GcodeStartEndFormatter
@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2026

Test Results

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 684bfb5.

♻️ This comment has been updated with latest results.

Copy link
Member

@rburema rburema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'C++ Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: 4cd5086 Previous: 2e6f6f9 Ratio
SimplifyTestFixture/simplify_slot_noplugin 1.886970768092735 ns/iter 1.2487941865752963 ns/iter 1.51

This comment was automatically generated by workflow using github-action-benchmark.

CC: @nallath @jellespijker @wawanbreton @casperlamboo @saumyaj3 @HellAholic

Copy link
Contributor

@casperlamboo casperlamboo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small remark, the npm packaging seems to be broken due to this PR. If not too much trouble could you see if you can fix it here. Otherwise we'll fix it when we make the neoprep upgrade.

rburema and others added 2 commits February 12, 2026 09:29
CURA-12556
One of the values will be a duplicate of extruder_nr, however it is much less confusing because otherwise you have to know which one is available in either the start or end gcode.
CURA-12556
Otherwise it is not possible to get the extruder_nr variable when resolving the extruder number for the expression. In this case one should not specify it, but they may also do a calculation based on this number.
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.

3 participants