Skip to content

Commit

Permalink
[Globals][Added] work_layer
Browse files Browse the repository at this point in the history
- To choose the temporal layer for internal operations

Closes #713
  • Loading branch information
set-soft committed Nov 12, 2024
1 parent d3338c8 commit 6b1d787
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 38 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [1.8.3] - UNRELEASED
### Added
- Global options:
- `work_layer`: to choose the temporal layer for internal operations (#713)
- BoM:
- Field aliases ${QUANTITY} and ${ITEM_NUMBER} for compatibility with
KiCad's internal BoM.
Expand All @@ -29,6 +31,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- BoM
- The field name `Reference` was accepted, but didn't work

### Changed
- Default temporal layer for internal use is now "Margin", instead of "User.9"


## [1.8.2] - 2024-10-28
### Added
- Experimental GUI
Expand Down
53 changes: 33 additions & 20 deletions docs/source/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ Versioning <https://semver.org/spec/v2.0.0.html>`__.
Added
~~~~~

- Global options:

- ``work_layer``: to choose the temporal layer for internal
operations (#713)

- BoM:

- Field aliases ${QUANTITY} and ${ITEM_NUMBER} for compatibility
Expand Down Expand Up @@ -48,6 +53,12 @@ Fixed

- The field name ``Reference`` was accepted, but didn’t work

Changed
~~~~~~~

- Default temporal layer for internal use is now “Margin”, instead of
“User.9”

[1.8.2] - 2024-10-28
--------------------

Expand Down Expand Up @@ -107,6 +118,8 @@ Fixed
- Expansion of internal field names. KiCad expands “VALUE”, not
“Value”, which is what you see in the GUI

.. _changed-1:

Changed
~~~~~~~

Expand Down Expand Up @@ -257,7 +270,7 @@ Fixed:
fills, that could generate huge lines in the generated PCB, not
supported by KiCad. (#660)

.. _changed-1:
.. _changed-2:

Changed:
~~~~~~~~
Expand Down Expand Up @@ -388,7 +401,7 @@ Fixed
- Expansion of variables in fields could fail if the KiCad config
wasn’t initialized

.. _changed-2:
.. _changed-3:

Changed
~~~~~~~
Expand Down Expand Up @@ -418,7 +431,7 @@ Added
- Navigate results: A header and navigation bar (#582)
- BoM: support for SVG format in the logos (#383)

.. _changed-3:
.. _changed-4:

Changed
~~~~~~~
Expand Down Expand Up @@ -615,7 +628,7 @@ Added
- Added a new mode where we can control the added/removed colors
(#551)

.. _changed-4:
.. _changed-5:

Changed
~~~~~~~
Expand Down Expand Up @@ -840,7 +853,7 @@ Added
- ``quote_all``: forces quotes to all values in the CSV output. (See
#456)

.. _changed-5:
.. _changed-6:

Changed
~~~~~~~
Expand Down Expand Up @@ -1020,7 +1033,7 @@ Fixed

- ref_y coordinate not used. (#419)

.. _changed-6:
.. _changed-7:

Changed:
~~~~~~~~
Expand Down Expand Up @@ -1275,7 +1288,7 @@ Added

- Option to control the *SVG precision* (units scale)

.. _changed-7:
.. _changed-8:

Changed
~~~~~~~
Expand Down Expand Up @@ -1420,7 +1433,7 @@ Fixed
- Position: Components wrongly separated by side when the side column
wasn’t the last column (#313)

.. _changed-8:
.. _changed-9:

Changed
~~~~~~~
Expand Down Expand Up @@ -1523,7 +1536,7 @@ Fixed
when VAR isn’t defined. The old code tried to make it an absolute
path.

.. _changed-9:
.. _changed-10:

Changed
~~~~~~~
Expand Down Expand Up @@ -1586,7 +1599,7 @@ Fixed
orientation.
- svg_pcb_print: page orientation for portrait.

.. _changed-10:
.. _changed-11:

Changed
~~~~~~~
Expand Down Expand Up @@ -1746,7 +1759,7 @@ Added
- Support for ``--subst-models`` option for KiCad 6’s kicad2step.
(#137)

.. _changed-11:
.. _changed-12:

Changed
~~~~~~~
Expand Down Expand Up @@ -1837,7 +1850,7 @@ Added
- Basic KiCost support (**experimental**).
- Basic internal BoM and KiCost integration (**experimental**).

.. _changed-12:
.. _changed-13:

Changed
~~~~~~~
Expand Down Expand Up @@ -1949,7 +1962,7 @@ Added
- KiAuto time-out control.
- Now you can import outputs from another config file.

.. _changed-13:
.. _changed-14:

Changed
~~~~~~~
Expand Down Expand Up @@ -1996,7 +2009,7 @@ Added
- A filter to rotate footprints in the position file (#28).
- The step output now can download missing 3D models.

.. _changed-14:
.. _changed-15:

Changed
~~~~~~~
Expand Down Expand Up @@ -2109,7 +2122,7 @@ Fixed
[0.6.2] - 2020-08-25
--------------------

.. _changed-15:
.. _changed-16:

Changed
~~~~~~~
Expand Down Expand Up @@ -2142,7 +2155,7 @@ Added

- More robust behavior on GUI dependent commands.

.. _changed-16:
.. _changed-17:

Changed
~~~~~~~
Expand Down Expand Up @@ -2194,7 +2207,7 @@ Added
- ``error_number`` -> ``number``
- ``regexp`` -> ``regex``

.. _changed-17:
.. _changed-18:

Changed
~~~~~~~
Expand All @@ -2214,7 +2227,7 @@ Changed
[0.5.0] - 2020-07-11
--------------------

.. _changed-18:
.. _changed-19:

Changed
~~~~~~~
Expand Down Expand Up @@ -2320,7 +2333,7 @@ Added
- Better debug information when a BoM fails to be generated.
- Support for compressed YAML files.

.. _changed-19:
.. _changed-20:

Changed
~~~~~~~
Expand Down Expand Up @@ -2362,7 +2375,7 @@ Fixed
[0.2.4] - 2020-05-19
--------------------

.. _changed-20:
.. _changed-21:

Changed
~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions docs/source/configuration/sup_globals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,5 @@
- ``use_pcb_fields`` :index:`: <pair: global options; use_pcb_fields>` [:ref:`boolean <boolean>`] (default: ``true``) When a PCB is processed also use fields defined in the PCB, for filter and variants processing.
This is available for KiCad 8 and newer.
- ``variant`` :index:`: <pair: global options; variant>` [:ref:`string <string>`] (default: ``''``) Default variant to apply to all outputs.
- ``work_layer`` :index:`: <pair: global options; work_layer>` [:ref:`string <string>`] (default: ``'Margin'``) Layer used for temporal tasks, choose a layer you are not using in your design.

2 changes: 0 additions & 2 deletions kibot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ def detect_kicad():
GS.kicad_dir = 'kicad-nightly'
GS.pro_ext = '.kicad_pro'
# KiCad 6+ doesn't support the Rescue layer, they can save it to disk, but can't load it
GS.work_layer = 'Margin'
else:
# Bug in KiCad (#6989), prints to stderr:
# `../src/common/stdpbase.cpp(62): assert "traits" failed in Get(test_dir): create wxApp before calling this`
Expand All @@ -333,7 +332,6 @@ def detect_kicad():
with hide_stderr():
GS.kicad_conf_path = pcbnew.GetKicadConfigPath()
GS.pro_ext = '.pro'
GS.work_layer = 'Rescue'
# Dirs to look for plugins
GS.kicad_plugins_dirs = []
# /usr/share/kicad/*
Expand Down
2 changes: 2 additions & 0 deletions kibot/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ def __init__(self):
self.layer_defaults = Layer
""" [list(dict)=[]] Used to indicate the default suffix and description for the layers.
Note that the name for the layer must match exactly, no aliases """
self.work_layer = 'Margin'
""" Layer used for temporal tasks, choose a layer you are not using in your design """
self.include_components_from_pcb = True
""" Include components that are only in the PCB, not in the schematic, for filter and variants processing.
Note that version 1.6.3 and older ignored them """
Expand Down
4 changes: 2 additions & 2 deletions kibot/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class GS(object):
kicad_share_path = None
kicad_dir = 'kicad'
kicad_plugins_dirs = []
work_layer = 'Rescue'
# KiCad version: major*1e6+minor*1e3+patch
kicad_version_n = 0
kicad_version_major = 0
Expand Down Expand Up @@ -138,7 +137,7 @@ class GS(object):
cli_global_defs = {}
# The variant value, but already solved
solved_global_variant = None
# This is used as default value for classes supporting "output" option
# This is used as default value for classes supporting "output" option
def_global_output = '%f-%i%I%v.%x'
# The class that controls the global options
class_for_global_opts = None
Expand Down Expand Up @@ -216,6 +215,7 @@ class GS(object):
global_kicad_dnp_applied = None
global_kicad_dnp_applies_to_3D = None
global_cross_using_kicad = None
global_work_layer = None
pasteable_cmd = shlex.join if hasattr(shlex, 'join') else lambda x: str(x) # novermin

@staticmethod
Expand Down
18 changes: 11 additions & 7 deletions kibot/kiplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ def load_board(pcb_file=None, forced=False):
try:
with hide_stderr():
board = pcbnew.LoadBoard(pcb_file)
if board.GetLayerID(GS.global_work_layer) < 0:
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:
# Workaround for unexpected KiCad behavior:
# https://gitlab.com/kicad/code/kicad/-/issues/14360
Expand Down Expand Up @@ -532,14 +536,14 @@ def get_output_dir(o_dir, obj, dry=False):
def config_output(out, dry=False, dont_stop=False):
if out._configured:
return True
# Should we load the PCB?
if not dry:
if out.is_pcb():
load_board()
if out.is_sch():
load_sch()
ok = True
try:
# Should we load the PCB?
if not dry:
if out.is_pcb():
load_board()
if out.is_sch():
load_sch()
ok = True
out.config(None)
except (KiPlotConfigurationError, PlotError) as e:
msg = "In section '"+out.name+"' ("+out.type+"): "+str(e)
Expand Down
4 changes: 2 additions & 2 deletions kibot/out_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def remove_paste_and_glue(self, board, comps_hash):
old_badhes = []
old_fmask = []
old_bmask = []
rescue = board.GetLayerID(GS.work_layer)
rescue = board.GetLayerID(GS.global_work_layer)
fmask = board.GetLayerID('F.Mask')
bmask = board.GetLayerID('B.Mask')
if GS.global_remove_solder_mask_for_dnp:
Expand Down Expand Up @@ -538,7 +538,7 @@ def remove_graphics_from_layer(self, board, comps_hash, layer_name):
logger.debug(f'Removing from {layer_name}')
layer_id = board.GetLayerID(layer_name)
old_graphs = []
rescue = board.GetLayerID(GS.work_layer)
rescue = board.GetLayerID(GS.global_work_layer)
for m in GS.get_modules_board(board):
ref = m.GetReference()
c = comps_hash.get(ref, None)
Expand Down
10 changes: 5 additions & 5 deletions kibot/out_pcb_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def get_targets(self, out_dir):
return [self._parent.expand_filename(out_dir, self.output)]

def clear_layer(self, layer):
tmp_layer = GS.board.GetLayerID(GS.work_layer)
tmp_layer = GS.board.GetLayerID(GS.global_work_layer)
cleared_layer = GS.board.GetLayerID(layer)
moved = []
for g in GS.board.GetDrawings():
Expand Down Expand Up @@ -674,7 +674,7 @@ def plot_frame_ki8_external(self, dir_name, p, page, pages, color):
# https://gitlab.com/kicad/code/kicad/-/issues/18959
logger.debugl(1, ' - Fixing images')
# Do a manual draw, just to collect any image
ws.draw(GS.board, GS.board.GetLayerID(GS.work_layer), page, self.pcb.paper_w, self.pcb.paper_h, tb_vars)
ws.draw(GS.board, GS.board.GetLayerID(GS.global_work_layer), page, self.pcb.paper_w, self.pcb.paper_h, tb_vars)
ws.undraw(GS.board)
# We need to plot the images in a separated pass
self.last_worksheet = ws
Expand All @@ -686,7 +686,7 @@ def plot_pads(self, la, pc, p, filelist):
id = la._id
logger.debug('- Plotting pads for layer {} ({})'.format(la.layer, id))
# Make invisible anything but through-hole pads
tmp_layer = GS.board.GetLayerID(GS.work_layer)
tmp_layer = GS.board.GetLayerID(GS.global_work_layer)
moved = []
removed = []
vias = []
Expand Down Expand Up @@ -750,7 +750,7 @@ def plot_vias(self, la, pc, p, filelist, via_t, via_c):
id = la._id
logger.debug('- Plotting vias for layer {} ({})'.format(la.layer, id))
# Make invisible anything but vias
tmp_layer = GS.board.GetLayerID(GS.work_layer)
tmp_layer = GS.board.GetLayerID(GS.global_work_layer)
moved = []
removed = []
vias = []
Expand Down Expand Up @@ -946,7 +946,7 @@ def move_kibot_image_groups(self):
if GS.ki5:
# Groups were introduced in KiCad 6
return
tmp_layer = GS.board.GetLayerID(GS.work_layer)
tmp_layer = GS.board.GetLayerID(GS.global_work_layer)
for g in GS.board.Groups():
name = g.GetName()
if not name.startswith('kibot_image_'):
Expand Down

0 comments on commit 6b1d787

Please sign in to comment.