Пример #1
0
def test_elem_layer():
    l1 = spira.Layer()
    l2 = spira.Layer(number=18, datatype=3)
    l3 = spira.Layer(number=18, datatype=3)
    assert l1.key == (0, 0)
    assert l2.key == (18, 3)
    assert l2.key != (18, 0)
    assert l1 != l2
    assert l2 == l3

    p1 = PurposeLayer(name='Metals')
    p2 = PurposeLayer(name='Ground')
    p3 = PurposeLayer(name='Skyplane', datatype=3)
    p4 = PurposeLayer(name='Skyplane', datatype=2)
    assert p1.name == 'Metals'
    assert p1 == p2
    assert p1 != p3

    p5 = p3 + p4
    assert p5.datatype == 5
    assert p3.datatype == 3
    p6 = p3 + 6
    assert p6.datatype == 9
    p6 += p3
    assert p6.datatype == 12
Пример #2
0
    def create_elements(self, elems):

        group = spira.Group()
        group += spira.Rectangle(p1=(0, 0), p2=(10, 10), layer=spira.Layer(1))
        group += spira.Rectangle(p1=(0, 15), p2=(10, 30), layer=spira.Layer(1))

        group.transform(self.group_transform)

        elems += group

        bbox_shape = group.bbox_info.bounding_box(margin=1)
        elems += spira.Polygon(shape=bbox_shape, layer=spira.Layer(2))

        return elems
Пример #3
0
 def create_t1(self):
     T = self.get_transforms()
     ply = spira.Rectangle(p1=(0, 0),
                           p2=(self.width, self.length),
                           layer=spira.Layer(number=2))
     ply.transform(transformation=T)
     return ply
Пример #4
0
 def create_t1(self):
     T = spira.Translation(Coord(-10, 0))
     ply = spira.Rectangle(p1=(0, 0),
                           p2=(10, 50),
                           layer=spira.Layer(number=2))
     ply.transform(T)
     return ply
Пример #5
0
 def create_t1(self):
     T = spira.Rotation(rotation=-30)
     ply = spira.Rectangle(p1=(0, 0),
                           p2=(10, 50),
                           layer=spira.Layer(number=2))
     ply.transform(T)
     return ply
Пример #6
0
 def create_t2(self):
     tf = spira.GenericTransform(translation=Coord(-22, 0))
     ply = spira.Rectangle(p1=(0, 0),
                           p2=(10, 50),
                           layer=spira.Layer(number=3),
                           transformation=tf)
     return ply
Пример #7
0
 def create_t2(self):
     T = spira.GenericTransform(rotation=-60)
     ply = spira.Rectangle(p1=(0, 0),
                           p2=(10, 50),
                           layer=spira.Layer(number=3),
                           transformation=T)
     return ply
Пример #8
0
def wrap_labels(cell, c2dmap):
    for l in cell.get_labels():
        D = c2dmap[cell]
        if isinstance(l, gdspy.Label):
            D += spira.Label(position=l.position,
                             text=l.text,
                             layer=spira.Layer(number=l.layer))
Пример #9
0
 def create_t3(self):
     cell = spira.Cell()
     cell += spira.Rectangle(p1=(0, 0),
                             p2=(10, 50),
                             layer=spira.Layer(number=4))
     S = spira.SRef(cell)
     S.rotate(-90)
     return S
Пример #10
0
 def create_t2(self):
     cell = spira.Cell()
     cell += spira.Rectangle(p1=(0, 0),
                             p2=(10, 50),
                             layer=spira.Layer(number=3))
     T = spira.GenericTransform(rotation=-60)
     S = spira.SRef(cell, transformation=T)
     return S
Пример #11
0
 def create_t1(self):
     cell = spira.Cell()
     cell += spira.Rectangle(p1=(0, 0),
                             p2=(10, 50),
                             layer=spira.Layer(number=2))
     T = spira.Rotation(-30)
     S = spira.SRef(cell, transformation=T)
     return S
Пример #12
0
 def create_t3(self):
     ply = spira.Rectangle(p1=(0, 0),
                           p2=(10, 50),
                           layer=spira.Layer(number=4))
     ply.translate((30, 0))
     ply.rotate(90)
     # FIXME: Reflection is not working.
     ply.reflect(True)
     return ply
Пример #13
0
    def parse(self):

        gdsii_lib = gdspy.GdsLibrary(name='SPiRA-cell')
        gdsii_lib.read_gds(self.file_name)
        top_level_gdspy_cells = gdsii_lib.top_level()

        if self.cell_name is not None:
            if self.cell_name not in gdsii_lib.cell_dict:
                error_message = "[SPiRA] import_gds() The requested gdspy_cell (named {}) is not present in file {}"
                raise ValueError(error_message.format(self.cell_name, self.file_name))
            topgdspy_cell = gdsii_lib.cell_dict[self.cell_name]
        elif self.cell_name is None and len(top_level_gdspy_cells) == 1:
            topgdspy_cell = top_level_gdspy_cells[0]
        elif self.cell_name is None and len(top_level_gdspy_cells) > 1:
            # TODO: Add this to logger.
            print('Multiple toplevel gdspy_cells found:')
            for gdspy_cell in top_level_gdspy_cells:
                print(gdspy_cell)
            raise ValueError('[SPiRA] import_gds() There are multiple' +
                            'top-level gdspy_cells, you must specify self.cell_name' +
                            'to select of one of them')

        c2dmap = {}
        for gdspy_cell in gdsii_lib.cell_dict.values():
            D = spira.Cell(name=gdspy_cell.name)
            for e in gdspy_cell.polygons:

                for i, p in enumerate(e.polygons):
                    n = e.layers[i]
                    d = e.datatypes[i]
                    # print(n, d)
                    layer = spira.Layer(number=int(n), datatype=int(d))
                    L = self.map_layer(layer)
                    # print(L)
                    # D += spira.Polygon(shape=p, layer=L)
                    ply = spira.Polygon(shape=p, layer=L)
                    # print(ply)
                    D += ply

                # print(e.datatypes)

                # key = (e.layer)

                # # FIXME: Maybe check the datatype and add layer mapping.
                # for n, p in zip(e.layers, e.polygons):
                #     layer = spira.Layer(number=int(n), datatype=int(0))
                #     L = self.map_layer(layer)
                #     D += spira.Polygon(shape=p, layer=L)

            c2dmap.update({gdspy_cell: D})

        for gdspy_cell in gdsii_lib.cell_dict.values():
            self._create_references(gdspy_cell, c2dmap)
            # self._create_labels(gdspy_cell, c2dmap)

        return c2dmap[topgdspy_cell]
Пример #14
0
def import_gds(filename, cellname=None, flatten=False, pcell=True):
    """  """

    gdsii_lib = gdspy.GdsLibrary(name='SPiRA-Cell')
    gdsii_lib.read_gds(filename)
    top_level_cells = gdsii_lib.top_level()

    if cellname is not None:
        if cellname not in gdsii_lib.cell_dict:
            raise ValueError("[SPiRA] import_gds() The requested cell " +
                             "(named {}) is not present in file {}".format(
                                 cellname, filename))
        topcell = gdsii_lib.cell_dict[cellname]
    elif cellname is None and len(top_level_cells) == 1:
        topcell = top_level_cells[0]
    elif cellname is None and len(top_level_cells) > 1:
        # TODO: Add this to logger.
        print('Multiple toplevel cells found:')
        for cell in top_level_cells:
            print(cell)
        raise ValueError('[SPiRA] import_gds() There are multiple' +
                         'top-level cells, you must specify cellname' +
                         'to select of one of them')

    cell_list = []
    c2dmap = {}
    for cell in gdsii_lib.cell_dict.values():
        D = spira.Cell(name=cell.name)
        for e in cell.polygons:

            # FIXME: Maybe check the datatype and add layer mapping.
            for n, p in zip(e.layers, e.polygons):
                layer = spira.Layer(number=int(n), datatype=0)
                D += spira.Polygon(shape=p, layer=layer)

        c2dmap.update({cell: D})
        cell_list.append(cell)

    for cell in cell_list:
        wrap_references(cell, c2dmap)
        # wrap_labels(cell, c2dmap)

    top_spira_cell = c2dmap[topcell]

    if flatten == True:
        C = spira.Cell(name='import_gds')
    else:
        C = top_spira_cell

    if pcell is True:
        D = parameterize_cell(C)
    else:
        D = C

    return D
Пример #15
0
 def create_t3(self):
     cell = spira.Cell()
     tf_1 = spira.Translation(Coord(12.5, 2.5)) + spira.Rotation(60)
     tf_2 = spira.Translation(Coord(
         12.5, 2.5)) + spira.Rotation(60) + spira.Reflection(True)
     cell += spira.Rectangle(p1=(0, 0),
                             p2=(10, 50),
                             layer=spira.Layer(number=4))
     S1 = spira.SRef(cell, transformation=tf_1)
     S2 = spira.SRef(cell, transformation=tf_2)
     return [S1, S2]
Пример #16
0
 def create_t2(self):
     cell = spira.Cell()
     tf_1 = spira.GenericTransform(translation=(10, 10), rotation=45)
     tf_2 = spira.GenericTransform(translation=Coord(10, 10),
                                   rotation=45,
                                   reflection=True)
     cell += spira.Rectangle(p1=(0, 0),
                             p2=(10, 50),
                             layer=spira.Layer(number=3))
     S1 = spira.SRef(cell, transformation=tf_1)
     S2 = spira.SRef(cell, transformation=tf_2)
     return [S1, S2]
Пример #17
0
    def create_elements(self, elems):

        points = [(10.0, 0.0), (15.0, 10.0), (0.0, 10.0), (0.0, 5.0),
                  (-15.0, 5.0), (-5.0, 0.0), (-10.0, -10.0), (-5.0, -15.0),
                  (10.0, -15.0), (5.0, -10.0), (5.0, -5.0)]
        s = spira.Shape(points=points)

        S1 = spira.Cell(name='shape',
                        elements=spira.Polygon(shape=s, layer=spira.Layer(1)))

        # #translate a copy of the shape
        # t = s.move_copy((0.0, 20.0))
        # S2 = Structure("shape_trans", Boundary(Layer(0), t))

        # #rotate the shape (angle in degree)
        # t = s.rotate_copy((0.0, 0.0), 50)
        # S3 = Structure("shape_rot", Boundary(Layer(0), t))

        # #scale the shape
        # t = s.magnify_copy((0.0, 0.0), 1.2)
        # S4 = Structure("shape_scale", Boundary(Layer(0), t))

        # #stretch the shape horizontally and squeeze vertically
        # t = Stretch(stretch_center = (0.0, 0.0), stretch_factor = (1.5, 0.5))(s)
        # S5 = Structure("shape_stretch", Boundary(Layer(0), t))

        # #fit the shape in a box
        # south_west = (-7.0, -7.0)
        # north_east = (7.0, 7.0)
        # t = ShapeFit(s, south_west, north_east)
        # S6 = Structure("shape_fit", Boundary(Layer(0), t))

        # #create a shape which traces the contour with a certain line width
        # t = ShapePath(original_shape = s, path_width = 0.5)
        # S7 = Structure("ShapePath1", Boundary(Layer(0), t))

        # t = ShapePathRounded(original_shape = s, path_width = 0.5)
        # S8 = Structure("ShapePath2", Boundary(Layer(0), t))

        # #expand the shape with a certain distance
        # t = ShapeGrow(s, 1.0)
        # S9 = Structure("shape_grow", Boundary(Layer(1), t) + Boundary(Layer(0), s))

        # #round the shape with a given radius
        # t = ShapeRound(original_shape = s, radius = 2.0)
        # S10 = Structure("shape_round", Boundary(Layer(1), t) + Boundary(Layer(0), s))

        elems += [
            spira.SRef(S1, (0.0, 200.0)),
        ]

        return elems
Пример #18
0
    def create_elements(self, elems):
        t1, t2 = self.get_transforms()

        jj = Junction()

        elems += spira.SRef(alias='ref_jj1', reference=jj, transformation=t1)
        elems += spira.SRef(alias='ref_jj2', reference=jj, transformation=t2)

        elems += spira.Rectangle(p1=(7, -13),
                                 p2=(143, 1),
                                 layer=spira.Layer(number=2))

        return elems
Пример #19
0
def test_elem_polygon():
    p1 = [[[0, 0], [3, 0], [3, 1], [0, 1]]]
    p2 = [[[4, 0], [7, 0], [7, 1], [4, 1]]]
    p3 = [[[8, 0], [11, 0], [11, 1], [8, 1]]]

    # Create polygon using class parameters.
    ply1 = spira.Polygon(p1)
    assert issubclass(type(ply1.shape), shapes.Shape)
    assert ply1.gds_layer.number == 0
    assert ply1.gds_layer.datatype == 0

    # Create polygon using new layer number.
    ply2 = spira.Polygon(shape=p2, gds_layer=spira.Layer(number=77))
    assert issubclass(type(ply2.shape), shapes.Shape)
    assert ply2.gds_layer.number == 77
    assert ply2.gds_layer.datatype == 0

    # Create polygon using new shape, number and datatype.
    ply3 = spira.Polygon(shape=shapes.Shape(points=p3),
                         gds_layer=spira.Layer(number=51, datatype=1))
    assert issubclass(type(ply3.shape), shapes.Shape)
    assert ply3.gds_layer.number == 51
    assert ply3.gds_layer.datatype == 1
Пример #20
0
class Box(spira.Cell):

    width = spira.NumberParameter(default=1)
    height = spira.NumberParameter(default=1)
    layer = spira.LayerParameter(default=spira.Layer(1))

    def create_elements(self, elems):
        shape = shapes.BoxShape(width=self.width, height=self.height)
        elems += spira.Polygon(shape=shape, layer=self.layer)
        return elems

    def create_ports(self, ports):
        ports += spira.Port(name='P1_M1', midpoint=(-0.5,0), orientation=180, width=1)
        ports += spira.Port(name='P2_M1', midpoint=(0.5,0), orientation=0, width=1)
        return ports
Пример #21
0
    def create_t1(self):
        cell = spira.Cell()
        cell += spira.Rectangle(p1=(0, 0),
                                p2=(10, 50),
                                layer=spira.Layer(number=2))

        S1 = spira.SRef(cell)
        S1.rotate(rotation=45)
        S1.translate(Coord(15, 15))

        S = spira.SRef(cell)
        S.rotate(rotation=45)
        S.translate(Coord(15, 15))
        S.reflect(True)

        return [S1, S]
Пример #22
0
 def create_ref_point(self):
     return spira.Rectangle(p1=(-2.5, -2.5),
                            p2=(2.5, 2.5),
                            layer=spira.Layer(number=1))
Пример #23
0
 def create_elements(self, elems):
     elems += spira.Rectangle(p1=(0,0), p2=(20,5), layer=spira.Layer(1))
     return elems
Пример #24
0
    # rect = spira.Polygon(shape=rect_shape, layer=spira.Layer(number=16))
    # rect.center = (15,0)
    # cell += rect

    # box = spira.Polygon(shape=box_shape, layer=spira.Layer(number=17))
    # box.center = (20,0)
    # cell += box

    # FIXME
    # basic = spira.Polygon(shape=basic_tri_shape, layer=spira.Layer(number=18))
    # basic.center = (25,0)
    # cell += basic

    # FIXME
    # tri = spira.Polygon(shape=tri_shape, layer=spira.Layer(number=19))
    # tri.center = (30,0)
    # cell += tri

    # FIXME
    # arrow = spira.Polygon(shape=arrow_shape, layer=spira.Layer(number=15))
    # arrow.center = (10,0)
    # cell += arrow

    # NOTE: Advanced shapes
    ytron_shape = YtronShape()
    ytron = spira.Polygon(shape=ytron_shape, layer=spira.Layer(number=20))
    ytron.center = (35, 0)
    cell += ytron

    cell.gdsii_output()
Пример #25
0
 def create_elements(self, elems):
     pts = [[0, 0], [2, 2], [2, 6], [-6, 6], [-6, -6], [-4, -4], [-4, 4],
            [0, 4]]
     shape = spira.Shape(points=pts)
     elems += spira.Polygon(shape=shape, layer=spira.Layer(1))
     return elems
Пример #26
0
 def _create_labels(self, gdspy_cell, c2dmap):
     for l in gdspy_cell.get_labels():
         D = c2dmap[gdspy_cell]
         if isinstance(l, gdspy.Label):
             D += spira.Label(position=l.position, text=l.text, layer=spira.Layer(number=l.layer))
Пример #27
0
import spira.all as spira

ll = spira.LayerList()
ll += spira.Layer(1)
ll += spira.Layer(2)
print(ll)
# lf = spira.LayerFilterDelete(layers=ll)
lf = spira.LayerFilterAllow(layers=ll)
print(lf.layers)
print(len(lf.layers))

print(lf)

p1 = spira.Rectangle(layer=spira.Layer(1))
p2 = spira.Rectangle(layer=spira.Layer(3))

F = lf([p1, p2])
print(F)
Пример #28
0
 def create_t3(self):
     ply = spira.Rectangle(p1=(0, 0),
                           p2=(10, 50),
                           layer=spira.Layer(number=4))
     ply.rotate(-90)
     return ply
Пример #29
0
 def create_t3(self):
     ply = spira.Rectangle(p1=(0, 0),
                           p2=(10, 50),
                           layer=spira.Layer(number=4))
     ply.reflect(True)
     return ply
Пример #30
0
 def create_t3(self):
     ply = spira.Rectangle(p1=(0, 0),
                           p2=(10, 50),
                           layer=spira.Layer(number=4))
     ply.translate((-34, 0))
     return ply