Dedup both Excellon and Gerber tools during write
This commit is contained in:
parent
900de13d8c
commit
ec0ecdeb68
2 changed files with 30 additions and 13 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -247,7 +247,9 @@ class GerberFile(CamFile):
|
|||
|
||||
processed_macros = set()
|
||||
aperture_map = {}
|
||||
for number, aperture in enumerate(self.apertures, start=10):
|
||||
defined_apertures = {}
|
||||
number = 10
|
||||
for aperture in self.apertures:
|
||||
|
||||
if isinstance(aperture, apertures.ApertureMacroInstance):
|
||||
macro_def = am_stmt(aperture._rotated().macro)
|
||||
|
|
@ -255,9 +257,15 @@ class GerberFile(CamFile):
|
|||
processed_macros.add(macro_def)
|
||||
yield macro_def
|
||||
|
||||
yield f'%ADD{number}{aperture.to_gerber(settings)}*%'
|
||||
ap_def = aperture.to_gerber(settings)
|
||||
if ap_def in defined_apertures:
|
||||
aperture_map[id(aperture)] = defined_apertures[ap_def]
|
||||
|
||||
aperture_map[id(aperture)] = number
|
||||
else:
|
||||
yield f'%ADD{number}{ap_def}*%'
|
||||
defined_apertures[ap_def] = number
|
||||
aperture_map[id(aperture)] = number
|
||||
number += 1
|
||||
|
||||
def warn(msg, kls=SyntaxWarning):
|
||||
warnings.warn(msg, kls)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue