diff options
author | jaseg <git@jaseg.de> | 2022-02-04 22:10:19 +0100 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2022-02-04 22:10:19 +0100 |
commit | 4cbda84aa61158c06acc78aac4b318bbea5b6214 (patch) | |
tree | 7b5724b019324bbadd862076ece399a73a670b90 /gerbonara/layers.py | |
parent | eaf4f21ce65081da0490a41ee1829b4ec8319109 (diff) | |
download | gerbonara-4cbda84aa61158c06acc78aac4b318bbea5b6214.tar.gz gerbonara-4cbda84aa61158c06acc78aac4b318bbea5b6214.tar.bz2 gerbonara-4cbda84aa61158c06acc78aac4b318bbea5b6214.zip |
More doc, fix tests
Diffstat (limited to 'gerbonara/layers.py')
-rw-r--r-- | gerbonara/layers.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/gerbonara/layers.py b/gerbonara/layers.py index 970b214..eb21c92 100644 --- a/gerbonara/layers.py +++ b/gerbonara/layers.py @@ -58,12 +58,14 @@ def match_files(filenames): gen[target] = gen.get(target, []) + [fn]
return matches
+
def best_match(filenames):
matches = match_files(filenames)
matches = sorted(matches.items(), key=lambda pair: len(pair[1]))
generator, files = matches[-1]
return generator, files
+
def identify_file(data):
if 'M48' in data:
return 'excellon'
@@ -79,6 +81,7 @@ def identify_file(data): return None
+
def common_prefix(l):
out = []
for cand in l:
@@ -115,6 +118,7 @@ def autoguess(filenames): return matches
+
def layername_autoguesser(fn):
fn, _, ext = fn.lower().rpartition('.')
@@ -125,6 +129,7 @@ def layername_autoguesser(fn): if re.search('top|front|pri?m?(ary)?', fn):
side = 'top'
use = 'copper'
+
if re.search('bot(tom)?|back|sec(ondary)?', fn):
side = 'bottom'
use = 'copper'
@@ -135,20 +140,20 @@ def layername_autoguesser(fn): elif re.search('(solder)?paste', fn):
use = 'paste'
- elif re.search('(solder)?mask', fn):
+ elif re.search('(solder)?(mask|resist)', fn):
use = 'mask'
elif re.search('drill|rout?e?', fn):
use = 'drill'
side = 'unknown'
- if re.search(r'np(th)?|(non|un)\W*plated|(non|un)\Wgalv', fn):
+ if re.search(r'np(th|lt)?|(non|un)\W*plated|(non|un)\Wgalv', fn):
side = 'nonplated'
- elif re.search('pth|plated|galv', fn):
+ elif re.search('pth|plated|galv|plt', fn):
side = 'plated'
- elif (m := re.search(r'(la?y?e?r?|in(ner)?)\W*(?P<num>[0-9]+)', fn)):
+ elif (m := re.search(r'(la?y?e?r?|in(ner)?|conduct(or|ive)?)\W*(?P<num>[0-9]+)', fn)):
use = 'copper'
side = f'inner_{int(m["num"]):02d}'
@@ -169,6 +174,7 @@ def layername_autoguesser(fn): return f'{side} {use}'
+
class LayerStack:
@classmethod
def from_directory(kls, directory, board_name=None, verbose=False):
@@ -179,7 +185,7 @@ class LayerStack: files = [ path for path in directory.glob('**/*') if path.is_file() ]
generator, filemap = best_match(files)
- print('detected generator', generator)
+ #print('detected generator', generator)
if len(filemap) < 6:
warnings.warn('Ambiguous gerber filenames. Trying last-resort autoguesser.')
@@ -210,6 +216,12 @@ class LayerStack: raise SystemError('Cannot figure out gerber file mapping')
# FIXME use layer metadata from comments and ipc file if available
+ elif generator == 'zuken':
+ filemap = autoguess([ f for files in filemap for f in files ])
+ if len(filemap < 6):
+ raise SystemError('Cannot figure out gerber file mapping')
+ # FIXME use layer metadata from comments and ipc file if available
+
elif generator == 'altium':
excellon_settings = None
@@ -231,8 +243,8 @@ class LayerStack: else:
excellon_settings = None
- import pprint
- pprint.pprint(filemap)
+ #import pprint
+ #pprint.pprint(filemap)
ambiguous = [ key for key, value in filemap.items() if len(value) > 1 and not 'drill' in key ]
if ambiguous:
@@ -247,7 +259,7 @@ class LayerStack: for path in paths:
id_result = identify_file(path.read_text())
- print('id_result', id_result)
+ #print('id_result', id_result)
if 'netlist' in key:
layer = Netlist.open(path)
|