📄 change.java
字号:
if (!changedAlready.contains(lNi)) { changedAlready.add(lNi); // disallow replacing if lock is on int errorCode = CircuitChangeJobs.cantEdit(cell, lNi, true, false, true); if (errorCode < 0) return false; if (errorCode > 0) continue; NodeInst newNi = CircuitChangeJobs.replaceNodeInst(lNi, np, ignorePortNames, allowMissingPorts); if (newNi != null) { total++; found = true; break; } } } } System.out.println("All " + total + " " + oldNType.describe(true) + " nodes in " + cell + " replaced with " + np); } else if (changeConnected) { // replace all connected to this in the cell if requested Cell curCell = WindowFrame.getCurrentCell(); Netlist netlist = curCell.getUserNetlist(); List<NodeInst> others = new ArrayList<NodeInst>(); NodeInst onlyNewNi = null; if (highlightThese.size() == 1 && highlightThese.get(0) instanceof NodeInst) onlyNewNi = (NodeInst)highlightThese.get(0); for(Iterator<NodeInst> it = curCell.getNodes(); it.hasNext(); ) { NodeInst lNi = it.next(); if (lNi.getProto() != oldNType) continue; if (lNi == onlyNewNi) continue; boolean found = false; for(Iterator<PortInst> pIt = onlyNewNi.getPortInsts(); pIt.hasNext(); ) { PortInst pi = pIt.next(); for(Iterator<PortInst> lPIt = lNi.getPortInsts(); lPIt.hasNext(); ) { PortInst lPi = lPIt.next(); if (netlist.sameNetwork(pi.getNodeInst(), pi.getPortProto(), lPi.getNodeInst(), lPi.getPortProto())) { found = true; break; } } if (found) break; } if (found) others.add(lNi); } // make the changes for(NodeInst lNi : others) { if (!changedAlready.contains(lNi)) { changedAlready.add(lNi); // disallow replacing if lock is on int errorCode = CircuitChangeJobs.cantEdit(curCell, lNi, true, false, true); if (errorCode < 0) return false; if (errorCode > 0) continue; NodeInst newNi = CircuitChangeJobs.replaceNodeInst(lNi, np, ignorePortNames, allowMissingPorts); if (newNi != null) total++; } } System.out.println("All " + total + " " + oldNType.describe(true) + " nodes connected to this replaced with " + np); } else System.out.println(oldNType + " replaced with " + np); } else { // get arc to be replaced ArcInst ai = (ArcInst)geomToChange; if (ap == null) { System.out.println("Arc " + ai.getName() + " skipped"); continue; } // disallow replacement if lock is on if (CircuitChangeJobs.cantEdit(ai.getParent(), null, true, false, true) != 0) return false; // sanity check ArcProto oldAType = ai.getProto(); if (oldAType == ap) { System.out.println("Arc already of type " + ap.describe()); return false; } // special case when replacing nodes, too if (changeNodesWithArcs) { if (changeInLibrary) { for(Iterator<Cell> it = Library.getCurrent().getCells(); it.hasNext(); ) { Cell cell = it.next(); replaceAllArcs(cell, highs, ai, ap, false, true); } } else { replaceAllArcs(ai.getParent(), highs, ai, ap, changeConnected, changeInCell); } return true; } // replace the arcinst ArcInst onlyNewAi = ai.replace(ap); if (onlyNewAi == null) { System.out.println(ap + " does not fit in the place of " + oldAType); return false; } highlightThese.add(onlyNewAi); // do additional replacements if requested int total = 1; if (changeEverywhere) { // replace in all cells of library if requested for(Iterator<Library> it = Library.getLibraries(); it.hasNext(); ) { Library lib = it.next(); for(Iterator<Cell> cIt = lib.getCells(); cIt.hasNext(); ) { Cell cell = cIt.next(); boolean found = true; while (found) { found = false; for(Iterator<ArcInst> nIt = cell.getArcs(); nIt.hasNext(); ) { ArcInst lAi = nIt.next(); if (lAi.getProto() != oldAType) continue; // disallow replacing if lock is on int errorCode = CircuitChangeJobs.cantEdit(cell, null, true, false, true); if (errorCode < 0) return false; if (errorCode > 0) continue; ArcInst newAi = lAi.replace(ap); if (newAi != null) { total++; found = true; break; } } } } } System.out.println("All " + total + " " + oldAType.describe() + " arcs in the library replaced with " + ap); } else if (changeInLibrary) { // replace throughout this library if requested Library lib = Library.getCurrent(); for(Iterator<Cell> cIt = lib.getCells(); cIt.hasNext(); ) { Cell cell = cIt.next(); boolean found = true; while (found) { found = false; for(Iterator<ArcInst> nIt = cell.getArcs(); nIt.hasNext(); ) { ArcInst lAi = nIt.next(); if (lAi.getProto() != oldAType) continue; // disallow replacing if lock is on int errorCode = CircuitChangeJobs.cantEdit(cell, null, true, false, true); if (errorCode < 0) return false; if (errorCode > 0) continue; ArcInst newAi = lAi.replace(ap); if (newAi != null) { total++; found = true; break; } } } } System.out.println("All " + total + " " + oldAType.describe() + " arcs in " + lib + " replaced with " + ap); } else if (changeInCell) { // replace throughout this cell if requested Cell cell = WindowFrame.getCurrentCell(); boolean found = true; while (found) { found = false; for(Iterator<ArcInst> nIt = cell.getArcs(); nIt.hasNext(); ) { ArcInst lAi = nIt.next(); if (lAi.getProto() != oldAType) continue; // disallow replacing if lock is on int errorCode = CircuitChangeJobs.cantEdit(cell, null, true, false, true); if (errorCode < 0) return false; if (errorCode > 0) continue; ArcInst newAi = lAi.replace(ap); if (newAi != null) { total++; found = true; break; } } } System.out.println("All " + total + " " + oldAType.describe() + " arcs in " + cell + " replaced with " + ap); } else if (changeConnected) { // replace all connected to this if requested List<ArcInst> others = new ArrayList<ArcInst>(); Cell cell = WindowFrame.getCurrentCell(); Netlist netlist = cell.getUserNetlist(); for(Iterator<ArcInst> it = cell.getArcs(); it.hasNext(); ) { ArcInst lAi = it.next(); if (lAi == onlyNewAi) continue; if (netlist.sameNetwork(onlyNewAi, lAi)) others.add(lAi); } for(ArcInst lAi : others) { ArcInst newAi = lAi.replace(ap); if (newAi != null) total++; } System.out.println("All " + total + " " + oldAType.describe() + " arcs connected to this replaced with " + ap); } else System.out.println(oldAType + " replaced with " +ap); } } return true; } public void terminateOK() { EditWindow wnd = EditWindow.getCurrent(); if (wnd != null) { Highlighter highlighter = wnd.getHighlighter(); for(Geometric geom : highlightThese) { highlighter.addElectricObject(geom, geom.getParent()); } } } /** * Method to replace arc "oldAi" with another of type "ap", adding layer-change contacts * as needed to keep the connections. If "connected" is true, replace all such arcs * connected to this. If "thiscell" is true, replace all such arcs in the cell. */ private void replaceAllArcs(Cell cell, List<Geometric> highs, ArcInst oldAi, ArcProto ap, boolean connected, boolean thiscell) { Set<Geometric> geomMarked = new HashSet<Geometric>(); List<NodeInst> changePins = new ArrayList<NodeInst>(); for(Geometric geom : highs) { if (!(geom instanceof ArcInst)) continue; ArcInst ai = (ArcInst)geom; if (ai.getProto() != oldAi.getProto()) continue; geomMarked.add(ai); } if (connected) { Netlist netlist = cell.getUserNetlist(); for(Iterator<ArcInst> it = cell.getArcs(); it.hasNext(); ) { ArcInst ai = it.next(); if (ai.getProto() != oldAi.getProto()) continue; if (!netlist.sameNetwork(ai, oldAi)) continue; geomMarked.add(ai); } } if (thiscell) { for(Iterator<ArcInst> it = cell.getArcs(); it.hasNext(); ) { ArcInst ai = it.next(); if (ai.getProto() != oldAi.getProto()) continue; geomMarked.add(ai); } } for(Iterator<NodeInst> it = cell.getNodes(); it.hasNext(); ) { NodeInst ni = it.next(); if (ni.isCellInstance()) continue; if (ni.getFunction() != PrimitiveNode.Function.PIN) continue; boolean allArcs = true; for(Iterator<Connection> cIt = ni.getConnections(); cIt.hasNext(); ) { Connection con = cIt.next(); if (!geomMarked.contains(con.getArc())) { allArcs = false; break; } } if (ni.hasConnections() && allArcs) changePins.add(ni); } // now create new pins where they belong PrimitiveNode pin = ap.findOverridablePinProto(); double xS = pin.getDefWidth(); double yS = pin.getDefHeight(); Map<NodeInst,NodeInst> newNodes = new HashMap<NodeInst,NodeInst>(); for(NodeInst ni : changePins) { NodeInst newNi = NodeInst.makeInstance(pin, ni.getAnchorCenter(), xS, yS, cell); if (newNi == null) return; newNodes.put(ni, newNi); // move exports for(Iterator<Export> eIt = ni.getExports(); eIt.hasNext(); ) { Export oldExport = eIt.next(); if (oldExport.move(newNi.getOnlyPortInst())) { System.out.println("Unable to move export " + oldExport.getName() + " from old pin " + ni.describe(true) + " to new pin " + newNi); } } } // now create new arcs to replace the old ones for(Geometric geom : geomMarked) { if (!(geom instanceof ArcInst)) continue; ArcInst ai = (ArcInst)geom; PortInst pi0 = null; NodeInst newNi0 = newNodes.get(ai.getHeadPortInst().getNodeInst()); if (newNi0 != null) { pi0 = newNi0.getOnlyPortInst(); } else { // need contacts to get to the right level pi0 = makeContactStack(ai, ArcInst.HEADEND, ap); if (pi0 == null) return; } PortInst pi1 = null; NodeInst newNi1 = newNodes.get(ai.getTailPortInst().getNodeInst()); if (newNi1 != null) { pi1 = newNi1.getOnlyPortInst(); } else { // need contacts to get to the right level pi1 = makeContactStack(ai, ArcInst.TAILEND, ap); if (pi1 == null) return; } double wid = ap.getDefaultLambdaBaseWidth(); if (ai.getLambdaBaseWidth() > wid) wid = ai.getLambdaBaseWidth(); ArcInst newAi = ArcInst.makeInstanceBase(ap, wid, pi0, pi1, ai.getHeadLocation(), ai.getTailLocation(), ai.getName()); if (newAi == null) return; newAi.copyPropertiesFrom(ai); geomMarked.remove(newAi); } // now remove the previous arcs and nodes for(Geometric geom : geomMarked) { if (geom instanceof ArcInst) { ArcInst ai = (ArcInst)geom; ai.kill();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -