diff options
author | jaseg <git@jaseg.de> | 2023-03-24 00:12:50 +0100 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2023-04-10 23:57:15 +0200 |
commit | ec0ecdeb68431485e7f86cfd6e5a3bbdffd93bfb (patch) | |
tree | 480b152a61ca875e6ddc0e1b91e4d22df8b234d3 /gerbonara/excellon.py | |
parent | 900de13d8c84a76b457c6973aed4aaf069523d6d (diff) | |
download | gerbonara-ec0ecdeb68431485e7f86cfd6e5a3bbdffd93bfb.tar.gz gerbonara-ec0ecdeb68431485e7f86cfd6e5a3bbdffd93bfb.tar.bz2 gerbonara-ec0ecdeb68431485e7f86cfd6e5a3bbdffd93bfb.zip |
Dedup both Excellon and Gerber tools during write
Diffstat (limited to 'gerbonara/excellon.py')
-rwxr-xr-x | gerbonara/excellon.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/gerbonara/excellon.py b/gerbonara/excellon.py index 657012b..fbbeb50 100755 --- a/gerbonara/excellon.py +++ b/gerbonara/excellon.py @@ -359,25 +359,34 @@ class ExcellonFile(CamFile): # Build tool index tool_map = { id(obj.tool): obj.tool for obj in self.objects } tools = sorted(tool_map.items(), key=lambda id_tool: (id_tool[1].plated, id_tool[1].diameter)) - tools = { tool_id: index for index, (tool_id, _tool) in enumerate(tools, start=1) } - # FIXME dedup tools mixed_plating = (len({ tool.plated for tool in tool_map.values() }) > 1) if mixed_plating: warnings.warn('Multiple plating values in same file. Will use non-standard Altium comment syntax to indicate hole plating.') - if tools and max(tools.values()) >= 100: - warnings.warn('More than 99 tools defined. Some programs may not like three-digit tool indices.', SyntaxWarning) + defined_tools = {} + tool_indices = {} + index = 1 + for tool_id, tool in tools: + xnc = tool.to_xnc(settings) + if (tool.plated, xnc) in defined_tools: + tool_indices[tool_id] = defined_tools[(tool.plated, xnc)] - for tool_id, index in tools.items(): - tool = tool_map[tool_id] - if mixed_plating: - yield ';TYPE=PLATED' if tool.plated else ';TYPE=NON_PLATED' - yield f'T{index:02d}' + tool.to_xnc(settings) + else: + if mixed_plating: + yield ';TYPE=PLATED' if tool.plated else ';TYPE=NON_PLATED' + + yield f'T{index:02d}' + xnc + + tool_indices[tool_id] = defined_tools[(tool.plated, xnc)] = index + index += 1 + + if index >= 100: + warnings.warn('More than 99 tools defined. Some programs may not like three-digit tool indices.', SyntaxWarning) yield '%' - ctx = ExcellonContext(settings, tools) + ctx = ExcellonContext(settings, tool_indices) # Export objects for obj in self.objects: |