Commit f6a1a159 authored by leonmuller's avatar leonmuller

Added capability to export with origin as top left or bottom left- select from...

Added capability to export with origin as top left or bottom left- select from exporter plugin menu at the top
parent f964fa97
...@@ -57,9 +57,10 @@ Fixed up as many situations I could find that threw python error messages and re ...@@ -57,9 +57,10 @@ Fixed up as many situations I could find that threw python error messages and re
Changelog 2015-03-30 Changelog 2015-03-30
Accounts for strokes on objects. Conditional raster export as some items in inkscape are positioned strangely. Accounts for strokes on objects. Conditional raster export as some items in inkscape are positioned strangely.
Modified the way that X-Y coordinates are determined for a node. This allows objects that are on a layer that has been transposed
or transformed or if the objects themselves have to be correctly positioned in the gcode exported data. It's a little bit slower but Changelog 2015-04-1
much more reliable. This change only applies to the export of rasters. Need to get the 'positioning for all' functionality working as exporting many raster objects is painfully slow.
Updated script to export rasters with top left as the origin or bottom left.
""" """
### ###
...@@ -590,7 +591,11 @@ class Gcode_tools(inkex.Effect): ...@@ -590,7 +591,11 @@ class Gcode_tools(inkex.Effect):
m = [1, -1, 1, 1, -1, 1] m = [1, -1, 1, 1, -1, 1]
a = [0, 0, 0, 0, 0, 0] a = [0, 0, 0, 0, 0, 0]
a[1] += self.pageHeight #Invert the y axis only if the origin should be the bottom left.
if (self.options.origin == 'topleft'):
m = [1, 1, 1, 1, -1, 1]
else:
a[1] += self.pageHeight
#I think this is the end of generating the header stuff (adina, june 22 2010) #I think this is the end of generating the header stuff (adina, june 22 2010)
args = [] args = []
...@@ -621,11 +626,11 @@ class Gcode_tools(inkex.Effect): ...@@ -621,11 +626,11 @@ class Gcode_tools(inkex.Effect):
#90dpi = 1 / (90 / 25.4) #90dpi = 1 / (90 / 25.4)
gcode += '\n\n;Beginning of Raster Image '+str(curve['id'])+' pixel size: '+str(curve['width'])+'x'+str(curve['height'])+'\n' gcode += '\n\n;Beginning of Raster Image '+str(curve['id'])+' pixel size: '+str(curve['width'])+'x'+str(curve['height'])+'\n'
gcode += 'M649 S'+str(laserPower)+' B2 D0 R0.09406\n' gcode += 'M649 S'+str(laserPower)+' B2 D0 R0.09406\n'
gcode += 'G28\n'
#Do not remove these two lines, they're important. Will not raster correctly if feedrate is not set prior. #Do not remove these two lines, they're important. Will not raster correctly if feedrate is not set prior.
#Move fast to point, cut at correct speed. #Move fast to point, cut at correct speed.
gcode += 'G0 X'+str(curve['x'])+' Y'+str(curve['y'])+' F'+str(self.options.Mfeed)+'\n' if(cutFeed < self.options.Mfeed):
gcode += 'G0 X'+str(curve['x'])+' Y'+str(curve['y'])+' F'+str(self.options.Mfeed)+'\n'
gcode += 'G0 X'+str(curve['x'])+' Y'+str(curve['y'])+' '+cutFeed+'\n' gcode += 'G0 X'+str(curve['x'])+' Y'+str(curve['y'])+' '+cutFeed+'\n'
#def get_chunks(arr, chunk_size = 51): #def get_chunks(arr, chunk_size = 51):
...@@ -655,18 +660,17 @@ class Gcode_tools(inkex.Effect): ...@@ -655,18 +660,17 @@ class Gcode_tools(inkex.Effect):
return end return end
first = True first = True
#Flip the image left to right. #Flip the image top to bottom.
#row = curve['data'][::-1] row = curve['data'][::-1]
#Turnkey - 29/3/15 - No more flipping. #Turnkey - 29/3/15 - No more flipping.
row = curve['data'] #row = curve['data']
previousRight = 99999999999 previousRight = 99999999999
previousLeft = 0 previousLeft = 0
firstRow = True firstRow = True
for index, rowData in enumerate(row): for index, rowData in enumerate(row):
#print "Line "+str(index+1)+" ="
splitRight = 0 splitRight = 0
splitLeft = 0 splitLeft = 0
...@@ -687,16 +691,13 @@ class Gcode_tools(inkex.Effect): ...@@ -687,16 +691,13 @@ class Gcode_tools(inkex.Effect):
else: else:
splitRight = last_in_list(rowData) splitRight = last_in_list(rowData)
#print "Prior Left cut = "+str(splitLeft)+" Right Cut == "+str(splitRight)
else: else:
splitLeft = first_in_list(rowData) splitLeft = first_in_list(rowData)
splitRight = last_in_list(rowData) splitRight = last_in_list(rowData)
#Positive direction #Positive direction
if forward: if forward:
#print "Forward!"
#Split the right side. #Split the right side.
########################################### ###########################################
...@@ -705,9 +706,7 @@ class Gcode_tools(inkex.Effect): ...@@ -705,9 +706,7 @@ class Gcode_tools(inkex.Effect):
previousRight = splitRight previousRight = splitRight
#Negative direction #Negative direction
else: else:
#print "Backward!"
#Split the left side. #Split the left side.
########################################### ###########################################
...@@ -716,14 +715,11 @@ class Gcode_tools(inkex.Effect): ...@@ -716,14 +715,11 @@ class Gcode_tools(inkex.Effect):
previousLeft = splitLeft previousLeft = splitLeft
#Exception to the rule : Don't split the left of the first row. #Exception to the rule : Don't split the left of the first row.
if(firstRow): if(firstRow):
splitLeft = (previousLeft) splitLeft = (previousLeft)
firstRow = False firstRow = False
#print "After : Left cut = "+str(splitLeft)+" Right Cut == "+str(splitRight)
row2 = rowData[(splitLeft+1):(splitRight+1)] row2 = rowData[(splitLeft+1):(splitRight+1)]
if not forward: if not forward:
...@@ -769,7 +765,7 @@ class Gcode_tools(inkex.Effect): ...@@ -769,7 +765,7 @@ class Gcode_tools(inkex.Effect):
#Setup our pulse per millimetre option, if applicable #Setup our pulse per millimetre option, if applicable
#B: laser firing mode (0 = continuous, 1 = pulsed, 2 = raster) #B: laser firing mode (0 = continuous, 1 = pulsed, 2 = raster)
if (altppm): if (altppm):
# Use the "alternative" ppm - L60000 is 60ms # Use the "alternative" ppm - L60000 is 60us
ppmValue = "L60000 P%.2f B1 D0" % altppm ppmValue = "L60000 P%.2f B1 D0" % altppm
else: else:
#Set the laser firing mode to continuous. #Set the laser firing mode to continuous.
...@@ -801,21 +797,11 @@ class Gcode_tools(inkex.Effect): ...@@ -801,21 +797,11 @@ class Gcode_tools(inkex.Effect):
#G01 : Move with the laser turned on to a new point #G01 : Move with the laser turned on to a new point
elif s[1] == 'line': elif s[1] == 'line':
#No longer needed because G01, G02 and G03 will be forced in marlin to automatically fire the laser.
#If the laser was turned off, turn it back on.
#if lg == "G00":
# gcode += LASER_ON + "\n"
gcode += "G01 " + "S%.2f " % laserPower + self.make_args(si[0]) + " %s " % cutFeed + "%s" % ppmValue + "\n" gcode += "G01 " + "S%.2f " % laserPower + self.make_args(si[0]) + " %s " % cutFeed + "%s" % ppmValue + "\n"
lg = 'G01' lg = 'G01'
#G02 and G03 : Move in an arc with the laser turned on. #G02 and G03 : Move in an arc with the laser turned on.
elif s[1] == 'arc': elif s[1] == 'arc':
#No longer needed because G01, G02 and G03 will be forced in marlin to automatically fire the laser.
#If the laser was turned off, turn it back on.
#if lg == "G00":
# gcode += LASER_ON + "\n"
dx = s[2][0]-s[0][0] dx = s[2][0]-s[0][0]
dy = s[2][1]-s[0][1] dy = s[2][1]-s[0][1]
if abs((dx**2 + dy**2)*self.options.Xscale) > self.options.min_arc_radius: if abs((dx**2 + dy**2)*self.options.Xscale) > self.options.min_arc_radius:
...@@ -933,7 +919,10 @@ class Gcode_tools(inkex.Effect): ...@@ -933,7 +919,10 @@ class Gcode_tools(inkex.Effect):
#Fetch the image Data #Fetch the image Data
filename = "%stmpinkscapeexport.png" % (tmp) filename = "%stmpinkscapeexport.png" % (tmp)
im = Image.open(filename).convert('L') if (self.options.origin == 'topleft'):
im = Image.open(filename).transpose(Image.FLIP_TOP_BOTTOM).convert('L')
else:
im = Image.open(filename).convert('L')
img = ImageOps.invert(im) img = ImageOps.invert(im)
#Get the image size #Get the image size
...@@ -968,8 +957,13 @@ class Gcode_tools(inkex.Effect): ...@@ -968,8 +957,13 @@ class Gcode_tools(inkex.Effect):
#text = p4.communicate()[0] #text = p4.communicate()[0]
#Text is y positioned from the top left. #Text is y positioned from the top left.
#Very small loss of positioning due to conversion of the dpi in the exported image. if (self.options.origin == 'topleft'):
y_position -= imageDataheight/3 #Don't flip the y position. Since we're moving the origin from bottom left to top left.
y_position = float(text)
else:
#Very small loss of positioning due to conversion of the dpi in the exported image.
y_position -= imageDataheight/3
#Convert from pixels to mm #Convert from pixels to mm
path['x'] = float(str("%.3f") %(self.unitScale * x_position)) path['x'] = float(str("%.3f") %(self.unitScale * x_position))
...@@ -1191,20 +1185,6 @@ class Gcode_tools(inkex.Effect): ...@@ -1191,20 +1185,6 @@ class Gcode_tools(inkex.Effect):
curve = self.parse_curve(objectData) curve = self.parse_curve(objectData)
header_data = ""
#Turnkey : Always output the layer header for information.
if (len(layers) > 0):
header_data += LASER_OFF+"\n"
size = 60
header_data += ";(%s)\n" % ("*"*size)
header_data += (";(***** Layer: %%-%ds *****)\n" % (size-19)) % (originalLayerName)
header_data += (";(***** Laser Power: %%-%ds *****)\n" % (size-25)) % (laserPower)
header_data += (";(***** Feed Rate: %%-%ds *****)\n" % (size-23)) % (altfeed)
if(altppm):
header_data += (";(***** Pulse Rate: %%-%ds *****)\n" % (size-24)) % (altppm)
header_data += ";(%s)\n" % ("*"*size)
header_data += ";(MSG,Starting layer '%s')\n\n" % originalLayerName
#Determind the power of the laser that this layer should be cut at. #Determind the power of the laser that this layer should be cut at.
#If the layer is not named as an integer value then default to the laser intensity set at the export settings. #If the layer is not named as an integer value then default to the laser intensity set at the export settings.
#Fetch the laser power from the export dialog box. #Fetch the laser power from the export dialog box.
...@@ -1224,6 +1204,20 @@ class Gcode_tools(inkex.Effect): ...@@ -1224,6 +1204,20 @@ class Gcode_tools(inkex.Effect):
if (self.options.mainboard == 'smoothie'): if (self.options.mainboard == 'smoothie'):
laserPower = float(laserPower) / 100 laserPower = float(laserPower) / 100
header_data = ""
#Turnkey : Always output the layer header for information.
if (len(layers) > 0):
header_data += LASER_OFF+"\n"
size = 60
header_data += ";(%s)\n" % ("*"*size)
header_data += (";(***** Layer: %%-%ds *****)\n" % (size-19)) % (originalLayerName)
header_data += (";(***** Laser Power: %%-%ds *****)\n" % (size-25)) % (laserPower)
header_data += (";(***** Feed Rate: %%-%ds *****)\n" % (size-23)) % (altfeed)
if(altppm):
header_data += (";(***** Pulse Rate: %%-%ds *****)\n" % (size-24)) % (altppm)
header_data += ";(%s)\n" % ("*"*size)
header_data += ";(MSG,Starting layer '%s')\n\n" % originalLayerName
#Generate the GCode for this layer #Generate the GCode for this layer
if (curve['type'] == "vector"): if (curve['type'] == "vector"):
#Should the curves be drawn in inkscape? #Should the curves be drawn in inkscape?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment