From ec0ecdeb68431485e7f86cfd6e5a3bbdffd93bfb Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 24 Mar 2023 00:12:50 +0100 Subject: Dedup both Excellon and Gerber tools during write --- gerbonara/rs274x.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'gerbonara/rs274x.py') 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) -- cgit