def run(self): self.alive = True self.feedbackHandler.setStatus("Opening file...") self.dxfFile = dxflib.dxf( self.fileName ) #self.dxfFile.printEnts() self.feedbackHandler.setStatus("Removing file offset...") # Remove file offset minX, minY, maxX, maxY = self.getFileLimitsXY() print "dxf m&ms", minX, minY, maxX, maxY for e in self.dxfFile.entities: if e.type == "LINE": e.startX -= minX e.startY -= minY e.endX -= minX e.endY -= minY elif e.type == "CIRCLE" or e.type == "ARC": e.centreX -= minX e.centreY -= minY # Start plot of entities for i, e in enumerate(self.dxfFile.entities): progress = int( float(i) / float( len(self.dxfFile.entities) ) * 100 ) self.feedbackHandler.setStatus("Drawing entities..." + str(progress) + "%") # Break if thread has been told to termiate if not self.alive: self.feedbackHandler.aborted() break if e.type == "LINE": self.toolpath.currentLayer.polygons.append( shapeplotter.line( (e.startX, e.startY, e.endX, e.endY) ) ) print "line makes", shapeplotter.line( (e.startX, e.startY, e.endX, e.endY) ), len(shapeplotter.line( (e.startX, e.startY, e.endX, e.endY) ).points) elif e.type == "CIRCLE": self.toolpath.currentLayer.polygons.append( shapeplotter.circle( e.centreX, e.centreY, e.radius, self.arcResolution ) ) elif e.type == "ARC": self.toolpath.currentLayer.polygons.append( shapeplotter.arc( e.centreX, e.centreY, e.radius, math.radians(e.startAngle), math.radians(e.endAngle), resolution = self.arcResolution ) ) if self.alive: # Tell gui that plot is complete (redraw screen) self.feedbackHandler.plotComplete()
def run(self): self.alive = True self.feedbackHandler.setStatus("Opening file...") self.gerberFile = gerberlib.gerber(self.fileName) self.feedbackHandler.setStatus("Removing file offset...") # Remove file offset minX, minY, maxX, maxY = self.getFileLimitsXY() for e in self.gerberFile.flashes + self.gerberFile.traces: if e.type == gerberlib.FLASH: e.x -= minX e.y -= minY elif e.type == gerberlib.STROKE: e.x1 -= minX e.x2 -= minX e.y1 -= minY e.y2 -= minY # Fill plot mode ( for pen drawing ) # TODO - apply grouping to this plotter also to remove excess penup ops? if self.pref_plotMode == 0: # Plotting is pretty simple at the moment, plotter blindly follows gerber file and plots out each trace / flash individually. # Can be impoved by re-ordering drawing, and by combining connected traces into continual events / removing overlap # Plot all gerber flashes for i, f in enumerate(self.gerberFile.flashes): # Break if thread has been told to termiate if not self.alive: self.feedbackHandler.aborted() break progress = int( float(i) / float( len(self.gerberFile.flashes) ) * 100 ) self.feedbackHandler.setStatus("Plotting flashes..." + str(progress) + "%") #f.printFlash() # Move is static flash type if f.aperture.isMacro: print "macro", f.aperture.macroName if f.aperture.apertureType == "C": # Using circular aperture if self.debug: print "aperture radius", radius, "mm" #self.shapePlot.plotCircle( f.x + self.offsetX, f.y + self.offsetY, f.aperture.radius, filled = True, fillDensity = self.fillDensity ) self.toolpath.currentLayer.polygons.append( shapeplotter.circle( f.x, f.y, f.aperture.radius, self.arcResolution, self.fillDensity ) ) elif f.aperture.apertureType == "R": # Using rectangular aperture #self.shapePlot.plotRectangle( f.x + self.offsetX, f.y + self.offsetY, f.aperture.width, f.aperture.height, self.fillDensity ) self.toolpath.currentLayer.polygons.append( shapeplotter.rectangle( f.x, f.y, f.aperture.width, f.aperture.height, self.fillDensity ) ) elif f.aperture.apertureType == "O": #self.shapePlot.plotEllipse( f.x + self.offsetX, f.y + self.offsetY, f.aperture.width / 2, f.aperture.height / 2, filled = True, fillDensity = self.fillDensity ) self.toolpath.currentLayer.polygons.append( shapeplotter.ellipse( f.x, f.y, f.aperture.width / 2, f.aperture.height / 2, self.arcResolution, self.fillDensity ) ) # Plot all gerber traces for i, t in enumerate(self.gerberFile.traces): # Break if thread has been told to termiate if not self.alive: self.feedbackHandler.aborted() break progress = int( float(i) / float( len(self.gerberFile.traces) ) * 100 ) self.feedbackHandler.setStatus("Plotting strokes..." + str(progress) + "%") #t.printTrace() # Move is aperture open (pen down) type if t.aperture.isMacro: print "macro", f.aperture.macroName if t.aperture.apertureType == "C": # Using circular aperture if t.aperture.code == 12 or t.aperture.code == 13: print t.aperture.code if self.debug: print "aperture radius", t.aperture.radius, "mm" #self.shapePlot.plotMoveWithCircle( t.x1 + self.offsetX, t.y1 + self.offsetY, t.x2 + self.offsetX, t.y2 + self.offsetY, t.aperture.radius, self.fillDensity ) self.toolpath.currentLayer.polygons.append( shapeplotter.circleStroke( t.x1, t.y1, t.x2, t.y2, t.aperture.radius, self.arcResolution, self.fillDensity ) ) elif t.aperture.apertureType == "R": # Using rectangular aperture print "TODO - rectangle transition" # Isolation plot mode ( for routing ) elif self.pref_plotMode == 1: self.pref_rasterResolution = 20.0 # dots per mm self.feedbackHandler.setStatus("Getting limits...") width = int( (maxX - minX) * self.pref_rasterResolution ) height = int( (maxY - minY) * self.pref_rasterResolution ) self.feedbackHandler.setStatus("Primary grouping entities...") groups = self.groupTracesPrimary(self.gerberFile.flashes + self.gerberFile.traces) self.feedbackHandler.setStatus("Secondary grouping entities...") groups = self.groupTracesSecondary(groups) self.feedbackHandler.setStatus("Rastering / Vectorising...") self.surfaceFullRender = pygame.Surface( (width, height) ) #problem is background on layers, can we blit black only? self.surfaceFullRender.fill( [255, 255, 255] ) for ig, g in enumerate(groups): if not self.alive: self.feedbackHandler.aborted() break progress = int( float(ig) / float( len(groups) ) * 100 ) self.feedbackHandler.setStatus("Creating Paths..." + str(progress) + "%") self.plotToRaster(width, height, 0, 0, self.pref_rasterResolution, "test" + str(ig) + ".bmp", g) poly = shapeplotter.raster("test" + str(ig) + ".bmp", width, height) self.toolpath.currentLayer.polygons.append(poly) pygame.image.save(self.surfaceFullRender, "fullplot.bmp") #set_colorkey([255, 255, 255]) # transparency when blitting. use this in plotToRaser, to add to full plot surface TODO self.feedbackHandler.setStatus("Plotting...") # Smart fill mode (for pen) elif self.pref_plotMode == 2: self.pref_rasterResolution = 20.0 # dots per mm self.feedbackHandler.setStatus("Getting limits...") width = int( (maxX - minX) * self.pref_rasterResolution ) height = int( (maxY - minY) * self.pref_rasterResolution ) self.feedbackHandler.setStatus("Primary grouping entities...") groups = self.groupTracesPrimary(self.gerberFile.flashes + self.gerberFile.traces) self.feedbackHandler.setStatus("Secondary grouping entities...") groups = self.groupTracesSecondary(groups) self.feedbackHandler.setStatus("Rastering / Vectorising...") self.surfaceFullRender = pygame.Surface( (width, height) ) self.surfaceFullRender.fill( [255, 255, 255] ) for ig, g in enumerate(groups): if not self.alive: self.feedbackHandler.aborted() break progress = int( float(ig) / float( len(groups) ) * 100 ) self.feedbackHandler.setStatus("Creating Paths..." + str(progress) + "%") self.plotToRaster(width, height, 0, 0, self.pref_rasterResolution, "test" + str(ig) + ".bmp", g) poly = shapeplotter.raster("test" + str(ig) + ".bmp", width, height) self.toolpath.currentLayer.polygons.append(poly) polyFill = shapeplotter.fill(poly) self.toolpath.currentLayer.polygons.append(polyFill) self.feedbackHandler.setStatus("Plotting...") if self.alive: # Tell gui that plot is complete (redraw screen) self.feedbackHandler.plotComplete()
def run(self): self.alive = True self.feedbackHandler.setStatus("Opening file...") self.gerberFile = gerberlib.gerber(self.fileName) self.feedbackHandler.setStatus("Removing file offset...") # Remove file offset minX, minY, maxX, maxY = self.getFileLimitsXY() for e in self.gerberFile.flashes + self.gerberFile.traces: if e.type == gerberlib.FLASH: e.x -= minX e.y -= minY elif e.type == gerberlib.STROKE: e.x1 -= minX e.x2 -= minX e.y1 -= minY e.y2 -= minY # Fill plot mode ( for pen drawing ) # TODO - apply grouping to this plotter also to remove excess penup ops? if self.pref_plotMode == 0: # Plotting is pretty simple at the moment, plotter blindly follows gerber file and plots out each trace / flash individually. # Can be impoved by re-ordering drawing, and by combining connected traces into continual events / removing overlap # Plot all gerber flashes for i, f in enumerate(self.gerberFile.flashes): # Break if thread has been told to termiate if not self.alive: self.feedbackHandler.aborted() break progress = int( float(i) / float(len(self.gerberFile.flashes)) * 100) self.feedbackHandler.setStatus("Plotting flashes..." + str(progress) + "%") #f.printFlash() # Move is static flash type if f.aperture.isMacro: print "macro", f.aperture.macroName if f.aperture.apertureType == "C": # Using circular aperture if self.debug: print "aperture radius", radius, "mm" #self.shapePlot.plotCircle( f.x + self.offsetX, f.y + self.offsetY, f.aperture.radius, filled = True, fillDensity = self.fillDensity ) self.toolpath.currentLayer.polygons.append( shapeplotter.circle(f.x, f.y, f.aperture.radius, self.arcResolution, self.fillDensity)) elif f.aperture.apertureType == "R": # Using rectangular aperture #self.shapePlot.plotRectangle( f.x + self.offsetX, f.y + self.offsetY, f.aperture.width, f.aperture.height, self.fillDensity ) self.toolpath.currentLayer.polygons.append( shapeplotter.rectangle(f.x, f.y, f.aperture.width, f.aperture.height, self.fillDensity)) elif f.aperture.apertureType == "O": #self.shapePlot.plotEllipse( f.x + self.offsetX, f.y + self.offsetY, f.aperture.width / 2, f.aperture.height / 2, filled = True, fillDensity = self.fillDensity ) self.toolpath.currentLayer.polygons.append( shapeplotter.ellipse(f.x, f.y, f.aperture.width / 2, f.aperture.height / 2, self.arcResolution, self.fillDensity)) # Plot all gerber traces for i, t in enumerate(self.gerberFile.traces): # Break if thread has been told to termiate if not self.alive: self.feedbackHandler.aborted() break progress = int( float(i) / float(len(self.gerberFile.traces)) * 100) self.feedbackHandler.setStatus("Plotting strokes..." + str(progress) + "%") #t.printTrace() # Move is aperture open (pen down) type if t.aperture.isMacro: print "macro", f.aperture.macroName if t.aperture.apertureType == "C": # Using circular aperture if t.aperture.code == 12 or t.aperture.code == 13: print t.aperture.code if self.debug: print "aperture radius", t.aperture.radius, "mm" #self.shapePlot.plotMoveWithCircle( t.x1 + self.offsetX, t.y1 + self.offsetY, t.x2 + self.offsetX, t.y2 + self.offsetY, t.aperture.radius, self.fillDensity ) self.toolpath.currentLayer.polygons.append( shapeplotter.circleStroke(t.x1, t.y1, t.x2, t.y2, t.aperture.radius, self.arcResolution, self.fillDensity)) elif t.aperture.apertureType == "R": # Using rectangular aperture print "TODO - rectangle transition" # Isolation plot mode ( for routing ) elif self.pref_plotMode == 1: self.pref_rasterResolution = 20.0 # dots per mm self.feedbackHandler.setStatus("Getting limits...") width = int((maxX - minX) * self.pref_rasterResolution) height = int((maxY - minY) * self.pref_rasterResolution) self.feedbackHandler.setStatus("Primary grouping entities...") groups = self.groupTracesPrimary(self.gerberFile.flashes + self.gerberFile.traces) self.feedbackHandler.setStatus("Secondary grouping entities...") groups = self.groupTracesSecondary(groups) self.feedbackHandler.setStatus("Rastering / Vectorising...") self.surfaceFullRender = pygame.Surface( (width, height )) #problem is background on layers, can we blit black only? self.surfaceFullRender.fill([255, 255, 255]) for ig, g in enumerate(groups): if not self.alive: self.feedbackHandler.aborted() break progress = int(float(ig) / float(len(groups)) * 100) self.feedbackHandler.setStatus("Creating Paths..." + str(progress) + "%") self.plotToRaster(width, height, 0, 0, self.pref_rasterResolution, "test" + str(ig) + ".bmp", g) poly = shapeplotter.raster("test" + str(ig) + ".bmp", width, height) self.toolpath.currentLayer.polygons.append(poly) pygame.image.save(self.surfaceFullRender, "fullplot.bmp") #set_colorkey([255, 255, 255]) # transparency when blitting. use this in plotToRaser, to add to full plot surface TODO self.feedbackHandler.setStatus("Plotting...") # Smart fill mode (for pen) elif self.pref_plotMode == 2: self.pref_rasterResolution = 20.0 # dots per mm self.feedbackHandler.setStatus("Getting limits...") width = int((maxX - minX) * self.pref_rasterResolution) height = int((maxY - minY) * self.pref_rasterResolution) self.feedbackHandler.setStatus("Primary grouping entities...") groups = self.groupTracesPrimary(self.gerberFile.flashes + self.gerberFile.traces) self.feedbackHandler.setStatus("Secondary grouping entities...") groups = self.groupTracesSecondary(groups) self.feedbackHandler.setStatus("Rastering / Vectorising...") self.surfaceFullRender = pygame.Surface((width, height)) self.surfaceFullRender.fill([255, 255, 255]) for ig, g in enumerate(groups): if not self.alive: self.feedbackHandler.aborted() break progress = int(float(ig) / float(len(groups)) * 100) self.feedbackHandler.setStatus("Creating Paths..." + str(progress) + "%") self.plotToRaster(width, height, 0, 0, self.pref_rasterResolution, "test" + str(ig) + ".bmp", g) poly = shapeplotter.raster("test" + str(ig) + ".bmp", width, height) self.toolpath.currentLayer.polygons.append(poly) polyFill = shapeplotter.fill(poly) self.toolpath.currentLayer.polygons.append(polyFill) self.feedbackHandler.setStatus("Plotting...") if self.alive: # Tell gui that plot is complete (redraw screen) self.feedbackHandler.plotComplete()