summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/excellon.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2022-01-21 21:15:53 +0100
committerjaseg <git@jaseg.de>2022-01-21 21:15:53 +0100
commit606e41d4b7969c1f1d0a935aa1e957631e71cd39 (patch)
tree59a28438a8d38a8cb548407389ecdd2c7399b23a /gerbonara/gerber/excellon.py
parent125ef6af40307402f8c9854fae9e208573ed9d37 (diff)
downloadgerbonara-606e41d4b7969c1f1d0a935aa1e957631e71cd39.tar.gz
gerbonara-606e41d4b7969c1f1d0a935aa1e957631e71cd39.tar.bz2
gerbonara-606e41d4b7969c1f1d0a935aa1e957631e71cd39.zip
Layer merging WIP
Diffstat (limited to 'gerbonara/gerber/excellon.py')
-rwxr-xr-xgerbonara/gerber/excellon.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/gerbonara/gerber/excellon.py b/gerbonara/gerber/excellon.py
index 0900859..dc2ea86 100755
--- a/gerbonara/gerber/excellon.py
+++ b/gerbonara/gerber/excellon.py
@@ -19,6 +19,7 @@ import math
import operator
import warnings
import functools
+import dataclasses
from enum import Enum
from dataclasses import dataclass
from collections import Counter
@@ -105,10 +106,57 @@ class ExcellonFile(CamFile):
self.import_settings = import_settings
self.generator_hints = generator_hints or [] # This is a purely informational goodie from the parser. Use it as you wish.
+ def __bool__(self):
+ return bool(self.objects)
+
+ @property
+ def is_plated(self):
+ return all(obj.plated for obj in self.objects)
+
+ @property
+ def is_nonplated(self):
+ return all(obj.plated == False for obj in self.objects) # False, not None
+
+ @property
+ def is_plating_unknown(self):
+ return all(obj.plated is None for obj in self.objects) # False, not None
+
+ @property
+ def is_mixed_plating(self):
+ return len({obj.plated for obj in self.objects}) > 1
+
+ def append(self, obj_or_comment):
+ if isinstnace(obj_or_comment, str):
+ self.comments.append(obj_or_comment)
+ else:
+ self.objects.append(obj_or_comment)
+
+ def to_gerber(self):
+ apertures = {}
+ out = GerberFile()
+ out.comments = self.comments
+
+ for obj in self.objects:
+ if id(obj.tool) not in apertures:
+ apertures[id(obj.tool)] = CircleAperture(obj.tool.diameter)
+
+ out.objects.append(dataclasses.replace(obj, aperture=apertures[id(obj.tool)]))
+
+ out.apertures = list(apertures.values())
+
@property
def generator(self):
return self.generator_hints[0] if self.generator_hints else None
+ def merge(self, other):
+ if other is None:
+ return
+
+ self.objects += other.objects
+ self.comments += other.comments
+ self.generator_hints = None
+ self.import_settings = None
+
@classmethod
def open(kls, filename, plated=None, settings=None):
filename = Path(filename)