From a35a422bcce0c8579bf7b282692db6a9de607bc8 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 15 Feb 2016 23:40:08 +0200 Subject: [PATCH 1/2] This is a implementation of the the sorting of the tools found in Excellon file done in Python language and independent of the UI. There is no need to revert the previous solution as that one will make the sorting visible in GUI. --- camlib.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/camlib.py b/camlib.py index 7e77d3a9..62ac63fd 100644 --- a/camlib.py +++ b/camlib.py @@ -55,6 +55,8 @@ from svgparse import * import logging +import operator + log = logging.getLogger('base2') log.setLevel(logging.DEBUG) # log.setLevel(logging.WARNING) @@ -2708,12 +2710,18 @@ class CNCjob(Geometry): log.debug("Creating CNC Job from Excellon...") # Tools + + #sort the tools list by the second item in tuple (here we have a dict with diameter of the tool) + #so we actually are sorting the tools by diameter + sorted_tools = sorted(exobj.tools.items(), key = operator.itemgetter(1)) if tools == "all": - tools = [tool for tool in exobj.tools] + tools = str([i[0] for i in sorted_tools]) #we get a string of ordered tools + log.debug("Tools 'all' and sorted are: %s" % str(tools)) else: - tools = [x.strip() for x in tools.split(",")] - tools = filter(lambda i: i in exobj.tools, tools) - log.debug("Tools are: %s" % str(tools)) + selected_tools = [x.strip() for x in tools.split(",")] #we strip spaces and also separate the tools by ',' + selected_tools = filter(lambda i: i in selected_tools, selected_tools) + tools = [i for i,j in sorted_tools for k in selected_tools if i == k] #create a list of tools from the sorted_tools list only if the tools is in the selected tools + log.debug("Tools selected and sorted are: %s" % str(tools)) # Points (Group by tool) points = {} From cfa078a1e5e99fc779a4908bf9e90fde34f4b977 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 15 Feb 2016 22:35:22 +0000 Subject: [PATCH 2/2] camlib.py (edited a comment) edited online with Bitbucket --- camlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/camlib.py b/camlib.py index 62ac63fd..325d1205 100644 --- a/camlib.py +++ b/camlib.py @@ -2720,7 +2720,7 @@ class CNCjob(Geometry): else: selected_tools = [x.strip() for x in tools.split(",")] #we strip spaces and also separate the tools by ',' selected_tools = filter(lambda i: i in selected_tools, selected_tools) - tools = [i for i,j in sorted_tools for k in selected_tools if i == k] #create a list of tools from the sorted_tools list only if the tools is in the selected tools + tools = [i for i,j in sorted_tools for k in selected_tools if i == k] #create a sorted list of selected tools from the sorted_tools list log.debug("Tools selected and sorted are: %s" % str(tools)) # Points (Group by tool)