📄 exportchanges.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: ExportChanges.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.user;import com.sun.electric.database.geometry.DBMath;import com.sun.electric.database.geometry.ERectangle;import com.sun.electric.database.geometry.GenMath;import com.sun.electric.database.geometry.Poly;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.EDatabase;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.network.Netlist;import com.sun.electric.database.network.Network;import com.sun.electric.database.network.NetworkTool;import com.sun.electric.database.prototype.PortCharacteristic;import com.sun.electric.database.prototype.PortProto;import com.sun.electric.database.text.Name;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.Geometric;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.topology.PortInst;import com.sun.electric.database.variable.DisplayedText;import com.sun.electric.database.variable.ElectricObject;import com.sun.electric.technology.ArcProto;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.tool.Job;import com.sun.electric.tool.JobException;import com.sun.electric.tool.user.menus.MenuCommands;import com.sun.electric.tool.user.ui.EditWindow;import com.sun.electric.tool.user.ui.TopLevel;import com.sun.electric.tool.user.ui.WindowFrame;import java.awt.Font;import java.awt.Point;import java.awt.font.FontRenderContext;import java.awt.font.GlyphVector;import java.awt.font.LineMetrics;import java.awt.geom.AffineTransform;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import javax.swing.JOptionPane;/** * This class has all of the Export change commands in Electric. */public final class ExportChanges{ /****************************** EXPORT LISTING ******************************/ public static void describeExports(boolean summarize) { new DescribeExports(summarize); } private static class ExportList { Export pp; int equiv; int busList; } /** * Class to rename an export in a new thread. */ private static class DescribeExports extends Job { private boolean summarize; protected DescribeExports(boolean summarize) { super("Describe Exports", User.getUserTool(), Job.Type.EXAMINE, null, null, Job.Priority.USER); this.summarize = summarize; startJob(); } public boolean doIt() throws JobException { Cell cell = WindowFrame.needCurCell(); if (cell == null) return false; Netlist netlist = cell.acquireUserNetlist(); if (netlist == null) { System.out.println("Sorry, a deadlock aborted your query (network information unavailable). Please try again"); return false; } // compute the associated cell to check Cell wnp = cell.contentsView(); if (wnp == null) wnp = cell.iconView(); if (wnp == cell) wnp = null; // count the number of exports if (cell.getNumPorts() == 0) { System.out.println("There are no exports on " + cell); return true; } // make a list of exports List<ExportList> exports = new ArrayList<ExportList>(); for(Iterator<PortProto> it = cell.getPorts(); it.hasNext(); ) { ExportList el = new ExportList(); el.pp = (Export)it.next(); el.equiv = -1; el.busList = -1; exports.add(el); } // sort exports by name within type Collections.sort(exports, new ExportSortedByNameAndType()); // if summarizing, make associations that combine exports int num_found = exports.size(); if (summarize) { // make associations among electrically equivalent exports for(int j=0; j<num_found; j++) { int eqJ = exports.get(j).equiv; int blJ = exports.get(j).busList; if (eqJ != -1 || blJ != -1) continue; Export ppJ = exports.get(j).pp; for(int k=j+1; k<num_found; k++) { int eqK = exports.get(k).equiv; int blK = exports.get(k).busList; if (eqK != -1 || blK != -1) continue; Export ppK = exports.get(k).pp; if (ppJ.getCharacteristic() != ppK.getCharacteristic()) break; if (!netlist.sameNetwork(ppJ.getOriginalPort().getNodeInst(), ppJ.getOriginalPort().getPortProto(), ppK.getOriginalPort().getNodeInst(), ppK.getOriginalPort().getPortProto())) continue; exports.get(k).equiv = j; exports.get(j).equiv = -2; } } // make associations among bussed exports for(int j=0; j<num_found; j++) { int eqJ = exports.get(j).equiv; int blJ = exports.get(j).busList; if (eqJ != -1 || blJ != -1) continue; Export ppJ = exports.get(j).pp; String ptJ = ppJ.getName(); int sqPosJ = ptJ.indexOf('['); if (sqPosJ < 0) continue; for(int k=j+1; k<num_found; k++) { int eqK = exports.get(k).equiv; int blK = exports.get(k).busList; if (eqK != -1 || blK != -1) continue; Export ppK = exports.get(k).pp; if (ppJ.getCharacteristic() != ppK.getCharacteristic()) break; String ptK = ppK.getName(); int sqPosK = ptK.indexOf('['); if (sqPosJ != sqPosK) continue; if (ptJ.substring(0, sqPosJ).equalsIgnoreCase(ptK.substring(0, sqPosK))) { exports.get(k).busList = j; exports.get(j).busList = -2; } } } } // describe each export System.out.println("----- Exports on " + cell + ": total " + num_found + " -----"); Set<ArcProto> arcsSeen = new HashSet<ArcProto>(); for(int j=0; j<num_found; j++) { ExportList el = exports.get(j); Export pp = el.pp; if (el.equiv >= 0 || el.busList >= 0) continue; // reset flags for arcs that can connect for(Iterator<Technology> it = Technology.getTechnologies(); it.hasNext(); ) { Technology tech = it.next(); for(Iterator<ArcProto> aIt = tech.getArcs(); aIt.hasNext(); ) { ArcProto ap = aIt.next(); arcsSeen.remove(ap); } } String infstr = ""; String activity = pp.getCharacteristic().getFullName(); int m = j+1; for( ; m<num_found; m++) { if (exports.get(m).equiv == j) break; } double lx = 0, hx = 0, ly = 0, hy = 0; if (m < num_found) { // many exports that are electrically equivalent infstr += activity + " exports "; for(int k=j; k<num_found; k++) { if (j != k && exports.get(k).equiv != j) continue; if (j != k) infstr += ", "; Export opp = exports.get(k).pp; infstr += "'" + opp.getName() + "'"; Poly poly = opp.getOriginalPort().getPoly(); double x = poly.getCenterX(); double y = poly.getCenterY(); if (j == k) { lx = hx = x; ly = hy = y; } else { if (x < lx) lx = x; if (x > hx) hx = x; if (y < ly) ly = y; if (y > hy) hy = y; } ArcProto [] arcList = opp.getBasePort().getConnections(); for(int a=0; a<arcList.length; a++) arcsSeen.add(arcList[a]); } infstr += " at (" + lx + "<=X<=" + hx + ", " + ly + "<=Y<=" + hy + "), electrically connected to"; infstr = addPossibleArcConnections(infstr, arcsSeen); } else { m = j + 1; for( ; m<num_found; m++) { if (exports.get(m).busList == j) break; } if (m < num_found) { // many exports from the same bus int tot = 0; for(int k=j; k<num_found; k++) { if (j != k && exports.get(k).busList != j) continue; tot++; Export opp = exports.get(k).pp; Poly poly = opp.getOriginalPort().getPoly(); double x = poly.getCenterX(); double y = poly.getCenterY(); if (j == k) { lx = hx = x; ly = hy = y; } else { if (x < lx) lx = x; if (x > hx) hx = x; if (y < ly) ly = y; if (y > hy) hy = y; } ArcProto [] arcList = opp.getBasePort().getConnections(); for(int a=0; a<arcList.length; a++) arcsSeen.add(arcList[a]); } List<Export> sortedBusList = new ArrayList<Export>(); sortedBusList.add(exports.get(j).pp); for(int k=j+1; k<num_found; k++) { ExportList elK = exports.get(k); if (elK.busList == j) sortedBusList.add(elK.pp); } // sort the bus by indices Collections.sort(sortedBusList, new ExportSortedByBusIndex()); boolean first = true; for(Export ppS : sortedBusList) { String pt1 = ppS.getName(); int openPos = pt1.indexOf('['); if (first) { infstr += activity + " ports '" + pt1.substring(0, openPos) + "["; first = false; } else { infstr += ","; } int closePos = pt1.lastIndexOf(']'); infstr += pt1.substring(openPos+1, closePos); } infstr += "]' at (" + lx + "<=X<=" + hx + ", " + ly + "<=Y<=" + hy + "), same bus, connects to"; infstr = addPossibleArcConnections(infstr, arcsSeen); } else { // isolated export Poly poly = pp.getOriginalPort().getPoly(); double x = poly.getCenterX(); double y = poly.getCenterY(); infstr += activity + " export '" + pp.getName() + "' at (" + x + ", " + y + ") connects to"; ArcProto [] arcList = pp.getBasePort().getConnections(); for(int a=0; a<arcList.length; a++) arcsSeen.add(arcList[a]); infstr = addPossibleArcConnections(infstr, arcsSeen); // check for the export in the associated cell if (wnp != null) { if (pp.getEquivalentPort(wnp) == null) infstr += " *** no equivalent in " + wnp; } } } TextUtils.printLongString(infstr); } if (wnp != null) { for(Iterator<PortProto> it = wnp.getPorts(); it.hasNext(); ) { Export pp = (Export)it.next(); if (pp.getEquivalentPort(cell) == null) System.out.println("*** Export " + pp.getName() + ", found in " + wnp + ", is missing here"); } } return true; } } /** * Helper method to add all marked arc prototypes to the infinite string. * Marking is done by having the "temp1" field be nonzero. */ private static String addPossibleArcConnections(String infstr, Set arcsSeen) { int i = 0; for(Iterator<Technology> it = Technology.getTechnologies(); it.hasNext(); ) { Technology tech = it.next(); for(Iterator<ArcProto> aIt = tech.getArcs(); aIt.hasNext(); ) { ArcProto ap = aIt.next(); if (!arcsSeen.contains(ap)) i++; } } if (i == 0) infstr += " EVERYTHING"; else { i = 0; for(Iterator<Technology> it = Technology.getTechnologies(); it.hasNext(); ) { Technology tech = it.next(); if (tech == Generic.tech()) continue; for(Iterator<ArcProto> aIt = tech.getArcs(); aIt.hasNext(); ) { ArcProto ap = aIt.next(); if (!arcsSeen.contains(ap)) continue; if (i != 0) infstr += ","; i++; infstr += " " + ap.getName(); } } } return infstr; } private static class ExportSortedByNameAndType implements Comparator<ExportList> { public int compare(ExportList el1, ExportList el2) { Export e1 = el1.pp; Export e2 = el2.pp; PortCharacteristic ch1 = e1.getCharacteristic(); PortCharacteristic ch2 = e2.getCharacteristic(); if (ch1 != ch2) return ch1.getOrder() - ch2.getOrder(); String s1 = e1.getName(); String s2 = e2.getName(); return TextUtils.STRING_NUMBER_ORDER.compare(s1, s2); } } public static class ExportSortedByBusIndex implements Comparator<Export> { public int compare(Export e1, Export e2) { String s1 = e1.getName(); String s2 = e2.getName(); return TextUtils.STRING_NUMBER_ORDER.compare(s1, s2); } } private static class PortInstsSortedByBusIndex implements Comparator<PortInst> { public int compare(PortInst p1, PortInst p2) { String s1 = p1.getPortProto().getName(); String s2 = p2.getPortProto().getName(); return TextUtils.STRING_NUMBER_ORDER.compare(s1, s2); } } /** * Class to follow the current export up the hierarchy. * Lists all networks and exports connected in higher cells. */ public static class FollowExport extends Job { public FollowExport() { super("Re-export highlighted", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); startJob(); } public boolean doIt() throws JobException { // make sure there is a current cell Cell cell = WindowFrame.needCurCell(); if (cell == null) return false; List<Export> exportsToFollow = getSelectedExports(); if (exportsToFollow.size() == 0) { System.out.println("There are no selected exports to follow"); return false; } Map<Cell,Set<Network>> networksSeen = new HashMap<Cell,Set<Network>>(); Map<Cell,Set<Export>> exportsSeen = new HashMap<Cell,Set<Export>>(); List<Export> exportsFollowed = new ArrayList<Export>(); for(Export e : exportsToFollow) exportsFollowed.add(e); for(int i=0; i<exportsFollowed.size(); i++) { Export e = exportsFollowed.get(i); Cell upperCell = e.getParent(); for(Iterator<NodeInst> nIt = upperCell.getInstancesOf(); nIt.hasNext(); ) { NodeInst ni = nIt.next(); Cell higher = ni.getParent();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -