Merge branch 'dev' into kiri_integration

This commit is contained in:
Salvador E. Tropea 2023-12-05 13:23:08 -03:00
commit d8f3b45d7c
10 changed files with 53 additions and 27 deletions

View File

@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.6.4] - UNRELEASED ## [1.6.4] - UNRELEASED
### Added ### Added
- General:
- Operations that copies the project now also copies the PRL
- Command line: - Command line:
- `--help-list-offsets` to list footprint offsets (JLCPCB) - `--help-list-offsets` to list footprint offsets (JLCPCB)
- `--help-list-rotations` to list footprint rotations (JLCPCB) - `--help-list-rotations` to list footprint rotations (JLCPCB)
@ -16,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `layer_defaults` to specify the default suffix and description. (#504) - `layer_defaults` to specify the default suffix and description. (#504)
- `include_components_from_pcb` to disable the new behavior that includes - `include_components_from_pcb` to disable the new behavior that includes
components from the PCB in the filter/variants processing components from the PCB in the filter/variants processing
- `restore_project` now also restores the PRL
- Schematic format: - Schematic format:
- Support for *unit names* (#513) - Support for *unit names* (#513)
- Internal templates: - Internal templates:
@ -114,6 +117,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- QR Lib: - QR Lib:
- When used from the preflight the name of the file changed to the name of a - When used from the preflight the name of the file changed to the name of a
temporal, generating problems with the plot outputs, like pcb_print temporal, generating problems with the plot outputs, like pcb_print
- Project options not preserved, i.e. set_text_variables failing
## [1.6.3] - 2023-06-26 ## [1.6.3] - 2023-06-26

View File

@ -59,6 +59,7 @@ preflight:
# If you need to check the parity use the `update_xml` preflight. # If you need to check the parity use the `update_xml` preflight.
# KiCad 6 introduced `warnings` they are currently counted be the `unconnected` counter of KiBot. # KiCad 6 introduced `warnings` they are currently counted be the `unconnected` counter of KiBot.
# This will change in the future. # This will change in the future.
# If you use DRC exclusions please consult the `drc_exclusions_workaround` global option.
run_drc: true run_drc: true
# [boolean=false] Runs the ERC (Electrical Rules Check). To ensure the schematic is electrically correct. # [boolean=false] Runs the ERC (Electrical Rules Check). To ensure the schematic is electrically correct.
# The report file name is controlled by the global output pattern (%i=erc %x=txt). # The report file name is controlled by the global output pattern (%i=erc %x=txt).

View File

@ -171,6 +171,7 @@
which is used by the KiBot docker images, on other OSs *your mileage may vary*. which is used by the KiBot docker images, on other OSs *your mileage may vary*.
- ``restore_project`` :index:`: <pair: global options; restore_project>` [boolean=false] Restore the KiCad project after execution. - ``restore_project`` :index:`: <pair: global options; restore_project>` [boolean=false] Restore the KiCad project after execution.
Note that this option will undo operations like `set_text_variables`. Note that this option will undo operations like `set_text_variables`.
Starting with 1.6.4 it also restores the PRL (Project Local Settings) file.
- ``set_text_variables_before_output`` :index:`: <pair: global options; set_text_variables_before_output>` [boolean=false] Run the `set_text_variables` preflight before running each output that involves variants. - ``set_text_variables_before_output`` :index:`: <pair: global options; set_text_variables_before_output>` [boolean=false] Run the `set_text_variables` preflight before running each output that involves variants.
This can be used when a text variable uses the variant and you want to create more than This can be used when a text variable uses the variant and you want to create more than
one variant in the same run. Note that this could be slow because it forces a board one variant in the same run. Note that this could be slow because it forces a board

View File

@ -84,7 +84,8 @@ Supported preflights
Note that the KiCad 6+ *Test for parity between PCB and schematic* option is not supported. |br| Note that the KiCad 6+ *Test for parity between PCB and schematic* option is not supported. |br|
If you need to check the parity use the `update_xml` preflight. |br| If you need to check the parity use the `update_xml` preflight. |br|
KiCad 6 introduced `warnings` they are currently counted be the `unconnected` counter of KiBot. |br| KiCad 6 introduced `warnings` they are currently counted be the `unconnected` counter of KiBot. |br|
This will change in the future. This will change in the future. |br|
If you use DRC exclusions please consult the `drc_exclusions_workaround` global option.
- **run_erc**: :index:`: <pair: preflights; run_erc>` [boolean=false] Runs the ERC (Electrical Rules Check). To ensure the schematic is electrically correct. - **run_erc**: :index:`: <pair: preflights; run_erc>` [boolean=false] Runs the ERC (Electrical Rules Check). To ensure the schematic is electrically correct.
The report file name is controlled by the global output pattern (%i=erc %x=txt). The report file name is controlled by the global output pattern (%i=erc %x=txt).
- **sch_replace**: :index:`: <pair: preflights; sch_replace>` [dict] Replaces tags in the schematic. I.e. to insert the git hash or last revision date. - **sch_replace**: :index:`: <pair: preflights; sch_replace>` [dict] Replaces tags in the schematic. I.e. to insert the git hash or last revision date.

View File

@ -238,7 +238,8 @@ class Globals(FiltersOptions):
""" When applying filters and variants remove the solder mask apertures for components that won't be included """ """ When applying filters and variants remove the solder mask apertures for components that won't be included """
self.restore_project = False self.restore_project = False
""" Restore the KiCad project after execution. """ Restore the KiCad project after execution.
Note that this option will undo operations like `set_text_variables` """ Note that this option will undo operations like `set_text_variables`.
Starting with 1.6.4 it also restores the PRL (Project Local Settings) file """
self.set_text_variables_before_output = False self.set_text_variables_before_output = False
""" Run the `set_text_variables` preflight before running each output that involves variants. """ Run the `set_text_variables` preflight before running each output that involves variants.
This can be used when a text variable uses the variant and you want to create more than This can be used when a text variable uses the variant and you want to create more than

View File

@ -243,17 +243,29 @@ class GS(object):
@staticmethod @staticmethod
def read_pro(): def read_pro():
if GS.pro_file: if not GS.pro_file:
# Note: We use binary mode to preserve the original end of lines return None
# Otherwise git could see changes in the file # Note: We use binary mode to preserve the original end of lines
with open(GS.pro_file, 'rb') as f: # Otherwise git could see changes in the file
return f.read() with open(GS.pro_file, 'rb') as f:
pro = f.read()
prl_name = GS.pro_file[:-3]+'prl'
prl = None
if os.path.isfile(prl_name):
with open(prl_name, 'rb') as f:
prl = f.read()
return (pro, prl)
@staticmethod @staticmethod
def write_pro(prj): def write_pro(data):
if GS.pro_file and prj: if not GS.pro_file or data is None:
with open(GS.pro_file, 'wb') as f: return
f.write(prj) with open(GS.pro_file, 'wb') as f:
f.write(data[0])
if data[1] is None:
return
with open(GS.pro_file[:-3]+'prl', 'wb') as f:
f.write(data[1])
@staticmethod @staticmethod
def load_sch_title_block(): def load_sch_title_block():
@ -468,12 +480,20 @@ class GS(object):
def copy_project(new_pcb_name, dry=False): def copy_project(new_pcb_name, dry=False):
pro_name = GS.pro_file pro_name = GS.pro_file
if pro_name is None or not os.path.isfile(pro_name): if pro_name is None or not os.path.isfile(pro_name):
return None return None, None
pro_copy = new_pcb_name.replace('.kicad_pcb', GS.pro_ext) pro_copy = new_pcb_name.replace('.kicad_pcb', GS.pro_ext)
if not dry: if not dry:
logger.debug('Copying project `{}` to `{}`'.format(pro_name, pro_copy)) logger.debug(f'Copying project `{pro_name}` to `{pro_copy}`')
copy2(pro_name, pro_copy) copy2(pro_name, pro_copy)
return pro_copy # Also copy the PRL
prl_name = pro_name[:-3]+'prl'
prl_copy = None
if os.path.isfile(prl_name):
prl_copy = pro_copy[:-3]+'prl'
if not dry:
logger.debug(f'Copying project local settings `{prl_name}` to `{prl_copy}`')
copy2(prl_name, prl_copy)
return pro_copy, prl_copy
@staticmethod @staticmethod
def copy_project_sch(sch_dir): def copy_project_sch(sch_dir):

View File

@ -930,7 +930,7 @@ class VariantOptions(BaseOptions):
fname = os.path.join(pcb_dir, basename+'.kicad_pcb') fname = os.path.join(pcb_dir, basename+'.kicad_pcb')
logger.debug('Storing modified PCB to `{}`'.format(fname)) logger.debug('Storing modified PCB to `{}`'.format(fname))
GS.board.Save(fname) GS.board.Save(fname)
pro_name = GS.copy_project(fname) pro_name, _ = GS.copy_project(fname)
KiConf.fix_page_layout(pro_name) KiConf.fix_page_layout(pro_name)
return fname, pcb_dir return fname, pcb_dir

View File

@ -178,6 +178,9 @@ class Copy_FilesOptions(Base3DOptions):
else: else:
# Create the libs # Create the libs
for lib, comps in libs.items(): for lib, comps in libs.items():
if lib == 'locally_edited':
# Not from a lib, just a copy inside the SCH
continue
GS.sch.write_lib(out_lib_base, lib, comps) GS.sch.write_lib(out_lib_base, lib, comps)
new_alias = LibAlias() new_alias = LibAlias()
new_alias.name = lib new_alias.name = lib
@ -232,11 +235,13 @@ class Copy_FilesOptions(Base3DOptions):
self.add_sch_files(extra_files, dest_dir) self.add_sch_files(extra_files, dest_dir)
elif mode_project: elif mode_project:
self.add_sch_files(extra_files, dest_dir) self.add_sch_files(extra_files, dest_dir)
prj_name = GS.copy_project(fname, dry) prj_name, prl_name = GS.copy_project(fname, dry)
# Extra files that we are generating # Extra files that we are generating
extra_files.append(fname) extra_files.append(fname)
if prj_name: if prj_name:
extra_files.append(prj_name) extra_files.append(prj_name)
if prl_name:
extra_files.append(prl_name)
if mode_project: if mode_project:
extra_files += self.copy_footprints(f.dest, dry) extra_files += self.copy_footprints(f.dest, dry)
extra_files += self.copy_symbols(f.dest, dry) extra_files += self.copy_symbols(f.dest, dry)

View File

@ -398,6 +398,8 @@ class QR_LibOptions(BaseOptions):
f.write(dumps(separated)) f.write(dumps(separated))
f.write('\n') f.write('\n')
tmp_pcb = f.name tmp_pcb = f.name
# Also copy the project
GS.copy_project(tmp_pcb)
# Reload it # Reload it
logger.debug('- Loading the temporal PCB') logger.debug('- Loading the temporal PCB')
load_board(tmp_pcb, forced=True) load_board(tmp_pcb, forced=True)
@ -405,19 +407,9 @@ class QR_LibOptions(BaseOptions):
logger.debug('- Replacing the old PCB') logger.debug('- Replacing the old PCB')
os.remove(tmp_pcb) os.remove(tmp_pcb)
GS.make_bkp(GS.pcb_file) GS.make_bkp(GS.pcb_file)
prl = None
if GS.ki6:
# KiCad 6 is destroying the PRL ...
prl_name = GS.pcb_no_ext+'.kicad_prl'
if os.path.isfile(prl_name):
with open(prl_name, 'rt') as f:
prl = f.read()
GS.board.Save(GS.pcb_file) GS.board.Save(GS.pcb_file)
# After saving the file the name isn't changed, we must force it!!! # After saving the file the name isn't changed, we must force it!!!
GS.board.SetFileName(GS.pcb_file) GS.board.SetFileName(GS.pcb_file)
if prl:
with open(prl_name, 'wt') as f:
f.write(prl)
def update_symbol(self, name, c_name, sexp, qr): def update_symbol(self, name, c_name, sexp, qr):
logger.debug('- Updating QR symbol: '+name) logger.debug('- Updating QR symbol: '+name)

View File

@ -30,7 +30,8 @@ class Run_DRC(BasePreFlight): # noqa: F821
Note that the KiCad 6+ *Test for parity between PCB and schematic* option is not supported. Note that the KiCad 6+ *Test for parity between PCB and schematic* option is not supported.
If you need to check the parity use the `update_xml` preflight. If you need to check the parity use the `update_xml` preflight.
KiCad 6 introduced `warnings` they are currently counted be the `unconnected` counter of KiBot. KiCad 6 introduced `warnings` they are currently counted be the `unconnected` counter of KiBot.
This will change in the future """ This will change in the future.
If you use DRC exclusions please consult the `drc_exclusions_workaround` global option """
def __init__(self, name, value): def __init__(self, name, value):
super().__init__(name, value) super().__init__(name, value)
if not isinstance(value, bool): if not isinstance(value, bool):