Added support for multiple matching rules

We now use the last matching rule when there are multiple matches. This allows local overrides as well as rules defined in order of specificity. This relies on Python 3.7+ ordered dicts.
This commit is contained in:
Matthew Lai 2022-07-23 10:26:56 +01:00
parent feabc95236
commit 5ecf6c9b13
4 changed files with 14 additions and 12 deletions

View File

@ -7,7 +7,7 @@ JLCKicadTools is a tool aims to work with JLCPCB assembly service featuring KiCa
See [this blog post](https://dubiouscreations.com/2019/10/21/using-kicad-with-jlcpcb-assembly-service) for instructions.
## Requirements
Python 3.6+
Python 3.7+
### Installation
```

View File

@ -1 +1 @@
__version__ = "1.0.4"
__version__ = "1.0.5"

View File

@ -111,22 +111,24 @@ def FixRotations(input_filename, output_filename, db):
row[posx_index] = "{0:.6f}".format(-float(row[posx_index]))
row[ref_index] = row[ref_index].upper()
no_match = True
last_correction = None
for pattern, correction in db.items():
if pattern.match(row[package_index]):
no_match = False
_LOGGER.logger.info(
"Footprint {} matched {}. Applying {} deg correction".format(
row[package_index], pattern.pattern, correction
)
)
if row[side_index].strip() == "bottom":
rotation = (rotation - correction + 180) % 360
else:
rotation = (rotation + correction) % 360
row[rotation_index] = "{0:.6f}".format(rotation)
break
if no_match and row[side_index].strip() == "bottom":
last_correction = correction
if last_correction is not None:
if row[side_index].strip() == "bottom":
rotation = (rotation - correction + 180) % 360
else:
rotation = (rotation + correction) % 360
row[rotation_index] = "{0:.6f}".format(rotation)
if last_correction is None and row[side_index].strip() == "bottom":
rotation = (rotation + 180) % 360
row[rotation_index] = "{0:.6f}".format(rotation)
writer.writerow(row)

View File

@ -12,7 +12,7 @@ setup(
license='GPL3',
packages=find_packages(),
include_package_data=True,
python_requires='>=3.6',
python_requires='>=3.7',
install_requires=['logzero>=1.5'],
entry_points={"console_scripts": [
"jlc-kicad-tools = jlc_kicad_tools.generate_jlc_files:main"