📄 calibredrcerrors.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: CalibreDrcErrors.java * * Copyright (c) 2005 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.drc;import com.sun.electric.database.geometry.EPoint;import com.sun.electric.database.geometry.PolyBase;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.variable.UserInterface;import com.sun.electric.tool.Job;import com.sun.electric.tool.user.ErrorLogger;import java.awt.Shape;import java.awt.geom.Line2D;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.io.File;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.NoSuchElementException;import java.util.StringTokenizer;/** * This reads an ASCII Calibre DRC error database * produced by running Calibre DRC. * It shows these errors on the specified cells in * Electric. */public class CalibreDrcErrors { private int scale; private String topCellName; private Cell topCell; private ErrorLogger logger; private BufferedReader in; private List<DrcRuleViolation> ruleViolations; // list of DrcRuleViolations private int lineno; private Map<Cell,String> mangledNames; private String type; private String filename; private boolean noPopupMessages; private static final String spaces = "[\\s\\t ]+"; /** * Create a new CalibreDrcError class, read the errors in, * and then convert them to the ErrorLogger. * @param filename the ASCII calibre drc results database file * @return number of erros. Negative number in case of valid data. */ public static int importErrors(String filename, Map<Cell,String> mangledNames, String type, boolean noPopupMessages) { BufferedReader in; try { FileReader reader = new FileReader(filename); in = new BufferedReader(reader); } catch (IOException e) { System.out.println("Error importing "+type+" Errors: "+e.getMessage()); return -1; } if (in == null) return -1; CalibreDrcErrors errors = new CalibreDrcErrors(in, mangledNames, type, noPopupMessages); errors.filename = filename; // read first line if (!errors.readTop()) return -1; // read all rule violations if (!errors.readRules()) return -1; // finish return errors.done(); } // Constructor private CalibreDrcErrors(BufferedReader in, Map<Cell,String> mangledNames, String type, boolean noPopupMessages) { assert(in != null); this.in = in; lineno = 0; ruleViolations = new ArrayList<DrcRuleViolation>(); this.mangledNames = mangledNames; this.type = type; this.noPopupMessages = noPopupMessages; } // read the cell name and precision, if any private boolean readTop() { scale = 1000; String line; try { line = readLine(true); } catch (IOException e) { System.out.println("Error reading first line of file: "+e.getMessage()); return false; } if (line == null) return false; String [] parts = line.trim().split(spaces); if (parts.length == 1) { topCellName = parts[0]; } else if (parts.length == 2) { topCellName = parts[0]; try { scale = Integer.parseInt(parts[1]); } catch (NumberFormatException e) { System.out.println("Error converting precision '"+parts[1]+"' to a number, using default of "+scale); return false; } } else { // error System.out.println("Error on first line: Expected cell name and precision, or 'drc'"); return false; } topCell = getCell(topCellName, mangledNames); if (topCell == null) { System.out.println("Cannot find cell "+topCellName+" specified in error file, line number "+lineno+", aborting"); return false; } return true; } // read all Rule violations in the file private boolean readRules() { // read all errors try { while(true) { DrcRuleViolation v = readRule(); if (v == null) break; if (v.errors.size() != 0) // something to include ruleViolations.add(v); } } catch (IOException e) { System.out.println("Error reading file: "+e.getMessage()); return false; } return true; } /** * Read a logged error. Return false if there was a problem, or nothing left to read. * @return true if read ok, false if error or End of File */ private DrcRuleViolation readRule() throws IOException { // read the first line: the rule name String ruleName = readLine(false); if (ruleName == null) return null; // EOF, no more errors // read the header start line, tells us how many header lines there are Header header = readHeader(); if (header == null) return null; // read the rest of the header for (int i=0; i<header.headerLength; i++) { String s = readLine(); if (s == null) return null; header.addHeaderLine(s); } if (header.comment.length() == 0) header.comment.append(ruleName); DrcRuleViolation v = new DrcRuleViolation(ruleName, header); // read shapes describing errors for (int i=0; i<header.currentDrcResultsCount; i++) { DrcError drc = readErrorShape(); if (drc == null) break; v.addError(drc); } return v; } // read the header of the rule violation private Header readHeader() throws IOException { String headerStart = readLine(); if (headerStart == null) return null; StringTokenizer tokenizer = new StringTokenizer(headerStart); Header header = null; try { String cur = tokenizer.nextToken(); String orig = tokenizer.nextToken(); String len = tokenizer.nextToken(); int icur = Integer.parseInt(cur); int iorig = Integer.parseInt(orig); int ilen = Integer.parseInt(len); header = new Header(icur, iorig, ilen); } catch (NoSuchElementException e) { System.out.println("Error parsing header start line, expected three integers on line number "+lineno+": "+headerStart); return null; } catch (NumberFormatException e) { System.out.println("Error converting count strings to integers on header start line, line number "+lineno+": "+headerStart); return null; } return header; } // populate a list of error shapes. return false on error. private DrcError readErrorShape() throws IOException { // we need to peek ahead, as it is unspecified how many error shapes there // may be String nextLine = readLine().trim(); boolean boole = nextLine.startsWith("e") ? true : false; boolean boolp = nextLine.startsWith("p") ? true : false; if (boole || boolp) { String [] parts = nextLine.split(spaces); if (parts.length != 3) { System.out.println("Error on shape: expected ordinal and count numbers, line number "+lineno+": "+nextLine); return null; }// int ordinal = 0; int lines = 0; try {// ordinal = Integer.parseInt(parts[1]); lines = Integer.parseInt(parts[2]); } catch (NumberFormatException e) { System.out.println("Error on shape: expected ordinal and count numbers, line number "+lineno+": "+nextLine); return null; } // need to peek ahead to see if next line specifies a subcell nextLine = readLine().trim(); Cell incell = topCell; if (nextLine.startsWith("CN")) { parts = nextLine.split(spaces); if (parts.length < 3) { System.out.println("Error reading CN line, expected at least three fields, line number "+lineno+": "+nextLine); return null; } String cellname = parts[1]; String coordSpace = parts[2]; if (coordSpace.equals("c")) { // coords are in sub cell coord system incell = getCell(cellname, mangledNames); if (incell == null) incell = topCell; } nextLine = readLine(); } DrcError drc = new DrcError(incell); double lambdaScale = incell.getTechnology().getScale() / 1000; // parse list of edges if this is edges shape if (boole) { for (int i=0; i<lines; i++) { if (i != 0) // skip first line read, done already when we looked for CN nextLine = readLine(); Shape s = parseErrorEdge(nextLine, lambdaScale); if (s == null) return drc; drc.addShape(s); } } // parse list of poly vertices if this is a poly else { // boolp Point2D [] points = new Point2D[lines]; for (int i=0; i<lines; i++) { if (i != 0) // skip first line read, done already when we looked for CN nextLine = readLine(); if (nextLine.startsWith("SN")) { nextLine = readLine(); } if (!parseErrorPoint(nextLine, points, i, lambdaScale)) return null; } Shape s = new PolyBase(points); drc.addShape(s); } return drc;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -