def gdsConv(u, m): global mode global unit global globIm global im rightFrame.pack_propagate(0) if im == None: for widget in rightFrame.winfo_children(): widget.destroy() l2 = Label(rightFrame, text=' Import Image first! ', relief=RAISED, font='calibri 15 bold', fg='red').pack(padx=140) else: if u == "" or (m not in ('2', '4', '8', '16', '32', '64')) or (not str.isdigit(u)): for widget in rightFrame.winfo_children(): widget.destroy() label = Label(rightFrame, image=globIm) label.image = globIm label.pack(padx=60) l2 = Label(rightFrame, text=' Please select valid unit and Layers! ', relief=RAISED, font='calibri 15 bold', fg='red').pack(padx=60, pady=10) else: saveLoc = tkFileDialog.asksaveasfilename() if saveLoc == None or saveLoc == "": for widget in rightFrame.winfo_children(): widget.destroy() label = Label(rightFrame, image=globIm) label.image = globIm label.pack(padx=60) l2 = Label(rightFrame, text=' Select a save location! ', relief=RAISED, font='calibri 15 bold', fg='red').pack(padx=60, pady=10) else: unit = int(u) * 1e-9 mode = int(m) for widget in rightFrame.winfo_children(): widget.destroy() # label = Label(rightFrame,image = globIm) # label.image = globIm # label.pack(padx = 60) ###gdsWriter### name = fileLoc.split('/')[-1].split('.')[0] width, height = im.size cell = core.Cell('GDSII') layout = core.Layout(name, unit) rows = np.arange(height) global imArray imArray = misc.imread(fileLoc, flatten=1) maxVal = np.max(imArray) minVal = np.min(imArray) bins = [] levels = mode for b in range(levels + 1): interval = (maxVal - minVal + 1) / float(levels) bins.append(minVal + b * interval) t = time.time() global mask mask = np.digitize(imArray, bins) ####Shows discritised image### digitized = mask * (256 / (levels)) im = Image.fromarray(digitized.astype('uint8')) width, height = im.size m = max(width, height) if m > 330: scale = 330.0 / m else: scale = 1 globIm = im.resize((int(width * scale), int(height * scale)), Image.ANTIALIAS) globIm = ImageTk.PhotoImage(globIm) label = Label(rightFrame, image=globIm) label.image = globIm label.pack(padx=int((420 - width * scale) / 2)) l2 = Label(rightFrame, text='Conversion in progress...', relief=RAISED, font='calibri 15 bold', fg='blue').pack(padx=60, pady=10) progress_var = DoubleVar(root) progress = Progressbar(rightFrame, orient=HORIZONTAL, variable=progress_var, maximum=100, length=290) progress.pack(padx=20) for row in rows: k = (float(row) / height) * 100 progress_var.set(k) time.sleep(0.001) root.update() r = mask[row] col = 0 while col < width: i = 0 pres = r[col] if r[col + i] == pres and r[col + i] > 1: while r[col + i] == pres: i = i + 1 if col + i > width - 1: break cell.add( core.Path([(col, height - row), (col + i, height - row)], pathtype=0, layer=pres - 1)) col = col + i else: col = col + 1 layout.add(cell) layout.save(saveLoc + '.gds') for widget in rightFrame.winfo_children(): widget.destroy() label = Label(rightFrame, image=globIm) label.image = globIm label.pack(padx=60) l2 = Label(rightFrame, text='Conversion completed.', relief=RAISED, font='calibri 15 bold', fg='blue').pack(padx=60, pady=10) tot = int((time.time() - t)) m = int(tot / 60) s = int(tot % 60) # message = Listbox(rightFrame,font = 'Times 12', width = 360) # message.pack(side = LEFT) # message.insert(END,'Time taken: '+str(m)+' minutes and '+str(s)+' seconds') # message.insert(END,'Image dimensions: width = '+str(width)+' height = '+str(height)) # message.insert(END,'Pixel size used: '+str(unit)) inpSize = os.path.getsize(fileLoc) outSize = os.path.getsize(saveLoc + '.gds') message = Label( rightFrame, text='Conversion time: ' + str(m) + ' minutes and ' + str(s) + ' seconds\n' + 'Image dimensions: width = ' + str(width) + ' height = ' + str(height) + '\n' + 'Pixel size used: ' + str(unit * 1e9) + ' nm\n' + 'Input file size: ' + str(inpSize / 1024) + ' KB Output GDSII file size: ' + str(outSize / 1024) + ' KB', anchor=W, justify=LEFT, font='calibri 11 bold') message.pack(side=LEFT, padx=5)
def gdsGenerate(s, base, height, radius, leng, breadth, rows, cols, period, mod): mod = int(mod) if s == 0: m = 'Select a shape!' message.config(text=m) message.text = m elif s == 1: if base == '0' or (not str.isdigit(base)): m = 'Enter Valid Base value!' message.config(text=m, fg='red') message.text = m elif height == '0' or (not str.isdigit(height)): m = 'Enter Valid Height value!' message.config(text=m, fg='red') message.text = m else: if rows != 0 and cols != 0 and period != 0 and ( str.isdigit(rows)) and (str.isdigit(cols)) and ( str.isdigit(period)): f = f = tkFileDialog.asksaveasfilename() if f == None: m = 'Choose a save location!' message.config(text=m, fg='red') message.text = m else: cell = core.Cell('Triangle') layout = core.Layout('Triangle', unit=1e-9) if mod == 0: points = [(0, 0), (float(base), 0), (float(base) / 2.0, float(height))] cell.add(core.Boundary(points)) cellArray = core.Cell('TriangleArray') cellArray.add( core.CellArray(cell, int(cols), int(rows), (int(period), int(period)))) layout.add(cellArray) layout.save(f + '.gds') m = 'GDSII generated!' message.config(text=m, fg='blue') message.text = m elif mod == 1: height = float(height) rows = int(rows) cols = int(cols) period = float(period) print 'hi' for i in range(rows): for j in range(cols): points = [(period * j, i * period), (float(base) + period * j, i * period), (float(base) / 2.0 + period * j, height + i * period)] cell.add(core.Boundary(points)) layout.add(cell) layout.save(f + '.gds') m = 'GDSII generated!' message.config(text=m, fg='blue') message.text = m else: m = 'Enter valid rows, columns and period!' message.config(text=m, fg='red') message.text = m elif s == 2: if radius == '0' or (not str.isdigit(radius)): m = 'Enter Valid Radius value!' message.config(text=m, fg='red') message.text = m else: if rows != 0 and cols != 0 and period != 0 and ( str.isdigit(rows)) and (str.isdigit(cols)) and ( str.isdigit(period)): f = tkFileDialog.asksaveasfilename() if f == None: m = 'Choose a save location!' message.config(text=m, fg='red') message.text = m else: cell = core.Cell('Circle') layout = core.Layout('CircleLayout', unit=1e-9) if mod == 0: cell.add(shapes.Disk((0, 0), float(radius))) cellArray = core.Cell('CircleArray') cellArray.add( core.CellArray(cell, int(cols), int(rows), (int(period), int(period)))) layout.add(cellArray) #layout.save(f) layout.save(f + '.gds') m = 'GDSII generated!' message.config(text=m, fg='blue') message.text = m elif mod == 1: radius = float(radius) rows = int(rows) cols = int(cols) period = float(period) print 'hi' for i in range(rows): for j in range(cols): cell.add( shapes.Disk((period * j, period * i), float(radius))) layout.add(cell) layout.save(f + '.gds') m = 'GDSII generated!' message.config(text=m, fg='blue') message.text = m else: m = 'Enter valid rows, columns and period!' message.config(text=m, fg='red') message.text = m elif s == 3: if leng == '0' or not (str.isdigit(leng)): m = 'Enter Valid Length value!' message.config(text=m, fg='red') message.text = m elif breadth == '0' or (not str.isdigit(breadth)): m = 'Enter Valid Breadth value!' message.config(text=m, fg='red') message.text = m else: if rows != 0 and cols != 0 and period != 0 and ( str.isdigit(rows)) and (str.isdigit(cols)) and ( str.isdigit(period)): f = tkFileDialog.asksaveasfilename() if f == None: m = 'Choose a save location!' message.config(text=m, fg='red') message.text = m else: cell = core.Cell('Rectangle') layout = core.Layout('RectangleLayout', 1e-9) if mod == 0: cell.add( shapes.Rectangle( (0, 0), (float(leng), float(breadth)))) cellArray = core.Cell('RectangleArray') cellArray.add( core.CellArray(cell, int(cols), int(rows), (int(period), int(period)))) layout.add(cellArray) layout.save(f + '.gds') m = 'GDSII generated!' message.config(text=m, fg='blue') message.text = m elif mod == 1: leng = float(leng) breadth = float(breadth) rows = int(rows) cols = int(cols) period = float(period) print 'hi' for i in range(rows): for j in range(cols): cell.add( shapes.Rectangle( (period * j, period * i), (float(leng) + period * j, float(breadth) + period * i))) layout.add(cell) layout.save(f + '.gds') m = 'GDSII generated!' message.config(text=m, fg='blue') message.text = m else: m = 'Enter valid rows, columns and period!' message.config(text=m, fg='red') message.text = m
else: # Mark = core.CellReference(amarks,(x,y),magnification=0.01) Mark = utils.translate(smallCross, (x, y)) # text = shapes.Label('%s%d'%(ALPHA[i//5],j//5),100,position=(x-300,y+50)) cell.add(Mark) for x in range(0, substrat[0], 1000): letter = shapes.Label('%s' % (ALPHA[x // 1000]), 1000, position=(x + 222, substrat[1] - 100)) # number = shapes.Label('%d'%(y//1000),40,position=(x+25,y-60)) cell.add(letter) for y in range(0, substrat[1], 1000): number = shapes.Label('%d' % ((substrat[1] - 1 - y) // 1000), 1000, position=(-700, y - 100)) # number = shapes.Label('%d'%(y//1000),40,position=(x+25,y-60)) cell.add(number) # Create two copies of the Cell #core.CellReference(cell, origin=(0, 40), magnification=1.5) #top = core.Cell('TOP') #cell_array = core.CellArray(cell, 5, 5, (1200, 1200)) #top.add(cell_array) # Add the copied cell to a Layout and save layout = core.Layout('LIBRARY') layout.add(cell) layout.save('output.gds') layout.show()