summaryrefslogtreecommitdiff
path: root/gerbonara/rs274x.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-03-24 00:12:50 +0100
committerjaseg <git@jaseg.de>2023-04-10 23:57:15 +0200
commitec0ecdeb68431485e7f86cfd6e5a3bbdffd93bfb (patch)
tree480b152a61ca875e6ddc0e1b91e4d22df8b234d3 /gerbonara/rs274x.py
parent900de13d8c84a76b457c6973aed4aaf069523d6d (diff)
downloadgerbonara-ec0ecdeb68431485e7f86cfd6e5a3bbdffd93bfb.tar.gz
gerbonara-ec0ecdeb68431485e7f86cfd6e5a3bbdffd93bfb.tar.bz2
gerbonara-ec0ecdeb68431485e7f86cfd6e5a3bbdffd93bfb.zip
Dedup both Excellon and Gerber tools during write
Diffstat (limited to 'gerbonara/rs274x.py')
-rw-r--r--gerbonara/rs274x.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/gerbonara/rs274x.py b/gerbonara/rs274x.py
index 0c50991..5956b53 100644
--- a/gerbonara/rs274x.py
+++ b/gerbonara/rs274x.py
@@ -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)