Now the global PCB detail vars control the default colors

- Used by rednder_3d and pcbdraw outputs.
This commit is contained in:
Salvador E. Tropea 2022-01-14 13:42:35 -03:00
parent 4bba7e9a9a
commit a2f5da14ab
5 changed files with 82 additions and 17 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2021 Salvador E. Tropea
# Copyright (c) 2020-2021 Instituto Nacional de Tecnología Industrial
# Copyright (c) 2020-2022 Salvador E. Tropea
# Copyright (c) 2020-2022 Instituto Nacional de Tecnología Industrial
# License: GPL-3.0
# Project: KiBot (formerly KiPlot)
""" Miscellaneous definitions """
@ -218,6 +218,17 @@ W_UNKFLD = '(W076) '
W_ALRDOWN = '(W077) '
W_KICOSTFLD = '(W078) '
W_MIXVARIANT = '(W079) '
# Somehow arbitrary, the colors are real, but can be different
PCB_MAT_COLORS = {'fr1': "937042", 'fr2': "949d70", 'fr3': "adacb4", 'fr4': "332B16", 'fr5': "6cc290"}
PCB_FINISH_COLORS = {'hal': "8b898c", 'hasl': "8b898c", 'imag': "8b898c", 'enig': "cfb96e", 'none': "d39751"}
SOLDER_COLORS = {'green': ("#285e3a", "#208b47"),
'black': ("#1d1918", "#2d2522"),
'blue': ("#1b1f44", "#00406a"),
'red': ("#812e2a", "#be352b"),
'white': ("#bdccc7", "#b7b7ad"),
'yellow': ("#73823d", "#f2a756"),
'purple': ("#30234a", "#451d70")}
SILK_COLORS = {'black': "0b1013", 'white': "d5dce4"}
class Rect(object):

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2021 Salvador E. Tropea
# Copyright (c) 2020-2021 Instituto Nacional de Tecnología Industrial
# Copyright (c) 2020-2022 Salvador E. Tropea
# Copyright (c) 2020-2022 Instituto Nacional de Tecnología Industrial
# License: GPL-3.0
# Project: KiBot (formerly KiPlot)
import os
@ -8,7 +8,8 @@ from tempfile import (NamedTemporaryFile)
# Here we import the whole module to make monkeypatch work
import subprocess
import shutil
from .misc import PCBDRAW, PCBDRAW_ERR, URL_PCBDRAW, W_AMBLIST, W_UNRETOOL, W_USESVG2, W_USEIMAGICK
from .misc import (PCBDRAW, PCBDRAW_ERR, URL_PCBDRAW, W_AMBLIST, W_UNRETOOL, W_USESVG2, W_USEIMAGICK, PCB_MAT_COLORS,
PCB_FINISH_COLORS, SOLDER_COLORS, SILK_COLORS)
from .kiplot import check_script
from .gs import (GS)
from .optionable import Optionable
@ -25,17 +26,17 @@ class PcbDrawStyle(Optionable):
def __init__(self):
super().__init__()
with document:
self.copper = "#417e5a"
self.copper = "#285e3a"
""" color for the copper zones (covered by solder mask) """
self.board = "#4ca06c"
self.board = "#208b47"
""" color for the board without copper (covered by solder mask) """
self.silk = "#f0f0f0"
self.silk = "#d5dce4"
""" color for the silk screen """
self.pads = "#b5ae30"
self.pads = "#8b898c"
""" color for the exposed pads (metal finish) """
self.outline = "#000000"
""" color for the outline """
self.clad = "#9c6b28"
self.clad = "#cabb3e"
""" color for the PCB core (not covered by solder mask) """
self.vcut = "#bf2600"
""" color for the V-CUTS """
@ -47,6 +48,27 @@ class PcbDrawStyle(Optionable):
""" [0,1000] how much the highlight extends around the component [mm] """
def config(self, parent):
# Apply global defaults
if GS.global_pcb_material is not None:
material = GS.global_pcb_material.lower()
for mat, color in PCB_MAT_COLORS.items():
if mat in material:
self.clad = "#"+color
break
if GS.global_solder_mask_color is not None:
name = GS.global_solder_mask_color.lower()
if name in SOLDER_COLORS:
(self.copper, self.board) = SOLDER_COLORS[name]
if GS.global_silk_screen_color is not None:
name = GS.global_silk_screen_color.lower()
if name in SILK_COLORS:
self.silk = "#"+SILK_COLORS[name]
if GS.global_pcb_finish is not None:
name = GS.global_pcb_finish.lower()
for nm, color in PCB_FINISH_COLORS.items():
if nm in name:
self.pads = "#"+color
break
super().config(parent)
self.validate_colors(['board', 'copper', 'board', 'silk', 'pads', 'outline', 'clad', 'vcut'])
# Not implemented but required
@ -155,7 +177,10 @@ class PcbDrawOptions(VariantOptions):
self.remap = self.remap._tree
# Style
if isinstance(self.style, type):
self.style = None
# Apply the global defaults
style = PcbDrawStyle()
style.config(self)
self.style = style.to_dict()
elif isinstance(self.style, PcbDrawStyle):
self.style = self.style.to_dict()
self._expand_id = 'bottom' if self.bottom else 'top'

View File

@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021 Salvador E. Tropea
# Copyright (c) 2021 Instituto Nacional de Tecnología Industrial
# Copyright (c) 2021-2022 Salvador E. Tropea
# Copyright (c) 2021-2022 Instituto Nacional de Tecnología Industrial
# License: GPL-3.0
# Project: KiBot (formerly KiPlot)
# KiCad 6 bug: https://gitlab.com/kicad/code/kicad/-/issues/9890
import os
from glob import glob
from shutil import rmtree
from .misc import CMD_PCBNEW_3D, URL_PCBNEW_3D, RENDER_3D_ERR
from .misc import (CMD_PCBNEW_3D, URL_PCBNEW_3D, RENDER_3D_ERR, PCB_MAT_COLORS, PCB_FINISH_COLORS, SOLDER_COLORS, SILK_COLORS)
from .gs import (GS)
from .kiplot import check_script, exec_with_retry, add_extra_options
from .out_base_3d import Base3DOptions, Base3D
@ -42,11 +42,11 @@ class Render3DOptions(Base3DOptions):
""" Second color for the background gradient """
self.board = "#332B16"
""" Color for the board without copper or solder mask """
self.copper = "#B29C00"
self.copper = "#8b898c"
""" Color for the copper """
self.silk = "#E5E5E5"
self.silk = "#d5dce4"
""" Color for the silk screen """
self.solder_mask = "#143324"
self.solder_mask = "#208b47"
""" Color for the solder mask """
self.solder_paste = "#808080"
""" Color for the solder paste """
@ -78,6 +78,27 @@ class Render3DOptions(Base3DOptions):
self._expand_ext = 'png'
def config(self, parent):
# Apply global defaults
if GS.global_pcb_material is not None:
material = GS.global_pcb_material.lower()
for mat, color in PCB_MAT_COLORS.items():
if mat in material:
self.board = "#"+color
break
if GS.global_solder_mask_color is not None:
name = GS.global_solder_mask_color.lower()
if name in SOLDER_COLORS:
(_, self.solder_mask) = SOLDER_COLORS[name]
if GS.global_silk_screen_color is not None:
name = GS.global_silk_screen_color.lower()
if name in SILK_COLORS:
self.silk = "#"+SILK_COLORS[name]
if GS.global_pcb_finish is not None:
name = GS.global_pcb_finish.lower()
for nm, color in PCB_FINISH_COLORS.items():
if nm in name:
self.copper = "#"+color
break
super().config(parent)
self.validate_colors(self._colors.keys())
view = self._views.get(self.view, None)

View File

@ -1,6 +1,10 @@
kiplot:
version: 1
global:
solder_mask_color: blue
pcb_finish: ENIG
outputs:
- name: PcbDraw
comment: "PcbDraw test top"

View File

@ -2,6 +2,10 @@
kibot:
version: 1
global:
solder_mask_color: blue
pcb_finish: ENIG
filters:
- name: '3D change'
comment: 'Changes R2 3D model'