-
-
Notifications
You must be signed in to change notification settings - Fork 531
feat(GcodePreview): adds multi-tool support #1753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
feat(GcodePreview): adds multi-tool support #1753
Conversation
Signed-off-by: Pedro Lamas <[email protected]>
There was a problem hiding this 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 |
| border-color: map-deep-get($material-dark, 'text', 'primary'); | ||
| & .extruder-color { | ||
| border-color: map-deep-get($material-dark, 'text', 'primary'); |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
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.
| 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'); |
There was a problem hiding this comment.
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'); |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
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.
| border-color: map-deep-get($material-dark, 'text', 'primary'); | |
| border-color: map-deep-get($material, 'text', 'primary'); |
There was a problem hiding this comment.
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.
src/workers/parseGcode.ts
Outdated
| fwretraction.z = args.z ?? fwretraction.z | ||
| break | ||
| case 'M600': | ||
| toolhead.tool = (toolhead.tool + 1) % 10 |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
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.
| toolhead.tool = (toolhead.tool + 1) % 10 | |
| toolhead.tool = toolhead.tool + 1 |
There was a problem hiding this comment.
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; |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
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.
| d: Rotation; | |
| direction: Rotation; |
There was a problem hiding this comment.
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' | ||
|
|
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
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.
| /** | |
| * Represents a tool identifier for multi-tool/multi-extruder support. | |
| * Format: "T0", "T1", etc. | |
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip.
Signed-off-by: Pedro Lamas <[email protected]>
There was a problem hiding this 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 |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
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.
| // Assumes the path is pr |
Signed-off-by: Pedro Lamas <[email protected]>
Signed-off-by: Pedro Lamas <[email protected]>
There was a problem hiding this 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] || |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
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.
| defaultColors[index - colorsFromFileMetadata.length] || | |
| defaultColors[index] || |
There was a problem hiding this comment.
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.
Signed-off-by: Pedro Lamas <[email protected]>
There was a problem hiding this 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.
| case 'M600': | ||
| tools.add(0) | ||
| tool = (tool + 1) % 10 | ||
| tools.add(tool) | ||
| break |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| &.active { | ||
| border-color: map-deep-get($material-dark, 'text', 'primary'); | ||
| & .extruder-color { | ||
| border-color: map-deep-get($material-dark, 'text', 'primary'); | ||
| } | ||
| } |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Signed-off-by: Pedro Lamas <[email protected]>
Adds multi-tool support detection and presentation to the Gcode Previewer.
When parsing a gcode file, we now follow this process:
M600(Filament change), add0to the used tools, then take the current index and move to the next one, up to 10.Tn, takenand 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.