Commit Graph
65 Commits
Author SHA1 Message Date
SoftFever 645610f015 Let Slice and Print retry after a post-processing script or plugin fails (#17095)
(cherry picked from commit 1093ff0714)
2026-11-01 09:53:53 +08:00
Arthur Porto ee6c30d5c1 Give each object the layer height limits of its own extruder, and compare layers rather than limits for the prime tower (#17000)
* Test the layer height limits taken for an object, and that they don't keep objects from sharing a prime tower

* Take the layer height limits from an object's own extruder, and don't let them refuse a prime tower

* Test the prime tower check through Print::validate(), and shorten the equal_layering comment

The test runs Print::validate() on two cubes, on filaments 1 and 3 of a printer whose first extruder allows thicker layers than the others. Without this PR, and with only the index fix, it fails with the refusal from #16938. It uses filament 3 because filament 2 read extruder 1's limits before the index fix.

---------

Co-authored-by: raistlin7447 <kris.austin@gmail.com>
(cherry picked from commit fcd96ad91c)
2026-11-01 09:53:53 +08:00
yw4zandcook0001 ab24043937 Make plate renames undoable and refresh G-code that uses {plate_name} (#16900)
Renaming a plate now creates an undo snapshot, so a rename is its own undo step and marks the project as modified. All four rename paths use the new `Plater::rename_plate()`.

When a G-code template uses `{plate_name}`, renaming a sliced plate invalidates only the G-code export step, so the next slice only re-exports the G-code. `filename_format` is excluded because the file name is built from the current plate name at export time.

The "Rename Plate" undo snapshot is from #16141.

Co-authored-by: cook0001 <79376116+cook0001@users.noreply.github.com>
2026-10-26 13:25:16 -05:00
Valerii Bokhan 887a8f1806 Feature: Add experimental high precision G-code export (#16568) 2026-10-25 16:29:13 -03:00
HanifKoh ca51cba597 Refuse a Filament Flow Ratio of 0 Instead of Writing NaN Extrusion (#16719)
A used filament with a flow ratio of 0 sliced in the GUI and wrote
E-92233720368547.758 on every extrusion move: GCode::_extrude multiplied
the flow by the ratio and divided by it again, giving 0 * 0 / 0 = NaN.
The CLI already rejected the value through the config check, but
Print::validate never looked at it.

Print::validate now stops the slice with an error naming the filament
when a used filament's flow ratio is 0 or nil, and _extrude converts the
flow to extrusion length with the bare filament cross-section, so the
ratio is applied once without a divide.
2026-10-25 03:39:51 +08:00
Ian Bassi 258ddc15e8 Fix a crash from the Russian extruder range warning, and check plural placeholders in CI (#16815) 2026-10-24 15:44:49 -03:00
SoftFever f92f75e0fa Feat: Add multiple and 3D bed exclusion volumes (#13777)
# Description

This PR adds opt-in, height-aware exclusion volumes to OrcaSlicer,
including multi-nozzle handling, object and generated-geometry
validation, final G-code collision checking, and travel rerouting.

It grew from the original object-placement prototype into a
collision-aware slicing pipeline with documented limitations. The
central compatibility decision is that Orca's existing
`bed_exclude_area` keeps its historical meaning, while the new
`bed_exclude_volumes` setting explicitly enables the stronger
collision-aware behavior.

<img width="935" height="707" alt="Travel paths routed around exclusion
volumes"
src="https://github.com/user-attachments/assets/22925e5c-a3b1-4c26-be1a-8a89d9970cb5"
/>

Related issues: #5922, #10579, #10638 and #12774.

## Why this is useful

The existing 2D exclusion area prevents object placement in areas such
as the filament-cutter corner on Bambu printers. It cannot describe low
bed clips, raised tool docks, camera arms, flying-gantry hardware, or
other obstacles that occupy only part of the printer's Z range.

Treating every existing area as a physical motion obstacle would also be
unsafe for compatibility: some printers deliberately move into their
excluded material area. This PR therefore separates the two concepts
rather than changing the meaning of existing profiles.

| Setting | Purpose | Existing motion affected? |
| --- | --- | --- |
| `bed_exclude_area` | Existing bed-fixed material/placement keep-out |
No G-code checking or travel rerouting |
| `bed_exclude_volumes` | Shared 3D collision volumes |
Object/generated-material checks, G-code validation and travel rerouting
|
| `extruder_bed_exclude_volumes` | Per-extruder 3D collision volumes |
Same collision behavior, resolved for the active physical nozzle |

Bed areas and collision volumes are additive. A printer can retain an
existing cutter/material keep-out while adding separate physical
collision volumes. Belt printers retain the existing projection of bed
areas onto the tilted belt surface; collision volumes remain in model
coordinates.

## Configuration and syntax

`bed_exclude_volumes` accepts one or more polygonal prisms:

```text
XxY,XxY,...
```

defines a full-height collision volume.

```text
REGION|REGION|REGION
```

defines multiple independent volumes.

```text
ZMIN..ZMAX;XxY,XxY,...
```

defines a volume active only across that Z range. Either Z bound may be
omitted:

```text
..10;20x20,40x20,40x40,20x40
30..;20x20,40x20,40x40,20x40
```

For example:

```text
20x0,45x0,45x18,20x18|8..22;115x20,145x20,145x48,115x48
```

defines one full-height volume and one volume active from Z=8 mm to Z=22
mm. Z ranges are validated and clamped against the configured printable
height, and decimal parsing is locale-independent.

The CLI exposes the same distinction:

```text
--bed-exclude-area
--bed-exclude-volumes
```

Existing scripts using `--bed-exclude-area` retain the original polygon
format and behavior.

## Backward compatibility and migration

- Existing profiles and projects using only `bed_exclude_area` keep its
material/placement keep-out meaning; they do not implicitly enable
collision-volume checking or travel rerouting.
- Stock printer motion is not checked or rerouted against bed areas.
This is important for machines that deliberately enter an excluded
material area during cutting or loading.
- The new syntax is stored under separate config keys, so an older Orca
build does not try to deserialize a volumetric string as the existing
point-list option.
- In **Printer settings → Basic information → Printable space**,
**Excluded bed area** remains a normal editable field with Orca's
standard reset controls. **Toolhead collision volumes** is a separate
field directly below it. There is no Convert/Copy button and neither
setting clears the other.
- A bed-area polygon can be manually copied into the collision-volume
field to describe a full-height physical obstacle. Pasting volume syntax
into the bed-area field instead prompts for confirmation before adding
it to the appropriate volume definitions. The saved bed area, existing
volumes and selected nozzle mode are preserved; cancelling leaves them
unchanged.
- If a user does not configure the new volume keys, the new G-code
checker, rerouter, support trimming and nozzle-specific brim behavior
remain inactive.

This gives existing profiles a stable compatibility boundary while
allowing users and maintainers to migrate deliberately to full collision
checking over time.

## Multi-nozzle behavior

For multi-nozzle printers, the collision-volume mode selects one of
three behaviours. In individual mode, each extruder's definition is
edited on its own Extruder settings page. These modes apply only to
collision volumes; the excluded bed area stays shared and bed-fixed.

Collision volumes support three modes:

<img width="549" height="441" alt="Exclusion volume behavior selector"
src="https://github.com/user-attachments/assets/6ca8c2e2-d00e-4b32-9b12-bfbff0928966"
/>

### Shared

Every physical nozzle uses the same collision-volume definition.

<img width="2353" height="1633" alt="Shared exclusion volumes"
src="https://github.com/user-attachments/assets/96fe938b-07b4-4cd9-b587-e31f2ebba5f8"
/>

### Toolhead-relative (nozzle offsets)

The shared definition is treated as relative to the toolhead. Orca
derives the other nozzles' collision regions using their configured XY
offset from the reference nozzle. This is useful where the same physical
carriage must avoid an obstacle but its position changes when a
different offset nozzle prints at the same model coordinate.

<img width="1084" height="803" alt="Toolhead-relative exclusion volumes"
src="https://github.com/user-attachments/assets/e0790ee4-68b5-444f-90ac-22a5eba05eec"
/>

### Individual per extruder

Each physical extruder/nozzle has its own independent volume definition.
This supports machines whose valid region differs by tool and cannot be
derived from a simple nozzle offset.

<img width="1123" height="761" alt="Independent exclusion volumes for
three extruders"
src="https://github.com/user-attachments/assets/c6404ceb-9958-4df8-93ed-5ff2ac7dc658"
/>

Object validation resolves logical filament assignments to the physical
nozzle or nozzles that may print the object, including automatic Bambu
mapping. If an object may use several nozzles through painting,
feature-level assignments, modifiers, support or interface material, the
complete object is conservatively checked against every relevant
nozzle's volumes.

## Object validation and 3D preview

Object collision detection uses a cheap XY/Z broad phase followed by an
exact mesh-versus-prism test. The exact test:

- Avoids rejecting an object whose XY shadow overlaps a raised volume
while its real mesh remains clear.
- Detects normal surface crossings.
- Detects a volume completely enclosed inside a solid model.
- Respects object-instance and model-volume transforms.
- Separates the collision decision from optional preview-mesh
generation.

When a collision is found, Orca reports the relevant extruder where
possible and renders the intersecting model surface in red. The bed
preview shows a neutral grey footprint, a thin nozzle-colored ownership
border where appropriate, and a translucent 3D prism when a nearby
object makes the volume relevant. Raised volumes keep their ownership
outline on the bed rather than floating at their starting Z.

<img width="578" height="534" alt="Red model and exclusion-volume
intersection preview"
src="https://github.com/user-attachments/assets/d409f574-1790-48e5-b4a3-703273439954"
/>

Single-nozzle/shared geometry remains visually neutral; nozzle colors
are used when they convey distinct tool ownership.

The default automatic preview limits the translucent 3D geometry to
nearby object height to avoid obscuring the workspace. **View → Show all
collision volumes** displays the complete configured Z ranges, including
on an empty bed. Its default shortcut is **Ctrl+Shift+V**
(**Command+Shift+V** on macOS), and it can be changed in the shortcut
settings. Orca remembers this application-level display preference
independently of printer presets; it does not change collision checks or
slicing.

## Arrange and Fill Bed

Arrange and Fill Bed receive Z-aware, nozzle-aware obstacles, so an
object may occupy a footprint belonging only to another nozzle or pass
below a raised volume when its height permits it.

- Existing objects remain obstacles when Fill Bed creates new copies.
- Convex volume footprints are passed through accurately.
- Orca's current libnest2d path supports convex NFP obstacles only, so
non-convex volumes use a documented conservative bounding box until
convex decomposition is implemented.
- Orca's existing final alignment and normal unplaced-item behavior are
retained.

<img width="1097" height="846" alt="Fill Bed with multiple tools and
exclusion volumes"
src="https://github.com/user-attachments/assets/8c0ee5cf-624b-42a6-b57a-13c73400ac5c"
/>

## Brim and support generation

When collision volumes are enabled, object and support brims are clipped
against the relevant first-layer volume footprints before their final
extrusion paths are generated. Brim ownership is retained so touching
object and support brims cannot be merged and silently reassigned to a
nozzle whose volume they intersect. Established bed-edge and bed-area
brim clipping remains unchanged when collision volumes are not
configured.

<img width="1139" height="770" alt="Object and support brims clipped
around nozzle-specific volumes"
src="https://github.com/user-attachments/assets/2913ff31-53e4-4e43-8b27-1afba7e3bafb"
/>

Normal support and raft polygon categories are trimmed against the
relevant volumes over each support layer's actual vertical slab.
Support-material resolution accounts for explicit support/interface
tools, “current filament” behavior, alternating material layers,
automatic physical-nozzle mapping, support brims, and shared support
geometry.

TreeSupport3D receives active exclusion geometry during branch planning
so its existing avoidance machinery can steer branches around obstacles
rather than merely cutting finished paths.

## Final G-code collision validation

The final emitted G-code is checked as a safety backstop after slicing.
The checker tracks:

- The active physical nozzle and its XY offset.
- Absolute and relative XY/Z motion.
- Travel, extrusion and other parsed motion types.
- Tool selection and physical/nozzle mapping.
- Explicit motion in start, filament-change and tool-change G-code.
- Coordinate resets and common `G28` forms, including bare, spaced,
compact and parameterized axis selections.

Material keep-outs from `bed_exclude_area` are deliberately ignored by
the motion checker. Only explicit collision volumes constrain motion.

If Z is genuinely unknown, the check is conservative across all relevant
heights and the warning identifies that fact and includes the relevant
G-code line. The artificial first segment that the preview draws from
`(0,0)` is not treated as a real machine move.

## Travel rerouting

Generated travel moves are rerouted around active collision volumes when
a valid route exists.

Routing is:

- Aware of the travel's actual Z slab and planned lift/Z-hop.
- Resolved for the active physical nozzle.
- Constrained so any detour vertices added by Orca remain inside the
printable bed.
- Able to accept firmware-established start/end points on or beyond the
nominal bed edge.
- Revalidated before the replacement path is emitted.

The implementation covers ordinary generated travels, the first
generated move after start G-code, and moves following physical or
same-nozzle filament changes. Explicit movement commands in custom
start/tool-change G-code update the tracked position so the next
generated travel begins from the correct point without defeating Orca's
post-toolchange Z restoration.

Obstacle geometry is cached by extruder and active Z-region set, with
bounding-box rejection before expensive polygon work. Clear travels
therefore avoid repeatedly unioning and offsetting the same obstacles.

If no safe route can be found, Orca leaves the original move for the
final checker to report rather than emitting an assumed-safe detour.
Extrusion paths are validated but never rerouted.

<img width="1286" height="706" alt="Travel rerouting from start G-code
across multiple Z-aware volumes"
src="https://github.com/user-attachments/assets/a68cd98f-5576-4f78-af43-697e9f687a9b"
/>

And here is an example of independent nozzle travel rerouting:
<img width="2532" height="876" alt="image"
src="https://github.com/user-attachments/assets/28b0c26e-59d6-42b9-a64f-4c2205c4ea3f"
/>


## Testing and review status

Targeted Catch2 coverage now includes:

- Bed-area/volume parsing, validation, confirmed paste handling,
additive behavior and CLI options.
- Belt-surface projection of bed areas through both static and dynamic
region resolution, including the reported cube positions, with collision
volumes left unprojected.
- Shared, toolhead-relative and individual per-extruder resolution.
- Physical-nozzle and filament mapping.
- Exact object intersection, including fully enclosed prisms and
transformed instances.
- 3MF persistence.
- Arrange behavior for convex and non-convex obstacles.
- Brim bed-boundary and volume clipping regressions.
- Support and interface-material masks across support polygon
categories.
- G-code motion classification, coordinate tracking, homing forms and
tool selection.
- Safe travel rerouting, Z-aware activation, nozzle selection, off-bed
firmware endpoints and failure cases.

The reviewed `929beaee15` revision passed the CI checks, and review
testing confirmed that the unit tests and earlier arrange, tool-change Z
restoration, support, brim and brim-ownership regressions still pass.
Stock-output comparisons covered 12 printers × 3 jobs plus 17 project
files and produced G-code identical to `main` when the new feature was
not configured.

The belt projection correction and its regression coverage are included
in the latest update. Please use the checks below for the current head's
build and test status; earlier successful runs do not substitute for
validation of a new revision.

Review also compared CLI output against `main` across stock printers and
multi-filament projects. The compatibility regressions found during that
review—including stock Bambu cutter motion, preset dirty state,
unintended bed-area brim/support changes, tool-change Z restoration,
stale post-change origins, arrange rejection, router cost, locale
parsing and bed-edge brim clipping—have been addressed.

## Known limitations and follow-up work

The implementation deliberately favors conservative safety. A false
positive or some unused build volume is preferable to emitting a
movement that may collide with the machine. Collision warnings are not
an automatic repair or a guarantee of safe output.

- Skirts and draft shields are not regenerated or detoured around
collision volumes. The final checker can report an intersection, but
producing a valid closed loop around internal obstacles while remaining
inside the bed needs a dedicated solution.
- Extrusion paths are checked but not rerouted.
- Spiral Z-hop's circular XY sweep is generated after the primary travel
route has been planned. That sweep is not currently rerouted; the final
G-code checker can report a collision, but does not repair it.
- Orca cannot infer movement hidden inside an opaque firmware macro. A
deterministic macro endpoint should be exposed with explicit `G90`/`G91`
and `G0`/`G1` motion in Orca's custom G-code so the following travel can
be routed from a known position. Movements inside custom G-code are
checked, but only the generated travel after them is rerouted.
- Negative model parts are not applied to the raw object-intersection
mesh, so geometry removed only by a negative part can produce a
conservative false positive.
- Multi-nozzle object validation applies every relevant nozzle's volume
to the complete object rather than only its visibly painted surface.
- Support shared by several instances uses a conservative union of
relevant plate-space exclusions.
- Support avoidance trims or steers generated geometry but does not
perform structural support re-planning. Support above a raised volume
may resume over a void; native tree-support paths not using
TreeSupport3D are not yet volume-aware.
- Raised-only collision volumes are not yet fully represented in
prime/wipe-tower placement validation; the final G-code checker remains
the safety backstop.
- Existing cross-object support-to-support overlap behavior is outside
this PR.
- “No tool selected” carriage-only exclusions are not represented by
Orca's current backend and remain a possible future extension.

## Origin

This work began with the [Muon3D
M1](https://www.youtube.com/watch?v=jBatFQpTM6g), whose notched glass
bed leaves usable print volume above a low obstruction. Upstreaming the
capability lets other printers describe low clips, raised docks,
toolchanger hardware and per-tool clearance limits without requiring a
permanent fork.

Thank you to everyone who tested the implementation, reviewed the
architecture, identified regressions and helped improve the test
coverage—especially the multi-tool and macOS testers. Further
real-hardware feedback remains welcome, but the current implementation
and compatibility behavior are ready to merge.

Harry Loud  
Muon3D
2026-10-22 22:04:40 +08:00
Kris Austin 14a1aa333b Fix custom G-code placeholders missing on some paths and in the editor (#16680)
Some calls of the same script set fewer placeholders than the others,
so a placeholder the editor offers could stop the slice with "Variable
does not exist" on one path only:

- layer_change_gcode set max_layer_z after processing the template.
- Belt brim layers ran layer_change_gcode without
  most_used_physical_extruder_id or the mass values. Both layer change
  paths now share one helper.
- Printers that aren't bed slingers ran time_lapse_gcode with only
  layer_num, layer_z and max_layer_z. Both timelapse paths now share
  one helper for the snapshot placeholders, which picks the snapshot
  position only when the template uses it.
- The Type 1 wipe tower ran filament_start_gcode without layer_num,
  layer_z and max_layer_z, and filament_end_gcode without
  filament_extruder_id and max_layer_z. filament_extruder_id is the
  filament being unloaded, as in the Type 1 filament start G-code and
  the end-of-print filament end G-code.
- The first filament start G-code on Bambu Lab printers had no layer_z
  or max_layer_z.

The editor looks up a script's placeholder list by its option key, but
the timelapse list was keyed timelapse_gcode while the option is
time_lapse_gcode, so the editor showed no timelapse placeholders. The
list and the name passed to placeholder_parser_process, which the
placeholder validator looks up by, are now both time_lapse_gcode.

previous_extruder and next_extruder hold filament indexes, and
previous_extruder is -1 before any filament is loaded.
filament_extruder_id is the extruder index in filament end G-code at a
tool change outside the Type 1 wipe tower, and machine end G-code gets
the value from the last end-of-print filament end G-code. layer_num is
-1 before the first layer. total_wipe_tower_filament is a length in mm.
2026-10-21 15:05:16 -05:00
Kris Austin 8a14a0383f fix: error on calculations with post-processed placeholders (#16597)
Placeholders that GCodeProcessor fills in after the G-code is generated
(print_time_total_sec and the other print_time_* parts,
used_filament_length, and the print statistics such as total_weight)
hold a tag such as @TOTAL_WEIGHT@ while the template is evaluated.
Multiplying one already failed with a type error. Adding a number
joined the tag as text, so {total_weight + 5} printed 123.455 for a
123.45 g print, and a comparison compared the tag as text, so
{if total_weight > 100} was always true. Neither gave an error.

PlaceholderParser::set_deferred() now registers such a value. Printing
it and joining it to text work as before. A calculation, a comparison,
a regex or a condition on it fails with an error that says the value is
known only after the G-code is generated, also after it was copied to a
variable or through regex_replace(). Adding a number or another
deferred value to one is treated as a sum and fails too. Text that
already contains one joins a number as text, like any other string.

filament_change() inside an {if} branch that is not taken now does
nothing. It used to set the current extruder from an uninitialized
value.
2026-10-20 21:01:50 -05:00
Rodrigo Faselli c67a46a277 Merge branch 'main' into feat-3D-Exclusion-Volumes 2026-10-19 09:59:50 -03:00
Ján Mišenko c6804fbb68 fix: print statistics placeholders fail in custom G-code (#16348)
The G-code editor lists the Print Statistics placeholders for every
custom G-code field, but total_weight, used_filament, total_cost,
print_time, normal_print_time, silent_print_time,
total_wipe_tower_cost and total_wipe_tower_filament were only defined
for filename_format. Using one in custom G-code, including the File
header G-code, stopped slicing with "Not a variable name".

They are known only once the whole G-code is generated, so they use the
reserved-tag mechanism of print_time_sec and used_filament_length: the
placeholder parser gets a tag such as @TOTAL_WEIGHT@ and
GCodeProcessor::run_post_process() replaces it with the same value
filename_format gets, with numbers written to two decimals. The
per-tag replacement loops are folded into one helper. The running
extruded_* totals are unchanged.

Fixes #15320
Fixes #7870
2026-10-16 16:30:05 -05:00
Harry Loud 247e903cbe Merge upstream/main and resolve exclusion volume integration conflicts 2026-10-15 18:05:19 +01:00
fa1k3 f1658855c8 Apply filament shrinkage compensation on the first slice (#16312)
Print::apply() decided the shrinkage compensation from the existing PrintObjects and their regions. On the first apply() they do not exist yet, so the first slice was not scaled. The CLI calls apply() only once, so filament_shrink and filament_shrinkage_compensation_z had no effect there.

The compensation is now decided before the PrintObjects are built, from the filaments the model uses, and stored in Print. When the filaments have different shrinkage values, every filament assigned to a feature, height range, modifier, support, tool change or the wipe tower counts, even if it does not end up printing. If they disagree, compensation stays off with the existing warning.
2026-10-14 09:39:08 -05:00
fa1k3 f32591ed64 Check the real print height: count the Z shrinkage compensation once and include the raft (#16313)
The build height check in Print::validate() compared object layers that already include the Z shrinkage compensation against printable_height divided by that compensation. That counted the compensation twice, so objects that fit were rejected. The check also left out the raft, so an object whose top plus the raft is above printable_height passed validation.

The check now adds object_print_z_min to the top layer and applies the compensation once. The shrinkage message is shown only when the object fits without the compensation. Belt printers apply the compensation to the raw model height, since their height does not come from the layers.
2026-10-13 19:36:47 -05:00
SoftFever 6263502697 Free a sharing object's own layers only when it takes over the shared ones 2026-10-13 00:15:07 +08:00
Harry Loud 2c0ce5c38b Merge upstream/main and refine exclusion-volume configuration UI 2026-10-09 18:27:44 +01:00
harrierpigeonandClaude Fable 5.1 cfad587c2d Belt: follow-ups from a second review pass
Guard the layer count and the per-object layer collection against an
object that is left without a layer to print on a belt (the counting
loop stepped before begin() and front() was taken of an empty vector).
Check the belt temperature tower's embossed model before the current
project is replaced, not after.  Only invalidate the support step of
objects that own a belt brim when an object is added or removed.  The
empty-layers test now counts an extrusion only where material is laid
down along a move.  The BeltBrim.cpp SEQUENCING note says exactly which
layers are read, and the machine-frame scale is 1/|sin|.

Remove more code that nothing calls: the kinematics inverse
(to_logical, apply_axis_remap_inverse, to_build_volume and the state
kept for them), the world_coordinates(), is_active() and
belt_brim_areas_by_layer() accessors, the PrintConfig overload of
physical_tilt() and the DynamicPrintConfig overload of
compute_belt_height_and_floor().  Comments in GCode.hpp,
BeltSliceStrategy.hpp/.cpp and PrintObjectSlice.cpp that described the
retired pre-slice remap and plane-evaluator still did; the purge-tower
width tooltip named the wrong switch.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-07 19:08:59 -05:00
harrierpigeonandClaude Fable 5.1 febd82f6df Belt G-code: count only the layers that are written
collect_layers_to_print() drops the belt layers that print nothing (an
object's empty lead-in), but m_layer_count still counted every object
and support layer, so "total layers count", the total_layer_count
placeholder and the M73 progress disagreed with the layer changes in the
file.  Count with the same predicate, shared through
belt_object_layer_prints_something().  The by-object overload of
collect_layers_to_print() now drops those layers as well, so both print
sequences write the same layer changes.

Dropping the empty entries per object has one more effect on multi-
filament belt prints: a layer no longer selects a filament that it then
prints nothing with.  On belt_project.3mf (two filaments, belt purge
tower) the T commands go from 472 to 106 while the extruded length per
filament is unchanged; each of the removed tool changes was followed by
no extrusion.

The empty-layers test now runs for both print sequences and also checks
"total layers count" against the layer changes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-07 19:08:58 -05:00
harrierpigeonandClaude Fable 5.1 54e079ae25 Organic supports: restore the per-slice collision, bed and belt trim
dda58b07cd stripped debug instrumentation from TreeSupport3D.cpp with a
script, and that script also deleted the loop in organic_draw_branches()
that trims every branch slice against the collision volume, the bed and,
on a belt, the belt plane.  This is the generator every printer uses, not
a belt code path, and it is the one place where raistlin7447's export
fixtures differed from main with belt printing off.  Restore the loop as
it was on main, with the belt-floor clip.

The new test prints a cube carrying a 60 mm plate with organic supports
on a flat-bed printer and checks on every support layer that no support
extrusion comes within 0.2 mm of the part's slice.  It guards that
invariant; on this fixture the loop's own effect is a sub-millimetre
reshaping of one branch (verified by slicing the fixture with and
without the loop), below the asserted gap, so the test does not by
itself fail without the loop.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-07 18:24:27 -05:00
harrierpigeonandClaude Fable 5.1 ef6d4a71de Tests: qualify Polyline in the belt overhang test for Windows
Windows headers declare a global Polyline, so the unqualified name in
test_print.cpp is ambiguous there (both Windows builds of belt-printer
fail at tests/fff_print/test_print.cpp:1336), as Polygon was in #16196.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-07 14:11:15 -05:00
harrierpigeonandClaude Fable 5.1 f64b49ab52 Belt printer: no layer changes that print nothing, and a preview that survives them
Since the slicing frame of a belt object starts at the belt below its
leading end, its first layers are empty.  On a single part they carry
the brim bands; with several parts along the belt the later parts'
empty layers fall between the earlier parts' printing layers and were
written to the G-code as layer changes with no moves at all.  The
preview numbers its layers (libvgcode::Layers) from the vertices it is
given and expects consecutive ids, so at the first such gap it stopped
creating layers and folded everything after it into the last one: the
top slider layer held nearly the whole print, the slider jumped every
other layer through the single-colour stretch before a second part on
another filament, and with the belt purge tower the whole print greyed
out while dragging.

Drop the belt layers that print nothing (no object, support or brim
content) in GCode::collect_layers_to_print, and renumber the layers
consecutively over the moves that exist when converting a result for
libvgcode, so a file with empty layers from any source still previews
correctly.  The layer slider labels a belt layer with its print Z (the
slicer's layer Z, which increases along the belt) instead of libvgcode's
toolpath height, which on a tilted layer is wherever its last extrusion
ended; the slider assumes that list increases and showed "0 / max" on
alternate layers.  The processor reads that print Z from the ";Z:" tag
non-BBL printers write (it only knew "; Z_HEIGHT:"), on belt printers
only, so nothing changes elsewhere.  Regression test: two cubes 60 mm apart along the
belt produce no layer without an extrusion and the header's layer count
matches.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-07 03:50:51 -05:00
harrierpigeonandClaude Fable 5.1 cd155f07ae Tests: include <cmath> for std::sqrt in the belt overhang test
clang-tidy (misc-include-cleaner) flagged it on belt-printer.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-07 01:29:53 -05:00
harrierpigeonandClaude Fable 5.1 a2f5a8ce2b Belt printer: size the layer range from the on-bed box
The belt object height is estimated from a bounding box swept through
the tilt rotation.  raw_bounding_box() has the instance's Z offset
removed, which did not matter while the estimate was the box's rotated
Z extent (a Z shift moves every corner alike), but the frame now starts
at the lowest belt-floor point under the footprint, and a point's
rotated z and the floor under it move in opposite directions under a Z
shift: the offset box under-estimated the height by twice the object's
height above the bed, so the layers stopped at the part's diagonal and
every part came out as a wedge (GUI and CLI alike; the unit tests never
checked the top).  Use the box of the mesh in the frame it is sliced in
(trafo_centered(), Z as placed on the bed), and have the leading
overhang test check that the whole part is sliced.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-07 00:10:29 -05:00
harrierpigeonandClaude Fable 5.1 dda58b07cd Belt printer: supports reach the belt under a leading overhang
The slicing frame of a belt object started at its lowest vertex, but the
belt under the leading end of an overhang lies below that, by the
overhang's length times the tilt's shear.  Every support generator works
in layers at z >= 0, so none of them could reach it: normal supports
stopped at the object's own lowest layer, and the two tree generators
each carried a stack of hacks to extend themselves below it (a post-hoc
copy of the lowest base area in TreeSupport, "virtual belt raft layers"
in TreeSupport3D/TreeModelVolumes), sized from the pre-rotation bbox
and capped at global z = 0, which is only right for the trailing half
of the belt.

Start the frame at the lowest belt-floor point under the footprint
instead, less a 10 mm margin along the belt for the base of a support
column (BeltSliceStrategy::apply_preslice_transforms and
BeltTransformPipeline::compute_belt_height_and_floor agree on it).  The
layers between it and the first vertex come out empty, which belt
slicing already tolerates, and the generators need no extension at all:

- normal supports: the generator anchors its layer grid at the frame
  origin, so run it in the object frame and shift the global belt Z
  offset onto the result afterwards, as organic supports already did.
  With the offset on the object layers a top contact at negative z
  turned the intermediate-layer count negative and the generator
  allocated layers until the kernel killed it (any overhang in the
  leading half of the belt).  Drop the first-layer flange expansion on a
  belt: the first support layer is the leading tip of the support, not
  a flange, and inflating it put lines in the air ahead of the belt.
- classic tree: a node now keeps dropping until its whole circle is in
  the belt, so the branch tapers to a tip on the belt instead of
  stopping, a radius above it, when its centre crosses.
- organic: the belt is no longer a support blocker.  A blocker is a
  collision, and a branch descending onto one slides off it, down the
  tilted belt and ahead of the part; the belt is where branches end,
  which the per-layer m_belt_floor clipping already does.

The belt brim is generated after the parallel support step instead of
inside it: belt_brim_obstacles() reads every object's layers and support
layers, which another object's support step rebuilds (and, now, shifts)
at the same time.  This is the race behind the Windows arm64 segfault
in "Belt brim of each object precedes its perimeters on its own
filament".

Also: the belt tilt axis moves to Developer mode as its own row (a
shared line is shown by its first option's mode), first_layer_plane
band thickness, belt_support_floor_mode, belt_preslice_global and
gcode_back_transform are retired and presumed on, the gravity arrow is
a plain line along the up direction, and the "Show raw G-code (belt
only)" preview toggle is gone.

Regression test: "Belt supports reach the belt under a leading
overhang" slices a cube with a fin whose underside is parallel to the
layers, 20 mm ahead of the cube and up to 41 mm of slicing Z above the
belt, for normal, organic and classic tree supports, and checks that
the lowest support layer sits on the belt beneath its own lines.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-06 22:14:25 -05:00
harrierpigeonandClaude Fable 5.1 8039d4d2ac Belt printer: retire the redundant and unused options
Removed, with the keys added to handle_legacy()'s ignore list so saved
profiles and 3MFs keep loading:

- belt_slice_rotation_global and preslice_remap_global. Both were only
  consulted when belt_preslice_global ("Global mesh transforms") was off,
  which no profile does; belt_preslice_global is now the single global
  mode and is presumed on everywhere the old flags were ORed in
  (PrintObjectSlice, BeltBackTransform, BeltGCode, Print::process,
  PrintApply). The Belt tilt row is axis + angle only.
- preslice_remap_x/y/z. No profile used the pre-slice axis remap; the belt
  tilt axis plus the G-code axis remap cover the machines that exist, and
  its implementation only agreed with itself for a plain swap (matrix
  columns vs remap_bbox rows). BeltTransformPipeline::build_preslice_remap,
  remap_bbox and has_preslice_remap are gone, the forward transform is the
  rotation, and the G-code header no longer carries the remap.
- belt_support_z_offset_mode. Saved and invalidated steps, but no support
  generator read it.
- first_layer_plane and first_layer_plane_offset, with FirstLayerPlane.cpp.
  On every shipped configuration the band is measured from the belt
  surface (GCode::belt_height_above_floor) and the evaluator was only
  reached for an explicit XY/YZ/XZ choice or a non-zero offset, which
  nobody set. first_layer_plane_thickness stays as the band unit,
  relabelled "First layer band thickness".

UI: the Machine frame transforms group is five single-option rows (G-code
remap X / Y / Z, Decouple machine-frame tilt, Machine-frame tilt angle;
the angle row is shown only when decoupled) instead of two multi-column
lines, and the remap fields carry full labels.

Also carries the phong.fs struct fix from #16226 so the worktree build
links its shaders.

libslic3r_tests and fff_print_tests pass; clang-tidy diff check clean;
orca_profile_tool.py check clean.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-06 18:14:34 -05:00
harrierpigeonandClaude Fable 5.1 f97aa6a5af Qualify Slic3r::Polygon in the blocker-index test
tests/fff_print/test_print.cpp includes <Windows.h>, so an unqualified Polygon
in the new TreeModelVolumes test is ambiguous with GDI's Polygon() and fails
the Windows x64 and arm64 builds on belt-printer.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-06 00:12:59 -05:00
harrierpigeonandClaude Fable 5.1 61a0db4a87 Belt printer: address the review on #14394
Code review items (raistlin7447):

1. PrintObject::slice() zeroes m_belt_min_z, m_belt_global_z_offset and
   m_belt_global_xy_correction before slicing. They were only written in belt
   mode, so a project switched to a normal printer, or whose tilt axis was set
   to None, kept the old offsets and shifted the adaptive infill octree and the
   organic support layers by them.
2. TreeModelVolumes shifts the support blockers into the raft-offset index
   space; a test now pins the index the blocker lands on.
3. The final-alignment clamp in libnest2d is opt-in (NfpPConfig::clamp_to_bin)
   and arrange sets it for belt printers only. Printers with an off-centre
   best_object_pos keep their alignment; a flat-bed test pins that.
4. The preview's belt view follows the loaded G-code, not the selected printer:
   GCodeProcessor carries the file's belt keys (and, for a belt file, its bed)
   into export_config_for_render(), and GCodeViewer enables the belt view from
   the header tilt.
5. belt_shift_layer_grid() also shifts the cached belt floor and the global Z
   offset, so a support-only or brim-only change after the purge-prism snap
   matches a fresh slice.
6. update_print_fff_config() resets raft_layers and draft_shield on a belt
   printer instead of only greying out the fields Print::validate() rejects.
7. GCodeWriter takes a first-layer point test instead of the FirstLayerPlane;
   GCode installs one that measures from the belt surface, like its
   extrusions, so the first-layer travel speed and the second-layer
   temperature change no longer depend on the gcode_remap_* convention.
8. belt_brim_clip_leading_edge() is exported and called by both the generator
   and the test.
9. Both phong.vs shaders use slope.up_direction for the overhang highlight.

The pre-slice and G-code axis remaps are gated on belt_printer through
BeltTransformPipeline::axis_remap_enabled(), so belt keys left in a profile
cannot change a non-belt print.

Tests requested in the review: belt-only keys at non-default values leave
non-belt G-code unchanged; switching a sliced project from belt to non-belt
(and tilt axis None) matches a fresh slice; a support-only change on a belt
purge print matches a fresh slice; non-belt start G-code moves keep the
first-layer Z in the processor; the belt brim's segment count catches a band
emitted twice.

The belt-to-non-belt test exposed an unrelated gap: invalidate_step(posSlice)
re-invalidated posSupportMaterial but not posSimplifySupportPath, so after
any re-slice the regenerated support paths were exported unsimplified.
posSimplifySupportPath is now in that list.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-05 23:06:01 -05:00
Hanif Koh 325ecdda10 Merge Main into Belt Printer 2026-10-05 17:27:52 +08:00
HanifKoh 4895bc03b4 Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced (#16099)
* Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced

Generated with include-what-you-use and applied conservatively. Only OrcaSlicer's own headers, the ones under src/ and tests/, are removed or forward-declared; standard-library and third-party includes are left alone. An include is removed only when both the Release and the Debug configuration leave it unused, never from inside a conditional block, and never from a file with platform-specific blocks, which only gain includes. Files whose only use of a header sits behind a feature or debug macro (libvgcode's OpenGL ES and marker code, the ARACHNE/TESTS_EXPORT_SVGS debug output) keep their includes.

clonable_ptr.hpp gains #pragma once; it had no include guard and was only safe while Config.hpp was its sole includer.

* Remove Unused Project Includes From Files With Platform-Specific Code

A Linux include-what-you-use run cannot see the code inside _WIN32, __APPLE__ or __linux__ blocks, so its verdict is only taken where nothing the removed header declares, directly or through what it includes, is named inside those blocks. Removals also have to hold in both the Release and Debug configuration and never touch a line inside a conditional block.

* Restore the libslic3r Precompiled Header and Direct Includes Lost in the Platform Pass

The platform-file pass treated pchheader.hpp as an ordinary header and
emptied it, and left GUI_Preview.hpp and 14 other files relying on
headers they no longer reached directly.

* Restore MainFrame.hpp in ParamsDialog.cpp for the Windows-Only Reparent Call

* Include Headers That Files Reached Through Ones the Cleanup Removed

* Drop Includes Duplicated by the Cleanup or by Main's Own Additions

* Leave PreciseSeam.cpp as Main Has It After the Precise Seam Rework
2026-10-05 16:47:17 +08:00
harrierpigeon bbb94724ba Merge upstream/main into belt-printer
Brings belt-printer up to main 4b4a261787. Resolutions:

- G-code header (#15897, #15915): main moved the header, config and
  thumbnail block later in _do_export; write_belt_header() moves with it,
  still after the thumbnails and outside the BTT_TFT gate.
- _extrude: first-layer acceleration keeps the per-path first-layer plane
  test with main's cached nozzle index (#16028); main's set_speed out-param
  form (#16108) everywhere else.
- GCodeWriter (#16108): the arc-to-polyline fallback for machine mappings
  that cannot express G2/G3 now runs in the out-param extrude_arc_to_xy,
  which is the overload GCode calls, and appends to the caller's string.
- GCodeProcessorResult: the belt fields join main's forwarding assign.
- Clipper2 (#15969): belt arrange helpers take Slic3r::Point; the tree
  support join types lose their ClipperLib qualifier.
- CLI arrange (#15837): belt printers still reserve no wipe tower.
- Wipe tower options (#15841): the two new sparse-layer toggles are hidden
  for belt printers like the rest of the tower options.
- Keyboard shortcuts (#15706): main's registry replaces the old key switch;
  the belt view toggle is re-registered in the next commit.
- Print::process: the belt purge-plan undo runs before main's SliceStarted
  event.
- scripts/filament_id_snapshot.json: deleted on main (a77209af8f).
- Includes and appended tests: union of both sides.
2026-10-04 19:20:33 -05:00
HanifKoh 84657ff11e Add Missing Includes Across the Remaining Sources and Tests (#16071)
* Ignore Clipper, libpng, mcut and Boost.Polygon Internals in clang-tidy

Each only works through a wrapper or umbrella header: libslic3r/clipper.hpp or clipper_z.hpp configure Clipper before including it, png.h pulls in libpng's config headers, and Boost.Polygon's headers only compile through polygon.hpp or voronoi.hpp.

* Ignore minilzo's Config Headers in clang-tidy

lzoconf.h and lzodefs.h are internal to minilzo.h, which is what the code includes.

* Add Missing Includes Across the Remaining Sources and Tests

Covers src/slic3r/Utils, src/slic3r/plugin, src/slic3r/Config, src/libvgcode, src/dev-utils, src/OrcaSlicer.cpp and tests/, the directories left after src/slic3r/GUI and src/libslic3r. Generated with clang-tidy misc-include-cleaner. libvgcode's own headers are included by relative path as in the rest of that library, and Catch2 and pybind11 with angle brackets as elsewhere in the repo.

* Make the GUI and Test Headers Compile on Their Own

Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Headers that only compile on one platform, or that nothing built includes, are left alone.

* Keep Windows and nanosvg Setup Ahead of the Added Includes

OrcaSlicer.cpp and several tests set _WIN32_WINNT, WIN32_LEAN_AND_MEAN or NOMINMAX before including Windows.h, and the profile validator defines NANOSVG_IMPLEMENTATION before any libslic3r header. The added includes had landed above those blocks, which broke the Windows build.

* Add the GUI Includes the First Pass Missed

Covers headers that only became editable once they compiled on their own, and wx symbols whose suggested header changed as the clang-tidy ignore list grew after the src/slic3r/GUI pass.

* Keep the Added Test Includes Below the NOMINMAX Guard

test_marchingsquares.cpp and test_texture_displacement.cpp had includes inside #ifndef NOMINMAX, which the tests inherit as defined on Windows from libslic3r, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory, as in #16068.
2026-10-03 13:45:21 +08:00
harrierpigeon d35af1806a Belt cooling: keep the fan off in the band inside the layer cooling pass
The band was a second pass over the finished layer that fought the fan commands
the layer pass had already written (overhang, bridge and resume requests). The
generator now marks where each segment enters and leaves the band and the layer
pass treats the band as the strongest fan request, so there is one place that
decides the fan.
2026-10-02 12:46:44 -05:00
harrierpigeon 31494a9836 tests: give the belt fan band test a band the walls reach 2026-10-02 02:42:14 -05:00
harrierpigeon 461063856d tests: fix two belt test expectations
The clearance test needs the relative-E reset in its layer change G-code to
get past validate()'s other checks, and now asserts the height message. The
fan band test counts cycles rather than commands: the band is decided per
path start, so a cube cycles the fan far less often than a benchy.
2026-10-02 02:33:14 -05:00
harrierpigeon 1b392955de tests: organic tree supports reaching the belt slice without a negative flow
Covers the case from Hanif Koh's review of #14394 (belt raft layers below
the object with no lower bound), which the negative-Z bottom layer fix in
layer_initialize() addresses.
2026-10-02 01:13:29 -05:00
harrierpigeon 360a68e078 Belt: warn when the purge tower is enabled but the project has no tower object
The purge tower is a model object the GUI creates and sizes, and libslic3r
only purges into one that exists. A multi-filament belt project sliced from
the CLI without it changed filament with nowhere to purge, silently.

Raised in Hanif Koh's review of #14394.
2026-10-02 01:11:59 -05:00
harrierpigeon 556569c0e3 Belt: drive the first-layer fan band from the generator, not from parsed moves
The cooling buffer's band pass rebuilt positions from the layer's G-code
and tested them against the first-layer plane. The G-code is in machine
coordinates and the plane is in slicing coordinates, so on the shipped
profiles the nearest move was over 100 mm from a 0.2 mm band and the pass
never changed the fan. GCode::_extrude() already knows each path's height
above the belt, so it now tags the band changes and the buffer applies and
strips the tags.

The pass also took the S of every M106 as the part fan, whatever its P
index, and stored that 0..255 value where a percentage was expected (an
auxiliary fan line came back as M106 S651); it now uses FanMover's parser,
which ignores other fans, and converts to percent. It no longer overwrites
the layer's intended speed, only the fan's actual state.

Raised in Hanif Koh's review of #14394.
2026-10-02 01:10:57 -05:00
harrierpigeon 2aa4122aae Belt: check object height against the gantry clearance again
validate() skipped the build-volume height check whenever the machine-frame
transform was active, which is every shipped belt profile, so a 400 mm
object passed on a 300 mm printable_height. The transform only changes how
the height is written to G-code; the clearance check from f682ab5cd3
applies regardless.

Raised in Hanif Koh's review of #14394.
2026-10-02 01:07:42 -05:00
Kris Austin d1d14329d9 fix: exporting a sliced print again gives different G-code (#16025)
extrude_infill() and extrude_support() reversed the layer's extrusion
entities in place while chaining them, so each export started from the
previous one's reversed toolpaths, and each copy of an object from the
copy before it. The export-time region lists now hold const pointers,
and chaining reverses a clone instead.
2026-10-01 08:08:03 -03:00
harrierpigeon 4f110bc261 Belt scarf test: slice without a z-hop
The default 0.4 mm z-hop is a 0.57 mm move along the belt axis and its
return tripped the back-step check. Shipped belt profiles print without a
z-hop, so the test does too.
2026-09-30 17:42:16 -05:00
harrierpigeon 6cf747808c Belt: never start a scarf joint seam below the layer
A scarf joint begins one layer height below the current layer and ramps
up along the wall. On a tilted belt that start is a step backwards along
the belt axis, into the previous layer's wall at the seam: 0.283 mm per
0.2 mm layer at 45 degrees. With an aligned seam the nozzle rams the same
spot on every layer. A BabyBelt Pro benchy with seam_slope_type=external
showed 601 such back-steps from layer 107 on, and in the field the belt
"jumped backwards" and the head knocked the part loose.

Belt printers now skip the scarf in GCode::extrude_loop, and the process
tab greys the scarf controls out for them, as it already does for arc
fitting. The regression test slices a cube on a belt with the scarf
enabled and checks the belt axis never steps back by a layer pitch.
2026-09-30 15:44:18 -05:00
789f848694 Write the estimated printing time comment after the config block, not before (#15897)
Co-authored-by: Fernando Marino <f.marino@rheagroup.com>
Co-authored-by: yw4z <ywsyildiz@gmail.com>
2026-09-29 19:18:15 -03:00
Harry Loud 1841de5f88 Merge remote-tracking branch 'upstream/main' into feature/exclusion-volume-tests
# Conflicts:
#	src/libslic3r/PrintBase.hpp
2026-09-29 17:41:28 +01:00
peachismomo 58842bab05 test: test for SliceStarted ensuring stable model ID is presetn when model name is absent 2026-09-27 17:29:01 +08:00
peachismomo 04204ec0d3 test: cover slicing lifecycle event context 2026-09-27 17:25:56 +08:00
HanifKoh af52da061f Report Per-Object Slicing Errors in the CLI (#15834)
G-code generation collects errors raised per object, such as an empty
first layer, into one SlicingErrors exception whose own message is just
"Errors". The CLI's generic handler printed that word and recorded the
generic slicing error text, so a headless caller had nothing to act on.

Let Print render the per-object messages with each object's name, and have
the CLI catch SlicingErrors ahead of the generic handler, print that text
and record it as the result's error string. The exit code is unchanged. A
unit test lifts a cube off the bed and checks the message names the object.
2026-09-25 08:37:28 +08:00
Harry Loud 82e670cc3b Merge remote-tracking branch 'upstream/main' into feature/exclusion-volume-tests
# Conflicts:
#	src/slic3r/GUI/GLCanvas3D.cpp
#	tests/libslic3r/test_3mf.cpp
2026-09-21 10:42:34 +01:00
Harry Loud f832cae2eb Separate legacy bed areas from collision volumes 2026-09-21 10:28:26 +01:00
Kiss Lorand caa15491c3 Fix duplicate timelapse G-code on i3 printers (#15734) 2026-09-19 13:19:54 -03:00
Harry Loud c00909e687 Add comprehensive exclusion volume tests 2026-09-14 12:27:57 +01:00