Solves Gerber parser bug in Issue #92 (Incorrect Flashes).

This commit is contained in:
Juan Pablo Caram
2015-01-06 13:06:01 -05:00
parent ba4ddee5fe
commit ddd90f9f33
2 changed files with 37 additions and 17 deletions

View File

@@ -12,6 +12,7 @@ import os
import Tkinter
import re
from PyQt4 import QtCore
import time
########################################
## Imports part of FlatCAM ##
@@ -52,8 +53,8 @@ class App(QtCore.QObject):
## Logging ##
log = logging.getLogger('base')
#log.setLevel(logging.DEBUG)
log.setLevel(logging.WARNING)
log.setLevel(logging.DEBUG)
#log.setLevel(logging.WARNING)
formatter = logging.Formatter('[%(levelname)s][%(threadName)s] %(message)s')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
@@ -717,6 +718,8 @@ class App(QtCore.QObject):
App.log.debug("new_object()")
t0 = time.time() # Debug
### Check for existing name
while name in self.collection.get_names():
## Create a new name
@@ -752,12 +755,18 @@ class App(QtCore.QObject):
# User must take care to implement initialize
# in a thread-safe way as is is likely that we
# have been invoked in a separate thread.
t1 = time.time()
self.log.debug("%f seconds before initialize()." % (t1 - t0))
initialize(obj, self)
t2 = time.time()
self.log.debug("%f seconds executing initialize()." % (t2 - t1))
# Check units and convert if necessary
if self.options["units"].upper() != obj.units.upper():
self.inform.emit("Converting units to " + self.options["units"] + ".")
obj.convert_units(self.options["units"])
t3 = time.time()
self.log.debug("%f seconds converting units." % (t3 - t2))
FlatCAMApp.App.log.debug("Moving new object back to main thread.")
@@ -1206,11 +1215,14 @@ class App(QtCore.QObject):
:param obj: The newly created FlatCAM object.
:return: None
"""
t0 = time.time() # DEBUG
self.log.debug("on_object_created()")
self.inform.emit("Object (%s) created: %s" % (obj.kind, obj.options['name']))
self.collection.append(obj)
obj.plot()
self.on_zoom_fit(None)
t1 = time.time() # DEBUG
self.log.debug("%f seconds adding object and plotting." % (t1 - t0))
def on_zoom_fit(self, event):
"""

View File

@@ -42,8 +42,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()
@@ -1194,6 +1194,8 @@ class Gerber (Geometry):
### Cleanup
gline = gline.strip(' \r\n')
#log.debug("%3s %s" % (line_num, gline))
### Aperture Macros
# Having this at the beggining will slow things down
# but macros can have complicated statements than could
@@ -1431,7 +1433,10 @@ class Gerber (Geometry):
## --- Buffered ---
try:
flash = Gerber.create_flash_geometry(Point(path[-1]),
log.debug("Bare op-code %d." % current_operation_code)
# flash = Gerber.create_flash_geometry(Point(path[-1]),
# self.apertures[current_aperture])
flash = Gerber.create_flash_geometry(Point(current_x, current_y),
self.apertures[current_aperture])
poly_buffer.append(flash)
except IndexError:
@@ -1511,8 +1516,9 @@ class Gerber (Geometry):
# Example: D12*
match = self.tool_re.search(gline)
if match:
log.debug("Line %d: Aperture change to (%s)" % (line_num, match.group(1)))
current_aperture = match.group(1)
log.debug("Line %d: Aperture change to (%s)" % (line_num, match.group(1)))
log.debug(self.apertures[current_aperture])
# Take care of the current path with the previous tool
if len(path) > 1:
@@ -1617,6 +1623,8 @@ class Gerber (Geometry):
@staticmethod
def create_flash_geometry(location, aperture):
log.debug('Flashing @%s, Aperture: %s' % (location, aperture))
if type(location) == list:
location = Point(location)