Skip to content

Conversation

@pedrolamas
Copy link
Member

@pedrolamas pedrolamas commented Nov 28, 2025

Adds multi-tool support detection and presentation to the Gcode Previewer.

When parsing a gcode file, we now follow this process:

  • For any M600 (Filament change), add 0 to the used tools, then take the current index and move to the next one, up to 10.
  • For any Tn, take n and add it to the used tools.

If neither of these commands is found, no tools will be shown on the frontend, and the behavior will remain the same as before this PR.

image

@pedrolamas pedrolamas added this to the 1.35.2 milestone Nov 28, 2025
@pedrolamas pedrolamas requested a review from Copilot November 28, 2025 21:33
@pedrolamas pedrolamas added the FR - Enhancement New feature or request label Nov 28, 2025
Copilot finished reviewing on behalf of pedrolamas November 28, 2025 21:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds multi-tool support to the GCode Preview feature, enabling detection and visualization of tool changes for multi-extruder/multi-tool 3D printers. The changes detect tool changes via T commands and M600 (filament change), track tool usage throughout the print, and render extrusions with tool-specific colors derived from file metadata or default color palettes.

Key Changes:

  • Added tool tracking in GCode parser to detect T commands and M600 filament changes
  • Modified Move data structures to include tool information with abbreviated property names (t, p, d)
  • Implemented per-tool extrusion path rendering with color-coded visualization in the preview

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/workers/parseGcode.worker.ts Added tools array to worker message types and result handling
src/workers/parseGcode.ts Implemented tool tracking (T commands, M600), updated regex for T commands, renamed properties to abbreviations
src/util/gcode-preview.ts Updated references from direction to d property
src/store/gcodePreview/types.ts Added tools array to state, renamed Move properties to abbreviations, changed LayerPaths.extrusions to per-tool Record
src/store/gcodePreview/state.ts Added tools array initialization in default state
src/store/gcodePreview/mutations.ts Added setTools mutation for tools array updates
src/store/gcodePreview/getters.ts Added getTools getter with color assignment logic, getColorsFromFileMetadata for file-based colors, updated getPaths for per-tool extrusion tracking
src/store/gcodePreview/actions.ts Added tools commit in loadGcode action and reset operations
src/components/widgets/gcode-preview/GcodePreviewTool.vue New component to display tool indicators with color and active state
src/components/widgets/gcode-preview/GcodePreview.vue Updated template to render per-tool extrusions with colors, added tool indicator display, wrapped buttons in container div
src/components/widgets/gcode-preview/GcodePreviewCard.vue Updated file type to support AppFileWithMeta for color metadata

Comment on lines +52 to +55
border-color: map-deep-get($material-dark, 'text', 'primary');
& .extruder-color {
border-color: map-deep-get($material-dark, 'text', 'primary');
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The active state styling uses hardcoded $material-dark theme variables instead of the dynamic $material variable from the @include theme block. This means the border color won't adapt to the current theme (light/dark). Use map-deep-get($material, 'text', 'primary') instead to match the theme-aware styling on line 40.

Suggested change
border-color: map-deep-get($material-dark, 'text', 'primary');
& .extruder-color {
border-color: map-deep-get($material-dark, 'text', 'primary');
border-color: map-deep-get($material, 'text', 'primary');
& .extruder-color {
border-color: map-deep-get($material, 'text', 'primary');

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

That's for inverted color, so keep as is.

border-color: map-deep-get($material-dark, 'text', 'primary');
& .extruder-color {
border-color: map-deep-get($material-dark, 'text', 'primary');
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The .extruder-color border styling within the active state also uses hardcoded $material-dark instead of the dynamic $material variable. This creates inconsistent theming. Use map-deep-get($material, 'text', 'primary') to match the base styling on line 40.

Suggested change
border-color: map-deep-get($material-dark, 'text', 'primary');
border-color: map-deep-get($material, 'text', 'primary');

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

That's for inverted color, so keep as is.

fwretraction.z = args.z ?? fwretraction.z
break
case 'M600':
toolhead.tool = (toolhead.tool + 1) % 10
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

M600 (filament change) increments tool with modulo 10, limiting support to 10 tools maximum. This arbitrary limit may not match actual printer configurations. Consider removing the modulo operation or making it configurable, as tool numbers can be higher in some multi-tool setups.

Suggested change
toolhead.tool = (toolhead.tool + 1) % 10
toolhead.tool = toolhead.tool + 1

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

We are setting an arbitrary maximum of 10 tools, if someone show up needing more, we will then assess the next step.

k?: number;
r?: number;
direction: Rotation;
d: Rotation;
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

Property name d is cryptic and unclear. The original direction was self-documenting. Consider reverting to direction or using a clearer name. Single-letter abbreviations reduce code readability significantly.

Suggested change
d: Rotation;
direction: Rotation;

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

Keep as is.

export type Move = LinearMove | ArcMove

export type Rotation = 'clockwise' | 'counter-clockwise'

Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The new Tool type lacks documentation explaining its purpose and usage. Add a JSDoc comment describing that this represents a tool identifier in the format "T0", "T1", etc., used for multi-tool/multi-extruder support.

Suggested change
/**
* Represents a tool identifier for multi-tool/multi-extruder support.
* Format: "T0", "T1", etc.
*/

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

Skip.

@pedrolamas pedrolamas requested a review from Copilot November 29, 2025 01:05
Copilot finished reviewing on behalf of pedrolamas November 29, 2025 01:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

throw new TypeError('Move is not a valid arc')
}

// Assumes the path is pr
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

Incomplete comment: "Assumes the path is pr" appears to be truncated. Please complete or remove this comment.

Suggested change
// Assumes the path is pr

Copilot uses AI. Check for mistakes.
Signed-off-by: Pedro Lamas <[email protected]>
Signed-off-by: Pedro Lamas <[email protected]>
@pedrolamas pedrolamas requested a review from Copilot November 29, 2025 01:26
Copilot finished reviewing on behalf of pedrolamas November 29, 2025 01:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

const tool: Tool = `T${toolIndex}`
const color = (
colorsFromFileMetadata[index] ||
defaultColors[index - colorsFromFileMetadata.length] ||
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

Color indexing logic is incorrect. When colorsFromFileMetadata has colors, index - colorsFromFileMetadata.length will be negative for early tools, causing wrong color selection. Should use: defaultColors[index] || defaultColors[0] or check index >= colorsFromFileMetadata.length before subtracting.

Suggested change
defaultColors[index - colorsFromFileMetadata.length] ||
defaultColors[index] ||

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is correct, keep as is.

@pedrolamas pedrolamas requested a review from Copilot November 29, 2025 14:58
Copilot finished reviewing on behalf of pedrolamas November 29, 2025 15:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Comment on lines +236 to +240
case 'M600':
tools.add(0)
tool = (tool + 1) % 10
tools.add(tool)
break
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

M600 (filament change) increments tool with modulo 10, which assumes max 10 tools and cycles back to 0. This creates incorrect tool tracking if there are actual T commands. M600 should either: (1) not modify tool state if using explicit T commands, or (2) use a dedicated color-change counter separate from tool index.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

I see no reason why M600 would be used together with Tx commands... for now, let's keep as is.

Comment on lines +51 to +57
&.active {
border-color: map-deep-get($material-dark, 'text', 'primary');
& .extruder-color {
border-color: map-deep-get($material-dark, 'text', 'primary');
}
}
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

The active state always uses $material-dark theme colors regardless of current theme. Should use $material variable (line 38-41 pattern) to respect light/dark theme.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

That's for inverted color, so keep as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FR - Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant