def __init__(self, port=None, polygon=None, **kwargs): super().__init__(port=port, polygon=polygon, **kwargs) from spira import shapes if polygon is None: rect_shape = shapes.RectangleShape(p1=[0, 0], p2=[self.width, self.length]) pp = spira.Polygons(shape=rect_shape, gdslayer=spira.Layer(number=65)) pp.rotate(angle=self.orientation, center=self.midpoint) # pp.rotate(angle=90-self.orientation, center=self.midpoint) pp.move(midpoint=pp.center, destination=self.midpoint) self.polygon = pp else: self.polygon = polygon arrow_shape = shapes.ArrowShape(a=self.width / 10, b=self.width / 20, c=self.width / 5) arrow_shape.apply_merge # arrow_shape.rotate(angle=self.orientation) self.arrow = spira.Polygons(shape=arrow_shape, gdslayer=spira.Layer(number=77)) self.arrow.rotate(angle=self.orientation)
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
def wrap_labels(cell, c2dmap): for l in cell.get_labels(): D = c2dmap[cell] if isinstance(l, gdspy.Label): layer = spira.Layer(name='', number=l.layer) params = {} params['text'] = l.text params['gdslayer'] = layer params['str_anchor'] = l.anchor D += spira.Label(position=scd(l.position), **params)
def add_new_node(self, n, D, pos): params = {} params['text'] = 'new' l1 = spira.Layer(name='Label', number=104) params['gdslayer'] = l1 # params['color'] = RDD.METALS.get_key_by_layer(self.layer)['COLOR'] label = spira.Label(position=pos, **params) label.id = '{}_{}'.format(n, n) num = self.g.number_of_nodes() self.g.add_node(num + 1, pos=pos, pin=D, surface=label) self.g.add_edge(n, num + 1)
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.Polygons(p1) assert issubclass(type(ply1.shape), shapes.Shape) assert ply1.gdslayer.number == 0 assert ply1.gdslayer.datatype == 0 # Create polygon using new layer number. ply2 = spira.Polygons(shape=p2, gdslayer=spira.Layer(number=77)) assert issubclass(type(ply2.shape), shapes.Shape) assert ply2.gdslayer.number == 77 assert ply2.gdslayer.datatype == 0 # Create polygon using new shape, number and datatype. ply3 = spira.Polygons(shape=shapes.Shape(points=p3), gdslayer=spira.Layer(number=51, datatype=1)) assert issubclass(type(ply3.shape), shapes.Shape) assert ply3.gdslayer.number == 51 assert ply3.gdslayer.datatype == 1
def _regular_bend(self, prev_port): """ Now connect a regular bend for the normal curved portion. """ B = Arc(shape=ArcRoute(radius=self.radius, width=self.width, theta=45 - np.rad2deg(self.angular_coverage), start_angle=self.angular_coverage, angle_resolution=self.angle_resolution, gdslayer=spira.Layer(number=88))) b = spira.SRef(B) b.connect(port='P1', destination=prev_port) p0 = b.ports['P2'] self.port2 = spira.Term( name='P2', midpoint=p0.midpoint, # midpoint=scu(p0.midpoint), width=p0.width, orientation=p0.orientation) return b
def import_gds(filename, cellname=None, flatten=False, duplayer={}): """ """ LOG.header('Imported GDS file -> \'{}\''.format(filename)) 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 = spira.ElementList() c2dmap = {} for cell in gdsii_lib.cell_dict.values(): D = create_spira_cell(cell) for e in cell.elements: if isinstance(e, gdspy.PolygonSet): for points in e.polygons: layer = spira.Layer(number=e.layers[0], datatype=e.datatypes[0]) ply = spira.Polygons(shape=spd([points]), gdslayer=layer) D += ply elif isinstance(e, gdspy.Polygon): layer = spira.Layer(number=e.layers, datatype=e.datatype) ply = spira.Polygons(shape=spd([e.points]), gdslayer=layer) D += ply c2dmap.update({cell: D}) cell_list += cell for cell in cell_list: wrap_references(cell, c2dmap) wrap_labels(cell, c2dmap) top_spira_cell = c2dmap[topcell] # print('Toplevel Cell: {}\n'.format(top_spira_cell)) # print('\n---------- Cells --------------') # for i, D in enumerate(top_spira_cell.dependencies()): # print('{}. {}'.format(i, D.name)) # print('') if flatten == True: D = spira.Cell(name='import_gds') # for key, polygon in top_spira_cell.get_polygons(True).items(): # layer, datatype = key[0], key[1] # for l1, l2 in duplayer.items(): # if layer == l1: layer = l2 # poly = spira.Polygons(polygons=polygon, gdslayer=layer, gdsdatatype=datatype) # poly.scale_up() # D += poly # for l in top_spira_cell.lbls: # params = {} # params['text'] = l.text # params['gdslayer'] = l.gdslayer # params['str_anchor'] = l.str_anchor # D += spira.Label(position=scu(l.position), **params) return D else: return top_spira_cell
def create_layer(self): ll = spira.Layer(number=self.connect_layer.number, datatype=RDD.PURPOSE.TERM.datatype) return ll
if __name__ == '__main__': circle_shape = CircleShape() hexagon_shape = ConvexPolygon() arrow_shape = ArrowShape() arrow_shape.apply_merge rect_shape = RectangleShape() box_shape = BoxShape() basic_tri_shape = BasicTriangle() tri_shape = TriangleShape() tri_shape.apply_merge cell = spira.Cell(name='Basic Shapes') circle = spira.Polygons(shape=circle_shape, gdslayer=spira.Layer(number=13)) circle.center = (0, 0) hexagon = spira.Polygons(shape=hexagon_shape, gdslayer=spira.Layer(number=14)) hexagon.center = (5, 0) arrow = spira.Polygons(shape=arrow_shape, gdslayer=spira.Layer(number=15)) arrow.center = (10, 0) rect = spira.Polygons(shape=rect_shape, gdslayer=spira.Layer(number=16)) rect.center = (15, 0) box = spira.Polygons(shape=box_shape, gdslayer=spira.Layer(number=17)) box.center = (20, 0) basic = spira.Polygons(shape=basic_tri_shape, gdslayer=spira.Layer(number=18)) basic.center = (25, 0) tri = spira.Polygons(shape=tri_shape, gdslayer=spira.Layer(number=19)) tri.center = (30, 0)
def create_elementals(self, elems): elems += spira.Polygons(shape=[[[0, 0], [3, 0], [3, 1], [0, 1]]], gdslayer=spira.Layer(number=77)) return elems
def __getitem__(self, key): value = self.__dict__[key] if key == 'LAYER': value = spira.Layer(name='M4', number=value) return value