Commit d39f6cd9 authored by leonmuller's avatar leonmuller

Fixed up exporting taking into accoutn stroke, transposing and transforming....

Fixed up exporting taking into accoutn stroke, transposing and transforming. This was accomplushed by improving the method of determining the X-Y coordinates of an object that is to be rastered - however it is slower though if you can wait around 2-5 seconds I am sure you willl be fine.
parent 938e3cf7
...@@ -63,8 +63,8 @@ For the latest revision please visit https://github.com/TurnkeyTyranny/laser-gco ...@@ -63,8 +63,8 @@ For the latest revision please visit https://github.com/TurnkeyTyranny/laser-gco
<param name="feed" type="int" min="0" max="5000" _gui-text="Default Cut Feedrate:">300</param> <param name="feed" type="int" min="0" max="5000" _gui-text="Default Cut Feedrate:">300</param>
<param name="Mfeed" type="int" min="0" max="5000" _gui-text="Default Traversal Feedrate:">2000</param> <param name="Mfeed" type="int" min="0" max="5000" _gui-text="Default Traversal Feedrate:">2000</param>
<param name="laser" type="int" min="0" max="100" _gui-text="Default Laser Intensity (0-100%):">10</param> <param name="laser" type="int" min="0" max="100" _gui-text="Default Laser Intensity (0-100%):">10</param>
<param name="homebefore" type="boolean" _gui-text="Home X & Y Before:">true</param> <param name="homebefore" type="boolean" _gui-text="Home X and Y Before:">true</param>
<param name="homeafter" type="boolean" _gui-text="Home X & Y After:">false</param> <param name="homeafter" type="boolean" _gui-text="Home X and Y After:">false</param>
<param name="Xscale" type="float" precision="4" min="-1000" max="1000" _gui-text="Scale along X axis:">1</param> <param name="Xscale" type="float" precision="4" min="-1000" max="1000" _gui-text="Scale along X axis:">1</param>
<param name="Yscale" type="float" precision="4" min="-1000" max="1000" _gui-text="Scale along Y axis:">1</param> <param name="Yscale" type="float" precision="4" min="-1000" max="1000" _gui-text="Scale along Y axis:">1</param>
......
...@@ -915,6 +915,7 @@ class Gcode_tools(inkex.Effect): ...@@ -915,6 +915,7 @@ class Gcode_tools(inkex.Effect):
return pathsGroup return pathsGroup
else : else :
#Raster the results.
if(node.get("x") > 0): if(node.get("x") > 0):
tmp = self.getTmpPath() #OS tmp directory tmp = self.getTmpPath() #OS tmp directory
bgcol = "#ffffff" #White bgcol = "#ffffff" #White
...@@ -926,6 +927,7 @@ class Gcode_tools(inkex.Effect): ...@@ -926,6 +927,7 @@ class Gcode_tools(inkex.Effect):
f = p.stdout f = p.stdout
err = p.stderr err = p.stderr
#Fetch the image Data #Fetch the image Data
filename = "%stmpinkscapeexport.png" % (tmp) filename = "%stmpinkscapeexport.png" % (tmp)
im = Image.open(filename).convert('L') im = Image.open(filename).convert('L')
...@@ -943,44 +945,32 @@ class Gcode_tools(inkex.Effect): ...@@ -943,44 +945,32 @@ class Gcode_tools(inkex.Effect):
path['height'] = imageDataheight path['height'] = imageDataheight
#Fetch the size of the stroke on the object #A slow, but reliable way of getting correct coordinates since working with inkscape transpositions and transforms is a major pain in the ass.
strokeWidth = 0 command="inkscape -X --query-id=%s %s" % (node.get("id"),curfile)
style = node.get('style') p2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if style: return_code = p2.wait()
style = simplestyle.parseStyle(style) text = p2.communicate()[0]
if style.has_key('stroke'): x_position = float(text)
if style['stroke'] and style['stroke'] != 'none' and style['stroke'][0:3] != 'url': command="inkscape -Y --query-id=%s %s" % (node.get("id"),curfile)
rgb = simplestyle.parseColor(style['stroke']) p3 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
strokeWidth = float(style['stroke-width']) return_code = p3.wait()
text = p3.communicate()[0]
y_position = float(text)*-1+self.pageHeight
#Transform is needed from the layer
y = 0
x = 0
if (trans):
csp = [float(node.get("x")),float(node.get("y"))]
simpletransform.applyTransformToPoint(trans, csp )
x,y = csp
x = ((x-(strokeWidth/2)) * 1)
#Add the height in px from inkscape from the image, as its top is measured from the origin top left, though in inkscape the origin is bottom left so we need to begin scanning the px at the bottom of the image for our laser bed. #A slow, but reliable way of getting correct coordinates since working with inkscape transpositions and transforms is a major pain in the ass.
if(node.tag == SVG_IMAGE_TAG): #command="inkscape -S %s" % (curfile)
#Strokes on images in inkscape aren't shown, so don't account for them. #p4 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
y = ((float(node.get("y"))+float(node.get("height"))+float(trans[1][2]))*-1+self.pageHeight) #return_code = p4.wait()
elif(node.tag == SVG_TEXT_TAG): #text = p4.communicate()[0]
#The multiplier is a little fudging, raster may be out on the y coordinate by 0.5mm for very large rasters. Text doesn't seem to convert exactly.
y = ((float(node.get("y"))-(strokeWidth/2)+float(trans[1][2]))*-1+self.pageHeight)
y = y - ( y * 1.0063074911335007855200895586976 - y)
x = (float(node.get("x"))-(strokeWidth/2)+float(trans[0][2]) * 1)
x = x - ( x * 1.0063074911335007855200895586976 - x)
else:
y = ((y+(float(imageDataheight)/3)-(strokeWidth/2)+float(trans[1][2]))*-1+self.pageHeight)
#Text is y positioned from the top left.
#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'] = self.unitScale * float(str("%.5f") %(x)) path['x'] = self.unitScale * float(str("%.3f") %(x_position))
path['y'] = self.unitScale * float(str("%.5f") %(y)) path['y'] = self.unitScale * float(str("%.3f") %(y_position))
#Do not permit being < 0 #Do not permit being < 0
if(path['y'] < 0): if(path['y'] < 0):
......
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