Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ choose from the slicers installed on your Mac.

## See your build plate before opening the file

<img src="docs/images/router-file-icons.png" width="100%" alt="Router logo variants with colours and letter markers for each slicer">
<img src="docs/images/router-file-icons.png" width="100%" alt="Whole Router logo and outline tinted in each destination slicer’s colour">

**Finder** file icons use the Router logo with the chosen slicer's colour and marker.
**Finder** file icons tint the entire Router logo in the destination slicer's colour.
The outline uses the same colour. Files with the same destination use the same colour for `.3mf` and `.gcode`.
macOS also uses this custom icon in Finder's icon view. Model thumbnails remain available to
Quick Look clients. Select a file and press **Space** for **Quick Look**: orbit and zoom a single-plate
project in 3D, or see all plates together in a multi-plate project. You do not need to launch a slicer.
Expand Down Expand Up @@ -276,8 +277,9 @@ contents stay byte-for-byte the same.
A saved manual choice for the file or an explicit printer mapping takes priority.
Hold **⌥ (Option)** when opening to choose another slicer.

**Do all file icons change immediately after installation?** No. Small icons use the Router logo with
the slicer's colour and marker. They update when a file is opened or indexed, and when Finder requests
**Do all file icons change immediately after installation?** No. The entire Router logo and its outline
use the destination slicer's colour, the same for `.3mf` and `.gcode`. Icons update when a file is
opened or indexed, and when Finder requests
a thumbnail. Files never opened or indexed can keep their previous icon. Finder's icon view also
shows the custom logo; press **Space** to inspect the model in Quick Look. If the file is not writable or its filesystem does not support extended
attributes, opening still works; Finder uses the extension icon or thumbnail fallback.
Expand Down
10 changes: 6 additions & 4 deletions README.pt-BR.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ ele pergunta qual slicer instalado usar.

## Veja a mesa antes mesmo de abrir o arquivo

<img src="docs/images/router-file-icons.png" width="100%" alt="Variantes da logo do Router com cores e marcadores de cada slicer">
<img src="docs/images/router-file-icons.png" width="100%" alt="Logo inteira do Router e borda na cor de cada slicer de destino">

Os ícones de arquivo no **Finder** usam a logo do Router, com a cor e o marcador do slicer escolhido.
Os ícones de arquivo no **Finder** usam a logo inteira do Router na cor do slicer de destino.
A borda usa a mesma cor. Arquivos `.3mf` e `.gcode` com o mesmo destino usam a mesma cor.
O macOS também usa esse ícone personalizado na visualização por ícones do Finder. As thumbnails
do modelo continuam disponíveis para clientes do Quick Look. Selecione um arquivo e pressione **Espaço** para abrir o **Quick Look**: gire e amplie um projeto
de uma mesa em 3D ou veja todas as mesas juntas em um projeto com várias mesas. Não é preciso abrir o slicer.
Expand Down Expand Up @@ -273,8 +274,9 @@ O conteúdo do 3MF ou G-code continua idêntico, byte a byte.
Uma escolha manual salva por arquivo ou um mapeamento explícito da impressora tem prioridade.
Segure **⌥ (Option)** ao abrir para escolher outro slicer.

**Todos os ícones mudam logo após instalar?** Não. Os ícones pequenos usam a logo do Router com a cor
e o marcador do slicer. Eles são atualizados ao abrir ou indexar o arquivo e quando o Finder solicita
**Todos os ícones mudam logo após instalar?** Não. A logo inteira do Router e sua borda usam a cor
do slicer de destino, igual para `.3mf` e `.gcode`. Os ícones são atualizados ao abrir ou indexar
o arquivo e quando o Finder solicita
uma thumbnail. Arquivos nunca abertos ou indexados podem manter o ícone anterior. A visualização por
ícones do Finder também mostra a logo personalizada; pressione **Espaço** para conferir o modelo no Quick Look. Se o arquivo não permitir escrita ou o sistema de arquivos
não aceitar atributos estendidos, a abertura continua funcionando; o Finder usa o ícone da extensão
Expand Down
46 changes: 16 additions & 30 deletions Sources/Core/RouterFileIcon.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AppKit
import CryptoKit

/// Our logo stays recognizable; the outline and letter identify the selected slicer.
/// The Router shape stays recognizable; its colour identifies the destination slicer.
public enum SlicerIconStyle: String, CaseIterable {
case router, bambu, orca, snapmaker, prusa, cura, creality, elegoo

Expand All @@ -18,30 +18,17 @@ public enum SlicerIconStyle: String, CaseIterable {
return .router
}

public var marker: String {
switch self {
case .router: return "R"
case .bambu: return "B"
case .orca: return "O"
case .snapmaker: return "S"
case .prusa: return "P"
case .cura: return "C"
case .creality: return "CR"
case .elegoo: return "E"
}
}

public var colour: NSColor {
let rgb: UInt32
switch self {
case .router: rgb = 0x87D9B6
case .bambu: rgb = 0x00AE42
case .orca: rgb = 0x368BC7
case .snapmaker: rgb = 0x25BBAA
case .snapmaker: rgb = 0xF1F1F1
case .prusa: rgb = 0xF47929
case .cura: rgb = 0x2463D8
case .creality: rgb = 0x00A67A
case .elegoo: rgb = 0xB64479
case .elegoo: rgb = 0x266FD5
}
return NSColor(srgbRed: CGFloat((rgb >> 16) & 255) / 255,
green: CGFloat((rgb >> 8) & 255) / 255, blue: CGFloat(rgb & 255) / 255, alpha: 1)
Expand Down Expand Up @@ -114,7 +101,7 @@ public enum RouterFileIcon {
xRadius: s * 0.20, yRadius: s * 0.20)
NSColor(srgbRed: 0.09, green: 0.11, blue: 0.14, alpha: 1).setFill(); outline.fill()
if let logo = logoURL.flatMap({ NSImage(contentsOf: $0) }) {
logo.draw(in: NSRect(x: s * 0.105, y: s * 0.105, width: s * 0.79, height: s * 0.79))
logo.draw(in: NSRect(origin: .zero, size: size))
} else {
// Keep an identifiable stacked Router mark if the resource cannot be loaded.
for y in [0.30, 0.44, 0.58] {
Expand All @@ -123,18 +110,17 @@ public enum RouterFileIcon {
xRadius: s * 0.025, yRadius: s * 0.025).fill()
}
}
outline.lineWidth = max(1, s * 0.055)
if style != .router {
// Colour blending keeps the original lighting and relief while replacing
// both the green and blue parts with the destination slicer's hue.
context.cgContext.saveGState()
context.cgContext.setBlendMode(.color)
style.colour.setFill()
outline.fill()
context.cgContext.restoreGState()
}
outline.lineWidth = max(1, s * 0.035)
style.colour.setStroke(); outline.stroke()
let badge = NSRect(x: s * 0.59, y: s * 0.025, width: s * 0.39, height: s * 0.39)
let circle = NSBezierPath(ovalIn: badge)
style.colour.setFill(); circle.fill()
circle.lineWidth = max(1, s * 0.025)
NSColor(srgbRed: 0.06, green: 0.08, blue: 0.10, alpha: 1).setStroke(); circle.stroke()
let font = NSFont.systemFont(ofSize: s * (style.marker.count == 1 ? 0.255 : 0.17), weight: .heavy)
let attributes: [NSAttributedString.Key: Any] = [.font: font, .foregroundColor: NSColor.white]
let text = style.marker as NSString
let textSize = text.size(withAttributes: attributes)
text.draw(at: NSPoint(x: badge.midX - textSize.width / 2, y: badge.midY - textSize.height / 2), withAttributes: attributes)
image.addRepresentation(bitmap)
return image
}
Expand Down Expand Up @@ -164,7 +150,7 @@ public enum RouterFileIcon {
private static func ownsIcon(_ url: URL, marker: String?) -> Bool {
guard let marker else { return false }
let fields = marker.split(separator: ":")
return fields.count == 3 && fields[0] == "v2" && resourceDigest(url) == String(fields[2])
return fields.count == 3 && ["v2", "v3"].contains(fields[0]) && resourceDigest(url) == String(fields[2])
}

private static func digest(_ handle: FileHandle) throws -> Data {
Expand Down Expand Up @@ -203,7 +189,7 @@ public enum RouterFileIcon {
public static func apply(to url: URL, app: SlicerApp?) -> Bool {
guard FileAssociations.extensions.contains(url.pathExtension.lowercased()),
FileManager.default.isWritableFile(atPath: url.path) else { return false }
let stamp = "v2:\(SlicerIconStyle.style(for: app).rawValue)"
let stamp = "v3:\(SlicerIconStyle.style(for: app).rawValue)"
lock.lock(); defer { lock.unlock() }
let previous = marker(for: url)
let owned = ownsIcon(url, marker: previous)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Thumbnail/ThumbnailProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AppKit
import QuickLookThumbnailing

/// Thumbnail do Finder para .3mf e .gcode.
/// - Small requests: Router logo with the preferred slicer's colour and marker.
/// - Small requests: the whole Router logo uses the destination slicer's colour.
/// - Larger requests: current model/toolpath preview, preserving geometry and painting.
final class ThumbnailProvider: QLThumbnailProvider {
override func provideThumbnail(for request: QLFileThumbnailRequest, _ handler: @escaping (QLThumbnailReply?, Error?) -> Void) {
Expand Down
81 changes: 80 additions & 1 deletion Tests/DocumentIconTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AppKit
import CryptoKit
import UniformTypeIdentifiers
import XCTest

Expand All @@ -8,8 +9,86 @@ final class DocumentIconTests: XCTestCase {
XCTAssertEqual(SlicerIconStyle.style(for: .orcaSlicer), .orca)
XCTAssertEqual(SlicerIconStyle.style(for: .snapmakerOrca), .snapmaker)
XCTAssertEqual(SlicerIconStyle.style(for: SlicerApp(bundleID: "com.prusa3d.slic3r", path: "/Synthetic/PrusaSlicer.app", name: "PrusaSlicer")), .prusa)
XCTAssertEqual(SlicerIconStyle.style(for: .cura), .cura)
XCTAssertEqual(SlicerIconStyle.style(for: .crealityPrint), .creality)
XCTAssertEqual(SlicerIconStyle.style(for: SlicerApp(bundleID: "com.elegoo.slicer", path: "/Synthetic/ElegooSlicer.app", name: "ElegooSlicer")), .elegoo)
XCTAssertEqual(SlicerIconStyle.style(for: SlicerApp(bundleID: "test.custom", path: "/Synthetic/Custom.app", name: "Custom")), .router)
XCTAssertEqual(Set(SlicerIconStyle.allCases.map(\.marker)).count, SlicerIconStyle.allCases.count)
}

func testTheLogoInteriorUsesTheDestinationColourAtFinderSizes() throws {
for style in SlicerIconStyle.allCases where style != .router {
let target = style.colour.usingColorSpace(.deviceRGB)!
let hue = target.hueComponent
for pixels in [16, 32, 64] {
let bitmap = try XCTUnwrap(NSBitmapImageRep(data: RouterFileIcon.png(style: style, pixels: pixels)))
var coloured = 0
var largestHueDistance: CGFloat = 0
for y in (pixels / 4)..<(pixels * 3 / 4) {
for x in (pixels / 4)..<(pixels * 3 / 4) {
guard let colour = bitmap.colorAt(x: x, y: y)?.usingColorSpace(.deviceRGB),
colour.alphaComponent > 0.9,
colour.brightnessComponent > 0.25 else { continue }
if target.saturationComponent < 0.05 {
XCTAssertLessThan(colour.saturationComponent, 0.05, "The monochrome destination must remove the original green and blue")
coloured += 1
continue
}
guard colour.saturationComponent > 0.2 else { continue }
let distance = abs(colour.hueComponent - hue)
largestHueDistance = max(largestHueDistance, min(distance, 1 - distance))
coloured += 1
}
}
XCTAssertLessThan(largestHueDistance, 0.08,
"\(style) at \(pixels) px must tint the logo interior, not just its border")
XCTAssertGreaterThan(coloured, pixels / 2, "The centre must show the destination colour")
}
}
}

func testMappedProjectsAndGCodeUseTheSameDestinationStyle() throws {
try withDirectory { directory in
let project = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent()
.appendingPathComponent("samples/snapmaker-u1-painted-faces.3mf")
let gcode = directory.appendingPathComponent("export.gcode")
try Data("; generated by OrcaSlicer 2.4.0\n; printer_model = Snapmaker U1\n".utf8).write(to: gcode)
let model = try RoutableDocument.read(url: project)
let export = try RoutableDocument.read(url: gcode)
let elegoo = SlicerApp(bundleID: "com.elegoo.slicer", path: "/Synthetic/ElegooSlicer.app", name: "ElegooSlicer")
for app in SlicerApp.known + [elegoo] {
var mappings = Mappings()
mappings.byModel[try XCTUnwrap(model.info.printerModel)] = app
let modelApp = model.expectedApp(record: nil, mappings: mappings)
let exportApp = export.expectedApp(record: nil, mappings: mappings)
XCTAssertEqual(modelApp, app)
XCTAssertEqual(exportApp, app)
XCTAssertEqual(SlicerIconStyle.style(for: modelApp), SlicerIconStyle.style(for: exportApp))
}
}
}

func testOwnedVersionTwoIconsUpgradeWithoutChangingTheDocument() throws {
try withDirectory { directory in
let file = directory.appendingPathComponent("legacy.gcode")
let contents = Data("; generated by BambuStudio 2.4\n".utf8)
try contents.write(to: file)
let oldIcon = NSImage(size: NSSize(width: 32, height: 32))
oldIcon.lockFocus(); NSColor.magenta.setFill(); NSRect(x: 0, y: 0, width: 32, height: 32).fill(); oldIcon.unlockFocus()
XCTAssertTrue(NSWorkspace.shared.setIcon(oldIcon, forFile: file.path, options: []))
let oldFork = try XCTUnwrap(fork(file))
let hash = SHA256.hash(data: oldFork).map { String(format: "%02x", $0) }.joined()
let marker = Data("v2:bambu:\(hash)".utf8)
marker.withUnsafeBytes { _ = setxattr(file.path, "com.moraesdev.slicer-router.icon", $0.baseAddress, marker.count, 0, 0) }
let modified = try file.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate
XCTAssertTrue(RouterFileIcon.apply(to: file, app: .bambuStudio))
XCTAssertNotEqual(fork(file), oldFork, "An owned icon from 1.5.0 must receive the new rendering")
var value = [UInt8](repeating: 0, count: 256)
let count = getxattr(file.path, "com.moraesdev.slicer-router.icon", &value, value.count, 0, 0)
XCTAssertGreaterThan(count, 0)
XCTAssertTrue(String(decoding: value.prefix(max(0, count)), as: UTF8.self).hasPrefix("v3:bambu:"))
XCTAssertEqual(try Data(contentsOf: file), contents)
XCTAssertEqual(try file.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate, modified)
}
}

func testSmallIconsHaveDistinctPixelsAndLargerViewsKeepTheModel() throws {
Expand Down
4 changes: 3 additions & 1 deletion docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ Opening a selected file and rendering its preview do not require Accessibility o

## Finder file icons

Small icons retain the Router logo. The outline colour and marker indicate the selected slicer: Bambu Studio (B), OrcaSlicer (O), Snapmaker Orca (S), PrusaSlicer (P), Cura (C), Creality Print (CR) or Elegoo (E). Unknown slicers use the neutral Router (R). Large thumbnails and Quick Look still show the model or toolpath.
File icons tint the entire Router logo and its outline in the destination slicer's colour. Files with the same destination use the same colour for `.3mf` and `.gcode`. Destinations include Bambu Studio, OrcaSlicer, Snapmaker Orca, PrusaSlicer, Cura, Creality Print and Elegoo. Unknown slicers use the neutral Router logo.

Finder's icon view also uses this custom logo. Model thumbnails remain available to Quick Look clients. Press **Space** to inspect the model or toolpath in Quick Look.

For G-code, a saved manual choice wins, followed by an explicit printer mapping and the declared generator. A plain brand default does not override a recognized generator. Hold Option while opening to choose again.

Expand Down
4 changes: 3 additions & 1 deletion docs/INSTALL.pt-BR.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ Abrir um arquivo selecionado e renderizar seu preview não exige Acessibilidade

## Ícones dos arquivos no Finder

Os ícones pequenos mantêm a logo do Router. A cor da borda e o marcador indicam o slicer escolhido: Bambu Studio (B), OrcaSlicer (O), Snapmaker Orca (S), PrusaSlicer (P), Cura (C), Creality Print (CR) ou Elegoo (E). Slicers desconhecidos usam o Router neutro (R). As miniaturas grandes e o Quick Look continuam mostrando a peça ou o toolpath.
Os ícones de arquivo usam a logo inteira do Router e a borda na cor do slicer de destino. Arquivos `.3mf` e `.gcode` com o mesmo destino usam a mesma cor. Os destinos incluem Bambu Studio, OrcaSlicer, Snapmaker Orca, PrusaSlicer, Cura, Creality Print e Elegoo. Slicers desconhecidos usam a logo neutra do Router.

A visualização por ícones do Finder também usa essa logo personalizada. As thumbnails do modelo continuam disponíveis para clientes do Quick Look. Pressione **Espaço** para conferir a peça ou o toolpath no Quick Look.

No G-code, a escolha manual salva tem prioridade. Depois vêm o mapeamento explícito da impressora e o gerador declarado. O padrão de uma marca não substitui um gerador reconhecido. Segure Option ao abrir para escolher novamente.

Expand Down
Binary file modified docs/images/router-file-icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions docs/images/router-file-icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ settings:
CODE_SIGN_STYLE: Manual
DEVELOPMENT_TEAM: ""
ENABLE_HARDENED_RUNTIME: NO
MARKETING_VERSION: "1.5.0"
CURRENT_PROJECT_VERSION: "15"
MARKETING_VERSION: "1.5.1"
CURRENT_PROJECT_VERSION: "16"
targets:
SlicerRouter:
type: application
Expand Down
2 changes: 1 addition & 1 deletion scripts/make_file_icons_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def main():
centre = 62.5 + index * 125
items.append(f'<image x="{centre - 44}" y="24" width="88" height="88" href="data:image/png;base64,{encoded}"/>')
items.append(f'<text x="{centre}" y="142" text-anchor="middle" fill="#E3ECE7" font-family="-apple-system,Helvetica,Arial,sans-serif" font-size="16">{label}</text>')
svg = '<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="170" viewBox="0 0 1000 170" role="img" aria-label="Router file icons with slicer colours and letter markers">\n'
svg = '<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="170" viewBox="0 0 1000 170" role="img" aria-label="Whole Router logos and outlines tinted by destination slicer">\n'
svg += '<rect width="1000" height="170" rx="18" fill="#111820"/>\n'
svg += "\n".join(items) + "\n</svg>\n"
destination = ROOT / "docs/images/router-file-icons.svg"
Expand Down
Loading