Fixed problems using layer suffixes containing non-ASCII chars

This commit is contained in:
Salvador E. Tropea 2021-02-11 11:29:21 -03:00
parent 3ed25cc5ff
commit e93bc6bf40
3 changed files with 15 additions and 2 deletions

View File

@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Extra data about drill marks in gerber files. - Extra data about drill marks in gerber files.
- Problems using internal names for drill maps in gerb_drill output (#47). - 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 ## [0.9.0] - 2021-01-04

View File

@ -6,7 +6,7 @@
import pcbnew import pcbnew
from .optionable import Optionable from .optionable import Optionable
from .gs import GS 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 re import match
from .error import (PlotError, KiPlotConfigurationError) from .error import (PlotError, KiPlotConfigurationError)
from .macros import macros, document, output_class # noqa: F401 from .macros import macros, document, output_class # noqa: F401
@ -116,6 +116,14 @@ class Layer(Optionable):
self.description = 'No description' self.description = 'No description'
if not self.suffix: if not self.suffix:
self.suffix = self.layer.replace('.', '_') 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 @property
def id(self): def id(self):
@ -215,6 +223,7 @@ class Layer(Optionable):
layer.description = Layer.DEFAULT_LAYER_DESC.get(name) layer.description = Layer.DEFAULT_LAYER_DESC.get(name)
layer._get_layer_id_from_name() layer._get_layer_id_from_name()
layer.fix_protel_ext() layer.fix_protel_ext()
layer.clean_suffix()
return layer return layer
@staticmethod @staticmethod
@ -257,7 +266,9 @@ class Layer(Optionable):
return self._id return self._id
def __str__(self): def __str__(self):
if hasattr(self, '_id'):
return "{} ({} '{}' {})".format(self.layer, self._id, self.description, self.suffix) return "{} ({} '{}' {})".format(self.layer, self._id, self.description, self.suffix)
return "{} ('{}' {})".format(self.layer, self.description, self.suffix)
for i in range(1, 30): for i in range(1, 30):

View File

@ -174,6 +174,7 @@ W_EXTNAME = '(W053) '
W_TIMEOUT = '(W054) ' W_TIMEOUT = '(W054) '
W_MUSTBEINT = '(W055) ' W_MUSTBEINT = '(W055) '
W_NOOUTPUTS = '(W056) ' W_NOOUTPUTS = '(W056) '
W_NOTASCII = '(W057) '
class Rect(object): class Rect(object):