Commit 0a1582ec authored by leonmuller's avatar leonmuller

Updated method to determine XY positions of nodes, so query doesnt have to be...

Updated method to determine XY positions of nodes, so query doesnt have to be run for each individual node.
parent f6a1a159
...@@ -858,6 +858,7 @@ class Gcode_tools(inkex.Effect): ...@@ -858,6 +858,7 @@ class Gcode_tools(inkex.Effect):
### ###
################################################################################ ################################################################################
def effect_curve(self, selected): def effect_curve(self, selected):
selected = list(selected) selected = list(selected)
...@@ -868,7 +869,9 @@ class Gcode_tools(inkex.Effect): ...@@ -868,7 +869,9 @@ class Gcode_tools(inkex.Effect):
# Recursively compiles a list of paths that are decendant from the given node # Recursively compiles a list of paths that are decendant from the given node
self.skipped = 0 self.skipped = 0
def compile_paths(node, trans):
def compile_paths(parent, node, trans):
# Apply the object transform, along with the parent transformation # Apply the object transform, along with the parent transformation
mat = node.get('transform', None) mat = node.get('transform', None)
path = {} path = {}
...@@ -895,7 +898,7 @@ class Gcode_tools(inkex.Effect): ...@@ -895,7 +898,7 @@ class Gcode_tools(inkex.Effect):
# This node is a group of other nodes # This node is a group of other nodes
pathsGroup = [] pathsGroup = []
for child in node.iterchildren(): for child in node.iterchildren():
data = compile_paths(child, trans) data = compile_paths(parent, child, trans)
#inkex.errormsg(str(data)) #inkex.errormsg(str(data))
if type(data) is not list: if type(data) is not list:
pathsGroup.append(data.copy()) pathsGroup.append(data.copy())
...@@ -938,28 +941,36 @@ class Gcode_tools(inkex.Effect): ...@@ -938,28 +941,36 @@ class Gcode_tools(inkex.Effect):
#A slow, but reliable way of getting correct coordinates since working with inkscape transpositions and transforms is a major pain in the ass. #A slow, but reliable way of getting correct coordinates since working with inkscape transpositions and transforms is a major pain in the ass.
command="inkscape -X --query-id=%s %s" % (node.get("id"),curfile) #command="inkscape -X --query-id=%s %s" % (node.get("id"),curfile)
p2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #p2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return_code = p2.wait() #return_code = p2.wait()
text = p2.communicate()[0] #text = p2.communicate()[0]
x_position = float(text) #x_position = float(text)
command="inkscape -Y --query-id=%s %s" % (node.get("id"),curfile) #command="inkscape -Y --query-id=%s %s" % (node.get("id"),curfile)
p3 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #p3 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return_code = p3.wait() #return_code = p3.wait()
text = p3.communicate()[0] #text = p3.communicate()[0]
y_position = float(text)*-1+self.pageHeight #y_position = float(text)*-1+self.pageHeight
if not hasattr(parent, 'glob_nodePositions'):
#Get the XY position of all elements in the inkscape job.
command="inkscape -S %s" % (curfile)
p5 = subprocess.Popen(command, stdout=subprocess.PIPE)
dataString = str(p5.communicate()[0]).split('\r\n')
del dataString[-1]
elementList = dict((item.split(",",1)[0],item.split(",",1)[1]) for item in dataString)
parent.glob_nodePositions = elementList
#Lookup the xy coords for this node.
elementData = parent.glob_nodePositions[node.get("id")].split(',')
x_position = float(elementData[0])
y_position = float(elementData[1])*-1+self.pageHeight
#A slow, but reliable way of getting correct coordinates since working with inkscape transpositions and transforms is a major pain in the ass.
#command="inkscape -S %s" % (curfile)
#p4 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#return_code = p4.wait()
#text = p4.communicate()[0]
#Text is y positioned from the top left. #Text is y positioned from the top left.
if (self.options.origin == 'topleft'): if (self.options.origin == 'topleft'):
#Don't flip the y position. Since we're moving the origin from bottom left to top left. #Don't flip the y position. Since we're moving the origin from bottom left to top left.
y_position = float(text) y_position = float(elementData[1])
else: else:
#Very small loss of positioning due to conversion of the dpi in the exported image. #Very small loss of positioning due to conversion of the dpi in the exported image.
y_position -= imageDataheight/3 y_position -= imageDataheight/3
...@@ -1086,12 +1097,12 @@ class Gcode_tools(inkex.Effect): ...@@ -1086,12 +1097,12 @@ class Gcode_tools(inkex.Effect):
try: try:
newPath = compile_paths(node, trans).copy(); newPath = compile_paths(self, node, trans).copy();
pathList.append(newPath) pathList.append(newPath)
inkex.errormsg("Built gcode for "+str(node.get("id"))+" - will be cut as %s." % (newPath['type']) ) inkex.errormsg("Built gcode for "+str(node.get("id"))+" - will be cut as %s." % (newPath['type']) )
except: except:
messageOnce = True messageOnce = True
for objectData in compile_paths(node, trans): for objectData in compile_paths(self, node, trans):
#if (messageOnce): #if (messageOnce):
inkex.errormsg("Built gcode for group "+str(node.get("id"))+", item %s - will be cut as %s." % (objectData['id'], objectData['type']) ) inkex.errormsg("Built gcode for group "+str(node.get("id"))+", item %s - will be cut as %s." % (objectData['id'], objectData['type']) )
#messageOnce = False #messageOnce = False
...@@ -1166,12 +1177,12 @@ class Gcode_tools(inkex.Effect): ...@@ -1166,12 +1177,12 @@ class Gcode_tools(inkex.Effect):
trans = simpletransform.parseTransform("") trans = simpletransform.parseTransform("")
for node in selected: for node in selected:
try: try:
newPath = compile_paths(node, trans).copy(); newPath = compile_paths(self, node, trans).copy();
pathList.append(newPath) pathList.append(newPath)
inkex.errormsg("Built gcode for "+str(node.get("id"))+" - will be cut as %s." % (newPath['type']) ) inkex.errormsg("Built gcode for "+str(node.get("id"))+" - will be cut as %s." % (newPath['type']) )
except: except:
messageOnce = True messageOnce = True
for objectData in compile_paths(node, trans): for objectData in compile_paths(self, node, trans):
#if (messageOnce): #if (messageOnce):
inkex.errormsg("Built gcode for group "+str(node.get("id"))+", item %s - will be cut as %s." % (objectData['id'], objectData['type']) ) inkex.errormsg("Built gcode for group "+str(node.get("id"))+", item %s - will be cut as %s." % (objectData['id'], objectData['type']) )
#messageOnce = False #messageOnce = False
......
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