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
22 changes: 17 additions & 5 deletions kibot/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,20 @@ def __init__(self):
""" [string|list(string)] Name/s of the field/s used for the current raiting.
You can use `_field_current` as field name to use it in most places """
self.invalidate_pcb_text_cache = 'auto'
""" [auto,yes,no] Remove any cached text variable in the PCB. This is needed in order to force a text
variables update when using `set_text_variables`. You might want to disable it when applying some
changes to the PCB and create a new copy to send to somebody without changing the cached values.
Note that it will save the PCB with the cache erased.
The `auto` value will remove the cached values only when using `set_text_variables` """
""" [auto,yes,no] Clear the text variables cache in the PCB file. This is needed in order to force KiCad to read
updated text variables from the project file when they are changed with `set_text_variables`. You might want to
disable it when applying some changes to the PCB and create a new copy to send to somebody without changing the
cached values.
The `auto` value will remove the cached values only when using `set_text_variables`.
Note that at least one of the `invalidate_pcb_text_cache` and `update_pcb_text_cache` config values must be set
to 'no', otherwise an error is produced."""
self.update_pcb_text_cache = 'no'
""" [auto,yes,no] Update the text variables cache in the PCB file. This makes the PCB file self-contained (usable
without the project file next to it) by copying all text variables from the project file (possibly modified by
the `set_text_variables` preflight) into the PCB file (the cache is completely replaced).
The `auto` value will update the cache only when using `set_text_variables`.
Note that at least one of the `invalidate_pcb_text_cache` and `update_pcb_text_cache` config values must be set
to 'no', otherwise an error is produced."""
self.git_diff_strategy = 'worktree'
""" [worktree,stash] When computing a PCB/SCH diff it configures how do we preserve the current
working state. The *worktree* mechanism creates a separated worktree, that then is just removed.
Expand Down Expand Up @@ -581,6 +590,9 @@ def config(self, parent):
KiConf.aliases_3D[alias.name] = alias.value
logger.debugl(1, '- {}={}'.format(alias.name, alias.value))
logger.debugl(1, 'Finished adding aliases')
if GS.global_invalidate_pcb_text_cache != 'no' and GS.global_update_pcb_text_cache != 'no':
raise KiPlotConfigurationError("At least one of `invalidate_pcb_text_cache` and `update_pcb_text_cache`"
" option must be `no`")


logger = get_logger(__name__)
Expand Down
1 change: 1 addition & 0 deletions kibot/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class GS(object):
global_git_diff_strategy = None
global_impedance_controlled = None
global_invalidate_pcb_text_cache = None
global_update_pcb_text_cache = None
global_kiauto_time_out_scale = None
global_kiauto_wait_start = None
global_layer_defaults = None
Expand Down
14 changes: 11 additions & 3 deletions kibot/kiplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,20 @@ def load_board(pcb_file=None, forced=False):
raise KiPlotConfigurationError(f"Unknown layer used for the global `work_layer` option"
f" (`{GS.global_work_layer}`)")

if GS.global_invalidate_pcb_text_cache == 'yes' and GS.ki6:
if (GS.global_invalidate_pcb_text_cache == 'yes' or GS.global_update_pcb_text_cache == 'yes') and GS.ki6:
# Workaround for unexpected KiCad behavior:
# https://gitlab.com/kicad/code/kicad/-/issues/14360
logger.debug('Current PCB text variables cache: {}'.format(board.GetProperties().items()))
logger.debug('Removing cached text variables')
board.SetProperties(pcbnew.MAP_STRING_STRING())

props = pcbnew.MAP_STRING_STRING()

if GS.global_update_pcb_text_cache == 'yes':
for k, v in GS.load_pro_variables().items():
props[k] = v
logger.debug('Updating cached text variables')
else:
logger.debug('Removing cached text variables')
board.SetProperties(props)
# Save the PCB, so external tools also gets the reset, i.e. panelize, see #652
GS.save_pcb(pcb_file, board)
if BasePreFlight.get_option('check_zone_fills'):
Expand Down
5 changes: 4 additions & 1 deletion kibot/pre_set_text_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ def apply(self):
if GS.board:
# Force a project and PCB reload
GS.reload_project(pro_name)
# Check if we need to force a PCB text variables reset
# Check if we need to force a PCB text variables reset or update
if GS.global_invalidate_pcb_text_cache == 'auto':
logger.debug('Forcing PCB text variables reset')
GS.global_invalidate_pcb_text_cache = 'yes'
if GS.global_update_pcb_text_cache == 'auto':
logger.debug('Forcing PCB text variables update')
GS.global_update_pcb_text_cache = 'yes'
Loading