From e93bc6bf40c8b4966a052186ce884f279a990300 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 11 Feb 2021 11:29:21 -0300 Subject: [PATCH] Fixed problems using layer suffixes containing non-ASCII chars --- CHANGELOG.md | 1 + kibot/layer.py | 15 +++++++++++++-- kibot/misc.py | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0044ddd4..e63890a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Extra data about drill marks in gerber files. - Problems using internal names for drill maps in gerb_drill output (#47). +- Problems using layer suffixes containing non-ASCII chars (i.e. UTF-8). ## [0.9.0] - 2021-01-04 diff --git a/kibot/layer.py b/kibot/layer.py index 62791d28..21ae1983 100644 --- a/kibot/layer.py +++ b/kibot/layer.py @@ -6,7 +6,7 @@ import pcbnew from .optionable import Optionable from .gs import GS -from .misc import KICAD_VERSION_5_99 +from .misc import KICAD_VERSION_5_99, W_NOTASCII from re import match from .error import (PlotError, KiPlotConfigurationError) from .macros import macros, document, output_class # noqa: F401 @@ -116,6 +116,14 @@ class Layer(Optionable): self.description = 'No description' if not self.suffix: self.suffix = self.layer.replace('.', '_') + self.clean_suffix() + + def clean_suffix(self): + filtered_suffix = ''.join(char for char in self.suffix if ord(char) < 128) + if filtered_suffix != self.suffix: + logger.warning(W_NOTASCII+'Only ASCII chars are allowed for layer suffixes ({}), using {}'. + format(self, filtered_suffix)) + self.suffix = filtered_suffix @property def id(self): @@ -215,6 +223,7 @@ class Layer(Optionable): layer.description = Layer.DEFAULT_LAYER_DESC.get(name) layer._get_layer_id_from_name() layer.fix_protel_ext() + layer.clean_suffix() return layer @staticmethod @@ -257,7 +266,9 @@ class Layer(Optionable): return self._id def __str__(self): - return "{} ({} '{}' {})".format(self.layer, self._id, self.description, self.suffix) + if hasattr(self, '_id'): + return "{} ({} '{}' {})".format(self.layer, self._id, self.description, self.suffix) + return "{} ('{}' {})".format(self.layer, self.description, self.suffix) for i in range(1, 30): diff --git a/kibot/misc.py b/kibot/misc.py index b3fffc61..4f9ccfc0 100644 --- a/kibot/misc.py +++ b/kibot/misc.py @@ -174,6 +174,7 @@ W_EXTNAME = '(W053) ' W_TIMEOUT = '(W054) ' W_MUSTBEINT = '(W055) ' W_NOOUTPUTS = '(W056) ' +W_NOTASCII = '(W057) ' class Rect(object):