From 873db32aad41dcff0a05c41f93deaedaa23152e5 Mon Sep 17 00:00:00 2001 From: jpcaram Date: Tue, 17 Feb 2015 17:54:51 -0500 Subject: [PATCH] Fixed gerber parse error related to extra trace. --- camlib.py | 6 ++++-- sandbox/gerber_find.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 sandbox/gerber_find.py diff --git a/camlib.py b/camlib.py index 0ff05e3e..cd65d388 100644 --- a/camlib.py +++ b/camlib.py @@ -43,8 +43,8 @@ import simplejson as json import logging log = logging.getLogger('base2') -#log.setLevel(logging.DEBUG) -log.setLevel(logging.WARNING) +log.setLevel(logging.DEBUG) +#log.setLevel(logging.WARNING) #log.setLevel(logging.INFO) formatter = logging.Formatter('[%(levelname)s] %(message)s') handler = logging.StreamHandler() @@ -1598,6 +1598,8 @@ class Gerber (Geometry): self.apertures[current_aperture]) poly_buffer.append(flash) + path = [[current_x, current_y]] # Reset path starting point + continue ### G02/3 - Circular interpolation diff --git a/sandbox/gerber_find.py b/sandbox/gerber_find.py new file mode 100644 index 00000000..e757c003 --- /dev/null +++ b/sandbox/gerber_find.py @@ -0,0 +1,30 @@ +from camlib import * + + +def gerber_find(filename, coords, frac_digits=5, tol=0.1): + g = Gerber() + f = open(filename) + current_x = None + current_y = None + line_num = 0 + for line in f: + line_num += 1 + try: + match = g.lin_re.search(line) + if match: + # Parse coordinates + if match.group(2) is not None: + current_x = parse_gerber_number(match.group(2), frac_digits) + if match.group(3) is not None: + current_y = parse_gerber_number(match.group(3), frac_digits) + + if distance(coords, (current_x, current_y)) <= tol: + print line_num, ":", line.strip('\n\r') + except Exception as e: + print str(e) + print line_num, ":", line.strip('\n\r') + + +if __name__ == "__main__": + filename = "/home/jpcaram/flatcam_test_files/ExtraTrace_cleanup.gbr" + gerber_find(filename, (1.2, 1.1)) \ No newline at end of file