allow using a string for the layer

Can't use it in gdsii, but no reason to forbit it in masque...
This commit is contained in:
Jan Petykiewicz 2020-05-17 14:11:47 -07:00
parent 247b31a9d6
commit 8302286a7a
4 changed files with 10 additions and 6 deletions

View File

@ -151,7 +151,7 @@ def dose2dtype(patterns: List[Pattern],
For each shape in each pattern, set shape.layer to the tuple For each shape in each pattern, set shape.layer to the tuple
(base_layer, datatype), where: (base_layer, datatype), where:
layer is chosen to be equal to the original shape.layer if it is an int, layer is chosen to be equal to the original shape.layer if it is an int,
or shape.layer[0] if it is a tuple or shape.layer[0] if it is a tuple. `str` layers raise a PatterError.
datatype is chosen arbitrarily, based on calcualted dose for each shape. datatype is chosen arbitrarily, based on calcualted dose for each shape.
Shapes with equal calcualted dose will have the same datatype. Shapes with equal calcualted dose will have the same datatype.
A list of doses is retured, providing a mapping between datatype A list of doses is retured, providing a mapping between datatype
@ -213,8 +213,10 @@ def dose2dtype(patterns: List[Pattern],
data_type = dose_vals_list.index(shape.dose * pat_dose) data_type = dose_vals_list.index(shape.dose * pat_dose)
if isinstance(shape.layer, int): if isinstance(shape.layer, int):
shape.layer = (shape.layer, data_type) shape.layer = (shape.layer, data_type)
else: elif isinstance(shape.layer, tuple):
shape.layer = (shape.layer[0], data_type) shape.layer = (shape.layer[0], data_type)
else:
raise PatternError(f'Invalid layer for gdsii: {shape.layer}')
new_pats[(pat_id, pat_dose)] = pat new_pats[(pat_id, pat_dose)] = pat
@ -377,12 +379,14 @@ def _mlayer2gds(mlayer: layer_t) -> Tuple[int, int]:
if isinstance(mlayer, int): if isinstance(mlayer, int):
layer = mlayer layer = mlayer
data_type = 0 data_type = 0
else: elif isinstance(mlayer, tuple):
layer = mlayer[0] layer = mlayer[0]
if len(mlayer) > 1: if len(mlayer) > 1:
data_type = mlayer[1] data_type = mlayer[1]
else: else:
data_type = 0 data_type = 0
else:
raise PatternError(f'Invalid layer for gdsii: {layer}. Note that gdsii layers cannot be strings.')
return layer, data_type return layer, data_type

View File

@ -55,7 +55,7 @@ class Label:
@property @property
def layer(self) -> layer_t: def layer(self) -> layer_t:
""" """
Layer number (int or tuple of ints) Layer number or name (int, tuple of ints, or string)
""" """
return self._layer return self._layer

View File

@ -174,7 +174,7 @@ class Shape(metaclass=ABCMeta):
@property @property
def layer(self) -> layer_t: def layer(self) -> layer_t:
""" """
Layer number (int or tuple of ints) Layer number or name (int, tuple of ints, or string)
""" """
return self._layer return self._layer

View File

@ -8,7 +8,7 @@ import numpy
# Type definitions # Type definitions
vector2 = Union[numpy.ndarray, Tuple[float, float], Sequence[float]] vector2 = Union[numpy.ndarray, Tuple[float, float], Sequence[float]]
layer_t = Union[int, Tuple[int, int]] layer_t = Union[int, Tuple[int, int], str]
def is_scalar(var: Any) -> bool: def is_scalar(var: Any) -> bool: