📄 exportchanges.java
字号:
Set<Network> netsSeenInCell = networksSeen.get(higher); if (netsSeenInCell == null) { netsSeenInCell = new HashSet<Network>(); networksSeen.put(higher, netsSeenInCell); } Netlist nl = higher.acquireUserNetlist(); Network net = nl.getNetwork(ni, e, 0); if (net == null) continue; if (netsSeenInCell.contains(net)) continue; netsSeenInCell.add(net); for(Iterator<Export> it = net.getExports(); it.hasNext(); ) { Export furtherUp = it.next(); Set<Export> exportsSeenInCell = exportsSeen.get(higher); if (exportsSeenInCell == null) { exportsSeenInCell = new HashSet<Export>(); exportsSeen.put(higher, exportsSeenInCell); } if (exportsSeenInCell.contains(furtherUp)) continue; exportsSeenInCell.add(furtherUp); exportsFollowed.add(furtherUp); } } // now consider icon cells Cell iconCell = upperCell.iconView(); if (iconCell != null) { for(Iterator<NodeInst> nIt = iconCell.getInstancesOf(); nIt.hasNext(); ) { NodeInst ni = nIt.next(); if (ni.isIconOfParent()) continue; Cell higher = ni.getParent(); Set<Network> netsSeenInCell = networksSeen.get(higher); if (netsSeenInCell == null) { netsSeenInCell = new HashSet<Network>(); networksSeen.put(higher, netsSeenInCell); } Netlist nl = higher.acquireUserNetlist(); Network net = nl.getNetwork(ni, e, 0); if (netsSeenInCell.contains(net)) continue; netsSeenInCell.add(net); for(Iterator<Export> it = net.getExports(); it.hasNext(); ) { Export furtherUp = it.next(); Set<Export> exportsSeenInCell = exportsSeen.get(higher); if (exportsSeenInCell == null) { exportsSeenInCell = new HashSet<Export>(); exportsSeen.put(higher, exportsSeenInCell); } if (exportsSeenInCell.contains(furtherUp)) continue; exportsSeenInCell.add(furtherUp); exportsFollowed.add(furtherUp); } } } } if (networksSeen.size() == 0) { System.out.println("The selected Exports are not used anywhere"); return true; } if (exportsToFollow.size() > 1) { System.out.print("The Exports "); for(int i=0; i<exportsToFollow.size(); i++) { if (i > 0) System.out.print(","); System.out.print(" " + exportsToFollow.get(i).getName()); } System.out.println(" are used:"); } else System.out.println("The Export " + exportsToFollow.get(0).getName() + " is used:"); for(Cell c : networksSeen.keySet()) { Set<Network> netsSeenInCell = networksSeen.get(c); Set<Export> exportsSeenInCell = exportsSeen.get(c); System.out.print(" Cell " + c.describe(false)); if (netsSeenInCell.size() > 1) System.out.print(" networks"); else System.out.print(" network"); boolean comma = false; for(Network n : netsSeenInCell) { if (comma) System.out.print(","); comma = true; System.out.print(" " + n.getName()); } System.out.println(); if (exportsSeenInCell != null) { System.out.print(" And further exported as"); comma = false; for(Export e : exportsSeenInCell) { if (comma) System.out.print(","); comma = true; System.out.print(" " + e.getName()); } System.out.println(); } } return true; } } /****************************** EXPORT CREATION ******************************/ /** * Method to re-export all unwired/unexported ports on cell instances in the current Cell. */ public static void reExportAll() { // make sure there is a current cell Cell cell = WindowFrame.needCurCell(); if (cell == null) return; List<Geometric> allNodes = new ArrayList<Geometric>(); for (Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); ) { allNodes.add(it.next()); } new ReExportNodes(cell, allNodes, false, true, false, true); } /** * Method to re-export everything that is selected. * @param wiredPorts true to re-export ports that are wired. * @param unwiredPorts true to re-export ports that are unwired. */ public static void reExportSelected(boolean wiredPorts, boolean unwiredPorts) { // make sure there is a current cell Cell cell = WindowFrame.needCurCell(); if (cell == null) return; List<Geometric> nodeInsts = MenuCommands.getSelectedObjects(true, false); if (nodeInsts.size() == 0) { JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), "Please select one or objects to re-export", "Re-export failed", JOptionPane.ERROR_MESSAGE); return; } new ReExportNodes(cell, nodeInsts, wiredPorts, unwiredPorts, false, true); } /** * Method to reexport the selected port on other nodes in the cell. */ public static void reExportSelectedPort() { // make sure there is a current cell EditWindow wnd = EditWindow.needCurrent(); if (wnd == null) return; Highlighter highlighter = wnd.getHighlighter(); if (highlighter == null) return; Highlight2 high = highlighter.getOneHighlight(); if (high == null || !high.isHighlightEOBJ() || !(high.getElectricObject() instanceof PortInst)) { System.out.println("Must first select a single node and its port"); return; } PortInst pi = (PortInst)high.getElectricObject(); PortProto pp = pi.getPortProto(); NodeInst ni = pi.getNodeInst(); // make a list of ports to reexport List<PortInst> queuedExports = new ArrayList<PortInst>(); Cell cell = ni.getParent(); for(Iterator<NodeInst>it = cell.getNodes(); it.hasNext(); ) { NodeInst oNi = it.next(); if (oNi.getProto() != ni.getProto()) continue; boolean unexported = true; for(Iterator<Export> eIt = oNi.getExports(); eIt.hasNext(); ) { Export e = eIt.next(); if (e.getOriginalPort().getPortProto() == pp) { unexported = false; break; } } if (unexported) { PortInst oPi = oNi.findPortInstFromProto(pp); queuedExports.add(oPi); } } // create job new ReExportPorts(cell, queuedExports, true, false, true, false, null); } /** * Method to re-export all unwired/unexported ports on cell instances in the current Cell. * Only works for power and ground ports. */ public static void reExportPowerAndGround() { // make sure there is a current cell Cell cell = WindowFrame.needCurCell(); if (cell == null) return; List<Geometric> allNodes = new ArrayList<Geometric>(); for (Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); ) { allNodes.add(it.next()); } new ReExportNodes(cell, allNodes, false, true, true, true); } /** * Helper class for re-exporting ports on nodes. */ private static class ReExportNodes extends Job { private Cell cell; private List<Geometric> nodeInsts; private boolean wiredPorts; private boolean unwiredPorts; private boolean onlyPowerGround; private boolean ignorePrimitives; /** * @see ExportChanges#reExportNodes(java.util.List, boolean, boolean, boolean) */ public ReExportNodes(Cell cell, List<Geometric> nodeInsts, boolean wiredPorts, boolean unwiredPorts, boolean onlyPowerGround, boolean ignorePrimitives) { super("Re-export nodes", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.cell = cell; this.nodeInsts = nodeInsts; this.wiredPorts = wiredPorts; this.unwiredPorts = unwiredPorts; this.onlyPowerGround = onlyPowerGround; this.ignorePrimitives = ignorePrimitives; startJob(); } public boolean doIt() throws JobException { // disallow port action if lock is on if (CircuitChangeJobs.cantEdit(cell, null, true, true, true) != 0) return false; int num = reExportNodes(cell, nodeInsts, wiredPorts, unwiredPorts, onlyPowerGround, ignorePrimitives); System.out.println(num+" ports exported."); return true; } } /** * Re-exports ports on each NodeInst in the list, in the order the nodeinsts appear * in the list. Sorts the exports on each node before exporting them to make sure they * get the correct bus indices at the next level up. * @param cell the cell in which exporting is happening. * @param nodeInsts a list of NodeInsts whose ports will be exported * @param wiredPorts true to include ports that have wire connections * @param unwiredPorts true to include ports that do not have wire connections * @param onlyPowerGround true to only export power and ground type ports * @param ignorePrimitives true to ignore primitive nodes * @return the number of exports created */ public static int reExportNodes(Cell cell, List<Geometric> nodeInsts, boolean wiredPorts, boolean unwiredPorts, boolean onlyPowerGround, boolean ignorePrimitives) { int total = 0; for (Geometric geom : nodeInsts) { NodeInst ni = (NodeInst)geom; // only look for cells, not primitives if (ignorePrimitives) if (!ni.isCellInstance()) continue; // ignore recursive references (showing icon in contents) if (ni.isIconOfParent()) continue; List<PortInst> portInstsToExport = new ArrayList<PortInst>(); for(Iterator<PortInst> pIt = ni.getPortInsts(); pIt.hasNext(); ) { PortInst pi = pIt.next(); // ignore if already exported boolean found = false; for(Iterator<Export> eIt = ni.getExports(); eIt.hasNext(); ) { Export pp = eIt.next(); if (pp.getOriginalPort() == pi) { found = true; break; } } if (found) continue; // add pi to list of ports to export portInstsToExport.add(pi); } total += reExportPorts(cell, portInstsToExport, true, wiredPorts, unwiredPorts, onlyPowerGround, null); } return total; } /** * Helper class for re-exporting a port on a node. */ public static class ReExportPorts extends Job { private Cell cell; private List<PortInst> portInsts; private boolean sort; private boolean wiredPorts; private boolean unwiredPorts; private boolean onlyPowerGround; private Map<PortInst,Export> originalExports; /** * Constructor. */ public ReExportPorts(Cell cell, List<PortInst> portInsts, boolean sort, boolean wiredPorts, boolean unwiredPorts, boolean onlyPowerGround, Map<PortInst,Export> originalExports) { super("Re-export ports", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.cell = cell; this.portInsts = portInsts; this.wiredPorts = wiredPorts; this.unwiredPorts = unwiredPorts; this.onlyPowerGround = onlyPowerGround; this.sort = sort; this.originalExports = originalExports; startJob(); } public boolean doIt() throws JobException { // disallow port action if lock is on if (CircuitChangeJobs.cantEdit(cell, null, true, true, true) != 0) return false; int num = reExportPorts(cell, portInsts, sort, wiredPorts, unwiredPorts, onlyPowerGround, originalExports); System.out.println(num+" ports exported."); return true; } } /****************************** EXPORT CREATION IN A HIGHLIGHTED AREA ******************************/ /** * Method to re-export all unwired/unexported ports on cell instances in the current Cell. * Only works in the currently highlighted area. * @param deep true to reexport hierarchically to the bottom. * @param wiredPorts true to reexport ports that are wired. * @param unwiredPorts true to reexport ports that are not wired. */ public static void reExportHighlighted(boolean deep, boolean wiredPorts, boolean unwiredPorts) { // make sure there is a current cell Cell cell = WindowFrame.needCurCell(); if (cell == null) return; EditWindow wnd = EditWindow.getCurrent(); Rectangle2D bounds = wnd.getHighlighter().getHighlightedArea(null); if (bounds == null) { JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), "Must select area before re-exporting the highlighted area", "Re-export failed", JOptionPane.ERROR_MESSAGE); return; } // do the job of reexporting in a boundary ERectangle eBounds = ERectangle.fromLambda(bounds); new ReExportHighlighted(cell, eBounds, deep, wiredPorts, unwiredPorts); } /** * Class to Re-export the highlighted area in a Job. */ private static class ReExportHighlighted extends Job { private Cell cell; private ERectangle bounds; private boolean deep; private boolean wiredPorts; private boolean unwiredPorts; public ReExportHighlighted(Cell cell, ERectangle bounds, boolean deep, boolean wiredPorts, boolean unwiredPorts) { super("Re-export highlighted", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.cell = cell; this.bounds = bounds; this.deep = deep; this.wiredPorts = wiredPorts; this.unwiredPorts = unwiredPorts; startJob(); } public boolean doIt() throws JobException { // disallow port action if lock is on if (CircuitChangeJobs.cantEdit(cell, null, true, true, true) != 0) return false; reExportInBounds(cell, bounds, deep, wiredPorts, unwiredPorts, true); return true; } } /** * Helper method to recursively re-export everything in a highlighted area. * @param cell the Cell in which to re-export. * @param bounds the area of the Cell to re-export. * @param deep true to recurse down to subcells and re-export. * @param wiredPorts true to re-export when the port is wired. * @param unwiredPorts true to re-export when the port is not wired. * @param topLevel true if this is the top-level call. */ private static void reExportInBounds(Cell cell, Rectangle2D bounds, boolean deep, boolean wiredPorts, boolean unwiredPorts, boolean topLevel) { // find all ports in highlighted area List<PortInst> queuedExports = new ArrayList<PortInst>(); for (Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); ) { NodeInst ni = it.next(); if (!ni.isCellInstance()) continue; // see if the cell intersects the bounds Rectangle2D cellBounds = ni.getBounds(); if (!bounds.intersects(cellBounds)) continue; // if doing a deep reexport, recurse into the cell if (deep) { AffineTransform goIn = ni.translateIn(ni.rotateIn()); Rectangle2D boundsInside = new Rectangle2D.Double(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight()); DBMath.transformRect(boundsInside, goIn); reExportInBounds((Cell)ni.getProto(), boundsInside, deep, wiredPorts, unwiredPorts, false); } for (Iterator<PortInst> pIt = ni.getPortInsts(); pIt.hasNext(); ) { PortInst pi = pIt.next(); // make sure the port is inside the selected area Poly portPoly = pi.getPoly(); if (!bounds.contains(portPoly.getCenterX(), portPoly.getCenterY())) continue; queuedExports.add(pi); } } // remove already-exported ports for(Iterator<PortProto> it = cell.getPorts(); it.hasNext(); ) { Export pp = (Export)it.next(); PortInst pi = pp.getOriginalPort(); queuedExports.remove(pi); } // no ports to export if (queuedExports.size() == 0) { if (topLevel) System.out.println("No ports in area to export"); return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -