📄 padgenerator.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: PadGenerator.java * * Copyright (c) 2003 Sun Microsystems and Static Free Software * * Electric(tm) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Electric(tm) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Electric(tm); see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.tool.generator;import com.sun.electric.database.geometry.DBMath;import com.sun.electric.database.geometry.Dimension2D;import com.sun.electric.database.geometry.EGraphics;import com.sun.electric.database.geometry.EPoint;import com.sun.electric.database.geometry.Orientation;import com.sun.electric.database.geometry.Poly;import com.sun.electric.database.geometry.PolyBase;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.hierarchy.Library;import com.sun.electric.database.hierarchy.View;import com.sun.electric.database.prototype.PortProto;import com.sun.electric.database.text.CellName;import com.sun.electric.database.text.Name;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.topology.PortInst;import com.sun.electric.database.variable.TextDescriptor;import com.sun.electric.database.variable.UserInterface;import com.sun.electric.lib.LibFile;import com.sun.electric.technology.ArcProto;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.technologies.Artwork;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.technology.technologies.Schematics;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.io.FileType;import com.sun.electric.tool.io.input.LibraryFiles;import com.sun.electric.tool.routing.AutoStitch;import com.sun.electric.tool.user.CellChangeJobs;import com.sun.electric.tool.user.User;import com.sun.electric.tool.user.ViewChanges;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;import java.net.URL;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.StringTokenizer;/** * Class to generate pad frames from a specification file. */public class PadGenerator{ /** * Method to generate a pad frame from an array file. * Schedules a change job to generate the pad frame. * @param destLib destination library. * @param fileName the array file name. */ public static void makePadFrame(Library destLib, String fileName) { if (fileName == null) return; new MakePadFrame(destLib, fileName, Job.getUserInterface().getGridAlignment()); } /** * Method to generate a pad frame from an array file. * Presumes that it is being run from inside a change job. * @param destLib destination library. * @param fileName the array file name. * @param job the Job running this task (null if none). */ public static Cell makePadFrameUseJob(Library destLib, String fileName, Dimension2D alignment, Job job) { PadGenerator pg = new PadGenerator(destLib, fileName, alignment); return pg.makePadFrame(job); } private static class MakePadFrame extends Job { private Library destLib; private String fileName; private Cell frameCell; private Dimension2D alignment; private MakePadFrame(Library destLib, String fileName, Dimension2D alignment) { super("Pad Frame Generator", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.destLib = destLib; this.fileName = fileName; this.alignment = alignment; startJob(); } public boolean doIt() throws JobException { frameCell = makePadFrameUseJob(destLib, fileName, alignment, this); fieldVariableChanged("frameCell"); return true; } public void terminateOK() { UserInterface ui = Job.getUserInterface(); ui.displayCell(frameCell); } } private Library destLib; // destination library private String fileName; // name of file with pad array instructions private Dimension2D alignment; // alignment amount private String padframename; // name of pad frame cell private String corename; // core cell to stick in pad frame private int lineno; // line no of the pad array file we are processing private Library cellLib; // library containing pad cells private boolean copycells; // if we copy cells into the library with the pad ring private List<View> views; // list of strings defining views of pad frame to create. private int angle; // angle of placed instances private HashMap<String,ArrayAlign> alignments; // how to align adjacent instances private HashMap<String,PadExports> exports; // which ports to export private List<Object> orderedCommands; // list of orderedCommands to do private boolean coreAllOnOneSide = false; private static class ArrayAlign { int lineno; String cellname; String inport; String outport; } private static class PadExports { int lineno; String cellname; String padname; String corename; } private static class PlacePad { int lineno; String cellname; String exportsname; int gap; NodeInst ni; List<PortAssociate> associations; List<ExportAssociate> exportAssociations; Double locx; Double locy; } private static class Rotation { int angle; } private static class ReverseDirection { } private static class PortAssociate { boolean export; String portname; String assocname; } private static class ExportAssociate { String padportName; String exportName; } private PadGenerator(Library destLib, String fileName, Dimension2D alignment) { this.destLib = destLib; this.fileName = fileName; this.alignment = alignment; alignments = new HashMap<String,ArrayAlign>(); exports = new HashMap<String,PadExports>(); views = new ArrayList<View>(); angle = 0; lineno = 1; orderedCommands = new ArrayList<Object>(); } private Cell makePadFrame(Job job) { String lineRead; File inputFile = new File(fileName); if (inputFile == null || !inputFile.canRead()) { System.out.println("Error reading file "+fileName); return null; } try { FileReader readFile = new FileReader(inputFile); BufferedReader readLine = new BufferedReader(readFile); lineRead = readLine.readLine(); while (lineRead != null) { StringTokenizer str = new StringTokenizer(lineRead, " \t"); if (str.hasMoreTokens()) { String keyWord = str.nextToken(); if (keyWord.charAt(0) != ';') { do { if (keyWord.equals("celllibrary")) { if (!processCellLibrary(str)) return null; continue; } else if (keyWord.equals("views")) { if (!processViews(str)) return null; continue; } else if (keyWord.equals("cell")) { if (!processCell(str)) return null; continue; } else if (keyWord.equals("core")) { if (!processCore(str)) return null; continue; } else if (keyWord.equals("rotate")) { if (!processRotate(str)) return null; continue; } else if (keyWord.equals("reverse")) { if (!processReverse(str)) return null; continue; } else if (keyWord.equals("align")) { if (!processAlign(str)) return null; continue; } else if (keyWord.equals("export")) { if (!processExport(str)) return null; continue; } else if (keyWord.equals("place")) { if (!processPlace(str)) return null; continue; } else if (keyWord.equals("coreExportsAllOnOneSideOfIcon")) { coreAllOnOneSide = true; continue; } System.out.println("Line " + lineno + ": unknown keyword'" + keyWord + "'"); break; } while (str.hasMoreTokens()); } } lineRead = readLine.readLine(); lineno++; } } catch (IOException e1) {} Cell frameCell = createPadFrames(job); return frameCell; } /** * Process the celllibrary keyword * @return true on success, false on error. */ private boolean processCellLibrary(StringTokenizer str) { String keyWord; if (str.hasMoreTokens()) { keyWord = str.nextToken(); URL fileURL = TextUtils.makeURLToFile(keyWord); cellLib = Library.findLibrary(TextUtils.getFileNameWithoutExtension(fileURL)); if (cellLib == null) { // library does not exist: see if in same directory is pad frame file StringBuffer errmsg = new StringBuffer(); String fileDir = TextUtils.getFilePath(TextUtils.makeURLToFile(fileName)); fileURL = TextUtils.makeURLToFile(fileDir + keyWord); if (!TextUtils.URLExists(fileURL, errmsg)) { // library does not exist: see if file can be found locally if (!TextUtils.URLExists(fileURL, errmsg)) { // try the Electric library area fileURL = LibFile.getLibFile(keyWord); if (!TextUtils.URLExists(fileURL, errmsg)) { System.out.println(errmsg.toString()); return false; } } } FileType style = FileType.DEFAULTLIB; if (TextUtils.getExtension(fileURL).equals("txt")) style = FileType.READABLEDUMP; if (TextUtils.getExtension(fileURL).equals("elib")) style = FileType.ELIB; cellLib = LibraryFiles.readLibrary(fileURL, null, style, false); if (cellLib == null) { err("cannot read library " + keyWord); return false; } } } if (str.hasMoreTokens()) { keyWord = str.nextToken(); if (keyWord.equals("copy")) copycells = true; } return true; } /** * Process any Views. * @return true on success, false on error. */ private boolean processViews(StringTokenizer str) { String keyWord; while (str.hasMoreTokens()) { keyWord = str.nextToken(); View view = View.findView(keyWord); if (view != null) views.add(view); else err("Unknown view '" + keyWord + "', ignoring"); } return true; } /** * Process the cell keyword * @return true on success, false on error. */ private boolean processCell(StringTokenizer str) { if (str.hasMoreTokens()) { padframename = str.nextToken(); return true; } return false; } /** * Process the core keyword * @return true on success, false on error. */ private boolean processCore(StringTokenizer str) { if (str.hasMoreTokens()) { corename = str.nextToken(); return true; } return false; } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -