diff options
author | jaseg <git@jaseg.de> | 2023-04-26 22:36:20 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2023-04-26 22:36:20 +0200 |
commit | 8409fbb90835c61bd675dc0070ea38ac671540f8 (patch) | |
tree | a253ed064dbf6597d8939c980ea585013e6b4b88 /gerbonara/rs274x.py | |
parent | 9f74fad6a238836339d158d388f538ef0eae61bc (diff) | |
download | gerbonara-8409fbb90835c61bd675dc0070ea38ac671540f8.tar.gz gerbonara-8409fbb90835c61bd675dc0070ea38ac671540f8.tar.bz2 gerbonara-8409fbb90835c61bd675dc0070ea38ac671540f8.zip |
Export flashes as svg <use> tags
Diffstat (limited to 'gerbonara/rs274x.py')
-rw-r--r-- | gerbonara/rs274x.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/gerbonara/rs274x.py b/gerbonara/rs274x.py index 01cdccf..fb70869 100644 --- a/gerbonara/rs274x.py +++ b/gerbonara/rs274x.py @@ -228,6 +228,26 @@ class GerberFile(CamFile): parser.parse(data, filename=filename) return obj + def dedup_apertures(self, settings=None): + settings = settings or FileSettings.defaults() + + defined_apertures = {} + ap_map = {} + for obj in self.objects: + if not hasattr(obj, 'aperture'): + continue + + if id(obj.aperture) in ap_map: + obj.aperture = ap_map[id(obj.aperture)] + + ap_def = obj.aperture.to_gerber(settings) + if ap_def in defined_apertures: + ap_map[id(obj.aperture)] = obj.aperture = defined_apertures[ap_def] + else: + ap_map[id(obj.aperture)] = defined_apertures[ap_def] = obj.aperture + + self.apertures = list(ap_map.values()) + def _generate_statements(self, settings, drop_comments=True): """ Export this file as Gerber code, yields one str per line. """ self.sync_apertures() @@ -265,7 +285,6 @@ class GerberFile(CamFile): defined_apertures = {} number = 10 for aperture in self.apertures: - if isinstance(aperture, apertures.ApertureMacroInstance): macro_def = am_stmt(aperture.rotated().macro) if macro_def not in processed_macros: |