add subpattern_t type (generalizattion of SubPattern and GridRepetition)

lethe/HEAD
Jan Petykiewicz 4 years ago
parent 6b09fc0c20
commit ee8f015172

@ -31,7 +31,7 @@ import pathlib
from .error import PatternError, PatternLockedError from .error import PatternError, PatternLockedError
from .shapes import Shape from .shapes import Shape
from .label import Label from .label import Label
from .subpattern import SubPattern from .subpattern import SubPattern, subpattern_t
from .repetition import GridRepetition from .repetition import GridRepetition
from .pattern import Pattern from .pattern import Pattern

@ -18,7 +18,7 @@ import pathlib
import gzip import gzip
from .utils import mangle_name, make_dose_table from .utils import mangle_name, make_dose_table
from .. import Pattern, SubPattern, GridRepetition, PatternError, Label, Shape from .. import Pattern, SubPattern, GridRepetition, PatternError, Label, Shape, subpattern_t
from ..shapes import Polygon, Path from ..shapes import Polygon, Path
from ..utils import rotation_matrix_2d, get_bit, set_bit, vector2, is_scalar, layer_t from ..utils import rotation_matrix_2d, get_bit, set_bit, vector2, is_scalar, layer_t
from ..utils import remove_colinear_vertices, normalize_mirror from ..utils import remove_colinear_vertices, normalize_mirror
@ -467,7 +467,7 @@ def _aref_to_gridrep(element: gdsii.elements.ARef) -> GridRepetition:
return gridrep return gridrep
def _subpatterns_to_refs(subpatterns: List[Union[SubPattern, GridRepetition]] def _subpatterns_to_refs(subpatterns: List[subpattern_t]
) -> List[Union[gdsii.elements.ARef, gdsii.elements.SRef]]: ) -> List[Union[gdsii.elements.ARef, gdsii.elements.SRef]]:
refs = [] refs = []
for subpat in subpatterns: for subpat in subpatterns:

@ -13,7 +13,7 @@ import numpy
from numpy import inf from numpy import inf
# .visualize imports matplotlib and matplotlib.collections # .visualize imports matplotlib and matplotlib.collections
from .subpattern import SubPattern from .subpattern import SubPattern, subpattern_t
from .repetition import GridRepetition from .repetition import GridRepetition
from .shapes import Shape, Polygon from .shapes import Shape, Polygon
from .label import Label from .label import Label
@ -40,7 +40,7 @@ class Pattern:
labels: List[Label] labels: List[Label]
""" List of all labels in this Pattern. """ """ List of all labels in this Pattern. """
subpatterns: List[Union[SubPattern, GridRepetition]] subpatterns: List[subpattern_t]
""" List of all objects referencing other patterns in this Pattern. """ List of all objects referencing other patterns in this Pattern.
Examples are SubPattern (gdsii "instances") or GridRepetition (gdsii "arrays") Examples are SubPattern (gdsii "instances") or GridRepetition (gdsii "arrays")
Multiple objects in this list may reference the same Pattern object Multiple objects in this list may reference the same Pattern object
@ -57,7 +57,7 @@ class Pattern:
name: str = '', name: str = '',
shapes: Sequence[Shape] = (), shapes: Sequence[Shape] = (),
labels: Sequence[Label] = (), labels: Sequence[Label] = (),
subpatterns: Sequence[Union[SubPattern, GridRepetition]] = (), subpatterns: Sequence[subpattern_t] = (),
locked: bool = False, locked: bool = False,
): ):
""" """
@ -130,7 +130,7 @@ class Pattern:
def subset(self, def subset(self,
shapes_func: Callable[[Shape], bool] = None, shapes_func: Callable[[Shape], bool] = None,
labels_func: Callable[[Label], bool] = None, labels_func: Callable[[Label], bool] = None,
subpatterns_func: Callable[[Union[SubPattern, GridRepetition]], bool] = None, subpatterns_func: Callable[[subpattern_t], bool] = None,
recursive: bool = False, recursive: bool = False,
) -> 'Pattern': ) -> 'Pattern':
""" """

@ -11,6 +11,8 @@ from numpy import pi
from .error import PatternError, PatternLockedError from .error import PatternError, PatternLockedError
from .utils import is_scalar, rotation_matrix_2d, vector2 from .utils import is_scalar, rotation_matrix_2d, vector2
from .repetition import GridRepetition
if TYPE_CHECKING: if TYPE_CHECKING:
from . import Pattern from . import Pattern
@ -348,3 +350,6 @@ class SubPattern:
dose = f' d{self.dose:g}' if self.dose != 1 else '' dose = f' d{self.dose:g}' if self.dose != 1 else ''
locked = ' L' if self.locked else '' locked = ' L' if self.locked else ''
return f'<SubPattern "{name}" at {self.offset}{rotation}{scale}{mirrored}{dose}{locked}>' return f'<SubPattern "{name}" at {self.offset}{rotation}{scale}{mirrored}{dose}{locked}>'
subpattern_t = Union[SubPattern, GridRepetition]

Loading…
Cancel
Save