diff --git a/README.md b/README.md index 7a2af02..d59032c 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,10 @@ choose from the slicers installed on your Mac. ## See your build plate before opening the file -Router logo variants with colours and letter markers for each slicer +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. @@ -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. diff --git a/README.pt-BR.md b/README.pt-BR.md index 1c68cf8..1837046 100644 --- a/README.pt-BR.md +++ b/README.pt-BR.md @@ -44,9 +44,10 @@ ele pergunta qual slicer instalado usar. ## Veja a mesa antes mesmo de abrir o arquivo -Variantes da logo do Router com cores e marcadores de cada slicer +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. @@ -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 diff --git a/Sources/Core/RouterFileIcon.swift b/Sources/Core/RouterFileIcon.swift index 275e4d1..896a2ba 100644 --- a/Sources/Core/RouterFileIcon.swift +++ b/Sources/Core/RouterFileIcon.swift @@ -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 @@ -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) @@ -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] { @@ -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 } @@ -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 { @@ -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) diff --git a/Sources/Thumbnail/ThumbnailProvider.swift b/Sources/Thumbnail/ThumbnailProvider.swift index c475fe4..2af590c 100644 --- a/Sources/Thumbnail/ThumbnailProvider.swift +++ b/Sources/Thumbnail/ThumbnailProvider.swift @@ -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) { diff --git a/Tests/DocumentIconTests.swift b/Tests/DocumentIconTests.swift index 8c887e3..5558f5c 100644 --- a/Tests/DocumentIconTests.swift +++ b/Tests/DocumentIconTests.swift @@ -1,4 +1,5 @@ import AppKit +import CryptoKit import UniformTypeIdentifiers import XCTest @@ -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 { diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 642153e..a16632f 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -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. diff --git a/docs/INSTALL.pt-BR.md b/docs/INSTALL.pt-BR.md index 39512b3..44963f2 100644 --- a/docs/INSTALL.pt-BR.md +++ b/docs/INSTALL.pt-BR.md @@ -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. diff --git a/docs/images/router-file-icons.png b/docs/images/router-file-icons.png index e0ab585..dd023a3 100644 Binary files a/docs/images/router-file-icons.png and b/docs/images/router-file-icons.png differ diff --git a/docs/images/router-file-icons.svg b/docs/images/router-file-icons.svg index 5c70ff2..e88adf6 100644 --- a/docs/images/router-file-icons.svg +++ b/docs/images/router-file-icons.svg @@ -1,19 +1,19 @@ - + - + Router - + Bambu - + Orca - + Snapmaker - + Prusa - + Cura - + Creality - + Elegoo diff --git a/project.yml b/project.yml index e13f7af..bbb296f 100644 --- a/project.yml +++ b/project.yml @@ -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 diff --git a/scripts/make_file_icons_svg.py b/scripts/make_file_icons_svg.py index ae56c2a..583bee8 100644 --- a/scripts/make_file_icons_svg.py +++ b/scripts/make_file_icons_svg.py @@ -24,7 +24,7 @@ def main(): centre = 62.5 + index * 125 items.append(f'') items.append(f'{label}') - svg = '\n' + svg = '\n' svg += '\n' svg += "\n".join(items) + "\n\n" destination = ROOT / "docs/images/router-file-icons.svg"