summaryrefslogtreecommitdiff
path: root/gerbonara/rs274x.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-03-31 16:31:44 +0200
committerjaseg <git@jaseg.de>2023-04-10 23:57:15 +0200
commit02954407703430dcefba0b165360d201fe8e205c (patch)
treee103a7df869064f8d1d4b36b4311f4aee393f12a /gerbonara/rs274x.py
parent800827b2c575c31f1449ce9d690d158c7bb2f497 (diff)
downloadgerbonara-02954407703430dcefba0b165360d201fe8e205c.tar.gz
gerbonara-02954407703430dcefba0b165360d201fe8e205c.tar.bz2
gerbonara-02954407703430dcefba0b165360d201fe8e205c.zip
Improve layer stack handling
Diffstat (limited to 'gerbonara/rs274x.py')
-rw-r--r--gerbonara/rs274x.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/gerbonara/rs274x.py b/gerbonara/rs274x.py
index 5956b53..5ef93dd 100644
--- a/gerbonara/rs274x.py
+++ b/gerbonara/rs274x.py
@@ -73,7 +73,7 @@ class GerberFile(CamFile):
self.apertures = [] # FIXME get rid of this? apertures are already in the objects.
self.file_attrs = file_attrs or {}
- def to_excellon(self, plated=None):
+ def to_excellon(self, plated=None, errors='raise'):
""" Convert this excellon file into a :py:class:`~.excellon.ExcellonFile`. This will convert interpolated lines
into slots, and circular aperture flashes into holes. Other features such as ``G36`` polygons or flashes with
non-circular apertures will result in a :py:obj:`ValueError`. You can, of course, programmatically remove such
@@ -83,7 +83,15 @@ class GerberFile(CamFile):
for obj in self.objects:
if not (isinstance(obj, go.Line) or isinstance(obj, go.Arc) or isinstance(obj, go.Flash)) or \
not isinstance(obj.aperture, apertures.CircleAperture):
- raise ValueError(f'Cannot convert {obj} to excellon!')
+ if errors == 'raise':
+ raise ValueError(f'Cannot convert {obj} to excellon.')
+ elif errors == 'warn':
+ warnings.warn(f'Gerber to Excellon conversion: Cannot convert {obj} to excellon.')
+ continue
+ elif errors == 'ignore':
+ continue
+ else:
+ raise ValueError('Invalid "errors" parameter. Allowed values: "raise", "warn" or "ignore".')
if not (new_tool := new_tools.get(id(obj.aperture))):
# TODO plating?
@@ -92,9 +100,9 @@ class GerberFile(CamFile):
return ExcellonFile(objects=new_objs, comments=self.comments)
- def to_gerber(self):
+ def to_gerber(self, errors='raise'):
""" Counterpart to :py:meth:`~.excellon.ExcellonFile.to_gerber`. Does nothing and returns :py:obj:`self`. """
- return
+ return self
def merge(self, other, mode='above', keep_settings=False):
""" Merge ``other`` into ``self``, i.e. add all objects that are in ``other`` to ``self``. This resets
@@ -110,6 +118,8 @@ class GerberFile(CamFile):
if other is None:
return
+ other = other.to_gerber()
+
if not keep_settings:
self.import_settings = None
self.comments += other.comments