Example #1
0
def check(device: Device, joined=False, blocking=True):
    ''' Shows the device layout.

        If run by terminal, blocks script until window is closed.

        Parameters
        ----------
            device : phidl.Device

            joined : boolean (optional, default False)

                if true, returns a flattened/joined version of device

    '''
    set_quickplot_options(blocking=blocking)

    if joined:

        cell = Device()
        cell.absorb(cell << device)
        cell.flatten()
        qp(join(cell))

    else:

        qp(device)
Example #2
0
def add_utility_cell(cell,align_scale=[0.25,0.5,1],position=['top','left']):

    align_mark=alignment_marks_4layers(scale=align_scale)

    test_cell=resistivity_test_cell()

    align_via=Device('Align_Via')

    maskname_cell=mask_names()

    align_via.add_array(
        align_TE_on_via(),
        rows=3,
        columns=1,
        spacing=(0,350))

    align_via.flatten()

    g=Group([align_via,align_mark,test_cell])

    g.distribute(direction='x',spacing=100)

    g.align(alignment='y')

    g.move(origin=(g.center[0],g.ymax),
        destination=(cell.center[0],cell.ymax-300))

    maskname_cell.move(
        origin=(maskname_cell.x,maskname_cell.ymin),
        destination=(g.x,test_cell.ymax+150))

    utility_cell=Device(name="UtilityCell")

    if isinstance(position,str):

        position=[position]

    if 'top' in position:

        utility_cell<<align_mark
        utility_cell<<align_via
        utility_cell<<test_cell
        utility_cell<<maskname_cell

    if 'left' in position:

        t2=utility_cell<<align_mark
        t3=utility_cell<<align_via
        g=Group(t2,t3)

        g.rotate(angle=90,center=(t2.xmin,t2.ymin))

        g.move(origin=(t2.xmin,t2.center[1]),\
            destination=(cell.xmin,cell.center[1]))

    cell<<utility_cell
Example #3
0
    def draw(self):
        ''' Generates layout cell based on current parameters.

        'top' and 'bottom' ports are included in the cell.

        Returns
        -------
        cell : phidl.Device.
        '''

        unitcell = self._draw_unit_cell()

        cell = Device(self.name)

        cell.name = self.name

        cell.add_array(unitcell,columns=self.n,rows=1,\
            spacing=(self.pitch*2,0))

        cell.flatten()

        totx = self.pitch * (self.n * 2 + 1) - self.pitch * (1 - self.coverage)

        midx = totx / 2

        finger_dist=Point(self.pitch*1,\
        self.length+self.y_offset)

        cell = join(cell)

        cell.name = self.name

        cell.add_port(Port(name='bottom',\
        midpoint=(self.origin+\
        Point(midx,0)).coord,\
        width=totx,
        orientation=-90))

        cell.add_port(Port(name='top',\
        midpoint=(self.origin+\
        Point(midx,self.length+self.y_offset)).coord,\
        width=totx,
        orientation=90))

        del unitcell

        return cell
Example #4
0
def text(text='abcd', size=10, justify='left', layer=0, font="DEPLOF"):
    """ Creates geometries of text

    Parameters
    ----------
    text : str
        Text string to be written.
    size : int or float
        Size of the text
    justify : {'left', 'right', 'center'}
        Justification of the text.
    layer : int, array-like[2], or set
        Specific layer(s) to put polygon geometry on.
    font: str
        Font face to use. Default DEPLOF does not require additional libraries, otherwise
        freetype will be used to load fonts. Font can be given either by name (e.g. "Times New Roman"),
        or by file path. OTF or TTF fonts are supported.

    Returns
    -------
    t : Device
        A Device containing the text geometry.
    """
    t = Device('text')
    xoffset = 0
    yoffset = 0

    face = font
    if face == "DEPLOF":
        scaling = size / 1000

        for line in text.split('\n'):
            l = Device(name='textline')
            for c in line:
                ascii_val = ord(c)
                if c == ' ':
                    xoffset += 500 * scaling
                elif (33 <= ascii_val <= 126) or (ascii_val == 181):
                    for poly in _glyph[ascii_val]:
                        xpts = np.array(poly)[:, 0] * scaling
                        ypts = np.array(poly)[:, 1] * scaling
                        l.add_polygon([xpts + xoffset, ypts + yoffset],
                                      layer=layer)
                    xoffset += (_width[ascii_val] +
                                _indent[ascii_val]) * scaling
                else:
                    valid_chars = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ยต'
                    warnings.warn('[PHIDL] text(): Warning, some characters ignored, no geometry for character "%s" with ascii value %s. ' \
                                  'Valid characters: %s' % (chr(ascii_val), ascii_val, valid_chars))
            t.add_ref(l)
            yoffset -= 1500 * scaling
            xoffset = 0
    else:
        from .font import _get_font_by_name, _get_font_by_file, _get_glyph

        # Load the font
        # If we've passed a valid file, try to load that, otherwise search system fonts
        font = None
        if (face.endswith(".otf")
                or face.endswith(".ttf")) and os.path.exists(face):
            font = _get_font_by_file(face)
        else:
            try:
                font = _get_font_by_name(face)
            except ValueError:
                pass
        if font is None:
            raise ValueError((
                '[PHIDL] Failed to find font: "%s". ' +
                'Try specifying the exact (full) path to the .ttf or .otf file. '
                +
                'Otherwise, it might be resolved by rebuilding the matplotlib font cache'
            ) % (face))

        # Render each character
        for line in text.split('\n'):
            l = Device('textline')
            xoffset = 0
            for letter in line:
                letter_dev = Device("letter")
                letter_template, advance_x = _get_glyph(font, letter)
                for poly in letter_template.polygons:
                    letter_dev.add_polygon(poly.polygons, layer=layer)
                ref = l.add_ref(letter_dev)
                ref.move(destination=(xoffset, 0))
                ref.magnification = size
                xoffset += size * advance_x

            ref = t.add_ref(l)
            ref.move(destination=(0, yoffset))
            yoffset -= size

    justify = justify.lower()
    for l in t.references:
        if justify == 'left': pass
        if justify == 'right': l.xmax = 0
        if justify == 'center':
            l.move(origin=l.center, destination=(0, 0), axis='x')

    t.flatten()
    return t