📄 change.java
字号:
lastAllowMissingPorts = allowMissingPorts.isSelected(); } private boolean dontReload = false; /** * Method called when dialog controls have changed. * Makes sure the displayed lists and options are correct. */ private void reload(boolean canSwitchLibraries) { lastChangeNodesWithArcs = changeNodesWithArcs.isSelected(); if (dontReload) return; changeListModel.clear(); changeNodeProtoList.clear(); if (geomsToChange.size() == 0) return; Technology curTech = Technology.getCurrent(); Geometric geomToChange = geomsToChange.get(0); if (geomToChange instanceof NodeInst) { NodeInst ni = (NodeInst)geomToChange; if (showCells.isSelected()) { // cell: only list other cells as replacements if (ni.isCellInstance() && canSwitchLibraries) { Cell parent = (Cell)ni.getProto(); Library lib = parent.getLibrary(); dontReload = true; librariesPopup.setSelectedItem(lib.getName()); dontReload = false; } View origView = null; if (ni.isCellInstance()) origView = ((Cell)ni.getProto()).getView(); String libName = (String)librariesPopup.getSelectedItem(); Library lib = Library.findLibrary(libName); for(Iterator<Cell> it = lib.getCells(); it.hasNext(); ) { Cell cell = it.next(); if (origView != null) { // filter according to original node's view if (origView == View.ICON) { if (cell.getView() != View.ICON) continue; } else if (origView == View.LAYOUT || origView == View.LAYOUTCOMP || origView == View.LAYOUTSKEL) { if (cell.getView() != View.LAYOUT && cell.getView() != View.LAYOUTCOMP && cell.getView() != View.LAYOUTSKEL) continue; } } changeListModel.addElement(cell.noLibDescribe()); changeNodeProtoList.add(cell); } } if (showPrimitives.isSelected()) { // primitive: list primitives in this and the generic technology for(PrimitiveNode np : curTech.getNodesSortedByName()) { changeListModel.addElement(np.describe(false)); changeNodeProtoList.add(np); } if (curTech != Generic.tech()) { changeListModel.addElement("Generic:Universal-Pin"); changeNodeProtoList.add(Generic.tech().universalPinNode); changeListModel.addElement("Generic:Invisible-Pin"); changeNodeProtoList.add(Generic.tech().invisiblePinNode); changeListModel.addElement("Generic:Unrouted-Pin"); changeNodeProtoList.add(Generic.tech().unroutedPinNode); } } changeList.setSelectedIndex(0); // try to select prototype of selected node if (ni.isCellInstance()) { Cell c = (Cell)ni.getProto(); for (int i=0; i<changeListModel.getSize(); i++) { String str = (String)changeListModel.get(i); if (str.equals(c.noLibDescribe())) { changeList.setSelectedIndex(i); break; } } } else { for (int i=0; i<changeListModel.getSize(); i++) { String str = (String)changeListModel.get(i); if (str.equals(ni.getProto().describe(false))) { changeList.setSelectedIndex(i); break; } } } if (showCells.isSelected()) { String geomName = ((NodeInst)geomToChange).getProto().describe(false); // if replacing dummy facet, name will be [cellname]FROM[libname][{view}] Matcher mat = dummyName.matcher(geomName); if (mat.matches()) { // try to select items. Nothing will happen if they are not in list. changeList.setSelectedValue(mat.group(1) + "{" + mat.group(3), true); librariesPopup.setSelectedItem(mat.group(2)); } else { // otherwise, try to match name changeList.setSelectedValue(geomName, true); } } } else { // load arcs in current technology, arc's technology, and generic technology ArcInst ai = (ArcInst)geomToChange; PortProto pp1 = ai.getHeadPortInst().getPortProto(); PortProto pp2 = ai.getTailPortInst().getPortProto(); for(Iterator<ArcProto> it = curTech.getArcs(); it.hasNext(); ) { ArcProto ap = it.next(); if (!changeNodesWithArcs.isSelected()) { if (!pp1.connectsTo(ap)) continue; if (!pp2.connectsTo(ap)) continue; } changeListModel.addElement(ap.describe()); } if (curTech != Generic.tech()) { for(Iterator<ArcProto> it = Generic.tech().getArcs(); it.hasNext(); ) { ArcProto ap = it.next(); if (!changeNodesWithArcs.isSelected()) { if (!pp1.connectsTo(ap)) continue; if (!pp2.connectsTo(ap)) continue; } changeListModel.addElement(ap.describe()); } } Technology arcTech = ai.getProto().getTechnology(); if (arcTech != curTech && arcTech != Generic.tech()) { for(Iterator<ArcProto> it = arcTech.getArcs(); it.hasNext(); ) { ArcProto ap = it.next(); if (!changeNodesWithArcs.isSelected()) { if (!pp1.connectsTo(ap)) continue; if (!pp2.connectsTo(ap)) continue; } changeListModel.addElement(ap.describe()); } } changeList.setSelectedIndex(0); } SwingUtilities.invokeLater(new Runnable() { public void run() { EDialog.centerSelection(changeList); }}); } private void doTheChange() { NodeProto np = null; ArcProto ap = null; Geometric geomToChange = geomsToChange.get(0); if (geomToChange instanceof NodeInst) { int index = changeList.getSelectedIndex(); np = changeNodeProtoList.get(index); } else { String line = (String)changeList.getSelectedValue(); ap = ArcProto.findArcProto(line); if (ap == null) { System.out.println("Nothing called '" + line + "'"); return; } } List<Geometric> highs = wnd.getHighlighter().getHighlightedEObjs(true, true); new ChangeObject(geomsToChange, highs, getLibSelected(), np, ap, ignorePortNames.isSelected(), allowMissingPorts.isSelected(), changeNodesWithArcs.isSelected(), changeInCell.isSelected(), changeInLibrary.isSelected(), changeEverywhere.isSelected(), changeConnected.isSelected()); } /** * Class to change the node/arc type in a new thread. */ private static class ChangeObject extends Job { private List<Geometric> geomsToChange, highs; private String libName; private NodeProto np; private ArcProto ap; private boolean ignorePortNames, allowMissingPorts, changeNodesWithArcs; private boolean changeInCell, changeInLibrary, changeEverywhere, changeConnected; private List<Geometric> highlightThese; private ChangeObject(List<Geometric> geomsToChange, List<Geometric> highs, String libName, NodeProto np, ArcProto ap, boolean ignorePortNames, boolean allowMissingPorts, boolean changeNodesWithArcs, boolean changeInCell, boolean changeInLibrary, boolean changeEverywhere, boolean changeConnected) { super("Change type", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.geomsToChange = geomsToChange; this.highs = highs; this.libName = libName; this.np = np; this.ap = ap; this.ignorePortNames = ignorePortNames; this.allowMissingPorts = allowMissingPorts; this.changeNodesWithArcs = changeNodesWithArcs; this.changeInCell = changeInCell; this.changeInLibrary = changeInLibrary; this.changeEverywhere = changeEverywhere; this.changeConnected = changeConnected; startJob(); } public boolean doIt() throws JobException { highlightThese = new ArrayList<Geometric>(); fieldVariableChanged("highlightThese"); Set<Geometric> changedAlready = new HashSet<Geometric>(); for (Geometric geomToChange : geomsToChange) { // handle node replacement if (geomToChange instanceof NodeInst) { // get node to be replaced NodeInst ni = (NodeInst)geomToChange; // disallow replacing if lock is on if (CircuitChangeJobs.cantEdit(ni.getParent(), ni, true, false, true) != 0) return false; // get nodeproto to replace it with Library library = Library.findLibrary(libName); if (library == null) return false; if (np == null) return false; // sanity check NodeProto oldNType = ni.getProto(); if (oldNType == np) { System.out.println("Node already of type " + np.describe(true)); // just skip this case. No need to redo it. This not an error. continue; } // replace the nodeinsts if (!changedAlready.contains(ni)) { changedAlready.add(ni); NodeInst onlyNewNi = CircuitChangeJobs.replaceNodeInst(ni, np, ignorePortNames, allowMissingPorts); if (onlyNewNi == null) { JOptionPane.showMessageDialog(TopLevel.getCurrentJFrame(), np + " does not fit in the place of " + oldNType, "Change failed", JOptionPane.ERROR_MESSAGE); return false; } highlightThese.add(onlyNewNi); } // 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<NodeInst> nIt = cell.getNodes(); nIt.hasNext(); ) { NodeInst lNi = nIt.next(); if (lNi.getProto() != oldNType) continue; if (!changedAlready.contains(lNi)) { changedAlready.add(lNi); // do not replace the example icon if (lNi.isIconOfParent()) { System.out.println("Example icon in " + cell + " not replaced"); continue; } // 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 all libraries replaced with " + np); } else if (changeInLibrary) { // replace throughout the library containing "this cell"if requested Library lib = WindowFrame.getCurrentCell().getLibrary(); for(Iterator<Cell> cIt = lib.getCells(); cIt.hasNext(); ) { Cell cell = cIt.next(); boolean found = true; while (found) { found = false; for(Iterator<NodeInst> nIt = cell.getNodes(); nIt.hasNext(); ) { NodeInst lNi = nIt.next(); if (lNi.getProto() != oldNType) continue; 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 " + lib + " replaced with " + np); } else if (changeInCell) { // replace throughout this cell if "requested Cell cell = WindowFrame.getCurrentCell(); boolean found = true; while (found) { found = false; for(Iterator<NodeInst> nIt = cell.getNodes(); nIt.hasNext(); ) { NodeInst lNi = nIt.next(); if (lNi.getProto() != oldNType) continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -